提交 ef975556 编写于 作者: W wetmore

Merge

......@@ -50,13 +50,13 @@ CC_DEPEND = -MM
CC_DEPEND_FILTER = $(SED) -e 's!$*\.$(OBJECT_SUFFIX)!$(dir $@)& $(dir $@)$*.$(DEPEND_SUFFIX)!g'
ifndef PLATFORM_SRC
PLATFORM_SRC = $(JDK_TOPDIR)/src/solaris
PLATFORM_SRC = $(BUILDDIR)/../src/solaris
endif # PLATFORM_SRC
# Platform specific closed sources
ifndef OPENJDK
ifndef CLOSED_PLATFORM_SRC
CLOSED_PLATFORM_SRC = $(JDK_TOPDIR)/src/closed/solaris
CLOSED_PLATFORM_SRC = $(BUILDDIR)/../src/closed/solaris
endif
endif
......
......@@ -45,13 +45,13 @@
include $(JDK_MAKE_SHARED_DIR)/Defs.gmk
ifndef PLATFORM_SRC
PLATFORM_SRC = $(JDK_TOPDIR)/src/solaris
PLATFORM_SRC = $(BUILDDIR)/../src/solaris
endif # PLATFORM_SRC
# Platform specific closed sources
ifndef OPENJDK
ifndef CLOSED_PLATFORM_SRC
CLOSED_PLATFORM_SRC = $(JDK_TOPDIR)/src/closed/solaris
CLOSED_PLATFORM_SRC = $(BUILDDIR)/../src/closed/solaris
endif
endif
......
......@@ -51,13 +51,13 @@ ifndef LIB_LOCATION
endif # LIB_LOCATION
ifndef PLATFORM_SRC
PLATFORM_SRC = $(JDK_TOPDIR)/src/windows
PLATFORM_SRC = $(BUILDDIR)/../src/windows
endif # PLATFORM_SRC
# Platform specific closed sources
ifndef OPENJDK
ifndef CLOSED_PLATFORM_SRC
CLOSED_PLATFORM_SRC = $(JDK_TOPDIR)/src/closed/windows
CLOSED_PLATFORM_SRC = $(BUILDDIR)/../src/closed/windows
endif
endif
......@@ -367,7 +367,7 @@ else
endif
# Settings for the VERSIONINFO tap on windows.
VERSIONINFO_RESOURCE = $(JDK_TOPDIR)/src/windows/resource/version.rc
VERSIONINFO_RESOURCE = $(BUILDDIR)/../src/windows/resource/version.rc
ifneq ($(JDK_BUILD_NUMBER),)
COOKED_BUILD_NUMBER = $(shell $(ECHO) $(JDK_BUILD_NUMBER) | $(SED) -e 's/^b//' -e 's/^0//')
......
......@@ -41,7 +41,15 @@
SUN_MAKE_TEST:sh = echo "ERROR: PLEASE USE GNU VERSION OF MAKE"; exit 33
ifndef JDK_TOPDIR
JDK_TOPDIR=$(BUILDDIR)/..
ifdef BUILDDIR
JDK_TOPDIR=$(BUILDDIR)/..
else
JDK_TOPDIR:=$(error "ERROR: Cannot define top of jdk repository")
endif
endif
ifndef BUILDDIR
# Hack, due to deploy repository using this file.
BUILDDIR=$(JDK_TOPDIR)/make
endif
ifndef JDK_MAKE_SHARED_DIR
JDK_MAKE_SHARED_DIR=$(JDK_TOPDIR)/make/common/shared
......@@ -59,13 +67,13 @@ include $(JDK_TOPDIR)/make/common/CancelImplicits.gmk
# there yet.
#
ifndef SHARE_SRC
SHARE_SRC = $(JDK_TOPDIR)/src/share
SHARE_SRC = $(BUILDDIR)/../src/share
endif
# Files that cannot be included in the OpenJDK distribution are
# collected under a parent directory which contains just those files.
ifndef CLOSED_SRC
CLOSED_SRC = $(JDK_TOPDIR)/src/closed
CLOSED_SRC = $(BUILDDIR)/../src/closed
endif
# If we have no closed directory, force it to an openjdk build
......@@ -170,14 +178,6 @@ ifdef OPENJDK
endif
endif # OPENJDK
# Default output directory
ifdef OPENJDK
_OUTPUTDIR=$(JDK_TOPDIR)/build/$(PLATFORM)-$(ARCH)$(OPENJDK_SUFFIX)
else
_OUTPUTDIR=$(JDK_TOPDIR)/build/$(PLATFORM)-$(ARCH)
endif
#
# Get platform definitions
#
......
......@@ -36,7 +36,7 @@ ifndef JDK_MAKE_SHARED_DIR
endif
ifndef CONTROL_TOPDIR
CONTROL_TOPDIR=$(TOPDIR)/control
CONTROL_TOPDIR=$(TOPDIR)
endif
ifndef HOTSPOT_TOPDIR
HOTSPOT_TOPDIR=$(TOPDIR)/hotspot
......@@ -70,7 +70,8 @@ endif
include $(JDK_MAKE_SHARED_DIR)/Platform.gmk
# Default output directory
_OUTPUTDIR=$(CONTROL_TOPDIR)/build/$(PLATFORM)-$(ARCH)
BUILD_PARENT_DIRECTORY=$(TOPDIR)
_OUTPUTDIR=$(TOPDIR)/build/$(PLATFORM)-$(ARCH)
# Get platform specific settings
include $(JDK_MAKE_SHARED_DIR)/Defs.gmk
......
......@@ -55,7 +55,10 @@ include $(JDK_MAKE_SHARED_DIR)/Defs-utils.gmk
# Simple pwd path
define PwdPath
$(shell cd $1 2> $(DEV_NULL) && pwd)
$(shell $(CD) $1 2> $(DEV_NULL) && $(PWD))
endef
define AbsPwdPathCheck
$(shell $(CD) .. 2> $(DEV_NULL) && $(CD) $1 2> $(DEV_NULL) && $(PWD))
endef
# Checks an ALT value for spaces (should be one word),
......@@ -422,23 +425,54 @@ CACERTS_FILE:=$(call AltCheckSpaces,CACERTS_FILE)
CACERTS_FILE:=$(call AltCheckValue,CACERTS_FILE)
# OUTPUTDIR: Location of all output for the build
_BACKUP_OUTPUTDIR = $(TEMP_DISK)/$(USER)/jdk-outputdir
ifdef ALT_OUTPUTDIR
_POSSIBLE_OUTPUTDIR =$(subst \,/,$(ALT_OUTPUTDIR))
OUTPUTDIR:=$(subst \,/,$(ALT_OUTPUTDIR))
# Assumes this is absolute (checks later)
ABS_OUTPUTDIR:=$(OUTPUTDIR)
else
ifndef _OUTPUTDIR
_OUTPUTDIR = $(_BACKUP_OUTPUTDIR)
# Default: Get "build" parent directory, which should always exist
ifndef BUILD_PARENT_DIRECTORY
BUILD_PARENT_DIRECTORY=$(BUILDDIR)/..
endif
ABS_BUILD_PARENT_DIRECTORY:=$(call FullPath,$(BUILD_PARENT_DIRECTORY))
ifdef OPENJDK
_OUTPUTDIRNAME=$(PLATFORM)-$(ARCH)$(OPENJDK_SUFFIX)
else
_OUTPUTDIRNAME=$(PLATFORM)-$(ARCH)
endif
_OUTPUTDIR=$(BUILD_PARENT_DIRECTORY)/build/$(_OUTPUTDIRNAME)
ABS_OUTPUTDIR:=$(ABS_BUILD_PARENT_DIRECTORY)/build/$(_OUTPUTDIRNAME)
endif
_POSSIBLE_OUTPUTDIR =$(_OUTPUTDIR)
endif
_create_outputdir1:=$(shell mkdir -p $(_POSSIBLE_OUTPUTDIR) > $(DEV_NULL) 2>&1)
OUTPUTDIR:=$(call WriteDirExists,$(_POSSIBLE_OUTPUTDIR),$(_BACKUP_OUTPUTDIR))
_create_outputdir2:=$(shell mkdir -p $(OUTPUTDIR) > $(DEV_NULL) 2>&1)
ifeq "$(OUTPUTDIR)" "$(_BACKUP_OUTPUTDIR)"
_outputdir_warning:=$(warning "WARNING: OUTPUTDIR '$(_POSSIBLE_OUTPUTDIR)' not writable, will use '$(_BACKUP_OUTPUTDIR)'")
OUTPUTDIR:=$(_OUTPUTDIR)
endif
# Check for spaces and null value
OUTPUTDIR:=$(call AltCheckSpaces,OUTPUTDIR)
OUTPUTDIR:=$(call AltCheckValue,OUTPUTDIR)
# Create the output directory and make sure it exists and is writable
_create_outputdir:=$(shell $(MKDIR) -p "$(OUTPUTDIR)" > $(DEV_NULL) 2>&1)
ifeq ($(call WriteDirExists,$(OUTPUTDIR),/dev/null),/dev/null)
_outputdir_error:=$(error "ERROR: OUTPUTDIR '$(OUTPUTDIR)' not created or not writable")
endif
# Define absolute path if needed and check for spaces and null value
ifndef ABS_OUTPUTDIR
ABS_OUTPUTDIR:=$(call FullPath,$(OUTPUTDIR))
endif
ABS_OUTPUTDIR:=$(call AltCheckSpaces,ABS_OUTPUTDIR)
ABS_OUTPUTDIR:=$(call AltCheckValue,ABS_OUTPUTDIR)
# Make doubly sure this is a full path
ifeq ($(call AbsPwdPathCheck,$(ABS_OUTPUTDIR)), )
ifdef ALT_OUTPUTDIR
_outputdir_error:=$(error "ERROR: Trouble with the absolute path for OUTPUTDIR '$(OUTPUTDIR)', was ALT_OUTPUTDIR '$(ALT_OUTPUTDIR)' an absolute path?")
else
_outputdir_error:=$(error "ERROR: Trouble with the absolute path for OUTPUTDIR '$(OUTPUTDIR)'")
endif
endif
_dir1:=$(call FullPath,$(ABS_OUTPUTDIR))
_dir2:=$(call FullPath,$(OUTPUTDIR))
ifneq ($(_dir1),$(_dir2))
_outputdir_error:=$(error "ERROR: ABS_OUTPUTDIR '$(ABS_OUTPUTDIR)' is not the same directory as OUTPUTDIR '$(OUTPUTDIR)', '$(_dir1)'!='$(_dir2)'")
endif
# Bin directory
# NOTE: ISA_DIR is usually empty, on Solaris it might be /sparcv9 or /amd64
......@@ -475,9 +509,6 @@ else
COPYRIGHT_YEAR = $(shell $(DATE) '+%Y')
endif
# Absolute path to output directory
ABS_OUTPUTDIR:=$(call FullPath,$(OUTPUTDIR))
# Get shared compiler settings
include $(JDK_MAKE_SHARED_DIR)/Compiler.gmk
......@@ -93,20 +93,18 @@ SYSTEM_UNAME := $(shell uname)
# Normal boot jdk is previous release, but a hard requirement is a 1.5 boot
REQUIRED_BOOT_VER = 1.5
#This is specific to OpenJDK build
ifdef OPENJDK
REQUIRED_FREETYPE_VERSION=2.3.0
endif
# If we are using freetype, this is the required version
REQUIRED_FREETYPE_VERSION=2.3.0
#
# Prune out all known SCM (Source Code Management) directories
# so they will not be included when copying directory trees
# or packaging up .jar files, etc. This applies to all workspaces.
#
SCM_DIRs = .hg .svn CVS RCS SCCS Codemgr_wsdata deleted_files
SCM_DIRs = .hg .svn CVS RCS SCCS Codemgr_wsdata deleted_files .hgignore .hgtags
# When changing SCM_DIRs also change SCM_DIRS_rexp and SCM_DIRS_prune:
SCM_DIRS_rexp = ".hg|.svn|CVS|RCS|SCCS|Codemgr_wsdata|deleted_files"
SCM_DIRS_prune = \( -name .hg -o -name .svn -o -name CVS -o -name RCS -o -name SCCS -o -name Codemgr_wsdata -o -name deleted_files \) -prune
SCM_DIRS_rexp = ".hg|.svn|CVS|RCS|SCCS|Codemgr_wsdata|deleted_files|.hgignore|.hgtags"
SCM_DIRS_prune = \( -name .hg -o -name .svn -o -name CVS -o -name RCS -o -name SCCS -o -name Codemgr_wsdata -o -name deleted_files -o -name .hgignore -o -name .hgtags \) -prune
# Don't define this unless it's not defined
ifndef VARIANT
......
......@@ -191,7 +191,7 @@ sources: $(SPP) $(FILES_genout)
GEN_BUFFER_SH = genBuffer.sh
GEN_BUFFER_CMD = SPP="$(SPP_CMD)" NAWK=$(NAWK) SED=$(SED) \
GEN_BUFFER_CMD = SPP="$(SPP_CMD)" NAWK=$(NAWK) SED=$(SED) SH=$(SH) \
$(SH) $(GEN_BUFFER_SH)
# Public abstract buffer classes
......@@ -582,7 +582,7 @@ $(BUF_GEN)/ByteBufferAsDoubleBuffer%L.java: $(BUF_SRC)/ByteBufferAs-X-Buffer.jav
GEN_CODER_SH = genCoder.sh
GEN_CODER_CMD = SPP="$(SPP_CMD)" SED=$(SED) NAWK=$(NAWK) $(SH) $(GEN_CODER_SH)
GEN_CODER_CMD = SPP="$(SPP_CMD)" SED=$(SED) NAWK=$(NAWK) SH=$(SH) $(SH) $(GEN_CODER_SH)
$(CS_GEN)/CharsetDecoder.java: $(CS_SRC)/Charset-X-Coder.java $(GEN_CODER_SH)
$(prep-target)
......@@ -602,7 +602,7 @@ $(CS_GEN)/CharsetEncoder.java: $(CS_SRC)/Charset-X-Coder.java $(GEN_CODER_SH)
GEN_EX_SH = genExceptions.sh
GEN_EX_CMD = NAWK=$(NAWK) $(SHELL) $(GEN_EX_SH)
GEN_EX_CMD = NAWK=$(NAWK) SH=$(SH) $(SH) $(GEN_EX_SH)
$(CH_GEN)/%Exception.java: genExceptions.sh $(CH_SRC)/exceptions
$(prep-target)
......@@ -635,8 +635,8 @@ $(SCS_GEN)/StandardCharsets.java: genCharsetProvider.sh \
$(HASHER_JARFILE) $(SCS_SRC)/standard-charsets
$(prep-target)
@$(RM) $@.temp
NAWK=$(NAWK) TEMPDIR=$(TEMPDIR) \
NAWK=$(NAWK) TEMPDIR=$(TEMPDIR) SH=$(SH) \
HASHER="$(BOOT_JAVA_CMD) -jar $(HASHER_JARFILE)" \
$(SHELL) -e genCharsetProvider.sh $(SCS_SRC)/standard-charsets $(SCS_GEN)
$(SH) -e genCharsetProvider.sh $(SCS_SRC)/standard-charsets $(SCS_GEN)
.PHONY: sources
......@@ -48,7 +48,7 @@ echo '-->' $OUT
# Header
#
$SHELL addNotices.sh "$COPYRIGHT_YEARS" > $OUT
$SH ./addNotices.sh "$COPYRIGHT_YEARS" > $OUT
cat <<__END__ >>$OUT
......
......@@ -41,7 +41,7 @@ gen() {
echo '-->' $DST/$ID.java
out=$DST/${ID}.java
$SHELL addNotices.sh "$COPYRIGHT_YEARS" > $out
$SH ./addNotices.sh "$COPYRIGHT_YEARS" > $out
cat >>$out <<__END__
......
......@@ -85,3 +85,13 @@ vpath %.c $(PLATFORM_SRC)/native/$(PKGDIR)/splashscreen
CPPFLAGS += -I$(PLATFORM_SRC)/native/$(PKGDIR)/splashscreen -I$(SHARE_SRC)/native/$(PKGDIR)/splashscreen
CPPFLAGS += -I$(SHARE_SRC)/native/$(PKGDIR)/image/jpeg -I$(SHARE_SRC)/native/java/util/zip/zlib-1.1.3
ifeq ($(PLATFORM), linux)
ifeq ($(ARCH_DATA_MODEL), 64)
# 64-bit gcc has problems compiling MMX instructions.
# Google it for more details. Possibly the newer versions of
# the PNG-library and/or the new compiler will not need this
# option in the future.
CPPFLAGS += -DPNG_NO_MMX_CODE
endif
endif
#
# Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved.
# Copyright 2002-2008 Sun Microsystems, Inc. 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
......@@ -246,7 +246,7 @@ $(SIZES): $(SIZERS)
@if [ "$(DOCOMPARE)$(suffix $@)" = "true.64" ]; then \
$(ECHO) COMPARING $@ and $(STORED_SIZES_TMPL_$(PLATFORM)_$(LIBARCH)); \
$(DIFF) $@ $(STORED_SIZES_TMPL_$(PLATFORM)_$(LIBARCH)); \
fi
fi
$(TEMPDIR)/.gen.wrappers: $(SIZES) $(WRAPPER_GENERATOR_CLASS) $(XLIBTYPES)
$(BOOT_JAVA_CMD) -cp $(WRAPPER_GENERATOR_TEMPDIR) WrapperGenerator \
......@@ -256,10 +256,11 @@ touch.wrappers: $(TEMPDIR)/.gen.wrappers
$(MKDIR) -p $(TEMPDIR)
$(TOUCH) $(TEMPDIR)/.gen.wrappers
generated.clean:
generated.clean:
$(RM) -r $(WRAPPER_GENERATOR_TEMPDIR)
$(RM) -r $(WRAPPER_GENERATOR_DIR)
$(RM) -r $(GEN_DIR)/*.java
$(RM) -r $(TEMPDIR)/.gen_icons
ifdef OPENJDK
ICONS_PATH_PREFIX=$(PLATFORM_SRC)
......
......@@ -38,7 +38,14 @@ FT_TEST_PATH = $(TEMPDIR)/$(FT_TEST)
all: $(FT_TEST_PATH)
FT_OPTIONS = -I$(FT_HEADERS) -I$(FT_HEADERS)/freetype2
# Start with CFLAGS (which gets us the required -xarch setting on solaris)
ifeq ($(PLATFORM), windows)
FT_OPTIONS =
else
FT_OPTIONS = $(CFLAGS)
endif
FT_OPTIONS += -I$(FT_HEADERS) -I$(FT_HEADERS)/freetype2
FT_OPTIONS += $(XARCH)
#add runtime library search path
......
......@@ -1118,11 +1118,11 @@ public abstract class OpenConverter {
final Class<ConstructorProperties> propertyNamesClass = ConstructorProperties.class;
Class targetClass = getTargetClass();
Constructor[] constrs = targetClass.getConstructors();
Constructor<?>[] constrs = targetClass.getConstructors();
// Applicable if and only if there are any annotated constructors
List<Constructor> annotatedConstrList = newList();
for (Constructor constr : constrs) {
List<Constructor<?>> annotatedConstrList = newList();
for (Constructor<?> constr : constrs) {
if (Modifier.isPublic(constr.getModifiers())
&& constr.getAnnotation(propertyNamesClass) != null)
annotatedConstrList.add(constr);
......@@ -1152,7 +1152,7 @@ public abstract class OpenConverter {
// Also remember the set of properties in that constructor
// so we can test unambiguity.
Set<BitSet> getterIndexSets = newSet();
for (Constructor constr : annotatedConstrList) {
for (Constructor<?> constr : annotatedConstrList) {
String[] propertyNames =
constr.getAnnotation(propertyNamesClass).value();
......@@ -1309,10 +1309,10 @@ public abstract class OpenConverter {
}
private static class Constr {
final Constructor constructor;
final Constructor<?> constructor;
final int[] paramIndexes;
final BitSet presentParams;
Constr(Constructor constructor, int[] paramIndexes,
Constr(Constructor<?> constructor, int[] paramIndexes,
BitSet presentParams) {
this.constructor = constructor;
this.paramIndexes = paramIndexes;
......
CTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!--
......
......@@ -634,6 +634,11 @@ public abstract class Component implements ImageObserver, MenuContainer,
*/
private PropertyChangeSupport changeSupport;
private transient final Object changeSupportLock = new Object();
private Object getChangeSupportLock() {
return changeSupportLock;
}
boolean isPacked = false;
/**
......@@ -935,24 +940,26 @@ public abstract class Component implements ImageObserver, MenuContainer,
*/
public GraphicsConfiguration getGraphicsConfiguration() {
synchronized(getTreeLock()) {
GraphicsConfiguration gc = graphicsConfig;
Component parent = getParent();
while ((gc == null) && (parent != null)) {
gc = parent.getGraphicsConfiguration();
parent = parent.getParent();
if (graphicsConfig != null) {
return graphicsConfig;
} else if (getParent() != null) {
return getParent().getGraphicsConfiguration();
} else {
return null;
}
return gc;
}
}
final GraphicsConfiguration getGraphicsConfiguration_NoClientCode() {
GraphicsConfiguration gc = this.graphicsConfig;
Component par = this.parent;
while ((gc == null) && (par != null)) {
gc = par.getGraphicsConfiguration_NoClientCode();
par = par.parent;
GraphicsConfiguration graphicsConfig = this.graphicsConfig;
Container parent = this.parent;
if (graphicsConfig != null) {
return graphicsConfig;
} else if (parent != null) {
return parent.getGraphicsConfiguration_NoClientCode();
} else {
return null;
}
return gc;
}
/**
......@@ -4602,7 +4609,8 @@ public abstract class Component implements ImageObserver, MenuContainer,
e.isPopupTrigger(),
e.getScrollType(),
e.getScrollAmount(),
e.getWheelRotation());
e.getWheelRotation(),
e.getPreciseWheelRotation());
((AWTEvent)e).copyPrivateDataInto(newMWE);
// When dispatching a wheel event to
// ancestor, there is no need trying to find descendant
......@@ -6484,7 +6492,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
// will need some help.
Container parent = this.parent;
if (parent != null && parent.peer instanceof LightweightPeer) {
nativeInLightFixer = new NativeInLightFixer();
relocateComponent();
}
}
invalidate();
......@@ -6595,10 +6603,6 @@ public abstract class Component implements ImageObserver, MenuContainer,
}
}
if (nativeInLightFixer != null) {
nativeInLightFixer.uninstall();
}
ComponentPeer p = peer;
if (p != null) {
boolean isLightweight = isLightweight();
......@@ -7836,15 +7840,17 @@ public abstract class Component implements ImageObserver, MenuContainer,
* @see #getPropertyChangeListeners
* @see #addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
*/
public synchronized void addPropertyChangeListener(
public void addPropertyChangeListener(
PropertyChangeListener listener) {
if (listener == null) {
return;
}
if (changeSupport == null) {
changeSupport = new PropertyChangeSupport(this);
synchronized (getChangeSupportLock()) {
if (listener == null) {
return;
}
if (changeSupport == null) {
changeSupport = new PropertyChangeSupport(this);
}
changeSupport.addPropertyChangeListener(listener);
}
changeSupport.addPropertyChangeListener(listener);
}
/**
......@@ -7860,12 +7866,14 @@ public abstract class Component implements ImageObserver, MenuContainer,
* @see #getPropertyChangeListeners
* @see #removePropertyChangeListener(java.lang.String,java.beans.PropertyChangeListener)
*/
public synchronized void removePropertyChangeListener(
public void removePropertyChangeListener(
PropertyChangeListener listener) {
if (listener == null || changeSupport == null) {
return;
synchronized (getChangeSupportLock()) {
if (listener == null || changeSupport == null) {
return;
}
changeSupport.removePropertyChangeListener(listener);
}
changeSupport.removePropertyChangeListener(listener);
}
/**
......@@ -7882,11 +7890,13 @@ public abstract class Component implements ImageObserver, MenuContainer,
* @see java.beans.PropertyChangeSupport#getPropertyChangeListeners
* @since 1.4
*/
public synchronized PropertyChangeListener[] getPropertyChangeListeners() {
if (changeSupport == null) {
return new PropertyChangeListener[0];
public PropertyChangeListener[] getPropertyChangeListeners() {
synchronized (getChangeSupportLock()) {
if (changeSupport == null) {
return new PropertyChangeListener[0];
}
return changeSupport.getPropertyChangeListeners();
}
return changeSupport.getPropertyChangeListeners();
}
/**
......@@ -7920,16 +7930,18 @@ public abstract class Component implements ImageObserver, MenuContainer,
* @see #getPropertyChangeListeners(java.lang.String)
* @see #addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
*/
public synchronized void addPropertyChangeListener(
public void addPropertyChangeListener(
String propertyName,
PropertyChangeListener listener) {
if (listener == null) {
return;
}
if (changeSupport == null) {
changeSupport = new PropertyChangeSupport(this);
synchronized (getChangeSupportLock()) {
if (listener == null) {
return;
}
if (changeSupport == null) {
changeSupport = new PropertyChangeSupport(this);
}
changeSupport.addPropertyChangeListener(propertyName, listener);
}
changeSupport.addPropertyChangeListener(propertyName, listener);
}
/**
......@@ -7948,13 +7960,15 @@ public abstract class Component implements ImageObserver, MenuContainer,
* @see #getPropertyChangeListeners(java.lang.String)
* @see #removePropertyChangeListener(java.beans.PropertyChangeListener)
*/
public synchronized void removePropertyChangeListener(
public void removePropertyChangeListener(
String propertyName,
PropertyChangeListener listener) {
if (listener == null || changeSupport == null) {
return;
synchronized (getChangeSupportLock()) {
if (listener == null || changeSupport == null) {
return;
}
changeSupport.removePropertyChangeListener(propertyName, listener);
}
changeSupport.removePropertyChangeListener(propertyName, listener);
}
/**
......@@ -7971,12 +7985,14 @@ public abstract class Component implements ImageObserver, MenuContainer,
* @see #getPropertyChangeListeners
* @since 1.4
*/
public synchronized PropertyChangeListener[] getPropertyChangeListeners(
public PropertyChangeListener[] getPropertyChangeListeners(
String propertyName) {
if (changeSupport == null) {
return new PropertyChangeListener[0];
synchronized (getChangeSupportLock()) {
if (changeSupport == null) {
return new PropertyChangeListener[0];
}
return changeSupport.getPropertyChangeListeners(propertyName);
}
return changeSupport.getPropertyChangeListeners(propertyName);
}
/**
......@@ -7991,7 +8007,10 @@ public abstract class Component implements ImageObserver, MenuContainer,
*/
protected void firePropertyChange(String propertyName,
Object oldValue, Object newValue) {
PropertyChangeSupport changeSupport = this.changeSupport;
PropertyChangeSupport changeSupport;
synchronized (getChangeSupportLock()) {
changeSupport = this.changeSupport;
}
if (changeSupport == null ||
(oldValue != null && newValue != null && oldValue.equals(newValue))) {
return;
......@@ -8491,8 +8510,6 @@ public abstract class Component implements ImageObserver, MenuContainer,
setComponentOrientation(orientation);
}
transient NativeInLightFixer nativeInLightFixer;
/**
* Checks that this component meets the prerequesites to be focus owner:
* - it is enabled, visible, focusable
......@@ -8518,188 +8535,25 @@ public abstract class Component implements ImageObserver, MenuContainer,
}
/**
* This odd class is to help out a native component that has been
* embedded in a lightweight component. Moving lightweight
* components around and changing their visibility is not seen
* by the native window system. This is a feature for lightweights,
* but a problem for native components that depend upon the
* lightweights. An instance of this class listens to the lightweight
* parents of an associated native component (the outer class).
*
* @author Timothy Prinzing
* Fix the location of the HW component in a LW container hierarchy.
*/
final class NativeInLightFixer implements ComponentListener, ContainerListener {
NativeInLightFixer() {
lightParents = new Vector();
install(parent);
}
void install(Container parent) {
lightParents.clear();
Container p = parent;
boolean isLwParentsVisible = true;
// stash a reference to the components that are being observed so that
// we can reliably remove ourself as a listener later.
for (; p.peer instanceof LightweightPeer; p = p.parent) {
// register listeners and stash a reference
p.addComponentListener(this);
p.addContainerListener(this);
lightParents.addElement(p);
isLwParentsVisible &= p.isVisible();
}
// register with the native host (native parent of associated native)
// to get notified if the top-level lightweight is removed.
nativeHost = p;
p.addContainerListener(this);
// kick start the fixup. Since the event isn't looked at
// we can simulate movement notification.
componentMoved(null);
if (!isLwParentsVisible) {
synchronized (getTreeLock()) {
if (peer != null) {
peer.hide();
}
}
}
}
void uninstall() {
if (nativeHost != null) {
removeReferences();
}
}
// --- ComponentListener -------------------------------------------
/**
* Invoked when one of the lightweight parents has been resized.
* This doesn't change the position of the native child so it
* is ignored.
*/
public void componentResized(ComponentEvent e) {
}
/**
* Invoked when one of the lightweight parents has been moved.
* The native peer must be told of the new position which is
* relative to the native container that is hosting the
* lightweight components.
*/
public void componentMoved(ComponentEvent e) {
synchronized (getTreeLock()) {
int nativeX = x;
int nativeY = y;
for(Component c = parent; (c != null) &&
(c.peer instanceof LightweightPeer);
c = c.parent) {
nativeX += c.x;
nativeY += c.y;
}
if (peer != null) {
peer.setBounds(nativeX, nativeY, width, height,
ComponentPeer.SET_LOCATION);
}
}
}
/**
* Invoked when a lightweight parent component has been
* shown. The associated native component must also be
* shown if it hasn't had an overriding hide done on it.
*/
public void componentShown(ComponentEvent e) {
if (shouldShow()) {
synchronized (getTreeLock()) {
if (peer != null) {
peer.show();
}
}
final void relocateComponent() {
synchronized (getTreeLock()) {
if (peer == null) {
return;
}
}
/**
* Invoked when one of the lightweight parents become visible.
* Returns true if component and all its lightweight
* parents are visible.
*/
private boolean shouldShow() {
boolean isLwParentsVisible = visible;
for (int i = lightParents.size() - 1;
i >= 0 && isLwParentsVisible;
i--)
int nativeX = x;
int nativeY = y;
for (Component cont = getContainer();
cont != null && cont.isLightweight();
cont = cont.getContainer())
{
isLwParentsVisible &=
((Container) lightParents.elementAt(i)).isVisible();
}
return isLwParentsVisible;
}
/**
* Invoked when component has been hidden.
*/
public void componentHidden(ComponentEvent e) {
if (visible) {
synchronized (getTreeLock()) {
if (peer != null) {
peer.hide();
}
}
nativeX += cont.x;
nativeY += cont.y;
}
peer.setBounds(nativeX, nativeY, width, height,
ComponentPeer.SET_LOCATION);
}
// --- ContainerListener ------------------------------------
/**
* Invoked when a component has been added to a lightweight
* parent. This doesn't effect the native component.
*/
public void componentAdded(ContainerEvent e) {
}
/**
* Invoked when a lightweight parent has been removed.
* This means the services of this listener are no longer
* required and it should remove all references (ie
* registered listeners).
*/
public void componentRemoved(ContainerEvent e) {
Component c = e.getChild();
if (c == Component.this) {
removeReferences();
} else {
int n = lightParents.size();
for (int i = 0; i < n; i++) {
Container p = (Container) lightParents.elementAt(i);
if (p == c) {
removeReferences();
break;
}
}
}
}
/**
* Removes references to this object so it can be
* garbage collected.
*/
void removeReferences() {
int n = lightParents.size();
for (int i = 0; i < n; i++) {
Container c = (Container) lightParents.elementAt(i);
c.removeComponentListener(this);
c.removeContainerListener(this);
}
nativeHost.removeContainerListener(this);
lightParents.clear();
nativeHost = null;
}
Vector lightParents;
Container nativeHost;
}
/**
......@@ -9452,6 +9306,19 @@ public abstract class Component implements ImageObserver, MenuContainer,
// ************************** MIXING CODE *******************************
/**
* Check whether we can trust the current bounds of the component.
* The return value of false indicates that the container of the
* component is invalid, and therefore needs to be layed out, which would
* probably mean changing the bounds of its children.
* Null-layout of the container or absence of the container mean
* the bounds of the component are final and can be trusted.
*/
private boolean areBoundsValid() {
Container cont = getContainer();
return cont == null || cont.isValid() || cont.getLayout() == null;
}
/**
* Applies the shape to the component
* @param shape Shape to be applied to the component
......@@ -9475,7 +9342,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
// to modify the object outside of the mixing code.
this.compoundShape = shape;
if (isValid()) {
if (areBoundsValid()) {
Point compAbsolute = getLocationOnWindow();
if (mixingLog.isLoggable(Level.FINER)) {
......@@ -9602,7 +9469,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
void applyCurrentShape() {
checkTreeLock();
if (!isValid()) {
if (!areBoundsValid()) {
return; // Because applyCompoundShape() ignores such components anyway
}
if (mixingLog.isLoggable(Level.FINE)) {
......
......@@ -832,16 +832,8 @@ public class Container extends Component {
}
if (!comp.isLightweight() && isLightweight()) {
// If component is heavyweight and one of the containers is lightweight
// some NativeInLightFixer activity should be performed
if (!curParent.isLightweight()) {
// Moving from heavyweight container to lightweight container - should create NativeInLightFixer
// since addNotify does this
comp.nativeInLightFixer = new NativeInLightFixer();
} else {
// Component already has NativeInLightFixer - just reinstall it
// because hierarchy changed and he needs to rebuild list of parents to listen.
comp.nativeInLightFixer.install(this);
}
// the location of the component should be fixed.
comp.relocateComponent();
}
}
}
......@@ -2267,53 +2259,56 @@ public class Container extends Component {
EventTargetFilter filter,
boolean searchHeavyweightChildren,
boolean searchHeavyweightDescendants) {
int ncomponents = this.ncomponents;
Component component[] = this.component;
synchronized (getTreeLock()) {
int ncomponents = this.ncomponents;
Component component[] = this.component;
for (int i = 0 ; i < ncomponents ; i++) {
Component comp = component[i];
if (comp != null && comp.visible &&
((!searchHeavyweightChildren &&
comp.peer instanceof LightweightPeer) ||
(searchHeavyweightChildren &&
!(comp.peer instanceof LightweightPeer))) &&
comp.contains(x - comp.x, y - comp.y)) {
// found a component that intersects the point, see if there is
// a deeper possibility.
if (comp instanceof Container) {
Container child = (Container) comp;
Component deeper = child.getMouseEventTarget(x - child.x,
y - child.y,
includeSelf,
filter,
searchHeavyweightDescendants);
if (deeper != null) {
return deeper;
}
} else {
if (filter.accept(comp)) {
// there isn't a deeper target, but this component is a
// target
return comp;
for (int i = 0 ; i < ncomponents ; i++) {
Component comp = component[i];
if (comp != null && comp.visible &&
((!searchHeavyweightChildren &&
comp.peer instanceof LightweightPeer) ||
(searchHeavyweightChildren &&
!(comp.peer instanceof LightweightPeer))) &&
comp.contains(x - comp.x, y - comp.y)) {
// found a component that intersects the point, see if there
// is a deeper possibility.
if (comp instanceof Container) {
Container child = (Container) comp;
Component deeper = child.getMouseEventTarget(
x - child.x,
y - child.y,
includeSelf,
filter,
searchHeavyweightDescendants);
if (deeper != null) {
return deeper;
}
} else {
if (filter.accept(comp)) {
// there isn't a deeper target, but this component
// is a target
return comp;
}
}
}
}
}
boolean isPeerOK;
boolean isMouseOverMe;
boolean isPeerOK;
boolean isMouseOverMe;
isPeerOK = (peer instanceof LightweightPeer) || includeSelf;
isMouseOverMe = contains(x,y);
isPeerOK = (peer instanceof LightweightPeer) || includeSelf;
isMouseOverMe = contains(x,y);
// didn't find a child target, return this component if it's a possible
// target
if (isMouseOverMe && isPeerOK && filter.accept(this)) {
return this;
// didn't find a child target, return this component if it's
// a possible target
if (isMouseOverMe && isPeerOK && filter.accept(this)) {
return this;
}
// no possible target
return null;
}
// no possible target
return null;
}
static interface EventTargetFilter {
......@@ -3950,6 +3945,83 @@ public class Container extends Component {
}
}
private void recursiveShowHeavyweightChildren() {
if (!hasHeavyweightDescendants() || !isVisible()) {
return;
}
for (int index = 0; index < getComponentCount(); index++) {
Component comp = getComponent(index);
if (comp.isLightweight()) {
if (comp instanceof Container) {
((Container)comp).recursiveShowHeavyweightChildren();
}
} else {
if (comp.isVisible()) {
ComponentPeer peer = comp.getPeer();
if (peer != null) {
peer.show();
}
}
}
}
}
private void recursiveHideHeavyweightChildren() {
if (!hasHeavyweightDescendants()) {
return;
}
for (int index = 0; index < getComponentCount(); index++) {
Component comp = getComponent(index);
if (comp.isLightweight()) {
if (comp instanceof Container) {
((Container)comp).recursiveHideHeavyweightChildren();
}
} else {
if (comp.isVisible()) {
ComponentPeer peer = comp.getPeer();
if (peer != null) {
peer.hide();
}
}
}
}
}
private void recursiveRelocateHeavyweightChildren(Point origin) {
for (int index = 0; index < getComponentCount(); index++) {
Component comp = getComponent(index);
if (comp.isLightweight()) {
if (comp instanceof Container &&
((Container)comp).hasHeavyweightDescendants())
{
final Point newOrigin = new Point(origin);
newOrigin.translate(comp.getX(), comp.getY());
((Container)comp).recursiveRelocateHeavyweightChildren(newOrigin);
}
} else {
ComponentPeer peer = comp.getPeer();
if (peer != null) {
peer.setBounds(origin.x + comp.getX(), origin.y + comp.getY(),
comp.getWidth(), comp.getHeight(),
ComponentPeer.SET_LOCATION);
}
}
}
}
/*
* Consider the heavyweight container hides or shows the HW descendants
* automatically. Therefore we care of LW containers' visibility only.
*/
private boolean isRecursivelyVisibleUpToHeavyweightContainer() {
if (!isLightweight()) {
return true;
}
return isVisible() && (getContainer() == null ||
getContainer().isRecursivelyVisibleUpToHeavyweightContainer());
}
@Override
void mixOnShowing() {
synchronized (getTreeLock()) {
if (mixingLog.isLoggable(Level.FINE)) {
......@@ -3958,6 +4030,10 @@ public class Container extends Component {
boolean isLightweight = isLightweight();
if (isLightweight && isRecursivelyVisibleUpToHeavyweightContainer()) {
recursiveShowHeavyweightChildren();
}
if (!isLightweight || (isLightweight && hasHeavyweightDescendants())) {
recursiveApplyCurrentShape();
}
......@@ -3966,6 +4042,42 @@ public class Container extends Component {
}
}
@Override
void mixOnHiding(boolean isLightweight) {
synchronized (getTreeLock()) {
if (mixingLog.isLoggable(Level.FINE)) {
mixingLog.fine("this = " + this +
"; isLightweight=" + isLightweight);
}
if (isLightweight) {
recursiveHideHeavyweightChildren();
}
super.mixOnHiding(isLightweight);
}
}
@Override
void mixOnReshaping() {
synchronized (getTreeLock()) {
if (mixingLog.isLoggable(Level.FINE)) {
mixingLog.fine("this = " + this);
}
if (isLightweight() && hasHeavyweightDescendants()) {
final Point origin = new Point(getX(), getY());
for (Container cont = getContainer();
cont != null && cont.isLightweight();
cont = cont.getContainer())
{
origin.translate(cont.getX(), cont.getY());
}
recursiveRelocateHeavyweightChildren(origin);
}
super.mixOnReshaping();
}
}
@Override
void mixOnZOrderChanging(int oldZorder, int newZorder) {
synchronized (getTreeLock()) {
if (mixingLog.isLoggable(Level.FINE)) {
......@@ -4431,7 +4543,8 @@ class LightweightDispatcher implements java.io.Serializable, AWTEventListener {
e.isPopupTrigger(),
((MouseWheelEvent)e).getScrollType(),
((MouseWheelEvent)e).getScrollAmount(),
((MouseWheelEvent)e).getWheelRotation());
((MouseWheelEvent)e).getWheelRotation(),
((MouseWheelEvent)e).getPreciseWheelRotation());
}
else {
retargeted = new MouseEvent(target,
......
......@@ -154,7 +154,7 @@ public class DefaultKeyboardFocusManager extends KeyboardFocusManager {
private boolean doRestoreFocus(Component toFocus, Component vetoedComponent,
boolean clearOnFailure)
{
if (toFocus.isShowing() && toFocus.isFocusable() &&
if (toFocus != vetoedComponent && toFocus.isShowing() && toFocus.isFocusable() &&
toFocus.requestFocus(false, CausedFocusEvent.Cause.ROLLBACK)) {
return true;
} else {
......
/*
* Copyright 1995-2007 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 1995-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -24,7 +24,6 @@
*/
package java.awt;
import java.applet.Applet;
import java.awt.event.*;
import java.awt.im.InputContext;
import java.awt.image.BufferStrategy;
......@@ -355,18 +354,21 @@ public class Window extends Container implements Accessible {
static class WindowDisposerRecord implements sun.java2d.DisposerRecord {
final WeakReference<Window> owner;
final WeakReference weakThis;
final AppContext context;
final WeakReference<AppContext> context;
WindowDisposerRecord(AppContext context, Window victim) {
owner = new WeakReference<Window>(victim.getOwner());
weakThis = victim.weakThis;
this.context = context;
this.context = new WeakReference<AppContext>(context);
}
public void dispose() {
Window parent = owner.get();
if (parent != null) {
parent.removeOwnedWindow(weakThis);
}
Window.removeFromWindowList(context, weakThis);
AppContext ac = context.get();
if (null != ac) {
Window.removeFromWindowList(ac, weakThis);
}
}
}
......@@ -824,7 +826,10 @@ public class Window extends Container implements Accessible {
static private final AtomicBoolean
beforeFirstWindowShown = new AtomicBoolean(true);
static final void closeSplashScreen() {
final void closeSplashScreen() {
if (isTrayIconWindow) {
return;
}
if (beforeFirstWindowShown.getAndSet(false)) {
SunToolkit.closeSplashScreen();
}
......
/*
* Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 1997-2008 Sun Microsystems, Inc. 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
......@@ -49,7 +49,6 @@ import java.util.WeakHashMap;
import sun.awt.datatransfer.DataTransferer;
/**
* The SystemFlavorMap is a configurable map between "natives" (Strings), which
* correspond to platform-specific data formats, and "flavors" (DataFlavors),
......@@ -117,15 +116,50 @@ public final class SystemFlavorMap implements FlavorMap, FlavorTable {
/**
* Maps native Strings to Lists of DataFlavors (or base type Strings for
* text DataFlavors).
* Do not use the field directly, use getNativeToFlavor() instead.
*/
private Map nativeToFlavor = new HashMap();
/**
* Accessor to nativeToFlavor map. Since we use lazy initialization we must
* use this accessor instead of direct access to the field which may not be
* initialized yet. This method will initialize the field if needed.
*
* @return nativeToFlavor
*/
private Map getNativeToFlavor() {
if (!isMapInitialized) {
initSystemFlavorMap();
}
return nativeToFlavor;
}
/**
* Maps DataFlavors (or base type Strings for text DataFlavors) to Lists of
* native Strings.
* Do not use the field directly, use getFlavorToNative() instead.
*/
private Map flavorToNative = new HashMap();
/**
* Accessor to flavorToNative map. Since we use lazy initialization we must
* use this accessor instead of direct access to the field which may not be
* initialized yet. This method will initialize the field if needed.
*
* @return flavorToNative
*/
private synchronized Map getFlavorToNative() {
if (!isMapInitialized) {
initSystemFlavorMap();
}
return flavorToNative;
}
/**
* Shows if the object has been initialized.
*/
private boolean isMapInitialized = false;
/**
* Caches the result of getNativesForFlavor(). Maps DataFlavors to
* SoftReferences which reference Lists of String natives.
......@@ -169,15 +203,24 @@ public final class SystemFlavorMap implements FlavorMap, FlavorTable {
return fm;
}
private SystemFlavorMap() {
}
/**
* Constructs a SystemFlavorMap by reading flavormap.properties and
* Initializes a SystemFlavorMap by reading flavormap.properties and
* AWT.DnD.flavorMapFileURL.
* For thread-safety must be called under lock on this.
*/
private SystemFlavorMap() {
BufferedReader flavormapDotProperties = (BufferedReader)
private void initSystemFlavorMap() {
if (isMapInitialized) {
return;
}
isMapInitialized = true;
BufferedReader flavormapDotProperties =
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public Object run() {
new java.security.PrivilegedAction<BufferedReader>() {
public BufferedReader run() {
String fileName =
System.getProperty("java.home") +
File.separator +
......@@ -197,12 +240,11 @@ public final class SystemFlavorMap implements FlavorMap, FlavorTable {
}
});
BufferedReader flavormapURL = (BufferedReader)
BufferedReader flavormapURL =
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public Object run() {
String url = Toolkit.getDefaultToolkit().getProperty
("AWT.DnD.flavorMapFileURL", null);
new java.security.PrivilegedAction<BufferedReader>() {
public BufferedReader run() {
String url = Toolkit.getProperty("AWT.DnD.flavorMapFileURL", null);
if (url == null) {
return null;
......@@ -237,7 +279,6 @@ public final class SystemFlavorMap implements FlavorMap, FlavorTable {
}
}
}
/**
* Copied code from java.util.Properties. Parsing the data ourselves is the
* only way to handle duplicate keys and values.
......@@ -388,11 +429,11 @@ public final class SystemFlavorMap implements FlavorMap, FlavorTable {
// For text/* flavors, store mappings in separate maps to
// enable dynamic mapping generation at a run-time.
if ("text".equals(flavor.getPrimaryType())) {
store(value, key, flavorToNative);
store(key, value, nativeToFlavor);
store(value, key, getFlavorToNative());
store(key, value, getNativeToFlavor());
} else {
store(flavor, key, flavorToNative);
store(key, flavor, nativeToFlavor);
store(flavor, key, getFlavorToNative());
store(key, flavor, getNativeToFlavor());
}
}
}
......@@ -494,7 +535,7 @@ public final class SystemFlavorMap implements FlavorMap, FlavorTable {
* only if the specified native is encoded as a Java MIME type.
*/
private List nativeToFlavorLookup(String nat) {
List flavors = (List)nativeToFlavor.get(nat);
List flavors = (List)getNativeToFlavor().get(nat);
if (nat != null && !disabledMappingGenerationKeys.contains(nat)) {
DataTransferer transferer = DataTransferer.getInstance();
......@@ -530,15 +571,15 @@ public final class SystemFlavorMap implements FlavorMap, FlavorTable {
if (flavor != null) {
flavors = new ArrayList(1);
nativeToFlavor.put(nat, flavors);
getNativeToFlavor().put(nat, flavors);
flavors.add(flavor);
getFlavorsForNativeCache.remove(nat);
getFlavorsForNativeCache.remove(null);
List natives = (List)flavorToNative.get(flavor);
List natives = (List)getFlavorToNative().get(flavor);
if (natives == null) {
natives = new ArrayList(1);
flavorToNative.put(flavor, natives);
getFlavorToNative().put(flavor, natives);
}
natives.add(nat);
getNativesForFlavorCache.remove(flavor);
......@@ -559,7 +600,7 @@ public final class SystemFlavorMap implements FlavorMap, FlavorTable {
*/
private List flavorToNativeLookup(final DataFlavor flav,
final boolean synthesize) {
List natives = (List)flavorToNative.get(flav);
List natives = (List)getFlavorToNative().get(flav);
if (flav != null && !disabledMappingGenerationKeys.contains(flav)) {
DataTransferer transferer = DataTransferer.getInstance();
......@@ -584,15 +625,15 @@ public final class SystemFlavorMap implements FlavorMap, FlavorTable {
if (synthesize) {
String encoded = encodeDataFlavor(flav);
natives = new ArrayList(1);
flavorToNative.put(flav, natives);
getFlavorToNative().put(flav, natives);
natives.add(encoded);
getNativesForFlavorCache.remove(flav);
getNativesForFlavorCache.remove(null);
List flavors = (List)nativeToFlavor.get(encoded);
List flavors = (List)getNativeToFlavor().get(encoded);
if (flavors == null) {
flavors = new ArrayList(1);
nativeToFlavor.put(encoded, flavors);
getNativeToFlavor().put(encoded, flavors);
}
flavors.add(flav);
getFlavorsForNativeCache.remove(encoded);
......@@ -645,7 +686,7 @@ public final class SystemFlavorMap implements FlavorMap, FlavorTable {
}
if (flav == null) {
retval = new ArrayList(nativeToFlavor.keySet());
retval = new ArrayList(getNativeToFlavor().keySet());
} else if (disabledMappingGenerationKeys.contains(flav)) {
// In this case we shouldn't synthesize a native for this flavor,
// since its mappings were explicitly specified.
......@@ -655,7 +696,7 @@ public final class SystemFlavorMap implements FlavorMap, FlavorTable {
// For text/* flavors, flavor-to-native mappings specified in
// flavormap.properties are stored per flavor's base type.
if ("text".equals(flav.getPrimaryType())) {
retval = (List)flavorToNative.get(flav.mimeType.getBaseType());
retval = (List)getFlavorToNative().get(flav.mimeType.getBaseType());
if (retval != null) {
// To prevent the List stored in the map from modification.
retval = new ArrayList(retval);
......@@ -663,7 +704,7 @@ public final class SystemFlavorMap implements FlavorMap, FlavorTable {
}
// Also include text/plain natives, but don't duplicate Strings
List textPlainList = (List)flavorToNative.get(TEXT_PLAIN_BASE_TYPE);
List textPlainList = (List)getFlavorToNative().get(TEXT_PLAIN_BASE_TYPE);
if (textPlainList != null && !textPlainList.isEmpty()) {
// To prevent the List stored in the map from modification.
......@@ -699,7 +740,7 @@ public final class SystemFlavorMap implements FlavorMap, FlavorTable {
}
}
} else if (DataTransferer.isFlavorNoncharsetTextType(flav)) {
retval = (List)flavorToNative.get(flav.mimeType.getBaseType());
retval = (List)getFlavorToNative().get(flav.mimeType.getBaseType());
if (retval == null || retval.isEmpty()) {
retval = flavorToNativeLookup(flav, SYNTHESIZE_IF_NOT_FOUND);
......@@ -1025,10 +1066,10 @@ public final class SystemFlavorMap implements FlavorMap, FlavorTable {
throw new NullPointerException("null arguments not permitted");
}
List natives = (List)flavorToNative.get(flav);
List natives = (List)getFlavorToNative().get(flav);
if (natives == null) {
natives = new ArrayList(1);
flavorToNative.put(flav, natives);
getFlavorToNative().put(flav, natives);
} else if (natives.contains(nat)) {
return;
}
......@@ -1071,7 +1112,7 @@ public final class SystemFlavorMap implements FlavorMap, FlavorTable {
throw new NullPointerException("null arguments not permitted");
}
flavorToNative.remove(flav);
getFlavorToNative().remove(flav);
for (int i = 0; i < natives.length; i++) {
addUnencodedNativeForFlavor(flav, natives[i]);
}
......@@ -1105,10 +1146,10 @@ public final class SystemFlavorMap implements FlavorMap, FlavorTable {
throw new NullPointerException("null arguments not permitted");
}
List flavors = (List)nativeToFlavor.get(nat);
List flavors = (List)getNativeToFlavor().get(nat);
if (flavors == null) {
flavors = new ArrayList(1);
nativeToFlavor.put(nat, flavors);
getNativeToFlavor().put(nat, flavors);
} else if (flavors.contains(flav)) {
return;
}
......@@ -1150,7 +1191,7 @@ public final class SystemFlavorMap implements FlavorMap, FlavorTable {
throw new NullPointerException("null arguments not permitted");
}
nativeToFlavor.remove(nat);
getNativeToFlavor().remove(nat);
for (int i = 0; i < flavors.length; i++) {
addFlavorForUnencodedNative(nat, flavors[i]);
}
......
/*
* Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 1997-2008 Sun Microsystems, Inc. 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
......@@ -110,7 +110,11 @@ public class DropTarget implements DropTargetListener, Serializable {
setActive(act);
}
if (fm != null) flavorMap = fm;
if (fm != null) {
flavorMap = fm;
} else {
flavorMap = SystemFlavorMap.getDefaultFlavorMap();
}
}
/**
......@@ -850,5 +854,5 @@ public class DropTarget implements DropTargetListener, Serializable {
* The FlavorMap
*/
private transient FlavorMap flavorMap = SystemFlavorMap.getDefaultFlavorMap();
private transient FlavorMap flavorMap;
}
/*
* Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2000-2007 Sun Microsystems, Inc. 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
......@@ -74,6 +74,19 @@ import java.awt.Component;
* methods for conforming to the underlying platform settings. These
* platform settings can be changed at any time by the user. MouseWheelEvents
* reflect the most recent settings.
* <P>
* The <code>MouseWheelEvent</code> class includes methods for
* getting the number of "clicks" by which the mouse wheel is rotated.
* The {@link #getWheelRotation} method returns the integer number
* of "clicks" corresponding to the number of notches by which the wheel was
* rotated. In addition to this method, the <code>MouseWheelEvent</code>
* class provides the {@link #getPreciseWheelRotation} method which returns
* a double number of "clicks" in case a partial rotation occurred.
* The {@link #getPreciseWheelRotation} method is useful if a mouse supports
* a high-resolution wheel, such as a freely rotating wheel with no
* notches. Applications can benefit by using this method to process
* mouse wheel events more precisely, and thus, making visual perception
* smoother.
*
* @author Brent Christian
* @see MouseWheelListener
......@@ -131,6 +144,13 @@ public class MouseWheelEvent extends MouseEvent {
*/
int wheelRotation;
/**
* Indicates how far the mouse wheel was rotated.
*
* @see #getPreciseWheelRotation
*/
double preciseWheelRotation;
/*
* serialVersionUID
*/
......@@ -165,8 +185,8 @@ public class MouseWheelEvent extends MouseEvent {
* <code>WHEEL_BLOCK_SCROLL</code>
* @param scrollAmount for scrollType <code>WHEEL_UNIT_SCROLL</code>,
* the number of units to be scrolled
* @param wheelRotation the amount that the mouse wheel was rotated (the
* number of "clicks")
* @param wheelRotation the integer number of "clicks" by which the mouse
* wheel was rotated
*
* @throws IllegalArgumentException if <code>source</code> is null
* @see MouseEvent#MouseEvent(java.awt.Component, int, long, int, int, int, int, boolean)
......@@ -211,8 +231,8 @@ public class MouseWheelEvent extends MouseEvent {
* <code>WHEEL_BLOCK_SCROLL</code>
* @param scrollAmount for scrollType <code>WHEEL_UNIT_SCROLL</code>,
* the number of units to be scrolled
* @param wheelRotation the amount that the mouse wheel was rotated (the
* number of "clicks")
* @param wheelRotation the integer number of "clicks" by which the mouse
* wheel was rotated
*
* @throws IllegalArgumentException if <code>source</code> is null
* @see MouseEvent#MouseEvent(java.awt.Component, int, long, int, int, int, int, boolean)
......@@ -223,12 +243,68 @@ public class MouseWheelEvent extends MouseEvent {
int x, int y, int xAbs, int yAbs, int clickCount, boolean popupTrigger,
int scrollType, int scrollAmount, int wheelRotation) {
this(source, id, when, modifiers, x, y, xAbs, yAbs, clickCount, popupTrigger,
scrollType, scrollAmount, wheelRotation, wheelRotation);
}
/**
* Constructs a <code>MouseWheelEvent</code> object with the specified
* source component, type, modifiers, coordinates, absolute coordinates,
* scroll type, scroll amount, and wheel rotation.
* <p>Note that passing in an invalid <code>id</code> parameter results
* in unspecified behavior. This method throws an
* <code>IllegalArgumentException</code> if <code>source</code> equals
* <code>null</code>.
* <p>Even if inconsistent values for relative and absolute coordinates
* are passed to the constructor, a <code>MouseWheelEvent</code> instance
* is still created and no exception is thrown.
*
* @param source the <code>Component</code> that originated the event
* @param id the integer value that identifies the event
* @param when a long value that gives the time when the event occurred
* @param modifiers the modifier keys down during event
* (shift, ctrl, alt, meta)
* @param x the horizontal <code>x</code> coordinate for the
* mouse location
* @param y the vertical <code>y</code> coordinate for the
* mouse location
* @param xAbs the absolute horizontal <code>x</code> coordinate for
* the mouse location
* @param yAbs the absolute vertical <code>y</code> coordinate for
* the mouse location
* @param clickCount the number of mouse clicks associated with the event
* @param popupTrigger a boolean value, <code>true</code> if this event is a trigger
* for a popup-menu
* @param scrollType the type of scrolling which should take place in
* response to this event; valid values are
* <code>WHEEL_UNIT_SCROLL</code> and
* <code>WHEEL_BLOCK_SCROLL</code>
* @param scrollAmount for scrollType <code>WHEEL_UNIT_SCROLL</code>,
* the number of units to be scrolled
* @param wheelRotation the integer number of "clicks" by which the mouse wheel
* was rotated
* @param preciseWheelRotation the double number of "clicks" by which the mouse wheel
* was rotated
*
* @throws IllegalArgumentException if <code>source</code> is null
* @see MouseEvent#MouseEvent(java.awt.Component, int, long, int, int, int, int, boolean)
* @see MouseEvent#MouseEvent(java.awt.Component, int, long, int, int, int, int, int, int, boolean, int)
* @since 1.7
*/
public MouseWheelEvent (Component source, int id, long when, int modifiers,
int x, int y, int xAbs, int yAbs, int clickCount, boolean popupTrigger,
int scrollType, int scrollAmount, int wheelRotation, double preciseWheelRotation) {
super(source, id, when, modifiers, x, y, xAbs, yAbs, clickCount,
popupTrigger, MouseEvent.NOBUTTON);
this.scrollType = scrollType;
this.scrollAmount = scrollAmount;
this.wheelRotation = wheelRotation;
this.preciseWheelRotation = preciseWheelRotation;
}
/**
......@@ -267,16 +343,34 @@ public class MouseWheelEvent extends MouseEvent {
}
/**
* Returns the number of "clicks" the mouse wheel was rotated.
* Returns the number of "clicks" the mouse wheel was rotated, as an integer.
* A partial rotation may occur if the mouse supports a high-resolution wheel.
* In this case, the method returns zero until a full "click" has been accumulated.
*
* @return negative values if the mouse wheel was rotated up/away from
* the user, and positive values if the mouse wheel was rotated down/
* towards the user
* @see #getPreciseWheelRotation
*/
public int getWheelRotation() {
return wheelRotation;
}
/**
* Returns the number of "clicks" the mouse wheel was rotated, as a double.
* A partial rotation may occur if the mouse supports a high-resolution wheel.
* In this case, the return value will include a fractional "click".
*
* @return negative values if the mouse wheel was rotated up or away from
* the user, and positive values if the mouse wheel was rotated down or
* towards the user
* @see #getWheelRotation
* @since 1.7
*/
public double getPreciseWheelRotation() {
return preciseWheelRotation;
}
/**
* This is a convenience method to aid in the implementation of
* the common-case MouseWheelListener - to scroll a ScrollPane or
......@@ -348,6 +442,6 @@ public class MouseWheelEvent extends MouseEvent {
}
return super.paramString()+",scrollType="+scrollTypeStr+
",scrollAmount="+getScrollAmount()+",wheelRotation="+
getWheelRotation();
getWheelRotation()+",preciseWheelRotation="+getPreciseWheelRotation();
}
}
......@@ -1553,7 +1553,7 @@ class MetaData {
private static String[] getConstructorProperties(Class type) {
String[] names = null;
int length = 0;
for (Constructor constructor : type.getConstructors()) {
for (Constructor<?> constructor : type.getConstructors()) {
String[] value = getAnnotationValue(constructor);
if ((value != null) && (length < value.length) && isValid(constructor, value)) {
names = value;
......@@ -1563,14 +1563,14 @@ class MetaData {
return names;
}
private static String[] getAnnotationValue(Constructor constructor) {
private static String[] getAnnotationValue(Constructor<?> constructor) {
ConstructorProperties annotation = constructor.getAnnotation(ConstructorProperties.class);
return (annotation != null)
? annotation.value()
: null;
}
private static boolean isValid(Constructor constructor, String[] names) {
private static boolean isValid(Constructor<?> constructor, String[] names) {
Class[] parameters = constructor.getParameterTypes();
if (names.length != parameters.length) {
return false;
......
......@@ -636,7 +636,11 @@ public interface Instrumentation {
* @param transformer
* The ClassFileTransformer which wraps using this prefix.
* @param prefix
* The prefix which has been applied to wrapped native methods.
* The prefix to apply to wrapped native methods when
* retrying a failed native method resolution. If prefix
* is either <code>null</code> or the empty string, then
* failed native method resolutions are not retried for
* this transformer.
* @throws java.lang.NullPointerException if passed a <code>null</code> transformer.
* @throws java.lang.UnsupportedOperationException if the current configuration of
* the JVM does not allow setting a native method prefix
......
......@@ -50,7 +50,7 @@ import javax.management.loading.ClassLoaderRepository;
* server. A Java object cannot be registered in the MBean server
* unless it is a JMX compliant MBean.</p>
*
* <p>When an MBean is registered or unregistered in the MBean server
* <p id="notif">When an MBean is registered or unregistered in the MBean server
* a {@link javax.management.MBeanServerNotification
* MBeanServerNotification} Notification is emitted. To register an
* object as listener to MBeanServerNotifications you should call the
......@@ -258,27 +258,43 @@ import javax.management.loading.ClassLoaderRepository;
*/
public interface MBeanServer extends MBeanServerConnection {
// doc comment inherited from MBeanServerConnection
/**
* {@inheritDoc}
* <p>If this method successfully creates an MBean, a notification
* is sent as described <a href="#notif">above</a>.</p>
*/
public ObjectInstance createMBean(String className, ObjectName name)
throws ReflectionException, InstanceAlreadyExistsException,
MBeanRegistrationException, MBeanException,
NotCompliantMBeanException;
// doc comment inherited from MBeanServerConnection
/**
* {@inheritDoc}
* <p>If this method successfully creates an MBean, a notification
* is sent as described <a href="#notif">above</a>.</p>
*/
public ObjectInstance createMBean(String className, ObjectName name,
ObjectName loaderName)
throws ReflectionException, InstanceAlreadyExistsException,
MBeanRegistrationException, MBeanException,
NotCompliantMBeanException, InstanceNotFoundException;
// doc comment inherited from MBeanServerConnection
/**
* {@inheritDoc}
* <p>If this method successfully creates an MBean, a notification
* is sent as described <a href="#notif">above</a>.</p>
*/
public ObjectInstance createMBean(String className, ObjectName name,
Object params[], String signature[])
throws ReflectionException, InstanceAlreadyExistsException,
MBeanRegistrationException, MBeanException,
NotCompliantMBeanException;
// doc comment inherited from MBeanServerConnection
/**
* {@inheritDoc}
* <p>If this method successfully creates an MBean, a notification
* is sent as described <a href="#notif">above</a>.</p>
*/
public ObjectInstance createMBean(String className, ObjectName name,
ObjectName loaderName, Object params[],
String signature[])
......@@ -287,12 +303,15 @@ public interface MBeanServer extends MBeanServerConnection {
NotCompliantMBeanException, InstanceNotFoundException;
/**
* Registers a pre-existing object as an MBean with the MBean
* <p>Registers a pre-existing object as an MBean with the MBean
* server. If the object name given is null, the MBean must
* provide its own name by implementing the {@link
* javax.management.MBeanRegistration MBeanRegistration} interface
* and returning the name from the {@link
* MBeanRegistration#preRegister preRegister} method.
* MBeanRegistration#preRegister preRegister} method.</p>
*
* <p>If this method successfully registers an MBean, a notification
* is sent as described <a href="#notif">above</a>.</p>
*
* @param object The MBean to be registered as an MBean.
* @param name The object name of the MBean. May be null.
......@@ -319,7 +338,12 @@ public interface MBeanServer extends MBeanServerConnection {
throws InstanceAlreadyExistsException, MBeanRegistrationException,
NotCompliantMBeanException;
// doc comment inherited from MBeanServerConnection
/**
* {@inheritDoc}
*
* <p>If this method successfully unregisters an MBean, a notification
* is sent as described <a href="#notif">above</a>.</p>
*/
public void unregisterMBean(ObjectName name)
throws InstanceNotFoundException, MBeanRegistrationException;
......
......@@ -48,6 +48,7 @@ import java.util.logging.Level;
import java.util.Map;
import java.util.Set;
import java.util.Vector;
import javax.management.Attribute;
import javax.management.AttributeChangeNotification;
import javax.management.AttributeChangeNotificationFilter;
......@@ -132,8 +133,6 @@ public class RequiredModelMBean
* and operations will be executed */
private Object managedResource = null;
private static final String currClass = "RequiredModelMBean";
/* records the registering in MBeanServer */
private boolean registered = false;
private transient MBeanServer server = null;
......@@ -2488,10 +2487,13 @@ public class RequiredModelMBean
}
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
Vector<String> enabledAttrs = currFilter.getEnabledAttributes();
String s = (enabledAttrs.size() > 1) ?
"[" + enabledAttrs.firstElement() + ", ...]" :
enabledAttrs.toString();
MODELMBEAN_LOGGER.logp(Level.FINER,
RequiredModelMBean.class.getName(), mth,
"Set attribute change filter to " +
currFilter.getEnabledAttributes().firstElement());
"Set attribute change filter to " + s);
}
attributeBroadcaster.addNotificationListener(inlistener,currFilter,
......
/*
* Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 1998-2008 Sun Microsystems, Inc. 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
......@@ -40,6 +40,8 @@ import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Set;
import java.util.HashSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.beans.PropertyChangeSupport;
import java.beans.PropertyChangeListener;
......@@ -126,6 +128,7 @@ import java.beans.PropertyChangeListener;
* @author Fred Ecks
*/
public final class AppContext {
private static final Logger log = Logger.getLogger("sun.awt.AppContext");
/* Since the contents of an AppContext are unique to each Java
* session, this class should never be serialized. */
......@@ -143,13 +146,15 @@ public final class AppContext {
* Returns a set containing all <code>AppContext</code>s.
*/
public static Set<AppContext> getAppContexts() {
return new HashSet<AppContext>(threadGroup2appContext.values());
synchronized (threadGroup2appContext) {
return new HashSet<AppContext>(threadGroup2appContext.values());
}
}
/* The main "system" AppContext, used by everything not otherwise
contained in another AppContext.
*/
private static AppContext mainAppContext = null;
private static volatile AppContext mainAppContext = null;
/*
* The hash map associated with this AppContext. A private delegate
......@@ -174,31 +179,30 @@ public final class AppContext {
public static final String DISPOSED_PROPERTY_NAME = "disposed";
public static final String GUI_DISPOSED = "guidisposed";
private boolean isDisposed = false; // true if AppContext is disposed
private volatile boolean isDisposed = false; // true if AppContext is disposed
public boolean isDisposed() {
return isDisposed;
}
static {
// On the main Thread, we get the ThreadGroup, make a corresponding
// AppContext, and instantiate the Java EventQueue. This way, legacy
// code is unaffected by the move to multiple AppContext ability.
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ThreadGroup currentThreadGroup =
Thread.currentThread().getThreadGroup();
ThreadGroup parentThreadGroup = currentThreadGroup.getParent();
while (parentThreadGroup != null) {
// Find the root ThreadGroup to construct our main AppContext
currentThreadGroup = parentThreadGroup;
parentThreadGroup = currentThreadGroup.getParent();
public Object run() {
ThreadGroup currentThreadGroup =
Thread.currentThread().getThreadGroup();
ThreadGroup parentThreadGroup = currentThreadGroup.getParent();
while (parentThreadGroup != null) {
// Find the root ThreadGroup to construct our main AppContext
currentThreadGroup = parentThreadGroup;
parentThreadGroup = currentThreadGroup.getParent();
}
mainAppContext = new AppContext(currentThreadGroup);
numAppContexts = 1;
return mainAppContext;
}
mainAppContext = new AppContext(currentThreadGroup);
numAppContexts = 1;
return mainAppContext;
}
});
}
......@@ -209,7 +213,7 @@ public final class AppContext {
* number is 1. If so, it returns the sole AppContext without
* checking Thread.currentThread().
*/
private static int numAppContexts;
private static volatile int numAppContexts;
/*
* The context ClassLoader that was used to create this AppContext.
......@@ -236,14 +240,15 @@ public final class AppContext {
threadGroup2appContext.put(threadGroup, this);
this.contextClassLoader =
(ClassLoader) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
public ClassLoader run() {
return Thread.currentThread().getContextClassLoader();
}
});
}
private static MostRecentThreadAppContext mostRecentThreadAppContext = null;
private static final ThreadLocal<AppContext> threadAppContext =
new ThreadLocal<AppContext>();
/**
* Returns the appropriate AppContext for the caller,
......@@ -260,59 +265,46 @@ public final class AppContext {
if (numAppContexts == 1) // If there's only one system-wide,
return mainAppContext; // return the main system AppContext.
final Thread currentThread = Thread.currentThread();
AppContext appContext = null;
// Note: this most recent Thread/AppContext caching is thread-hot.
// A simple test using SwingSet found that 96.8% of lookups
// were matched using the most recent Thread/AppContext. By
// instantiating a simple MostRecentThreadAppContext object on
// cache misses, the cache hits can be processed without
// synchronization.
AppContext appContext = threadAppContext.get();
if (null == appContext) {
appContext = AccessController.doPrivileged(new PrivilegedAction<AppContext>()
{
public AppContext run() {
// Get the current ThreadGroup, and look for it and its
// parents in the hash from ThreadGroup to AppContext --
// it should be found, because we use createNewContext()
// when new AppContext objects are created.
ThreadGroup currentThreadGroup = Thread.currentThread().getThreadGroup();
ThreadGroup threadGroup = currentThreadGroup;
AppContext context = threadGroup2appContext.get(threadGroup);
while (context == null) {
threadGroup = threadGroup.getParent();
if (threadGroup == null) {
// If we get here, we're running under a ThreadGroup that
// has no AppContext associated with it. This should never
// happen, because createNewContext() should be used by the
// toolkit to create the ThreadGroup that everything runs
// under.
throw new RuntimeException("Invalid ThreadGroup");
}
context = threadGroup2appContext.get(threadGroup);
}
// In case we did anything in the above while loop, we add
// all the intermediate ThreadGroups to threadGroup2appContext
// so we won't spin again.
for (ThreadGroup tg = currentThreadGroup; tg != threadGroup; tg = tg.getParent()) {
threadGroup2appContext.put(tg, context);
}
// Now we're done, so we cache the latest key/value pair.
// (we do this before checking with any AWTSecurityManager, so if
// this Thread equates with the main AppContext in the cache, it
// still will)
threadAppContext.set(context);
MostRecentThreadAppContext recent = mostRecentThreadAppContext;
if ((recent != null) && (recent.thread == currentThread)) {
appContext = recent.appContext; // Cache hit
} else {
appContext = (AppContext)AccessController.doPrivileged(
new PrivilegedAction() {
public Object run() {
// Get the current ThreadGroup, and look for it and its
// parents in the hash from ThreadGroup to AppContext --
// it should be found, because we use createNewContext()
// when new AppContext objects are created.
ThreadGroup currentThreadGroup = currentThread.getThreadGroup();
ThreadGroup threadGroup = currentThreadGroup;
AppContext context = threadGroup2appContext.get(threadGroup);
while (context == null) {
threadGroup = threadGroup.getParent();
if (threadGroup == null) {
// If we get here, we're running under a ThreadGroup that
// has no AppContext associated with it. This should never
// happen, because createNewContext() should be used by the
// toolkit to create the ThreadGroup that everything runs
// under.
throw new RuntimeException("Invalid ThreadGroup");
return context;
}
context = threadGroup2appContext.get(threadGroup);
}
// In case we did anything in the above while loop, we add
// all the intermediate ThreadGroups to threadGroup2appContext
// so we won't spin again.
for (ThreadGroup tg = currentThreadGroup; tg != threadGroup; tg = tg.getParent()) {
threadGroup2appContext.put(tg, context);
}
// Now we're done, so we cache the latest key/value pair.
// (we do this before checking with any AWTSecurityManager, so if
// this Thread equates with the main AppContext in the cache, it
// still will)
mostRecentThreadAppContext =
new MostRecentThreadAppContext(currentThread, context);
return context;
}
});
});
}
if (appContext == mainAppContext) {
......@@ -321,9 +313,9 @@ public final class AppContext {
// allow it to choose the AppContext to return.
SecurityManager securityManager = System.getSecurityManager();
if ((securityManager != null) &&
(securityManager instanceof AWTSecurityManager)) {
AWTSecurityManager awtSecMgr =
(AWTSecurityManager)securityManager;
(securityManager instanceof AWTSecurityManager))
{
AWTSecurityManager awtSecMgr = (AWTSecurityManager)securityManager;
AppContext secAppContext = awtSecMgr.getAppContext();
if (secAppContext != null) {
appContext = secAppContext; // Return what we're told
......@@ -385,7 +377,13 @@ public final class AppContext {
public void run() {
Window[] windowsToDispose = Window.getOwnerlessWindows();
for (Window w : windowsToDispose) {
w.dispose();
try {
w.dispose();
} catch (Throwable t) {
if (log.isLoggable(Level.FINER)) {
log.log(Level.FINER, "exception occured while disposing app context", t);
}
}
}
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
......@@ -444,7 +442,7 @@ public final class AppContext {
// Threads in the ThreadGroup to exit.
long startTime = System.currentTimeMillis();
long endTime = startTime + (long)THREAD_INTERRUPT_TIMEOUT;
long endTime = startTime + THREAD_INTERRUPT_TIMEOUT;
while ((this.threadGroup.activeCount() > 0) &&
(System.currentTimeMillis() < endTime)) {
try {
......@@ -459,7 +457,7 @@ public final class AppContext {
// Threads in the ThreadGroup to die.
startTime = System.currentTimeMillis();
endTime = startTime + (long)THREAD_INTERRUPT_TIMEOUT;
endTime = startTime + THREAD_INTERRUPT_TIMEOUT;
while ((this.threadGroup.activeCount() > 0) &&
(System.currentTimeMillis() < endTime)) {
try {
......@@ -478,10 +476,7 @@ public final class AppContext {
}
threadGroup2appContext.remove(this.threadGroup);
MostRecentThreadAppContext recent = mostRecentThreadAppContext;
if ((recent != null) && (recent.appContext == this))
mostRecentThreadAppContext = null;
// If the "most recent" points to this, clear it for GC
threadAppContext.set(null);
// Finally, we destroy the ThreadGroup entirely.
try {
......@@ -664,6 +659,7 @@ public final class AppContext {
* Returns a string representation of this AppContext.
* @since 1.2
*/
@Override
public String toString() {
return getClass().getName() + "[threadGroup=" + threadGroup.getName() + "]";
}
......@@ -769,15 +765,6 @@ public final class AppContext {
}
}
final class MostRecentThreadAppContext {
final Thread thread;
final AppContext appContext;
MostRecentThreadAppContext(Thread key, AppContext value) {
thread = key;
appContext = value;
}
}
final class MostRecentKeyValue {
Object key;
Object value;
......
/*
* Copyright 2000-2007 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2000-2008 Sun Microsystems, Inc. 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
......@@ -270,62 +270,58 @@ public abstract class DataTransferer {
* instead, null will be returned.
*/
public static DataTransferer getInstance() {
if (transferer == null) {
synchronized (DataTransferer.class) {
if (transferer == null) {
final String name = SunToolkit.
getDataTransfererClassName();
if (name != null) {
PrivilegedAction action = new PrivilegedAction() {
public Object run() {
Class cls = null;
Method method = null;
Object ret = null;
try {
cls = Class.forName(name);
} catch (ClassNotFoundException e) {
ClassLoader cl = ClassLoader.
getSystemClassLoader();
if (cl != null) {
try {
cls = cl.loadClass(name);
} catch (ClassNotFoundException ee) {
ee.printStackTrace();
throw new AWTError("DataTransferer not found: " + name);
}
}
}
if (cls != null) {
synchronized (DataTransferer.class) {
if (transferer == null) {
final String name = SunToolkit.getDataTransfererClassName();
if (name != null) {
PrivilegedAction<DataTransferer> action = new PrivilegedAction<DataTransferer>()
{
public DataTransferer run() {
Class cls = null;
Method method = null;
DataTransferer ret = null;
try {
cls = Class.forName(name);
} catch (ClassNotFoundException e) {
ClassLoader cl = ClassLoader.
getSystemClassLoader();
if (cl != null) {
try {
method = cls.getDeclaredMethod
("getInstanceImpl");
method.setAccessible(true);
} catch (NoSuchMethodException e) {
e.printStackTrace();
throw new AWTError("Cannot instantiate DataTransferer: " + name);
} catch (SecurityException e) {
e.printStackTrace();
throw new AWTError("Access is denied for DataTransferer: " + name);
cls = cl.loadClass(name);
} catch (ClassNotFoundException ee) {
ee.printStackTrace();
throw new AWTError("DataTransferer not found: " + name);
}
}
if (method != null) {
try {
ret = method.invoke(null);
} catch (InvocationTargetException e) {
e.printStackTrace();
throw new AWTError("Cannot instantiate DataTransferer: " + name);
} catch (IllegalAccessException e) {
e.printStackTrace();
throw new AWTError("Cannot access DataTransferer: " + name);
}
}
if (cls != null) {
try {
method = cls.getDeclaredMethod("getInstanceImpl");
method.setAccessible(true);
} catch (NoSuchMethodException e) {
e.printStackTrace();
throw new AWTError("Cannot instantiate DataTransferer: " + name);
} catch (SecurityException e) {
e.printStackTrace();
throw new AWTError("Access is denied for DataTransferer: " + name);
}
return ret;
}
};
transferer = (DataTransferer)
AccessController.doPrivileged(action);
}
if (method != null) {
try {
ret = (DataTransferer) method.invoke(null);
} catch (InvocationTargetException e) {
e.printStackTrace();
throw new AWTError("Cannot instantiate DataTransferer: " + name);
} catch (IllegalAccessException e) {
e.printStackTrace();
throw new AWTError("Cannot access DataTransferer: " + name);
}
}
return ret;
}
};
transferer = AccessController.doPrivileged(action);
}
}
}
......
......@@ -303,39 +303,78 @@ public class InstrumentationImpl implements Instrumentation {
NoSuchMethodException firstExc = null;
boolean twoArgAgent = false;
// The agent class has a premain or agentmain method that has 1 or 2
// arguments. We first check for a signature of (String, Instrumentation),
// and if not found we check for (String). If neither is found then we
// throw the NoSuchMethodException from the first attempt so that the
// exception text indicates the lookup failed for the 2-arg method
// (same as JDK5.0).
// The agent class must have a premain or agentmain method that
// has 1 or 2 arguments. We check in the following order:
//
// 1) declared with a signature of (String, Instrumentation)
// 2) declared with a signature of (String)
// 3) inherited with a signature of (String, Instrumentation)
// 4) inherited with a signature of (String)
//
// So the declared version of either 1-arg or 2-arg always takes
// primary precedence over an inherited version. After that, the
// 2-arg version takes precedence over the 1-arg version.
//
// If no method is found then we throw the NoSuchMethodException
// from the first attempt so that the exception text indicates
// the lookup failed for the 2-arg method (same as JDK5.0).
try {
m = javaAgentClass.getMethod( methodname,
new Class[] {
String.class,
java.lang.instrument.Instrumentation.class
}
);
m = javaAgentClass.getDeclaredMethod( methodname,
new Class[] {
String.class,
java.lang.instrument.Instrumentation.class
}
);
twoArgAgent = true;
} catch (NoSuchMethodException x) {
// remember the NoSuchMethodException
firstExc = x;
}
// check for the 1-arg method
if (m == null) {
// now try the declared 1-arg method
try {
m = javaAgentClass.getMethod(methodname, new Class[] { String.class });
m = javaAgentClass.getDeclaredMethod(methodname,
new Class[] { String.class });
} catch (NoSuchMethodException x) {
// Neither method exists so we throw the first NoSuchMethodException
// as per 5.0
// ignore this exception because we'll try
// two arg inheritance next
}
}
if (m == null) {
// now try the inherited 2-arg method
try {
m = javaAgentClass.getMethod( methodname,
new Class[] {
String.class,
java.lang.instrument.Instrumentation.class
}
);
twoArgAgent = true;
} catch (NoSuchMethodException x) {
// ignore this exception because we'll try
// one arg inheritance next
}
}
if (m == null) {
// finally try the inherited 1-arg method
try {
m = javaAgentClass.getMethod(methodname,
new Class[] { String.class });
} catch (NoSuchMethodException x) {
// none of the methods exists so we throw the
// first NoSuchMethodException as per 5.0
throw firstExc;
}
}
// the premain method should not be required to be public,
// make it accessible so we can call it
// Note: The spec says the following:
// The agent class must implement a public static premain method...
setAccessible(m, true);
// invoke the 1 or 2-arg method
......
......@@ -64,7 +64,8 @@ class Flag {
}
VMOption getVMOption() {
return new VMOption(name, value.toString(), writeable, origin);
String val = value == null ? "" : value.toString();
return new VMOption(name, val, writeable, origin);
}
static Flag getFlag(String name) {
......
......@@ -626,6 +626,7 @@ appendClassPath( JPLISAgent* agent,
jvmtiError jvmtierr;
jvmtierr = (*jvmtienv)->AddToSystemClassLoaderSearch(jvmtienv, jarfile);
check_phase_ret_1(jvmtierr);
if (jvmtierr == JVMTI_ERROR_NONE) {
return 0;
......@@ -634,6 +635,7 @@ appendClassPath( JPLISAgent* agent,
jvmtiError err;
err = (*jvmtienv)->GetPhase(jvmtienv, &phase);
/* can be called from any phase */
jplis_assert(err == JVMTI_ERROR_NONE);
if (phase == JVMTI_PHASE_LIVE) {
......@@ -805,6 +807,8 @@ appendBootClassPath( JPLISAgent* agent,
/* print warning if boot class path not updated */
if (jvmtierr != JVMTI_ERROR_NONE) {
check_phase_blob_ret(jvmtierr, free(path));
fprintf(stderr, "WARNING: %s not added to bootstrap class loader search: ", path);
switch (jvmtierr) {
case JVMTI_ERROR_ILLEGAL_ARGUMENT :
......
......@@ -179,6 +179,7 @@ getJPLISEnvironment(jvmtiEnv * jvmtienv) {
jvmtierror = (*jvmtienv)->GetEnvironmentLocalStorage(
jvmtienv,
(void**)&environment);
/* can be called from any phase */
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
if (jvmtierror == JVMTI_ERROR_NONE) {
......@@ -230,6 +231,7 @@ createNewJPLISAgent(JavaVM * vm, JPLISAgent **agent_ptr) {
/* don't leak envs */
if ( initerror != JPLIS_INIT_ERROR_NONE ) {
jvmtiError jvmtierror = (*jvmtienv)->DisposeEnvironment(jvmtienv);
/* can be called from any phase */
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
}
}
......@@ -259,7 +261,7 @@ initializeJPLISAgent( JPLISAgent * agent,
agent->mNormalEnvironment.mIsRetransformer = JNI_FALSE;
agent->mRetransformEnvironment.mJVMTIEnv = NULL; /* NULL until needed */
agent->mRetransformEnvironment.mAgent = agent;
agent->mRetransformEnvironment.mIsRetransformer = JNI_TRUE;
agent->mRetransformEnvironment.mIsRetransformer = JNI_FALSE; /* JNI_FALSE until mJVMTIEnv is set */
agent->mAgentmainCaller = NULL;
agent->mInstrumentationImpl = NULL;
agent->mPremainCaller = NULL;
......@@ -277,18 +279,25 @@ initializeJPLISAgent( JPLISAgent * agent,
jvmtierror = (*jvmtienv)->SetEnvironmentLocalStorage(
jvmtienv,
&(agent->mNormalEnvironment));
/* can be called from any phase */
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
/* check what capabilities are available */
checkCapabilities(agent);
/* check phase - if live phase then we don't need the VMInit event */
jvmtierror == (*jvmtienv)->GetPhase(jvmtienv, &phase);
jvmtierror = (*jvmtienv)->GetPhase(jvmtienv, &phase);
/* can be called from any phase */
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
if (phase == JVMTI_PHASE_LIVE) {
return JPLIS_INIT_ERROR_NONE;
}
if (phase != JVMTI_PHASE_ONLOAD) {
/* called too early or called too late; either way bail out */
return JPLIS_INIT_ERROR_FAILURE;
}
/* now turn on the VMInit event */
if ( jvmtierror == JVMTI_ERROR_NONE ) {
jvmtiEventCallbacks callbacks;
......@@ -298,6 +307,7 @@ initializeJPLISAgent( JPLISAgent * agent,
jvmtierror = (*jvmtienv)->SetEventCallbacks( jvmtienv,
&callbacks,
sizeof(callbacks));
check_phase_ret_blob(jvmtierror, JPLIS_INIT_ERROR_FAILURE);
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
}
......@@ -307,6 +317,7 @@ initializeJPLISAgent( JPLISAgent * agent,
JVMTI_ENABLE,
JVMTI_EVENT_VM_INIT,
NULL /* all threads */);
check_phase_ret_blob(jvmtierror, JPLIS_INIT_ERROR_FAILURE);
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
}
......@@ -622,6 +633,7 @@ setLivePhaseEventHandlers( JPLISAgent * agent) {
jvmtierror = (*jvmtienv)->SetEventCallbacks( jvmtienv,
&callbacks,
sizeof(callbacks));
check_phase_ret_false(jvmtierror);
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
......@@ -632,6 +644,7 @@ setLivePhaseEventHandlers( JPLISAgent * agent) {
JVMTI_DISABLE,
JVMTI_EVENT_VM_INIT,
NULL /* all threads */);
check_phase_ret_false(jvmtierror);
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
}
......@@ -642,6 +655,7 @@ setLivePhaseEventHandlers( JPLISAgent * agent) {
JVMTI_ENABLE,
JVMTI_EVENT_CLASS_FILE_LOAD_HOOK,
NULL /* all threads */);
check_phase_ret_false(jvmtierror);
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
}
......@@ -660,6 +674,7 @@ checkCapabilities(JPLISAgent * agent) {
memset(&potentialCapabilities, 0, sizeof(potentialCapabilities));
jvmtierror = (*jvmtienv)->GetPotentialCapabilities(jvmtienv, &potentialCapabilities);
check_phase_ret(jvmtierror);
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
if ( jvmtierror == JVMTI_ERROR_NONE ) {
......@@ -681,9 +696,11 @@ enableNativeMethodPrefixCapability(jvmtiEnv * jvmtienv) {
jvmtiError jvmtierror;
jvmtierror = (*jvmtienv)->GetCapabilities(jvmtienv, &desiredCapabilities);
/* can be called from any phase */
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
desiredCapabilities.can_set_native_method_prefix = 1;
jvmtierror = (*jvmtienv)->AddCapabilities(jvmtienv, &desiredCapabilities);
check_phase_ret(jvmtierror);
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
}
......@@ -715,9 +732,11 @@ addOriginalMethodOrderCapability(JPLISAgent * agent) {
jvmtiError jvmtierror;
jvmtierror = (*jvmtienv)->GetCapabilities(jvmtienv, &desiredCapabilities);
/* can be called from any phase */
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
desiredCapabilities.can_maintain_original_method_order = 1;
jvmtierror = (*jvmtienv)->AddCapabilities(jvmtienv, &desiredCapabilities);
check_phase_ret(jvmtierror);
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
}
......@@ -732,9 +751,11 @@ addRedefineClassesCapability(JPLISAgent * agent) {
if (agent->mRedefineAvailable && !agent->mRedefineAdded) {
jvmtierror = (*jvmtienv)->GetCapabilities(jvmtienv, &desiredCapabilities);
/* can be called from any phase */
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
desiredCapabilities.can_redefine_classes = 1;
jvmtierror = (*jvmtienv)->AddCapabilities(jvmtienv, &desiredCapabilities);
check_phase_ret(jvmtierror);
/*
* With mixed premain/agentmain agents then it's possible that the
......@@ -998,6 +1019,7 @@ retransformableEnvironment(JPLISAgent * agent) {
if (jvmtierror == JVMTI_ERROR_NONE) {
// install the retransforming environment
agent->mRetransformEnvironment.mJVMTIEnv = retransformerEnv;
agent->mRetransformEnvironment.mIsRetransformer = JNI_TRUE;
// Make it for ClassFileLoadHook handling
jvmtierror = (*retransformerEnv)->SetEnvironmentLocalStorage(
......@@ -1025,6 +1047,7 @@ isModifiableClass(JNIEnv * jnienv, JPLISAgent * agent, jclass clazz) {
jvmtierror = (*jvmtienv)->IsModifiableClass( jvmtienv,
clazz,
&is_modifiable);
check_phase_ret_false(jvmtierror);
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
return is_modifiable;
......@@ -1032,7 +1055,7 @@ isModifiableClass(JNIEnv * jnienv, JPLISAgent * agent, jclass clazz) {
jboolean
isRetransformClassesSupported(JNIEnv * jnienv, JPLISAgent * agent) {
return retransformableEnvironment(agent) != NULL;
return agent->mRetransformEnvironment.mIsRetransformer;
}
void
......@@ -1075,6 +1098,12 @@ retransformClasses(JNIEnv * jnienv, JPLISAgent * agent, jobjectArray classes) {
numClasses = (*jnienv)->GetArrayLength(jnienv, classes);
errorOccurred = checkForThrowable(jnienv);
jplis_assert(!errorOccurred);
if (!errorOccurred && numClasses == 0) {
jplis_assert(numClasses != 0);
errorOccurred = JNI_TRUE;
errorCode = JVMTI_ERROR_NULL_POINTER;
}
}
if (!errorOccurred) {
......@@ -1096,6 +1125,13 @@ retransformClasses(JNIEnv * jnienv, JPLISAgent * agent, jobjectArray classes) {
if (errorOccurred) {
break;
}
if (classArray[index] == NULL) {
jplis_assert(classArray[index] != NULL);
errorOccurred = JNI_TRUE;
errorCode = JVMTI_ERROR_NULL_POINTER;
break;
}
}
}
......@@ -1217,6 +1253,7 @@ redefineClasses(JNIEnv * jnienv, JPLISAgent * agent, jobjectArray classDefinitio
if (!errorOccurred) {
jvmtiError errorCode = JVMTI_ERROR_NONE;
errorCode = (*jvmtienv)->RedefineClasses(jvmtienv, numDefs, classDefs);
check_phase_blob_ret(errorCode, deallocate(jvmtienv, (void*)classDefs));
errorOccurred = (errorCode != JVMTI_ERROR_NONE);
if ( errorOccurred ) {
createAndThrowThrowableFromJVMTIErrorCode(jnienv, errorCode);
......@@ -1250,6 +1287,7 @@ commonGetClassList( JNIEnv * jnienv,
classLoader,
&classCount,
&classes);
check_phase_ret_blob(jvmtierror, localArray);
errorOccurred = (jvmtierror != JVMTI_ERROR_NONE);
jplis_assert(!errorOccurred);
......@@ -1311,6 +1349,7 @@ getObjectSize(JNIEnv * jnienv, JPLISAgent * agent, jobject objectToSize) {
jvmtiError jvmtierror = JVMTI_ERROR_NONE;
jvmtierror = (*jvmtienv)->GetObjectSize(jvmtienv, objectToSize, &objectSize);
check_phase_ret_0(jvmtierror);
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
if ( jvmtierror != JVMTI_ERROR_NONE ) {
createAndThrowThrowableFromJVMTIErrorCode(jnienv, jvmtierror);
......@@ -1360,6 +1399,7 @@ appendToClassLoaderSearch(JNIEnv * jnienv, JPLISAgent * agent, jstring jarFile,
} else {
jvmtierror = (*jvmtienv)->AddToSystemClassLoaderSearch(jvmtienv, platformChars);
}
check_phase_ret(jvmtierror);
if ( jvmtierror != JVMTI_ERROR_NONE ) {
createAndThrowThrowableFromJVMTIErrorCode(jnienv, jvmtierror);
......@@ -1450,6 +1490,7 @@ setNativeMethodPrefixes(JNIEnv * jnienv, JPLISAgent * agent, jobjectArray prefix
}
err = (*jvmtienv)->SetNativeMethodPrefixes(jvmtienv, inx, (char**)prefixes);
/* can be called from any phase */
jplis_assert(err == JVMTI_ERROR_NONE);
for (i = 0; i < inx; i++) {
......
......@@ -266,6 +266,48 @@ setNativeMethodPrefixes(JNIEnv * jnienv, JPLISAgent * agent, jobjectArray prefix
#define jvmti(a) a->mNormalEnvironment.mJVMTIEnv
/*
* A set of macros for insulating the JLI method callers from
* JVMTI_ERROR_WRONG_PHASE return codes.
*/
/* for a JLI method where "blob" is executed before simply returning */
#define check_phase_blob_ret(ret, blob) \
if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \
blob; \
return; \
}
/* for a JLI method where simply returning is benign */
#define check_phase_ret(ret) \
if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \
return; \
}
/* for a JLI method where returning zero (0) is benign */
#define check_phase_ret_0(ret) \
if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \
return 0; \
}
/* for a JLI method where returning one (1) is benign */
#define check_phase_ret_1(ret) \
if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \
return 1; \
}
/* for a case where a specific "blob" must be returned */
#define check_phase_ret_blob(ret, blob) \
if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \
return (blob); \
}
/* for a JLI method where returning false is benign */
#define check_phase_ret_false(ret) \
if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \
return (jboolean) 0; \
}
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
......
......@@ -23,6 +23,14 @@
* have any questions.
*/
#ifdef _WIN32
/*
* Win* needs this include. However, Linux and Solaris do not.
* Having this include on Solaris SPARC breaks having non US-ASCII
* characters in the value of the Premain-Class attribute.
*/
#include <ctype.h>
#endif /* _WIN32 */
#include <string.h>
#include <stdlib.h>
......@@ -45,11 +53,37 @@ doAttribute(const char* name, const char* value, void* user_data) {
if (attribute->name == NULL) {
free(attribute);
} else {
attribute->value = strdup(value);
char *begin = (char *)value;
char *end;
size_t value_len;
/* skip any leading white space */
while (isspace(*begin)) {
begin++;
}
/* skip any trailing white space */
end = &begin[strlen(begin)];
while (end > begin && isspace(end[-1])) {
end--;
}
if (begin == end) {
/* no value so skip this attribute */
free(attribute->name);
free(attribute);
return;
}
value_len = (size_t)(end - begin);
attribute->value = malloc(value_len + 1);
if (attribute->value == NULL) {
free(attribute->name);
free(attribute);
} else {
/* save the value without leading or trailing whitespace */
strncpy(attribute->value, begin, value_len);
attribute->value[value_len] = '\0';
attribute->next = NULL;
if (context->head == NULL) {
context->head = attribute;
......
......@@ -74,6 +74,7 @@ confirmingTLSSet( jvmtiEnv * jvmtienv,
jvmtienv,
thread,
newValue);
check_phase_ret_blob(error, error);
#if JPLISASSERT_ENABLEASSERTIONS
assertTLSValue( jvmtienv,
......@@ -96,6 +97,7 @@ assertTLSValue( jvmtiEnv * jvmtienv,
jvmtienv,
thread,
&test);
check_phase_ret(error);
jplis_assert(error == JVMTI_ERROR_NONE);
jplis_assert(test == expected);
}
......@@ -111,6 +113,7 @@ tryToAcquireReentrancyToken( jvmtiEnv * jvmtienv,
jvmtienv,
thread,
&storedValue);
check_phase_ret_false(error);
jplis_assert(error == JVMTI_ERROR_NONE);
if ( error == JVMTI_ERROR_NONE ) {
/* if this thread is already inside, just return false and short-circuit */
......
......@@ -46,6 +46,7 @@ allocate(jvmtiEnv * jvmtienv, size_t bytecount) {
error = (*jvmtienv)->Allocate(jvmtienv,
bytecount,
(unsigned char**) &resultBuffer);
/* may be called from any phase */
jplis_assert(error == JVMTI_ERROR_NONE);
if ( error != JVMTI_ERROR_NONE ) {
resultBuffer = NULL;
......@@ -66,6 +67,7 @@ deallocate(jvmtiEnv * jvmtienv, void * buffer) {
error = (*jvmtienv)->Deallocate(jvmtienv,
(unsigned char*)buffer);
/* may be called from any phase */
jplis_assert_msg(error == JVMTI_ERROR_NONE, "Can't deallocate memory");
return;
}
......
/*
* Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -39,6 +39,8 @@ import sun.misc.Unsafe;
* @since 1.5
*/
class MotifDnDConstants {
// utility class can not be instantiated
private MotifDnDConstants() {}
// Note that offsets in all native structures below do not depend on the
// architecture.
private static final Unsafe unsafe = XlibWrapper.unsafe;
......@@ -55,8 +57,7 @@ class MotifDnDConstants {
XAtom.get("XmTRANSFER_SUCCESS");
static final XAtom XA_XmTRANSFER_FAILURE =
XAtom.get("XmTRANSFER_FAILURE");
static final XSelection MotifDnDSelection =
new XSelection(XA_MOTIF_ATOM_0, null);
static final XSelection MotifDnDSelection = new XSelection(XA_MOTIF_ATOM_0);
public static final byte MOTIF_DND_PROTOCOL_VERSION = 0;
......@@ -231,6 +232,9 @@ class MotifDnDConstants {
}
public static final class Swapper {
// utility class can not be instantiated
private Swapper() {}
public static short swap(short s) {
return (short)(((s & 0xFF00) >>> 8) | ((s & 0xFF) << 8));
}
......
/*
* Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2003-2008 Sun Microsystems, Inc. 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
......@@ -933,7 +933,7 @@ class MotifDnDDropTargetProtocol extends XDropTargetProtocol {
XSelection selection = XSelection.getSelection(selectionAtom);
if (selection == null) {
selection = new XSelection(selectionAtom, null);
selection = new XSelection(selectionAtom);
}
return selection.getData(format, time_stamp);
......@@ -1056,7 +1056,7 @@ class MotifDnDDropTargetProtocol extends XDropTargetProtocol {
// the original structure can be freed before this
// SunDropTargetEvent is dispatched.
if (xclient != null) {
int size = new XClientMessageEvent(nativeCtxt).getSize();
int size = XClientMessageEvent.getSize();
nativeCtxt = unsafe.allocateMemory(size + 4 * Native.getLongSize());
......
/*
* Copyright 2008 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package sun.awt.X11;
interface OwnershipListener {
public void ownershipChanged(final boolean isOwner);
}
/*
* Copyright 2002-2006 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2002-2008 Sun Microsystems, Inc. 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
......@@ -58,7 +58,7 @@ package sun.awt.X11;
import sun.misc.Unsafe;
import java.util.HashMap;
public class XAtom {
public final class XAtom {
// Order of lock: XAWTLock -> XAtom.class
......@@ -175,7 +175,7 @@ public class XAtom {
public static XAtom get(String name) {
XAtom xatom = lookup(name);
if (xatom == null) {
xatom = new XAtom(name);
xatom = new XAtom(XToolkit.getDisplay(), name);
}
return xatom;
}
......@@ -232,10 +232,6 @@ public class XAtom {
this(display, name, true);
}
private XAtom(String name) {
this(XToolkit.getDisplay(), name, true);
}
public XAtom(String name, boolean autoIntern) {
this(XToolkit.getDisplay(), name, autoIntern);
}
......@@ -262,7 +258,7 @@ public class XAtom {
* @since 1.5
*/
public XAtom(long display, String name, boolean autoIntern) {
private XAtom(long display, String name, boolean autoIntern) {
this.name = name;
this.display = display;
if (autoIntern) {
......@@ -651,28 +647,6 @@ public class XAtom {
}
}
/**
* Initializes atom with name and display values
*/
public void setValues(long display, String name, boolean autoIntern) {
this.display = display;
this.name = name;
if (autoIntern) {
XToolkit.awtLock();
try {
atom = XlibWrapper.InternAtom(display,name,0);
} finally {
XToolkit.awtUnlock();
}
}
register();
}
public void setValues(long display, long atom) {
this.display = display;
this.atom = atom;
register();
}
public void setValues(long display, String name, long atom) {
this.display = display;
this.atom = atom;
......
/*
* Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2003-2008 Sun Microsystems, Inc. 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,30 +26,32 @@
package sun.awt.X11;
import java.awt.datatransfer.Transferable;
import java.util.SortedMap;
import java.util.Set;
import java.util.Iterator;
import java.util.HashSet;
import java.io.IOException;
import java.security.AccessController;
import java.util.HashMap;
import java.util.Map;
import sun.awt.UNIXToolkit;
import sun.awt.datatransfer.DataTransferer;
import sun.awt.datatransfer.SunClipboard;
import sun.awt.datatransfer.ClipboardTransferable;
import sun.security.action.GetIntegerAction;
/**
* A class which interfaces with the X11 selection service in order to support
* data transfer via Clipboard operations.
*/
public class XClipboard extends SunClipboard implements Runnable {
public final class XClipboard extends SunClipboard implements OwnershipListener
{
private final XSelection selection;
// Time of calling XConvertSelection().
private long convertSelectionTime;
// The flag used not to call XConvertSelection() if the previous SelectionNotify
// has not been processed by checkChange().
private volatile boolean isSelectionNotifyProcessed;
// The property in which the owner should place requested targets
// when tracking changes of available data flavors (practically targets).
private volatile XAtom targetsPropertyAtom;
private static final Object classLock = new Object();
......@@ -57,31 +59,33 @@ public class XClipboard extends SunClipboard implements Runnable {
private static int pollInterval;
private static Set listenedClipboards;
private static Map<Long, XClipboard> targetsAtom2Clipboard;
/**
* Creates a system clipboard object.
*/
public XClipboard(String name, String selectionName) {
super(name);
selection = new XSelection(XAtom.get(selectionName), this);
selection = new XSelection(XAtom.get(selectionName));
selection.registerOwershipListener(this);
}
/**
* The action to be run when we lose ownership
/*
* NOTE: This method may be called by privileged threads.
* DO NOT INVOKE CLIENT CODE ON THIS THREAD!
*/
public void run() {
lostOwnershipImpl();
public void ownershipChanged(final boolean isOwner) {
if (isOwner) {
checkChangeHere(contents);
} else {
lostOwnershipImpl();
}
}
protected synchronized void setContentsNative(Transferable contents) {
SortedMap formatMap = DataTransferer.getInstance().getFormatsForTransferable
(contents, DataTransferer.adaptFlavorMap(flavorMap));
long[] formats =
DataTransferer.getInstance().keysToLongArray(formatMap);
long[] formats = DataTransferer.keysToLongArray(formatMap);
if (!selection.setOwner(contents, formatMap, formats,
XToolkit.getCurrentServerTime())) {
......@@ -94,6 +98,7 @@ public class XClipboard extends SunClipboard implements Runnable {
return selection.getSelectionAtom().getAtom();
}
@Override
public synchronized Transferable getContents(Object requestor) {
if (contents != null) {
return contents;
......@@ -115,62 +120,163 @@ public class XClipboard extends SunClipboard implements Runnable {
return selection.getData(format, XToolkit.getCurrentServerTime());
}
// Called on the toolkit thread under awtLock.
public void checkChange(long[] formats) {
if (!selection.isOwner()) {
super.checkChange(formats);
}
}
void checkChangeHere(Transferable contents) {
private void checkChangeHere(Transferable contents) {
if (areFlavorListenersRegistered()) {
super.checkChange(DataTransferer.getInstance().
checkChange(DataTransferer.getInstance().
getFormatsForTransferableAsArray(contents, flavorMap));
}
}
protected void registerClipboardViewerChecked() {
if (pollInterval <= 0) {
pollInterval = ((Integer)AccessController.doPrivileged(
new GetIntegerAction("awt.datatransfer.clipboard.poll.interval",
defaultPollInterval))).intValue();
private static int getPollInterval() {
synchronized (XClipboard.classLock) {
if (pollInterval <= 0) {
pollInterval = defaultPollInterval;
pollInterval = AccessController.doPrivileged(
new GetIntegerAction("awt.datatransfer.clipboard.poll.interval",
defaultPollInterval));
if (pollInterval <= 0) {
pollInterval = defaultPollInterval;
}
}
return pollInterval;
}
}
private XAtom getTargetsPropertyAtom() {
if (null == targetsPropertyAtom) {
targetsPropertyAtom =
XAtom.get("XAWT_TARGETS_OF_SELECTION:" + selection.getSelectionAtom().getName());
}
selection.initializeSelectionForTrackingChanges();
return targetsPropertyAtom;
}
protected void registerClipboardViewerChecked() {
// for XConvertSelection() to be called for the first time in getTargetsDelayed()
isSelectionNotifyProcessed = true;
boolean mustSchedule = false;
synchronized (XClipboard.classLock) {
if (listenedClipboards == null) {
listenedClipboards = new HashSet(2);
if (targetsAtom2Clipboard == null) {
targetsAtom2Clipboard = new HashMap<Long, XClipboard>(2);
}
mustSchedule = targetsAtom2Clipboard.isEmpty();
targetsAtom2Clipboard.put(getTargetsPropertyAtom().getAtom(), this);
if (mustSchedule) {
XToolkit.addEventDispatcher(XWindow.getXAWTRootWindow().getWindow(),
new SelectionNotifyHandler());
}
mustSchedule = listenedClipboards.isEmpty();
listenedClipboards.add(this);
}
if (mustSchedule) {
XToolkit.schedule(new CheckChangeTimerTask(), pollInterval);
XToolkit.schedule(new CheckChangeTimerTask(), XClipboard.getPollInterval());
}
}
private static class CheckChangeTimerTask implements Runnable {
public void run() {
for (Iterator iter = listenedClipboards.iterator(); iter.hasNext();) {
XClipboard clpbrd = (XClipboard)iter.next();
clpbrd.selection.getTargetsDelayed();
for (XClipboard clpbrd : targetsAtom2Clipboard.values()) {
clpbrd.getTargetsDelayed();
}
synchronized (XClipboard.classLock) {
if (listenedClipboards != null && !listenedClipboards.isEmpty()) {
XToolkit.schedule(this, pollInterval);
if (targetsAtom2Clipboard != null && !targetsAtom2Clipboard.isEmpty()) {
XToolkit.schedule(this, XClipboard.getPollInterval());
}
}
}
}
private static class SelectionNotifyHandler implements XEventDispatcher {
public void dispatchEvent(XEvent ev) {
if (ev.get_type() == XlibWrapper.SelectionNotify) {
final XSelectionEvent xse = ev.get_xselection();
XClipboard clipboard = null;
synchronized (XClipboard.classLock) {
if (targetsAtom2Clipboard != null && !targetsAtom2Clipboard.isEmpty()) {
XToolkit.removeEventDispatcher(XWindow.getXAWTRootWindow().getWindow(), this);
return;
}
final long propertyAtom = xse.get_property();
clipboard = targetsAtom2Clipboard.get(propertyAtom);
}
if (null != clipboard) {
clipboard.checkChange(xse);
}
}
}
}
protected void unregisterClipboardViewerChecked() {
selection.deinitializeSelectionForTrackingChanges();
isSelectionNotifyProcessed = false;
synchronized (XClipboard.classLock) {
listenedClipboards.remove(this);
targetsAtom2Clipboard.remove(getTargetsPropertyAtom().getAtom());
}
}
// checkChange() will be called on SelectionNotify
private void getTargetsDelayed() {
XToolkit.awtLock();
try {
long curTime = System.currentTimeMillis();
if (isSelectionNotifyProcessed || curTime >= (convertSelectionTime + UNIXToolkit.getDatatransferTimeout()))
{
convertSelectionTime = curTime;
XlibWrapper.XConvertSelection(XToolkit.getDisplay(),
selection.getSelectionAtom().getAtom(),
XDataTransferer.TARGETS_ATOM.getAtom(),
getTargetsPropertyAtom().getAtom(),
XWindow.getXAWTRootWindow().getWindow(),
XlibWrapper.CurrentTime);
isSelectionNotifyProcessed = false;
}
} finally {
XToolkit.awtUnlock();
}
}
/*
* Tracks changes of available formats.
* NOTE: This method may be called by privileged threads.
* DO NOT INVOKE CLIENT CODE ON THIS THREAD!
*/
private void checkChange(XSelectionEvent xse) {
final long propertyAtom = xse.get_property();
if (propertyAtom != getTargetsPropertyAtom().getAtom()) {
// wrong atom
return;
}
final XAtom selectionAtom = XAtom.get(xse.get_selection());
final XSelection changedSelection = XSelection.getSelection(selectionAtom);
if (null == changedSelection || changedSelection != selection) {
// unknown selection - do nothing
return;
}
isSelectionNotifyProcessed = true;
if (selection.isOwner()) {
// selection is owner - do not need formats
return;
}
long[] formats = null;
if (propertyAtom == XlibWrapper.None) {
// We treat None property atom as "empty selection".
formats = new long[0];
} else {
WindowPropertyGetter targetsGetter =
new WindowPropertyGetter(XWindow.getXAWTRootWindow().getWindow(),
XAtom.get(propertyAtom), 0,
XSelection.MAX_LENGTH, true,
XlibWrapper.AnyPropertyType);
try {
targetsGetter.execute();
formats = XSelection.getFormats(targetsGetter);
} finally {
targetsGetter.dispose();
}
}
checkChange(formats);
}
}
/*
* Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2002-2008 Sun Microsystems, Inc. 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,17 +31,13 @@ import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.DefaultKeyboardFocusManager;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Insets;
import java.awt.KeyboardFocusManager;
import java.awt.MenuBar;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.SystemColor;
import java.awt.Toolkit;
......@@ -60,12 +56,9 @@ import java.awt.event.InvocationEvent;
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;
import java.awt.image.VolatileImage;
import java.awt.peer.CanvasPeer;
import java.awt.peer.ComponentPeer;
import java.awt.peer.ContainerPeer;
import java.awt.peer.LightweightPeer;
import java.awt.peer.PanelPeer;
import java.awt.peer.WindowPeer;
import java.lang.reflect.*;
import java.security.*;
import java.util.Collection;
......@@ -821,7 +814,7 @@ public class XComponentPeer extends XWindow implements ComponentPeer, DropTarget
public void setFont(Font f) {
synchronized (getStateLock()) {
if (f == null) {
f = defaultFont;
f = XWindow.getDefaultFont();
}
font = f;
}
......
/*
* Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -39,16 +39,37 @@ import sun.awt.ComponentAccessor;
* This class implements window which serves as content window for decorated frames.
* Its purpose to provide correct events dispatching for the complex
* constructs such as decorated frames.
*
* It should always be located at (- left inset, - top inset) in the associated
* decorated window. So coordinates in it would be the same as java coordinates.
*/
public class XContentWindow extends XWindow implements XConstants {
public final class XContentWindow extends XWindow implements XConstants {
private static Logger insLog = Logger.getLogger("sun.awt.X11.insets.XContentWindow");
XDecoratedPeer parentFrame;
static XContentWindow createContent(XDecoratedPeer parentFrame) {
final WindowDimensions dims = parentFrame.getDimensions();
Rectangle rec = dims.getBounds();
// Fix for - set the location of the content window to the (-left inset, -top inset)
Insets ins = dims.getInsets();
if (ins != null) {
rec.x = -ins.left;
rec.y = -ins.top;
} else {
rec.x = 0;
rec.y = 0;
}
final XContentWindow cw = new XContentWindow(parentFrame, rec);
cw.xSetVisible(true);
return cw;
}
private final XDecoratedPeer parentFrame;
// A list of expose events that come when the parentFrame is iconified
private java.util.List<SavedExposeEvent> iconifiedExposeEvents = new java.util.ArrayList<SavedExposeEvent>();
private final java.util.List<SavedExposeEvent> iconifiedExposeEvents =
new java.util.ArrayList<SavedExposeEvent>();
XContentWindow(XDecoratedPeer parentFrame, Rectangle bounds) {
private XContentWindow(XDecoratedPeer parentFrame, Rectangle bounds) {
super((Component)parentFrame.getTarget(), parentFrame.getShell(), bounds);
this.parentFrame = parentFrame;
}
......@@ -63,9 +84,6 @@ public class XContentWindow extends XWindow implements XConstants {
}
}
void initialize() {
xSetVisible(true);
}
protected String getWMName() {
return "Content window";
}
......
......@@ -36,7 +36,7 @@ import java.util.logging.Logger;
import sun.awt.ComponentAccessor;
import sun.awt.SunToolkit;
class XDecoratedPeer extends XWindowPeer {
abstract class XDecoratedPeer extends XWindowPeer {
private static final Logger log = Logger.getLogger("sun.awt.X11.XDecoratedPeer");
private static final Logger insLog = Logger.getLogger("sun.awt.X11.insets.XDecoratedPeer");
private static final Logger focusLog = Logger.getLogger("sun.awt.X11.focus.XDecoratedPeer");
......@@ -98,8 +98,7 @@ class XDecoratedPeer extends XWindowPeer {
// happen after the X window is created.
initResizability();
updateSizeHints(dimensions);
content = createContent(dimensions);
content.initialize();
content = XContentWindow.createContent(this);
if (warningWindow != null) {
warningWindow.toFront();
}
......@@ -160,20 +159,6 @@ class XDecoratedPeer extends XWindowPeer {
}
}
XContentWindow createContent(WindowDimensions dims) {
Rectangle rec = dims.getBounds();
// Fix for - set the location of the content window to the (-left inset, -top inset)
Insets ins = dims.getInsets();
if (ins != null) {
rec.x = -ins.left;
rec.y = -ins.top;
} else {
rec.x = 0;
rec.y = 0;
}
return new XContentWindow(this, rec);
}
XFocusProxyWindow createFocusProxy() {
return new XFocusProxyWindow(this);
}
......@@ -286,7 +271,7 @@ class XDecoratedPeer extends XWindowPeer {
return;
}
Component t = (Component)target;
if (getDecorations() == winAttr.AWT_DECOR_NONE) {
if (getDecorations() == XWindowAttributesData.AWT_DECOR_NONE) {
setReparented(true);
insets_corrected = true;
reshape(dimensions, SET_SIZE, false);
......@@ -471,6 +456,15 @@ class XDecoratedPeer extends XWindowPeer {
if (insLog.isLoggable(Level.FINE)) {
insLog.fine("Reshaping " + this + " to " + newDimensions + " op " + op + " user reshape " + userReshape);
}
if (userReshape) {
// We handle only userReshape == true cases. It means that
// if the window manager or any other part of the windowing
// system sets inappropriate size for this window, we can
// do nothing but accept it.
Rectangle reqBounds = newDimensions.getBounds();
Rectangle newBounds = constrainBounds(reqBounds.x, reqBounds.y, reqBounds.width, reqBounds.height);
newDimensions = new WindowDimensions(newBounds, newDimensions.getInsets(), newDimensions.isClientSizeSet());
}
XToolkit.awtLock();
try {
if (!isReparented() || !isVisible()) {
......@@ -586,6 +580,49 @@ class XDecoratedPeer extends XWindowPeer {
reshape(dims, operation, userReshape);
}
// This method gets overriden in XFramePeer & XDialogPeer.
abstract boolean isTargetUndecorated();
@Override
Rectangle constrainBounds(int x, int y, int width, int height) {
// We don't restrict the setBounds() operation if the code is trusted.
if (!hasWarningWindow()) {
return new Rectangle(x, y, width, height);
}
// If it's undecorated or is not currently visible,
// apply the same constraints as for the Window.
if (!isVisible() || isTargetUndecorated()) {
return super.constrainBounds(x, y, width, height);
}
// If it's visible & decorated, constraint the size only
int newX = x;
int newY = y;
int newW = width;
int newH = height;
GraphicsConfiguration gc = ((Window)target).getGraphicsConfiguration();
Rectangle sB = gc.getBounds();
Insets sIn = ((Window)target).getToolkit().getScreenInsets(gc);
Rectangle curBounds = getBounds();
int maxW = Math.max(sB.width - sIn.left - sIn.right, curBounds.width);
int maxH = Math.max(sB.height - sIn.top - sIn.bottom, curBounds.height);
// First make sure the size is withing the visible part of the screen
if (newW > maxW) {
newW = maxW;
}
if (newH > maxH) {
newH = maxH;
}
return new Rectangle(newX, newY, newW, newH);
}
/**
* @see java.awt.peer.ComponentPeer#setBounds
*/
......@@ -651,12 +688,12 @@ class XDecoratedPeer extends XWindowPeer {
}
if (!isReparented() && isVisible() && runningWM != XWM.NO_WM
&& !XWM.isNonReparentingWM()
&& getDecorations() != winAttr.AWT_DECOR_NONE) {
&& getDecorations() != XWindowAttributesData.AWT_DECOR_NONE) {
insLog.fine("- visible but not reparented, skipping");
return;
}
//Last chance to correct insets
if (!insets_corrected && getDecorations() != winAttr.AWT_DECOR_NONE) {
if (!insets_corrected && getDecorations() != XWindowAttributesData.AWT_DECOR_NONE) {
long parent = XlibUtil.getParentWindow(window);
Insets correctWM = (parent != -1) ? XWM.getWM().getInsets(this, window, parent) : null;
if (insLog.isLoggable(Level.FINER)) {
......@@ -824,7 +861,7 @@ class XDecoratedPeer extends XWindowPeer {
fs &= ~(MWM_FUNC_RESIZE | MWM_FUNC_MAXIMIZE);
}
winAttr.functions = fs;
XWM.setShellNotResizable(this, dimensions, dimensions.getScreenBounds(), false);
XWM.setShellNotResizable(this, dimensions, dimensions.getBounds(), false);
}
}
......@@ -870,7 +907,7 @@ class XDecoratedPeer extends XWindowPeer {
return getSize().height;
}
public WindowDimensions getDimensions() {
final public WindowDimensions getDimensions() {
return dimensions;
}
......
......@@ -88,7 +88,8 @@ class XDialogPeer extends XDecoratedPeer implements DialogPeer {
}
}
private boolean isTargetUndecorated() {
@Override
boolean isTargetUndecorated() {
if (undecorated != null) {
return undecorated.booleanValue();
} else {
......
/*
* Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2003-2008 Sun Microsystems, Inc. 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
......@@ -48,8 +48,7 @@ class XDnDConstants {
static final XAtom XA_XdndStatus = XAtom.get("XdndStatus");
static final XAtom XA_XdndFinished = XAtom.get("XdndFinished");
static final XSelection XDnDSelection =
new XSelection(XA_XdndSelection, null);
static final XSelection XDnDSelection = new XSelection(XA_XdndSelection);
public static final int XDND_MIN_PROTOCOL_VERSION = 3;
public static final int XDND_PROTOCOL_VERSION = 5;
......
......@@ -647,12 +647,6 @@ public class XEmbedCanvasPeer extends XCanvasPeer implements WindowFocusListener
}
if (isXEmbedActive()) {
switch ((int)msg.get_data(1)) {
case _SUN_XEMBED_START:
// Child has finished initialization and waits for notify
xembed.processXEmbedInfo();
notifyChildEmbedded();
break;
case XEMBED_REQUEST_FOCUS:
requestXEmbedFocus();
break;
......
......@@ -74,7 +74,6 @@ public class XEmbedClientHelper extends XEmbedHelper implements XEventDispatcher
XToolkit.awtUnlock();
}
}
notifyReady();
}
void handleClientMessage(XEvent xev) {
......@@ -84,7 +83,6 @@ public class XEmbedClientHelper extends XEmbedHelper implements XEventDispatcher
if (xembedLog.isLoggable(Level.FINE)) xembedLog.fine("Embedded message: " + msgidToString((int)msg.get_data(1)));
switch ((int)msg.get_data(1)) {
case XEMBED_EMBEDDED_NOTIFY: // Notification about embedding protocol start
// NOTE: May be called two times because we send _SUN_XEMBED_START
active = true;
server = getEmbedder(embedded, msg);
// Check if window is reparented. If not - it was created with
......@@ -223,13 +221,4 @@ public class XEmbedClientHelper extends XEmbedHelper implements XEventDispatcher
long getX11Mods(AWTKeyStroke stroke) {
return XWindow.getXModifiers(stroke);
}
void notifyReady() {
long wnd = server;
if (wnd == 0) {
// Server is still 0, get the parent
wnd = embedded.getParentWindowHandle();
}
sendMessage(wnd, _SUN_XEMBED_START);
}
}
......@@ -58,7 +58,6 @@ public class XEmbedHelper {
final static int XEMBED_REGISTER_ACCELERATOR = 12;
final static int XEMBED_UNREGISTER_ACCELERATOR= 13;
final static int XEMBED_ACTIVATE_ACCELERATOR = 14;
final static int _SUN_XEMBED_START = 1119;
final static int NON_STANDARD_XEMBED_GTK_GRAB_KEY = 108;
final static int NON_STANDARD_XEMBED_GTK_UNGRAB_KEY = 109;
......@@ -151,8 +150,6 @@ public class XEmbedHelper {
return "NON_STANDARD_XEMBED_GTK_UNGRAB_KEY";
case NON_STANDARD_XEMBED_GTK_GRAB_KEY:
return "NON_STANDARD_XEMBED_GTK_GRAB_KEY";
case _SUN_XEMBED_START:
return "XEMBED_START";
case XConstants.KeyPress | XEmbedServerTester.SYSTEM_EVENT_MASK:
return "KeyPress";
case XConstants.MapNotify | XEmbedServerTester.SYSTEM_EVENT_MASK:
......
......@@ -177,13 +177,6 @@ public class XEmbedServerTester implements XEventDispatcher {
embedCompletely();
}
public void test3_2() {
embedCompletely();
int res = getEventPos();
sendMessage(XEmbedHelper._SUN_XEMBED_START);
waitEmbeddedNotify(res);
}
public void test3_3() {
reparent = true;
embedCompletely();
......
......@@ -184,6 +184,12 @@ public class XEmbeddedFramePeer extends XFramePeer {
}
}
@Override
Rectangle constrainBounds(int x, int y, int width, int height) {
// We don't constrain the bounds of the EmbeddedFrames
return new Rectangle(x, y, width, height);
}
// don't use getBounds() inherited from XDecoratedPeer
public Rectangle getBounds() {
return new Rectangle(x, y, width, height);
......
/*
* Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2002-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -24,15 +24,18 @@
*/
package sun.awt.X11;
import java.util.Vector;
import java.awt.*;
import java.awt.peer.*;
import java.awt.event.*;
import sun.awt.im.*;
import sun.awt.*;
import java.util.logging.*;
import java.lang.reflect.Field;
import java.util.*;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.MenuBar;
import java.awt.Rectangle;
import java.awt.peer.FramePeer;
import java.util.logging.Level;
import java.util.logging.Logger;
class XFramePeer extends XDecoratedPeer implements FramePeer, XConstants {
private static Logger log = Logger.getLogger("sun.awt.X11.XFramePeer");
......@@ -92,7 +95,8 @@ class XFramePeer extends XDecoratedPeer implements FramePeer, XConstants {
}
}
private boolean isTargetUndecorated() {
@Override
boolean isTargetUndecorated() {
if (undecorated != null) {
return undecorated.booleanValue();
} else {
......@@ -285,19 +289,20 @@ class XFramePeer extends XDecoratedPeer implements FramePeer, XConstants {
* Let's see if this is a window state protocol message, and
* if it is - decode a new state in terms of java constants.
*/
Integer newState = XWM.getWM().isStateChange(this, ev);
if (newState == null) {
if (!XWM.getWM().isStateChange(this, ev)) {
stateLog.finer("either not a state atom or state has not been changed");
return;
}
int changed = state ^ newState.intValue();
final int newState = XWM.getWM().getState(this);
int changed = state ^ newState;
if (changed == 0) {
stateLog.finer("State is the same: " + state);
return;
}
int old_state = state;
state = newState.intValue();
state = newState;
if ((changed & Frame.ICONIFIED) != 0) {
if ((state & Frame.ICONIFIED) != 0) {
......
/*
* Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2002-2008 Sun Microsystems, Inc. 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
......@@ -218,7 +218,7 @@ public class XMenuItemPeer implements MenuItemPeer {
Font getTargetFont() {
if (target == null) {
return XWindow.defaultFont;
return XWindow.getDefaultFont();
}
try {
return (Font)m_getFont.invoke(target, new Object[0]);
......@@ -227,7 +227,7 @@ public class XMenuItemPeer implements MenuItemPeer {
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return XWindow.defaultFont;
return XWindow.getDefaultFont();
}
String getTargetLabel() {
......
/*
* Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2003-2008 Sun Microsystems, Inc. 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,17 +26,15 @@
package sun.awt.X11;
import java.awt.*;
import java.awt.Frame;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.LogManager;
import java.awt.*;
import java.awt.image.*;
import java.util.*;
class XNETProtocol extends XProtocol implements XStateProtocol, XLayerProtocol {
final static Logger log = Logger.getLogger("sun.awt.X11.XNETProtocol");
final class XNETProtocol extends XProtocol implements XStateProtocol, XLayerProtocol
{
private final static Logger log = Logger.getLogger("sun.awt.X11.XNETProtocol");
private final static Logger iconLog = Logger.getLogger("sun.awt.X11.icon.XNETProtocol");
private static Logger stateLog = Logger.getLogger("sun.awt.X11.states.XNETProtocol");
/**
* XStateProtocol
......@@ -276,6 +274,7 @@ class XNETProtocol extends XProtocol implements XStateProtocol, XLayerProtocol {
boolean doStateProtocol() {
boolean res = active() && checkProtocol(XA_NET_SUPPORTED, XA_NET_WM_STATE);
stateLog.finer("doStateProtocol() returns " + res);
return res;
}
......
/*
* Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2002-2008 Sun Microsystems, Inc. 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
......@@ -187,7 +187,7 @@ public class XPopupMenuPeer extends XMenuWindow implements PopupMenuPeer {
//Fix for 6267144: PIT: Popup menu label is not shown, XToolkit
Font getTargetFont() {
if (popupMenuTarget == null) {
return XWindow.defaultFont;
return XWindow.getDefaultFont();
}
try {
return (Font)m_getFont.invoke(popupMenuTarget, new Object[0]);
......@@ -196,7 +196,7 @@ public class XPopupMenuPeer extends XMenuWindow implements PopupMenuPeer {
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return XWindow.defaultFont;
return XWindow.getDefaultFont();
}
String getTargetLabel() {
......
/*
* Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2002-2008 Sun Microsystems, Inc. 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,11 +25,9 @@
package sun.awt.X11;
import java.awt.*;
import java.awt.event.*;
import java.awt.peer.*;
import java.beans.PropertyChangeListener;
import sun.awt.*;
import java.util.*;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
import java.awt.datatransfer.Clipboard;
import java.awt.dnd.DragSource;
import java.awt.dnd.DragGestureListener;
import java.awt.dnd.DragGestureEvent;
......@@ -37,20 +35,27 @@ import java.awt.dnd.DragGestureRecognizer;
import java.awt.dnd.MouseDragGestureRecognizer;
import java.awt.dnd.InvalidDnDOperationException;
import java.awt.dnd.peer.DragSourceContextPeer;
import java.awt.image.*;
import java.security.*;
import java.awt.im.InputMethodHighlight;
import java.awt.im.spi.InputMethodDescriptor;
import java.awt.datatransfer.Clipboard;
import java.awt.image.ColorModel;
import java.awt.peer.*;
import java.beans.PropertyChangeListener;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.LookAndFeel;
import javax.swing.UIDefaults;
import java.util.logging.*;
import sun.awt.*;
import sun.font.FontManager;
import sun.misc.PerformanceLogger;
import sun.print.PrintJob2D;
import java.lang.reflect.*;
public class XToolkit extends UNIXToolkit implements Runnable, XConstants {
public final class XToolkit extends UNIXToolkit implements Runnable, XConstants
{
private static Logger log = Logger.getLogger("sun.awt.X11.XToolkit");
private static Logger eventLog = Logger.getLogger("sun.awt.X11.event.XToolkit");
private static final Logger timeoutTaskLog = Logger.getLogger("sun.awt.X11.timeoutTask.XToolkit");
......@@ -1871,9 +1876,7 @@ public class XToolkit extends UNIXToolkit implements Runnable, XConstants {
}
public boolean isAlwaysOnTopSupported() {
Iterator iter = XWM.getWM().getProtocols(XLayerProtocol.class).iterator();
while (iter.hasNext()) {
XLayerProtocol proto = (XLayerProtocol)iter.next();
for (XLayerProtocol proto : XWM.getWM().getProtocols(XLayerProtocol.class)) {
if (proto.supportsLayer(XLayerProtocol.LAYER_ALWAYS_ON_TOP)) {
return true;
}
......
/*
* Copyright 2005-2007 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2005-2008 Sun Microsystems, Inc. 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,11 +31,8 @@ import java.awt.peer.TrayIconPeer;
import sun.awt.*;
import java.awt.image.*;
import java.text.BreakIterator;
import java.util.Vector;
import java.lang.reflect.Field;
import java.util.logging.Logger;
import java.util.logging.Level;
import java.util.AbstractQueue;
import java.util.concurrent.ArrayBlockingQueue;
import java.security.AccessController;
import java.security.PrivilegedAction;
......@@ -629,7 +626,7 @@ public class XTrayIconPeer implements TrayIconPeer {
final static int TOOLTIP_MAX_LENGTH = 64;
final static int TOOLTIP_MOUSE_CURSOR_INDENT = 5;
final static Color TOOLTIP_BACKGROUND_COLOR = new Color(255, 255, 220);
final static Font TOOLTIP_TEXT_FONT = XWindow.defaultFont;
final static Font TOOLTIP_TEXT_FONT = XWindow.getDefaultFont();
Tooltip(XTrayIconPeer xtiPeer, Frame parent) {
super(parent, Color.black);
......
/*
* Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2003-2008 Sun Microsystems, Inc. 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,20 +31,23 @@
package sun.awt.X11;
import sun.misc.Unsafe;
import java.util.regex.*;
import java.awt.Insets;
import java.awt.Frame;
import java.awt.Rectangle;
import java.util.*;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import java.awt.Insets;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Class incapsulating knowledge about window managers in general
* Descendants should provide some information about specific window manager.
*/
class XWM implements MWMConstants, XUtilConstants {
final class XWM implements MWMConstants, XUtilConstants
{
private final static Logger log = Logger.getLogger("sun.awt.X11.XWM");
private final static Logger insLog = Logger.getLogger("sun.awt.X11.insets.XWM");
......@@ -1026,21 +1029,21 @@ class XWM implements MWMConstants, XUtilConstants {
/*****************************************************************************\
* Protocols support
*/
HashMap<Class<?>, Collection<XProtocol>> protocolsMap = new HashMap<Class<?>, Collection<XProtocol>>();
private HashMap<Class<?>, Collection<?>> protocolsMap = new HashMap<Class<?>, Collection<?>>();
/**
* Returns all protocols supporting given protocol interface
*/
Collection<XProtocol> getProtocols(Class protocolInterface) {
Collection<XProtocol> res = protocolsMap.get(protocolInterface);
<T> Collection<T> getProtocols(Class<T> protocolInterface) {
Collection<T> res = (Collection<T>) protocolsMap.get(protocolInterface);
if (res != null) {
return (Collection<XProtocol>)res;
return res;
} else {
return new LinkedList<XProtocol>();
return new LinkedList<T>();
}
}
void addProtocol(Class protocolInterface, XProtocol protocol) {
Collection<XProtocol> protocols = getProtocols(protocolInterface);
private <T> void addProtocol(Class<T> protocolInterface, T protocol) {
Collection<T> protocols = getProtocols(protocolInterface);
protocols.add(protocol);
protocolsMap.put(protocolInterface, protocols);
}
......@@ -1085,9 +1088,7 @@ class XWM implements MWMConstants, XUtilConstants {
}
/* FALLTROUGH */
case Frame.MAXIMIZED_BOTH:
Iterator iter = getProtocols(XStateProtocol.class).iterator();
while (iter.hasNext()) {
XStateProtocol proto = (XStateProtocol)iter.next();
for (XStateProtocol proto : getProtocols(XStateProtocol.class)) {
if (proto.supportsState(state)) {
return true;
}
......@@ -1105,10 +1106,8 @@ class XWM implements MWMConstants, XUtilConstants {
int getExtendedState(XWindowPeer window) {
Iterator iter = getProtocols(XStateProtocol.class).iterator();
int state = 0;
while (iter.hasNext()) {
XStateProtocol proto = (XStateProtocol)iter.next();
for (XStateProtocol proto : getProtocols(XStateProtocol.class)) {
state |= proto.getState(window);
}
if (state != 0) {
......@@ -1127,18 +1126,17 @@ class XWM implements MWMConstants, XUtilConstants {
/*
* Check if property change is a window state protocol message.
* If it is - return the new state as Integer, otherwise return null
*/
Integer isStateChange(XDecoratedPeer window, XPropertyEvent e) {
boolean isStateChange(XDecoratedPeer window, XPropertyEvent e) {
if (!window.isShowing()) {
stateLog.finer("Window is not showing");
return null;
return false;
}
int wm_state = window.getWMState();
if (wm_state == XlibWrapper.WithdrawnState) {
stateLog.finer("WithdrawnState");
return null;
return false;
} else {
stateLog.finer("Window WM_STATE is " + wm_state);
}
......@@ -1147,26 +1145,26 @@ class XWM implements MWMConstants, XUtilConstants {
is_state_change = true;
}
Iterator iter = getProtocols(XStateProtocol.class).iterator();
while (iter.hasNext()) {
XStateProtocol proto = (XStateProtocol)iter.next();
for (XStateProtocol proto : getProtocols(XStateProtocol.class)) {
is_state_change |= proto.isStateChange(e);
stateLog.finest(proto + ": is state changed = " + is_state_change);
}
int res = 0;
return is_state_change;
}
if (is_state_change) {
if (wm_state == XlibWrapper.IconicState) {
res = Frame.ICONIFIED;
} else {
res = Frame.NORMAL;
}
res |= getExtendedState(window);
}
if (is_state_change) {
return Integer.valueOf(res);
/*
* Returns current state (including extended) of a given window.
*/
int getState(XDecoratedPeer window) {
int res = 0;
final int wm_state = window.getWMState();
if (wm_state == XlibWrapper.IconicState) {
res = Frame.ICONIFIED;
} else {
return null;
res = Frame.NORMAL;
}
res |= getExtendedState(window);
return res;
}
/*****************************************************************************\
......@@ -1180,9 +1178,7 @@ class XWM implements MWMConstants, XUtilConstants {
* in XLayerProtocol
*/
void setLayer(XWindowPeer window, int layer) {
Iterator iter = getProtocols(XLayerProtocol.class).iterator();
while (iter.hasNext()) {
XLayerProtocol proto = (XLayerProtocol)iter.next();
for (XLayerProtocol proto : getProtocols(XLayerProtocol.class)) {
if (proto.supportsLayer(layer)) {
proto.setLayer(window, layer);
}
......@@ -1191,9 +1187,7 @@ class XWM implements MWMConstants, XUtilConstants {
}
void setExtendedState(XWindowPeer window, int state) {
Iterator iter = getProtocols(XStateProtocol.class).iterator();
while (iter.hasNext()) {
XStateProtocol proto = (XStateProtocol)iter.next();
for (XStateProtocol proto : getProtocols(XStateProtocol.class)) {
if (proto.supportsState(state)) {
proto.setState(window, state);
break;
......@@ -1239,9 +1233,7 @@ class XWM implements MWMConstants, XUtilConstants {
void unshadeKludge(XDecoratedPeer window) {
assert(window.isShowing());
Iterator iter = getProtocols(XStateProtocol.class).iterator();
while (iter.hasNext()) {
XStateProtocol proto = (XStateProtocol)iter.next();
for (XStateProtocol proto : getProtocols(XStateProtocol.class)) {
proto.unshadeKludge(window);
}
XToolkit.XSync();
......
/*
* Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2002-2008 Sun Microsystems, Inc. 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
......@@ -92,8 +92,16 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer {
SurfaceData surfaceData;
XRepaintArea paintArea;
// fallback default font object
final static Font defaultFont = new Font(Font.DIALOG, Font.PLAIN, 12);
private static Font defaultFont;
static synchronized Font getDefaultFont() {
if (null == defaultFont) {
defaultFont = new Font(Font.DIALOG, Font.PLAIN, 12);
}
return defaultFont;
}
/*
* Keeps all buttons which were pressed at the time of the last mouse
......@@ -333,7 +341,7 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer {
}
Font font = afont;
if (font == null) {
font = defaultFont;
font = XWindow.getDefaultFont();
}
return new SunGraphics2D(surfData, fgColor, bgColor, font);
}
......@@ -902,13 +910,11 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer {
super.handleConfigureNotifyEvent(xev);
insLog.log(Level.FINER, "Configure, {0}, event disabled: {1}",
new Object[] {xev, isEventDisabled(xev)});
new Object[] {xev.get_xconfigure(), isEventDisabled(xev)});
if (isEventDisabled(xev)) {
return;
}
long eventWindow = xev.get_xany().get_window();
// if ( Check if it's a resize, a move, or a stacking order change )
// {
Rectangle bounds = getBounds();
......@@ -982,7 +988,6 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer {
// called directly from this package, unlike handleKeyRelease.
// un-final it if you need to override it in a subclass.
final void handleKeyPress(XKeyEvent ev) {
int keycode = java.awt.event.KeyEvent.VK_UNDEFINED;
long keysym[] = new long[2];
char unicodeKey = 0;
keysym[0] = NoSymbol;
......@@ -1066,7 +1071,6 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer {
}
// un-private it if you need to call it from elsewhere
private void handleKeyRelease(XKeyEvent ev) {
int keycode = java.awt.event.KeyEvent.VK_UNDEFINED;
long keysym[] = new long[2];
char unicodeKey = 0;
keysym[0] = NoSymbol;
......
/*
* Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2002-2008 Sun Microsystems, Inc. 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
......@@ -112,9 +112,6 @@ class XWindowPeer extends XPanelPeer implements WindowPeer,
PARENT_WINDOW, Long.valueOf(0)}));
}
// fallback default font object
static Font defaultFont;
/*
* This constant defines icon size recommended for using.
* Apparently, we should use XGetIconSizes which should
......@@ -162,10 +159,7 @@ class XWindowPeer extends XPanelPeer implements WindowPeer,
Font f = target.getFont();
if (f == null) {
if (defaultFont == null) {
defaultFont = new Font(Font.DIALOG, Font.PLAIN, 12);
}
f = defaultFont;
f = XWindow.getDefaultFont();
target.setFont(f);
// we should not call setFont because it will call a repaint
// which the peer may not be ready to do yet.
......@@ -188,6 +182,9 @@ class XWindowPeer extends XPanelPeer implements WindowPeer,
GraphicsConfiguration gc = getGraphicsConfiguration();
((X11GraphicsDevice)gc.getDevice()).addDisplayChangedListener(this);
Rectangle bounds = (Rectangle)(params.get(BOUNDS));
params.put(BOUNDS, constrainBounds(bounds.x, bounds.y, bounds.width, bounds.height));
}
private void initWMProtocols() {
......@@ -437,6 +434,56 @@ class XWindowPeer extends XPanelPeer implements WindowPeer,
return ownerPeer;
}
// This method is overriden at the XDecoratedPeer to handle
// decorated windows a bit differently.
Rectangle constrainBounds(int x, int y, int width, int height) {
// We don't restrict the setBounds() operation if the code is trusted.
if (!hasWarningWindow()) {
return new Rectangle(x, y, width, height);
}
// The window bounds should be within the visible part of the screen
int newX = x;
int newY = y;
int newW = width;
int newH = height;
// Now check each point is within the visible part of the screen
GraphicsConfiguration gc = ((Window)target).getGraphicsConfiguration();
Rectangle sB = gc.getBounds();
Insets sIn = ((Window)target).getToolkit().getScreenInsets(gc);
int screenX = sB.x + sIn.left;
int screenY = sB.y + sIn.top;
int screenW = sB.width - sIn.left - sIn.right;
int screenH = sB.height - sIn.top - sIn.bottom;
// First make sure the size is withing the visible part of the screen
if (newW > screenW) {
newW = screenW;
}
if (newH > screenH) {
newH = screenH;
}
// Tweak the location if needed
if (newX < screenX) {
newX = screenX;
} else if (newX + newW > screenX + screenW) {
newX = screenX + screenW - newW;
}
if (newY < screenY) {
newY = screenY;
} else if (newY + newH > screenY + screenH) {
newY = screenY + screenH - newH;
}
return new Rectangle(newX, newY, newW, newH);
}
//Fix for 6318144: PIT:Setting Min Size bigger than current size enlarges
//the window but fails to revalidate, Sol-CDE
//This bug is regression for
......@@ -445,10 +492,14 @@ class XWindowPeer extends XPanelPeer implements WindowPeer,
//Note that this function is overriden in XDecoratedPeer so event
//posting is not changing for decorated peers
public void setBounds(int x, int y, int width, int height, int op) {
Rectangle newBounds = constrainBounds(x, y, width, height);
XToolkit.awtLock();
try {
Rectangle oldBounds = getBounds();
super.setBounds(x, y, width, height, op);
super.setBounds(newBounds.x, newBounds.y, newBounds.width, newBounds.height, op);
Rectangle bounds = getBounds();
XSizeHints hints = getHints();
......@@ -1035,7 +1086,7 @@ class XWindowPeer extends XPanelPeer implements WindowPeer,
return !(target instanceof Frame || target instanceof Dialog);
}
boolean hasWarningWindow() {
return warningWindow != null;
return ((Window)target).getWarningString() != null;
}
// The height of menu bar window
......
......@@ -102,4 +102,9 @@ class MDialogPeer extends MWindowPeer implements DialogPeer, MInputMethodControl
public void blockWindows(java.util.List<Window> toBlock) {
// do nothing
}
@Override
final boolean isTargetUndecorated() {
return ((Dialog)target).isUndecorated();
}
}
......@@ -204,4 +204,10 @@ public class MEmbeddedFramePeer extends MFramePeer {
}
public native Rectangle getBoundsPrivate();
@Override
Rectangle constrainBounds(int x, int y, int width, int height) {
// We don't constrain the bounds of the EmbeddedFrames
return new Rectangle(x, y, width, height);
}
}
......@@ -503,4 +503,9 @@ class MFramePeer extends MWindowPeer implements FramePeer, MInputMethodControl {
public Rectangle getBoundsPrivate() {
return getBounds();
}
@Override
final boolean isTargetUndecorated() {
return ((Frame)target).isUndecorated();
}
}
......@@ -113,6 +113,12 @@ DisplayChangedListener {
insets.right = getInset("awt.frame.rightInset", -1);
}
Rectangle bounds = target.getBounds();
sysX = bounds.x;
sysY = bounds.y;
sysW = bounds.width;
sysH = bounds.height;
super.init(target);
InputMethodManager imm = InputMethodManager.getInstance();
String menuString = imm.getTriggerMenuString();
......@@ -150,6 +156,7 @@ DisplayChangedListener {
GraphicsConfiguration gc = getGraphicsConfiguration();
((X11GraphicsDevice)gc.getDevice()).addDisplayChangedListener(this);
}
/* Support for multiple icons is not implemented in MAWT */
......@@ -246,6 +253,8 @@ DisplayChangedListener {
// NOTE: This method may be called by privileged threads.
// DO NOT INVOKE CLIENT CODE ON THIS THREAD!
public void handleResize(int width, int height) {
sysW = width;
sysH = height;
// REMIND: Is this secure? Can client code subclass input method?
if (!tcList.isEmpty() &&
......@@ -268,6 +277,8 @@ DisplayChangedListener {
}
public void handleMoved(int x, int y) {
sysX = x;
sysY = y;
postEvent(new ComponentEvent(target, ComponentEvent.COMPONENT_MOVED));
}
......@@ -505,4 +516,87 @@ DisplayChangedListener {
}
return false;
}
private final boolean hasWarningWindow() {
return ((Window)target).getWarningString() != null;
}
// This method is overriden at Dialog and Frame peers.
boolean isTargetUndecorated() {
return true;
}
private volatile int sysX = 0;
private volatile int sysY = 0;
private volatile int sysW = 0;
private volatile int sysH = 0;
Rectangle constrainBounds(int x, int y, int width, int height) {
// We don't restrict the setBounds() operation if the code is trusted.
if (!hasWarningWindow()) {
return new Rectangle(x, y, width, height);
}
int newX = x;
int newY = y;
int newW = width;
int newH = height;
GraphicsConfiguration gc = ((Window)target).getGraphicsConfiguration();
Rectangle sB = gc.getBounds();
Insets sIn = ((Window)target).getToolkit().getScreenInsets(gc);
int screenW = sB.width - sIn.left - sIn.right;
int screenH = sB.height - sIn.top - sIn.bottom;
// If it's undecorated or is not currently visible,
// then check each point is within the visible part of the screen
if (!target.isVisible() || isTargetUndecorated()) {
int screenX = sB.x + sIn.left;
int screenY = sB.y + sIn.top;
// First make sure the size is withing the visible part of the screen
if (newW > screenW) {
newW = screenW;
}
if (newH > screenH) {
newH = screenH;
}
// Tweak the location if needed
if (newX < screenX) {
newX = screenX;
} else if (newX + newW > screenX + screenW) {
newX = screenX + screenW - newW;
}
if (newY < screenY) {
newY = screenY;
} else if (newY + newH > screenY + screenH) {
newY = screenY + screenH - newH;
}
} else {
int maxW = Math.max(screenW, sysW);
int maxH = Math.max(screenH, sysH);
// Make sure the size is withing the visible part of the screen
// OR is less that the current size of the window.
if (newW > maxW) {
newW = maxW;
}
if (newH > maxH) {
newH = maxH;
}
}
return new Rectangle(newX, newY, newW, newH);
}
public void setBounds(int x, int y, int width, int height, int op) {
Rectangle newBounds = constrainBounds(x, y, width, height);
super.setBounds(newBounds.x, newBounds.y, newBounds.width, newBounds.height, op);
}
}
......@@ -63,15 +63,8 @@
#define CLOSEIO
#endif /* NO_INTERRUPTIBLE_IO */
/*
* Linux <sys/resource.h> does not define rlim_t (solaris
* does). THIS IS PROBABLY NOT THE RIGHT THING TO DO, so
* somebody please fix this.
*/
#ifdef __linux__
typedef int rlim_t ;
#endif
/* Get typedef for rlim_t */
#include <sys/resource.h>
#ifdef CLOSEIO
......
......@@ -108,11 +108,18 @@ class WDialogPeer extends WWindowPeer implements DialogPeer {
}
}
@Override
boolean isTargetUndecorated() {
return ((Dialog)target).isUndecorated();
}
public void reshape(int x, int y, int width, int height) {
Rectangle newBounds = constrainBounds(x, y, width, height);
if (((Dialog)target).isUndecorated()) {
super.reshape(x,y,width,height);
super.reshape(newBounds.x, newBounds.y, newBounds.width, newBounds.height);
} else {
reshapeFrame(x,y,width,height);
reshapeFrame(newBounds.x, newBounds.y, newBounds.width, newBounds.height);
}
}
......
......@@ -65,4 +65,10 @@ public class WEmbeddedFramePeer extends WFramePeer {
public native Rectangle getBoundsPrivate();
public native void synthesizeWmActivate(boolean doActivate);
@Override
Rectangle constrainBounds(int x, int y, int width, int height) {
// We don't constrain the bounds of the EmbeddedFrames
return new Rectangle(x, y, width, height);
}
}
......@@ -64,11 +64,18 @@ class WFramePeer extends WWindowPeer implements FramePeer {
}
}
@Override
boolean isTargetUndecorated() {
return ((Frame)target).isUndecorated();
}
public void reshape(int x, int y, int width, int height) {
Rectangle newBounds = constrainBounds(x, y, width, height);
if (((Frame)target).isUndecorated()) {
super.reshape(x,y,width,height);
super.reshape(newBounds.x, newBounds.y, newBounds.width, newBounds.height);
} else {
reshapeFrame(x,y,width,height);
reshapeFrame(newBounds.x, newBounds.y, newBounds.width, newBounds.height);
}
}
......
/*
* Copyright 1996-2007 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 1996-2008 Sun Microsystems, Inc. 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,8 +30,12 @@ abstract class WObjectPeer {
initIDs();
}
long pData; // The Windows handle for the native widget.
Object target; // The associated AWT object.
// The Windows handle for the native widget.
long pData;
// if the native peer has been destroyed
boolean destroyed = false;
// The associated AWT object.
Object target;
private volatile boolean disposed;
......
......@@ -434,6 +434,97 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer {
private native void nativeGrab();
private native void nativeUngrab();
private final boolean hasWarningWindow() {
return ((Window)target).getWarningString() != null;
}
boolean isTargetUndecorated() {
return true;
}
// These are the peer bounds. They get updated at:
// 1. the WWindowPeer.setBounds() method.
// 2. the native code (on WM_SIZE/WM_MOVE)
private volatile int sysX = 0;
private volatile int sysY = 0;
private volatile int sysW = 0;
private volatile int sysH = 0;
Rectangle constrainBounds(int x, int y, int width, int height) {
// We don't restrict the setBounds() operation if the code is trusted.
if (!hasWarningWindow()) {
return new Rectangle(x, y, width, height);
}
int newX = x;
int newY = y;
int newW = width;
int newH = height;
GraphicsConfiguration gc = ((Window)target).getGraphicsConfiguration();
Rectangle sB = gc.getBounds();
Insets sIn = ((Window)target).getToolkit().getScreenInsets(gc);
int screenW = sB.width - sIn.left - sIn.right;
int screenH = sB.height - sIn.top - sIn.bottom;
// If it's undecorated or is not currently visible
if (!((Window)target).isVisible() || isTargetUndecorated()) {
// Now check each point is within the visible part of the screen
int screenX = sB.x + sIn.left;
int screenY = sB.y + sIn.top;
// First make sure the size is withing the visible part of the screen
if (newW > screenW) {
newW = screenW;
}
if (newH > screenH) {
newH = screenH;
}
// Tweak the location if needed
if (newX < screenX) {
newX = screenX;
} else if (newX + newW > screenX + screenW) {
newX = screenX + screenW - newW;
}
if (newY < screenY) {
newY = screenY;
} else if (newY + newH > screenY + screenH) {
newY = screenY + screenH - newH;
}
} else {
int maxW = Math.max(screenW, sysW);
int maxH = Math.max(screenH, sysH);
// Make sure the size is withing the visible part of the screen
// OR less that the current size of the window.
if (newW > maxW) {
newW = maxW;
}
if (newH > maxH) {
newH = maxH;
}
}
return new Rectangle(newX, newY, newW, newH);
}
@Override
public void setBounds(int x, int y, int width, int height, int op) {
Rectangle newBounds = constrainBounds(x, y, width, height);
sysX = newBounds.x;
sysY = newBounds.y;
sysW = newBounds.width;
sysH = newBounds.height;
super.setBounds(newBounds.x, newBounds.y, newBounds.width, newBounds.height, op);
}
/*
* The method maps the list of the active windows to the window's AppContext,
* then the method registers ActiveWindowListener, GuiDisposedListener listeners;
......
/*
* Copyright 1996-2006 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 1996-2008 Sun Microsystems, Inc. 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,7 +47,7 @@ typedef AwtObject* PDATA;
JNI_CHECK_NULL_GOTO(peer, "peer", where); \
pData = JNI_GET_PDATA(peer); \
if (pData == NULL) { \
JNU_ThrowNullPointerException(env, "null pData"); \
THROW_NULL_PDATA_IF_NOT_DESTROYED(peer); \
goto where; \
} \
}
......@@ -63,7 +63,7 @@ typedef AwtObject* PDATA;
JNI_CHECK_NULL_RETURN(peer, "peer"); \
pData = JNI_GET_PDATA(peer); \
if (pData == NULL) { \
JNU_ThrowNullPointerException(env, "null pData"); \
THROW_NULL_PDATA_IF_NOT_DESTROYED(peer); \
return; \
} \
}
......@@ -96,7 +96,7 @@ typedef AwtObject* PDATA;
JNI_CHECK_NULL_RETURN_NULL(peer, "peer"); \
pData = JNI_GET_PDATA(peer); \
if (pData == NULL) { \
JNU_ThrowNullPointerException(env, "null pData"); \
THROW_NULL_PDATA_IF_NOT_DESTROYED(peer); \
return 0; \
} \
}
......@@ -105,16 +105,27 @@ typedef AwtObject* PDATA;
JNI_CHECK_NULL_RETURN_VAL(peer, "peer", val); \
pData = JNI_GET_PDATA(peer); \
if (pData == NULL) { \
JNU_ThrowNullPointerException(env, "null pData"); \
THROW_NULL_PDATA_IF_NOT_DESTROYED(peer); \
return val; \
} \
}
#define THROW_NULL_PDATA_IF_NOT_DESTROYED(peer) { \
jboolean destroyed = JNI_GET_DESTROYED(peer); \
if (destroyed != JNI_TRUE) { \
JNU_ThrowNullPointerException(env, "null pData"); \
} \
}
#define JNI_GET_PDATA(peer) (PDATA) env->GetLongField(peer, AwtObject::pDataID)
#define JNI_GET_DESTROYED(peer) env->GetBooleanField(peer, AwtObject::destroyedID)
#define JNI_SET_PDATA(peer, data) env->SetLongField(peer, \
AwtObject::pDataID, \
(jlong)data)
AwtObject::pDataID, \
(jlong)data)
#define JNI_SET_DESTROYED(peer) env->SetBooleanField(peer, \
AwtObject::destroyedID, \
JNI_TRUE)
/* /NEW JNI */
/*
......
......@@ -392,7 +392,7 @@ public:
jint modifiers, jint clickCount,
jboolean popupTrigger, jint scrollType,
jint scrollAmount, jint wheelRotation,
MSG *msg = NULL);
jdouble preciseWheelRotation, MSG *msg = NULL);
/*
* Allocate and initialize a new java.awt.event.FocusEvent, and
......@@ -785,7 +785,9 @@ private:
int windowMoveLockPosCX;
int windowMoveLockPosCY;
private:
// 6524352: support finer-resolution
static int sm_wheelRotationAmount;
/*
* The association list of children's IDs and corresponding components.
* Some components like Choice or List are required their sizes while
......
......@@ -273,6 +273,10 @@ LRESULT CALLBACK AwtDialog::MouseHookProc(int nCode,
{
HWND blocker = AwtWindow::GetModalBlocker(AwtComponent::GetTopLevelParentForWindow(hWnd));
HWND topMostBlocker = blocker;
HWND prevForegroundWindow = ::GetForegroundWindow();
if (::IsWindow(blocker)) {
::BringWindowToTop(hWnd);
}
while (::IsWindow(blocker)) {
topMostBlocker = blocker;
::BringWindowToTop(blocker);
......@@ -282,7 +286,7 @@ LRESULT CALLBACK AwtDialog::MouseHookProc(int nCode,
// no beep/flash if the mouse was clicked in the taskbar menu
// or the dialog is currently inactive
if ((::WindowFromPoint(mhs->pt) == hWnd) &&
(::GetForegroundWindow() == topMostBlocker))
(prevForegroundWindow == topMostBlocker))
{
::MessageBeep(MB_OK);
// some heuristics: 3 times x 64 milliseconds
......@@ -292,6 +296,7 @@ LRESULT CALLBACK AwtDialog::MouseHookProc(int nCode,
::BringWindowToTop(topMostBlocker);
::SetForegroundWindow(topMostBlocker);
}
return 1;
}
}
}
......
/*
* Copyright 1996-2007 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 1996-2008 Sun Microsystems, Inc. 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
......@@ -221,8 +221,7 @@ AwtFrame* AwtFrame::Create(jobject self, jobject parent)
// Update target's dimensions to reflect this embedded window.
::GetClientRect(frame->m_hwnd, &rect);
::MapWindowPoints(frame->m_hwnd, hwndParent, (LPPOINT)&rect,
2);
::MapWindowPoints(frame->m_hwnd, hwndParent, (LPPOINT)&rect, 2);
env->SetIntField(target, AwtComponent::xID, rect.left);
env->SetIntField(target, AwtComponent::yID, rect.top);
......@@ -231,6 +230,7 @@ AwtFrame* AwtFrame::Create(jobject self, jobject parent)
env->SetIntField(target, AwtComponent::heightID,
rect.bottom-rect.top);
frame->InitPeerGraphicsConfig(env, self);
AwtToolkit::GetInstance().RegisterEmbedderProcessId(hwndParent);
} else {
jint state = env->GetIntField(target, AwtFrame::stateID);
DWORD exStyle;
......@@ -408,8 +408,9 @@ MsgRouting AwtFrame::WmShowWindow(BOOL show, UINT status)
* message. This breaks Java focus. To workaround the problem we
* set the toplevel being shown foreground programmatically.
* The fix is localized to non-foreground process case only.
* (See also: 6599270)
*/
if (show == TRUE && status == 0) {
if (!IsEmbeddedFrame() && show == TRUE && status == 0) {
HWND fgHWnd = ::GetForegroundWindow();
if (fgHWnd != NULL) {
DWORD fgProcessID;
......@@ -495,7 +496,7 @@ MsgRouting AwtFrame::WmMouseMove(UINT flags, int x, int y) {
::SetWindowPos(GetHWnd(), NULL, r.left, r.top,
r.right-r.left, r.bottom-r.top,
SWP_NOACTIVATE | SWP_NOSENDCHANGING | SWP_NOZORDER |
SWP_NOACTIVATE | SWP_NOZORDER |
SWP_NOCOPYBITS | SWP_DEFERERASE);
}
return mrConsume;
......
/*
* Copyright 1996-2006 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 1996-2008 Sun Microsystems, Inc. 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
......@@ -51,6 +51,7 @@ public:
/* sun.awt.windows.WObjectPeer field and method ids */
static jfieldID pDataID;
static jfieldID destroyedID;
static jfieldID targetID;
static jmethodID getPeerForTargetMID;
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -27,7 +27,7 @@
* @summary test setNativeMethodPrefix
* @author Robert Field, Sun Microsystems
*
* @run shell MakeJAR2.sh NativeMethodPrefixAgent NativeMethodPrefixApp 'Can-Retransform-Classes: true' 'Can-Set-Native-Method-Prefix: true'
* @run shell/timeout=240 MakeJAR2.sh NativeMethodPrefixAgent NativeMethodPrefixApp 'Can-Retransform-Classes: true' 'Can-Set-Native-Method-Prefix: true'
* @run main/othervm -javaagent:NativeMethodPrefixAgent.jar NativeMethodPrefixApp
*/
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册