mirror of
https://github.com/openjdk/jdk.git
synced 2026-04-19 19:30:51 +00:00
Merge
This commit is contained in:
commit
433b31bbda
@ -55,7 +55,6 @@ $(eval $(call SetupJavaCompilation,BUILD_BREAKITERATOR_BASE, \
|
||||
$(eval $(call SetupJavaCompilation,BUILD_BREAKITERATOR_LD, \
|
||||
SETUP := GENERATE_OLDBYTECODE, \
|
||||
SRC := $(JDK_TOPDIR)/src/jdk.localedata/share/classes, \
|
||||
INCLUDES := $(TEXT_PKG_LD), \
|
||||
INCLUDE_FILES := \
|
||||
$(TEXT_PKG_LD)/BreakIteratorRules_th.java \
|
||||
$(TEXT_PKG_LD)/BreakIteratorInfo_th.java, \
|
||||
|
||||
@ -44,6 +44,7 @@ SUNWprivate_1.1 {
|
||||
SplashSetFileJarName;
|
||||
SplashSetScaleFactor;
|
||||
SplashGetScaledImageName;
|
||||
SplashGetScaledImgNameMaxPstfixLen;
|
||||
local:
|
||||
*;
|
||||
};
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1994, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1994, 2016, 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,6 @@
|
||||
package java.io;
|
||||
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import sun.nio.ch.FileChannelImpl;
|
||||
|
||||
|
||||
@ -60,7 +59,9 @@ class FileInputStream extends InputStream
|
||||
|
||||
private volatile FileChannel channel;
|
||||
|
||||
private final AtomicBoolean closed = new AtomicBoolean(false);
|
||||
private final Object closeLock = new Object();
|
||||
|
||||
private volatile boolean closed;
|
||||
|
||||
/**
|
||||
* Creates a <code>FileInputStream</code> by
|
||||
@ -313,14 +314,21 @@ class FileInputStream extends InputStream
|
||||
* @spec JSR-51
|
||||
*/
|
||||
public void close() throws IOException {
|
||||
if (!closed.compareAndSet(false, true)) {
|
||||
// if compareAndSet() returns false closed was already true
|
||||
if (closed) {
|
||||
return;
|
||||
}
|
||||
synchronized (closeLock) {
|
||||
if (closed) {
|
||||
return;
|
||||
}
|
||||
closed = true;
|
||||
}
|
||||
|
||||
FileChannel fc = channel;
|
||||
if (fc != null) {
|
||||
fc.close();
|
||||
// possible race with getChannel(), benign since
|
||||
// FileChannel.close is final and idempotent
|
||||
fc.close();
|
||||
}
|
||||
|
||||
fd.closeAll(new Closeable() {
|
||||
@ -370,8 +378,10 @@ class FileInputStream extends InputStream
|
||||
fc = this.channel;
|
||||
if (fc == null) {
|
||||
this.channel = fc = FileChannelImpl.open(fd, path, true, false, this);
|
||||
if (closed.get()) {
|
||||
if (closed) {
|
||||
try {
|
||||
// possible race with close(), benign since
|
||||
// FileChannel.close is final and idempotent
|
||||
fc.close();
|
||||
} catch (IOException ioe) {
|
||||
throw new InternalError(ioe); // should not happen
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1994, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1994, 2016, 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,6 @@
|
||||
package java.io;
|
||||
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import jdk.internal.misc.SharedSecrets;
|
||||
import jdk.internal.misc.JavaIOFileDescriptorAccess;
|
||||
import sun.nio.ch.FileChannelImpl;
|
||||
@ -77,7 +76,9 @@ class FileOutputStream extends OutputStream
|
||||
*/
|
||||
private final String path;
|
||||
|
||||
private final AtomicBoolean closed = new AtomicBoolean(false);
|
||||
private final Object closeLock = new Object();
|
||||
|
||||
private volatile boolean closed;
|
||||
|
||||
/**
|
||||
* Creates a file output stream to write to the file with the
|
||||
@ -341,14 +342,21 @@ class FileOutputStream extends OutputStream
|
||||
* @spec JSR-51
|
||||
*/
|
||||
public void close() throws IOException {
|
||||
if (!closed.compareAndSet(false, true)) {
|
||||
// if compareAndSet() returns false closed was already true
|
||||
if (closed) {
|
||||
return;
|
||||
}
|
||||
synchronized (closeLock) {
|
||||
if (closed) {
|
||||
return;
|
||||
}
|
||||
closed = true;
|
||||
}
|
||||
|
||||
FileChannel fc = channel;
|
||||
if (fc != null) {
|
||||
fc.close();
|
||||
// possible race with getChannel(), benign since
|
||||
// FileChannel.close is final and idempotent
|
||||
fc.close();
|
||||
}
|
||||
|
||||
fd.closeAll(new Closeable() {
|
||||
@ -399,8 +407,10 @@ class FileOutputStream extends OutputStream
|
||||
fc = this.channel;
|
||||
if (fc == null) {
|
||||
this.channel = fc = FileChannelImpl.open(fd, path, false, true, this);
|
||||
if (closed.get()) {
|
||||
if (closed) {
|
||||
try {
|
||||
// possible race with close(), benign since
|
||||
// FileChannel.close is final and idempotent
|
||||
fc.close();
|
||||
} catch (IOException ioe) {
|
||||
throw new InternalError(ioe); // should not happen
|
||||
|
||||
@ -104,9 +104,9 @@ import sun.security.util.SecurityConstants;
|
||||
* class or resource itself.
|
||||
*
|
||||
* <p> Class loaders that support concurrent loading of classes are known as
|
||||
* <em>parallel capable</em> class loaders and are required to register
|
||||
* themselves at their class initialization time by invoking the
|
||||
* {@link
|
||||
* <em>{@linkplain #isParallelCapable() parallel capable}</em> class loaders and
|
||||
* are required to register themselves at their class initialization time by
|
||||
* invoking the {@link
|
||||
* #registerAsParallelCapable <tt>ClassLoader.registerAsParallelCapable</tt>}
|
||||
* method. Note that the <tt>ClassLoader</tt> class is registered as parallel
|
||||
* capable by default. However, its subclasses still need to register themselves
|
||||
@ -1437,7 +1437,7 @@ public abstract class ClassLoader {
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the caller as parallel capable.
|
||||
* Registers the caller as {@linkplain #isParallelCapable() parallel capable}.
|
||||
* The registration succeeds if and only if all of the following
|
||||
* conditions are met:
|
||||
* <ol>
|
||||
@ -1448,8 +1448,10 @@ public abstract class ClassLoader {
|
||||
* <p>Note that once a class loader is registered as parallel capable, there
|
||||
* is no way to change it back.</p>
|
||||
*
|
||||
* @return true if the caller is successfully registered as
|
||||
* parallel capable and false if otherwise.
|
||||
* @return {@code true} if the caller is successfully registered as
|
||||
* parallel capable and {@code false} if otherwise.
|
||||
*
|
||||
* @see #isParallelCapable()
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
@ -1460,6 +1462,22 @@ public abstract class ClassLoader {
|
||||
return ParallelLoaders.register(callerClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if this class loader is
|
||||
* {@linkplain #registerAsParallelCapable parallel capable}, otherwise
|
||||
* {@code false}.
|
||||
*
|
||||
* @return {@code true} if this class loader is parallel capable,
|
||||
* otherwise {@code false}.
|
||||
*
|
||||
* @see #registerAsParallelCapable()
|
||||
*
|
||||
* @since 9
|
||||
*/
|
||||
public final boolean isParallelCapable() {
|
||||
return ParallelLoaders.isRegistered(this.getClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a resource of the specified name from the search path used to load
|
||||
* classes. This method locates the resource through the system class
|
||||
@ -1663,6 +1681,15 @@ public abstract class ClassLoader {
|
||||
* this method during startup should take care not to cache the return
|
||||
* value until the system is fully initialized.
|
||||
*
|
||||
* <p> The class path used by the built-in system class loader is determined
|
||||
* by the system property "{@code java.class.path}" during early
|
||||
* initialization of the VM. If the system property is not defined,
|
||||
* or its value is an empty string, then there is no class path
|
||||
* when the initial module is a module on the application module path,
|
||||
* i.e. <em>a named module</em>. If the initial module is not on
|
||||
* the application module path then the class path defaults to
|
||||
* the current working directory.
|
||||
*
|
||||
* @return The system <tt>ClassLoader</tt> for delegation
|
||||
*
|
||||
* @throws SecurityException
|
||||
|
||||
@ -201,13 +201,13 @@ class InetAddress implements java.io.Serializable {
|
||||
* Specify the address family: Internet Protocol, Version 4
|
||||
* @since 1.4
|
||||
*/
|
||||
static final int IPv4 = 1;
|
||||
@Native static final int IPv4 = 1;
|
||||
|
||||
/**
|
||||
* Specify the address family: Internet Protocol, Version 6
|
||||
* @since 1.4
|
||||
*/
|
||||
static final int IPv6 = 2;
|
||||
@Native static final int IPv6 = 2;
|
||||
|
||||
/* Specify address family preference */
|
||||
static transient final int preferIPv6Address;
|
||||
|
||||
@ -69,16 +69,17 @@ public class ClassLoaders {
|
||||
bcp = toURLClassPath(s);
|
||||
|
||||
// we have a class path if -cp is specified or -m is not specified.
|
||||
// If neither is specified then default to -cp <working directory>.
|
||||
// If neither is specified then default to -cp <working directory>
|
||||
// If -cp is not specified and -m is specified, the value of
|
||||
// java.class.path is an empty string, then no class path.
|
||||
URLClassPath ucp = null;
|
||||
String mainMid = System.getProperty("jdk.module.main");
|
||||
String cp = System.getProperty("java.class.path");
|
||||
if (mainMid == null && cp == null)
|
||||
if (cp == null)
|
||||
cp = "";
|
||||
if (cp != null)
|
||||
if (mainMid == null || cp.length() > 0)
|
||||
ucp = toURLClassPath(cp);
|
||||
|
||||
|
||||
// create the class loaders
|
||||
BOOT_LOADER = new BootClassLoader(bcp);
|
||||
PLATFORM_LOADER = new PlatformClassLoader(BOOT_LOADER);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
# Copyright (c) 2007, 2016, 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
|
||||
@ -31,7 +31,7 @@ java.launcher.opt.header = Usage: {0} [options] class [args...]\n\
|
||||
\ (to execute the main class in a module)\n\
|
||||
where options include:\n
|
||||
|
||||
java.launcher.opt.datamodel =\ -d{0}\t use a {0}-bit data model if available\n
|
||||
java.launcher.opt.datamodel =\ -d{0}\t Deprecated, will be removed in a future release\n
|
||||
java.launcher.opt.vmselect =\ {0}\t to select the "{1}" VM\n
|
||||
java.launcher.opt.hotspot =\ {0}\t is a synonym for the "{1}" VM [deprecated]\n
|
||||
|
||||
@ -95,6 +95,12 @@ java.launcher.opt.footer =\ -cp <class search path of directories and zip
|
||||
\ load Java programming language agent, see java.lang.instrument\n\
|
||||
\ -splash:<imagepath>\n\
|
||||
\ show splash screen with specified image\n\
|
||||
\ HiDPI scaled images are automatically supported and used\n\
|
||||
\ if available. The unscaled image filename, e.g. image.ext,\n\
|
||||
\ should always be passed as the argument to the -splash option.\n\
|
||||
\ The most appropriate scaled image provided will be picked up\n\
|
||||
\ automatically.\n\
|
||||
\ See the SplashScreen API documentation for more information.\n\
|
||||
\ @<filepath> read options from the specified file\n\
|
||||
\To specify an argument for a long option, you can use --<name>=<value> or\n\
|
||||
\--<name> <value>.\n\
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2016, 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
|
||||
@ -37,15 +37,10 @@
|
||||
* This notice and attribution to Taligent may not be removed.
|
||||
* Taligent is a registered trademark of Taligent, Inc.
|
||||
*/
|
||||
package sun.util.locale.provider;
|
||||
package sun.text;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Module;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedActionException;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.nio.BufferUnderflowException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.MissingResourceException;
|
||||
import sun.text.CompactByteArray;
|
||||
import sun.text.SupplementaryCharacterData;
|
||||
@ -137,131 +132,90 @@ class BreakDictionary {
|
||||
// deserialization
|
||||
//=========================================================================
|
||||
|
||||
BreakDictionary(Module module, String dictionaryName)
|
||||
throws IOException, MissingResourceException {
|
||||
|
||||
readDictionaryFile(module, dictionaryName);
|
||||
BreakDictionary(String dictionaryName, byte[] dictionaryData) {
|
||||
try {
|
||||
setupDictionary(dictionaryName, dictionaryData);
|
||||
} catch (BufferUnderflowException bue) {
|
||||
MissingResourceException e;
|
||||
e = new MissingResourceException("Corrupted dictionary data",
|
||||
dictionaryName, "");
|
||||
e.initCause(bue);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private void readDictionaryFile(final Module module, final String dictionaryName)
|
||||
throws IOException, MissingResourceException {
|
||||
|
||||
BufferedInputStream in;
|
||||
try {
|
||||
PrivilegedExceptionAction<BufferedInputStream> pa = () -> {
|
||||
String pathName = "jdk.localedata".equals(module.getName()) ?
|
||||
"sun/text/resources/ext/" :
|
||||
"sun/text/resources/";
|
||||
InputStream is = module.getResourceAsStream(pathName + dictionaryName);
|
||||
if (is == null) {
|
||||
// Try to load the file with "java.base" module instance. Assumption
|
||||
// here is that the fall back data files to be read should reside in
|
||||
// java.base.
|
||||
is = BreakDictionary.class.getModule().getResourceAsStream("sun/text/resources/" + dictionaryName);
|
||||
}
|
||||
|
||||
return new BufferedInputStream(is);
|
||||
};
|
||||
in = AccessController.doPrivileged(pa);
|
||||
}
|
||||
catch (PrivilegedActionException e) {
|
||||
throw new InternalError(e.toString(), e);
|
||||
}
|
||||
|
||||
byte[] buf = new byte[8];
|
||||
if (in.read(buf) != 8) {
|
||||
throw new MissingResourceException("Wrong data length",
|
||||
dictionaryName, "");
|
||||
}
|
||||
private void setupDictionary(String dictionaryName, byte[] dictionaryData) {
|
||||
ByteBuffer bb = ByteBuffer.wrap(dictionaryData);
|
||||
|
||||
// check version
|
||||
int version = RuleBasedBreakIterator.getInt(buf, 0);
|
||||
int version = bb.getInt();
|
||||
if (version != supportedVersion) {
|
||||
throw new MissingResourceException("Dictionary version(" + version + ") is unsupported",
|
||||
dictionaryName, "");
|
||||
}
|
||||
|
||||
// get data size
|
||||
int len = RuleBasedBreakIterator.getInt(buf, 4);
|
||||
buf = new byte[len];
|
||||
if (in.read(buf) != len) {
|
||||
throw new MissingResourceException("Wrong data length",
|
||||
dictionaryName, "");
|
||||
}
|
||||
|
||||
// close the stream
|
||||
in.close();
|
||||
|
||||
int l;
|
||||
int offset = 0;
|
||||
// Check data size
|
||||
int len = bb.getInt();
|
||||
if (bb.position() + len != bb.limit()) {
|
||||
throw new MissingResourceException("Dictionary size is wrong: " + bb.limit(),
|
||||
dictionaryName, "");
|
||||
}
|
||||
|
||||
// read in the column map for BMP characteres (this is serialized in
|
||||
// its internal form: an index array followed by a data array)
|
||||
l = RuleBasedBreakIterator.getInt(buf, offset);
|
||||
offset += 4;
|
||||
short[] temp = new short[l];
|
||||
for (int i = 0; i < l; i++, offset+=2) {
|
||||
temp[i] = RuleBasedBreakIterator.getShort(buf, offset);
|
||||
}
|
||||
l = RuleBasedBreakIterator.getInt(buf, offset);
|
||||
offset += 4;
|
||||
byte[] temp2 = new byte[l];
|
||||
for (int i = 0; i < l; i++, offset++) {
|
||||
temp2[i] = buf[offset];
|
||||
len = bb.getInt();
|
||||
short[] temp = new short[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
temp[i] = bb.getShort();
|
||||
}
|
||||
len = bb.getInt();
|
||||
byte[] temp2 = new byte[len];
|
||||
bb.get(temp2);
|
||||
columnMap = new CompactByteArray(temp, temp2);
|
||||
|
||||
// read in numCols and numColGroups
|
||||
numCols = RuleBasedBreakIterator.getInt(buf, offset);
|
||||
offset += 4;
|
||||
numColGroups = RuleBasedBreakIterator.getInt(buf, offset);
|
||||
offset += 4;
|
||||
numCols = bb.getInt();
|
||||
numColGroups = bb.getInt();
|
||||
|
||||
// read in the row-number index
|
||||
l = RuleBasedBreakIterator.getInt(buf, offset);
|
||||
offset += 4;
|
||||
rowIndex = new short[l];
|
||||
for (int i = 0; i < l; i++, offset+=2) {
|
||||
rowIndex[i] = RuleBasedBreakIterator.getShort(buf, offset);
|
||||
len = bb.getInt();
|
||||
rowIndex = new short[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
rowIndex[i] = bb.getShort();
|
||||
}
|
||||
|
||||
// load in the populated-cells bitmap: index first, then bitmap list
|
||||
l = RuleBasedBreakIterator.getInt(buf, offset);
|
||||
offset += 4;
|
||||
rowIndexFlagsIndex = new short[l];
|
||||
for (int i = 0; i < l; i++, offset+=2) {
|
||||
rowIndexFlagsIndex[i] = RuleBasedBreakIterator.getShort(buf, offset);
|
||||
len = bb.getInt();
|
||||
rowIndexFlagsIndex = new short[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
rowIndexFlagsIndex[i] = bb.getShort();
|
||||
}
|
||||
l = RuleBasedBreakIterator.getInt(buf, offset);
|
||||
offset += 4;
|
||||
rowIndexFlags = new int[l];
|
||||
for (int i = 0; i < l; i++, offset+=4) {
|
||||
rowIndexFlags[i] = RuleBasedBreakIterator.getInt(buf, offset);
|
||||
len = bb.getInt();
|
||||
rowIndexFlags = new int[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
rowIndexFlags[i] = bb.getInt();
|
||||
}
|
||||
|
||||
// load in the row-shift index
|
||||
l = RuleBasedBreakIterator.getInt(buf, offset);
|
||||
offset += 4;
|
||||
rowIndexShifts = new byte[l];
|
||||
for (int i = 0; i < l; i++, offset++) {
|
||||
rowIndexShifts[i] = buf[offset];
|
||||
}
|
||||
len = bb.getInt();
|
||||
rowIndexShifts = new byte[len];
|
||||
bb.get(rowIndexShifts);
|
||||
|
||||
// load in the actual state table
|
||||
l = RuleBasedBreakIterator.getInt(buf, offset);
|
||||
offset += 4;
|
||||
table = new short[l];
|
||||
for (int i = 0; i < l; i++, offset+=2) {
|
||||
table[i] = RuleBasedBreakIterator.getShort(buf, offset);
|
||||
len = bb.getInt();
|
||||
table = new short[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
table[i] = bb.getShort();
|
||||
}
|
||||
|
||||
// finally, prepare the column map for supplementary characters
|
||||
l = RuleBasedBreakIterator.getInt(buf, offset);
|
||||
offset += 4;
|
||||
int[] temp3 = new int[l];
|
||||
for (int i = 0; i < l; i++, offset+=4) {
|
||||
temp3[i] = RuleBasedBreakIterator.getInt(buf, offset);
|
||||
len = bb.getInt();
|
||||
int[] temp3 = new int[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
temp3[i] = bb.getInt();
|
||||
}
|
||||
assert bb.position() == bb.limit();
|
||||
|
||||
supplementaryCharColumnMap = new SupplementaryCharacterData(temp3);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2016, 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
|
||||
@ -38,10 +38,8 @@
|
||||
* Taligent is a registered trademark of Taligent, Inc.
|
||||
*/
|
||||
|
||||
package sun.util.locale.provider;
|
||||
package sun.text;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Module;
|
||||
import java.text.CharacterIterator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -72,7 +70,7 @@ import java.util.Stack;
|
||||
* slow) BuildDictionaryFile utility for creating dictionary files, but aren't
|
||||
* currently making it public. Contact us for help.
|
||||
*/
|
||||
class DictionaryBasedBreakIterator extends RuleBasedBreakIterator {
|
||||
public class DictionaryBasedBreakIterator extends RuleBasedBreakIterator {
|
||||
|
||||
/**
|
||||
* a list of known words that is used to divide up contiguous ranges of letters,
|
||||
@ -109,18 +107,22 @@ class DictionaryBasedBreakIterator extends RuleBasedBreakIterator {
|
||||
|
||||
/**
|
||||
* Constructs a DictionaryBasedBreakIterator.
|
||||
* @param module The module where the dictionary file resides
|
||||
* @param dictionaryFilename The filename of the dictionary file to use
|
||||
*
|
||||
* @param ruleFile the name of the rule data file
|
||||
* @param ruleData the rule data loaded from the rule data file
|
||||
* @param dictionaryFile the name of the dictionary file
|
||||
* @param dictionartData the dictionary data loaded from the dictionary file
|
||||
* @throws MissingResourceException if rule data or dictionary initialization failed
|
||||
*/
|
||||
DictionaryBasedBreakIterator(Module module, String dataFile, String dictionaryFile)
|
||||
throws IOException {
|
||||
super(module, dataFile);
|
||||
public DictionaryBasedBreakIterator(String ruleFile, byte[] ruleData,
|
||||
String dictionaryFile, byte[] dictionaryData) {
|
||||
super(ruleFile, ruleData);
|
||||
byte[] tmp = super.getAdditionalData();
|
||||
if (tmp != null) {
|
||||
prepareCategoryFlags(tmp);
|
||||
super.setAdditionalData(null);
|
||||
}
|
||||
dictionary = new BreakDictionary(module, dictionaryFile);
|
||||
dictionary = new BreakDictionary(dictionaryFile, dictionaryData);
|
||||
}
|
||||
|
||||
private void prepareCategoryFlags(byte[] data) {
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2016, 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
|
||||
@ -38,15 +38,10 @@
|
||||
* Taligent is a registered trademark of Taligent, Inc.
|
||||
*/
|
||||
|
||||
package sun.util.locale.provider;
|
||||
package sun.text;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Module;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedActionException;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.nio.BufferUnderflowException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.text.BreakIterator;
|
||||
import java.text.CharacterIterator;
|
||||
import java.text.StringCharacterIterator;
|
||||
@ -218,7 +213,7 @@ import sun.text.SupplementaryCharacterData;
|
||||
*
|
||||
* @author Richard Gillam
|
||||
*/
|
||||
class RuleBasedBreakIterator extends BreakIterator {
|
||||
public class RuleBasedBreakIterator extends BreakIterator {
|
||||
|
||||
/**
|
||||
* A token used as a character-category value to identify ignore characters
|
||||
@ -249,11 +244,6 @@ class RuleBasedBreakIterator extends BreakIterator {
|
||||
*/
|
||||
static final byte supportedVersion = 1;
|
||||
|
||||
/**
|
||||
* Header size in byte count
|
||||
*/
|
||||
private static final int HEADER_LENGTH = 36;
|
||||
|
||||
/**
|
||||
* An array length of indices for BMP characters
|
||||
*/
|
||||
@ -315,16 +305,26 @@ class RuleBasedBreakIterator extends BreakIterator {
|
||||
//=======================================================================
|
||||
|
||||
/**
|
||||
* Constructs a RuleBasedBreakIterator according to the module and the datafile
|
||||
* provided.
|
||||
* Constructs a RuleBasedBreakIterator using the given rule data.
|
||||
*
|
||||
* @throws MissingResourceException if the rule data is invalid or corrupted
|
||||
*/
|
||||
RuleBasedBreakIterator(Module module, String datafile)
|
||||
throws IOException, MissingResourceException {
|
||||
readTables(module, datafile);
|
||||
public RuleBasedBreakIterator(String ruleFile, byte[] ruleData) {
|
||||
ByteBuffer bb = ByteBuffer.wrap(ruleData);
|
||||
try {
|
||||
validateRuleData(ruleFile, bb);
|
||||
setupTables(ruleFile, bb);
|
||||
} catch (BufferUnderflowException bue) {
|
||||
MissingResourceException e;
|
||||
e = new MissingResourceException("Corrupted rule data file", ruleFile, "");
|
||||
e.initCause(bue);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read datafile. The datafile's format is as follows:
|
||||
* Initializes the fields with the given rule data.
|
||||
* The data format is as follows:
|
||||
* <pre>
|
||||
* BreakIteratorData {
|
||||
* u1 magic[7];
|
||||
@ -370,133 +370,101 @@ class RuleBasedBreakIterator extends BreakIterator {
|
||||
* u1 additionalData[additionalDataLength];
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @throws BufferUnderflowException if the end-of-data is reached before
|
||||
* setting up all the tables
|
||||
*/
|
||||
protected final void readTables(Module module, String datafile)
|
||||
throws IOException, MissingResourceException {
|
||||
|
||||
byte[] buffer = readFile(module, datafile);
|
||||
|
||||
private void setupTables(String ruleFile, ByteBuffer bb) {
|
||||
/* Read header_info. */
|
||||
int stateTableLength = getInt(buffer, 0);
|
||||
int backwardsStateTableLength = getInt(buffer, 4);
|
||||
int endStatesLength = getInt(buffer, 8);
|
||||
int lookaheadStatesLength = getInt(buffer, 12);
|
||||
int BMPdataLength = getInt(buffer, 16);
|
||||
int nonBMPdataLength = getInt(buffer, 20);
|
||||
int additionalDataLength = getInt(buffer, 24);
|
||||
checksum = getLong(buffer, 28);
|
||||
int stateTableLength = bb.getInt();
|
||||
int backwardsStateTableLength = bb.getInt();
|
||||
int endStatesLength = bb.getInt();
|
||||
int lookaheadStatesLength = bb.getInt();
|
||||
int BMPdataLength = bb.getInt();
|
||||
int nonBMPdataLength = bb.getInt();
|
||||
int additionalDataLength = bb.getInt();
|
||||
checksum = bb.getLong();
|
||||
|
||||
/* Read stateTable[numCategories * numRows] */
|
||||
stateTable = new short[stateTableLength];
|
||||
int offset = HEADER_LENGTH;
|
||||
for (int i = 0; i < stateTableLength; i++, offset+=2) {
|
||||
stateTable[i] = getShort(buffer, offset);
|
||||
for (int i = 0; i < stateTableLength; i++) {
|
||||
stateTable[i] = bb.getShort();
|
||||
}
|
||||
|
||||
/* Read backwardsStateTable[numCategories * numRows] */
|
||||
backwardsStateTable = new short[backwardsStateTableLength];
|
||||
for (int i = 0; i < backwardsStateTableLength; i++, offset+=2) {
|
||||
backwardsStateTable[i] = getShort(buffer, offset);
|
||||
for (int i = 0; i < backwardsStateTableLength; i++) {
|
||||
backwardsStateTable[i] = bb.getShort();
|
||||
}
|
||||
|
||||
/* Read endStates[numRows] */
|
||||
endStates = new boolean[endStatesLength];
|
||||
for (int i = 0; i < endStatesLength; i++, offset++) {
|
||||
endStates[i] = buffer[offset] == 1;
|
||||
for (int i = 0; i < endStatesLength; i++) {
|
||||
endStates[i] = bb.get() == 1;
|
||||
}
|
||||
|
||||
/* Read lookaheadStates[numRows] */
|
||||
lookaheadStates = new boolean[lookaheadStatesLength];
|
||||
for (int i = 0; i < lookaheadStatesLength; i++, offset++) {
|
||||
lookaheadStates[i] = buffer[offset] == 1;
|
||||
for (int i = 0; i < lookaheadStatesLength; i++) {
|
||||
lookaheadStates[i] = bb.get() == 1;
|
||||
}
|
||||
|
||||
/* Read a category table and indices for BMP characters. */
|
||||
short[] temp1 = new short[BMP_INDICES_LENGTH]; // BMPindices
|
||||
for (int i = 0; i < BMP_INDICES_LENGTH; i++, offset+=2) {
|
||||
temp1[i] = getShort(buffer, offset);
|
||||
for (int i = 0; i < BMP_INDICES_LENGTH; i++) {
|
||||
temp1[i] = bb.getShort();
|
||||
}
|
||||
byte[] temp2 = new byte[BMPdataLength]; // BMPdata
|
||||
System.arraycopy(buffer, offset, temp2, 0, BMPdataLength);
|
||||
offset += BMPdataLength;
|
||||
bb.get(temp2);
|
||||
charCategoryTable = new CompactByteArray(temp1, temp2);
|
||||
|
||||
/* Read a category table for non-BMP characters. */
|
||||
int[] temp3 = new int[nonBMPdataLength];
|
||||
for (int i = 0; i < nonBMPdataLength; i++, offset+=4) {
|
||||
temp3[i] = getInt(buffer, offset);
|
||||
for (int i = 0; i < nonBMPdataLength; i++) {
|
||||
temp3[i] = bb.getInt();
|
||||
}
|
||||
supplementaryCharCategoryTable = new SupplementaryCharacterData(temp3);
|
||||
|
||||
/* Read additional data */
|
||||
if (additionalDataLength > 0) {
|
||||
additionalData = new byte[additionalDataLength];
|
||||
System.arraycopy(buffer, offset, additionalData, 0, additionalDataLength);
|
||||
bb.get(additionalData);
|
||||
}
|
||||
assert bb.position() == bb.limit();
|
||||
|
||||
/* Set numCategories */
|
||||
numCategories = stateTable.length / endStates.length;
|
||||
}
|
||||
|
||||
protected byte[] readFile(final Module module, final String datafile)
|
||||
throws IOException, MissingResourceException {
|
||||
|
||||
BufferedInputStream is;
|
||||
try {
|
||||
PrivilegedExceptionAction<BufferedInputStream> pa = () -> {
|
||||
String pathName = "jdk.localedata".equals(module.getName()) ?
|
||||
"sun/text/resources/ext/" :
|
||||
"sun/text/resources/";
|
||||
InputStream in = module.getResourceAsStream(pathName + datafile);
|
||||
if (in == null) {
|
||||
// Try to load the file with "java.base" module instance. Assumption
|
||||
// here is that the fall back data files to be read should reside in
|
||||
// java.base.
|
||||
in = RuleBasedBreakIterator.class.getModule().getResourceAsStream("sun/text/resources/" + datafile);
|
||||
}
|
||||
|
||||
return new BufferedInputStream(in);
|
||||
};
|
||||
is = AccessController.doPrivileged(pa);
|
||||
} catch (PrivilegedActionException e) {
|
||||
throw new InternalError(e.toString(), e);
|
||||
}
|
||||
|
||||
int offset = 0;
|
||||
|
||||
/* First, read magic, version, and header_info. */
|
||||
int len = LABEL_LENGTH + 5;
|
||||
byte[] buf = new byte[len];
|
||||
if (is.read(buf) != len) {
|
||||
throw new MissingResourceException("Wrong header length",
|
||||
datafile, "");
|
||||
}
|
||||
|
||||
/* Validate the magic number. */
|
||||
for (int i = 0; i < LABEL_LENGTH; i++, offset++) {
|
||||
if (buf[offset] != LABEL[offset]) {
|
||||
/**
|
||||
* Validates the magic number, version, and the length of the given data.
|
||||
*
|
||||
* @throws BufferUnderflowException if the end-of-data is reached while
|
||||
* validating data
|
||||
* @throws MissingResourceException if valification failed
|
||||
*/
|
||||
void validateRuleData(String ruleFile, ByteBuffer bb) {
|
||||
/* Verify the magic number. */
|
||||
for (int i = 0; i < LABEL_LENGTH; i++) {
|
||||
if (bb.get() != LABEL[i]) {
|
||||
throw new MissingResourceException("Wrong magic number",
|
||||
datafile, "");
|
||||
ruleFile, "");
|
||||
}
|
||||
}
|
||||
|
||||
/* Validate the version number. */
|
||||
if (buf[offset] != supportedVersion) {
|
||||
throw new MissingResourceException("Unsupported version(" + buf[offset] + ")",
|
||||
datafile, "");
|
||||
/* Verify the version number. */
|
||||
byte version = bb.get();
|
||||
if (version != supportedVersion) {
|
||||
throw new MissingResourceException("Unsupported version(" + version + ")",
|
||||
ruleFile, "");
|
||||
}
|
||||
|
||||
/* Read data: totalDataSize + 8(for checksum) */
|
||||
len = getInt(buf, ++offset);
|
||||
buf = new byte[len];
|
||||
if (is.read(buf) != len) {
|
||||
// Check the length of the rest of data
|
||||
int len = bb.getInt();
|
||||
if (bb.position() + len != bb.limit()) {
|
||||
throw new MissingResourceException("Wrong data length",
|
||||
datafile, "");
|
||||
ruleFile, "");
|
||||
}
|
||||
|
||||
is.close();
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
byte[] getAdditionalData() {
|
||||
@ -1061,28 +1029,6 @@ class RuleBasedBreakIterator extends BreakIterator {
|
||||
return backwardsStateTable[state * numCategories + category];
|
||||
}
|
||||
|
||||
static long getLong(byte[] buf, int offset) {
|
||||
long num = buf[offset]&0xFF;
|
||||
for (int i = 1; i < 8; i++) {
|
||||
num = num<<8 | (buf[offset+i]&0xFF);
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
static int getInt(byte[] buf, int offset) {
|
||||
int num = buf[offset]&0xFF;
|
||||
for (int i = 1; i < 4; i++) {
|
||||
num = num<<8 | (buf[offset+i]&0xFF);
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
static short getShort(byte[] buf, int offset) {
|
||||
short num = (short)(buf[offset]&0xFF);
|
||||
num = (short)(num<<8 | (buf[offset+1]&0xFF));
|
||||
return num;
|
||||
}
|
||||
|
||||
/*
|
||||
* This class exists to work around a bug in incorrect implementations
|
||||
* of CharacterIterator, which incorrectly handle setIndex(endIndex).
|
||||
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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 sun.text.resources;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
import sun.util.resources.BreakIteratorResourceBundle;
|
||||
|
||||
public class BreakIteratorResources extends BreakIteratorResourceBundle {
|
||||
@Override
|
||||
protected ResourceBundle getBreakIteratorInfo() {
|
||||
return new BreakIteratorInfo();
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2016, 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
|
||||
@ -32,6 +32,8 @@ import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import sun.text.DictionaryBasedBreakIterator;
|
||||
import sun.text.RuleBasedBreakIterator;
|
||||
|
||||
/**
|
||||
* Concrete implementation of the {@link java.text.spi.BreakIteratorProvider
|
||||
@ -153,29 +155,31 @@ public class BreakIteratorProviderImpl extends BreakIteratorProvider
|
||||
}
|
||||
|
||||
private BreakIterator getBreakInstance(Locale locale,
|
||||
int type,
|
||||
String dataName,
|
||||
String dictionaryName) {
|
||||
int type,
|
||||
String ruleName,
|
||||
String dictionaryName) {
|
||||
Objects.requireNonNull(locale);
|
||||
|
||||
LocaleResources lr = LocaleProviderAdapter.forJRE().getLocaleResources(locale);
|
||||
String[] classNames = (String[]) lr.getBreakIteratorInfo("BreakIteratorClasses");
|
||||
String dataFile = (String) lr.getBreakIteratorInfo(dataName);
|
||||
String ruleFile = (String) lr.getBreakIteratorInfo(ruleName);
|
||||
byte[] ruleData = lr.getBreakIteratorResources(ruleName);
|
||||
|
||||
try {
|
||||
switch (classNames[type]) {
|
||||
case "RuleBasedBreakIterator":
|
||||
return new RuleBasedBreakIterator(
|
||||
lr.getBreakIteratorDataModule(), dataFile);
|
||||
return new RuleBasedBreakIterator(ruleFile, ruleData);
|
||||
|
||||
case "DictionaryBasedBreakIterator":
|
||||
String dictionaryFile = (String) lr.getBreakIteratorInfo(dictionaryName);
|
||||
return new DictionaryBasedBreakIterator(
|
||||
lr.getBreakIteratorDataModule(), dataFile, dictionaryFile);
|
||||
byte[] dictionaryData = lr.getBreakIteratorResources(dictionaryName);
|
||||
return new DictionaryBasedBreakIterator(ruleFile, ruleData,
|
||||
dictionaryFile, dictionaryData);
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid break iterator class \"" +
|
||||
classNames[type] + "\"");
|
||||
}
|
||||
} catch (IOException | MissingResourceException | IllegalArgumentException e) {
|
||||
} catch (MissingResourceException | IllegalArgumentException e) {
|
||||
throw new InternalError(e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2016, 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
|
||||
@ -42,7 +42,6 @@ package sun.util.locale.provider;
|
||||
|
||||
import java.lang.ref.ReferenceQueue;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.lang.reflect.Module;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.LinkedHashSet;
|
||||
@ -113,13 +112,14 @@ public class LocaleResources {
|
||||
if (data == null || ((biInfo = data.get()) == null)) {
|
||||
biInfo = localeData.getBreakIteratorInfo(locale).getObject(key);
|
||||
cache.put(cacheKey, new ResourceReference(cacheKey, biInfo, referenceQueue));
|
||||
}
|
||||
}
|
||||
|
||||
return biInfo;
|
||||
}
|
||||
|
||||
Module getBreakIteratorDataModule() {
|
||||
return localeData.getBreakIteratorInfo(locale).getClass().getModule();
|
||||
@SuppressWarnings("unchecked")
|
||||
byte[] getBreakIteratorResources(String key) {
|
||||
return (byte[]) localeData.getBreakIteratorResources(locale).getObject(key);
|
||||
}
|
||||
|
||||
int getCalendarData(String key) {
|
||||
|
||||
@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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 sun.util.resources;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedActionException;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* BreakIteratorResourceBundle is an abstract class for loading BreakIterator
|
||||
* data (rules or dictionary) from each module. An implementation class must
|
||||
* implement getBreakIteratorInfo() that returns an instance of the
|
||||
* corresponding BreakIteratorInfo (basename). The data name is taken from the
|
||||
* BreakIteratorInfo instance.
|
||||
*
|
||||
* <p>For example, if the given key is "WordDictionary" and Locale is "th", the
|
||||
* data name is taken from a BreakIteratorInfo_th and the key's value is
|
||||
* "thai_dict". Its data thai_dict is loaded from the Module of the
|
||||
* implementation class of this class.
|
||||
*/
|
||||
|
||||
public abstract class BreakIteratorResourceBundle extends ResourceBundle {
|
||||
// If any keys that are not for data names are added to BreakIteratorInfo*,
|
||||
// those keys must be added to NON_DATA_KEYS.
|
||||
private static final Set<String> NON_DATA_KEYS = Set.of("BreakIteratorClasses");
|
||||
|
||||
private volatile Set<String> keys;
|
||||
|
||||
/**
|
||||
* Returns an instance of the corresponding {@code BreakIteratorInfo} (basename).
|
||||
* The instance shouldn't have its parent.
|
||||
*/
|
||||
protected abstract ResourceBundle getBreakIteratorInfo();
|
||||
|
||||
@Override
|
||||
protected Object handleGetObject(String key) {
|
||||
if (NON_DATA_KEYS.contains(key)) {
|
||||
return null;
|
||||
}
|
||||
ResourceBundle info = getBreakIteratorInfo();
|
||||
if (!info.containsKey(key)) {
|
||||
return null;
|
||||
}
|
||||
String path = getClass().getPackage().getName().replace('.', '/')
|
||||
+ '/' + info.getString(key);
|
||||
byte[] data;
|
||||
try (InputStream is = getResourceAsStream(path)) {
|
||||
data = is.readAllBytes();
|
||||
} catch (Exception e) {
|
||||
throw new InternalError("Can't load " + path, e);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private InputStream getResourceAsStream(String path) throws Exception {
|
||||
PrivilegedExceptionAction<InputStream> pa;
|
||||
pa = () -> getClass().getModule().getResourceAsStream(path);
|
||||
InputStream is;
|
||||
try {
|
||||
is = AccessController.doPrivileged(pa);
|
||||
} catch (PrivilegedActionException e) {
|
||||
throw e.getException();
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<String> getKeys() {
|
||||
return Collections.enumeration(keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<String> handleKeySet() {
|
||||
if (keys == null) {
|
||||
ResourceBundle info = getBreakIteratorInfo();
|
||||
Set<String> k = info.keySet();
|
||||
k.removeAll(NON_DATA_KEYS);
|
||||
synchronized (this) {
|
||||
if (keys == null) {
|
||||
keys = k;
|
||||
}
|
||||
}
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
}
|
||||
@ -122,6 +122,14 @@ public class LocaleData {
|
||||
return getBundle(type.getTextResourcesPackage() + ".BreakIteratorInfo", locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a break iterator resources resource bundle, using
|
||||
* privileges to allow accessing a sun.* package.
|
||||
*/
|
||||
public ResourceBundle getBreakIteratorResources(Locale locale) {
|
||||
return getBundle(type.getTextResourcesPackage() + ".BreakIteratorResources", locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a collation data resource bundle, using privileges
|
||||
* to allow accessing a sun.* package.
|
||||
|
||||
@ -32,8 +32,22 @@ grant codeBase "jrt:/java.smartcardio" {
|
||||
permission javax.smartcardio.CardPermission "*", "*";
|
||||
permission java.lang.RuntimePermission "loadLibrary.j2pcsc";
|
||||
permission java.lang.RuntimePermission
|
||||
"accessClassInPackage.sun.security.*";
|
||||
permission java.util.PropertyPermission "*", "read";
|
||||
"accessClassInPackage.sun.security.jca";
|
||||
permission java.lang.RuntimePermission
|
||||
"accessClassInPackage.sun.security.util";
|
||||
permission java.util.PropertyPermission
|
||||
"javax.smartcardio.TerminalFactory.DefaultType", "read";
|
||||
permission java.util.PropertyPermission "os.name", "read";
|
||||
permission java.util.PropertyPermission "os.arch", "read";
|
||||
permission java.util.PropertyPermission "sun.arch.data.model", "read";
|
||||
permission java.util.PropertyPermission
|
||||
"sun.security.smartcardio.library", "read";
|
||||
permission java.util.PropertyPermission
|
||||
"sun.security.smartcardio.t0GetResponse", "read";
|
||||
permission java.util.PropertyPermission
|
||||
"sun.security.smartcardio.t1GetResponse", "read";
|
||||
permission java.util.PropertyPermission
|
||||
"sun.security.smartcardio.t1StripLe", "read";
|
||||
// needed for looking up native PC/SC library
|
||||
permission java.io.FilePermission "<<ALL FILES>>","read";
|
||||
permission java.security.SecurityPermission "putProviderProperty.SunPCSC";
|
||||
|
||||
@ -51,16 +51,6 @@ static const char* const_progname = PROGNAME;
|
||||
static char* const_progname = NULL;
|
||||
#endif
|
||||
static const char* const_jargs[] = JAVA_ARGS;
|
||||
/*
|
||||
* ApplicationHome is prepended to each of these entries; the resulting
|
||||
* strings are concatenated (separated by PATH_SEPARATOR) and used as the
|
||||
* value of -cp option to the launcher.
|
||||
*/
|
||||
#ifndef APP_CLASSPATH
|
||||
static const char* const_appclasspath[] = { NULL };
|
||||
#else
|
||||
static const char* const_appclasspath[] = APP_CLASSPATH;
|
||||
#endif /* APP_CLASSPATH */
|
||||
#else /* !JAVA_ARGS */
|
||||
#define HAS_JAVA_ARGS JNI_FALSE
|
||||
static const char* const_progname = "java";
|
||||
|
||||
@ -83,7 +83,7 @@ char **__initenv;
|
||||
int WINAPI
|
||||
WinMain(HINSTANCE inst, HINSTANCE previnst, LPSTR cmdline, int cmdshow)
|
||||
{
|
||||
int margc, appclassc;
|
||||
int margc;
|
||||
char** margv;
|
||||
const jboolean const_javaw = JNI_TRUE;
|
||||
|
||||
@ -93,7 +93,7 @@ WinMain(HINSTANCE inst, HINSTANCE previnst, LPSTR cmdline, int cmdshow)
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int margc, appclassc;
|
||||
int margc;
|
||||
char** margv;
|
||||
const jboolean const_javaw = JNI_FALSE;
|
||||
#endif /* JAVAW */
|
||||
@ -148,14 +148,9 @@ main(int argc, char **argv)
|
||||
margv = args->elements;
|
||||
}
|
||||
#endif /* WIN32 */
|
||||
if (const_appclasspath[0] == NULL) {
|
||||
appclassc = 0;
|
||||
} else {
|
||||
appclassc = sizeof(const_appclasspath) / sizeof(char *);
|
||||
}
|
||||
return JLI_Launch(margc, margv,
|
||||
sizeof(const_jargs) / sizeof(char *), const_jargs,
|
||||
appclassc, const_appclasspath,
|
||||
0, NULL,
|
||||
VERSION_STRING,
|
||||
DOT_VERSION,
|
||||
(const_progname != NULL) ? const_progname : *margv,
|
||||
|
||||
@ -1664,19 +1664,21 @@ AddApplicationOptions(int cpathc, const char **cpathv)
|
||||
AddOption(apphome, NULL);
|
||||
|
||||
/* How big is the application's classpath? */
|
||||
size = 40; /* 40: "-Djava.class.path=" */
|
||||
for (i = 0; i < cpathc; i++) {
|
||||
size += (int)JLI_StrLen(home) + (int)JLI_StrLen(cpathv[i]) + 1; /* 1: separator */
|
||||
if (cpathc > 0) {
|
||||
size = 40; /* 40: "-Djava.class.path=" */
|
||||
for (i = 0; i < cpathc; i++) {
|
||||
size += (int)JLI_StrLen(home) + (int)JLI_StrLen(cpathv[i]) + 1; /* 1: separator */
|
||||
}
|
||||
appcp = (char *)JLI_MemAlloc(size + 1);
|
||||
JLI_StrCpy(appcp, "-Djava.class.path=");
|
||||
for (i = 0; i < cpathc; i++) {
|
||||
JLI_StrCat(appcp, home); /* c:\program files\myapp */
|
||||
JLI_StrCat(appcp, cpathv[i]); /* \lib\myapp.jar */
|
||||
JLI_StrCat(appcp, separator); /* ; */
|
||||
}
|
||||
appcp[JLI_StrLen(appcp)-1] = '\0'; /* remove trailing path separator */
|
||||
AddOption(appcp, NULL);
|
||||
}
|
||||
appcp = (char *)JLI_MemAlloc(size + 1);
|
||||
JLI_StrCpy(appcp, "-Djava.class.path=");
|
||||
for (i = 0; i < cpathc; i++) {
|
||||
JLI_StrCat(appcp, home); /* c:\program files\myapp */
|
||||
JLI_StrCat(appcp, cpathv[i]); /* \lib\myapp.jar */
|
||||
JLI_StrCat(appcp, separator); /* ; */
|
||||
}
|
||||
appcp[JLI_StrLen(appcp)-1] = '\0'; /* remove trailing path separator */
|
||||
AddOption(appcp, NULL);
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
|
||||
@ -23,20 +23,19 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include "jni.h"
|
||||
#include "jvm.h"
|
||||
#include "jni_util.h"
|
||||
#include "net_util.h"
|
||||
|
||||
int IPv6_supported() ;
|
||||
int reuseport_supported() ;
|
||||
#include "java_net_InetAddress.h"
|
||||
|
||||
int IPv6_supported();
|
||||
int reuseport_supported();
|
||||
|
||||
static int IPv6_available;
|
||||
static int REUSEPORT_available;
|
||||
|
||||
JNIEXPORT jint JNICALL ipv6_available()
|
||||
{
|
||||
return IPv6_available ;
|
||||
return IPv6_available;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL reuseport_available()
|
||||
@ -206,11 +205,7 @@ NET_SockaddrToInetAddress(JNIEnv *env, struct sockaddr *him, int *port) {
|
||||
jobject iaObj;
|
||||
#ifdef AF_INET6
|
||||
if (him->sa_family == AF_INET6) {
|
||||
#ifdef WIN32
|
||||
struct SOCKADDR_IN6 *him6 = (struct SOCKADDR_IN6 *)him;
|
||||
#else
|
||||
struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)him;
|
||||
#endif
|
||||
jbyte *caddr = (jbyte *)&(him6->sin6_addr);
|
||||
if (NET_IsIPv4Mapped(caddr)) {
|
||||
int address;
|
||||
@ -218,7 +213,7 @@ NET_SockaddrToInetAddress(JNIEnv *env, struct sockaddr *him, int *port) {
|
||||
CHECK_NULL_RETURN(iaObj, NULL);
|
||||
address = NET_IPv4MappedToIPv4(caddr);
|
||||
setInetAddress_addr(env, iaObj, address);
|
||||
setInetAddress_family(env, iaObj, IPv4);
|
||||
setInetAddress_family(env, iaObj, java_net_InetAddress_IPv4);
|
||||
} else {
|
||||
jint scope;
|
||||
jboolean ret;
|
||||
@ -227,7 +222,7 @@ NET_SockaddrToInetAddress(JNIEnv *env, struct sockaddr *him, int *port) {
|
||||
ret = setInet6Address_ipaddress(env, iaObj, (char *)&(him6->sin6_addr));
|
||||
if (ret == JNI_FALSE)
|
||||
return NULL;
|
||||
setInetAddress_family(env, iaObj, IPv6);
|
||||
setInetAddress_family(env, iaObj, java_net_InetAddress_IPv6);
|
||||
scope = getScopeID(him);
|
||||
setInet6Address_scopeid(env, iaObj, scope);
|
||||
}
|
||||
@ -238,7 +233,7 @@ NET_SockaddrToInetAddress(JNIEnv *env, struct sockaddr *him, int *port) {
|
||||
struct sockaddr_in *him4 = (struct sockaddr_in *)him;
|
||||
iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
|
||||
CHECK_NULL_RETURN(iaObj, NULL);
|
||||
setInetAddress_family(env, iaObj, IPv4);
|
||||
setInetAddress_family(env, iaObj, java_net_InetAddress_IPv4);
|
||||
setInetAddress_addr(env, iaObj, ntohl(him4->sin_addr.s_addr));
|
||||
*port = ntohs(him4->sin_port);
|
||||
}
|
||||
@ -251,13 +246,10 @@ NET_SockaddrEqualsInetAddress(JNIEnv *env, struct sockaddr *him, jobject iaObj)
|
||||
jint family = AF_INET;
|
||||
|
||||
#ifdef AF_INET6
|
||||
family = getInetAddress_family(env, iaObj) == IPv4? AF_INET : AF_INET6;
|
||||
family = getInetAddress_family(env, iaObj) == java_net_InetAddress_IPv4 ?
|
||||
AF_INET : AF_INET6;
|
||||
if (him->sa_family == AF_INET6) {
|
||||
#ifdef WIN32
|
||||
struct SOCKADDR_IN6 *him6 = (struct SOCKADDR_IN6 *)him;
|
||||
#else
|
||||
struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)him;
|
||||
#endif
|
||||
jbyte *caddrNew = (jbyte *)&(him6->sin6_addr);
|
||||
if (NET_IsIPv4Mapped(caddrNew)) {
|
||||
int addrNew;
|
||||
|
||||
@ -36,12 +36,6 @@
|
||||
|
||||
#define MAX_PACKET_LEN 65536
|
||||
|
||||
#define IPv4 1
|
||||
#define IPv6 2
|
||||
|
||||
#define NET_ERROR(env, ex, msg) \
|
||||
{ if (!(*env)->ExceptionOccurred(env)) JNU_ThrowByName(env, ex, msg); }
|
||||
|
||||
#define NET_WAIT_READ 0x01
|
||||
#define NET_WAIT_WRITE 0x02
|
||||
#define NET_WAIT_CONNECT 0x04
|
||||
@ -127,45 +121,43 @@ JNIEXPORT void JNICALL Java_java_net_Inet6Address_init(JNIEnv *env, jclass cls);
|
||||
JNIEXPORT void JNICALL Java_java_net_NetworkInterface_init(JNIEnv *env, jclass cls);
|
||||
|
||||
JNIEXPORT void JNICALL NET_ThrowNew(JNIEnv *env, int errorNum, char *msg);
|
||||
|
||||
int NET_GetError();
|
||||
|
||||
void NET_ThrowCurrent(JNIEnv *env, char *msg);
|
||||
|
||||
jfieldID NET_GetFileDescriptorID(JNIEnv *env);
|
||||
|
||||
JNIEXPORT jint JNICALL ipv6_available() ;
|
||||
JNIEXPORT jint JNICALL ipv6_available();
|
||||
|
||||
JNIEXPORT jint JNICALL reuseport_available() ;
|
||||
JNIEXPORT jint JNICALL reuseport_available();
|
||||
|
||||
JNIEXPORT int JNICALL
|
||||
NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr *him, int *len, jboolean v4MappedAddress);
|
||||
NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port,
|
||||
struct sockaddr *him, int *len,
|
||||
jboolean v4MappedAddress);
|
||||
|
||||
JNIEXPORT jobject JNICALL
|
||||
NET_SockaddrToInetAddress(JNIEnv *env, struct sockaddr *him, int *port);
|
||||
|
||||
void platformInit();
|
||||
|
||||
void parseExclusiveBindProperty(JNIEnv *env);
|
||||
|
||||
void
|
||||
NET_SetTrafficClass(struct sockaddr *him, int trafficClass);
|
||||
void NET_SetTrafficClass(struct sockaddr *him, int trafficClass);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
NET_GetPortFromSockaddr(struct sockaddr *him);
|
||||
JNIEXPORT jint JNICALL NET_GetPortFromSockaddr(struct sockaddr *him);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
NET_SockaddrEqualsInetAddress(JNIEnv *env,struct sockaddr *him, jobject iaObj);
|
||||
|
||||
int
|
||||
NET_IsIPv4Mapped(jbyte* caddr);
|
||||
int NET_IsIPv4Mapped(jbyte* caddr);
|
||||
|
||||
int
|
||||
NET_IPv4MappedToIPv4(jbyte* caddr);
|
||||
int NET_IPv4MappedToIPv4(jbyte* caddr);
|
||||
|
||||
int
|
||||
NET_IsEqual(jbyte* caddr1, jbyte* caddr2);
|
||||
int NET_IsEqual(jbyte* caddr1, jbyte* caddr2);
|
||||
|
||||
int
|
||||
NET_IsZeroAddr(jbyte* caddr);
|
||||
int NET_IsZeroAddr(jbyte* caddr);
|
||||
|
||||
/* Socket operations
|
||||
*
|
||||
@ -191,9 +183,9 @@ NET_MapSocketOptionV6(jint cmd, int *level, int *optname);
|
||||
JNIEXPORT jint JNICALL
|
||||
NET_EnableFastTcpLoopback(int fd);
|
||||
|
||||
int getScopeID (struct sockaddr *);
|
||||
int getScopeID(struct sockaddr *);
|
||||
|
||||
int cmpScopeID (unsigned int, struct sockaddr *);
|
||||
int cmpScopeID(unsigned int, struct sockaddr *);
|
||||
|
||||
unsigned short in_cksum(unsigned short *addr, int len);
|
||||
|
||||
|
||||
34
jdk/src/java.base/unix/conf/s390x/jvm.cfg
Normal file
34
jdk/src/java.base/unix/conf/s390x/jvm.cfg
Normal file
@ -0,0 +1,34 @@
|
||||
# Copyright (c) 2011, 2016, 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.
|
||||
#
|
||||
# List of JVMs that can be used as an option to java, javac, etc.
|
||||
# Order is important -- first in this list is the default JVM.
|
||||
# NOTE that this both this file and its format are UNSUPPORTED and
|
||||
# WILL GO AWAY in a future release.
|
||||
#
|
||||
# You may also select a JVM in an arbitrary location with the
|
||||
# "-XXaltjvm=<jvm_dir>" option, but that too is unsupported
|
||||
# and may not be available in a future release.
|
||||
#
|
||||
-server KNOWN
|
||||
-client IGNORE
|
||||
@ -22,27 +22,17 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/ip_icmp.h>
|
||||
#include <netdb.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#ifdef _ALLBSD_SOURCE
|
||||
#include <unistd.h>
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#include "jvm.h"
|
||||
#include "jni_util.h"
|
||||
#include "net_util.h"
|
||||
|
||||
#include "java_net_Inet4AddressImpl.h"
|
||||
@ -293,13 +283,12 @@ Java_java_net_Inet4AddressImpl_getHostByAddr(JNIEnv *env, jobject this,
|
||||
addr |= ((caddr[2] <<8) & 0xff00);
|
||||
addr |= (caddr[3] & 0xff);
|
||||
memset((char *) &him4, 0, sizeof(him4));
|
||||
him4.sin_addr.s_addr = (uint32_t) htonl(addr);
|
||||
him4.sin_addr.s_addr = htonl(addr);
|
||||
him4.sin_family = AF_INET;
|
||||
sa = (struct sockaddr *) &him4;
|
||||
len = sizeof(him4);
|
||||
|
||||
error = getnameinfo(sa, len, host, NI_MAXHOST, NULL, 0,
|
||||
NI_NAMEREQD);
|
||||
error = getnameinfo(sa, len, host, NI_MAXHOST, NULL, 0, NI_NAMEREQD);
|
||||
|
||||
if (!error) {
|
||||
ret = (*env)->NewStringUTF(env, host);
|
||||
@ -443,7 +432,7 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
|
||||
|
||||
if (!skip) {
|
||||
struct addrinfo *next
|
||||
= (struct addrinfo*) malloc(sizeof(struct addrinfo));
|
||||
= (struct addrinfo *)malloc(sizeof(struct addrinfo));
|
||||
if (!next) {
|
||||
JNU_ThrowOutOfMemoryError(env, "Native heap allocation failed");
|
||||
ret = NULL;
|
||||
@ -528,13 +517,12 @@ Java_java_net_Inet4AddressImpl_getHostByAddr(JNIEnv *env, jobject this,
|
||||
addr |= ((caddr[2] <<8) & 0xff00);
|
||||
addr |= (caddr[3] & 0xff);
|
||||
memset((void *) &him4, 0, sizeof(him4));
|
||||
him4.sin_addr.s_addr = (uint32_t) htonl(addr);
|
||||
him4.sin_addr.s_addr = htonl(addr);
|
||||
him4.sin_family = AF_INET;
|
||||
sa = (struct sockaddr *) &him4;
|
||||
len = sizeof(him4);
|
||||
|
||||
error = getnameinfo(sa, len, host, NI_MAXHOST, NULL, 0,
|
||||
NI_NAMEREQD);
|
||||
error = getnameinfo(sa, len, host, NI_MAXHOST, NULL, 0, NI_NAMEREQD);
|
||||
|
||||
if (!error) {
|
||||
ret = (*env)->NewStringUTF(env, host);
|
||||
|
||||
@ -22,29 +22,21 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#ifdef MACOSX
|
||||
#include <netinet/icmp6.h>
|
||||
|
||||
#if defined(_ALLBSD_SOURCE)
|
||||
#include <ifaddrs.h>
|
||||
#include <net/if.h>
|
||||
#include <unistd.h> /* gethostname */
|
||||
#endif
|
||||
|
||||
#include "jvm.h"
|
||||
#include "jni_util.h"
|
||||
#include "net_util.h"
|
||||
#ifndef IPV6_DEFS_H
|
||||
#include <netinet/icmp6.h>
|
||||
#endif
|
||||
|
||||
#include "java_net_Inet4AddressImpl.h"
|
||||
#include "java_net_Inet6AddressImpl.h"
|
||||
@ -504,24 +496,23 @@ Java_java_net_Inet6AddressImpl_getHostByAddr(JNIEnv *env, jobject this,
|
||||
addr |= ((caddr[2] <<8) & 0xff00);
|
||||
addr |= (caddr[3] & 0xff);
|
||||
memset((void *) &him4, 0, sizeof(him4));
|
||||
him4.sin_addr.s_addr = (uint32_t) htonl(addr);
|
||||
him4.sin_addr.s_addr = htonl(addr);
|
||||
him4.sin_family = AF_INET;
|
||||
sa = (struct sockaddr *) &him4;
|
||||
sa = (struct sockaddr *)&him4;
|
||||
len = sizeof(him4);
|
||||
} else {
|
||||
/*
|
||||
* For IPv6 address construct a sockaddr_in6 structure.
|
||||
*/
|
||||
(*env)->GetByteArrayRegion(env, addrArray, 0, 16, caddr);
|
||||
memset((void *) &him6, 0, sizeof(him6));
|
||||
memcpy((void *)&(him6.sin6_addr), caddr, sizeof(struct in6_addr) );
|
||||
memset((void *)&him6, 0, sizeof(him6));
|
||||
memcpy((void *)&(him6.sin6_addr), caddr, sizeof(struct in6_addr));
|
||||
him6.sin6_family = AF_INET6;
|
||||
sa = (struct sockaddr *) &him6 ;
|
||||
len = sizeof(him6) ;
|
||||
sa = (struct sockaddr *)&him6;
|
||||
len = sizeof(him6);
|
||||
}
|
||||
|
||||
error = getnameinfo(sa, len, host, NI_MAXHOST, NULL, 0,
|
||||
NI_NAMEREQD);
|
||||
error = getnameinfo(sa, len, host, NI_MAXHOST, NULL, 0, NI_NAMEREQD);
|
||||
|
||||
if (!error) {
|
||||
ret = (*env)->NewStringUTF(env, host);
|
||||
|
||||
@ -22,55 +22,36 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <strings.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <errno.h>
|
||||
#include <net/if.h>
|
||||
#include <net/if_arp.h>
|
||||
|
||||
#if defined(__solaris__)
|
||||
#include <sys/dlpi.h>
|
||||
#include <fcntl.h>
|
||||
#include <stropts.h>
|
||||
#include <sys/sockio.h>
|
||||
#endif
|
||||
|
||||
#if defined(__linux__)
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#if defined(_AIX)
|
||||
#include <sys/ioctl.h>
|
||||
#include <netinet/in6_var.h>
|
||||
#include <sys/ndd_var.h>
|
||||
#include <sys/kinfo.h>
|
||||
#endif
|
||||
|
||||
#if defined(_ALLBSD_SOURCE)
|
||||
#include <sys/param.h>
|
||||
#include <sys/ioctl.h>
|
||||
#if defined(__solaris__)
|
||||
#include <stropts.h>
|
||||
#include <sys/dlpi.h>
|
||||
#include <sys/sockio.h>
|
||||
#if defined(__APPLE__)
|
||||
#include <net/ethernet.h>
|
||||
#include <net/if_var.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <netinet/in_var.h>
|
||||
#include <ifaddrs.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "jvm.h"
|
||||
#include "jni_util.h"
|
||||
#if defined(_ALLBSD_SOURCE)
|
||||
#include <net/ethernet.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <ifaddrs.h>
|
||||
#endif
|
||||
|
||||
#include "net_util.h"
|
||||
|
||||
#include "java_net_InetAddress.h"
|
||||
|
||||
#if defined(__linux__)
|
||||
#define _PATH_PROCNET_IFINET6 "/proc/net/if_inet6"
|
||||
#elif defined(__solaris__)
|
||||
@ -332,7 +313,7 @@ JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByInetAddress0
|
||||
{
|
||||
netif *ifs, *curr;
|
||||
#if defined(AF_INET6)
|
||||
int family = (getInetAddress_family(env, iaObj) == IPv4) ? AF_INET : AF_INET6;
|
||||
int family = (getInetAddress_family(env, iaObj) == java_net_InetAddress_IPv4) ? AF_INET : AF_INET6;
|
||||
#else
|
||||
int family = AF_INET;
|
||||
#endif
|
||||
|
||||
@ -22,29 +22,23 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#ifdef __solaris__
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <stropts.h>
|
||||
#if defined(__solaris__)
|
||||
#include <sys/filio.h>
|
||||
#endif
|
||||
|
||||
#include "net_util.h"
|
||||
|
||||
#include "java_net_PlainDatagramSocketImpl.h"
|
||||
#include "java_net_InetAddress.h"
|
||||
#include "java_net_NetworkInterface.h"
|
||||
#include "java_net_SocketOptions.h"
|
||||
|
||||
#ifndef BSD_COMP
|
||||
#define BSD_COMP
|
||||
#endif
|
||||
#endif
|
||||
#ifdef __linux__
|
||||
#include <unistd.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <netinet/ip.h>
|
||||
|
||||
#define IPV6_MULTICAST_IF 17
|
||||
#ifndef SO_BSDCOMPAT
|
||||
#define SO_BSDCOMPAT 14
|
||||
@ -58,7 +52,11 @@
|
||||
#endif
|
||||
#endif // __linux__
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#ifdef __solaris__
|
||||
#ifndef BSD_COMP
|
||||
#define BSD_COMP
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef IPTOS_TOS_MASK
|
||||
#define IPTOS_TOS_MASK 0x1e
|
||||
@ -67,12 +65,6 @@
|
||||
#define IPTOS_PREC_MASK 0xe0
|
||||
#endif
|
||||
|
||||
#include "jvm.h"
|
||||
#include "jni_util.h"
|
||||
#include "net_util.h"
|
||||
#include "java_net_SocketOptions.h"
|
||||
#include "java_net_PlainDatagramSocketImpl.h"
|
||||
#include "java_net_NetworkInterface.h"
|
||||
/************************************************************************
|
||||
* PlainDatagramSocketImpl
|
||||
*/
|
||||
@ -151,9 +143,6 @@ static int getFD(JNIEnv *env, jobject this) {
|
||||
JNIEXPORT void JNICALL
|
||||
Java_java_net_PlainDatagramSocketImpl_init(JNIEnv *env, jclass cls) {
|
||||
|
||||
#ifdef __linux__
|
||||
struct utsname sysinfo;
|
||||
#endif
|
||||
pdsi_fdID = (*env)->GetFieldID(env, cls, "fd",
|
||||
"Ljava/io/FileDescriptor;");
|
||||
CHECK_NULL(pdsi_fdID);
|
||||
@ -550,7 +539,8 @@ Java_java_net_PlainDatagramSocketImpl_peek(JNIEnv *env, jobject this,
|
||||
|
||||
iaObj = NET_SockaddrToInetAddress(env, &rmtaddr.sa, &port);
|
||||
#ifdef AF_INET6
|
||||
family = getInetAddress_family(env, iaObj) == IPv4? AF_INET : AF_INET6;
|
||||
family = getInetAddress_family(env, iaObj) == java_net_InetAddress_IPv4 ?
|
||||
AF_INET : AF_INET6;
|
||||
#else
|
||||
family = AF_INET;
|
||||
#endif
|
||||
@ -1071,7 +1061,7 @@ static void mcast_set_if_by_if_v4(JNIEnv *env, jobject this, int fd, jobject val
|
||||
*/
|
||||
for (i = 0; i < len; i++) {
|
||||
addr = (*env)->GetObjectArrayElement(env, addrArray, i);
|
||||
if (getInetAddress_family(env, addr) == IPv4) {
|
||||
if (getInetAddress_family(env, addr) == java_net_InetAddress_IPv4) {
|
||||
in.s_addr = htonl(getInetAddress_addr(env, addr));
|
||||
break;
|
||||
}
|
||||
@ -1970,7 +1960,7 @@ static void mcast_join_leave(JNIEnv *env, jobject this,
|
||||
ipv6_join_leave = ipv6_available();
|
||||
|
||||
#ifdef __linux__
|
||||
if (getInetAddress_family(env, iaObj) == IPv4) {
|
||||
if (getInetAddress_family(env, iaObj) == java_net_InetAddress_IPv4) {
|
||||
ipv6_join_leave = JNI_FALSE;
|
||||
}
|
||||
#endif
|
||||
@ -2162,7 +2152,8 @@ static void mcast_join_leave(JNIEnv *env, jobject this,
|
||||
jbyte caddr[16];
|
||||
jint family;
|
||||
jint address;
|
||||
family = getInetAddress_family(env, iaObj) == IPv4? AF_INET : AF_INET6;
|
||||
family = getInetAddress_family(env, iaObj) == java_net_InetAddress_IPv4 ?
|
||||
AF_INET : AF_INET6;
|
||||
if (family == AF_INET) { /* will convert to IPv4-mapped address */
|
||||
memset((char *) caddr, 0, 16);
|
||||
address = getInetAddress_addr(env, iaObj);
|
||||
|
||||
@ -22,32 +22,8 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#if defined(__linux__)
|
||||
#include <sys/poll.h>
|
||||
#endif
|
||||
#include <netinet/tcp.h> /* Defines TCP_NODELAY, needed for 2.6 */
|
||||
#include <netinet/in.h>
|
||||
#ifdef __linux__
|
||||
#include <netinet/ip.h>
|
||||
#endif
|
||||
#include <netdb.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __solaris__
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
#ifdef __linux__
|
||||
#include <unistd.h>
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
|
||||
#include "jvm.h"
|
||||
#include "jni_util.h"
|
||||
#include "net_util.h"
|
||||
|
||||
#include "java_net_SocketOptions.h"
|
||||
|
||||
@ -22,20 +22,15 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "jvm.h"
|
||||
#include "jni_util.h"
|
||||
#include "net_util.h"
|
||||
|
||||
#include "java_net_SocketInputStream.h"
|
||||
|
||||
/************************************************************************
|
||||
/*
|
||||
* SocketInputStream
|
||||
*/
|
||||
|
||||
|
||||
@ -22,15 +22,10 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "jni_util.h"
|
||||
#include "jvm.h"
|
||||
#include "net_util.h"
|
||||
|
||||
#include "java_net_SocketOutputStream.h"
|
||||
|
||||
@ -22,59 +22,41 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/tcp.h> /* Defines TCP_NODELAY, needed for 2.6 */
|
||||
#include <netinet/in.h>
|
||||
#include <net/if.h>
|
||||
#include <netdb.h>
|
||||
#include <stdlib.h>
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <net/if.h>
|
||||
#include <netinet/tcp.h> // defines TCP_NODELAY
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#ifndef _ALLBSD_SOURCE
|
||||
#include <values.h>
|
||||
#else
|
||||
#include <limits.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#ifndef MAXINT
|
||||
#define MAXINT INT_MAX
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __solaris__
|
||||
#include <sys/filio.h>
|
||||
#include <sys/sockio.h>
|
||||
#include <stropts.h>
|
||||
#include <inet/nd.h>
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
#include <sys/ioctl.h>
|
||||
#if defined(__linux__)
|
||||
#include <arpa/inet.h>
|
||||
#include <net/route.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
#ifndef IPV6_FLOWINFO_SEND
|
||||
#define IPV6_FLOWINFO_SEND 33
|
||||
#endif
|
||||
|
||||
#if defined(__solaris__)
|
||||
#include <inet/nd.h>
|
||||
#include <limits.h>
|
||||
#include <stropts.h>
|
||||
#include <sys/filio.h>
|
||||
#include <sys/sockio.h>
|
||||
#endif
|
||||
|
||||
#ifdef _AIX
|
||||
#include <sys/ioctl.h>
|
||||
#endif
|
||||
|
||||
#include "jni_util.h"
|
||||
#include "jvm.h"
|
||||
#include "net_util.h"
|
||||
|
||||
#include "java_net_SocketOptions.h"
|
||||
#include "java_net_InetAddress.h"
|
||||
|
||||
#if defined(__linux__) && !defined(IPV6_FLOWINFO_SEND)
|
||||
#define IPV6_FLOWINFO_SEND 33
|
||||
#endif
|
||||
|
||||
#if defined(__solaris__) && !defined(MAXINT)
|
||||
#define MAXINT INT_MAX
|
||||
#endif
|
||||
|
||||
/*
|
||||
* EXCLBIND socket options only on Solaris
|
||||
@ -806,13 +788,15 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr
|
||||
family = getInetAddress_family(env, iaObj);
|
||||
#ifdef AF_INET6
|
||||
/* needs work. 1. family 2. clean up him6 etc deallocate memory */
|
||||
if (ipv6_available() && !(family == IPv4 && v4MappedAddress == JNI_FALSE)) {
|
||||
if (ipv6_available() && !(family == java_net_InetAddress_IPv4 &&
|
||||
v4MappedAddress == JNI_FALSE)) {
|
||||
struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)him;
|
||||
jbyte caddr[16];
|
||||
jint address;
|
||||
|
||||
|
||||
if (family == IPv4) { /* will convert to IPv4-mapped address */
|
||||
if (family == java_net_InetAddress_IPv4) {
|
||||
// convert to IPv4-mapped address
|
||||
memset((char *) caddr, 0, 16);
|
||||
address = getInetAddress_addr(env, iaObj);
|
||||
if (address == INADDR_ANY) {
|
||||
@ -906,7 +890,7 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr
|
||||
#else
|
||||
/* handle scope_id for solaris */
|
||||
|
||||
if (family != IPv4) {
|
||||
if (family != java_net_InetAddress_IPv4) {
|
||||
if (ia6_scopeidID) {
|
||||
him6->sin6_scope_id = getInet6Address_scopeid(env, iaObj);
|
||||
}
|
||||
@ -917,14 +901,14 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr
|
||||
{
|
||||
struct sockaddr_in *him4 = (struct sockaddr_in*)him;
|
||||
jint address;
|
||||
if (family == IPv6) {
|
||||
if (family == java_net_InetAddress_IPv6) {
|
||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Protocol family unavailable");
|
||||
return -1;
|
||||
}
|
||||
memset((char *) him4, 0, sizeof(struct sockaddr_in));
|
||||
address = getInetAddress_addr(env, iaObj);
|
||||
him4->sin_port = htons((short) port);
|
||||
him4->sin_addr.s_addr = (uint32_t) htonl(address);
|
||||
him4->sin_addr.s_addr = htonl(address);
|
||||
him4->sin_family = AF_INET;
|
||||
*len = sizeof(struct sockaddr_in);
|
||||
}
|
||||
|
||||
@ -26,13 +26,9 @@
|
||||
#ifndef NET_UTILS_MD_H
|
||||
#define NET_UTILS_MD_H
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/poll.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
int NET_Timeout(int s, long timeout);
|
||||
int NET_Timeout0(int s, long timeout, long currentTime);
|
||||
|
||||
@ -22,10 +22,8 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include "jni.h"
|
||||
#include "net_util.h"
|
||||
|
||||
#include "java_net_DualStackPlainDatagramSocketImpl.h"
|
||||
|
||||
/*
|
||||
|
||||
@ -22,11 +22,10 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include "jni.h"
|
||||
#include "net_util.h"
|
||||
|
||||
#include "java_net_DualStackPlainSocketImpl.h"
|
||||
#include "java_net_SocketOptions.h"
|
||||
|
||||
#define SET_BLOCKING 0
|
||||
#define SET_NONBLOCKING 1
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 2016, 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,24 +22,12 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
#include <sys/types.h>
|
||||
#include <process.h>
|
||||
#include <iphlpapi.h>
|
||||
#include <icmpapi.h>
|
||||
#include <WinError.h>
|
||||
|
||||
#include "net_util.h"
|
||||
|
||||
#include "java_net_InetAddress.h"
|
||||
#include "java_net_Inet4AddressImpl.h"
|
||||
#include "net_util.h"
|
||||
#include "icmp.h"
|
||||
|
||||
|
||||
/*
|
||||
* Returns true if hostname is in dotted IP address format. Note that this
|
||||
|
||||
@ -22,38 +22,13 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
#include <sys/types.h>
|
||||
#include <process.h>
|
||||
#include <iphlpapi.h>
|
||||
#include <icmpapi.h>
|
||||
|
||||
#include "net_util.h"
|
||||
|
||||
#include "java_net_InetAddress.h"
|
||||
#include "java_net_Inet4AddressImpl.h"
|
||||
#include "java_net_Inet6AddressImpl.h"
|
||||
#include "net_util.h"
|
||||
#include "icmp.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#ifndef _WIN64
|
||||
|
||||
/* Retain this code a little longer to support building in
|
||||
* old environments. _MSC_VER is defined as:
|
||||
* 1200 for MSVC++ 6.0
|
||||
* 1310 for Vc7
|
||||
*/
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1310
|
||||
#define sockaddr_in6 SOCKADDR_IN6
|
||||
#endif
|
||||
#endif
|
||||
#define uint32_t UINT32
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Inet6AddressImpl
|
||||
@ -300,7 +275,7 @@ Java_java_net_Inet6AddressImpl_getHostByAddr(JNIEnv *env, jobject this,
|
||||
addr |= ((caddr[2] <<8) & 0xff00);
|
||||
addr |= (caddr[3] & 0xff);
|
||||
memset((char *) &him4, 0, sizeof(him4));
|
||||
him4.sin_addr.s_addr = (uint32_t) htonl(addr);
|
||||
him4.sin_addr.s_addr = htonl(addr);
|
||||
him4.sin_family = AF_INET;
|
||||
sa = (struct sockaddr *) &him4;
|
||||
len = sizeof(him4);
|
||||
|
||||
@ -22,17 +22,10 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
#include <winsock2.h> /* needed for htonl */
|
||||
#include <iprtrmib.h>
|
||||
#include <assert.h>
|
||||
#include "net_util.h"
|
||||
#include "NetworkInterface.h"
|
||||
|
||||
#include "java_net_NetworkInterface.h"
|
||||
#include "jni_util.h"
|
||||
|
||||
#include "NetworkInterface.h"
|
||||
|
||||
/*
|
||||
* Windows implementation of the java.net.NetworkInterface native methods.
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 2016, 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,6 @@
|
||||
#ifndef NETWORK_INTERFACE_H
|
||||
#define NETWORK_INTERFACE_H
|
||||
|
||||
#include <iphlpapi.h>
|
||||
#include "net_util.h"
|
||||
|
||||
/*
|
||||
|
||||
@ -22,19 +22,10 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
#include <winsock2.h> /* needed for htonl */
|
||||
#include <iprtrmib.h>
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#include "net_util.h"
|
||||
#include "NetworkInterface.h"
|
||||
|
||||
#include "java_net_NetworkInterface.h"
|
||||
#include "jni_util.h"
|
||||
|
||||
#include "NetworkInterface.h"
|
||||
#include "net_util.h"
|
||||
|
||||
/*
|
||||
* Windows implementation of the java.net.NetworkInterface native methods.
|
||||
|
||||
@ -22,24 +22,15 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "java_net_SocketInputStream.h"
|
||||
|
||||
#include "net_util.h"
|
||||
#include "jni_util.h"
|
||||
|
||||
#include "java_net_SocketInputStream.h"
|
||||
|
||||
/*************************************************************************
|
||||
* SocketInputStream
|
||||
*/
|
||||
|
||||
static jfieldID IO_fd_fdID;
|
||||
|
||||
/*
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2016, 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,19 +22,11 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "java_net_SocketOutputStream.h"
|
||||
|
||||
#include "net_util.h"
|
||||
#include "jni_util.h"
|
||||
|
||||
#include "java_net_SocketOutputStream.h"
|
||||
|
||||
/************************************************************************
|
||||
* SocketOutputStream
|
||||
|
||||
@ -22,15 +22,15 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "net_util.h"
|
||||
#include "NetworkInterface.h"
|
||||
|
||||
#include "java_net_TwoStacksPlainDatagramSocketImpl.h"
|
||||
#include "java_net_SocketOptions.h"
|
||||
#include "java_net_NetworkInterface.h"
|
||||
#include "java_net_InetAddress.h"
|
||||
|
||||
#ifndef IPTOS_TOS_MASK
|
||||
#define IPTOS_TOS_MASK 0x1e
|
||||
@ -39,14 +39,6 @@
|
||||
#define IPTOS_PREC_MASK 0xe0
|
||||
#endif
|
||||
|
||||
#include "java_net_TwoStacksPlainDatagramSocketImpl.h"
|
||||
#include "java_net_SocketOptions.h"
|
||||
#include "java_net_NetworkInterface.h"
|
||||
|
||||
#include "NetworkInterface.h"
|
||||
#include "jvm.h"
|
||||
#include "jni_util.h"
|
||||
#include "net_util.h"
|
||||
|
||||
#define IN_CLASSD(i) (((long)(i) & 0xf0000000) == 0xe0000000)
|
||||
#define IN_MULTICAST(i) IN_CLASSD(i)
|
||||
@ -439,7 +431,7 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_bind0(JNIEnv *env, jobject this,
|
||||
memset((char *)&lcladdr, 0, sizeof(lcladdr));
|
||||
|
||||
family = getInetAddress_family(env, addressObj);
|
||||
if (family == IPv6 && !ipv6_supported) {
|
||||
if (family == java_net_InetAddress_IPv6 && !ipv6_supported) {
|
||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
|
||||
"Protocol family not supported");
|
||||
return;
|
||||
@ -561,13 +553,13 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_connect0(JNIEnv *env, jobject thi
|
||||
addr = getInetAddress_addr(env, address);
|
||||
|
||||
family = getInetAddress_family(env, address);
|
||||
if (family == IPv6 && !ipv6_supported) {
|
||||
if (family == java_net_InetAddress_IPv6 && !ipv6_supported) {
|
||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
|
||||
"Protocol family not supported");
|
||||
return;
|
||||
}
|
||||
|
||||
fdc = family == IPv4? fd: fd1;
|
||||
fdc = family == java_net_InetAddress_IPv4 ? fd : fd1;
|
||||
|
||||
if (xp_or_later) {
|
||||
/* SIO_UDP_CONNRESET fixes a bug introduced in Windows 2000, which
|
||||
@ -605,12 +597,12 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_disconnect0(JNIEnv *env, jobject
|
||||
jint fd, len;
|
||||
SOCKETADDRESS addr;
|
||||
|
||||
if (family == IPv4) {
|
||||
if (family == java_net_InetAddress_IPv4) {
|
||||
fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
|
||||
len = sizeof (struct sockaddr_in);
|
||||
len = sizeof(struct sockaddr_in);
|
||||
} else {
|
||||
fdObj = (*env)->GetObjectField(env, this, pdsi_fd1ID);
|
||||
len = sizeof (struct SOCKADDR_IN6);
|
||||
len = sizeof(struct sockaddr_in6);
|
||||
}
|
||||
|
||||
if (IS_NULL(fdObj)) {
|
||||
@ -678,7 +670,7 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_send(JNIEnv *env, jobject this,
|
||||
}
|
||||
|
||||
family = getInetAddress_family(env, iaObj);
|
||||
if (family == IPv4) {
|
||||
if (family == java_net_InetAddress_IPv4) {
|
||||
fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
|
||||
} else {
|
||||
if (!ipv6_available()) {
|
||||
@ -906,7 +898,7 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_peek(JNIEnv *env, jobject this,
|
||||
return 0;
|
||||
}
|
||||
setInetAddress_addr(env, addressObj, ntohl(remote_addr.sa4.sin_addr.s_addr));
|
||||
setInetAddress_family(env, addressObj, IPv4);
|
||||
setInetAddress_family(env, addressObj, java_net_InetAddress_IPv4);
|
||||
|
||||
/* return port */
|
||||
return ntohs(remote_addr.sa4.sin_port);
|
||||
@ -1610,7 +1602,7 @@ static int getInet4AddrFromIf (JNIEnv *env, jobject nif, struct in_addr *iaddr)
|
||||
{
|
||||
jobject addr;
|
||||
|
||||
int ret = getInetAddrFromIf (env, IPv4, nif, &addr);
|
||||
int ret = getInetAddrFromIf(env, java_net_InetAddress_IPv4, nif, &addr);
|
||||
if (ret == -1) {
|
||||
return -1;
|
||||
}
|
||||
@ -2285,9 +2277,9 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_socketLocalAddress
|
||||
len = sizeof(struct sockaddr_in);
|
||||
|
||||
/* family==-1 when socket is not connected */
|
||||
if ((family == IPv6) || (family == -1 && fd == -1)) {
|
||||
if ((family == java_net_InetAddress_IPv6) || (family == -1 && fd == -1)) {
|
||||
fd = fd1; /* must be IPv6 only */
|
||||
len = sizeof (struct SOCKADDR_IN6);
|
||||
len = sizeof(struct sockaddr_in6);
|
||||
}
|
||||
|
||||
if (fd == -1) {
|
||||
|
||||
@ -22,23 +22,13 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "java_net_SocketOptions.h"
|
||||
#include "java_net_TwoStacksPlainSocketImpl.h"
|
||||
#include "java_net_InetAddress.h"
|
||||
#include "java_io_FileDescriptor.h"
|
||||
#include "java_lang_Integer.h"
|
||||
|
||||
#include "net_util.h"
|
||||
#include "jni_util.h"
|
||||
|
||||
#include "java_net_TwoStacksPlainSocketImpl.h"
|
||||
#include "java_net_SocketOptions.h"
|
||||
#include "java_net_InetAddress.h"
|
||||
|
||||
/************************************************************************
|
||||
* TwoStacksPlainSocketImpl
|
||||
@ -413,7 +403,7 @@ Java_java_net_TwoStacksPlainSocketImpl_socketBind(JNIEnv *env, jobject this,
|
||||
|
||||
family = getInetAddress_family(env, iaObj);
|
||||
|
||||
if (family == IPv6 && !ipv6_supported) {
|
||||
if (family == java_net_InetAddress_IPv6 && !ipv6_supported) {
|
||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
|
||||
"Protocol family not supported");
|
||||
return;
|
||||
@ -655,18 +645,18 @@ Java_java_net_TwoStacksPlainSocketImpl_socketAccept(JNIEnv *env, jobject this,
|
||||
return;
|
||||
}
|
||||
if (fd2 == fd) { /* v4 */
|
||||
len = sizeof (struct sockaddr_in);
|
||||
len = sizeof(struct sockaddr_in);
|
||||
} else {
|
||||
len = sizeof (struct SOCKADDR_IN6);
|
||||
len = sizeof(struct sockaddr_in6);
|
||||
}
|
||||
fd = fd2;
|
||||
} else {
|
||||
int ret;
|
||||
if (fd1 != -1) {
|
||||
fd = fd1;
|
||||
len = sizeof (struct SOCKADDR_IN6);
|
||||
len = sizeof(struct sockaddr_in6);
|
||||
} else {
|
||||
len = sizeof (struct sockaddr_in);
|
||||
len = sizeof(struct sockaddr_in);
|
||||
}
|
||||
if (timeout) {
|
||||
ret = NET_Timeout(fd, timeout);
|
||||
@ -728,7 +718,7 @@ Java_java_net_TwoStacksPlainSocketImpl_socketAccept(JNIEnv *env, jobject this,
|
||||
}
|
||||
|
||||
setInetAddress_addr(env, socketAddressObj, ntohl(him.sa4.sin_addr.s_addr));
|
||||
setInetAddress_family(env, socketAddressObj, IPv4);
|
||||
setInetAddress_family(env, socketAddressObj, java_net_InetAddress_IPv4);
|
||||
(*env)->SetObjectField(env, socket, psi_addressID, socketAddressObj);
|
||||
} else {
|
||||
/* AF_INET6 -> Inet6Address */
|
||||
@ -754,7 +744,7 @@ Java_java_net_TwoStacksPlainSocketImpl_socketAccept(JNIEnv *env, jobject this,
|
||||
return;
|
||||
}
|
||||
setInet6Address_ipaddress(env, socketAddressObj, (char *)&him.sa6.sin6_addr);
|
||||
setInetAddress_family(env, socketAddressObj, IPv6);
|
||||
setInetAddress_family(env, socketAddressObj, java_net_InetAddress_IPv6);
|
||||
setInet6Address_scopeid(env, socketAddressObj, him.sa6.sin6_scope_id);
|
||||
|
||||
}
|
||||
|
||||
@ -1,148 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2013, 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.
|
||||
*/
|
||||
|
||||
#ifndef ICMP_H
|
||||
#define ICMP_H
|
||||
|
||||
/*
|
||||
* Structure of an internet header, naked of options.
|
||||
*
|
||||
* We declare ip_len and ip_off to be short, rather than ushort_t
|
||||
* pragmatically since otherwise unsigned comparisons can result
|
||||
* against negative integers quite easily, and fail in subtle ways.
|
||||
*/
|
||||
struct ip {
|
||||
unsigned char ip_hl:4, /* header length */
|
||||
ip_v:4; /* version */
|
||||
unsigned char ip_tos; /* type of service */
|
||||
short ip_len; /* total length */
|
||||
unsigned short ip_id; /* identification */
|
||||
short ip_off; /* fragment offset field */
|
||||
#define IP_DF 0x4000 /* don't fragment flag */
|
||||
#define IP_MF 0x2000 /* more fragments flag */
|
||||
unsigned char ip_ttl; /* time to live */
|
||||
unsigned char ip_p; /* protocol */
|
||||
unsigned short ip_sum; /* checksum */
|
||||
struct in_addr ip_src, ip_dst; /* source and dest address */
|
||||
};
|
||||
|
||||
/*
|
||||
* Structure of an icmp header.
|
||||
*/
|
||||
struct icmp {
|
||||
unsigned char icmp_type; /* type of message, see below */
|
||||
unsigned char icmp_code; /* type sub code */
|
||||
unsigned short icmp_cksum; /* ones complement cksum of struct */
|
||||
union {
|
||||
unsigned char ih_pptr; /* ICMP_PARAMPROB */
|
||||
struct in_addr ih_gwaddr; /* ICMP_REDIRECT */
|
||||
struct ih_idseq {
|
||||
unsigned short icd_id;
|
||||
unsigned short icd_seq;
|
||||
} ih_idseq;
|
||||
int ih_void;
|
||||
|
||||
/* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */
|
||||
struct ih_pmtu {
|
||||
unsigned short ipm_void;
|
||||
unsigned short ipm_nextmtu;
|
||||
} ih_pmtu;
|
||||
|
||||
struct ih_rtradv {
|
||||
unsigned char irt_num_addrs;
|
||||
unsigned char irt_wpa;
|
||||
unsigned short irt_lifetime;
|
||||
} ih_rtradv;
|
||||
} icmp_hun;
|
||||
#define icmp_pptr icmp_hun.ih_pptr
|
||||
#define icmp_gwaddr icmp_hun.ih_gwaddr
|
||||
#define icmp_id icmp_hun.ih_idseq.icd_id
|
||||
#define icmp_seq icmp_hun.ih_idseq.icd_seq
|
||||
#define icmp_void icmp_hun.ih_void
|
||||
#define icmp_pmvoid icmp_hun.ih_pmtu.ipm_void
|
||||
#define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu
|
||||
union {
|
||||
struct id_ts {
|
||||
unsigned int its_otime;
|
||||
unsigned int its_rtime;
|
||||
unsigned int its_ttime;
|
||||
} id_ts;
|
||||
struct id_ip {
|
||||
struct ip idi_ip;
|
||||
/* options and then 64 bits of data */
|
||||
} id_ip;
|
||||
unsigned int id_mask;
|
||||
char id_data[1];
|
||||
} icmp_dun;
|
||||
#define icmp_otime icmp_dun.id_ts.its_otime
|
||||
#define icmp_rtime icmp_dun.id_ts.its_rtime
|
||||
#define icmp_ttime icmp_dun.id_ts.its_ttime
|
||||
#define icmp_ip icmp_dun.id_ip.idi_ip
|
||||
#define icmp_mask icmp_dun.id_mask
|
||||
#define icmp_data icmp_dun.id_data
|
||||
};
|
||||
|
||||
#define ICMP_ECHOREPLY 0 /* echo reply */
|
||||
#define ICMP_ECHO 8 /* echo service */
|
||||
|
||||
/*
|
||||
* ICMPv6 structures & constants
|
||||
*/
|
||||
|
||||
typedef struct icmp6_hdr {
|
||||
u_char icmp6_type; /* type field */
|
||||
u_char icmp6_code; /* code field */
|
||||
u_short icmp6_cksum; /* checksum field */
|
||||
union {
|
||||
u_int icmp6_un_data32[1]; /* type-specific field */
|
||||
u_short icmp6_un_data16[2]; /* type-specific field */
|
||||
u_char icmp6_un_data8[4]; /* type-specific field */
|
||||
} icmp6_dataun;
|
||||
} icmp6_t;
|
||||
|
||||
#define icmp6_data32 icmp6_dataun.icmp6_un_data32
|
||||
#define icmp6_data16 icmp6_dataun.icmp6_un_data16
|
||||
#define icmp6_data8 icmp6_dataun.icmp6_un_data8
|
||||
#define icmp6_pptr icmp6_data32[0] /* parameter prob */
|
||||
#define icmp6_mtu icmp6_data32[0] /* packet too big */
|
||||
#define icmp6_id icmp6_data16[0] /* echo request/reply */
|
||||
#define icmp6_seq icmp6_data16[1] /* echo request/reply */
|
||||
#define icmp6_maxdelay icmp6_data16[0] /* mcast group membership */
|
||||
|
||||
struct ip6_pseudo_hdr /* for calculate the ICMPv6 checksum */
|
||||
{
|
||||
struct in6_addr ip6_src;
|
||||
struct in6_addr ip6_dst;
|
||||
u_int ip6_plen;
|
||||
u_int ip6_nxt;
|
||||
};
|
||||
|
||||
#define ICMP6_ECHO_REQUEST 128
|
||||
#define ICMP6_ECHO_REPLY 129
|
||||
#define IPPROTO_ICMPV6 58
|
||||
#define IPV6_UNICAST_HOPS 4 /* Set/get IP unicast hop limit */
|
||||
|
||||
|
||||
#endif
|
||||
@ -22,12 +22,10 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
|
||||
#include "net_util.h"
|
||||
#include "jni.h"
|
||||
|
||||
#include "java_net_InetAddress.h"
|
||||
#include "java_net_SocketOptions.h"
|
||||
|
||||
// Taken from mstcpip.h in Windows SDK 8.0 or newer.
|
||||
#define SIO_LOOPBACK_FAST_PATH _WSAIOW(IOC_VENDOR,16)
|
||||
@ -593,7 +591,7 @@ NET_Timeout2(int fd, int fd1, long timeout, int *fdret) {
|
||||
|
||||
|
||||
void dumpAddr (char *str, void *addr) {
|
||||
struct SOCKADDR_IN6 *a = (struct SOCKADDR_IN6 *)addr;
|
||||
struct sockaddr_in6 *a = (struct sockaddr_in6 *)addr;
|
||||
int family = a->sin6_family;
|
||||
printf ("%s\n", str);
|
||||
if (family == AF_INET) {
|
||||
@ -812,7 +810,7 @@ NET_BindV6(struct ipv6bind *b, jboolean exclBind) {
|
||||
* 0 if error
|
||||
* > 0 interface index to use
|
||||
*/
|
||||
jint getDefaultIPv6Interface(JNIEnv *env, struct SOCKADDR_IN6 *target_addr)
|
||||
jint getDefaultIPv6Interface(JNIEnv *env, struct sockaddr_in6 *target_addr)
|
||||
{
|
||||
int ret;
|
||||
DWORD b;
|
||||
@ -866,9 +864,9 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr
|
||||
int *len, jboolean v4MappedAddress) {
|
||||
jint family, iafam;
|
||||
iafam = getInetAddress_family(env, iaObj);
|
||||
family = (iafam == IPv4)? AF_INET : AF_INET6;
|
||||
family = (iafam == java_net_InetAddress_IPv4)? AF_INET : AF_INET6;
|
||||
if (ipv6_available() && !(family == AF_INET && v4MappedAddress == JNI_FALSE)) {
|
||||
struct SOCKADDR_IN6 *him6 = (struct SOCKADDR_IN6 *)him;
|
||||
struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)him;
|
||||
jbyte caddr[16];
|
||||
jint address, scopeid = 0;
|
||||
jint cached_scope_id = 0;
|
||||
@ -894,7 +892,7 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr
|
||||
cached_scope_id = (jint)(*env)->GetIntField(env, iaObj, ia6_cachedscopeidID);
|
||||
}
|
||||
|
||||
memset((char *)him6, 0, sizeof(struct SOCKADDR_IN6));
|
||||
memset((char *)him6, 0, sizeof(struct sockaddr_in6));
|
||||
him6->sin6_port = (u_short) htons((u_short)port);
|
||||
memcpy((void *)&(him6->sin6_addr), caddr, sizeof(struct in6_addr) );
|
||||
him6->sin6_family = AF_INET6;
|
||||
@ -904,7 +902,7 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr
|
||||
(*env)->SetIntField(env, iaObj, ia6_cachedscopeidID, cached_scope_id);
|
||||
}
|
||||
him6->sin6_scope_id = scopeid != 0 ? scopeid : cached_scope_id;
|
||||
*len = sizeof(struct SOCKADDR_IN6) ;
|
||||
*len = sizeof(struct sockaddr_in6) ;
|
||||
} else {
|
||||
struct sockaddr_in *him4 = (struct sockaddr_in *)him;
|
||||
jint address;
|
||||
@ -964,12 +962,12 @@ NET_IsEqual(jbyte* caddr1, jbyte* caddr2) {
|
||||
}
|
||||
|
||||
int getScopeID(struct sockaddr *him) {
|
||||
struct SOCKADDR_IN6 *him6 = (struct SOCKADDR_IN6 *)him;
|
||||
struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)him;
|
||||
return him6->sin6_scope_id;
|
||||
}
|
||||
|
||||
int cmpScopeID(unsigned int scope, struct sockaddr *him) {
|
||||
struct SOCKADDR_IN6 *him6 = (struct SOCKADDR_IN6 *)him;
|
||||
struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)him;
|
||||
return him6->sin6_scope_id == scope;
|
||||
}
|
||||
|
||||
|
||||
@ -22,195 +22,10 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <winsock2.h>
|
||||
#include <WS2tcpip.h>
|
||||
|
||||
/* typedefs that were defined correctly for the first time
|
||||
* in Nov. 2001 SDK, which we need to include here.
|
||||
* Specifically, in6_addr and sockaddr_in6 (which is defined but
|
||||
* not correctly). When moving to a later SDK remove following
|
||||
* code between START and END
|
||||
*/
|
||||
|
||||
/* --- START --- */
|
||||
|
||||
/* WIN64 already uses newer SDK */
|
||||
#ifdef _WIN64
|
||||
|
||||
#define SOCKADDR_IN6 sockaddr_in6
|
||||
|
||||
#else
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define WS2TCPIP_INLINE __inline
|
||||
#else
|
||||
#define WS2TCPIP_INLINE extern inline /* GNU style */
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1310
|
||||
|
||||
#define SOCKADDR_IN6 sockaddr_in6
|
||||
|
||||
#else
|
||||
|
||||
/*SO_REUSEPORT is not supported on Windows, define it to 0*/
|
||||
#define SO_REUSEPORT 0
|
||||
|
||||
/* Retain this code a little longer to support building in
|
||||
* old environments. _MSC_VER is defined as:
|
||||
* 1200 for MSVC++ 6.0
|
||||
* 1310 for Vc7
|
||||
*/
|
||||
|
||||
#define IPPROTO_IPV6 41
|
||||
#define IPV6_MULTICAST_IF 9
|
||||
|
||||
struct in6_addr {
|
||||
union {
|
||||
u_char Byte[16];
|
||||
u_short Word[8];
|
||||
} u;
|
||||
};
|
||||
|
||||
/*
|
||||
** Defines to match RFC 2553.
|
||||
*/
|
||||
#define _S6_un u
|
||||
#define _S6_u8 Byte
|
||||
#define s6_addr _S6_un._S6_u8
|
||||
|
||||
/*
|
||||
** Defines for our implementation.
|
||||
*/
|
||||
#define s6_bytes u.Byte
|
||||
#define s6_words u.Word
|
||||
|
||||
/* IPv6 socket address structure, RFC 2553 */
|
||||
|
||||
struct SOCKADDR_IN6 {
|
||||
short sin6_family; /* AF_INET6 */
|
||||
u_short sin6_port; /* Transport level port number */
|
||||
u_long sin6_flowinfo; /* IPv6 flow information */
|
||||
struct in6_addr sin6_addr; /* IPv6 address */
|
||||
u_long sin6_scope_id; /* set of interfaces for a scope */
|
||||
};
|
||||
|
||||
|
||||
/* Error codes from getaddrinfo() */
|
||||
|
||||
#define EAI_AGAIN WSATRY_AGAIN
|
||||
#define EAI_BADFLAGS WSAEINVAL
|
||||
#define EAI_FAIL WSANO_RECOVERY
|
||||
#define EAI_FAMILY WSAEAFNOSUPPORT
|
||||
#define EAI_MEMORY WSA_NOT_ENOUGH_MEMORY
|
||||
//#define EAI_NODATA WSANO_DATA
|
||||
#define EAI_NONAME WSAHOST_NOT_FOUND
|
||||
#define EAI_SERVICE WSATYPE_NOT_FOUND
|
||||
#define EAI_SOCKTYPE WSAESOCKTNOSUPPORT
|
||||
|
||||
#define EAI_NODATA EAI_NONAME
|
||||
|
||||
/* Structure used in getaddrinfo() call */
|
||||
|
||||
typedef struct addrinfo {
|
||||
int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
|
||||
int ai_family; /* PF_xxx */
|
||||
int ai_socktype; /* SOCK_xxx */
|
||||
int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
|
||||
size_t ai_addrlen; /* Length of ai_addr */
|
||||
char *ai_canonname; /* Canonical name for nodename */
|
||||
struct sockaddr *ai_addr; /* Binary address */
|
||||
struct addrinfo *ai_next; /* Next structure in linked list */
|
||||
} ADDRINFO, FAR * LPADDRINFO;
|
||||
|
||||
/* Flags used in "hints" argument to getaddrinfo() */
|
||||
|
||||
#define AI_PASSIVE 0x1 /* Socket address will be used in bind() call */
|
||||
#define AI_CANONNAME 0x2 /* Return canonical name in first ai_canonname */
|
||||
#define AI_NUMERICHOST 0x4 /* Nodename must be a numeric address string */
|
||||
|
||||
/* IPv6 Multicasting definitions */
|
||||
|
||||
/* Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP */
|
||||
|
||||
typedef struct ipv6_mreq {
|
||||
struct in6_addr ipv6mr_multiaddr; /* IPv6 multicast address */
|
||||
unsigned int ipv6mr_interface; /* Interface index */
|
||||
} IPV6_MREQ;
|
||||
|
||||
#define IPV6_ADD_MEMBERSHIP 12 /* Add an IP group membership */
|
||||
#define IPV6_DROP_MEMBERSHIP 13 /* Drop an IP group membership */
|
||||
#define IPV6_MULTICAST_LOOP 11 /* Set/get IP multicast loopback */
|
||||
|
||||
WS2TCPIP_INLINE int
|
||||
IN6_IS_ADDR_MULTICAST(const struct in6_addr *a)
|
||||
{
|
||||
return (a->s6_bytes[0] == 0xff);
|
||||
}
|
||||
|
||||
WS2TCPIP_INLINE int
|
||||
IN6_IS_ADDR_LINKLOCAL(const struct in6_addr *a)
|
||||
{
|
||||
return (a->s6_bytes[0] == 0xfe
|
||||
&& a->s6_bytes[1] == 0x80);
|
||||
}
|
||||
|
||||
#define NI_MAXHOST 1025 /* Max size of a fully-qualified domain name */
|
||||
#define NI_MAXSERV 32 /* Max size of a service name */
|
||||
|
||||
#define INET_ADDRSTRLEN 16 /* Max size of numeric form of IPv4 address */
|
||||
#define INET6_ADDRSTRLEN 46 /* Max size of numeric form of IPv6 address */
|
||||
|
||||
/* Flags for getnameinfo() */
|
||||
|
||||
#define NI_NOFQDN 0x01 /* Only return nodename portion for local hosts */
|
||||
#define NI_NUMERICHOST 0x02 /* Return numeric form of the host's address */
|
||||
#define NI_NAMEREQD 0x04 /* Error if the host's name not in DNS */
|
||||
#define NI_NUMERICSERV 0x08 /* Return numeric form of the service (port #) */
|
||||
#define NI_DGRAM 0x10 /* Service is a datagram service */
|
||||
|
||||
|
||||
#define IN6_IS_ADDR_V4MAPPED(a) \
|
||||
(((a)->s6_words[0] == 0) && ((a)->s6_words[1] == 0) && \
|
||||
((a)->s6_words[2] == 0) && ((a)->s6_words[3] == 0) && \
|
||||
((a)->s6_words[4] == 0) && ((a)->s6_words[5] == 0xffff))
|
||||
|
||||
|
||||
/* --- END --- */
|
||||
#endif /* end 'else older build environment' */
|
||||
|
||||
#endif
|
||||
|
||||
#if !INCL_WINSOCK_API_TYPEDEFS
|
||||
|
||||
typedef
|
||||
int
|
||||
(WSAAPI * LPFN_GETADDRINFO)(
|
||||
IN const char FAR * nodename,
|
||||
IN const char FAR * servname,
|
||||
IN const struct addrinfo FAR * hints,
|
||||
OUT struct addrinfo FAR * FAR * res
|
||||
);
|
||||
|
||||
typedef
|
||||
void
|
||||
(WSAAPI * LPFN_FREEADDRINFO)(
|
||||
IN struct addrinfo FAR * ai
|
||||
);
|
||||
|
||||
typedef
|
||||
int
|
||||
(WSAAPI * LPFN_GETNAMEINFO)(
|
||||
IN const struct sockaddr FAR * sa,
|
||||
IN int salen,
|
||||
OUT char FAR * host,
|
||||
IN DWORD hostlen,
|
||||
OUT char FAR * serv,
|
||||
IN DWORD servlen,
|
||||
IN int flags
|
||||
);
|
||||
#endif
|
||||
#include <iphlpapi.h>
|
||||
#include <icmpapi.h>
|
||||
|
||||
/* used to disable connection reset messages on Windows XP */
|
||||
#ifndef SIO_UDP_CONNRESET
|
||||
@ -229,13 +44,9 @@ int
|
||||
#define IPV6_V6ONLY 27 /* Treat wildcard bind as AF_INET6-only. */
|
||||
#endif
|
||||
|
||||
#include "java_io_FileDescriptor.h"
|
||||
#include "java_net_SocketOptions.h"
|
||||
|
||||
#define MAX_BUFFER_LEN 2048
|
||||
#define MAX_HEAP_BUFFER_LEN 65536
|
||||
|
||||
|
||||
/* true if SO_RCVTIMEO is supported by underlying provider */
|
||||
extern jboolean isRcvTimeoutSupported;
|
||||
|
||||
@ -249,7 +60,7 @@ int NET_GetDefaultTOS(void);
|
||||
typedef union {
|
||||
struct sockaddr sa;
|
||||
struct sockaddr_in sa4;
|
||||
struct SOCKADDR_IN6 sa6;
|
||||
struct sockaddr_in6 sa6;
|
||||
} SOCKETADDRESS;
|
||||
|
||||
/*
|
||||
@ -264,7 +75,7 @@ struct ipv6bind {
|
||||
|
||||
#define SOCKETADDRESS_COPY(DST,SRC) { \
|
||||
if ((SRC)->sa_family == AF_INET6) { \
|
||||
memcpy ((DST), (SRC), sizeof (struct SOCKADDR_IN6)); \
|
||||
memcpy ((DST), (SRC), sizeof (struct sockaddr_in6)); \
|
||||
} else { \
|
||||
memcpy ((DST), (SRC), sizeof (struct sockaddr_in)); \
|
||||
} \
|
||||
|
||||
@ -29,11 +29,9 @@ import sun.lwawt.LWWindowPeer;
|
||||
|
||||
import java.awt.*;
|
||||
import java.beans.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import sun.awt.AWTAccessor;
|
||||
|
||||
import javax.accessibility.*;
|
||||
import javax.swing.*;
|
||||
@ -73,8 +71,20 @@ class CAccessibility implements PropertyChangeListener {
|
||||
}
|
||||
|
||||
public void propertyChange(final PropertyChangeEvent evt) {
|
||||
if (evt.getNewValue() == null) return;
|
||||
focusChanged();
|
||||
Object newValue = evt.getNewValue();
|
||||
if (newValue == null) return;
|
||||
// Don't post focus on things that don't matter, i.e. alert, colorchooser,
|
||||
// desktoppane, dialog, directorypane, filechooser, filler, fontchoose,
|
||||
// frame, glasspane, layeredpane, optionpane, panel, rootpane, separator,
|
||||
// tooltip, viewport, window.
|
||||
// List taken from initializeRoles() in JavaComponentUtilities.m.
|
||||
if (newValue instanceof Accessible) {
|
||||
AccessibleContext nvAC = ((Accessible) newValue).getAccessibleContext();
|
||||
AccessibleRole nvRole = nvAC.getAccessibleRole();
|
||||
if (!ignoredRoles.contains(roleKey(nvRole))) {
|
||||
focusChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private native void focusChanged();
|
||||
@ -683,9 +693,15 @@ class CAccessibility implements PropertyChangeListener {
|
||||
if (context == null) continue;
|
||||
|
||||
if (whichChildren == JAVA_AX_VISIBLE_CHILDREN) {
|
||||
if (!context.getAccessibleComponent().isVisible()) continue;
|
||||
AccessibleComponent acomp = context.getAccessibleComponent();
|
||||
if (acomp == null || !acomp.isVisible()) {
|
||||
continue;
|
||||
}
|
||||
} else if (whichChildren == JAVA_AX_SELECTED_CHILDREN) {
|
||||
if (!ac.getAccessibleSelection().isAccessibleChildSelected(i)) continue;
|
||||
AccessibleSelection sel = ac.getAccessibleSelection();
|
||||
if (sel == null || !sel.isAccessibleChildSelected(i)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!allowIgnored) {
|
||||
|
||||
@ -39,7 +39,10 @@ import javax.swing.event.ChangeListener;
|
||||
import static javax.accessibility.AccessibleContext.ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY;
|
||||
import static javax.accessibility.AccessibleContext.ACCESSIBLE_CARET_PROPERTY;
|
||||
import static javax.accessibility.AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY;
|
||||
import static javax.accessibility.AccessibleContext.ACCESSIBLE_STATE_PROPERTY;
|
||||
import static javax.accessibility.AccessibleContext.ACCESSIBLE_TEXT_PROPERTY;
|
||||
import javax.accessibility.AccessibleRole;
|
||||
import javax.accessibility.AccessibleState;
|
||||
import sun.awt.AWTAccessor;
|
||||
|
||||
|
||||
@ -63,6 +66,9 @@ class CAccessible extends CFRetainedResource implements Accessible {
|
||||
private static native void valueChanged(long ptr);
|
||||
private static native void selectedTextChanged(long ptr);
|
||||
private static native void selectionChanged(long ptr);
|
||||
private static native void menuOpened(long ptr);
|
||||
private static native void menuClosed(long ptr);
|
||||
private static native void menuItemSelected(long ptr);
|
||||
|
||||
private Accessible accessible;
|
||||
|
||||
@ -111,16 +117,45 @@ class CAccessible extends CFRetainedResource implements Accessible {
|
||||
public void propertyChange(PropertyChangeEvent e) {
|
||||
String name = e.getPropertyName();
|
||||
if ( ptr != 0 ) {
|
||||
Object newValue = e.getNewValue();
|
||||
Object oldValue = e.getOldValue();
|
||||
if (name.compareTo(ACCESSIBLE_CARET_PROPERTY) == 0) {
|
||||
selectedTextChanged(ptr);
|
||||
} else if (name.compareTo(ACCESSIBLE_TEXT_PROPERTY) == 0 ) {
|
||||
valueChanged(ptr);
|
||||
} else if (name.compareTo(ACCESSIBLE_SELECTION_PROPERTY) == 0 ) {
|
||||
selectionChanged(ptr);
|
||||
} else if (name.compareTo(ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY) == 0 ) {
|
||||
Object nv = e.getNewValue();
|
||||
if (nv instanceof AccessibleContext) {
|
||||
activeDescendant = (AccessibleContext)nv;
|
||||
} else if (name.compareTo(ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY) == 0 ) {
|
||||
if (newValue instanceof AccessibleContext) {
|
||||
activeDescendant = (AccessibleContext)newValue;
|
||||
}
|
||||
} else if (name.compareTo(ACCESSIBLE_STATE_PROPERTY) == 0) {
|
||||
AccessibleContext thisAC = accessible.getAccessibleContext();
|
||||
AccessibleRole thisRole = thisAC.getAccessibleRole();
|
||||
Accessible parentAccessible = thisAC.getAccessibleParent();
|
||||
AccessibleRole parentRole = null;
|
||||
if (parentAccessible != null) {
|
||||
parentRole = parentAccessible.getAccessibleContext().getAccessibleRole();
|
||||
}
|
||||
// At least for now don't handle combo box menu state changes.
|
||||
// This may change when later fixing issues which currently
|
||||
// exist for combo boxes, but for now the following is only
|
||||
// for JPopupMenus, not for combobox menus.
|
||||
if (parentRole != AccessibleRole.COMBO_BOX) {
|
||||
if (thisRole == AccessibleRole.POPUP_MENU) {
|
||||
if ( newValue != null &&
|
||||
((AccessibleState)newValue) == AccessibleState.VISIBLE ) {
|
||||
menuOpened(ptr);
|
||||
} else if ( oldValue != null &&
|
||||
((AccessibleState)oldValue) == AccessibleState.VISIBLE ) {
|
||||
menuClosed(ptr);
|
||||
}
|
||||
} else if (thisRole == AccessibleRole.MENU_ITEM) {
|
||||
if ( newValue != null &&
|
||||
((AccessibleState)newValue) == AccessibleState.FOCUSED ) {
|
||||
menuItemSelected(ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,7 +97,7 @@ public class CEmbeddedFrame extends EmbeddedFrame {
|
||||
int absY = locationOnScreen.y + y;
|
||||
|
||||
responder.handleScrollEvent(x, y, absX, absY, modifierFlags, deltaX,
|
||||
deltaY);
|
||||
deltaY, NSEvent.SCROLL_PHASE_UNSUPPORTED);
|
||||
}
|
||||
|
||||
public void handleKeyEvent(int eventType, int modifierFlags, String characters,
|
||||
|
||||
@ -44,6 +44,8 @@ final class CPlatformResponder {
|
||||
private final PlatformEventNotifier eventNotifier;
|
||||
private final boolean isNpapiCallback;
|
||||
private int lastKeyPressCode = KeyEvent.VK_UNDEFINED;
|
||||
private final DeltaAccumulator deltaAccumulatorX = new DeltaAccumulator();
|
||||
private final DeltaAccumulator deltaAccumulatorY = new DeltaAccumulator();
|
||||
|
||||
CPlatformResponder(final PlatformEventNotifier eventNotifier,
|
||||
final boolean isNpapiCallback) {
|
||||
@ -89,37 +91,37 @@ final class CPlatformResponder {
|
||||
*/
|
||||
void handleScrollEvent(final int x, final int y, final int absX,
|
||||
final int absY, final int modifierFlags,
|
||||
final double deltaX, final double deltaY) {
|
||||
final double deltaX, final double deltaY,
|
||||
final int scrollPhase) {
|
||||
int jmodifiers = NSEvent.nsToJavaModifiers(modifierFlags);
|
||||
final boolean isShift = (jmodifiers & InputEvent.SHIFT_DOWN_MASK) != 0;
|
||||
|
||||
int roundDeltaX = deltaAccumulatorX.getRoundedDelta(deltaX, scrollPhase);
|
||||
int roundDeltaY = deltaAccumulatorY.getRoundedDelta(deltaY, scrollPhase);
|
||||
|
||||
// Vertical scroll.
|
||||
if (!isShift && deltaY != 0.0) {
|
||||
dispatchScrollEvent(x, y, absX, absY, jmodifiers, deltaY);
|
||||
if (!isShift && (deltaY != 0.0 || roundDeltaY != 0)) {
|
||||
dispatchScrollEvent(x, y, absX, absY, jmodifiers, roundDeltaY, deltaY);
|
||||
}
|
||||
// Horizontal scroll or shirt+vertical scroll.
|
||||
final double delta = isShift && deltaY != 0.0 ? deltaY : deltaX;
|
||||
if (delta != 0.0) {
|
||||
final int roundDelta = isShift && roundDeltaY != 0 ? roundDeltaY : roundDeltaX;
|
||||
if (delta != 0.0 || roundDelta != 0) {
|
||||
jmodifiers |= InputEvent.SHIFT_DOWN_MASK;
|
||||
dispatchScrollEvent(x, y, absX, absY, jmodifiers, delta);
|
||||
dispatchScrollEvent(x, y, absX, absY, jmodifiers, roundDelta, delta);
|
||||
}
|
||||
}
|
||||
|
||||
private void dispatchScrollEvent(final int x, final int y, final int absX,
|
||||
final int absY, final int modifiers,
|
||||
final double delta) {
|
||||
final int roundDelta, final double delta) {
|
||||
final long when = System.currentTimeMillis();
|
||||
final int scrollType = MouseWheelEvent.WHEEL_UNIT_SCROLL;
|
||||
final int scrollAmount = 1;
|
||||
int wheelRotation = (int) delta;
|
||||
int signum = (int) Math.signum(delta);
|
||||
if (signum * delta < 1) {
|
||||
wheelRotation = signum;
|
||||
}
|
||||
// invert the wheelRotation for the peer
|
||||
eventNotifier.notifyMouseWheelEvent(when, x, y, absX, absY, modifiers,
|
||||
scrollType, scrollAmount,
|
||||
-wheelRotation, -delta, null);
|
||||
-roundDelta, -delta, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -260,4 +262,46 @@ final class CPlatformResponder {
|
||||
void handleWindowFocusEvent(boolean gained, LWWindowPeer opposite) {
|
||||
eventNotifier.notifyActivation(gained, opposite);
|
||||
}
|
||||
|
||||
static class DeltaAccumulator {
|
||||
|
||||
static final double MIN_THRESHOLD = 0.1;
|
||||
static final double MAX_THRESHOLD = 0.5;
|
||||
double accumulatedDelta;
|
||||
|
||||
int getRoundedDelta(double delta, int scrollPhase) {
|
||||
|
||||
int roundDelta = (int) Math.round(delta);
|
||||
|
||||
if (scrollPhase == NSEvent.SCROLL_PHASE_UNSUPPORTED) { // mouse wheel
|
||||
if (roundDelta == 0 && delta != 0) {
|
||||
roundDelta = delta > 0 ? 1 : -1;
|
||||
}
|
||||
} else { // trackpad
|
||||
boolean begin = scrollPhase == NSEvent.SCROLL_PHASE_BEGAN;
|
||||
boolean end = scrollPhase == NSEvent.SCROLL_MASK_PHASE_ENDED
|
||||
|| scrollPhase == NSEvent.SCROLL_MASK_PHASE_CANCELLED;
|
||||
|
||||
if (begin) {
|
||||
accumulatedDelta = 0;
|
||||
}
|
||||
|
||||
accumulatedDelta += delta;
|
||||
|
||||
double absAccumulatedDelta = Math.abs(accumulatedDelta);
|
||||
if (absAccumulatedDelta > MAX_THRESHOLD) {
|
||||
roundDelta = (int) Math.round(accumulatedDelta);
|
||||
accumulatedDelta -= roundDelta;
|
||||
}
|
||||
|
||||
if (end) {
|
||||
if (roundDelta == 0 && absAccumulatedDelta > MIN_THRESHOLD) {
|
||||
roundDelta = accumulatedDelta > 0 ? 1 : -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return roundDelta;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,7 +194,8 @@ public class CPlatformView extends CFRetainedResource {
|
||||
|
||||
if (event.getType() == CocoaConstants.NSScrollWheel) {
|
||||
responder.handleScrollEvent(x, y, absX, absY, event.getModifierFlags(),
|
||||
event.getScrollDeltaX(), event.getScrollDeltaY());
|
||||
event.getScrollDeltaX(), event.getScrollDeltaY(),
|
||||
event.getScrollPhase());
|
||||
} else {
|
||||
responder.handleMouseEvent(event.getType(), event.getModifierFlags(), event.getButtonNumber(),
|
||||
event.getClickCount(), x, y,
|
||||
|
||||
@ -32,6 +32,13 @@ import java.awt.event.*;
|
||||
* JDK functionality.
|
||||
*/
|
||||
final class NSEvent {
|
||||
|
||||
static final int SCROLL_PHASE_UNSUPPORTED = 1;
|
||||
static final int SCROLL_PHASE_BEGAN = 2;
|
||||
static final int SCROLL_PHASE_CONTINUED = 3;
|
||||
static final int SCROLL_MASK_PHASE_CANCELLED = 4;
|
||||
static final int SCROLL_MASK_PHASE_ENDED = 5;
|
||||
|
||||
private int type;
|
||||
private int modifierFlags;
|
||||
|
||||
@ -42,6 +49,7 @@ final class NSEvent {
|
||||
private int y;
|
||||
private double scrollDeltaY;
|
||||
private double scrollDeltaX;
|
||||
private int scrollPhase;
|
||||
private int absX;
|
||||
private int absY;
|
||||
|
||||
@ -62,7 +70,7 @@ final class NSEvent {
|
||||
// Called from native
|
||||
NSEvent(int type, int modifierFlags, int clickCount, int buttonNumber,
|
||||
int x, int y, int absX, int absY,
|
||||
double scrollDeltaY, double scrollDeltaX) {
|
||||
double scrollDeltaY, double scrollDeltaX, int scrollPhase) {
|
||||
this.type = type;
|
||||
this.modifierFlags = modifierFlags;
|
||||
this.clickCount = clickCount;
|
||||
@ -73,6 +81,7 @@ final class NSEvent {
|
||||
this.absY = absY;
|
||||
this.scrollDeltaY = scrollDeltaY;
|
||||
this.scrollDeltaX = scrollDeltaX;
|
||||
this.scrollPhase = scrollPhase;
|
||||
}
|
||||
|
||||
int getType() {
|
||||
@ -107,6 +116,10 @@ final class NSEvent {
|
||||
return scrollDeltaX;
|
||||
}
|
||||
|
||||
int getScrollPhase() {
|
||||
return scrollPhase;
|
||||
}
|
||||
|
||||
int getAbsX() {
|
||||
return absX;
|
||||
}
|
||||
|
||||
@ -383,7 +383,7 @@ static BOOL shouldUsePressAndHold() {
|
||||
}
|
||||
|
||||
static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/NSEvent");
|
||||
static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IIIIIIIIDD)V");
|
||||
static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IIIIIIIIDDI)V");
|
||||
jobject jEvent = JNFNewObject(env, jctor_NSEvent,
|
||||
[event type],
|
||||
[event modifierFlags],
|
||||
@ -392,7 +392,8 @@ static BOOL shouldUsePressAndHold() {
|
||||
(jint)localPoint.x, (jint)localPoint.y,
|
||||
(jint)absP.x, (jint)absP.y,
|
||||
[event deltaY],
|
||||
[event deltaX]);
|
||||
[event deltaX],
|
||||
[AWTToolkit scrollStateWithEvent: event]);
|
||||
CHECK_NULL(jEvent);
|
||||
|
||||
static JNF_CLASS_CACHE(jc_PlatformView, "sun/lwawt/macosx/CPlatformView");
|
||||
|
||||
@ -317,7 +317,7 @@ AWT_ASSERT_APPKIT_THREAD;
|
||||
[self setPropertiesForStyleBits:styleBits mask:MASK(_METHOD_PROP_BITMASK)];
|
||||
|
||||
if (IS(self.styleBits, IS_POPUP)) {
|
||||
[self.nsWindow setCollectionBehavior:(1 << 8) /*NSWindowCollectionBehaviorFullScreenAuxiliary*/];
|
||||
[self.nsWindow setCollectionBehavior:(1 << 8) /*NSWindowCollectionBehaviorFullScreenAuxiliary*/];
|
||||
}
|
||||
|
||||
return self;
|
||||
@ -330,7 +330,7 @@ AWT_ASSERT_APPKIT_THREAD;
|
||||
// returns id for the topmost window under mouse
|
||||
+ (NSInteger) getTopmostWindowUnderMouseID {
|
||||
NSInteger result = -1;
|
||||
|
||||
|
||||
NSRect screenRect = [[NSScreen mainScreen] frame];
|
||||
NSPoint nsMouseLocation = [NSEvent mouseLocation];
|
||||
CGPoint cgMouseLocation = CGPointMake(nsMouseLocation.x, screenRect.size.height - nsMouseLocation.y);
|
||||
@ -433,18 +433,18 @@ AWT_ASSERT_APPKIT_THREAD;
|
||||
// Tests wheather the corresponding Java paltform window is visible or not
|
||||
+ (BOOL) isJavaPlatformWindowVisible:(NSWindow *)window {
|
||||
BOOL isVisible = NO;
|
||||
|
||||
|
||||
if ([AWTWindow isAWTWindow:window] && [window delegate] != nil) {
|
||||
AWTWindow *awtWindow = (AWTWindow *)[window delegate];
|
||||
[AWTToolkit eventCountPlusPlus];
|
||||
|
||||
|
||||
JNIEnv *env = [ThreadUtilities getJNIEnv];
|
||||
jobject platformWindow = [awtWindow.javaPlatformWindow jObjectWithEnv:env];
|
||||
if (platformWindow != NULL) {
|
||||
static JNF_MEMBER_CACHE(jm_isVisible, jc_CPlatformWindow, "isVisible", "()Z");
|
||||
isVisible = JNFCallBooleanMethod(env, platformWindow, jm_isVisible) == JNI_TRUE ? YES : NO;
|
||||
(*env)->DeleteLocalRef(env, platformWindow);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
return isVisible;
|
||||
@ -577,7 +577,9 @@ AWT_ASSERT_APPKIT_THREAD;
|
||||
- (NSRect)windowWillUseStandardFrame:(NSWindow *)window
|
||||
defaultFrame:(NSRect)newFrame {
|
||||
|
||||
return [self standardFrame];
|
||||
return NSEqualSizes(NSZeroSize, [self standardFrame].size)
|
||||
? newFrame
|
||||
: [self standardFrame];
|
||||
}
|
||||
|
||||
// Hides/shows window's childs during iconify/de-iconify operation
|
||||
@ -1085,17 +1087,17 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowSt
|
||||
jdouble width, jdouble height)
|
||||
{
|
||||
JNF_COCOA_ENTER(env);
|
||||
|
||||
|
||||
NSRect jrect = NSMakeRect(originX, originY, width, height);
|
||||
|
||||
|
||||
NSWindow *nsWindow = OBJC(windowPtr);
|
||||
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
|
||||
|
||||
|
||||
NSRect rect = ConvertNSScreenRect(NULL, jrect);
|
||||
AWTWindow *window = (AWTWindow*)[nsWindow delegate];
|
||||
window.standardFrame = rect;
|
||||
}];
|
||||
|
||||
|
||||
JNF_COCOA_EXIT(env);
|
||||
}
|
||||
|
||||
@ -1366,7 +1368,7 @@ JNF_COCOA_ENTER(env);
|
||||
} else {
|
||||
[JNFException raise:env as:kIllegalArgumentException reason:"unknown event type"];
|
||||
}
|
||||
|
||||
|
||||
JNF_COCOA_EXIT(env);
|
||||
}
|
||||
|
||||
@ -1476,7 +1478,7 @@ JNF_COCOA_ENTER(env);
|
||||
|
||||
if (CGDisplayRelease(aID) == kCGErrorSuccess) {
|
||||
NSUInteger styleMask = [AWTWindow styleMaskForStyleBits:window.styleBits];
|
||||
[nsWindow setStyleMask:styleMask];
|
||||
[nsWindow setStyleMask:styleMask];
|
||||
[nsWindow setLevel: window.preFullScreenLevel];
|
||||
|
||||
// GraphicsDevice takes care of restoring pre full screen bounds
|
||||
|
||||
@ -45,7 +45,7 @@
|
||||
self = [super init];
|
||||
|
||||
if (nil != self) {
|
||||
javaToMacKeyMap = [NSDictionary dictionaryWithObjectsAndKeys :
|
||||
self.javaToMacKeyMap = [NSDictionary dictionaryWithObjectsAndKeys :
|
||||
[NSNumber numberWithInt : OSX_Delete], [NSNumber numberWithInt : java_awt_event_KeyEvent_VK_BACK_SPACE],
|
||||
[NSNumber numberWithInt : OSX_kVK_Tab], [NSNumber numberWithInt : java_awt_event_KeyEvent_VK_TAB],
|
||||
[NSNumber numberWithInt : OSX_kVK_Return], [NSNumber numberWithInt : java_awt_event_KeyEvent_VK_ENTER],
|
||||
|
||||
@ -139,9 +139,9 @@ static NSSize ScaledImageSizeForStatusBar(NSSize imageSize, BOOL autosize) {
|
||||
jint clickCount;
|
||||
|
||||
clickCount = [event clickCount];
|
||||
|
||||
|
||||
static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/NSEvent");
|
||||
static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IIIIIIIIDD)V");
|
||||
static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IIIIIIIIDDI)V");
|
||||
jobject jEvent = JNFNewObject(env, jctor_NSEvent,
|
||||
[event type],
|
||||
[event modifierFlags],
|
||||
@ -150,7 +150,8 @@ static NSSize ScaledImageSizeForStatusBar(NSSize imageSize, BOOL autosize) {
|
||||
(jint)localPoint.x, (jint)localPoint.y,
|
||||
(jint)absP.x, (jint)absP.y,
|
||||
[event deltaY],
|
||||
[event deltaX]);
|
||||
[event deltaX],
|
||||
[AWTToolkit scrollStateWithEvent: event]);
|
||||
CHECK_NULL(jEvent);
|
||||
|
||||
static JNF_CLASS_CACHE(jc_TrayIcon, "sun/lwawt/macosx/CTrayIcon");
|
||||
|
||||
@ -66,7 +66,6 @@ static JNF_CLASS_CACHE(sjc_CAccessible, "sun/lwawt/macosx/CAccessible");
|
||||
static JNF_MEMBER_CACHE(jf_ptr, sjc_CAccessible, "ptr", "J");
|
||||
static JNF_STATIC_MEMBER_CACHE(sjm_getCAccessible, sjc_CAccessible, "getCAccessible", "(Ljavax/accessibility/Accessible;)Lsun/lwawt/macosx/CAccessible;");
|
||||
|
||||
|
||||
static jobject sAccessibilityClass = NULL;
|
||||
|
||||
// sAttributeNamesForRoleCache holds the names of the attributes to which each java
|
||||
@ -213,6 +212,24 @@ static NSObject *sAttributeNamesLOCK = nil;
|
||||
NSAccessibilityPostNotification(self, NSAccessibilitySelectedChildrenChangedNotification);
|
||||
}
|
||||
|
||||
- (void)postMenuOpened
|
||||
{
|
||||
AWT_ASSERT_APPKIT_THREAD;
|
||||
NSAccessibilityPostNotification(self, (NSString *)kAXMenuOpenedNotification);
|
||||
}
|
||||
|
||||
- (void)postMenuClosed
|
||||
{
|
||||
AWT_ASSERT_APPKIT_THREAD;
|
||||
NSAccessibilityPostNotification(self, (NSString *)kAXMenuClosedNotification);
|
||||
}
|
||||
|
||||
- (void)postMenuItemSelected
|
||||
{
|
||||
AWT_ASSERT_APPKIT_THREAD;
|
||||
NSAccessibilityPostNotification(self, (NSString *)kAXMenuItemSelectedNotification);
|
||||
}
|
||||
|
||||
- (BOOL)isEqual:(id)anObject
|
||||
{
|
||||
if (![anObject isKindOfClass:[self class]]) return NO;
|
||||
@ -278,8 +295,7 @@ static NSObject *sAttributeNamesLOCK = nil;
|
||||
+ (jobject) getCAccessible:(jobject)jaccessible withEnv:(JNIEnv *)env {
|
||||
if (JNFIsInstanceOf(env, jaccessible, &sjc_CAccessible)) {
|
||||
return jaccessible;
|
||||
}
|
||||
else if (JNFIsInstanceOf(env, jaccessible, &sjc_Accessible)) {
|
||||
} else if (JNFIsInstanceOf(env, jaccessible, &sjc_Accessible)) {
|
||||
return JNFCallStaticObjectMethod(env, sjm_getCAccessible, jaccessible);
|
||||
}
|
||||
return NULL;
|
||||
@ -368,6 +384,14 @@ static NSObject *sAttributeNamesLOCK = nil;
|
||||
// must init freshly -alloc'd object
|
||||
[newChild initWithParent:parent withEnv:env withAccessible:jCAX withIndex:index withView:view withJavaRole:javaRole]; // must init new instance
|
||||
|
||||
// If creating a JPopupMenu (not a combobox popup list) need to fire menuOpened.
|
||||
// This is the only way to know if the menu is opening; visible state change
|
||||
// can't be caught because the listeners are not set up in time.
|
||||
if ( [javaRole isEqualToString:@"popupmenu"] &&
|
||||
![[parent javaRole] isEqualToString:@"combobox"] ) {
|
||||
[newChild postMenuOpened];
|
||||
}
|
||||
|
||||
// must hard retain pointer poked into Java object
|
||||
[newChild retain];
|
||||
JNFSetLongField(env, jCAX, jf_ptr, ptr_to_jlong(newChild));
|
||||
@ -634,6 +658,15 @@ static NSObject *sAttributeNamesLOCK = nil;
|
||||
return moreNames;
|
||||
}
|
||||
}
|
||||
// popupmenu's return values not selected children
|
||||
if ( [javaRole isEqualToString:@"popupmenu"] &&
|
||||
![[[self parent] javaRole] isEqualToString:@"combobox"] ) {
|
||||
NSMutableArray *moreNames =
|
||||
[[NSMutableArray alloc] initWithCapacity: [names count] + 1];
|
||||
[moreNames addObjectsFromArray: names];
|
||||
[moreNames addObject:NSAccessibilityValueAttribute];
|
||||
return moreNames;
|
||||
}
|
||||
return names;
|
||||
|
||||
} // end @synchronized
|
||||
@ -707,6 +740,7 @@ static NSObject *sAttributeNamesLOCK = nil;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
- (BOOL)accessibilityIsChildrenAttributeSettable
|
||||
{
|
||||
return NO;
|
||||
@ -939,6 +973,13 @@ static NSObject *sAttributeNamesLOCK = nil;
|
||||
if (fNSRole == nil) {
|
||||
NSString *javaRole = [self javaRole];
|
||||
fNSRole = [sRoles objectForKey:javaRole];
|
||||
// The sRoles NSMutableDictionary maps popupmenu to Mac's popup button.
|
||||
// JComboBox behavior currently relies on this. However this is not the
|
||||
// proper mapping for a JPopupMenu so fix that.
|
||||
if ( [javaRole isEqualToString:@"popupmenu"] &&
|
||||
![[[self parent] javaRole] isEqualToString:@"combobox"] ) {
|
||||
fNSRole = NSAccessibilityMenuRole;
|
||||
}
|
||||
if (fNSRole == nil) {
|
||||
// this component has assigned itself a custom AccessibleRole not in the sRoles array
|
||||
fNSRole = javaRole;
|
||||
@ -947,6 +988,7 @@ static NSObject *sAttributeNamesLOCK = nil;
|
||||
}
|
||||
return fNSRole;
|
||||
}
|
||||
|
||||
- (BOOL)accessibilityIsRoleAttributeSettable
|
||||
{
|
||||
return NO;
|
||||
@ -1046,8 +1088,7 @@ static NSObject *sAttributeNamesLOCK = nil;
|
||||
- (NSString *)accessibilitySubroleAttribute
|
||||
{
|
||||
NSString *value = nil;
|
||||
if ([[self javaRole] isEqualToString:@"passwordtext"])
|
||||
{
|
||||
if ([[self javaRole] isEqualToString:@"passwordtext"]) {
|
||||
value = NSAccessibilitySecureTextFieldSubrole;
|
||||
}
|
||||
/*
|
||||
@ -1123,6 +1164,45 @@ static NSObject *sAttributeNamesLOCK = nil;
|
||||
|
||||
JNIEnv* env = [ThreadUtilities getJNIEnv];
|
||||
|
||||
// Need to handle popupmenus differently.
|
||||
//
|
||||
// At least for now don't handle combo box menus.
|
||||
// This may change when later fixing issues which currently
|
||||
// exist for combo boxes, but for now the following is only
|
||||
// for JPopupMenus, not for combobox menus.
|
||||
id parent = [self parent];
|
||||
if ( [[self javaRole] isEqualToString:@"popupmenu"] &&
|
||||
![[parent javaRole] isEqualToString:@"combobox"] ) {
|
||||
NSArray *children =
|
||||
[JavaComponentAccessibility childrenOfParent:self
|
||||
withEnv:env
|
||||
withChildrenCode:JAVA_AX_ALL_CHILDREN
|
||||
allowIgnored:YES];
|
||||
if ([children count] > 0) {
|
||||
// handle case of AXMenuItem
|
||||
// need to ask menu what is selected
|
||||
NSArray *selectedChildrenOfMenu =
|
||||
[self accessibilitySelectedChildrenAttribute];
|
||||
JavaComponentAccessibility *selectedMenuItem =
|
||||
[selectedChildrenOfMenu objectAtIndex:0];
|
||||
if (selectedMenuItem != nil) {
|
||||
jobject itemValue =
|
||||
JNFCallStaticObjectMethod( env,
|
||||
sjm_getAccessibleName,
|
||||
selectedMenuItem->fAccessible,
|
||||
selectedMenuItem->fComponent ); // AWT_THREADING Safe (AWTRunLoop)
|
||||
if (itemValue == NULL) {
|
||||
return nil;
|
||||
}
|
||||
NSString* itemString = JNFJavaToNSString(env, itemValue);
|
||||
(*env)->DeleteLocalRef(env, itemValue);
|
||||
return itemString;
|
||||
} else {
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ask Java for the component's accessibleValue. In java, the "accessibleValue" just means a numerical value
|
||||
// a text value is taken care of in JavaTextAccessibility
|
||||
|
||||
@ -1343,6 +1423,54 @@ JNF_COCOA_ENTER(env);
|
||||
JNF_COCOA_EXIT(env);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: sun_lwawt_macosx_CAccessible
|
||||
* Method: menuOpened
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CAccessible_menuOpened
|
||||
(JNIEnv *env, jclass jklass, jlong element)
|
||||
{
|
||||
JNF_COCOA_ENTER(env);
|
||||
[ThreadUtilities performOnMainThread:@selector(postMenuOpened)
|
||||
on:(JavaComponentAccessibility *)jlong_to_ptr(element)
|
||||
withObject:nil
|
||||
waitUntilDone:NO];
|
||||
JNF_COCOA_EXIT(env);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: sun_lwawt_macosx_CAccessible
|
||||
* Method: menuClosed
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CAccessible_menuClosed
|
||||
(JNIEnv *env, jclass jklass, jlong element)
|
||||
{
|
||||
JNF_COCOA_ENTER(env);
|
||||
[ThreadUtilities performOnMainThread:@selector(postMenuClosed)
|
||||
on:(JavaComponentAccessibility *)jlong_to_ptr(element)
|
||||
withObject:nil
|
||||
waitUntilDone:NO];
|
||||
JNF_COCOA_EXIT(env);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: sun_lwawt_macosx_CAccessible
|
||||
* Method: menuItemSelected
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CAccessible_menuItemSelected
|
||||
(JNIEnv *env, jclass jklass, jlong element)
|
||||
{
|
||||
JNF_COCOA_ENTER(env);
|
||||
[ThreadUtilities performOnMainThread:@selector(postMenuItemSelected)
|
||||
on:(JavaComponentAccessibility *)jlong_to_ptr(element)
|
||||
withObject:nil
|
||||
waitUntilDone:NO];
|
||||
JNF_COCOA_EXIT(env);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: sun_lwawt_macosx_CAccessible
|
||||
* Method: unregisterFromCocoaAXSystem
|
||||
|
||||
@ -41,6 +41,7 @@ extern jint* gButtonDownMasks;
|
||||
@interface AWTToolkit : NSObject { }
|
||||
+ (long) getEventCount;
|
||||
+ (void) eventCountPlusPlus;
|
||||
+ (jint) scrollStateWithEvent: (NSEvent*) event;
|
||||
@end
|
||||
|
||||
/*
|
||||
|
||||
@ -43,6 +43,13 @@
|
||||
|
||||
#import <JavaRuntimeSupport/JavaRuntimeSupport.h>
|
||||
|
||||
// SCROLL PHASE STATE
|
||||
#define SCROLL_PHASE_UNSUPPORTED 1
|
||||
#define SCROLL_PHASE_BEGAN 2
|
||||
#define SCROLL_PHASE_CONTINUED 3
|
||||
#define SCROLL_PHASE_CANCELLED 4
|
||||
#define SCROLL_PHASE_ENDED 5
|
||||
|
||||
int gNumberOfButtons;
|
||||
jint* gButtonDownMasks;
|
||||
|
||||
@ -72,6 +79,23 @@ static long eventCount;
|
||||
eventCount++;
|
||||
}
|
||||
|
||||
+ (jint) scrollStateWithEvent: (NSEvent*) event {
|
||||
|
||||
if ([event type] != NSScrollWheel) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
NSEventPhase phase = [event phase];
|
||||
NSEventPhase momentumPhase = [event momentumPhase];
|
||||
|
||||
if (!phase && !momentumPhase) return SCROLL_PHASE_UNSUPPORTED;
|
||||
switch (phase) {
|
||||
case NSEventPhaseBegan: return SCROLL_PHASE_BEGAN;
|
||||
case NSEventPhaseCancelled: return SCROLL_PHASE_CANCELLED;
|
||||
case NSEventPhaseEnded: return SCROLL_PHASE_ENDED;
|
||||
default: return SCROLL_PHASE_CONTINUED;
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@ -193,6 +193,44 @@ GetFamilyNameForFontName(NSString* fontname)
|
||||
return [sFontFamilyTable objectForKey:fontname];
|
||||
}
|
||||
|
||||
static void addFont(CTFontUIFontType uiType,
|
||||
NSMutableArray *allFonts,
|
||||
NSMutableDictionary* fontFamilyTable) {
|
||||
|
||||
CTFontRef font = CTFontCreateUIFontForLanguage(uiType, 0.0, NULL);
|
||||
if (font == NULL) {
|
||||
return;
|
||||
}
|
||||
CTFontDescriptorRef desc = CTFontCopyFontDescriptor(font);
|
||||
if (desc == NULL) {
|
||||
CFRelease(font);
|
||||
return;
|
||||
}
|
||||
CFStringRef family = CTFontDescriptorCopyAttribute(desc, kCTFontFamilyNameAttribute);
|
||||
if (family == NULL) {
|
||||
CFRelease(desc);
|
||||
CFRelease(font);
|
||||
return;
|
||||
}
|
||||
CFStringRef name = CTFontDescriptorCopyAttribute(desc, kCTFontNameAttribute);
|
||||
if (name == NULL) {
|
||||
CFRelease(family);
|
||||
CFRelease(desc);
|
||||
CFRelease(font);
|
||||
return;
|
||||
}
|
||||
[allFonts addObject:name];
|
||||
[fontFamilyTable setObject:family forKey:name];
|
||||
#ifdef DEBUG
|
||||
NSLog(@"name is : %@", (NSString*)name);
|
||||
NSLog(@"family is : %@", (NSString*)family);
|
||||
#endif
|
||||
CFRelease(family);
|
||||
CFRelease(name);
|
||||
CFRelease(desc);
|
||||
CFRelease(font);
|
||||
}
|
||||
|
||||
static NSArray*
|
||||
GetFilteredFonts()
|
||||
{
|
||||
@ -227,6 +265,16 @@ GetFilteredFonts()
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* JavaFX registers these fonts and so JDK needs to do so as well.
|
||||
* If this isn't done we will have mis-matched rendering, since
|
||||
* although these may include fonts that are enumerated normally
|
||||
* they also demonstrably includes fonts that are not.
|
||||
*/
|
||||
addFont(kCTFontUIFontSystem, allFonts, fontFamilyTable);
|
||||
addFont(kCTFontUIFontEmphasizedSystem, allFonts, fontFamilyTable);
|
||||
addFont(kCTFontUIFontUserFixedPitch, allFonts, fontFamilyTable);
|
||||
|
||||
sFilteredFonts = allFonts;
|
||||
sFontFamilyTable = fontFamilyTable;
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -47,6 +47,10 @@
|
||||
#include <sizecalc.h>
|
||||
#import "ThreadUtilities.h"
|
||||
|
||||
NSString* findScaledImageName(NSString *fileName,
|
||||
NSUInteger dotIndex,
|
||||
NSString *strToAppend);
|
||||
|
||||
static NSScreen* SplashNSScreen()
|
||||
{
|
||||
return [[NSScreen screens] objectAtIndex: 0];
|
||||
@ -134,8 +138,8 @@ BOOL isSWTRunning() {
|
||||
}
|
||||
|
||||
jboolean SplashGetScaledImageName(const char* jar, const char* file,
|
||||
float *scaleFactor, char *scaledFile,
|
||||
const size_t scaledImageLength) {
|
||||
float *scaleFactor, char *scaledFile,
|
||||
const size_t scaledImageLength) {
|
||||
*scaleFactor = 1;
|
||||
|
||||
if(isSWTRunning()){
|
||||
@ -158,18 +162,14 @@ jboolean SplashGetScaledImageName(const char* jar, const char* file,
|
||||
options:NSBackwardsSearch];
|
||||
NSUInteger dotIndex = range.location;
|
||||
NSString *fileName2x = nil;
|
||||
|
||||
if (dotIndex == NSNotFound) {
|
||||
fileName2x = [fileName stringByAppendingString: @"@2x"];
|
||||
} else {
|
||||
fileName2x = [fileName substringToIndex: dotIndex];
|
||||
fileName2x = [fileName2x stringByAppendingString: @"@2x"];
|
||||
fileName2x = [fileName2x stringByAppendingString:
|
||||
[fileName substringFromIndex: dotIndex]];
|
||||
|
||||
fileName2x = findScaledImageName(fileName, dotIndex, @"@2x");
|
||||
if(![[NSFileManager defaultManager]
|
||||
fileExistsAtPath: fileName2x]) {
|
||||
fileName2x = findScaledImageName(fileName, dotIndex, @"@200pct");
|
||||
}
|
||||
|
||||
if ((fileName2x != nil) && (jar || [[NSFileManager defaultManager]
|
||||
fileExistsAtPath: fileName2x])){
|
||||
if (jar || [[NSFileManager defaultManager]
|
||||
fileExistsAtPath: fileName2x]){
|
||||
if (strlen([fileName2x UTF8String]) > scaledImageLength) {
|
||||
[pool drain];
|
||||
return JNI_FALSE;
|
||||
@ -458,3 +458,16 @@ SplashReconfigure(Splash * splash) {
|
||||
sendctl(splash, SPLASHCTL_RECONFIGURE);
|
||||
}
|
||||
|
||||
NSString* findScaledImageName(NSString *fileName, NSUInteger dotIndex, NSString *strToAppend) {
|
||||
NSString *fileName2x = nil;
|
||||
if (dotIndex == NSNotFound) {
|
||||
fileName2x = [fileName stringByAppendingString: strToAppend];
|
||||
} else {
|
||||
fileName2x = [fileName substringToIndex: dotIndex];
|
||||
fileName2x = [fileName2x stringByAppendingString: strToAppend];
|
||||
fileName2x = [fileName2x stringByAppendingString:
|
||||
[fileName substringFromIndex: dotIndex]];
|
||||
}
|
||||
return fileName2x;
|
||||
}
|
||||
|
||||
|
||||
@ -1314,7 +1314,7 @@ class GIFImageWriteParam extends ImageWriteParam {
|
||||
super(locale);
|
||||
this.canWriteCompressed = true;
|
||||
this.canWriteProgressive = true;
|
||||
this.compressionTypes = new String[] {"LZW", "lzw"};
|
||||
this.compressionTypes = new String[] {"LZW"};
|
||||
this.compressionType = compressionTypes[0];
|
||||
}
|
||||
|
||||
|
||||
@ -298,31 +298,24 @@ public class MotifComboBoxUI extends BasicComboBoxUI implements Serializable {
|
||||
public void paintIcon(Component c, Graphics g, int xo, int yo) {
|
||||
int w = getIconWidth();
|
||||
int h = getIconHeight();
|
||||
int x1 = xo + w - 1;
|
||||
int y1 = yo;
|
||||
int x2 = xo + w / 2;
|
||||
int y2 = yo + h - 1;
|
||||
|
||||
g.setColor(fill);
|
||||
g.fillPolygon(new int[]{xo, x1, x2}, new int[]{yo, y1, y2}, 3);
|
||||
g.setColor(lightShadow);
|
||||
g.drawLine(xo, yo, xo+w-1, yo);
|
||||
g.drawLine(xo, yo+1, xo+w-3, yo+1);
|
||||
g.setColor(darkShadow);
|
||||
g.drawLine(xo+w-2, yo+1, xo+w-1, yo+1);
|
||||
|
||||
for ( int x = xo+1, y = yo+2, dx = w-6; y+1 < yo+h; y += 2 ) {
|
||||
g.setColor(lightShadow);
|
||||
g.drawLine(x, y, x+1, y);
|
||||
g.drawLine(x, y+1, x+1, y+1);
|
||||
if ( dx > 0 ) {
|
||||
g.setColor(fill);
|
||||
g.drawLine(x+2, y, x+1+dx, y);
|
||||
g.drawLine(x+2, y+1, x+1+dx, y+1);
|
||||
}
|
||||
g.setColor(darkShadow);
|
||||
g.drawLine(x+dx+2, y, x+dx+3, y);
|
||||
g.drawLine(x+dx+2, y+1, x+dx+3, y+1);
|
||||
x += 1;
|
||||
dx -= 2;
|
||||
}
|
||||
g.drawLine(xo, yo, x1, y1);
|
||||
|
||||
g.drawLine(xo, yo + 1, x2, y2);
|
||||
g.drawLine(xo, yo + 1, x1, y1 + 1);
|
||||
g.drawLine(xo + 1, yo + 1, x2, y2 - 1);
|
||||
g.setColor(darkShadow);
|
||||
g.drawLine(xo+(w/2), yo+h-1, xo+(w/2), yo+h-1);
|
||||
g.drawLine(x1, y1 + 1, x2, y2);
|
||||
g.drawLine(x1 - 1, y1 + 1, x2, y2 - 1);
|
||||
g.drawLine(x1 - 1, y1 + 1, x1, y1 + 1); // corner
|
||||
g.drawLine(x2, y2, x2, y2); // corner
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -249,17 +249,11 @@ public class MotifIconFactory implements Serializable
|
||||
if (check) {
|
||||
// draw check
|
||||
g.setColor(foreground);
|
||||
g.drawLine(csize-2,1,csize-2,2);
|
||||
g.drawLine(csize-3,2,csize-3,3);
|
||||
g.drawLine(csize-4,3,csize-4,4);
|
||||
g.drawLine(csize-5,4,csize-5,6);
|
||||
g.drawLine(csize-6,5,csize-6,8);
|
||||
g.drawLine(csize-7,6,csize-7,10);
|
||||
g.drawLine(csize-8,7,csize-8,10);
|
||||
g.drawLine(csize-9,6,csize-9,9);
|
||||
g.drawLine(csize-10,5,csize-10,8);
|
||||
g.drawLine(csize-11,5,csize-11,7);
|
||||
g.drawLine(csize-12,6,csize-12,6);
|
||||
int[] xa = {csize - 12, csize - 8, csize - 7, csize - 4,
|
||||
csize - 2, csize - 2, csize - 8, csize - 10,
|
||||
csize - 11};
|
||||
int[] ya = new int[]{6, 10, 10, 4, 2, 1, 7, 5, 5};
|
||||
g.fillPolygon(xa, ya, 9);
|
||||
}
|
||||
g.translate(-x, -y);
|
||||
g.setColor(oldColor);
|
||||
@ -301,50 +295,18 @@ public class MotifIconFactory implements Serializable
|
||||
|
||||
if (checkIn){
|
||||
g.setColor(shadow);
|
||||
g.drawLine(x+5,y+0,x+8,y+0);
|
||||
g.drawLine(x+3,y+1,x+4,y+1);
|
||||
g.drawLine(x+9,y+1,x+9,y+1);
|
||||
g.drawLine(x+2,y+2,x+2,y+2);
|
||||
g.drawLine(x+1,y+3,x+1,y+3);
|
||||
g.drawLine(x,y+4,x,y+9);
|
||||
g.drawLine(x+1,y+10,x+1,y+10);
|
||||
g.drawLine(x+2,y+11,x+2,y+11);
|
||||
g.drawArc(x, y, w - 1, h - 1, 45, 180);
|
||||
g.setColor(highlight);
|
||||
g.drawLine(x+3,y+12,x+4,y+12);
|
||||
g.drawLine(x+5,y+13,x+8,y+13);
|
||||
g.drawLine(x+9,y+12,x+10,y+12);
|
||||
g.drawLine(x+11,y+11,x+11,y+11);
|
||||
g.drawLine(x+12,y+10,x+12,y+10);
|
||||
g.drawLine(x+13,y+9,x+13,y+4);
|
||||
g.drawLine(x+12,y+3,x+12,y+3);
|
||||
g.drawLine(x+11,y+2,x+11,y+2);
|
||||
g.drawLine(x+10,y+1,x+10,y+1);
|
||||
g.drawArc(x, y, w - 1, h - 1, 45, -180);
|
||||
g.setColor(dot);
|
||||
g.fillRect(x+4,y+5,6,4);
|
||||
g.drawLine(x+5,y+4,x+8,y+4);
|
||||
g.drawLine(x+5,y+9,x+8,y+9);
|
||||
g.fillOval(x + 3, y + 3, 7, 7);
|
||||
}
|
||||
else {
|
||||
g.setColor(highlight);
|
||||
g.drawLine(x+5,y+0,x+8,y+0);
|
||||
g.drawLine(x+3,y+1,x+4,y+1);
|
||||
g.drawLine(x+9,y+1,x+9,y+1);
|
||||
g.drawLine(x+2,y+2,x+2,y+2);
|
||||
g.drawLine(x+1,y+3,x+1,y+3);
|
||||
g.drawLine(x,y+4,x,y+9);
|
||||
g.drawLine(x+1,y+10,x+1,y+10);
|
||||
g.drawLine(x+2,y+11,x+2,y+11);
|
||||
g.drawArc(x, y, w - 1, h - 1, 45, 180);
|
||||
|
||||
g.setColor(shadow);
|
||||
g.drawLine(x+3,y+12,x+4,y+12);
|
||||
g.drawLine(x+5,y+13,x+8,y+13);
|
||||
g.drawLine(x+9,y+12,x+10,y+12);
|
||||
g.drawLine(x+11,y+11,x+11,y+11);
|
||||
g.drawLine(x+12,y+10,x+12,y+10);
|
||||
g.drawLine(x+13,y+9,x+13,y+4);
|
||||
g.drawLine(x+12,y+3,x+12,y+3);
|
||||
g.drawLine(x+11,y+2,x+11,y+2);
|
||||
g.drawLine(x+10,y+1,x+10,y+1);
|
||||
g.drawArc(x, y, w - 1, h - 1, 45, -180);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -117,95 +117,57 @@ public class MotifScrollBarButton extends BasicArrowButton
|
||||
|
||||
switch (direction) {
|
||||
case NORTH:
|
||||
g.setColor(fill);
|
||||
g.fillPolygon(new int[]{cx, 0, s - 1}, new int[]{0, s - 1, s - 1}, 3);
|
||||
g.setColor(trail);
|
||||
g.drawLine(cx, 0, s - 1, s - 2);
|
||||
g.drawLine(0, s - 1, s - 1, s - 1);
|
||||
g.drawLine(s - 1, s - 2, s - 1, s - 1); // corner
|
||||
g.setColor(lead);
|
||||
g.drawLine(cx, 0, cx, 0);
|
||||
for (int x = cx - 1, y = 1, dx = 1; y <= s - 2; y += 2) {
|
||||
g.setColor(lead);
|
||||
g.drawLine(x, y, x, y);
|
||||
if (y >= (s - 2)) {
|
||||
g.drawLine(x, y + 1, x, y + 1);
|
||||
}
|
||||
g.setColor(fill);
|
||||
g.drawLine(x + 1, y, x + dx, y);
|
||||
if (y < (s - 2)) {
|
||||
g.drawLine(x, y + 1, x + dx + 1, y + 1);
|
||||
}
|
||||
g.setColor(trail);
|
||||
g.drawLine(x + dx + 1, y, x + dx + 1, y);
|
||||
if (y >= (s - 2)) {
|
||||
g.drawLine(x + 1, y + 1, x + dx + 1, y + 1);
|
||||
}
|
||||
dx += 2;
|
||||
x -= 1;
|
||||
}
|
||||
g.drawLine(cx, 0, 0, s - 2);
|
||||
g.drawLine(cx, 0, cx, 0); // corner
|
||||
g.drawLine(0, s - 1, 0, s - 1); // corner
|
||||
break;
|
||||
|
||||
case SOUTH:
|
||||
g.setColor(fill);
|
||||
g.fillPolygon(new int[]{0, s - 1, cx}, new int[]{1, 1, s}, 3);
|
||||
g.setColor(trail);
|
||||
g.drawLine(cx, s, cx, s);
|
||||
for (int x = cx - 1, y = s - 1, dx = 1; y >= 1; y -= 2) {
|
||||
g.setColor(lead);
|
||||
g.drawLine(x, y, x, y);
|
||||
if (y <= 2) {
|
||||
g.drawLine(x, y - 1, x + dx + 1, y - 1);
|
||||
}
|
||||
g.setColor(fill);
|
||||
g.drawLine(x + 1, y, x + dx, y);
|
||||
if (y > 2) {
|
||||
g.drawLine(x, y - 1, x + dx + 1, y - 1);
|
||||
}
|
||||
g.setColor(trail);
|
||||
g.drawLine(x + dx + 1, y, x + dx + 1, y);
|
||||
|
||||
dx += 2;
|
||||
x -= 1;
|
||||
}
|
||||
g.drawLine(s - 1, 2, cx, s);
|
||||
g.drawLine(s - 1, 2, s - 1, 2); // corner
|
||||
g.setColor(lead);
|
||||
g.drawLine(0, 2, cx, s);
|
||||
g.drawLine(0, 1, s - 1, 1);
|
||||
g.drawLine(0, 1, 0, 2);
|
||||
g.setColor(trail);
|
||||
g.drawLine(cx, s, cx, s); // corner
|
||||
break;
|
||||
|
||||
case EAST:
|
||||
g.setColor(fill);
|
||||
g.fillPolygon(new int[]{1, s, 1}, new int[]{0, cy, s}, 3);
|
||||
g.setColor(trail);
|
||||
g.drawLine(1, s, s, cy);
|
||||
g.drawLine(2, s, 2, s); // corner
|
||||
g.setColor(lead);
|
||||
g.drawLine(1, 0, 1, s);
|
||||
g.drawLine(2, 0, s, cy);
|
||||
g.drawLine(2, 0, 2, 0); // corner
|
||||
g.drawLine(s, cy, s, cy);
|
||||
for (int y = cy - 1, x = s - 1, dy = 1; x >= 1; x -= 2) {
|
||||
g.setColor(lead);
|
||||
g.drawLine(x, y, x, y);
|
||||
if (x <= 2) {
|
||||
g.drawLine(x - 1, y, x - 1, y + dy + 1);
|
||||
}
|
||||
g.setColor(fill);
|
||||
g.drawLine(x, y + 1, x, y + dy);
|
||||
if (x > 2) {
|
||||
g.drawLine(x - 1, y, x - 1, y + dy + 1);
|
||||
}
|
||||
g.setColor(trail);
|
||||
g.drawLine(x, y + dy + 1, x, y + dy + 1);
|
||||
|
||||
dy += 2;
|
||||
y -= 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case WEST:
|
||||
g.setColor(fill);
|
||||
g.fillPolygon(new int[]{0, s - 1, s - 1}, new int[]{cy, 0, s}, 3);
|
||||
g.drawLine(s - 1, 0, s - 1, s);
|
||||
g.setColor(trail);
|
||||
g.drawLine(0, cy, 0, cy);
|
||||
for (int y = cy - 1, x = 1, dy = 1; x <= s - 2; x += 2) {
|
||||
g.setColor(lead);
|
||||
g.drawLine(x, y, x, y);
|
||||
if (x >= (s - 2)) {
|
||||
g.drawLine(x + 1, y, x + 1, y);
|
||||
}
|
||||
g.setColor(fill);
|
||||
g.drawLine(x, y + 1, x, y + dy);
|
||||
if (x < (s - 2)) {
|
||||
g.drawLine(x + 1, y, x + 1, y + dy + 1);
|
||||
}
|
||||
g.setColor(trail);
|
||||
g.drawLine(x, y + dy + 1, x, y + dy + 1);
|
||||
if (x >= (s - 2)) {
|
||||
g.drawLine(x + 1, y + 1, x + 1, y + dy + 1);
|
||||
}
|
||||
dy += 2;
|
||||
y -= 1;
|
||||
}
|
||||
g.drawLine(0, cy, s - 1, s);
|
||||
g.drawLine(s - 1, 0, s - 1, s);
|
||||
g.setColor(lead);
|
||||
g.drawLine(0, cy, s - 2, 0);
|
||||
g.drawLine(s - 2, 0, s - 1, 0); // corner
|
||||
g.setColor(trail);
|
||||
g.drawLine(0, cy, 0, cy); // corner
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2016, 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,25 +30,26 @@ import java.util.Objects;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.sound.sampled.AudioFormat;
|
||||
import javax.sound.sampled.AudioFormat.Encoding;
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.spi.FormatConversionProvider;
|
||||
|
||||
/**
|
||||
* A-law encodes linear data, and decodes a-law data to linear data.
|
||||
*
|
||||
* @author Kara Kytle
|
||||
*/
|
||||
public final class AlawCodec extends SunCodec {
|
||||
public final class AlawCodec extends FormatConversionProvider {
|
||||
|
||||
/* Tables used for A-law decoding */
|
||||
|
||||
private static final byte[] ALAW_TABH = new byte[256];
|
||||
private static final byte[] ALAW_TABL = new byte[256];
|
||||
|
||||
private static final AudioFormat.Encoding[] alawEncodings = { AudioFormat.Encoding.ALAW, AudioFormat.Encoding.PCM_SIGNED };
|
||||
|
||||
private static final short seg_end [] = {0xFF, 0x1FF, 0x3FF,
|
||||
0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF};
|
||||
private static final short seg_end[] = {
|
||||
0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF
|
||||
};
|
||||
|
||||
/**
|
||||
* Initializes the decode tables.
|
||||
@ -73,13 +74,14 @@ public final class AlawCodec extends SunCodec {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AudioFormat.Encoding[] getSourceEncodings() {
|
||||
return new Encoding[]{Encoding.ALAW, Encoding.PCM_SIGNED};
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new ALAW codec object.
|
||||
*/
|
||||
public AlawCodec() {
|
||||
|
||||
super(alawEncodings, alawEncodings);
|
||||
@Override
|
||||
public AudioFormat.Encoding[] getTargetEncodings() {
|
||||
return getSourceEncodings();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2016, 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
|
||||
@ -562,8 +562,7 @@ public final class AudioFloatFormatConverter extends FormatConversionProvider {
|
||||
|
||||
@Override
|
||||
public Encoding[] getTargetEncodings() {
|
||||
return new Encoding[] { Encoding.PCM_SIGNED, Encoding.PCM_UNSIGNED,
|
||||
Encoding.PCM_FLOAT };
|
||||
return getSourceEncodings();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 2016, 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
|
||||
@ -1034,6 +1034,7 @@ final class DirectAudioDevice extends AbstractMixer {
|
||||
|
||||
// $$fb part of fix for 4679187: Clip.open() throws unexpected Exceptions
|
||||
Toolkit.isFullySpecifiedAudioFormat(format);
|
||||
Toolkit.validateBuffer(format.getFrameSize(), bufferSize);
|
||||
|
||||
byte[] newData = new byte[bufferSize];
|
||||
System.arraycopy(data, offset, newData, 0, bufferSize);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2016, 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,32 +30,26 @@ import java.util.Objects;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.sound.sampled.AudioFormat;
|
||||
import javax.sound.sampled.AudioFormat.Encoding;
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.spi.FormatConversionProvider;
|
||||
|
||||
/**
|
||||
* Converts among signed/unsigned and little/big endianness of sampled.
|
||||
*
|
||||
* @author Jan Borgersen
|
||||
*/
|
||||
public final class PCMtoPCMCodec extends SunCodec {
|
||||
public final class PCMtoPCMCodec extends FormatConversionProvider {
|
||||
|
||||
private static final AudioFormat.Encoding[] inputEncodings = {
|
||||
AudioFormat.Encoding.PCM_SIGNED,
|
||||
AudioFormat.Encoding.PCM_UNSIGNED,
|
||||
};
|
||||
@Override
|
||||
public AudioFormat.Encoding[] getSourceEncodings() {
|
||||
return new Encoding[]{Encoding.PCM_SIGNED, Encoding.PCM_UNSIGNED};
|
||||
}
|
||||
|
||||
private static final AudioFormat.Encoding[] outputEncodings = {
|
||||
AudioFormat.Encoding.PCM_SIGNED,
|
||||
AudioFormat.Encoding.PCM_UNSIGNED,
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructs a new PCMtoPCM codec object.
|
||||
*/
|
||||
public PCMtoPCMCodec() {
|
||||
|
||||
super( inputEncodings, outputEncodings);
|
||||
@Override
|
||||
public AudioFormat.Encoding[] getTargetEncodings() {
|
||||
return getSourceEncodings();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2016, 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
|
||||
@ -363,9 +363,7 @@ public final class SoftMixingClip extends SoftMixingDataLine implements Clip {
|
||||
if (AudioFloatConverter.getConverter(format) == null)
|
||||
throw new IllegalArgumentException("Invalid format : "
|
||||
+ format.toString());
|
||||
if (bufferSize % format.getFrameSize() != 0)
|
||||
throw new IllegalArgumentException(
|
||||
"Buffer size does not represent an integral number of sample frames!");
|
||||
Toolkit.validateBuffer(format.getFrameSize(), bufferSize);
|
||||
|
||||
if (data != null) {
|
||||
this.data = Arrays.copyOf(data, data.length);
|
||||
|
||||
@ -1,71 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
* 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 com.sun.media.sound;
|
||||
|
||||
import javax.sound.sampled.AudioFormat;
|
||||
import javax.sound.sampled.spi.FormatConversionProvider;
|
||||
|
||||
/**
|
||||
* A codec can encode and/or decode audio data. It provides an
|
||||
* AudioInputStream from which processed data may be read.
|
||||
* <p>
|
||||
* Its input format represents the format of the incoming
|
||||
* audio data, or the format of the data in the underlying stream.
|
||||
* <p>
|
||||
* Its output format represents the format of the processed, outgoing
|
||||
* audio data. This is the format of the data which may be read from
|
||||
* the filtered stream.
|
||||
*
|
||||
* @author Kara Kytle
|
||||
*/
|
||||
abstract class SunCodec extends FormatConversionProvider {
|
||||
|
||||
private final AudioFormat.Encoding[] inputEncodings;
|
||||
private final AudioFormat.Encoding[] outputEncodings;
|
||||
|
||||
/**
|
||||
* Constructs a new codec object.
|
||||
*/
|
||||
SunCodec(final AudioFormat.Encoding[] inputEncodings,
|
||||
final AudioFormat.Encoding[] outputEncodings) {
|
||||
this.inputEncodings = inputEncodings;
|
||||
this.outputEncodings = outputEncodings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final AudioFormat.Encoding[] getSourceEncodings() {
|
||||
AudioFormat.Encoding[] encodings = new AudioFormat.Encoding[inputEncodings.length];
|
||||
System.arraycopy(inputEncodings, 0, encodings, 0, inputEncodings.length);
|
||||
return encodings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final AudioFormat.Encoding[] getTargetEncodings() {
|
||||
AudioFormat.Encoding[] encodings = new AudioFormat.Encoding[outputEncodings.length];
|
||||
System.arraycopy(outputEncodings, 0, encodings, 0, outputEncodings.length);
|
||||
return encodings;
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2016, 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
|
||||
@ -149,6 +149,20 @@ public final class Toolkit {
|
||||
return (long) (((double) frames) / format.getFrameRate() * 1000000.0d);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws an exception if the buffer size does not represent an integral
|
||||
* number of sample frames.
|
||||
*/
|
||||
static void validateBuffer(final int frameSize, final int bufferSize) {
|
||||
if (bufferSize % frameSize == 0) {
|
||||
return;
|
||||
}
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"Buffer size (%d) does not represent an integral number of "
|
||||
+ "sample frames (%d)", bufferSize, frameSize));
|
||||
}
|
||||
|
||||
|
||||
static void isFullySpecifiedAudioFormat(AudioFormat format) {
|
||||
if (!format.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED)
|
||||
&& !format.getEncoding().equals(AudioFormat.Encoding.PCM_UNSIGNED)
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2016, 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,26 +30,26 @@ import java.util.Objects;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.sound.sampled.AudioFormat;
|
||||
import javax.sound.sampled.AudioFormat.Encoding;
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.spi.FormatConversionProvider;
|
||||
|
||||
/**
|
||||
* U-law encodes linear data, and decodes u-law data to linear data.
|
||||
*
|
||||
* @author Kara Kytle
|
||||
*/
|
||||
public final class UlawCodec extends SunCodec {
|
||||
public final class UlawCodec extends FormatConversionProvider {
|
||||
|
||||
/* Tables used for U-law decoding */
|
||||
|
||||
private static final byte[] ULAW_TABH = new byte[256];
|
||||
private static final byte[] ULAW_TABL = new byte[256];
|
||||
|
||||
private static final AudioFormat.Encoding[] ulawEncodings = {AudioFormat.Encoding.ULAW,
|
||||
AudioFormat.Encoding.PCM_SIGNED};
|
||||
|
||||
private static final short seg_end [] = {0xFF, 0x1FF, 0x3FF,
|
||||
0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF};
|
||||
private static final short seg_end[] = {
|
||||
0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF
|
||||
};
|
||||
|
||||
/**
|
||||
* Initializes the decode tables.
|
||||
@ -69,11 +69,14 @@ public final class UlawCodec extends SunCodec {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new ULAW codec object.
|
||||
*/
|
||||
public UlawCodec() {
|
||||
super(ulawEncodings, ulawEncodings);
|
||||
@Override
|
||||
public AudioFormat.Encoding[] getSourceEncodings() {
|
||||
return new Encoding[]{Encoding.ULAW, Encoding.PCM_SIGNED};
|
||||
}
|
||||
|
||||
@Override
|
||||
public AudioFormat.Encoding[] getTargetEncodings() {
|
||||
return getSourceEncodings();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -851,8 +851,8 @@ public abstract class Component implements ImageObserver, MenuContainer,
|
||||
{
|
||||
comp.setGraphicsConfiguration(gc);
|
||||
}
|
||||
public boolean requestFocus(Component comp, FocusEvent.Cause cause) {
|
||||
return comp.requestFocus(cause);
|
||||
public void requestFocus(Component comp, FocusEvent.Cause cause) {
|
||||
comp.requestFocus(cause);
|
||||
}
|
||||
public boolean canBeFocusOwner(Component comp) {
|
||||
return comp.canBeFocusOwner();
|
||||
@ -7511,8 +7511,51 @@ public abstract class Component implements ImageObserver, MenuContainer,
|
||||
requestFocusHelper(false, true);
|
||||
}
|
||||
|
||||
boolean requestFocus(FocusEvent.Cause cause) {
|
||||
return requestFocusHelper(false, true, cause);
|
||||
|
||||
/**
|
||||
* Requests by the reason of {@code cause} that this Component get the input
|
||||
* focus, and that this Component's top-level ancestor become the
|
||||
* focused Window. This component must be displayable, focusable, visible
|
||||
* and all of its ancestors (with the exception of the top-level Window)
|
||||
* must be visible for the request to be granted. Every effort will be
|
||||
* made to honor the request; however, in some cases it may be
|
||||
* impossible to do so. Developers must never assume that this
|
||||
* Component is the focus owner until this Component receives a
|
||||
* FOCUS_GAINED event.
|
||||
* <p>
|
||||
* The focus request effect may also depend on the provided
|
||||
* cause value. If this request is succeed the {@code FocusEvent}
|
||||
* generated in the result will receive the cause value specified as the
|
||||
* argument of method. If this request is denied because this Component's
|
||||
* top-level Window cannot become the focused Window, the request will be
|
||||
* remembered and will be granted when the Window is later focused by the
|
||||
* user.
|
||||
* <p>
|
||||
* This method cannot be used to set the focus owner to no Component at
|
||||
* all. Use {@code KeyboardFocusManager.clearGlobalFocusOwner()}
|
||||
* instead.
|
||||
* <p>
|
||||
* Because the focus behavior of this method is platform-dependent,
|
||||
* developers are strongly encouraged to use
|
||||
* {@code requestFocusInWindow(FocusEvent.Cause)} when possible.
|
||||
*
|
||||
* <p>Note: Not all focus transfers result from invoking this method. As
|
||||
* such, a component may receive focus without this or any of the other
|
||||
* {@code requestFocus} methods of {@code Component} being invoked.
|
||||
*
|
||||
* @param cause the cause why the focus is requested
|
||||
* @see FocusEvent
|
||||
* @see FocusEvent.Cause
|
||||
* @see #requestFocusInWindow(FocusEvent.Cause)
|
||||
* @see java.awt.event.FocusEvent
|
||||
* @see #addFocusListener
|
||||
* @see #isFocusable
|
||||
* @see #isDisplayable
|
||||
* @see KeyboardFocusManager#clearGlobalFocusOwner
|
||||
* @since 9
|
||||
*/
|
||||
public void requestFocus(FocusEvent.Cause cause) {
|
||||
requestFocusHelper(false, true, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -7578,9 +7621,77 @@ public abstract class Component implements ImageObserver, MenuContainer,
|
||||
return requestFocusHelper(temporary, true);
|
||||
}
|
||||
|
||||
boolean requestFocus(boolean temporary, FocusEvent.Cause cause) {
|
||||
/**
|
||||
* Requests by the reason of {@code cause} that this {@code Component} get
|
||||
* the input focus, and that this {@code Component}'s top-level ancestor
|
||||
* become the focused {@code Window}. This component must be
|
||||
* displayable, focusable, visible and all of its ancestors (with
|
||||
* the exception of the top-level Window) must be visible for the
|
||||
* request to be granted. Every effort will be made to honor the
|
||||
* request; however, in some cases it may be impossible to do
|
||||
* so. Developers must never assume that this component is the
|
||||
* focus owner until this component receives a FOCUS_GAINED
|
||||
* event. If this request is denied because this component's
|
||||
* top-level window cannot become the focused window, the request
|
||||
* will be remembered and will be granted when the window is later
|
||||
* focused by the user.
|
||||
* <p>
|
||||
* This method returns a boolean value. If {@code false} is returned,
|
||||
* the request is <b>guaranteed to fail</b>. If {@code true} is
|
||||
* returned, the request will succeed <b>unless</b> it is vetoed, or an
|
||||
* extraordinary event, such as disposal of the component's peer, occurs
|
||||
* before the request can be granted by the native windowing system. Again,
|
||||
* while a return value of {@code true} indicates that the request is
|
||||
* likely to succeed, developers must never assume that this component is
|
||||
* the focus owner until this component receives a FOCUS_GAINED event.
|
||||
* <p>
|
||||
* The focus request effect may also depend on the provided
|
||||
* cause value. If this request is succeed the {FocusEvent}
|
||||
* generated in the result will receive the cause value specified as the
|
||||
* argument of the method.
|
||||
* <p>
|
||||
* This method cannot be used to set the focus owner to no component at
|
||||
* all. Use {@code KeyboardFocusManager.clearGlobalFocusOwner}
|
||||
* instead.
|
||||
* <p>
|
||||
* Because the focus behavior of this method is platform-dependent,
|
||||
* developers are strongly encouraged to use
|
||||
* {@code requestFocusInWindow} when possible.
|
||||
* <p>
|
||||
* Every effort will be made to ensure that {@code FocusEvent}s
|
||||
* generated as a
|
||||
* result of this request will have the specified temporary value. However,
|
||||
* because specifying an arbitrary temporary state may not be implementable
|
||||
* on all native windowing systems, correct behavior for this method can be
|
||||
* guaranteed only for lightweight {@code Component}s.
|
||||
* This method is not intended
|
||||
* for general use, but exists instead as a hook for lightweight component
|
||||
* libraries, such as Swing.
|
||||
* <p>
|
||||
* Note: Not all focus transfers result from invoking this method. As
|
||||
* such, a component may receive focus without this or any of the other
|
||||
* {@code requestFocus} methods of {@code Component} being invoked.
|
||||
*
|
||||
* @param temporary true if the focus change is temporary,
|
||||
* such as when the window loses the focus; for
|
||||
* more information on temporary focus changes see the
|
||||
*<a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
|
||||
*
|
||||
* @param cause the cause why the focus is requested
|
||||
* @return {@code false} if the focus change request is guaranteed to
|
||||
* fail; {@code true} if it is likely to succeed
|
||||
* @see FocusEvent
|
||||
* @see FocusEvent.Cause
|
||||
* @see #addFocusListener
|
||||
* @see #isFocusable
|
||||
* @see #isDisplayable
|
||||
* @see KeyboardFocusManager#clearGlobalFocusOwner
|
||||
* @since 9
|
||||
*/
|
||||
protected boolean requestFocus(boolean temporary, FocusEvent.Cause cause) {
|
||||
return requestFocusHelper(temporary, true, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that this Component get the input focus, if this
|
||||
* Component's top-level ancestor is already the focused
|
||||
@ -7629,7 +7740,59 @@ public abstract class Component implements ImageObserver, MenuContainer,
|
||||
return requestFocusHelper(false, false);
|
||||
}
|
||||
|
||||
boolean requestFocusInWindow(FocusEvent.Cause cause) {
|
||||
/**
|
||||
* Requests by the reason of {@code cause} that this Component get the input
|
||||
* focus, if this Component's top-level ancestor is already the focused
|
||||
* Window. This component must be displayable, focusable, visible
|
||||
* and all of its ancestors (with the exception of the top-level
|
||||
* Window) must be visible for the request to be granted. Every
|
||||
* effort will be made to honor the request; however, in some
|
||||
* cases it may be impossible to do so. Developers must never
|
||||
* assume that this Component is the focus owner until this
|
||||
* Component receives a FOCUS_GAINED event.
|
||||
* <p>
|
||||
* This method returns a boolean value. If {@code false} is returned,
|
||||
* the request is <b>guaranteed to fail</b>. If {@code true} is
|
||||
* returned, the request will succeed <b>unless</b> it is vetoed, or an
|
||||
* extraordinary event, such as disposal of the Component's peer, occurs
|
||||
* before the request can be granted by the native windowing system. Again,
|
||||
* while a return value of {@code true} indicates that the request is
|
||||
* likely to succeed, developers must never assume that this Component is
|
||||
* the focus owner until this Component receives a FOCUS_GAINED event.
|
||||
* <p>
|
||||
* The focus request effect may also depend on the provided
|
||||
* cause value. If this request is succeed the {@code FocusEvent}
|
||||
* generated in the result will receive the cause value specified as the
|
||||
* argument of the method.
|
||||
* <p>
|
||||
* This method cannot be used to set the focus owner to no Component at
|
||||
* all. Use {@code KeyboardFocusManager.clearGlobalFocusOwner()}
|
||||
* instead.
|
||||
* <p>
|
||||
* The focus behavior of this method can be implemented uniformly across
|
||||
* platforms, and thus developers are strongly encouraged to use this
|
||||
* method over {@code requestFocus(FocusEvent.Cause)} when possible.
|
||||
* Code which relies on {@code requestFocus(FocusEvent.Cause)} may exhibit
|
||||
* different focus behavior on different platforms.
|
||||
*
|
||||
* <p>Note: Not all focus transfers result from invoking this method. As
|
||||
* such, a component may receive focus without this or any of the other
|
||||
* {@code requestFocus} methods of {@code Component} being invoked.
|
||||
*
|
||||
* @param cause the cause why the focus is requested
|
||||
* @return {@code false} if the focus change request is guaranteed to
|
||||
* fail; {@code true} if it is likely to succeed
|
||||
* @see #requestFocus(FocusEvent.Cause)
|
||||
* @see FocusEvent
|
||||
* @see FocusEvent.Cause
|
||||
* @see java.awt.event.FocusEvent
|
||||
* @see #addFocusListener
|
||||
* @see #isFocusable
|
||||
* @see #isDisplayable
|
||||
* @see KeyboardFocusManager#clearGlobalFocusOwner
|
||||
* @since 9
|
||||
*/
|
||||
public boolean requestFocusInWindow(FocusEvent.Cause cause) {
|
||||
return requestFocusHelper(false, false, cause);
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 2016, 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
|
||||
@ -142,6 +142,7 @@ public final class DisplayMode {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object dm) {
|
||||
if (dm instanceof DisplayMode) {
|
||||
return equals((DisplayMode)dm);
|
||||
@ -153,9 +154,20 @@ public final class DisplayMode {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getWidth() + getHeight() + getBitDepth() * 7
|
||||
+ getRefreshRate() * 13;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return getWidth() + "x" + getHeight() + "x" +
|
||||
(getBitDepth() > 0 ? getBitDepth() + "bpp": "[Multi depth]")
|
||||
+ "@" + (getRefreshRate() > 0 ? getRefreshRate() + "Hz" :
|
||||
"[Unknown refresh rate]");
|
||||
}
|
||||
}
|
||||
|
||||
@ -154,6 +154,10 @@ import static sun.font.EAttribute.*;
|
||||
* associated with a font face, each differing in size, style, transform
|
||||
* and font features.
|
||||
* <p>
|
||||
* Glyphs may not always be rendered with the requested properties (e.g, font
|
||||
* and style) due to platform limitations such as the absence of suitable
|
||||
* platform fonts to implement a logical font.
|
||||
* <p>
|
||||
* The {@link GraphicsEnvironment#getAllFonts() getAllFonts} method
|
||||
* of the {@code GraphicsEnvironment} class returns an
|
||||
* array of all font faces available in the system. These font faces are
|
||||
|
||||
@ -65,6 +65,16 @@ import sun.awt.image.SunWritableRaster;
|
||||
* <PRE>
|
||||
* java -splash:filename.gif Test
|
||||
* </PRE>
|
||||
* HiDPI scaled image is also supported.
|
||||
* Unscaled image name i.e. filename.gif should be passed in
|
||||
* {@code manifest.mf}/{@code -splash:} option for all image types irrespective of
|
||||
* HiDPI and Non-HiDPI.
|
||||
* Following is the naming convention for scaled images.
|
||||
* Screen scale 1.25: filename@125pct.gif
|
||||
* Screen scale 1.50: filename@150pct.gif
|
||||
* Screen scale 2: filename@200pct.gif and filename@2x.gif both are supported
|
||||
* Screen scale 2.50: filename@250pct.gif
|
||||
* Screen scale 3: filename@300pct.gif and filename@3x.gif both are supported
|
||||
* The command line interface has higher precedence over the manifest
|
||||
* setting.
|
||||
* <p>
|
||||
|
||||
@ -122,7 +122,7 @@ class IIONodeList implements NodeList {
|
||||
}
|
||||
|
||||
public Node item(int index) {
|
||||
if (index < 0 || index > nodes.size()) {
|
||||
if (index < 0 || index >= nodes.size()) {
|
||||
return null;
|
||||
}
|
||||
return nodes.get(index);
|
||||
@ -882,7 +882,7 @@ public class IIOMetadataNode implements Element, NodeList {
|
||||
}
|
||||
|
||||
private void getElementsByTagName(String name, List<Node> l) {
|
||||
if (nodeName.equals(name)) {
|
||||
if (nodeName.equals(name) || "*".equals(name)) {
|
||||
l.add(this);
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2016, 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 @@
|
||||
|
||||
package javax.sound.sampled.spi;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.sound.sampled.AudioFormat;
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
@ -81,16 +81,8 @@ public abstract class FormatConversionProvider {
|
||||
* {@code false}
|
||||
* @throws NullPointerException if {@code sourceEncoding} is {@code null}
|
||||
*/
|
||||
public boolean isSourceEncodingSupported(Encoding sourceEncoding) {
|
||||
Objects.requireNonNull(sourceEncoding);
|
||||
Encoding sourceEncodings[] = getSourceEncodings();
|
||||
|
||||
for(int i=0; i<sourceEncodings.length; i++) {
|
||||
if( sourceEncoding.equals( sourceEncodings[i]) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
public boolean isSourceEncodingSupported(final Encoding sourceEncoding) {
|
||||
return Stream.of(getSourceEncodings()).anyMatch(sourceEncoding::equals);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,16 +95,8 @@ public abstract class FormatConversionProvider {
|
||||
* {@code false}
|
||||
* @throws NullPointerException if {@code targetEncoding} is {@code null}
|
||||
*/
|
||||
public boolean isTargetEncodingSupported(Encoding targetEncoding) {
|
||||
Objects.requireNonNull(targetEncoding);
|
||||
Encoding targetEncodings[] = getTargetEncodings();
|
||||
|
||||
for(int i=0; i<targetEncodings.length; i++) {
|
||||
if( targetEncoding.equals( targetEncodings[i]) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
public boolean isTargetEncodingSupported(final Encoding targetEncoding) {
|
||||
return Stream.of(getTargetEncodings()).anyMatch(targetEncoding::equals);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -137,17 +121,10 @@ public abstract class FormatConversionProvider {
|
||||
* @throws NullPointerException if {@code targetEncoding} or
|
||||
* {@code sourceFormat} are {@code null}
|
||||
*/
|
||||
public boolean isConversionSupported(Encoding targetEncoding,
|
||||
AudioFormat sourceFormat) {
|
||||
Objects.requireNonNull(targetEncoding);
|
||||
Encoding targetEncodings[] = getTargetEncodings(sourceFormat);
|
||||
|
||||
for(int i=0; i<targetEncodings.length; i++) {
|
||||
if( targetEncoding.equals( targetEncodings[i]) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
public boolean isConversionSupported(final Encoding targetEncoding,
|
||||
final AudioFormat sourceFormat) {
|
||||
return Stream.of(getTargetEncodings(sourceFormat))
|
||||
.anyMatch(targetEncoding::equals);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -175,17 +152,11 @@ public abstract class FormatConversionProvider {
|
||||
* @throws NullPointerException if {@code targetFormat} or
|
||||
* {@code sourceFormat} are {@code null}
|
||||
*/
|
||||
public boolean isConversionSupported(AudioFormat targetFormat,
|
||||
AudioFormat sourceFormat) {
|
||||
|
||||
AudioFormat targetFormats[] = getTargetFormats( targetFormat.getEncoding(), sourceFormat );
|
||||
|
||||
for(int i=0; i<targetFormats.length; i++) {
|
||||
if( targetFormat.matches( targetFormats[i] ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
public boolean isConversionSupported(final AudioFormat targetFormat,
|
||||
final AudioFormat sourceFormat) {
|
||||
final Encoding targetEncoding = targetFormat.getEncoding();
|
||||
return Stream.of(getTargetFormats(targetEncoding, sourceFormat))
|
||||
.anyMatch(targetFormat::matches);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -46,7 +46,11 @@ public abstract class TextUI extends ComponentUI
|
||||
* @return the coordinates as a {@code Rectangle}
|
||||
* @exception BadLocationException if the given position does not
|
||||
* represent a valid location in the associated document
|
||||
*
|
||||
* @deprecated replaced by
|
||||
* {@link #modelToView2D(JTextComponent, int, Position.Bias)}
|
||||
*/
|
||||
@Deprecated(since = "9")
|
||||
public abstract Rectangle modelToView(JTextComponent t, int pos) throws BadLocationException;
|
||||
|
||||
/**
|
||||
@ -59,7 +63,11 @@ public abstract class TextUI extends ComponentUI
|
||||
* @return the coordinates as a {@code Rectangle}
|
||||
* @exception BadLocationException if the given position does not
|
||||
* represent a valid location in the associated document
|
||||
*
|
||||
* @deprecated replaced by
|
||||
* {@link #modelToView2D(JTextComponent, int, Position.Bias)}
|
||||
*/
|
||||
@Deprecated(since = "9")
|
||||
public abstract Rectangle modelToView(JTextComponent t, int pos, Position.Bias bias) throws BadLocationException;
|
||||
|
||||
/**
|
||||
@ -92,7 +100,11 @@ public abstract class TextUI extends ComponentUI
|
||||
* should be in the same coordinate system as the mouse
|
||||
* events.
|
||||
* @return the offset from the start of the document >= 0
|
||||
*
|
||||
* @deprecated replaced by
|
||||
* {@link #viewToModel2D(JTextComponent, Point2D, Position.Bias[])}
|
||||
*/
|
||||
@Deprecated(since = "9")
|
||||
public abstract int viewToModel(JTextComponent t, Point pt);
|
||||
|
||||
/**
|
||||
@ -110,7 +122,11 @@ public abstract class TextUI extends ComponentUI
|
||||
*
|
||||
* @return the location within the model that best represents the
|
||||
* given point in the view >= 0
|
||||
*
|
||||
* @deprecated replaced by
|
||||
* {@link #viewToModel2D(JTextComponent, Point2D, Position.Bias[])}
|
||||
*/
|
||||
@Deprecated(since = "9")
|
||||
public abstract int viewToModel(JTextComponent t, Point pt,
|
||||
Position.Bias[] biasReturn);
|
||||
|
||||
@ -222,7 +238,11 @@ public abstract class TextUI extends ComponentUI
|
||||
* @return a {@code String} containing the tooltip
|
||||
* @see javax.swing.text.JTextComponent#getToolTipText
|
||||
* @since 1.4
|
||||
*
|
||||
* @deprecated replaced by
|
||||
* {@link #getToolTipText2D(JTextComponent, Point2D)}
|
||||
*/
|
||||
@Deprecated(since = "9")
|
||||
public String getToolTipText(JTextComponent t, Point pt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -28,6 +28,8 @@ import java.util.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.datatransfer.*;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.im.InputContext;
|
||||
import java.beans.*;
|
||||
import java.io.*;
|
||||
@ -1047,7 +1049,12 @@ public abstract class BasicTextUI extends TextUI implements ViewFactory {
|
||||
* @exception BadLocationException if the given position does not
|
||||
* represent a valid location in the associated document
|
||||
* @see TextUI#modelToView
|
||||
*
|
||||
* @deprecated replaced by
|
||||
* {@link #modelToView2D(JTextComponent, int, Position.Bias)}
|
||||
*/
|
||||
@Deprecated(since = "9")
|
||||
@Override
|
||||
public Rectangle modelToView(JTextComponent tc, int pos) throws BadLocationException {
|
||||
return modelToView(tc, pos, Position.Bias.Forward);
|
||||
}
|
||||
@ -1064,8 +1071,30 @@ public abstract class BasicTextUI extends TextUI implements ViewFactory {
|
||||
* @exception BadLocationException if the given position does not
|
||||
* represent a valid location in the associated document
|
||||
* @see TextUI#modelToView
|
||||
*
|
||||
* @deprecated replaced by
|
||||
* {@link #modelToView2D(JTextComponent, int, Position.Bias)}
|
||||
*/
|
||||
public Rectangle modelToView(JTextComponent tc, int pos, Position.Bias bias) throws BadLocationException {
|
||||
@Deprecated(since = "9")
|
||||
@Override
|
||||
public Rectangle modelToView(JTextComponent tc, int pos, Position.Bias bias)
|
||||
throws BadLocationException
|
||||
{
|
||||
return (Rectangle) modelToView(tc, pos, bias, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rectangle2D modelToView2D(JTextComponent tc, int pos,
|
||||
Position.Bias bias)
|
||||
throws BadLocationException
|
||||
{
|
||||
return modelToView(tc, pos, bias, true);
|
||||
}
|
||||
|
||||
private Rectangle2D modelToView(JTextComponent tc, int pos,
|
||||
Position.Bias bias, boolean useFPAPI)
|
||||
throws BadLocationException
|
||||
{
|
||||
Document doc = editor.getDocument();
|
||||
if (doc instanceof AbstractDocument) {
|
||||
((AbstractDocument)doc).readLock();
|
||||
@ -1076,7 +1105,7 @@ public abstract class BasicTextUI extends TextUI implements ViewFactory {
|
||||
rootView.setSize(alloc.width, alloc.height);
|
||||
Shape s = rootView.modelToView(pos, alloc, bias);
|
||||
if (s != null) {
|
||||
return s.getBounds();
|
||||
return useFPAPI ? s.getBounds2D() : s.getBounds();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
@ -1099,7 +1128,12 @@ public abstract class BasicTextUI extends TextUI implements ViewFactory {
|
||||
* @return the offset from the start of the document >= 0,
|
||||
* -1 if not painted
|
||||
* @see TextUI#viewToModel
|
||||
*
|
||||
* @deprecated replaced by
|
||||
* {@link #viewToModel2D(JTextComponent, Point2D, Position.Bias[])}
|
||||
*/
|
||||
@Deprecated(since = "9")
|
||||
@Override
|
||||
public int viewToModel(JTextComponent tc, Point pt) {
|
||||
return viewToModel(tc, pt, discardBias);
|
||||
}
|
||||
@ -1116,9 +1150,25 @@ public abstract class BasicTextUI extends TextUI implements ViewFactory {
|
||||
* @return the offset from the start of the document >= 0,
|
||||
* -1 if the component doesn't yet have a positive size.
|
||||
* @see TextUI#viewToModel
|
||||
*
|
||||
* @deprecated replaced by
|
||||
* {@link #viewToModel2D(JTextComponent, Point2D, Position.Bias[])}
|
||||
*/
|
||||
@Deprecated(since = "9")
|
||||
@Override
|
||||
public int viewToModel(JTextComponent tc, Point pt,
|
||||
Position.Bias[] biasReturn) {
|
||||
return viewToModel(tc, pt.x, pt.y, biasReturn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int viewToModel2D(JTextComponent tc, Point2D pt,
|
||||
Position.Bias[] biasReturn) {
|
||||
return viewToModel(tc, (float) pt.getX(), (float) pt.getY(), biasReturn);
|
||||
}
|
||||
|
||||
private int viewToModel(JTextComponent tc, float x, float y,
|
||||
Position.Bias[] biasReturn) {
|
||||
int offs = -1;
|
||||
Document doc = editor.getDocument();
|
||||
if (doc instanceof AbstractDocument) {
|
||||
@ -1128,7 +1178,7 @@ public abstract class BasicTextUI extends TextUI implements ViewFactory {
|
||||
Rectangle alloc = getVisibleEditorRect();
|
||||
if (alloc != null) {
|
||||
rootView.setSize(alloc.width, alloc.height);
|
||||
offs = rootView.viewToModel(pt.x, pt.y, alloc, biasReturn);
|
||||
offs = rootView.viewToModel(x, y, alloc, biasReturn);
|
||||
}
|
||||
} finally {
|
||||
if (doc instanceof AbstractDocument) {
|
||||
|
||||
@ -38,6 +38,8 @@ import javax.swing.plaf.ComponentUI;
|
||||
import javax.swing.JComponent;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import javax.accessibility.Accessible;
|
||||
|
||||
/**
|
||||
@ -97,7 +99,11 @@ public class MultiTextUI extends TextUI {
|
||||
*
|
||||
* @return the value obtained from the first UI, which is
|
||||
* the UI obtained from the default <code>LookAndFeel</code>
|
||||
*
|
||||
* @deprecated replaced by
|
||||
* {@link #modelToView2D(JTextComponent, int, Position.Bias)}
|
||||
*/
|
||||
@Deprecated(since = "9")
|
||||
public Rectangle modelToView(JTextComponent a, int b)
|
||||
throws BadLocationException {
|
||||
Rectangle returnValue =
|
||||
@ -113,7 +119,12 @@ public class MultiTextUI extends TextUI {
|
||||
*
|
||||
* @return the value obtained from the first UI, which is
|
||||
* the UI obtained from the default <code>LookAndFeel</code>
|
||||
*
|
||||
* @deprecated replaced by
|
||||
* {@link #modelToView2D(JTextComponent, int, Position.Bias)}
|
||||
*/
|
||||
@Deprecated(since = "9")
|
||||
@Override
|
||||
public Rectangle modelToView(JTextComponent a, int b, Position.Bias c)
|
||||
throws BadLocationException {
|
||||
Rectangle returnValue =
|
||||
@ -124,12 +135,24 @@ public class MultiTextUI extends TextUI {
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rectangle2D modelToView2D(JTextComponent a, int b, Position.Bias c) throws BadLocationException {
|
||||
Rectangle2D returnValue =
|
||||
((TextUI) (uis.elementAt(0))).modelToView2D(a,b,c);
|
||||
for (int i = 1; i < uis.size(); i++) {
|
||||
((TextUI) (uis.elementAt(i))).modelToView2D(a,b,c);
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes the <code>viewToModel</code> method on each UI handled by this object.
|
||||
*
|
||||
* @return the value obtained from the first UI, which is
|
||||
* the UI obtained from the default <code>LookAndFeel</code>
|
||||
*/
|
||||
@Deprecated(since = "9")
|
||||
@Override
|
||||
public int viewToModel(JTextComponent a, Point b) {
|
||||
int returnValue =
|
||||
((TextUI) (uis.elementAt(0))).viewToModel(a,b);
|
||||
@ -145,6 +168,8 @@ public class MultiTextUI extends TextUI {
|
||||
* @return the value obtained from the first UI, which is
|
||||
* the UI obtained from the default <code>LookAndFeel</code>
|
||||
*/
|
||||
@Deprecated(since = "9")
|
||||
@Override
|
||||
public int viewToModel(JTextComponent a, Point b, Position.Bias[] c) {
|
||||
int returnValue =
|
||||
((TextUI) (uis.elementAt(0))).viewToModel(a,b,c);
|
||||
@ -154,6 +179,16 @@ public class MultiTextUI extends TextUI {
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int viewToModel2D(JTextComponent a, Point2D b, Position.Bias[] c) {
|
||||
int returnValue =
|
||||
((TextUI) (uis.elementAt(0))).viewToModel2D(a,b,c);
|
||||
for (int i = 1; i < uis.size(); i++) {
|
||||
((TextUI) (uis.elementAt(i))).viewToModel2D(a,b,c);
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes the <code>getNextVisualPositionFrom</code> method on each UI handled by this object.
|
||||
*
|
||||
|
||||
@ -98,26 +98,27 @@ class GlyphPainter1 extends GlyphView.GlyphPainter {
|
||||
Rectangle alloc = (a instanceof Rectangle) ? (Rectangle)a : a.getBounds();
|
||||
|
||||
// determine the x coordinate to render the glyphs
|
||||
int x = alloc.x;
|
||||
float x = alloc.x;
|
||||
int p = v.getStartOffset();
|
||||
int[] justificationData = getJustificationData(v);
|
||||
if (p != p0) {
|
||||
text = v.getText(p, p0);
|
||||
int width = Utilities.getTabbedTextWidth(v, text, metrics, x, expander, p,
|
||||
justificationData);
|
||||
float width = Utilities.getTabbedTextWidth(v, text, metrics, x,
|
||||
expander, p,
|
||||
justificationData);
|
||||
x += width;
|
||||
SegmentCache.releaseSharedSegment(text);
|
||||
}
|
||||
|
||||
// determine the y coordinate to render the glyphs
|
||||
int y = alloc.y + metrics.getHeight() - metrics.getDescent();
|
||||
float y = alloc.y + metrics.getHeight() - metrics.getDescent();
|
||||
|
||||
// render the glyphs
|
||||
text = v.getText(p0, p1);
|
||||
g.setFont(metrics.getFont());
|
||||
|
||||
Utilities.drawTabbedText(v, text, x, y, g, expander,p0,
|
||||
justificationData);
|
||||
justificationData, true);
|
||||
SegmentCache.releaseSharedSegment(text);
|
||||
}
|
||||
|
||||
@ -210,9 +211,9 @@ class GlyphPainter1 extends GlyphView.GlyphPainter {
|
||||
TabExpander expander = v.getTabExpander();
|
||||
Segment s = v.getText(p0, v.getEndOffset());
|
||||
int[] justificationData = getJustificationData(v);
|
||||
int index = Utilities.getTabbedTextOffset(v, s, metrics, (int)x, (int)(x+len),
|
||||
int index = Utilities.getTabbedTextOffset(v, s, metrics, x, (x+len),
|
||||
expander, p0, false,
|
||||
justificationData);
|
||||
justificationData, true);
|
||||
SegmentCache.releaseSharedSegment(s);
|
||||
int p1 = p0 + index;
|
||||
return p1;
|
||||
|
||||
@ -145,8 +145,9 @@ class GlyphPainter2 extends GlyphView.GlyphPainter {
|
||||
|
||||
// vertical at the baseline, should use slope and check if glyphs
|
||||
// are being rendered vertically.
|
||||
alloc.setRect(alloc.getX() + locs[0], alloc.getY(), 1, alloc.getHeight());
|
||||
return alloc;
|
||||
Rectangle2D rect = new Rectangle2D.Float();
|
||||
rect.setRect(alloc.getX() + locs[0], alloc.getY(), 1, alloc.getHeight());
|
||||
return rect;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -49,6 +49,8 @@ import java.awt.im.InputContext;
|
||||
import java.awt.im.InputMethodRequests;
|
||||
import java.awt.font.TextHitInfo;
|
||||
import java.awt.font.TextAttribute;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import java.awt.print.Printable;
|
||||
import java.awt.print.PrinterException;
|
||||
@ -1370,11 +1372,37 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A
|
||||
* @exception BadLocationException if the given position does not
|
||||
* represent a valid location in the associated document
|
||||
* @see TextUI#modelToView
|
||||
*
|
||||
* @deprecated replaced by
|
||||
* {@link #modelToView2D(int)}
|
||||
*/
|
||||
@Deprecated(since = "9")
|
||||
public Rectangle modelToView(int pos) throws BadLocationException {
|
||||
return getUI().modelToView(this, pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given location in the model to a place in
|
||||
* the view coordinate system.
|
||||
* The component must have a positive size for
|
||||
* this translation to be computed (i.e. layout cannot
|
||||
* be computed until the component has been sized). The
|
||||
* component does not have to be visible or painted.
|
||||
*
|
||||
* @param pos the position {@code >= 0}
|
||||
* @return the coordinates as a rectangle, with (r.x, r.y) as the location
|
||||
* in the coordinate system, or null if the component does
|
||||
* not yet have a positive size.
|
||||
* @exception BadLocationException if the given position does not
|
||||
* represent a valid location in the associated document
|
||||
* @see TextUI#modelToView2D
|
||||
*
|
||||
* @since 9
|
||||
*/
|
||||
public Rectangle2D modelToView2D(int pos) throws BadLocationException {
|
||||
return getUI().modelToView2D(this, pos, Position.Bias.Forward);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given place in the view coordinate system
|
||||
* to the nearest representative location in the model.
|
||||
@ -1388,11 +1416,35 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A
|
||||
* or -1 if the component does not yet have a positive
|
||||
* size.
|
||||
* @see TextUI#viewToModel
|
||||
*
|
||||
* @deprecated replaced by
|
||||
* {@link #viewToModel2D(Point2D)}
|
||||
*/
|
||||
@Deprecated(since = "9")
|
||||
public int viewToModel(Point pt) {
|
||||
return getUI().viewToModel(this, pt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given place in the view coordinate system
|
||||
* to the nearest representative location in the model.
|
||||
* The component must have a positive size for
|
||||
* this translation to be computed (i.e. layout cannot
|
||||
* be computed until the component has been sized). The
|
||||
* component does not have to be visible or painted.
|
||||
*
|
||||
* @param pt the location in the view to translate
|
||||
* @return the offset {@code >= 0} from the start of the document,
|
||||
* or {@code -1} if the component does not yet have a positive
|
||||
* size.
|
||||
* @see TextUI#viewToModel2D
|
||||
*
|
||||
* @since 9
|
||||
*/
|
||||
public int viewToModel2D(Point2D pt) {
|
||||
return getUI().viewToModel2D(this, pt, new Position.Bias[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfers the currently selected range in the associated
|
||||
* text model to the system clipboard, removing the contents
|
||||
|
||||
@ -27,6 +27,7 @@ package javax.swing.text;
|
||||
import java.util.Arrays;
|
||||
import java.awt.*;
|
||||
import java.awt.font.TextAttribute;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.SizeRequirements;
|
||||
|
||||
@ -888,10 +889,9 @@ public class ParagraphView extends FlowView implements TabExpander {
|
||||
int height = r.height;
|
||||
int y = r.y;
|
||||
Shape loc = super.modelToView(pos, a, b);
|
||||
r = loc.getBounds();
|
||||
r.height = height;
|
||||
r.y = y;
|
||||
return r;
|
||||
Rectangle2D bounds = loc.getBounds2D();
|
||||
bounds.setRect(bounds.getX(), y, bounds.getWidth(), height);
|
||||
return bounds;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -26,7 +26,11 @@ package javax.swing.text;
|
||||
|
||||
import sun.swing.SwingUtilities2;
|
||||
import java.awt.*;
|
||||
import java.awt.font.FontRenderContext;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import javax.swing.JPasswordField;
|
||||
import static javax.swing.text.PlainView.isFPMethodOverriden;
|
||||
|
||||
/**
|
||||
* Implements a View suitable for use in JPasswordField
|
||||
@ -61,15 +65,40 @@ public class PasswordView extends FieldView {
|
||||
* @param p1 the ending offset in the model >= p0
|
||||
* @return the X location of the end of the range >= 0
|
||||
* @exception BadLocationException if p0 or p1 are out of range
|
||||
*
|
||||
* @deprecated replaced by
|
||||
* {@link #drawUnselectedText(Graphics2D, float, float, int, int)}
|
||||
*/
|
||||
@Deprecated(since = "9")
|
||||
@Override
|
||||
protected int drawUnselectedText(Graphics g, int x, int y,
|
||||
int p0, int p1) throws BadLocationException {
|
||||
return (int) drawUnselectedTextImpl(g, x, y, p0, p1, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float drawUnselectedText(Graphics2D g, float x, float y,
|
||||
int p0, int p1)
|
||||
throws BadLocationException
|
||||
{
|
||||
return drawUnselectedTextImpl(g, x, y, p0, p1, true);
|
||||
}
|
||||
|
||||
private float drawUnselectedTextImpl(Graphics g, float x, float y,
|
||||
int p0, int p1,
|
||||
boolean useFPAPI)
|
||||
throws BadLocationException
|
||||
{
|
||||
Container c = getContainer();
|
||||
if (c instanceof JPasswordField) {
|
||||
JPasswordField f = (JPasswordField) c;
|
||||
if (! f.echoCharIsSet()) {
|
||||
return super.drawUnselectedText(g, x, y, p0, p1);
|
||||
if (!f.echoCharIsSet()) {
|
||||
boolean useDrawUnselectedFPAPI = useFPAPI
|
||||
&& drawUnselectedTextOverridden
|
||||
&& g instanceof Graphics2D;
|
||||
return (useDrawUnselectedFPAPI )
|
||||
? super.drawUnselectedText((Graphics2D) g, x, y, p0, p1)
|
||||
: super.drawUnselectedText(g, (int) x, (int) y, p0, p1);
|
||||
}
|
||||
if (f.isEnabled()) {
|
||||
g.setColor(f.getForeground());
|
||||
@ -79,8 +108,13 @@ public class PasswordView extends FieldView {
|
||||
}
|
||||
char echoChar = f.getEchoChar();
|
||||
int n = p1 - p0;
|
||||
boolean useEchoCharFPAPI = useFPAPI
|
||||
&& drawEchoCharacterOverridden
|
||||
&& g instanceof Graphics2D;
|
||||
for (int i = 0; i < n; i++) {
|
||||
x = drawEchoCharacter(g, x, y, echoChar);
|
||||
x = (useEchoCharFPAPI)
|
||||
? drawEchoCharacter((Graphics2D) g, x, y, echoChar)
|
||||
: drawEchoCharacter(g, (int) x, (int) y, echoChar);
|
||||
}
|
||||
}
|
||||
return x;
|
||||
@ -100,20 +134,50 @@ public class PasswordView extends FieldView {
|
||||
* @param p1 the ending offset in the model >= p0
|
||||
* @return the X location of the end of the range >= 0
|
||||
* @exception BadLocationException if p0 or p1 are out of range
|
||||
*
|
||||
* @deprecated replaced by
|
||||
* {@link #drawSelectedText(Graphics2D, float, float, int, int)}
|
||||
*/
|
||||
@Deprecated(since = "9")
|
||||
@Override
|
||||
protected int drawSelectedText(Graphics g, int x,
|
||||
int y, int p0, int p1) throws BadLocationException {
|
||||
return (int) drawSelectedTextImpl(g, x, y, p0, p1, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float drawSelectedText(Graphics2D g, float x, float y,
|
||||
int p0, int p1) throws BadLocationException
|
||||
{
|
||||
return drawSelectedTextImpl(g, x, y, p0, p1, true);
|
||||
}
|
||||
|
||||
private float drawSelectedTextImpl(Graphics g, float x, float y,
|
||||
int p0, int p1,
|
||||
boolean useFPAPI)
|
||||
throws BadLocationException {
|
||||
g.setColor(selected);
|
||||
Container c = getContainer();
|
||||
if (c instanceof JPasswordField) {
|
||||
JPasswordField f = (JPasswordField) c;
|
||||
if (! f.echoCharIsSet()) {
|
||||
return super.drawSelectedText(g, x, y, p0, p1);
|
||||
if (!f.echoCharIsSet()) {
|
||||
boolean useDrawUnselectedFPAPI = useFPAPI
|
||||
&& drawSelectedTextOverridden
|
||||
&& g instanceof Graphics2D;
|
||||
return (useFPAPI)
|
||||
? super.drawSelectedText((Graphics2D) g, x, y, p0, p1)
|
||||
: super.drawSelectedText(g, (int) x, (int) y, p0, p1);
|
||||
}
|
||||
char echoChar = f.getEchoChar();
|
||||
int n = p1 - p0;
|
||||
boolean useEchoCharFPAPI = useFPAPI
|
||||
&& drawEchoCharacterOverridden
|
||||
&& g instanceof Graphics2D;
|
||||
for (int i = 0; i < n; i++) {
|
||||
x = drawEchoCharacter(g, x, y, echoChar);
|
||||
x = (useEchoCharFPAPI)
|
||||
? drawEchoCharacter((Graphics2D) g, x, y, echoChar)
|
||||
: drawEchoCharacter(g, (int) x, (int) y, echoChar);
|
||||
|
||||
}
|
||||
}
|
||||
return x;
|
||||
@ -130,12 +194,13 @@ public class PasswordView extends FieldView {
|
||||
* @param y the starting Y coordinate >= 0
|
||||
* @param c the echo character
|
||||
* @return the updated X position >= 0
|
||||
*
|
||||
* @deprecated replaced by
|
||||
* {@link #drawEchoCharacter(Graphics2D, float, float, char)}
|
||||
*/
|
||||
@Deprecated(since = "9")
|
||||
protected int drawEchoCharacter(Graphics g, int x, int y, char c) {
|
||||
ONE[0] = c;
|
||||
SwingUtilities2.drawChars(Utilities.getJComponent(this),
|
||||
g, ONE, 0, 1, x, y);
|
||||
return x + g.getFontMetrics().charWidth(c);
|
||||
return (int) drawEchoCharacterImpl(g, x, y, c, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -144,18 +209,29 @@ public class PasswordView extends FieldView {
|
||||
* object is set to the appropriate foreground color for selected
|
||||
* or unselected text.
|
||||
*
|
||||
* @implSpec This implementation calls
|
||||
* {@link #drawEchoCharacter(Graphics, int, int, char)
|
||||
* drawEchoCharacter((Graphics) g, (int) x, (int) y, c)}.
|
||||
*
|
||||
* @param g the graphics context
|
||||
* @param x the starting X coordinate {@code >= 0}
|
||||
* @param y the starting Y coordinate {@code >= 0}
|
||||
* @param c the echo character
|
||||
* @return the updated X position {@code >= 0}
|
||||
*
|
||||
* @since 9
|
||||
*/
|
||||
protected float drawEchoCharacter(Graphics2D g, float x, float y, char c) {
|
||||
return drawEchoCharacter((Graphics) g, (int) x, (int) y, c);
|
||||
return drawEchoCharacterImpl(g, x, y, c, true);
|
||||
}
|
||||
|
||||
private float drawEchoCharacterImpl(Graphics g, float x, float y,
|
||||
char c, boolean useFPAPI) {
|
||||
ONE[0] = c;
|
||||
SwingUtilities2.drawChars(Utilities.getJComponent(this),
|
||||
g, ONE, 0, 1, x, y);
|
||||
if (useFPAPI) {
|
||||
return x + g.getFontMetrics().charWidth(c);
|
||||
} else {
|
||||
FontRenderContext frc = g.getFontMetrics().getFontRenderContext();
|
||||
return x + (float) g.getFont().getStringBounds(ONE, 0, 1, frc).getWidth();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -253,4 +329,23 @@ public class PasswordView extends FieldView {
|
||||
}
|
||||
|
||||
static char[] ONE = new char[1];
|
||||
|
||||
private final boolean drawEchoCharacterOverridden;
|
||||
|
||||
{
|
||||
final Class<?> CLS = getClass();
|
||||
final Class<?> INT = Integer.TYPE;
|
||||
final Class<?> FP = Float.TYPE;
|
||||
final Class<?> CHAR = Character.TYPE;
|
||||
|
||||
drawEchoCharacterOverridden = AccessController
|
||||
.doPrivileged(new PrivilegedAction<Boolean>() {
|
||||
@Override
|
||||
public Boolean run() {
|
||||
Class<?>[] intTypes = {Graphics.class, INT, INT, CHAR};
|
||||
Class<?>[] fpTypes = {Graphics2D.class, FP, FP, CHAR};
|
||||
return isFPMethodOverriden("drawEchoCharacter", CLS, intTypes, fpTypes);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,11 +24,14 @@
|
||||
*/
|
||||
package javax.swing.text;
|
||||
|
||||
import java.util.Vector;
|
||||
import java.util.Properties;
|
||||
import java.awt.*;
|
||||
import java.awt.font.FontRenderContext;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Objects;
|
||||
import javax.swing.event.*;
|
||||
import java.lang.reflect.Module;
|
||||
|
||||
/**
|
||||
* Implements View interface for a simple multi-line text view
|
||||
@ -60,17 +63,6 @@ public class PlainView extends View implements TabExpander {
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tab size set for the document, defaulting to 8.
|
||||
*
|
||||
* @implSpec This implementation calls {@link #getTabSize() getTabSize()}.
|
||||
*
|
||||
* @return the tab size
|
||||
*/
|
||||
protected float getFractionalTabSize() {
|
||||
return getTabSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a line of text, suppressing whitespace at the end
|
||||
* and expanding any tabs. This is implemented to make calls
|
||||
@ -84,8 +76,16 @@ public class PlainView extends View implements TabExpander {
|
||||
* @param y the starting Y position >= 0
|
||||
* @see #drawUnselectedText
|
||||
* @see #drawSelectedText
|
||||
*
|
||||
* @deprecated replaced by
|
||||
* {@link #drawLine(int, Graphics2D, float, float)}
|
||||
*/
|
||||
@Deprecated(since = "9")
|
||||
protected void drawLine(int lineIndex, Graphics g, int x, int y) {
|
||||
drawLineImpl(lineIndex, g, x, y);
|
||||
}
|
||||
|
||||
private void drawLineImpl(int lineIndex, Graphics g, float x, float y) {
|
||||
Element line = getElement().getElement(lineIndex);
|
||||
Element elem;
|
||||
|
||||
@ -112,22 +112,23 @@ public class PlainView extends View implements TabExpander {
|
||||
* {@code drawSelectedText} so that the way selected and
|
||||
* unselected text are rendered can be customized.
|
||||
*
|
||||
* @implSpec This implementation calls
|
||||
* {@link #drawLine(int, Graphics, int, int)
|
||||
* drawLine(lineIndex, (Graphics)g, (int) x, (int) y)}.
|
||||
*
|
||||
* @param lineIndex the line to draw {@code >= 0}
|
||||
* @param g the {@code Graphics} context
|
||||
* @param x the starting X position {@code >= 0}
|
||||
* @param y the starting Y position {@code >= 0}
|
||||
* @see #drawUnselectedText
|
||||
* @see #drawSelectedText
|
||||
*
|
||||
* @since 9
|
||||
*/
|
||||
protected void drawLine(int lineIndex, Graphics2D g, float x, float y) {
|
||||
drawLine(lineIndex, (Graphics)g, (int) x, (int) y);
|
||||
drawLineImpl(lineIndex, g, x, y);
|
||||
}
|
||||
|
||||
private int drawElement(int lineIndex, Element elem, Graphics g, int x, int y) throws BadLocationException {
|
||||
private float drawElement(int lineIndex, Element elem, Graphics g,
|
||||
float x, float y)
|
||||
throws BadLocationException
|
||||
{
|
||||
int p0 = elem.getStartOffset();
|
||||
int p1 = elem.getEndOffset();
|
||||
p1 = Math.min(getDocument().getLength(), p1);
|
||||
@ -144,23 +145,23 @@ public class PlainView extends View implements TabExpander {
|
||||
} else {
|
||||
if (sel0 == sel1 || selected == unselected) {
|
||||
// no selection, or it is invisible
|
||||
x = drawUnselectedText(g, x, y, p0, p1);
|
||||
x = callDrawUnselectedText(g, x, y, p0, p1);
|
||||
} else if ((p0 >= sel0 && p0 <= sel1) && (p1 >= sel0 && p1 <= sel1)) {
|
||||
x = drawSelectedText(g, x, y, p0, p1);
|
||||
x = callDrawSelectedText(g, x, y, p0, p1);
|
||||
} else if (sel0 >= p0 && sel0 <= p1) {
|
||||
if (sel1 >= p0 && sel1 <= p1) {
|
||||
x = drawUnselectedText(g, x, y, p0, sel0);
|
||||
x = drawSelectedText(g, x, y, sel0, sel1);
|
||||
x = drawUnselectedText(g, x, y, sel1, p1);
|
||||
x = callDrawUnselectedText(g, x, y, p0, sel0);
|
||||
x = callDrawSelectedText(g, x, y, sel0, sel1);
|
||||
x = callDrawUnselectedText(g, x, y, sel1, p1);
|
||||
} else {
|
||||
x = drawUnselectedText(g, x, y, p0, sel0);
|
||||
x = drawSelectedText(g, x, y, sel0, p1);
|
||||
x = callDrawUnselectedText(g, x, y, p0, sel0);
|
||||
x = callDrawSelectedText(g, x, y, sel0, p1);
|
||||
}
|
||||
} else if (sel1 >= p0 && sel1 <= p1) {
|
||||
x = drawSelectedText(g, x, y, p0, sel1);
|
||||
x = drawUnselectedText(g, x, y, sel1, p1);
|
||||
x = callDrawSelectedText(g, x, y, p0, sel1);
|
||||
x = callDrawUnselectedText(g, x, y, sel1, p1);
|
||||
} else {
|
||||
x = drawUnselectedText(g, x, y, p0, p1);
|
||||
x = callDrawUnselectedText(g, x, y, p0, p1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -178,14 +179,36 @@ public class PlainView extends View implements TabExpander {
|
||||
* @param p1 the ending position in the model >= 0
|
||||
* @return the X location of the end of the range >= 0
|
||||
* @exception BadLocationException if the range is invalid
|
||||
*
|
||||
* @deprecated replaced by
|
||||
* {@link #drawUnselectedText(Graphics2D, float, float, int, int)}
|
||||
*/
|
||||
@Deprecated(since = "9")
|
||||
protected int drawUnselectedText(Graphics g, int x, int y,
|
||||
int p0, int p1) throws BadLocationException {
|
||||
return (int) drawUnselectedTextImpl(g, x, y, p0, p1, false);
|
||||
}
|
||||
|
||||
private float callDrawUnselectedText(Graphics g, float x, float y,
|
||||
int p0, int p1)
|
||||
throws BadLocationException
|
||||
{
|
||||
return drawUnselectedTextOverridden && (g instanceof Graphics2D)
|
||||
? drawUnselectedText((Graphics2D) g, x, y, p0, p1)
|
||||
: drawUnselectedText(g, (int) x, (int) y, p0, p1);
|
||||
}
|
||||
|
||||
private float drawUnselectedTextImpl(Graphics g, float x, float y,
|
||||
int p0, int p1,
|
||||
boolean useFPAPI)
|
||||
throws BadLocationException
|
||||
{
|
||||
g.setColor(unselected);
|
||||
Document doc = getDocument();
|
||||
Segment s = SegmentCache.getSharedSegment();
|
||||
doc.getText(p0, p1 - p0, s);
|
||||
int ret = Utilities.drawTabbedText(this, s, x, y, g, this, p0);
|
||||
float ret = Utilities.drawTabbedText(this, s, x, y, g, this, p0, null,
|
||||
useFPAPI);
|
||||
SegmentCache.releaseSharedSegment(s);
|
||||
return ret;
|
||||
}
|
||||
@ -194,10 +217,6 @@ public class PlainView extends View implements TabExpander {
|
||||
* Renders the given range in the model as normal unselected
|
||||
* text. Uses the foreground or disabled color to render the text.
|
||||
*
|
||||
* @implSpec This implementation calls
|
||||
* {@link #drawUnselectedText(Graphics, int, int, int, int)
|
||||
* drawUnselectedText((Graphics)g, (int) x, (int) y, p0, p1)}.
|
||||
*
|
||||
* @param g the graphics context
|
||||
* @param x the starting X coordinate {@code >= 0}
|
||||
* @param y the starting Y coordinate {@code >= 0}
|
||||
@ -205,10 +224,12 @@ public class PlainView extends View implements TabExpander {
|
||||
* @param p1 the ending position in the model {@code >= 0}
|
||||
* @return the X location of the end of the range {@code >= 0}
|
||||
* @exception BadLocationException if the range is invalid
|
||||
*
|
||||
* @since 9
|
||||
*/
|
||||
protected float drawUnselectedText(Graphics2D g, float x, float y,
|
||||
int p0, int p1) throws BadLocationException {
|
||||
return drawUnselectedText((Graphics)g, (int) x, (int) y, p0, p1);
|
||||
return drawUnselectedTextImpl(g, x, y, p0, p1, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -224,14 +245,38 @@ public class PlainView extends View implements TabExpander {
|
||||
* @param p1 the ending position in the model >= 0
|
||||
* @return the location of the end of the range
|
||||
* @exception BadLocationException if the range is invalid
|
||||
*
|
||||
* @deprecated replaced by
|
||||
* {@link #drawSelectedText(Graphics2D, float, float, int, int)}
|
||||
*/
|
||||
@Deprecated(since = "9")
|
||||
protected int drawSelectedText(Graphics g, int x,
|
||||
int y, int p0, int p1) throws BadLocationException {
|
||||
int y, int p0, int p1)
|
||||
throws BadLocationException
|
||||
{
|
||||
return (int) drawSelectedTextImpl(g, x, y, p0, p1, false);
|
||||
}
|
||||
|
||||
float callDrawSelectedText(Graphics g, float x, float y,
|
||||
int p0, int p1)
|
||||
throws BadLocationException
|
||||
{
|
||||
return drawSelectedTextOverridden && g instanceof Graphics2D
|
||||
? drawSelectedText((Graphics2D) g, x, y, p0, p1)
|
||||
: drawSelectedText(g, (int) x, (int) y, p0, p1);
|
||||
}
|
||||
|
||||
private float drawSelectedTextImpl(Graphics g, float x, float y,
|
||||
int p0, int p1,
|
||||
boolean useFPAPI)
|
||||
throws BadLocationException
|
||||
{
|
||||
g.setColor(selected);
|
||||
Document doc = getDocument();
|
||||
Segment s = SegmentCache.getSharedSegment();
|
||||
doc.getText(p0, p1 - p0, s);
|
||||
int ret = Utilities.drawTabbedText(this, s, x, y, g, this, p0);
|
||||
float ret = Utilities.drawTabbedText(this, s, x, y, g, this, p0, null,
|
||||
useFPAPI);
|
||||
SegmentCache.releaseSharedSegment(s);
|
||||
return ret;
|
||||
}
|
||||
@ -242,10 +287,6 @@ public class PlainView extends View implements TabExpander {
|
||||
* the hosting component. It assumes the highlighter will render
|
||||
* the selected background.
|
||||
*
|
||||
* @implSpec This implementation calls
|
||||
* {@link #drawSelectedText(Graphics, int, int, int, int)
|
||||
* drawSelectedText((Graphics)g, (int) x, (int) y, p0, p1)}.
|
||||
*
|
||||
* @param g the graphics context
|
||||
* @param x the starting X coordinate {@code >= 0}
|
||||
* @param y the starting Y coordinate {@code >= 0}
|
||||
@ -253,11 +294,12 @@ public class PlainView extends View implements TabExpander {
|
||||
* @param p1 the ending position in the model {@code >= 0}
|
||||
* @return the location of the end of the range
|
||||
* @exception BadLocationException if the range is invalid
|
||||
*
|
||||
* @since 9
|
||||
*/
|
||||
|
||||
protected float drawSelectedText(Graphics2D g, float x,
|
||||
float y, int p0, int p1) throws BadLocationException {
|
||||
return drawSelectedText((Graphics)g, (int) x, (int) y, p0, p1);
|
||||
return drawSelectedTextImpl(g, x, y, p0, p1, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -287,7 +329,13 @@ public class PlainView extends View implements TabExpander {
|
||||
// The font changed, we need to recalculate the
|
||||
// longest line.
|
||||
calculateLongestLine();
|
||||
tabSize = getTabSize() * metrics.charWidth('m');
|
||||
if (useFloatingPointAPI) {
|
||||
FontRenderContext frc = metrics.getFontRenderContext();
|
||||
float tabWidth = (float) font.getStringBounds("m", frc).getWidth();
|
||||
tabSize = getTabSize() * tabWidth;
|
||||
} else {
|
||||
tabSize = getTabSize() * metrics.charWidth('m');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -388,7 +436,11 @@ public class PlainView extends View implements TabExpander {
|
||||
originalA, host, this);
|
||||
}
|
||||
}
|
||||
drawLine(line, g, x, y);
|
||||
if (drawLineOverridden && (g instanceof Graphics2D)) {
|
||||
drawLine(line, (Graphics2D) g, (float) x, (float) y);
|
||||
} else {
|
||||
drawLine(line, g, x, y);
|
||||
}
|
||||
y += fontHeight;
|
||||
if (line == 0) {
|
||||
// This should never really happen, in so far as if
|
||||
@ -435,6 +487,13 @@ public class PlainView extends View implements TabExpander {
|
||||
int p0 = line.getStartOffset();
|
||||
Segment s = SegmentCache.getSharedSegment();
|
||||
doc.getText(p0, pos - p0, s);
|
||||
|
||||
if (useFloatingPointAPI) {
|
||||
float xOffs = Utilities.getTabbedTextWidth(s, metrics, (float) tabBase, this, p0);
|
||||
SegmentCache.releaseSharedSegment(s);
|
||||
return new Rectangle2D.Float(lineArea.x + xOffs, lineArea.y, 1, metrics.getHeight());
|
||||
}
|
||||
|
||||
int xOffs = Utilities.getTabbedTextWidth(s, metrics, tabBase, this,p0);
|
||||
SegmentCache.releaseSharedSegment(s);
|
||||
|
||||
@ -456,14 +515,13 @@ public class PlainView extends View implements TabExpander {
|
||||
* given point in the view >= 0
|
||||
* @see View#viewToModel
|
||||
*/
|
||||
public int viewToModel(float fx, float fy, Shape a, Position.Bias[] bias) {
|
||||
public int viewToModel(float x, float y, Shape a, Position.Bias[] bias) {
|
||||
// PENDING(prinz) properly calculate bias
|
||||
bias[0] = Position.Bias.Forward;
|
||||
|
||||
Rectangle alloc = a.getBounds();
|
||||
Document doc = getDocument();
|
||||
int x = (int) fx;
|
||||
int y = (int) fy;
|
||||
|
||||
if (y < alloc.y) {
|
||||
// above the area covered by this icon, so the position
|
||||
// is assumed to be the start of the coverage for this view.
|
||||
@ -481,7 +539,7 @@ public class PlainView extends View implements TabExpander {
|
||||
Element map = doc.getDefaultRootElement();
|
||||
int fontHeight = metrics.getHeight();
|
||||
int lineIndex = (fontHeight > 0 ?
|
||||
Math.abs((y - alloc.y) / fontHeight) :
|
||||
(int)Math.abs((y - alloc.y) / fontHeight) :
|
||||
map.getElementCount() - 1);
|
||||
if (lineIndex >= map.getElementCount()) {
|
||||
return getEndOffset() - 1;
|
||||
@ -507,7 +565,7 @@ public class PlainView extends View implements TabExpander {
|
||||
doc.getText(p0, p1 - p0, s);
|
||||
tabBase = alloc.x;
|
||||
int offs = p0 + Utilities.getTabbedTextOffset(s, metrics,
|
||||
tabBase, x, this, p0);
|
||||
tabBase, x, this, p0, true);
|
||||
SegmentCache.releaseSharedSegment(s);
|
||||
return offs;
|
||||
} catch (BadLocationException e) {
|
||||
@ -586,7 +644,7 @@ public class PlainView extends View implements TabExpander {
|
||||
if (tabSize == 0) {
|
||||
return x;
|
||||
}
|
||||
int ntabs = (((int) x) - tabBase) / tabSize;
|
||||
float ntabs = (x - tabBase) / tabSize;
|
||||
return tabBase + ((ntabs + 1) * tabSize);
|
||||
}
|
||||
|
||||
@ -758,6 +816,28 @@ public class PlainView extends View implements TabExpander {
|
||||
return w;
|
||||
}
|
||||
|
||||
static boolean isFPMethodOverriden(String method,
|
||||
Class<?> cls,
|
||||
Class<?>[] intTypes,
|
||||
Class<?>[] fpTypes)
|
||||
{
|
||||
Module thisModule = PlainView.class.getModule();
|
||||
while (!thisModule.equals(cls.getModule())) {
|
||||
try {
|
||||
cls.getDeclaredMethod(method, fpTypes);
|
||||
return true;
|
||||
} catch (Exception e1) {
|
||||
try {
|
||||
cls.getDeclaredMethod(method, intTypes);
|
||||
return false;
|
||||
} catch (Exception e2) {
|
||||
cls = cls.getSuperclass();
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// --- member variables -----------------------------------------------
|
||||
|
||||
/**
|
||||
@ -780,7 +860,7 @@ public class PlainView extends View implements TabExpander {
|
||||
Font font;
|
||||
|
||||
Segment lineBuffer;
|
||||
int tabSize;
|
||||
float tabSize;
|
||||
int tabBase;
|
||||
|
||||
int sel0;
|
||||
@ -796,4 +876,46 @@ public class PlainView extends View implements TabExpander {
|
||||
*/
|
||||
int firstLineOffset;
|
||||
|
||||
final boolean drawLineOverridden;
|
||||
final boolean drawSelectedTextOverridden;
|
||||
final boolean drawUnselectedTextOverridden;
|
||||
final boolean useFloatingPointAPI;
|
||||
|
||||
{
|
||||
final Class<?> CLS = getClass();
|
||||
final Class<?> INT = Integer.TYPE;
|
||||
final Class<?> FP = Float.TYPE;
|
||||
|
||||
drawLineOverridden = AccessController
|
||||
.doPrivileged(new PrivilegedAction<Boolean>() {
|
||||
@Override
|
||||
public Boolean run() {
|
||||
Class<?>[] intTypes = {INT, Graphics.class, INT, INT};
|
||||
Class<?>[] fpTypes = {INT, Graphics2D.class, FP, FP};
|
||||
return isFPMethodOverriden("drawLine", CLS, intTypes, fpTypes);
|
||||
}
|
||||
});
|
||||
|
||||
drawUnselectedTextOverridden = AccessController
|
||||
.doPrivileged(new PrivilegedAction<Boolean>() {
|
||||
@Override
|
||||
public Boolean run() {
|
||||
Class<?>[] intTypes = {Graphics.class, INT, INT, INT, INT};
|
||||
Class<?>[] fpTypes = {Graphics2D.class, FP, FP, INT, INT};
|
||||
return isFPMethodOverriden("drawUnselectedText", CLS, intTypes, fpTypes);
|
||||
}
|
||||
});
|
||||
|
||||
drawSelectedTextOverridden = AccessController
|
||||
.doPrivileged(new PrivilegedAction<Boolean>() {
|
||||
@Override
|
||||
public Boolean run() {
|
||||
Class<?>[] intTypes = {Graphics.class, INT, INT, INT, INT};
|
||||
Class<?>[] fpTypes = {Graphics2D.class, FP, FP, INT, INT};
|
||||
return isFPMethodOverriden("drawSelectedText", CLS, intTypes, fpTypes);
|
||||
}
|
||||
});
|
||||
|
||||
useFloatingPointAPI = drawUnselectedTextOverridden || drawSelectedTextOverridden;
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,24 +24,23 @@
|
||||
*/
|
||||
package javax.swing.text;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Shape;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.font.FontRenderContext;
|
||||
import java.awt.font.TextLayout;
|
||||
import java.awt.font.TextAttribute;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import java.text.*;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.text.ParagraphView.Row;
|
||||
import sun.swing.SwingUtilities2;
|
||||
import static sun.swing.SwingUtilities2.drawChars;
|
||||
import static sun.swing.SwingUtilities2.getFontCharWidth;
|
||||
import static sun.swing.SwingUtilities2.getFontCharsWidth;
|
||||
|
||||
/**
|
||||
* A collection of methods to deal with various text
|
||||
@ -78,7 +77,11 @@ public class Utilities {
|
||||
* tabs will be expanded as a space character.
|
||||
* @param startOffset starting offset of the text in the document >= 0
|
||||
* @return the X location at the end of the rendered text
|
||||
*
|
||||
* @deprecated replaced by
|
||||
* {@link #drawTabbedText(Segment, float, float, Graphics2D, TabExpander, int)}
|
||||
*/
|
||||
@Deprecated(since = "9")
|
||||
public static final int drawTabbedText(Segment s, int x, int y, Graphics g,
|
||||
TabExpander e, int startOffset) {
|
||||
return drawTabbedText(null, s, x, y, g, e, startOffset);
|
||||
@ -96,6 +99,8 @@ public class Utilities {
|
||||
* tabs will be expanded as a space character.
|
||||
* @param startOffset starting offset of the text in the document {@code >= 0}
|
||||
* @return the X location at the end of the rendered text
|
||||
*
|
||||
* @since 9
|
||||
*/
|
||||
public static final float drawTabbedText(Segment s, float x, float y,
|
||||
Graphics2D g,
|
||||
@ -138,9 +143,19 @@ public class Utilities {
|
||||
Segment s, int x, int y, Graphics g,
|
||||
TabExpander e, int startOffset,
|
||||
int [] justificationData) {
|
||||
return (int) drawTabbedText(view, s, x, y, g, e, startOffset,
|
||||
justificationData, false);
|
||||
}
|
||||
|
||||
static final float drawTabbedText(View view,
|
||||
Segment s, float x, float y, Graphics g,
|
||||
TabExpander e, int startOffset,
|
||||
int [] justificationData,
|
||||
boolean useFPAPI)
|
||||
{
|
||||
JComponent component = getJComponent(view);
|
||||
FontMetrics metrics = SwingUtilities2.getFontMetrics(component, g);
|
||||
int nextX = x;
|
||||
float nextX = x;
|
||||
char[] txt = s.array;
|
||||
int txtOffset = s.offset;
|
||||
int flushLen = 0;
|
||||
@ -174,19 +189,19 @@ public class Utilities {
|
||||
&& i <= endJustifiableContent
|
||||
)) {
|
||||
if (flushLen > 0) {
|
||||
nextX = SwingUtilities2.drawChars(component, g, txt,
|
||||
flushIndex, flushLen, x, y);
|
||||
nextX = drawChars(component, g, txt, flushIndex, flushLen, x, y);
|
||||
flushLen = 0;
|
||||
}
|
||||
flushIndex = i + 1;
|
||||
if (txt[i] == '\t') {
|
||||
if (e != null) {
|
||||
nextX = (int) e.nextTabStop((float) nextX, startOffset + i - txtOffset);
|
||||
nextX = e.nextTabStop(nextX, startOffset + i - txtOffset);
|
||||
} else {
|
||||
nextX += metrics.charWidth(' ');
|
||||
nextX += getFontCharWidth(' ', metrics, useFPAPI);
|
||||
}
|
||||
} else if (txt[i] == ' ') {
|
||||
nextX += metrics.charWidth(' ') + spaceAddon;
|
||||
float spaceWidth = getFontCharWidth(' ', metrics, useFPAPI);
|
||||
nextX += spaceWidth + spaceAddon;
|
||||
if (i <= spaceAddonLeftoverEnd) {
|
||||
nextX++;
|
||||
}
|
||||
@ -194,8 +209,8 @@ public class Utilities {
|
||||
x = nextX;
|
||||
} else if ((txt[i] == '\n') || (txt[i] == '\r')) {
|
||||
if (flushLen > 0) {
|
||||
nextX = SwingUtilities2.drawChars(component, g, txt,
|
||||
flushIndex, flushLen, x, y);
|
||||
nextX = drawChars(component, g, txt, flushIndex, flushLen,
|
||||
x, y, useFPAPI);
|
||||
flushLen = 0;
|
||||
}
|
||||
flushIndex = i + 1;
|
||||
@ -205,8 +220,7 @@ public class Utilities {
|
||||
}
|
||||
}
|
||||
if (flushLen > 0) {
|
||||
nextX = SwingUtilities2.drawChars(component, g,txt, flushIndex,
|
||||
flushLen, x, y);
|
||||
nextX = drawChars(component, g,txt, flushIndex, flushLen, x, y, useFPAPI);
|
||||
}
|
||||
return nextX;
|
||||
}
|
||||
@ -223,7 +237,11 @@ public class Utilities {
|
||||
* tabs will be expanded as a space character.
|
||||
* @param startOffset starting offset of the text in the document >= 0
|
||||
* @return the width of the text
|
||||
*
|
||||
* @deprecated replaced by
|
||||
* {@link #getTabbedTextWidth(Segment, FontMetrics, float, TabExpander, int)}
|
||||
*/
|
||||
@Deprecated(since = "9")
|
||||
public static final int getTabbedTextWidth(Segment s, FontMetrics metrics, int x,
|
||||
TabExpander e, int startOffset) {
|
||||
return getTabbedTextWidth(null, s, metrics, x, e, startOffset, null);
|
||||
@ -240,11 +258,13 @@ public class Utilities {
|
||||
* tabs will be expanded as a space character.
|
||||
* @param startOffset starting offset of the text in the document {@code >= 0}
|
||||
* @return the width of the text
|
||||
*
|
||||
* @since 9
|
||||
*/
|
||||
public static final float getTabbedTextWidth(Segment s, FontMetrics metrics,
|
||||
float x, TabExpander e,
|
||||
int startOffset) {
|
||||
return getTabbedTextWidth(s, metrics, (int) x, e, startOffset);
|
||||
return getTabbedTextWidth(null, s, metrics, x, e, startOffset, null);
|
||||
}
|
||||
|
||||
// In addition to the previous method it can extend spaces for
|
||||
@ -254,10 +274,32 @@ public class Utilities {
|
||||
// one:
|
||||
// @param justificationData justificationData for the row.
|
||||
// if null not justification is needed
|
||||
static final int getTabbedTextWidth(View view, Segment s, FontMetrics metrics, int x,
|
||||
static final int getTabbedTextWidth(View view, Segment s,
|
||||
FontMetrics metrics, int x,
|
||||
TabExpander e, int startOffset,
|
||||
int[] justificationData) {
|
||||
int nextX = x;
|
||||
int[] justificationData)
|
||||
{
|
||||
return (int) getTabbedTextWidth(view, s, metrics, x, e, startOffset,
|
||||
justificationData, false);
|
||||
|
||||
}
|
||||
|
||||
static final float getTabbedTextWidth(View view, Segment s,
|
||||
FontMetrics metrics, float x,
|
||||
TabExpander e, int startOffset,
|
||||
int[] justificationData)
|
||||
{
|
||||
return getTabbedTextWidth(view, s, metrics, x, e, startOffset,
|
||||
justificationData, true);
|
||||
|
||||
}
|
||||
|
||||
static final float getTabbedTextWidth(View view, Segment s,
|
||||
FontMetrics metrics, float x,
|
||||
TabExpander e, int startOffset,
|
||||
int[] justificationData,
|
||||
boolean useFPAPI) {
|
||||
float nextX = x;
|
||||
char[] txt = s.array;
|
||||
int txtOffset = s.offset;
|
||||
int n = s.offset + s.count;
|
||||
@ -294,13 +336,13 @@ public class Utilities {
|
||||
charCount = 0;
|
||||
if (txt[i] == '\t') {
|
||||
if (e != null) {
|
||||
nextX = (int) e.nextTabStop((float) nextX,
|
||||
startOffset + i - txtOffset);
|
||||
nextX = e.nextTabStop(nextX, startOffset + i - txtOffset);
|
||||
} else {
|
||||
nextX += metrics.charWidth(' ');
|
||||
nextX += getFontCharWidth(' ', metrics, useFPAPI);
|
||||
}
|
||||
} else if (txt[i] == ' ') {
|
||||
nextX += metrics.charWidth(' ') + spaceAddon;
|
||||
float spaceWidth = getFontCharWidth(' ', metrics, useFPAPI);
|
||||
nextX += spaceWidth + spaceAddon;
|
||||
if (i <= spaceAddonLeftoverEnd) {
|
||||
nextX++;
|
||||
}
|
||||
@ -308,13 +350,15 @@ public class Utilities {
|
||||
} else if(txt[i] == '\n') {
|
||||
// Ignore newlines, they take up space and we shouldn't be
|
||||
// counting them.
|
||||
nextX += metrics.charsWidth(txt, i - charCount, charCount);
|
||||
nextX += getFontCharsWidth(txt, i - charCount, charCount,
|
||||
metrics, useFPAPI);
|
||||
charCount = 0;
|
||||
} else {
|
||||
charCount++;
|
||||
}
|
||||
}
|
||||
nextX += metrics.charsWidth(txt, n - charCount, charCount);
|
||||
nextX += getFontCharsWidth(txt, n - charCount, charCount,
|
||||
metrics, useFPAPI);
|
||||
return nextX - x;
|
||||
}
|
||||
|
||||
@ -334,7 +378,12 @@ public class Utilities {
|
||||
* tabs will be expanded as a space character.
|
||||
* @param startOffset starting offset of the text in the document >= 0
|
||||
* @return the offset into the text >= 0
|
||||
*
|
||||
* @deprecated replaced by
|
||||
* {@link #getTabbedTextOffset(Segment, FontMetrics, float, float,
|
||||
* TabExpander, int, boolean)}
|
||||
*/
|
||||
@Deprecated(since = "9")
|
||||
public static final int getTabbedTextOffset(Segment s, FontMetrics metrics,
|
||||
int x0, int x, TabExpander e,
|
||||
int startOffset) {
|
||||
@ -346,7 +395,7 @@ public class Utilities {
|
||||
int startOffset,
|
||||
int[] justificationData) {
|
||||
return getTabbedTextOffset(view, s, metrics, x0, x, e, startOffset, true,
|
||||
justificationData);
|
||||
justificationData, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -365,13 +414,19 @@ public class Utilities {
|
||||
* @param startOffset starting offset of the text in the document >= 0
|
||||
* @param round whether or not to round
|
||||
* @return the offset into the text >= 0
|
||||
*
|
||||
* @deprecated replaced by
|
||||
* {@link #getTabbedTextOffset(Segment, FontMetrics, float, float,
|
||||
* TabExpander, int, boolean)}
|
||||
*/
|
||||
@Deprecated(since = "9")
|
||||
public static final int getTabbedTextOffset(Segment s,
|
||||
FontMetrics metrics,
|
||||
int x0, int x, TabExpander e,
|
||||
int startOffset,
|
||||
boolean round) {
|
||||
return getTabbedTextOffset(null, s, metrics, x0, x, e, startOffset, round, null);
|
||||
return getTabbedTextOffset(null, s, metrics, x0, x, e, startOffset,
|
||||
round, null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -390,6 +445,8 @@ public class Utilities {
|
||||
* @param startOffset starting offset of the text in the document {@code >= 0}
|
||||
* @param round whether or not to round
|
||||
* @return the offset into the text {@code >= 0}
|
||||
*
|
||||
* @since 9
|
||||
*/
|
||||
public static final int getTabbedTextOffset(Segment s,
|
||||
FontMetrics metrics,
|
||||
@ -398,8 +455,8 @@ public class Utilities {
|
||||
int startOffset,
|
||||
boolean round)
|
||||
{
|
||||
return getTabbedTextOffset(null, s, metrics, (int) x0, (int) x, e,
|
||||
startOffset, round, null);
|
||||
return getTabbedTextOffset(null, s, metrics, x0, x, e,
|
||||
startOffset, round, null, true);
|
||||
}
|
||||
|
||||
// In addition to the previous method it can extend spaces for
|
||||
@ -412,15 +469,16 @@ public class Utilities {
|
||||
static final int getTabbedTextOffset(View view,
|
||||
Segment s,
|
||||
FontMetrics metrics,
|
||||
int x0, int x, TabExpander e,
|
||||
float x0, float x, TabExpander e,
|
||||
int startOffset,
|
||||
boolean round,
|
||||
int[] justificationData) {
|
||||
int[] justificationData,
|
||||
boolean useFPAPI) {
|
||||
if (x0 >= x) {
|
||||
// x before x0, return.
|
||||
return 0;
|
||||
}
|
||||
int nextX = x0;
|
||||
float nextX = x0;
|
||||
// s may be a shared segment, so it is copied prior to calling
|
||||
// the tab expander
|
||||
char[] txt = s.array;
|
||||
@ -456,19 +514,19 @@ public class Utilities {
|
||||
)){
|
||||
if (txt[i] == '\t') {
|
||||
if (e != null) {
|
||||
nextX = (int) e.nextTabStop((float) nextX,
|
||||
startOffset + i - txtOffset);
|
||||
nextX = e.nextTabStop(nextX, startOffset + i - txtOffset);
|
||||
} else {
|
||||
nextX += metrics.charWidth(' ');
|
||||
nextX += getFontCharWidth(' ', metrics, useFPAPI);
|
||||
}
|
||||
} else if (txt[i] == ' ') {
|
||||
nextX += metrics.charWidth(' ') + spaceAddon;
|
||||
nextX += getFontCharWidth(' ', metrics, useFPAPI);
|
||||
nextX += spaceAddon;
|
||||
if (i <= spaceAddonLeftoverEnd) {
|
||||
nextX++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
nextX += metrics.charWidth(txt[i]);
|
||||
nextX += getFontCharWidth(txt[i], metrics, useFPAPI);
|
||||
}
|
||||
if (x < nextX) {
|
||||
// found the hit position... return the appropriate side
|
||||
@ -480,12 +538,15 @@ public class Utilities {
|
||||
if (round) {
|
||||
offset = i + 1 - txtOffset;
|
||||
|
||||
int width = metrics.charsWidth(txt, txtOffset, offset);
|
||||
int span = x - x0;
|
||||
float width = getFontCharsWidth(txt, txtOffset, offset,
|
||||
metrics, useFPAPI);
|
||||
float span = x - x0;
|
||||
|
||||
if (span < width) {
|
||||
while (offset > 0) {
|
||||
int nextWidth = offset > 1 ? metrics.charsWidth(txt, txtOffset, offset - 1) : 0;
|
||||
float charsWidth = getFontCharsWidth(txt, txtOffset,
|
||||
offset - 1, metrics, useFPAPI);
|
||||
float nextWidth = offset > 1 ? charsWidth : 0;
|
||||
|
||||
if (span >= nextWidth) {
|
||||
if (span - nextWidth < width - span) {
|
||||
@ -502,7 +563,9 @@ public class Utilities {
|
||||
} else {
|
||||
offset = i - txtOffset;
|
||||
|
||||
while (offset > 0 && metrics.charsWidth(txt, txtOffset, offset) > (x - x0)) {
|
||||
while (offset > 0 && getFontCharsWidth(txt, txtOffset, offset,
|
||||
metrics, useFPAPI)
|
||||
> (x - x0)) {
|
||||
offset--;
|
||||
}
|
||||
}
|
||||
@ -528,15 +591,26 @@ public class Utilities {
|
||||
* tabs will be expanded as a space character.
|
||||
* @param startOffset starting offset in the document of the text
|
||||
* @return the offset into the given text
|
||||
*
|
||||
* @deprecated replaced by
|
||||
* {@link #getBreakLocation(Segment, FontMetrics, float, float,
|
||||
* TabExpander, int)}
|
||||
*/
|
||||
@Deprecated(since = "9")
|
||||
public static final int getBreakLocation(Segment s, FontMetrics metrics,
|
||||
int x0, int x, TabExpander e,
|
||||
int startOffset) {
|
||||
return getBreakLocation(s, metrics, x0, x, e, startOffset, false);
|
||||
}
|
||||
|
||||
static final int getBreakLocation(Segment s, FontMetrics metrics,
|
||||
float x0, float x, TabExpander e,
|
||||
int startOffset, boolean useFPIAPI) {
|
||||
char[] txt = s.array;
|
||||
int txtOffset = s.offset;
|
||||
int txtCount = s.count;
|
||||
int index = Utilities.getTabbedTextOffset(s, metrics, x0, x,
|
||||
e, startOffset, false);
|
||||
int index = getTabbedTextOffset(null, s, metrics, x0, x, e, startOffset,
|
||||
false, null, useFPIAPI);
|
||||
|
||||
if (index >= txtCount - 1) {
|
||||
return txtCount;
|
||||
@ -577,11 +651,13 @@ public class Utilities {
|
||||
* tabs will be expanded as a space character.
|
||||
* @param startOffset starting offset in the document of the text
|
||||
* @return the offset into the given text
|
||||
*
|
||||
* @since 9
|
||||
*/
|
||||
public static final int getBreakLocation(Segment s, FontMetrics metrics,
|
||||
float x0, float x, TabExpander e,
|
||||
int startOffset) {
|
||||
return getBreakLocation(s, metrics, (int) x0, (int) x, e, startOffset);
|
||||
return getBreakLocation(s, metrics, x0, x, e, startOffset, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -627,16 +703,16 @@ public class Utilities {
|
||||
* @exception BadLocationException if the offset is out of range
|
||||
*/
|
||||
public static final int getRowEnd(JTextComponent c, int offs) throws BadLocationException {
|
||||
Rectangle r = c.modelToView(offs);
|
||||
Rectangle2D r = c.modelToView2D(offs);
|
||||
if (r == null) {
|
||||
return -1;
|
||||
}
|
||||
int n = c.getDocument().getLength();
|
||||
int lastOffs = offs;
|
||||
int y = r.y;
|
||||
while ((r != null) && (y == r.y)) {
|
||||
double y = r.getY();
|
||||
while ((r != null) && (y == r.getY())) {
|
||||
// Skip invisible elements
|
||||
if (r.height !=0) {
|
||||
if (r.getHeight() !=0) {
|
||||
offs = lastOffs;
|
||||
}
|
||||
lastOffs += 1;
|
||||
@ -657,27 +733,44 @@ public class Utilities {
|
||||
* @return the position >= 0 if the request can be computed, otherwise
|
||||
* a value of -1 will be returned.
|
||||
* @exception BadLocationException if the offset is out of range
|
||||
*
|
||||
* @deprecated replaced by
|
||||
* {@link #getPositionAbove(JTextComponent, int, float)}
|
||||
*/
|
||||
public static final int getPositionAbove(JTextComponent c, int offs, int x) throws BadLocationException {
|
||||
@Deprecated(since = "9")
|
||||
public static final int getPositionAbove(JTextComponent c, int offs, int x)
|
||||
throws BadLocationException
|
||||
{
|
||||
return getPositionAbove(c, offs, x, false);
|
||||
}
|
||||
|
||||
static final int getPositionAbove(JTextComponent c, int offs, float x,
|
||||
boolean useFPAPI) throws BadLocationException
|
||||
{
|
||||
int lastOffs = getRowStart(c, offs) - 1;
|
||||
if (lastOffs < 0) {
|
||||
return -1;
|
||||
}
|
||||
int bestSpan = Integer.MAX_VALUE;
|
||||
int y = 0;
|
||||
Rectangle r = null;
|
||||
double bestSpan = Integer.MAX_VALUE;
|
||||
double y = 0;
|
||||
Rectangle2D r = null;
|
||||
if (lastOffs >= 0) {
|
||||
r = c.modelToView(lastOffs);
|
||||
y = r.y;
|
||||
r = useFPAPI ? c.modelToView2D(lastOffs) : c.modelToView(lastOffs);
|
||||
y = r.getY();
|
||||
}
|
||||
while ((r != null) && (y == r.y)) {
|
||||
int span = Math.abs(r.x - x);
|
||||
while ((r != null) && (y == r.getY())) {
|
||||
double span = Math.abs(r.getX() - x);
|
||||
if (span < bestSpan) {
|
||||
offs = lastOffs;
|
||||
bestSpan = span;
|
||||
}
|
||||
lastOffs -= 1;
|
||||
r = (lastOffs >= 0) ? c.modelToView(lastOffs) : null;
|
||||
|
||||
if ((lastOffs >= 0)) {
|
||||
r = useFPAPI ? c.modelToView2D(lastOffs) : c.modelToView(lastOffs);
|
||||
} else {
|
||||
r = null;
|
||||
}
|
||||
}
|
||||
return offs;
|
||||
}
|
||||
@ -694,10 +787,12 @@ public class Utilities {
|
||||
* @return the position {@code >= 0} if the request can be computed, otherwise
|
||||
* a value of -1 will be returned.
|
||||
* @exception BadLocationException if the offset is out of range
|
||||
*
|
||||
* @since 9
|
||||
*/
|
||||
public static final int getPositionAbove(JTextComponent c, int offs, float x)
|
||||
throws BadLocationException {
|
||||
return getPositionAbove(c, offs, (int) x);
|
||||
return getPositionAbove(c, offs, x, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -712,28 +807,45 @@ public class Utilities {
|
||||
* @return the position >= 0 if the request can be computed, otherwise
|
||||
* a value of -1 will be returned.
|
||||
* @exception BadLocationException if the offset is out of range
|
||||
*
|
||||
* @deprecated replaced by
|
||||
* {@link #getPositionBelow(JTextComponent, int, float)}
|
||||
*/
|
||||
public static final int getPositionBelow(JTextComponent c, int offs, int x) throws BadLocationException {
|
||||
@Deprecated(since = "9")
|
||||
public static final int getPositionBelow(JTextComponent c, int offs, int x)
|
||||
throws BadLocationException
|
||||
{
|
||||
return getPositionBelow(c, offs, x, false);
|
||||
}
|
||||
|
||||
static final int getPositionBelow(JTextComponent c, int offs, float x,
|
||||
boolean useFPAPI) throws BadLocationException
|
||||
{
|
||||
int lastOffs = getRowEnd(c, offs) + 1;
|
||||
if (lastOffs <= 0) {
|
||||
return -1;
|
||||
}
|
||||
int bestSpan = Integer.MAX_VALUE;
|
||||
double bestSpan = Integer.MAX_VALUE;
|
||||
int n = c.getDocument().getLength();
|
||||
int y = 0;
|
||||
Rectangle r = null;
|
||||
double y = 0;
|
||||
Rectangle2D r = null;
|
||||
if (lastOffs <= n) {
|
||||
r = c.modelToView(lastOffs);
|
||||
y = r.y;
|
||||
r = useFPAPI ? c.modelToView2D(lastOffs) : c.modelToView(lastOffs);
|
||||
y = r.getY();
|
||||
}
|
||||
while ((r != null) && (y == r.y)) {
|
||||
int span = Math.abs(x - r.x);
|
||||
while ((r != null) && (y == r.getY())) {
|
||||
double span = Math.abs(x - r.getX());
|
||||
if (span < bestSpan) {
|
||||
offs = lastOffs;
|
||||
bestSpan = span;
|
||||
}
|
||||
lastOffs += 1;
|
||||
r = (lastOffs <= n) ? c.modelToView(lastOffs) : null;
|
||||
|
||||
if (lastOffs <= n) {
|
||||
r = useFPAPI ? c.modelToView2D(lastOffs) : c.modelToView(lastOffs);
|
||||
} else {
|
||||
r = null;
|
||||
}
|
||||
}
|
||||
return offs;
|
||||
}
|
||||
@ -750,10 +862,12 @@ public class Utilities {
|
||||
* @return the position {@code >= 0} if the request can be computed, otherwise
|
||||
* a value of -1 will be returned.
|
||||
* @exception BadLocationException if the offset is out of range
|
||||
*
|
||||
* @since 9
|
||||
*/
|
||||
public static final int getPositionBelow(JTextComponent c, int offs, float x)
|
||||
throws BadLocationException {
|
||||
return getPositionBelow(c, offs, (int) x);
|
||||
return getPositionBelow(c, offs, x, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1029,7 +1143,23 @@ public class Utilities {
|
||||
*/
|
||||
static int drawComposedText(View view, AttributeSet attr, Graphics g,
|
||||
int x, int y, int p0, int p1)
|
||||
throws BadLocationException {
|
||||
throws BadLocationException
|
||||
{
|
||||
return (int) drawComposedText(view, attr, g, x, y, p0, p1, false);
|
||||
}
|
||||
|
||||
static float drawComposedText(View view, AttributeSet attr, Graphics g,
|
||||
float x, float y, int p0, int p1)
|
||||
throws BadLocationException
|
||||
{
|
||||
return drawComposedText(view, attr, g, x, y, p0, p1, true);
|
||||
}
|
||||
|
||||
static float drawComposedText(View view, AttributeSet attr, Graphics g,
|
||||
float x, float y, int p0, int p1,
|
||||
boolean useFPAPI)
|
||||
throws BadLocationException
|
||||
{
|
||||
Graphics2D g2d = (Graphics2D)g;
|
||||
AttributedString as = (AttributedString)attr.getAttribute(
|
||||
StyleConstants.ComposedTextAttribute);
|
||||
@ -1039,8 +1169,7 @@ public class Utilities {
|
||||
return x;
|
||||
|
||||
AttributedCharacterIterator aci = as.getIterator(null, p0, p1);
|
||||
return x + (int)SwingUtilities2.drawString(
|
||||
getJComponent(view), g2d,aci,x,y);
|
||||
return x + SwingUtilities2.drawString(getJComponent(view), g2d, aci, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -25,8 +25,12 @@
|
||||
package javax.swing.text;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.font.FontRenderContext;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import javax.swing.event.*;
|
||||
import static javax.swing.text.PlainView.isFPMethodOverriden;
|
||||
|
||||
/**
|
||||
* View of plain text (text with only one font and color)
|
||||
@ -86,17 +90,6 @@ public class WrappedPlainView extends BoxView implements TabExpander {
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tab size set for the document, defaulting to 8.
|
||||
*
|
||||
* @implSpec This implementation calls {@link #getTabSize() getTabSize()}.
|
||||
*
|
||||
* @return the tab size
|
||||
*/
|
||||
protected float getFractionalTabSize() {
|
||||
return getTabSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a line of text, suppressing whitespace at the end
|
||||
* and expanding any tabs. This is implemented to make calls
|
||||
@ -111,8 +104,17 @@ public class WrappedPlainView extends BoxView implements TabExpander {
|
||||
* @param y the starting Y position >= 0
|
||||
* @see #drawUnselectedText
|
||||
* @see #drawSelectedText
|
||||
*
|
||||
* @deprecated replaced by
|
||||
* {@link #drawLine(int, int, Graphics2D, float, float)}
|
||||
*/
|
||||
@Deprecated(since = "9")
|
||||
protected void drawLine(int p0, int p1, Graphics g, int x, int y) {
|
||||
drawLineImpl(p0, p1, g, x, y, false);
|
||||
}
|
||||
|
||||
private void drawLineImpl(int p0, int p1, Graphics g, float x, float y,
|
||||
boolean useFPAPI) {
|
||||
Element lineMap = getElement();
|
||||
Element line = lineMap.getElement(lineMap.getElementIndex(p0));
|
||||
Element elem;
|
||||
@ -143,10 +145,6 @@ public class WrappedPlainView extends BoxView implements TabExpander {
|
||||
* <code>drawSelectedText</code> so that the way selected and
|
||||
* unselected text are rendered can be customized.
|
||||
*
|
||||
* @implSpec This implementation calls
|
||||
* {@link #drawLine(int, int, Graphics, int, int)
|
||||
* drawLine(p0, p1, (Graphics) g, (int) x, (int) y)}.
|
||||
*
|
||||
* @param p0 the starting document location to use >= 0
|
||||
* @param p1 the ending document location to use >= p1
|
||||
* @param g the graphics context
|
||||
@ -154,12 +152,17 @@ public class WrappedPlainView extends BoxView implements TabExpander {
|
||||
* @param y the starting Y position >= 0
|
||||
* @see #drawUnselectedText
|
||||
* @see #drawSelectedText
|
||||
*
|
||||
* @since 9
|
||||
*/
|
||||
protected void drawLine(int p0, int p1, Graphics2D g, float x, float y) {
|
||||
drawLine(p0, p1, (Graphics) g, (int) x, (int) y);
|
||||
drawLineImpl(p0, p1, g, x, y, true);
|
||||
}
|
||||
|
||||
private int drawText(Element elem, int p0, int p1, Graphics g, int x, int y) throws BadLocationException {
|
||||
private float drawText(Element elem, int p0, int p1, Graphics g,
|
||||
float x, float y)
|
||||
throws BadLocationException
|
||||
{
|
||||
p1 = Math.min(getDocument().getLength(), p1);
|
||||
AttributeSet attr = elem.getAttributes();
|
||||
|
||||
@ -171,23 +174,23 @@ public class WrappedPlainView extends BoxView implements TabExpander {
|
||||
} else {
|
||||
if (sel0 == sel1 || selected == unselected) {
|
||||
// no selection, or it is invisible
|
||||
x = drawUnselectedText(g, x, y, p0, p1);
|
||||
x = callDrawUnselectedText(g, x, y, p0, p1);
|
||||
} else if ((p0 >= sel0 && p0 <= sel1) && (p1 >= sel0 && p1 <= sel1)) {
|
||||
x = drawSelectedText(g, x, y, p0, p1);
|
||||
x = callDrawSelectedText(g, x, y, p0, p1);
|
||||
} else if (sel0 >= p0 && sel0 <= p1) {
|
||||
if (sel1 >= p0 && sel1 <= p1) {
|
||||
x = drawUnselectedText(g, x, y, p0, sel0);
|
||||
x = drawSelectedText(g, x, y, sel0, sel1);
|
||||
x = drawUnselectedText(g, x, y, sel1, p1);
|
||||
x = callDrawUnselectedText(g, x, y, p0, sel0);
|
||||
x = callDrawSelectedText(g, x, y, sel0, sel1);
|
||||
x = callDrawUnselectedText(g, x, y, sel1, p1);
|
||||
} else {
|
||||
x = drawUnselectedText(g, x, y, p0, sel0);
|
||||
x = drawSelectedText(g, x, y, sel0, p1);
|
||||
x = callDrawUnselectedText(g, x, y, p0, sel0);
|
||||
x = callDrawSelectedText(g, x, y, sel0, p1);
|
||||
}
|
||||
} else if (sel1 >= p0 && sel1 <= p1) {
|
||||
x = drawSelectedText(g, x, y, p0, sel1);
|
||||
x = drawUnselectedText(g, x, y, sel1, p1);
|
||||
x = callDrawSelectedText(g, x, y, p0, sel1);
|
||||
x = callDrawUnselectedText(g, x, y, sel1, p1);
|
||||
} else {
|
||||
x = drawUnselectedText(g, x, y, p0, p1);
|
||||
x = callDrawUnselectedText(g, x, y, p0, p1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -205,14 +208,36 @@ public class WrappedPlainView extends BoxView implements TabExpander {
|
||||
* @param p1 the ending position in the model >= p0
|
||||
* @return the X location of the end of the range >= 0
|
||||
* @exception BadLocationException if the range is invalid
|
||||
*
|
||||
* @deprecated replaced by
|
||||
* {@link #drawUnselectedText(Graphics2D, float, float, int, int)}
|
||||
*/
|
||||
@Deprecated(since = "9")
|
||||
protected int drawUnselectedText(Graphics g, int x, int y,
|
||||
int p0, int p1) throws BadLocationException {
|
||||
int p0, int p1) throws BadLocationException
|
||||
{
|
||||
return (int) drawUnselectedTextImpl(g, x, y, p0, p1, false);
|
||||
}
|
||||
|
||||
private float callDrawUnselectedText(Graphics g, float x, float y,
|
||||
int p0, int p1)
|
||||
throws BadLocationException
|
||||
{
|
||||
return drawUnselectedTextOverridden && g instanceof Graphics2D
|
||||
? drawUnselectedText((Graphics2D) g, x, y, p0, p1)
|
||||
: drawUnselectedText(g, (int) x, (int) y, p0, p1);
|
||||
}
|
||||
|
||||
private float drawUnselectedTextImpl(Graphics g, float x, float y,
|
||||
int p0, int p1, boolean useFPAPI)
|
||||
throws BadLocationException
|
||||
{
|
||||
g.setColor(unselected);
|
||||
Document doc = getDocument();
|
||||
Segment segment = SegmentCache.getSharedSegment();
|
||||
doc.getText(p0, p1 - p0, segment);
|
||||
int ret = Utilities.drawTabbedText(this, segment, x, y, g, this, p0);
|
||||
float ret = Utilities.drawTabbedText(this, segment, x, y, g, this, p0,
|
||||
null, useFPAPI);
|
||||
SegmentCache.releaseSharedSegment(segment);
|
||||
return ret;
|
||||
}
|
||||
@ -221,10 +246,6 @@ public class WrappedPlainView extends BoxView implements TabExpander {
|
||||
* Renders the given range in the model as normal unselected
|
||||
* text.
|
||||
*
|
||||
* @implSpec This implementation calls
|
||||
* {@link #drawUnselectedText(Graphics, int, int, int, int)
|
||||
* drawUnselectedText((Graphics)g, (int) x, (int) y, p0, p1)}.
|
||||
*
|
||||
* @param g the graphics context
|
||||
* @param x the starting X coordinate >= 0
|
||||
* @param y the starting Y coordinate >= 0
|
||||
@ -232,10 +253,12 @@ public class WrappedPlainView extends BoxView implements TabExpander {
|
||||
* @param p1 the ending position in the model >= p0
|
||||
* @return the X location of the end of the range >= 0
|
||||
* @exception BadLocationException if the range is invalid
|
||||
*
|
||||
* @since 9
|
||||
*/
|
||||
protected float drawUnselectedText(Graphics2D g, float x, float y,
|
||||
int p0, int p1) throws BadLocationException {
|
||||
return drawUnselectedText((Graphics) g, (int) x, (int) y, p0, p1);
|
||||
return drawUnselectedTextImpl(g, x, y, p0, p1, true);
|
||||
}
|
||||
/**
|
||||
* Renders the given range in the model as selected text. This
|
||||
@ -250,14 +273,37 @@ public class WrappedPlainView extends BoxView implements TabExpander {
|
||||
* @param p1 the ending position in the model >= p0
|
||||
* @return the location of the end of the range.
|
||||
* @exception BadLocationException if the range is invalid
|
||||
*
|
||||
* @deprecated replaced by
|
||||
* {@link #drawSelectedText(Graphics2D, float, float, int, int)}
|
||||
*/
|
||||
protected int drawSelectedText(Graphics g, int x,
|
||||
int y, int p0, int p1) throws BadLocationException {
|
||||
@Deprecated(since = "9")
|
||||
protected int drawSelectedText(Graphics g, int x, int y, int p0, int p1)
|
||||
throws BadLocationException
|
||||
{
|
||||
return (int) drawSelectedTextImpl(g, x, y, p0, p1, false);
|
||||
}
|
||||
|
||||
private float callDrawSelectedText(Graphics g, float x, float y,
|
||||
int p0, int p1)
|
||||
throws BadLocationException
|
||||
{
|
||||
return drawSelectedTextOverridden && g instanceof Graphics2D
|
||||
? drawSelectedText((Graphics2D) g, x, y, p0, p1)
|
||||
: drawSelectedText(g, (int) x, (int) y, p0, p1);
|
||||
}
|
||||
|
||||
private float drawSelectedTextImpl(Graphics g, float x, float y,
|
||||
int p0, int p1,
|
||||
boolean useFPAPI)
|
||||
throws BadLocationException
|
||||
{
|
||||
g.setColor(selected);
|
||||
Document doc = getDocument();
|
||||
Segment segment = SegmentCache.getSharedSegment();
|
||||
doc.getText(p0, p1 - p0, segment);
|
||||
int ret = Utilities.drawTabbedText(this, segment, x, y, g, this, p0);
|
||||
float ret = Utilities.drawTabbedText(this, segment, x, y, g, this, p0,
|
||||
null, useFPAPI);
|
||||
SegmentCache.releaseSharedSegment(segment);
|
||||
return ret;
|
||||
}
|
||||
@ -268,10 +314,6 @@ public class WrappedPlainView extends BoxView implements TabExpander {
|
||||
* the hosting component. It assumes the highlighter will render
|
||||
* the selected background.
|
||||
*
|
||||
* @implSpec This implementation calls
|
||||
* {@link #drawSelectedText(Graphics, int, int, int, int)
|
||||
* drawSelectedText((Graphics)g, (int) x, (int) y, p0, p1)}.
|
||||
*
|
||||
* @param g the graphics context
|
||||
* @param x the starting X coordinate >= 0
|
||||
* @param y the starting Y coordinate >= 0
|
||||
@ -279,10 +321,12 @@ public class WrappedPlainView extends BoxView implements TabExpander {
|
||||
* @param p1 the ending position in the model >= p0
|
||||
* @return the location of the end of the range.
|
||||
* @exception BadLocationException if the range is invalid
|
||||
*
|
||||
* @since 9
|
||||
*/
|
||||
protected float drawSelectedText(Graphics2D g, float x, float y,
|
||||
int p0, int p1) throws BadLocationException {
|
||||
return drawSelectedText((Graphics) g, (int) x, (int) y, p0, p1);
|
||||
return drawSelectedTextImpl(g, x, y, p0, p1, true);
|
||||
}
|
||||
/**
|
||||
* Gives access to a buffer that can be used to fetch
|
||||
@ -395,7 +439,13 @@ public class WrappedPlainView extends BoxView implements TabExpander {
|
||||
Component host = getContainer();
|
||||
Font f = host.getFont();
|
||||
metrics = host.getFontMetrics(f);
|
||||
tabSize = getTabSize() * metrics.charWidth('m');
|
||||
if (useFloatingPointAPI) {
|
||||
FontRenderContext frc = metrics.getFontRenderContext();
|
||||
float tabWidth = (float) f.getStringBounds("m", frc).getWidth();
|
||||
tabSize = getTabSize() * tabWidth;
|
||||
} else {
|
||||
tabSize = getTabSize() * metrics.charWidth('m');
|
||||
}
|
||||
}
|
||||
|
||||
// --- TabExpander methods ------------------------------------------
|
||||
@ -413,7 +463,7 @@ public class WrappedPlainView extends BoxView implements TabExpander {
|
||||
public float nextTabStop(float x, int tabOffset) {
|
||||
if (tabSize == 0)
|
||||
return x;
|
||||
int ntabs = ((int) x - tabBase) / tabSize;
|
||||
float ntabs = (x - tabBase) / tabSize;
|
||||
return tabBase + ((ntabs + 1) * tabSize);
|
||||
}
|
||||
|
||||
@ -591,7 +641,7 @@ public class WrappedPlainView extends BoxView implements TabExpander {
|
||||
Segment lineBuffer;
|
||||
boolean widthChanging;
|
||||
int tabBase;
|
||||
int tabSize;
|
||||
float tabSize;
|
||||
boolean wordWrap;
|
||||
|
||||
int sel0;
|
||||
@ -668,6 +718,7 @@ public class WrappedPlainView extends BoxView implements TabExpander {
|
||||
int end = getEndOffset();
|
||||
int p0 = start;
|
||||
int[] lineEnds = getLineEnds();
|
||||
boolean useDrawLineFP = drawLineOverridden && g instanceof Graphics2D;
|
||||
for (int i = 0; i < lineCount; i++) {
|
||||
int p1 = (lineEnds == null) ? end :
|
||||
start + lineEnds[i];
|
||||
@ -677,8 +728,11 @@ public class WrappedPlainView extends BoxView implements TabExpander {
|
||||
: p1;
|
||||
dh.paintLayeredHighlights(g, p0, hOffset, a, host, this);
|
||||
}
|
||||
drawLine(p0, p1, g, x, y);
|
||||
|
||||
if (useDrawLineFP) {
|
||||
drawLine(p0, p1, (Graphics2D) g, (float) x, (float) y);
|
||||
} else {
|
||||
drawLine(p0, p1, g, x, y);
|
||||
}
|
||||
p0 = p1;
|
||||
y += metrics.getHeight();
|
||||
}
|
||||
@ -929,4 +983,47 @@ public class WrappedPlainView extends BoxView implements TabExpander {
|
||||
int lineCount;
|
||||
SoftReference<int[]> lineCache = null;
|
||||
}
|
||||
|
||||
private final boolean drawLineOverridden;
|
||||
private final boolean drawSelectedTextOverridden;
|
||||
private final boolean drawUnselectedTextOverridden;
|
||||
private final boolean useFloatingPointAPI;
|
||||
|
||||
{
|
||||
final Class<?> CLS = getClass();
|
||||
final Class<?> INT = Integer.TYPE;
|
||||
final Class<?> FP = Float.TYPE;
|
||||
|
||||
drawLineOverridden = AccessController
|
||||
.doPrivileged(new PrivilegedAction<Boolean>() {
|
||||
@Override
|
||||
public Boolean run() {
|
||||
Class<?>[] intTypes = {INT, INT, Graphics.class, INT, INT};
|
||||
Class<?>[] fpTypes = {INT, INT, Graphics2D.class, FP, FP};
|
||||
return isFPMethodOverriden("drawLine", CLS, intTypes, fpTypes);
|
||||
}
|
||||
});
|
||||
|
||||
drawUnselectedTextOverridden = AccessController
|
||||
.doPrivileged(new PrivilegedAction<Boolean>() {
|
||||
@Override
|
||||
public Boolean run() {
|
||||
Class<?>[] intTypes = {Graphics.class, INT, INT, INT, INT};
|
||||
Class<?>[] fpTypes = {Graphics2D.class, FP, FP, INT, INT};
|
||||
return isFPMethodOverriden("drawUnselectedText", CLS, intTypes, fpTypes);
|
||||
}
|
||||
});
|
||||
|
||||
drawSelectedTextOverridden = AccessController
|
||||
.doPrivileged(new PrivilegedAction<Boolean>() {
|
||||
@Override
|
||||
public Boolean run() {
|
||||
Class<?>[] intTypes = {Graphics.class, INT, INT, INT, INT};
|
||||
Class<?>[] fpTypes = {Graphics2D.class, FP, FP, INT, INT};
|
||||
return isFPMethodOverriden("drawSelectedText", CLS, intTypes, fpTypes);
|
||||
}
|
||||
});
|
||||
|
||||
useFloatingPointAPI = drawUnselectedTextOverridden || drawSelectedTextOverridden;
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,6 +88,9 @@ module java.desktop {
|
||||
exports sun.awt to
|
||||
jdk.accessibility;
|
||||
|
||||
exports com.sun.awt to
|
||||
jdk.desktop;
|
||||
|
||||
uses java.awt.im.spi.InputMethodDescriptor;
|
||||
uses javax.accessibility.AccessibilityProvider;
|
||||
uses javax.imageio.spi.ImageInputStreamSpi;
|
||||
|
||||
@ -107,7 +107,7 @@ public final class AWTAccessor {
|
||||
/*
|
||||
* Requests focus to the component.
|
||||
*/
|
||||
boolean requestFocus(Component comp, Cause cause);
|
||||
void requestFocus(Component comp, Cause cause);
|
||||
/*
|
||||
* Determines if the component can gain focus.
|
||||
*/
|
||||
@ -1392,4 +1392,4 @@ public final class AWTAccessor {
|
||||
AWTAccessor.dropTargetContextAccessor = accessor;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2006, 2016, 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
|
||||
@ -103,7 +103,7 @@ public class IconInfo {
|
||||
}
|
||||
this.scaledWidth = width;
|
||||
this.scaledHeight = height;
|
||||
this.rawLength = getScaledRawLength();
|
||||
this.rawLength = getScaledRawLength(width, height);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -112,14 +112,14 @@ public class IconInfo {
|
||||
public void setScaledSize(int width, int height) {
|
||||
this.scaledWidth = width;
|
||||
this.scaledHeight = height;
|
||||
this.rawLength = getScaledRawLength();
|
||||
this.rawLength = getScaledRawLength(width, height);
|
||||
}
|
||||
|
||||
/*
|
||||
* returns scaled raw length.
|
||||
*/
|
||||
private int getScaledRawLength() {
|
||||
int scaledWidthAndHeight[] = getScaledWidthAndHeight(width, height);
|
||||
private int getScaledRawLength(int w, int h) {
|
||||
int scaledWidthAndHeight[] = getScaledWidthAndHeight(w, h);
|
||||
return scaledWidthAndHeight[0] * scaledWidthAndHeight[1] + 2;
|
||||
}
|
||||
|
||||
|
||||
@ -142,8 +142,8 @@ public abstract class KeyboardFocusManagerPeerImpl implements KeyboardFocusManag
|
||||
}
|
||||
|
||||
// WARNING: Don't call it on the Toolkit thread.
|
||||
public static boolean requestFocusFor(Component target, FocusEvent.Cause cause) {
|
||||
return AWTAccessor.getComponentAccessor().requestFocus(target, cause);
|
||||
public static void requestFocusFor(Component target, FocusEvent.Cause cause) {
|
||||
AWTAccessor.getComponentAccessor().requestFocus(target, cause);
|
||||
}
|
||||
|
||||
// WARNING: Don't call it on the Toolkit thread.
|
||||
|
||||
@ -1512,9 +1512,9 @@ public abstract class SunToolkit extends Toolkit
|
||||
*/
|
||||
protected abstract boolean syncNativeQueue(final long timeout);
|
||||
|
||||
private boolean eventDispatched = false;
|
||||
private boolean queueEmpty = false;
|
||||
private final Object waitLock = "Wait Lock";
|
||||
private boolean eventDispatched;
|
||||
private boolean queueEmpty;
|
||||
private final Object waitLock = new Object();
|
||||
|
||||
private boolean isEQEmpty() {
|
||||
EventQueue queue = getSystemEventQueueImpl();
|
||||
@ -1531,10 +1531,11 @@ public abstract class SunToolkit extends Toolkit
|
||||
@SuppressWarnings("serial")
|
||||
protected final boolean waitForIdle(final long timeout) {
|
||||
flushPendingEvents();
|
||||
boolean queueWasEmpty = isEQEmpty();
|
||||
queueEmpty = false;
|
||||
eventDispatched = false;
|
||||
synchronized(waitLock) {
|
||||
final boolean queueWasEmpty;
|
||||
synchronized (waitLock) {
|
||||
queueWasEmpty = isEQEmpty();
|
||||
queueEmpty = false;
|
||||
eventDispatched = false;
|
||||
postEvent(AppContext.getAppContext(),
|
||||
new PeerEvent(getSystemEventQueueImpl(), null, PeerEvent.LOW_PRIORITY_EVENT) {
|
||||
@Override
|
||||
|
||||
@ -1902,11 +1902,7 @@ public final class SunGraphics2D
|
||||
clipRegion = devClip;
|
||||
} else if (usrClip instanceof Rectangle2D) {
|
||||
clipState = CLIP_RECTANGULAR;
|
||||
if (usrClip instanceof Rectangle) {
|
||||
clipRegion = devClip.getIntersection((Rectangle)usrClip);
|
||||
} else {
|
||||
clipRegion = devClip.getIntersection(usrClip.getBounds());
|
||||
}
|
||||
clipRegion = devClip.getIntersection((Rectangle2D) usrClip);
|
||||
} else {
|
||||
PathIterator cpi = usrClip.getPathIterator(null);
|
||||
int box[] = new int[4];
|
||||
|
||||
@ -28,10 +28,13 @@ package sun.java2d.pipe;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.geom.RectangularShape;
|
||||
|
||||
import sun.java2d.loops.TransformHelper;
|
||||
|
||||
import static java.lang.Double.isNaN;
|
||||
|
||||
/**
|
||||
* This class encapsulates a definition of a two dimensional region which
|
||||
* consists of a number of Y ranges each containing multiple X bands.
|
||||
@ -117,6 +120,34 @@ public final class Region {
|
||||
return newv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the closest {@code int} to the argument, with ties rounding to
|
||||
* negative infinity.
|
||||
* <p>
|
||||
* Special cases:
|
||||
* <ul><li>If the argument is NaN, the result is 0.
|
||||
* <li>If the argument is negative infinity or any value less than or
|
||||
* equal to the value of {@code Integer.MIN_VALUE}, the result is
|
||||
* equal to the value of {@code Integer.MIN_VALUE}.
|
||||
* <li>If the argument is positive infinity or any value greater than or
|
||||
* equal to the value of {@code Integer.MAX_VALUE}, the result is
|
||||
* equal to the value of {@code Integer.MAX_VALUE}.</ul>
|
||||
*
|
||||
* @param coordinate a floating-point value to be rounded to an integer
|
||||
* @return the value of the argument rounded to the nearest
|
||||
* {@code int} value.
|
||||
*/
|
||||
public static int clipRound(final double coordinate) {
|
||||
final double newv = coordinate - 0.5;
|
||||
if (newv < Integer.MIN_VALUE) {
|
||||
return Integer.MIN_VALUE;
|
||||
}
|
||||
if (newv > Integer.MAX_VALUE) {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
return (int) Math.ceil(newv);
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply the scale factor {@code sv} and the value {@code v} with
|
||||
* appropriate clipping to the bounds of Integer resolution. If the answer
|
||||
@ -557,6 +588,33 @@ public final class Region {
|
||||
return getIntersectionXYXY(x, y, dimAdd(x, w), dimAdd(y, h));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Region object that represents the intersection of
|
||||
* this object with the specified Rectangle2D. The return value
|
||||
* may be this same object if no clipping occurs.
|
||||
*/
|
||||
public Region getIntersection(final Rectangle2D r) {
|
||||
if (r instanceof Rectangle) {
|
||||
return getIntersection((Rectangle) r);
|
||||
}
|
||||
return getIntersectionXYXY(r.getMinX(), r.getMinY(), r.getMaxX(),
|
||||
r.getMaxY());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Region object that represents the intersection of
|
||||
* this object with the specified rectangular area. The return
|
||||
* value may be this same object if no clipping occurs.
|
||||
*/
|
||||
public Region getIntersectionXYXY(double lox, double loy, double hix,
|
||||
double hiy) {
|
||||
if (isNaN(lox) || isNaN(loy) || isNaN(hix) || isNaN(hiy)) {
|
||||
return EMPTY_REGION;
|
||||
}
|
||||
return getIntersectionXYXY(clipRound(lox), clipRound(loy),
|
||||
clipRound(hix), clipRound(hiy));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Region object that represents the intersection of
|
||||
* this object with the specified rectangular area. The return
|
||||
|
||||
@ -30,6 +30,7 @@ import java.awt.*;
|
||||
import static java.awt.RenderingHints.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.font.*;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import static java.awt.geom.AffineTransform.TYPE_FLIP;
|
||||
import static java.awt.geom.AffineTransform.TYPE_TRANSLATION;
|
||||
@ -723,10 +724,31 @@ public class SwingUtilities2 {
|
||||
int length,
|
||||
int x,
|
||||
int y) {
|
||||
return (int) drawChars(c, g, data, offset, length, x, y, false);
|
||||
}
|
||||
|
||||
public static float drawChars(JComponent c, Graphics g,
|
||||
char[] data,
|
||||
int offset,
|
||||
int length,
|
||||
float x,
|
||||
float y) {
|
||||
return drawChars(c, g, data, offset, length, x, y, true);
|
||||
}
|
||||
|
||||
public static float drawChars(JComponent c, Graphics g,
|
||||
char[] data,
|
||||
int offset,
|
||||
int length,
|
||||
float x,
|
||||
float y,
|
||||
boolean useFPAPI) {
|
||||
if ( length <= 0 ) { //no need to paint empty strings
|
||||
return x;
|
||||
}
|
||||
int nextX = x + getFontMetrics(c, g).charsWidth(data, offset, length);
|
||||
float nextX = x + getFontCharsWidth(data, offset, length,
|
||||
getFontMetrics(c, g),
|
||||
useFPAPI);
|
||||
if (isPrinting(g)) {
|
||||
Graphics2D g2d = getGraphics2D(g);
|
||||
if (g2d != null) {
|
||||
@ -766,8 +788,14 @@ public class SwingUtilities2 {
|
||||
Object aaHint = (c == null)
|
||||
? null
|
||||
: c.getClientProperty(KEY_TEXT_ANTIALIASING);
|
||||
if (aaHint != null && (g instanceof Graphics2D)) {
|
||||
Graphics2D g2 = (Graphics2D)g;
|
||||
|
||||
if (!(g instanceof Graphics2D)) {
|
||||
g.drawChars(data, offset, length, (int) x, (int) y);
|
||||
return nextX;
|
||||
}
|
||||
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
if (aaHint != null) {
|
||||
|
||||
Object oldContrast = null;
|
||||
Object oldAAValue = g2.getRenderingHint(KEY_TEXT_ANTIALIASING);
|
||||
@ -788,7 +816,7 @@ public class SwingUtilities2 {
|
||||
}
|
||||
}
|
||||
|
||||
g.drawChars(data, offset, length, x, y);
|
||||
g2.drawString(new String(data, offset, length), x, y);
|
||||
|
||||
if (oldAAValue != null) {
|
||||
g2.setRenderingHint(KEY_TEXT_ANTIALIASING, oldAAValue);
|
||||
@ -798,19 +826,59 @@ public class SwingUtilities2 {
|
||||
}
|
||||
}
|
||||
else {
|
||||
g.drawChars(data, offset, length, x, y);
|
||||
g2.drawString(new String(data, offset, length), x, y);
|
||||
}
|
||||
return nextX;
|
||||
}
|
||||
|
||||
public static float getFontCharWidth(char c, FontMetrics fm,
|
||||
boolean useFPAPI)
|
||||
{
|
||||
return getFontCharsWidth(new char[]{c}, 0, 1, fm, useFPAPI);
|
||||
}
|
||||
|
||||
public static float getFontCharsWidth(char[] data, int offset, int len,
|
||||
FontMetrics fm,
|
||||
boolean useFPAPI)
|
||||
{
|
||||
return len == 0 ? 0 : getFontStringWidth(new String(data, offset, len),
|
||||
fm, useFPAPI);
|
||||
}
|
||||
|
||||
public static float getFontStringWidth(String data, FontMetrics fm,
|
||||
boolean useFPAPI)
|
||||
{
|
||||
if (useFPAPI) {
|
||||
Rectangle2D bounds = fm.getFont()
|
||||
.getStringBounds(data, fm.getFontRenderContext());
|
||||
return (float) bounds.getWidth();
|
||||
} else {
|
||||
return fm.stringWidth(data);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* see documentation for drawChars
|
||||
* returns the advance
|
||||
*/
|
||||
public static float drawString(JComponent c, Graphics g,
|
||||
AttributedCharacterIterator iterator,
|
||||
int x,
|
||||
int y) {
|
||||
int x, int y)
|
||||
{
|
||||
return drawStringImpl(c, g, iterator, x, y);
|
||||
}
|
||||
|
||||
public static float drawString(JComponent c, Graphics g,
|
||||
AttributedCharacterIterator iterator,
|
||||
float x, float y)
|
||||
{
|
||||
return drawStringImpl(c, g, iterator, x, y);
|
||||
}
|
||||
|
||||
private static float drawStringImpl(JComponent c, Graphics g,
|
||||
AttributedCharacterIterator iterator,
|
||||
float x, float y)
|
||||
{
|
||||
|
||||
float retVal;
|
||||
boolean isPrinting = isPrinting(g);
|
||||
@ -825,8 +893,8 @@ public class SwingUtilities2 {
|
||||
|
||||
Graphics2D g2d = getGraphics2D(g);
|
||||
if (g2d == null) {
|
||||
g.drawString(iterator,x,y); //for the cases where advance
|
||||
//matters it should not happen
|
||||
g.drawString(iterator, (int)x, (int)y); //for the cases where advance
|
||||
//matters it should not happen
|
||||
retVal = x;
|
||||
|
||||
} else {
|
||||
|
||||
@ -25,7 +25,12 @@
|
||||
|
||||
#include "splashscreen_impl.h"
|
||||
#include "splashscreen_gfx_impl.h"
|
||||
|
||||
#define BUFF_SIZE 1024
|
||||
#ifdef _MSC_VER
|
||||
# ifndef snprintf
|
||||
# define snprintf _snprintf
|
||||
# endif
|
||||
#endif
|
||||
int splashIsVisible = 0;
|
||||
|
||||
Splash *
|
||||
@ -392,5 +397,101 @@ int SplashStreamInitMemory(SplashStream * pStream, void* pData, int size) {
|
||||
|
||||
SPLASHEXPORT int
|
||||
SplashGetScaledImgNameMaxPstfixLen(const char *fileName){
|
||||
return strlen(fileName) + strlen(".java-scale-200") + 1;
|
||||
return strlen(fileName) + strlen("@100pct") + 1;
|
||||
}
|
||||
|
||||
jboolean GetScaledImageName(const char *fileName, char *scaleImageName,
|
||||
float *scaleFactor, const size_t scaledImageLength) {
|
||||
if (*scaleFactor > 1.0) {
|
||||
FILE *fp = NULL;
|
||||
char scaledImgPct[BUFF_SIZE];
|
||||
char scaledImgX[BUFF_SIZE];
|
||||
char *scaledImageXName = NULL;
|
||||
char *scaledImagePctName = malloc(scaledImageLength);
|
||||
char *dupFileName = strdup(fileName);
|
||||
char *fileExtension = strrchr(dupFileName, '.');
|
||||
size_t lengthPct = 0;
|
||||
size_t lengthX = 0;
|
||||
int retValPct = 0;
|
||||
int retValX = 0;
|
||||
jboolean isPctScaledImage = (*scaleFactor * 100) != ((int) (*scaleFactor)) *100;
|
||||
snprintf(scaledImgPct, BUFF_SIZE, "%s%d%s", "@",
|
||||
(int) (*scaleFactor * 100), "pct");
|
||||
if (!isPctScaledImage) {
|
||||
scaledImageXName = malloc(scaledImageLength);
|
||||
snprintf(scaledImgX, BUFF_SIZE, "%s%d%s", "@", (int) (*scaleFactor), "x");
|
||||
}
|
||||
/*File is missing extension */
|
||||
if (fileExtension == NULL) {
|
||||
lengthPct = strlen(dupFileName) +
|
||||
strlen(scaledImgPct) + 1;
|
||||
if (!isPctScaledImage) {
|
||||
lengthX = strlen(dupFileName) +
|
||||
strlen(scaledImgX) + 1;
|
||||
}
|
||||
if (lengthPct > scaledImageLength || lengthX > scaledImageLength) {
|
||||
cleanUp(dupFileName, scaledImageXName, scaledImagePctName, scaleFactor);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
retValPct = snprintf(scaledImagePctName, lengthPct, "%s%s", dupFileName,
|
||||
scaledImgPct);
|
||||
if (!isPctScaledImage) {
|
||||
retValX = snprintf(scaledImageXName, lengthX, "%s%s", dupFileName,
|
||||
scaledImgX);
|
||||
}
|
||||
if ((retValPct < 0 || (retValPct > lengthPct - 1)) ||
|
||||
(retValX < 0 || (retValX > lengthX - 1))) {
|
||||
cleanUp(dupFileName, scaledImageXName, scaledImagePctName, scaleFactor);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
} else {
|
||||
int length_Without_Ext = fileExtension - dupFileName;
|
||||
lengthPct = length_Without_Ext + strlen(scaledImgPct) +
|
||||
strlen(fileExtension) + 1;
|
||||
if (!isPctScaledImage) {
|
||||
lengthX = length_Without_Ext + strlen(scaledImgX) +
|
||||
strlen(fileExtension) + 1;
|
||||
}
|
||||
if (lengthPct > scaledImageLength || lengthX > scaledImageLength) {
|
||||
cleanUp(dupFileName, scaledImageXName, scaledImagePctName, scaleFactor);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
retValPct = snprintf(scaledImagePctName, lengthPct, "%.*s%s%s",
|
||||
length_Without_Ext, dupFileName, scaledImgPct, fileExtension);
|
||||
if (!isPctScaledImage) {
|
||||
retValX = snprintf(scaledImageXName, lengthX, "%.*s%s%s",
|
||||
length_Without_Ext, dupFileName, scaledImgX, fileExtension);
|
||||
}
|
||||
if ((retValPct < 0 || (retValPct > lengthPct - 1)) ||
|
||||
(retValX < 0 || (retValX > lengthX - 1))) {
|
||||
cleanUp(dupFileName, scaledImageXName, scaledImagePctName, scaleFactor);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
}
|
||||
free(dupFileName);
|
||||
if (!(fp = fopen(scaledImagePctName, "r"))) {
|
||||
if (!isPctScaledImage && (fp = fopen(scaledImageXName, "r"))) {
|
||||
fclose(fp);
|
||||
strcpy(scaleImageName, scaledImageXName);
|
||||
free(scaledImageXName);
|
||||
free(scaledImagePctName);
|
||||
return JNI_TRUE;
|
||||
}
|
||||
cleanUp(NULL, scaledImageXName, scaledImagePctName, scaleFactor);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
fclose(fp);
|
||||
strcpy(scaleImageName, scaledImagePctName);
|
||||
free(scaledImageXName);
|
||||
free(scaledImagePctName);
|
||||
return JNI_TRUE;
|
||||
}
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
void cleanUp(char *fName, char *xName, char *pctName, float *scaleFactor) {
|
||||
*scaleFactor = 1;
|
||||
free(fName);
|
||||
free(xName);
|
||||
free(pctName);
|
||||
}
|
||||
|
||||
@ -150,7 +150,9 @@ void SplashUpdateScreenData(Splash * splash);
|
||||
void SplashCleanup(Splash * splash);
|
||||
void SplashSetScaleFactor(float scaleFactor);
|
||||
int SplashGetScaledImgNameMaxPstfixLen(const char *fileName);
|
||||
|
||||
void cleanUp(char *fName, char *xName, char *pctName, float *scaleFactor);
|
||||
jboolean GetScaledImageName(const char *fileName, char *scaledImgName,
|
||||
float *scaleFactor, const size_t scaledImageLength);
|
||||
typedef struct SplashStream {
|
||||
int (*read)(void* pStream, void* pData, int nBytes);
|
||||
int (*peek)(void* pStream);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user