提交 469b62bd 编写于 作者: L lana

Merge

......@@ -142,59 +142,59 @@ FILES_2D_c = \
# These files rely on motif to be built, and should not be included
# in a headless build.
FILES_MOTIF_c = \
awt_AWTEvent.c \
awt_Button.c \
awt_Canvas.c \
awt_Checkbox.c \
awt_Component.c \
awt_Cursor.c \
awt_DataTransferer.c \
awt_DrawingSurface.c \
awt_Event.c \
awt_FileDialog.c \
awt_GlobalCursorManager.c \
awt_GraphicsEnv.c \
awt_InputMethod.c \
awt_Insets.c \
awt_KeyboardFocusManager.c \
awt_Label.c \
awt_List.c \
awt_Menu.c \
awt_MenuBar.c \
awt_MenuComponent.c \
awt_MenuItem.c \
awt_motif.c \
awt_Plugin.c \
awt_PopupMenu.c \
awt_Robot.c \
awt_Scrollbar.c \
awt_ScrollPane.c \
awt_Selection.c \
awt_UNIXToolkit.c \
awt_TextArea.c \
awt_TextField.c \
awt_TopLevel.c \
awt_mgrsel.c \
awt_util.c \
awt_wm.c \
awt_XmDnD.c \
awt_dnd.c \
awt_dnd_ds.c \
awt_dnd_dt.c \
canvas.c \
cursor.c \
multi_font.c \
robot_common.c \
list.c \
multiVis.c \
XDrawingArea.c \
MouseInfo.c \
awt_xembed.c \
awt_xembed_server.c \
gtk2_interface.c \
swing_GTKEngine.c \
swing_GTKStyle.c
#FILES_MOTIF_c = \
#keep awt_AWTEvent.c \
# awt_Button.c \
# awt_Canvas.c \
# awt_Checkbox.c \
#keep .h awt_Component.c \
#keep .h awt_Cursor.c \
# awt_DataTransferer.c \
# awt_DrawingSurface.c \
# awt_Event.c \
# awt_FileDialog.c \
# awt_GlobalCursorManager.c \
# awt_GraphicsEnv.c \
# awt_InputMethod.c \
#keep awt_Insets.c \
# awt_KeyboardFocusManager.c \
# awt_Label.c \
# awt_List.c \
# awt_Menu.c \
# awt_MenuBar.c \
# awt_MenuComponent.c \
# awt_MenuItem.c \
# awt_motif.c \
# awt_Plugin.c \
# awt_PopupMenu.c \
# awt_Robot.c \
# awt_Scrollbar.c \
# awt_ScrollPane.c \
# awt_Selection.c \
# awt_UNIXToolkit.c \
# awt_TextArea.c \
# awt_TextField.c \
# awt_TopLevel.c \
# awt_mgrsel.c \
# awt_util.c \
# awt_wm.c \
# awt_XmDnD.c \
# awt_dnd.c \
# awt_dnd_ds.c \
# awt_dnd_dt.c \
# canvas.c \
# cursor.c \
# multi_font.c \
# robot_common.c \
# list.c \
# multiVis.c \
# XDrawingArea.c \
# MouseInfo.c \
# awt_xembed.c \
# awt_xembed_server.c \
# gtk2_interface.c \
# swing_GTKEngine.c \
# swing_GTKStyle.c
# These files are required to be built, with or without motif. Some of
......
......@@ -60,48 +60,15 @@ FILES_export = \
sun/awt/image/DataBufferNative.java \
\
sun/awt/motif/X11FontMetrics.java \
sun/awt/motif/X11Clipboard.java \
sun/awt/motif/X11Selection.java \
sun/awt/motif/X11SelectionHolder.java \
sun/awt/X11InputMethod.java \
sun/awt/motif/MInputMethod.java \
sun/awt/motif/MInputMethodControl.java \
sun/awt/motif/MCustomCursor.java \
sun/awt/motif/MFontConfiguration.java \
sun/awt/motif/MFontPeer.java \
sun/awt/motif/MToolkit.java \
sun/awt/motif/MComponentPeer.java \
sun/awt/motif/MButtonPeer.java \
sun/awt/motif/MCanvasPeer.java \
sun/awt/motif/MCheckboxPeer.java \
sun/awt/motif/MFileDialogPeer.java \
sun/awt/motif/MGlobalCursorManager.java \
sun/awt/motif/MTextFieldPeer.java \
sun/awt/motif/MLabelPeer.java \
sun/awt/motif/MListPeer.java \
sun/awt/motif/MWindowPeer.java \
sun/awt/motif/MMenuBarPeer.java \
sun/awt/motif/MMenuPeer.java \
sun/awt/motif/MPopupMenuPeer.java \
sun/awt/motif/MDialogPeer.java \
sun/awt/motif/MMenuItemPeer.java \
sun/awt/motif/MCheckboxMenuItemPeer.java \
sun/awt/motif/MChoicePeer.java \
sun/awt/motif/MTextAreaPeer.java \
sun/awt/motif/MScrollbarPeer.java \
sun/awt/motif/MScrollPanePeer.java \
sun/awt/motif/MFramePeer.java \
sun/awt/DebugSettings.java \
sun/awt/EmbeddedFrame.java \
sun/awt/motif/MEmbeddedFramePeer.java \
sun/awt/PlatformFont.java \
sun/awt/FontDescriptor.java \
sun/awt/NativeLibLoader.java \
sun/awt/motif/MDropTargetContextPeer.java \
sun/awt/motif/MDragSourceContextPeer.java \
sun/awt/motif/MRobotPeer.java \
sun/awt/motif/X11DragSourceContextPeer.java \
sun/awt/motif/X11DropTargetContextPeer.java \
sun/awt/X11GraphicsEnvironment.java \
sun/awt/X11GraphicsDevice.java \
sun/awt/X11GraphicsConfig.java \
......@@ -124,7 +91,6 @@ FILES_export = \
sun/java2d/cmm/ColorTransform.java \
sun/awt/datatransfer/DataTransferer.java \
sun/awt/dnd/SunDragSourceContextPeer.java \
sun/awt/motif/MDataTransferer.java \
sun/awt/motif/MToolkitThreadBlockedHandler.java \
sun/java2d/opengl/OGLBlitLoops.java \
sun/java2d/opengl/OGLContext.java \
......@@ -220,6 +186,5 @@ FILES_export2 = \
java/awt/event/NativeLibLoader.java \
java/awt/peer/ComponentPeer.java \
java/awt/dnd/DnDConstants.java \
sun/awt/CausedFocusEvent.java \
sun/awt/motif/MEmbedCanvasPeer.java
sun/awt/CausedFocusEvent.java
此差异已折叠。
此差异已折叠。
......@@ -28,14 +28,6 @@
#
INIT += $(LIB_LOCATION)
ifndef HEADLESS
ifeq ($(PLATFORM), linux)
ifeq ($(STATIC_MOTIF),false)
INIT += $(LIB_LOCATION)/libXm.so
endif
endif
endif
#
# Files
#
......@@ -52,13 +44,9 @@ include $(BUILDDIR)/sun/awt/FILES_export_unix.gmk
ifdef HEADLESS
FILES_c = $(FILES_NO_MOTIF_c)
else
FILES_c = $(FILES_MOTIF_c) $(FILES_NO_MOTIF_c)
ifeq ($(MOTIF_VERSION), 2)
FILES_c += awt_motif21.c
FILES_c += awt_Choice21.c
endif
# FILES_c = $(FILES_MOTIF_c) $(FILES_NO_MOTIF_c)
# XXX if in FILES_MOTIF_c there are unrelated to motif stuff, create a separate list!
FILES_c = $(FILES_NO_MOTIF_c)
endif
ifeq ($(PLATFORM), solaris)
......@@ -93,15 +81,6 @@ include $(BUILDDIR)/common/Library.gmk
$(LIB_LOCATION):
$(MKDIR) -p $@
ifeq ($(PLATFORM), linux)
ifeq ($(STATIC_MOTIF),false)
$(LIB_LOCATION)/libXm.so:
$(CP) $(MOTIF_LIB)/libXm.so $(LIB_LOCATION)/libXm.so
# Automounter problem makes the link fail on Redhat 6.1.
# $(LN) -s $(MOTIF_LIB)/libXm.so $(LIB_LOCATION)/libXm.so
endif
endif
clean::
#
......@@ -135,12 +114,36 @@ CFLAGS += -DHEADLESS=$(HEADLESS)
CPPFLAGS += -DHEADLESS=$(HEADLESS)
OTHER_LDLIBS =
else
CFLAGS += -DMOTIF_VERSION=$(MOTIF_VERSION)
#CFLAGS += -DMOTIF_VERSION=$(MOTIF_VERSION)
#ifeq ($(STATIC_MOTIF),true)
# LIBXM = $(MOTIF_LIB)/libXm.a -lXp -lXmu
# ifeq ($(PLATFORM), linux)
# ifeq ($(ARCH_DATA_MODEL), 64)
# LIBXT = -lXt
# else
# # Allows for builds on Debian GNU Linux, X11 is in a different place
# LIBXT = $(firstword $(wildcard /usr/X11R6/lib/libXt.a) \
# $(wildcard /usr/lib/libXt.a))
# LIBSM = $(firstword $(wildcard /usr/X11R6/lib/libSM.a) \
# $(wildcard /usr/lib/libSM.a))
# LIBICE = $(firstword $(wildcard /usr/X11R6/lib/libICE.a) \
# $(wildcard /usr/lib/libICE.a))
# endif
# endif
#else
# LIBXM = -L$(MOTIF_LIB) -lXm -lXp
# ifeq ($(PLATFORM), linux)
# LIBXT = -lXt
# LIBSM =
# LIBICE =
# endif
#endif
ifeq ($(STATIC_MOTIF),true)
LIBXM = $(MOTIF_LIB)/libXm.a -lXp -lXmu
ifeq ($(PLATFORM), linux)
LIBXTST = -lXtst
ifeq ($(PLATFORM), linux)
ifeq ($(ARCH_DATA_MODEL), 64)
# XXX what about the rest of them?
LIBXT = -lXt
else
# Allows for builds on Debian GNU Linux, X11 is in a different place
......@@ -150,33 +153,25 @@ ifeq ($(STATIC_MOTIF),true)
$(wildcard /usr/lib/libSM.a))
LIBICE = $(firstword $(wildcard /usr/X11R6/lib/libICE.a) \
$(wildcard /usr/lib/libICE.a))
endif
endif
else
LIBXM = -L$(MOTIF_LIB) -lXm -lXp
ifeq ($(PLATFORM), linux)
LIBXT = -lXt
LIBSM =
LIBICE =
LIBXTST = $(firstword $(wildcard /usr/X11R6/lib/libXtst.a) \
$(wildcard /usr/lib/libXtst.a))
endif
endif
LIBXTST = -lXtst
# Use -lXmu for EditRes support
LIBXMU_DBG = -lXmu
LIBXMU_OPT =
LIBXMU = $(LIBXMU_$(VARIANT))
ifeq ($(PLATFORM), solaris)
OTHER_LDLIBS = $(LIBXM) -lXt -lXext $(LIBXTST) $(LIBXMU) -lX11 -lXi
OTHER_LDLIBS = -lXt -lXext $(LIBXTST) $(LIBXMU) -lX11 -lXi
endif
ifeq ($(PLATFORM), linux)
OTHER_CFLAGS += -DMLIB_NO_LIBSUNMATH
OTHER_CFLAGS += -DMOTIF_VERSION=2
# XXX what is this define below? Isn't it motif-related?
OTHER_CFLAGS += -DXMSTRINGDEFINES=1
OTHER_LDLIBS = $(LIBXM) $(LIBXMU) $(LIBXTST) -lXext $(LIBXT) $(LIBSM) $(LIBICE) -lX11 -lXi
OTHER_LDLIBS = $(LIBXMU) $(LIBXTST) -lXext $(LIBXT) $(LIBSM) $(LIBICE) -lX11 -lXi
endif
endif
......@@ -199,9 +194,8 @@ endif
CPPFLAGS += -I$(CUPS_HEADERS_PATH)
ifndef HEADLESS
CPPFLAGS += -I$(MOTIF_DIR)/include \
-I$(OPENWIN_HOME)/include
LDFLAGS += -L$(MOTIF_LIB) -L$(OPENWIN_LIB)
CPPFLAGS += -I$(OPENWIN_HOME)/include
LDFLAGS += -L$(OPENWIN_LIB)
endif # !HEADLESS
......
......@@ -213,8 +213,8 @@ public class Button extends Component implements Accessible {
}
// This could change the preferred size of the Component.
if (testvalid && valid) {
invalidate();
if (testvalid) {
invalidateIfValid();
}
}
......
/*
* Copyright 1995-2006 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
......@@ -284,8 +284,8 @@ public class Checkbox extends Component implements ItemSelectable, Accessible {
}
// This could change the preferred size of the Component.
if (testvalid && valid) {
invalidate();
if (testvalid) {
invalidateIfValid();
}
}
......
/*
* Copyright 1995-2006 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
......@@ -207,9 +207,7 @@ public class Choice extends Component implements ItemSelectable, Accessible {
}
// This could change the preferred size of the Component.
if (valid) {
invalidate();
}
invalidateIfValid();
}
/**
......@@ -269,9 +267,7 @@ public class Choice extends Component implements ItemSelectable, Accessible {
}
// This could change the preferred size of the Component.
if (valid) {
invalidate();
}
invalidateIfValid();
}
/**
......@@ -299,9 +295,7 @@ public class Choice extends Component implements ItemSelectable, Accessible {
}
// This could change the preferred size of the Component.
if (valid) {
invalidate();
}
invalidateIfValid();
}
/**
......@@ -323,9 +317,7 @@ public class Choice extends Component implements ItemSelectable, Accessible {
}
// This could change the preferred size of the Component.
if (valid) {
invalidate();
}
invalidateIfValid();
}
/**
......@@ -367,9 +359,7 @@ public class Choice extends Component implements ItemSelectable, Accessible {
}
// This could change the preferred size of the Component.
if (valid) {
invalidate();
}
invalidateIfValid();
}
/**
......
......@@ -350,7 +350,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
* @see #validate
* @see #invalidate
*/
volatile boolean valid = false;
private volatile boolean valid = false;
/**
* The <code>DropTarget</code> associated with this component.
......@@ -639,11 +639,21 @@ public abstract class Component implements ImageObserver, MenuContainer,
*/
private PropertyChangeSupport changeSupport;
// Note: this field is considered final, though readObject() prohibits
// initializing final fields.
private transient Object changeSupportLock = new Object();
private Object getChangeSupportLock() {
return changeSupportLock;
/*
* In some cases using "this" as an object to synchronize by
* can lead to a deadlock if client code also uses synchronization
* by a component object. For every such situation revealed we should
* consider possibility of replacing "this" with the package private
* objectLock object introduced below. So far there're 2 issues known:
* - CR 6708322 (the getName/setName methods);
* - CR 6608764 (the PropertyChangeListener machinery).
*
* Note: this field is considered final, though readObject() prohibits
* initializing final fields.
*/
private transient Object objectLock = new Object();
Object getObjectLock() {
return objectLock;
}
boolean isPacked = false;
......@@ -816,7 +826,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
*/
public String getName() {
if (name == null && !nameExplicitlySet) {
synchronized(this) {
synchronized(getObjectLock()) {
if (name == null && !nameExplicitlySet)
name = constructComponentName();
}
......@@ -833,7 +843,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
*/
public void setName(String name) {
String oldName;
synchronized(this) {
synchronized(getObjectLock()) {
oldName = this.name;
this.name = name;
nameExplicitlySet = true;
......@@ -1708,9 +1718,9 @@ public abstract class Component implements ImageObserver, MenuContainer,
// This could change the preferred size of the Component.
// Fix for 6213660. Should compare old and new fonts and do not
// call invalidate() if they are equal.
if (valid && f != oldFont && (oldFont == null ||
if (f != oldFont && (oldFont == null ||
!oldFont.equals(f))) {
invalidate();
invalidateIfValid();
}
}
......@@ -1767,9 +1777,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
firePropertyChange("locale", oldValue, l);
// This could change the preferred size of the Component.
if (valid) {
invalidate();
}
invalidateIfValid();
}
/**
......@@ -2078,8 +2086,8 @@ public abstract class Component implements ImageObserver, MenuContainer,
if (resized) {
invalidate();
}
if (parent != null && parent.valid) {
parent.invalidate();
if (parent != null) {
parent.invalidateIfValid();
}
}
if (needNotify) {
......@@ -2135,7 +2143,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
Toolkit.getEventQueue().postEvent(e);
}
} else {
if (this instanceof Container && ((Container)this).ncomponents > 0) {
if (this instanceof Container && ((Container)this).countComponents() > 0) {
boolean enabledOnToolkit =
Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK);
if (resized) {
......@@ -2648,7 +2656,8 @@ public abstract class Component implements ImageObserver, MenuContainer,
public void validate() {
synchronized (getTreeLock()) {
ComponentPeer peer = this.peer;
if (!valid && peer != null) {
boolean wasValid = isValid();
if (!wasValid && peer != null) {
Font newfont = getFont();
Font oldfont = peerFont;
if (newfont != oldfont && (oldfont == null
......@@ -2659,6 +2668,9 @@ public abstract class Component implements ImageObserver, MenuContainer,
peer.layout();
}
valid = true;
if (!wasValid) {
mixOnValidating();
}
}
}
......@@ -2687,12 +2699,20 @@ public abstract class Component implements ImageObserver, MenuContainer,
if (!isMaximumSizeSet()) {
maxSize = null;
}
if (parent != null && parent.valid) {
parent.invalidate();
if (parent != null) {
parent.invalidateIfValid();
}
}
}
/** Invalidates the component unless it is already invalid.
*/
final void invalidateIfValid() {
if (isValid()) {
invalidate();
}
}
/**
* Creates a graphics context for this component. This method will
* return <code>null</code> if this component is currently not
......@@ -5794,7 +5814,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
}
}
transient EventQueueItem[] eventCache;
transient sun.awt.EventQueueItem[] eventCache;
/**
* @see #isCoalescingEnabled
......@@ -7545,9 +7565,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
Container rootAncestor = getTraversalRoot();
Component comp = this;
while (rootAncestor != null &&
!(rootAncestor.isShowing() &&
rootAncestor.isFocusable() &&
rootAncestor.isEnabled()))
!(rootAncestor.isShowing() && rootAncestor.canBeFocusOwner()))
{
comp = rootAncestor;
rootAncestor = comp.getFocusCycleRootAncestor();
......@@ -7596,9 +7614,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
Container rootAncestor = getTraversalRoot();
Component comp = this;
while (rootAncestor != null &&
!(rootAncestor.isShowing() &&
rootAncestor.isFocusable() &&
rootAncestor.isEnabled()))
!(rootAncestor.isShowing() && rootAncestor.canBeFocusOwner()))
{
comp = rootAncestor;
rootAncestor = comp.getFocusCycleRootAncestor();
......@@ -7777,7 +7793,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
protected String paramString() {
String thisName = getName();
String str = (thisName != null? thisName : "") + "," + x + "," + y + "," + width + "x" + height;
if (!valid) {
if (!isValid()) {
str += ",invalid";
}
if (!visible) {
......@@ -7905,7 +7921,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
*/
public void addPropertyChangeListener(
PropertyChangeListener listener) {
synchronized (getChangeSupportLock()) {
synchronized (getObjectLock()) {
if (listener == null) {
return;
}
......@@ -7931,7 +7947,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
*/
public void removePropertyChangeListener(
PropertyChangeListener listener) {
synchronized (getChangeSupportLock()) {
synchronized (getObjectLock()) {
if (listener == null || changeSupport == null) {
return;
}
......@@ -7954,7 +7970,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
* @since 1.4
*/
public PropertyChangeListener[] getPropertyChangeListeners() {
synchronized (getChangeSupportLock()) {
synchronized (getObjectLock()) {
if (changeSupport == null) {
return new PropertyChangeListener[0];
}
......@@ -7996,7 +8012,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
public void addPropertyChangeListener(
String propertyName,
PropertyChangeListener listener) {
synchronized (getChangeSupportLock()) {
synchronized (getObjectLock()) {
if (listener == null) {
return;
}
......@@ -8026,7 +8042,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
public void removePropertyChangeListener(
String propertyName,
PropertyChangeListener listener) {
synchronized (getChangeSupportLock()) {
synchronized (getObjectLock()) {
if (listener == null || changeSupport == null) {
return;
}
......@@ -8050,7 +8066,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
*/
public PropertyChangeListener[] getPropertyChangeListeners(
String propertyName) {
synchronized (getChangeSupportLock()) {
synchronized (getObjectLock()) {
if (changeSupport == null) {
return new PropertyChangeListener[0];
}
......@@ -8071,7 +8087,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
protected void firePropertyChange(String propertyName,
Object oldValue, Object newValue) {
PropertyChangeSupport changeSupport;
synchronized (getChangeSupportLock()) {
synchronized (getObjectLock()) {
changeSupport = this.changeSupport;
}
if (changeSupport == null ||
......@@ -8373,7 +8389,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
private void readObject(ObjectInputStream s)
throws ClassNotFoundException, IOException
{
changeSupportLock = new Object();
objectLock = new Object();
s.defaultReadObject();
......@@ -8537,9 +8553,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
firePropertyChange("componentOrientation", oldValue, o);
// This could change the preferred size of the Component.
if (valid) {
invalidate();
}
invalidateIfValid();
}
/**
......@@ -8575,6 +8589,14 @@ public abstract class Component implements ImageObserver, MenuContainer,
setComponentOrientation(orientation);
}
final boolean canBeFocusOwner() {
// It is enabled, visible, focusable.
if (isEnabled() && isDisplayable() && isVisible() && isFocusable()) {
return true;
}
return false;
}
/**
* Checks that this component meets the prerequesites to be focus owner:
* - it is enabled, visible, focusable
......@@ -8584,9 +8606,9 @@ public abstract class Component implements ImageObserver, MenuContainer,
* this component as focus owner
* @since 1.5
*/
final boolean canBeFocusOwner() {
final boolean canBeFocusOwnerRecursively() {
// - it is enabled, visible, focusable
if (!(isEnabled() && isDisplayable() && isVisible() && isFocusable())) {
if (!canBeFocusOwner()) {
return false;
}
......@@ -9381,7 +9403,8 @@ public abstract class Component implements ImageObserver, MenuContainer,
*/
private boolean areBoundsValid() {
Container cont = getContainer();
return cont == null || cont.isValid() || cont.getLayout() == null;
return cont == null || cont.isValid()
|| cont.getLayout() == null;
}
/**
......@@ -9652,5 +9675,10 @@ public abstract class Component implements ImageObserver, MenuContainer,
}
}
void mixOnValidating() {
// This method gets overriden in the Container. Obviously, a plain
// non-container components don't need to handle validation.
}
// ****************** END OF MIXING CODE ********************************
}
......@@ -556,8 +556,7 @@ public class ContainerOrderFocusTraversalPolicy extends FocusTraversalPolicy
* enabled, and focusable; <code>false</code> otherwise
*/
protected boolean accept(Component aComponent) {
if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
aComponent.isFocusable() && aComponent.isEnabled())) {
if (!aComponent.canBeFocusOwner()) {
return false;
}
......
......@@ -154,7 +154,7 @@ public class DefaultKeyboardFocusManager extends KeyboardFocusManager {
private boolean doRestoreFocus(Component toFocus, Component vetoedComponent,
boolean clearOnFailure)
{
if (toFocus != vetoedComponent && toFocus.isShowing() && toFocus.isFocusable() &&
if (toFocus != vetoedComponent && toFocus.isShowing() && toFocus.canBeFocusOwner() &&
toFocus.requestFocus(false, CausedFocusEvent.Cause.ROLLBACK))
{
return true;
......@@ -500,8 +500,11 @@ public class DefaultKeyboardFocusManager extends KeyboardFocusManager {
}
}
if (!(newFocusOwner.isFocusable() && newFocusOwner.isEnabled()
&& newFocusOwner.isShowing()))
if (!(newFocusOwner.isFocusable() && newFocusOwner.isShowing() &&
// Refuse focus on a disabled component if the focus event
// isn't of UNKNOWN reason (i.e. not a result of a direct request
// but traversal, activation or system generated).
(newFocusOwner.isEnabled() || cause.equals(CausedFocusEvent.Cause.UNKNOWN))))
{
// we should not accept focus on such component, so reject it.
dequeueKeyEvents(-1, newFocusOwner);
......@@ -742,8 +745,7 @@ public class DefaultKeyboardFocusManager extends KeyboardFocusManager {
public boolean dispatchKeyEvent(KeyEvent e) {
Component focusOwner = (((AWTEvent)e).isPosted) ? getFocusOwner() : e.getComponent();
if (focusOwner != null && focusOwner.isShowing() &&
focusOwner.isFocusable() && focusOwner.isEnabled()) {
if (focusOwner != null && focusOwner.isShowing() && focusOwner.canBeFocusOwner()) {
if (!e.isConsumed()) {
Component comp = e.getComponent();
if (comp != null && comp.isEnabled()) {
......
/*
* 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
......@@ -1327,8 +1327,8 @@ public class Dialog extends Window {
// the insets of the Dialog. If we could, we'd call invalidate()
// from the peer, but we need to guarantee that we're not holding
// the Dialog lock when we call invalidate().
if (testvalid && valid) {
invalidate();
if (testvalid) {
invalidateIfValid();
}
}
......
......@@ -42,6 +42,7 @@ import sun.awt.AppContext;
import sun.awt.AWTAutoShutdown;
import sun.awt.PeerEvent;
import sun.awt.SunToolkit;
import sun.awt.EventQueueItem;
/**
* <code>EventQueue</code> is a platform-independent class
......@@ -359,7 +360,7 @@ public class EventQueue {
entry != null; entry = entry.next)
{
// Give Component.coalesceEvents a chance
if (entry.event.getSource() == source && entry.id == id) {
if (entry.event.getSource() == source && entry.event.getID() == id) {
AWTEvent coalescedEvent = source.coalesceEvents(
entry.event, e);
if (coalescedEvent != null) {
......@@ -499,7 +500,7 @@ public class EventQueue {
for (EventQueueItem entry = queues[i].head, prev = null;
entry != null; prev = entry, entry = entry.next)
{
if (entry.id == id) {
if (entry.event.getID() == id) {
if (prev == null) {
queues[i].head = entry.next;
} else {
......@@ -545,7 +546,7 @@ public class EventQueue {
for (int i = NUM_PRIORITIES - 1; i >= 0; i--) {
EventQueueItem q = queues[i].head;
for (; q != null; q = q.next) {
if (q.id == id) {
if (q.event.getID() == id) {
return q.event;
}
}
......@@ -1051,14 +1052,3 @@ class Queue {
EventQueueItem head;
EventQueueItem tail;
}
class EventQueueItem {
AWTEvent event;
int id;
EventQueueItem next;
EventQueueItem(AWTEvent evt) {
event = evt;
id = evt.getID();
}
}
/*
* Copyright 1995-2006 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
......@@ -590,9 +590,7 @@ public class Frame extends Window implements MenuContainer {
if (peer != null) {
mbManagement = true;
menuBar.addNotify();
if (valid) {
invalidate();
}
invalidateIfValid();
peer.setMenuBar(menuBar);
}
}
......@@ -633,8 +631,8 @@ public class Frame extends Window implements MenuContainer {
// the insets of the Frame. If we could, we'd call invalidate()
// from the peer, but we need to guarantee that we're not holding
// the Frame lock when we call invalidate().
if (testvalid && valid) {
invalidate();
if (testvalid) {
invalidateIfValid();
}
firePropertyChange("resizable", oldResizable, resizable);
}
......@@ -907,9 +905,7 @@ public class Frame extends Window implements MenuContainer {
FramePeer peer = (FramePeer)this.peer;
if (peer != null) {
mbManagement = true;
if (valid) {
invalidate();
}
invalidateIfValid();
peer.setMenuBar(null);
m.removeNotify();
}
......
/*
* Copyright 1995-2006 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
......@@ -257,8 +257,8 @@ public class Label extends Component implements Accessible {
}
// This could change the preferred size of the Component.
if (testvalid && valid) {
invalidate();
if (testvalid) {
invalidateIfValid();
}
}
......
......@@ -357,7 +357,7 @@ public class ScrollPane extends Container implements Accessible {
*/
public void setScrollPosition(int x, int y) {
synchronized (getTreeLock()) {
if (ncomponents <= 0) {
if (getComponentCount()==0) {
throw new NullPointerException("child is null");
}
hAdjustable.setValue(x);
......@@ -393,11 +393,13 @@ public class ScrollPane extends Container implements Accessible {
*/
@Transient
public Point getScrollPosition() {
if (ncomponents <= 0) {
synchronized (getTreeLock()) {
if (getComponentCount()==0) {
throw new NullPointerException("child is null");
}
return new Point(hAdjustable.getValue(), vAdjustable.getValue());
}
}
/**
* Sets the layout manager for this container. This method is
......@@ -486,7 +488,9 @@ public class ScrollPane extends Container implements Accessible {
*/
@Deprecated
public void layout() {
if (ncomponents > 0) {
if (getComponentCount()==0) {
return;
}
Component c = getComponent(0);
Point p = getScrollPosition();
Dimension cs = calculateChildSize();
......@@ -506,7 +510,6 @@ public class ScrollPane extends Container implements Accessible {
hAdjustable.setSpan(0, cs.width, vs.width);
vAdjustable.setSpan(0, cs.height, vs.height);
}
}
/**
* Prints the component in this scroll pane.
......@@ -515,8 +518,10 @@ public class ScrollPane extends Container implements Accessible {
* @see Component#printAll
*/
public void printComponents(Graphics g) {
if (ncomponents > 0) {
Component c = component[0];
if (getComponentCount()==0) {
return;
}
Component c = getComponent(0);
Point p = c.getLocation();
Dimension vs = getViewportSize();
Insets i = getInsets();
......@@ -530,7 +535,6 @@ public class ScrollPane extends Container implements Accessible {
cg.dispose();
}
}
}
/**
* Creates the scroll pane's peer.
......@@ -589,7 +593,7 @@ public class ScrollPane extends Container implements Accessible {
default:
sdpStr = "invalid display policy";
}
Point p = ncomponents > 0? getScrollPosition() : new Point(0,0);
Point p = (getComponentCount()>0)? getScrollPosition() : new Point(0,0);
Insets i = getInsets();
return super.paramString()+",ScrollPosition=("+p.x+","+p.y+")"+
",Insets=("+i.top+","+i.left+","+i.bottom+","+i.right+")"+
......
/*
* 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
......@@ -125,6 +125,8 @@ public class SystemTray {
transient private SystemTrayPeer peer;
private static final TrayIcon[] EMPTY_TRAY_ARRAY = new TrayIcon[0];
/**
* Private <code>SystemTray</code> constructor.
*
......@@ -201,18 +203,19 @@ public class SystemTray {
* functionality is supported for the current platform
*/
public static boolean isSupported() {
Toolkit toolkit = Toolkit.getDefaultToolkit();
if (toolkit instanceof SunToolkit) {
// connecting tray to native resource
initializeSystemTrayIfNeeded();
if (Toolkit.getDefaultToolkit() instanceof SunToolkit) {
return ((SunToolkit)Toolkit.getDefaultToolkit()).isTraySupported();
} else if (Toolkit.getDefaultToolkit() instanceof HeadlessToolkit) {
return ((HeadlessToolkit)Toolkit.getDefaultToolkit()).isTraySupported();
}
return ((SunToolkit)toolkit).isTraySupported();
} else if (toolkit instanceof HeadlessToolkit) {
// skip initialization as the init routine
// throws HeadlessException
return ((HeadlessToolkit)toolkit).isTraySupported();
} else {
return false;
}
}
/**
* Adds a <code>TrayIcon</code> to the <code>SystemTray</code>.
......@@ -323,7 +326,7 @@ public class SystemTray {
if (icons != null) {
return (TrayIcon[])icons.toArray(new TrayIcon[icons.size()]);
}
return new TrayIcon[0];
return EMPTY_TRAY_ARRAY;
}
/**
......@@ -475,7 +478,12 @@ public class SystemTray {
synchronized void addNotify() {
if (peer == null) {
Toolkit toolkit = Toolkit.getDefaultToolkit();
if (toolkit instanceof SunToolkit) {
peer = ((SunToolkit)Toolkit.getDefaultToolkit()).createSystemTray(this);
} else if (toolkit instanceof HeadlessToolkit) {
peer = ((HeadlessToolkit)Toolkit.getDefaultToolkit()).createSystemTray(this);
}
}
}
......
/*
* 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
......@@ -296,9 +296,7 @@ public class TextField extends TextComponent {
super.setText(t);
// This could change the preferred size of the Component.
if (valid) {
invalidate();
}
invalidateIfValid();
}
/**
......
/*
* Copyright 2005-2006 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
......@@ -38,6 +38,7 @@ import java.util.EventListener;
import java.awt.peer.TrayIconPeer;
import sun.awt.AppContext;
import sun.awt.SunToolkit;
import sun.awt.HeadlessToolkit;
import java.util.EventObject;
/**
......@@ -142,9 +143,6 @@ public class TrayIcon {
*/
public TrayIcon(Image image) {
this();
if (image == null) {
throw new IllegalArgumentException("creating TrayIcon with null Image");
}
setImage(image);
}
......@@ -433,7 +431,7 @@ public class TrayIcon {
* @see java.awt.event.MouseListener
*/
public synchronized MouseListener[] getMouseListeners() {
return (MouseListener[])(getListeners(MouseListener.class));
return AWTEventMulticaster.getListeners(mouseListener, MouseListener.class);
}
/**
......@@ -494,7 +492,7 @@ public class TrayIcon {
* @see java.awt.event.MouseMotionListener
*/
public synchronized MouseMotionListener[] getMouseMotionListeners() {
return (MouseMotionListener[]) (getListeners(MouseMotionListener.class));
return AWTEventMulticaster.getListeners(mouseMotionListener, MouseMotionListener.class);
}
/**
......@@ -581,7 +579,7 @@ public class TrayIcon {
* @see java.awt.event.ActionListener
*/
public synchronized ActionListener[] getActionListeners() {
return (ActionListener[])(getListeners(ActionListener.class));
return AWTEventMulticaster.getListeners(actionListener, ActionListener.class);
}
/**
......@@ -635,7 +633,7 @@ public class TrayIcon {
TrayIconPeer peer = this.peer;
if (peer != null) {
peer.displayMessage(caption, text, messageType.toString());
peer.displayMessage(caption, text, messageType.name());
}
}
......@@ -657,24 +655,17 @@ public class TrayIcon {
// ****************************************************************
// ****************************************************************
<T extends EventListener> T[] getListeners(Class<T> listenerType) {
EventListener l = null;
if (listenerType == MouseListener.class) {
l = mouseListener;
} else if (listenerType == MouseMotionListener.class) {
l = mouseMotionListener;
} else if (listenerType == ActionListener.class) {
l = actionListener;
}
return AWTEventMulticaster.getListeners(l, listenerType);
}
void addNotify()
throws AWTException
{
synchronized (this) {
if (peer == null) {
Toolkit toolkit = Toolkit.getDefaultToolkit();
if (toolkit instanceof SunToolkit) {
peer = ((SunToolkit)Toolkit.getDefaultToolkit()).createTrayIcon(this);
} else if (toolkit instanceof HeadlessToolkit) {
peer = ((HeadlessToolkit)Toolkit.getDefaultToolkit()).createTrayIcon(this);
}
}
}
peer.setToolTip(tooltip);
......
......@@ -3145,9 +3145,7 @@ public class Window extends Container implements Accessible {
Component previousComp = temporaryLostComponent;
// Check that "component" is an acceptable focus owner and don't store it otherwise
// - or later we will have problems with opposite while handling WINDOW_GAINED_FOCUS
if (component == null
|| (component.isDisplayable() && component.isVisible() && component.isEnabled() && component.isFocusable()))
{
if (component == null || component.canBeFocusOwner()) {
temporaryLostComponent = component;
} else {
temporaryLostComponent = null;
......
......@@ -486,6 +486,8 @@ public class DragSourceContext
Cursor c = null;
switch (status) {
default:
targetAct = DnDConstants.ACTION_NONE;
case ENTER:
case OVER:
case CHANGED:
......@@ -506,10 +508,6 @@ public class DragSourceContext
else
c = DragSource.DefaultCopyDrop;
}
break;
default:
targetAct = DnDConstants.ACTION_NONE;
}
setCursorImpl(c);
......
......@@ -26,7 +26,9 @@
package javax.swing;
import java.awt.*;
import sun.awt.ModalExclude;
import sun.awt.SunToolkit;
/**
* Popups are used to display a <code>Component</code> to the user, typically
......@@ -225,7 +227,12 @@ public class Popup {
HeavyWeightWindow(Window parent) {
super(parent);
setFocusableWindowState(false);
setName("###overrideRedirect###");
Toolkit tk = Toolkit.getDefaultToolkit();
if (tk instanceof SunToolkit) {
// all the short-lived windows like Popups should be
// OverrideRedirect on X11 platforms
((SunToolkit)tk).setOverrideRedirect(this);
}
// Popups are typically transient and most likely won't benefit
// from true double buffering. Turn it off here.
getRootPane().setUseTrueDoubleBuffering(false);
......
......@@ -257,23 +257,29 @@ public abstract class EmbeddedFrame extends Frame
Set toTest;
Component currentFocused = e.getComponent();
Component last = getFocusTraversalPolicy().getLastComponent(this);
toTest = getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
if (toTest.contains(stroke) && (currentFocused == last || last == null)) {
if (toTest.contains(stroke)) {
// 6581899: performance improvement for SortingFocusTraversalPolicy
Component last = getFocusTraversalPolicy().getLastComponent(this);
if (currentFocused == last || last == null) {
if (traverseOut(FORWARD)) {
e.consume();
return true;
}
}
}
Component first = getFocusTraversalPolicy().getFirstComponent(this);
toTest = getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
if (toTest.contains(stroke) && (currentFocused == first || first == null)) {
if (toTest.contains(stroke)) {
// 6581899: performance improvement for SortingFocusTraversalPolicy
Component first = getFocusTraversalPolicy().getFirstComponent(this);
if (currentFocused == first || first == null) {
if (traverseOut(BACKWARD)) {
e.consume();
return true;
}
}
}
return false;
}
......
/*
* Copyright 1998 Sun Microsystems, Inc. All Rights Reserved.
* 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
......@@ -23,10 +23,15 @@
* have any questions.
*/
#include <jni_util.h>
package sun.awt;
/* fieldIDs for Menu fields that may be accessed from C */
struct MenuIDs {
jfieldID tearOff;
jfieldID isHelpMenu;
};
import java.awt.AWTEvent;
public class EventQueueItem {
public AWTEvent event;
public EventQueueItem next;
public EventQueueItem(AWTEvent evt) {
event = evt;
}
}
/*
* 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
......@@ -852,6 +852,15 @@ public abstract class SunToolkit extends Toolkit
return AccessController.doPrivileged(new GetBooleanAction("sun.awt.erasebackgroundonresize"));
}
/**
* Makes the window OverrideRedirect, on X11 platforms. See
* ICCCM specification for more details about OverrideRedirect
* windows. Implemented in XToolkit, no-op in WToolkit.
*/
public void setOverrideRedirect(Window target) {
}
static SoftCache imgCache = new SoftCache();
static synchronized Image getImageFromHash(Toolkit tk, URL url) {
......@@ -2039,12 +2048,3 @@ class PostEventQueue {
SunToolkit.wakeupEventQueue(eventQueue, event.getSource() == AWTAutoShutdown.getInstance());
}
} // class PostEventQueue
class EventQueueItem {
AWTEvent event;
EventQueueItem next;
EventQueueItem(AWTEvent evt) {
event = evt;
}
} // class EventQueueItem
......@@ -101,10 +101,15 @@ public class XKeysym {
// Otherwise, it is [1].
int ndx = XToolkit.isXsunServer() &&
! XToolkit.isXKBenabled() ? 2 : 1;
// Even if XKB is enabled, we have another problem: some symbol tables (e.g. cz) force
// a regular comma instead of KP_comma for a decimal separator. Result is,
// bugs like 6454041. So, we will try for keypadness a keysym with ndx==0 as well.
XToolkit.awtLock();
try {
return XlibWrapper.IsKeypadKey(
XlibWrapper.XKeycodeToKeysym(ev.get_display(), ev.get_keycode(), ndx ) );
return (XlibWrapper.IsKeypadKey(
XlibWrapper.XKeycodeToKeysym(ev.get_display(), ev.get_keycode(), ndx ) ) ||
XlibWrapper.IsKeypadKey(
XlibWrapper.XKeycodeToKeysym(ev.get_display(), ev.get_keycode(), 0 ) ));
} finally {
XToolkit.awtUnlock();
}
......
......@@ -189,6 +189,8 @@ final class XNETProtocol extends XProtocol implements XStateProtocol, XLayerProt
req.set_format(32);
req.set_data(0, (!set) ? _NET_WM_STATE_REMOVE : _NET_WM_STATE_ADD);
req.set_data(1, state.getAtom());
// Fix for 6735584: req.data[2] must be set to 0 when only one property is changed
req.set_data(2, 0);
log.log(Level.FINE, "Setting _NET_STATE atom {0} on {1} for {2}", new Object[] {state, window, Boolean.valueOf(set)});
XToolkit.awtLock();
try {
......
......@@ -97,6 +97,11 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
static int awt_multiclick_time;
static boolean securityWarningEnabled;
// WeakSet should be used here, but there is no such class
// in JDK (at least in JDK6 and earlier versions)
private WeakHashMap<Window, Boolean> overrideRedirectWindows =
new WeakHashMap<Window, Boolean>();
private static int screenWidth = -1, screenHeight = -1; // Dimensions of default screen
static long awt_defaultFg; // Pixel
private static XMouseInfoPeer xPeer;
......@@ -1248,6 +1253,19 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
}
}
@Override
public void setOverrideRedirect(Window target) {
synchronized (overrideRedirectWindows) {
overrideRedirectWindows.put(target, true);
}
}
public boolean isOverrideRedirect(Window target) {
synchronized (overrideRedirectWindows) {
return overrideRedirectWindows.containsKey(target);
}
}
static void dumpPeers() {
if (log.isLoggable(Level.FINE)) {
log.fine("Mapped windows:");
......
......@@ -129,6 +129,7 @@ class XWindowPeer extends XPanelPeer implements WindowPeer,
private static final int MAXIMUM_BUFFER_LENGTH_NET_WM_ICON = (2<<15) - 1;
void preInit(XCreateWindowParams params) {
target = (Component)params.get(TARGET);
params.put(REPARENTED,
Boolean.valueOf(isOverrideRedirect() || isSimpleWindow()));
super.preInit(params);
......@@ -1117,6 +1118,7 @@ class XWindowPeer extends XPanelPeer implements WindowPeer,
boolean isOverrideRedirect() {
return (XWM.getWMID() == XWM.OPENLOOK_WM ? true : false) ||
((XToolkit)Toolkit.getDefaultToolkit()).isOverrideRedirect((Window)target) ||
XTrayIconPeer.isTrayIconStuffWindow((Window)target);
}
......
......@@ -139,10 +139,15 @@ tojava // Xsun without XKB uses keysymarray[2] keysym to determine if it
tojava // Otherwise, it is [1].
tojava int ndx = XToolkit.isXsunServer() &&
tojava ! XToolkit.isXKBenabled() ? 2 : 1;
tojava // Even if XKB is enabled, we have another problem: some symbol tables (e.g. cz) force
tojava // a regular comma instead of KP_comma for a decimal separator. Result is,
tojava // bugs like 6454041. So, we will try for keypadness a keysym with ndx==0 as well.
tojava XToolkit.awtLock();
tojava try {
tojava return XlibWrapper.IsKeypadKey(
tojava XlibWrapper.XKeycodeToKeysym(ev.get_display(), ev.get_keycode(), ndx ) );
tojava return (XlibWrapper.IsKeypadKey(
tojava XlibWrapper.XKeycodeToKeysym(ev.get_display(), ev.get_keycode(), ndx ) ) ||
tojava XlibWrapper.IsKeypadKey(
tojava XlibWrapper.XKeycodeToKeysym(ev.get_display(), ev.get_keycode(), 0 ) ));
tojava } finally {
tojava XToolkit.awtUnlock();
tojava }
......
/*
* Copyright 1995-2001 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.motif;
import java.awt.*;
import java.awt.peer.*;
import java.awt.event.ActionEvent;
class MButtonPeer extends MComponentPeer implements ButtonPeer {
native void create(MComponentPeer peer);
public native void setLabel(String label);
MButtonPeer(Button target) {
super(target);
}
public Dimension getMinimumSize() {
FontMetrics fm = getFontMetrics(target.getFont());
String label = ((Button)target).getLabel();
if ( label == null ) {
label = "";
}
return new Dimension(fm.stringWidth(label) + 14,
fm.getHeight() + 8);
}
public boolean isFocusable() {
return true;
}
// NOTE: This method is called by privileged threads.
// DO NOT INVOKE CLIENT CODE ON THIS THREAD!
public void action(final long when, final int modifiers) {
MToolkit.executeOnEventHandlerThread(target, new Runnable() {
public void run() {
postEvent(new ActionEvent(target, ActionEvent.ACTION_PERFORMED,
((Button)target).getActionCommand(),
when, modifiers));
}
});
}
/*
* Print the native component by rendering the Motif look ourselves.
* ToDo(aim): needs to query native motif for more accurate size and
* color information.
*/
public void print(Graphics g) {
Button b = (Button)target;
Dimension d = b.size();
Color bg = b.getBackground();
Color fg = b.getForeground();
g.setColor(bg);
g.fillRect(2, 2, d.width - 3, d.height - 3);
draw3DRect(g, bg, 1, 1, d.width - 2, d.height - 2, true);
g.setColor(fg);
g.setFont(b.getFont());
FontMetrics fm = g.getFontMetrics();
String lbl = b.getLabel();
g.drawString(lbl, (d.width - fm.stringWidth(lbl)) / 2,
(d.height + fm.getMaxAscent() - fm.getMaxDescent()) / 2);
target.print(g);
}
/**
* DEPRECATED
*/
public Dimension minimumSize() {
return getMinimumSize();
}
}
/*
* Copyright 1995-2005 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.motif;
import java.awt.*;
import java.awt.peer.*;
import sun.awt.DisplayChangedListener;
import sun.awt.X11GraphicsConfig;
import sun.awt.X11GraphicsDevice;
import sun.awt.X11GraphicsEnvironment;
class MCanvasPeer extends MComponentPeer implements CanvasPeer,
DisplayChangedListener {
native void create(MComponentPeer parent);
private static native void initIDs();
static {
initIDs();
}
MCanvasPeer() {}
MCanvasPeer(Component target) {
super(target);
}
MCanvasPeer(Component target, Object arg) {
super(target, arg);
}
/* --- DisplayChangedListener Stuff --- */
public void displayChanged() {}
public void paletteChanged() {}
native void resetTargetGC(Component target);
/*
* Called when the Window this
* Canvas is on is moved onto another Xinerama screen.
*
* Canvases can be created with a non-defulat GraphicsConfiguration. The
* GraphicsConfiguration needs to be changed to one on the new screen,
* preferably with the same visual ID.
*
* Up-called for other windows peer instances (WPanelPeer, WWindowPeer).
*
* Should only be called from the event thread.
*/
public void displayChanged(int screenNum) {
resetLocalGC(screenNum);
resetTargetGC(target); /* call Canvas.setGCFromPeer() via native */
}
/* Set graphicsConfig to a GraphicsConfig with the same visual on the new
* screen, which should be easy in Xinerama mode.
*
* Should only be called from displayChanged(), and therefore only from
* the event thread.
*/
void resetLocalGC(int screenNum) {
// Opt: Only need to do if we're not using the default GC
if (graphicsConfig != null) {
X11GraphicsConfig parentgc;
// save vis id of current gc
int visual = graphicsConfig.getVisual();
X11GraphicsDevice newDev = (X11GraphicsDevice) GraphicsEnvironment.
getLocalGraphicsEnvironment().
getScreenDevices()[screenNum];
for (int i = 0; i < newDev.getNumConfigs(screenNum); i++) {
if (visual == newDev.getConfigVisualId(i, screenNum)) {
// use that
graphicsConfig = (X11GraphicsConfig)newDev.getConfigurations()[i];
break;
}
}
// just in case...
if (graphicsConfig == null) {
graphicsConfig = (X11GraphicsConfig) GraphicsEnvironment.
getLocalGraphicsEnvironment().
getScreenDevices()[screenNum].
getDefaultConfiguration();
}
}
}
protected boolean shouldFocusOnClick() {
// Canvas should always be able to be focused by mouse clicks.
return true;
}
}
/*
* Copyright 1995-2000 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.motif;
import java.awt.*;
import java.awt.peer.*;
import java.awt.event.*;
public class MCheckboxPeer extends MComponentPeer implements CheckboxPeer {
private boolean inUpCall = false;
private boolean inInit=false;
native void create(MComponentPeer parent);
native void pSetState(boolean state);
native boolean pGetState();
public native void setLabel(String label);
public native void setCheckboxGroup(CheckboxGroup g);
void initialize() {
Checkbox t = (Checkbox)target;
inInit=true;
setState(t.getState());
setCheckboxGroup(t.getCheckboxGroup());
super.initialize();
inInit=false;
}
public MCheckboxPeer(Checkbox target) {
super(target);
}
public boolean isFocusable() {
return true;
}
public void setState(boolean state) {
if (inInit) {
pSetState(state);
} else if (!inUpCall && (state != pGetState())) {
pSetState(state);
// 4135725 : do not notify on programatic changes
// notifyStateChanged(state);
}
}
private native int getIndicatorSize();
private native int getSpacing();
public Dimension getMinimumSize() {
String lbl = ((Checkbox)target).getLabel();
if (lbl == null) {
lbl = "";
}
FontMetrics fm = getFontMetrics(target.getFont());
/*
* Spacing (number of pixels between check mark and label text) is
* currently set to 0, but in case it ever changes we have to add
* it. 8 is a heuristic number. Indicator size depends on font
* height, so we don't need to include it in checkbox's height
* calculation.
*/
int wdth = fm.stringWidth(lbl) + getIndicatorSize() + getSpacing() + 8;
int hght = Math.max(fm.getHeight() + 8, 15);
return new Dimension(wdth, hght);
}
void notifyStateChanged(boolean state) {
Checkbox cb = (Checkbox) target;
ItemEvent e = new ItemEvent(cb,
ItemEvent.ITEM_STATE_CHANGED,
cb.getLabel(),
state ? ItemEvent.SELECTED : ItemEvent.DESELECTED);
postEvent(e);
}
// NOTE: This method is called by privileged threads.
// DO NOT INVOKE CLIENT CODE ON THIS THREAD!
void action(boolean state) {
final Checkbox cb = (Checkbox)target;
final boolean newState = state;
MToolkit.executeOnEventHandlerThread(cb, new Runnable() {
public void run() {
CheckboxGroup cbg = cb.getCheckboxGroup();
/* Bugid 4039594. If this is the current Checkbox in
* a CheckboxGroup, then return to prevent deselection.
* Otherwise, it's logical state will be turned off,
* but it will appear on.
*/
if ((cbg != null) && (cbg.getSelectedCheckbox() == cb) &&
cb.getState()) {
inUpCall = false;
cb.setState(true);
return;
}
// All clear - set the new state
cb.setState(newState);
notifyStateChanged(newState);
} // run()
});
} // action()
static final int SIZE = 19;
static final int BORDER = 4;
static final int SIZ = SIZE - BORDER*2 - 1;
/*
* Print the native component by rendering the Motif look ourselves.
* ToDo(aim): needs to query native motif for more accurate size and
* color information; need to render check mark.
*/
public void print(Graphics g) {
Checkbox cb = (Checkbox)target;
Dimension d = cb.size();
Color bg = cb.getBackground();
Color fg = cb.getForeground();
Color shadow = bg.darker();
int x = BORDER;
int y = ((d.height - SIZE) / 2) + BORDER;
g.setColor(cb.getState()? shadow : bg);
if (cb.getCheckboxGroup() != null) {
g.fillOval(x, y, SIZ, SIZ);
draw3DOval(g, bg, x, y, SIZ, SIZ, !(cb.getState()));
if (cb.getState()) {
g.setColor(fg);
g.fillOval(x + 3, y + 3, SIZ - 6, SIZ - 6);
}
} else {
g.fillRect(x, y, SIZ, SIZ);
draw3DRect(g, bg, x, y, SIZ, SIZ, !(cb.getState()));
if (cb.getState()) {
g.setColor(fg);
g.drawLine(x+1, y+1, x+SIZ-1, y+SIZ-1);
g.drawLine(x+1, y+SIZ-1, x+SIZ-1, y+1);
}
}
g.setColor(fg);
String lbl = cb.getLabel();
if (lbl != null) {
// REMIND: align
g.setFont(cb.getFont());
FontMetrics fm = g.getFontMetrics();
g.drawString(lbl, SIZE,
(d.height + fm.getMaxAscent() - fm.getMaxDescent()) / 2);
}
target.print(g);
}
/**
* DEPRECATED
*/
public Dimension minimumSize() {
return getMinimumSize();
}
}
/*
* Copyright 1995-2003 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.motif;
import java.awt.*;
import java.awt.peer.*;
import java.awt.event.ItemEvent;
class MChoicePeer extends MComponentPeer implements ChoicePeer {
boolean inUpCall=false;
native void create(MComponentPeer parent);
native void pReshape(int x, int y, int width, int height);
native void pSelect(int index, boolean init);
native void appendItems(String[] items);
void initialize() {
Choice opt = (Choice)target;
int itemCount = opt.countItems();
String[] items = new String[itemCount];
for (int i=0; i < itemCount; i++) {
items[i] = opt.getItem(i);
}
if (itemCount > 0) {
appendItems(items);
pSelect(opt.getSelectedIndex(), true);
}
super.initialize();
}
public MChoicePeer(Choice target) {
super(target);
}
public boolean isFocusable() {
return true;
}
public Dimension getMinimumSize() {
FontMetrics fm = getFontMetrics(target.getFont());
Choice c = (Choice)target;
int w = 0;
for (int i = c.countItems() ; i-- > 0 ;) {
w = Math.max(fm.stringWidth(c.getItem(i)), w);
}
return new Dimension(32 + w, Math.max(fm.getHeight() + 8, 15) + 5);
}
public native void setFont(Font f);
public void add(String item, int index) {
addItem(item, index);
// Adding an item can change the size of the Choice, so do
// a reshape, based on the font size.
Rectangle r = target.getBounds();
reshape(r.x, r.y, 0, 0);
}
public native void remove(int index);
public native void removeAll();
/**
* DEPRECATED, but for now, called by add(String, int).
*/
public native void addItem(String item, int index);
// public native void remove(int index);
public native void setBackground(Color c);
public native void setForeground(Color c);
public void select(int index) {
if (!inUpCall) {
pSelect(index, false);
}
}
void notifySelection(String item) {
Choice c = (Choice)target;
ItemEvent e = new ItemEvent(c, ItemEvent.ITEM_STATE_CHANGED,
item, ItemEvent.SELECTED);
postEvent(e);
}
// NOTE: This method is called by privileged threads.
// DO NOT INVOKE CLIENT CODE ON THIS THREAD!
void action(final int index) {
final Choice c = (Choice)target;
inUpCall = false; /* Used to prevent native selection. */
MToolkit.executeOnEventHandlerThread(c, new Runnable() {
public void run() {
String item;
synchronized(c) {
if (index >= c.getItemCount()) {
/* Nothing to do when the list is too short */
return;
}
inUpCall = true; /* Prevent native selection. */
c.select(index); /* set value in target */
item = c.getItem(index);
inUpCall = false;
}
notifySelection(item);
}
});
}
/*
* Print the native component by rendering the Motif look ourselves.
* ToDo(aim): needs to query native motif for more accurate size and
* color information.
*/
public void print(Graphics g) {
Choice ch = (Choice)target;
Dimension d = ch.size();
Color bg = ch.getBackground();
Color fg = ch.getForeground();
g.setColor(bg);
g.fillRect(2, 2, d.width-1, d.height-1);
draw3DRect(g, bg, 1, 1, d.width-2, d.height-2, true);
draw3DRect(g, bg, d.width - 18, (d.height / 2) - 3, 10, 6, true);
g.setColor(fg);
g.setFont(ch.getFont());
FontMetrics fm = g.getFontMetrics();
String lbl = ch.getSelectedItem();
if (lbl == null){
lbl = "";
}
if (lbl != ""){
g.drawString(lbl, 5, (d.height + fm.getMaxAscent()-fm.getMaxDescent())/2);
}
target.print(g);
}
/**
* DEPRECATED
*/
public Dimension minimumSize() {
return getMinimumSize();
}
protected void disposeImpl() {
freeNativeData();
super.disposeImpl();
}
private native void freeNativeData();
}
/*
* Copyright 2003 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.motif;
import sun.awt.X11CustomCursor;
import sun.awt.CustomCursor;
import java.awt.*;
import java.awt.image.*;
import sun.awt.image.ImageRepresentation;
public class MCustomCursor extends X11CustomCursor {
public MCustomCursor(Image cursor, Point hotSpot, String name)
throws IndexOutOfBoundsException {
super(cursor, hotSpot, name);
}
/**
* Returns the supported cursor size
*/
public static Dimension getBestCursorSize(
int preferredWidth, int preferredHeight) {
// Fix for bug 4212593 The Toolkit.createCustomCursor does not
// check absence of the image of cursor
// We use XQueryBestCursor which accepts unsigned ints to obtain
// the largest cursor size that could be dislpayed
Dimension d = new Dimension(Math.abs(preferredWidth), Math.abs(preferredHeight));
queryBestCursor(d);
return d;
}
private static native void queryBestCursor(Dimension d);
protected native void createCursor(byte[] xorMask, byte[] andMask,
int width, int height,
int fcolor, int bcolor,
int xHotSpot, int yHotSpot);
static {
cacheInit();
}
private native static void cacheInit();
}
/*
* Copyright 1997-2003 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.motif;
import sun.awt.motif.MComponentPeer;
import sun.awt.motif.MInputMethod;
/**
* An interface for controlling containment hierarchy configuration to
* keep track of existence of any TextArea or TextField and to manage
* input method status area.
*
* @auther JavaSoft International
*/
interface MInputMethodControl {
/**
* Informs Frame or Dialog that a text component has been added to
* the hierarchy.
* @param textComponentPeer peer of the text component
*/
void addTextComponent(MComponentPeer textComponentPeer);
/**
* Informs Frame or Dialog that a text component has been removed
* from the hierarchy.
* @param textComponentPeer peer of the text component
*/
void removeTextComponent(MComponentPeer textComponentPeer);
/**
* Returns a text component peer in the containment hierarchy
* to obtain the Motif status area information
*/
MComponentPeer getTextComponent();
/**
* Inform Frame or Dialog that an MInputMethod has been
* constructed so that Frame and Dialog can invoke the method in
* MInputMethod to reconfigure XICs.
* @param inputMethod an MInputMethod instance
*/
void addInputMethod(MInputMethod inputMethod);
/**
* Inform Frame or Dialog that an X11InputMethod is being destroyed.
* @param inputMethod an X11InputMethod instance
*/
void removeInputMethod(MInputMethod inputMethod);
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册