6632140: minor refactoring for XWM
Summary: code cleanup and generificaion for XWM
Reviewed-by: anthony
--- a/jdk/src/solaris/classes/sun/awt/X11/XFramePeer.java Thu Mar 13 16:12:56 2008 +0300
+++ b/jdk/src/solaris/classes/sun/awt/X11/XFramePeer.java Thu Mar 13 16:19:32 2008 +0300
@@ -1,5 +1,5 @@
/*
- * 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");
@@ -285,19 +288,20 @@
* 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) {
--- a/jdk/src/solaris/classes/sun/awt/X11/XNETProtocol.java Thu Mar 13 16:12:56 2008 +0300
+++ b/jdk/src/solaris/classes/sun/awt/X11/XNETProtocol.java Thu Mar 13 16:19:32 2008 +0300
@@ -1,5 +1,5 @@
/*
- * 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 @@
boolean doStateProtocol() {
boolean res = active() && checkProtocol(XA_NET_SUPPORTED, XA_NET_WM_STATE);
+ stateLog.finer("doStateProtocol() returns " + res);
return res;
}
--- a/jdk/src/solaris/classes/sun/awt/X11/XToolkit.java Thu Mar 13 16:12:56 2008 +0300
+++ b/jdk/src/solaris/classes/sun/awt/X11/XToolkit.java Thu Mar 13 16:19:32 2008 +0300
@@ -1,5 +1,5 @@
/*
- * 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.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 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;
}
--- a/jdk/src/solaris/classes/sun/awt/X11/XWM.java Thu Mar 13 16:12:56 2008 +0300
+++ b/jdk/src/solaris/classes/sun/awt/X11/XWM.java Thu Mar 13 16:19:32 2008 +0300
@@ -1,5 +1,5 @@
/*
- * 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 @@
/*****************************************************************************\
* 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 @@
}
/* 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 @@
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 @@
/*
* 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 @@
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);
+ /*
+ * 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 {
+ res = Frame.NORMAL;
}
- if (is_state_change) {
- return Integer.valueOf(res);
- } else {
- return null;
- }
+ res |= getExtendedState(window);
+ return res;
}
/*****************************************************************************\
@@ -1180,9 +1178,7 @@
* 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 @@
}
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 @@
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();