From 7b0264f63ec38256a9714dcb00349ebf352b252d Mon Sep 17 00:00:00 2001 From: son Date: Thu, 13 Mar 2008 17:08:15 +0300 Subject: [PATCH] 6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont Summary: unnedded code has been removed. Added getter for XWindow.defaultFont to initialize it lazily. Reviewed-by: dav --- .../classes/sun/awt/X11/XComponentPeer.java | 11 ++-------- .../classes/sun/awt/X11/XMenuItemPeer.java | 6 +++--- .../classes/sun/awt/X11/XPopupMenuPeer.java | 6 +++--- .../classes/sun/awt/X11/XTrayIconPeer.java | 7 ++----- src/solaris/classes/sun/awt/X11/XWindow.java | 20 +++++++++++-------- .../classes/sun/awt/X11/XWindowPeer.java | 10 ++-------- 6 files changed, 24 insertions(+), 36 deletions(-) diff --git a/src/solaris/classes/sun/awt/X11/XComponentPeer.java b/src/solaris/classes/sun/awt/X11/XComponentPeer.java index 4657f75c4..fb687e368 100644 --- a/src/solaris/classes/sun/awt/X11/XComponentPeer.java +++ b/src/solaris/classes/sun/awt/X11/XComponentPeer.java @@ -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 @@ -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; } diff --git a/src/solaris/classes/sun/awt/X11/XMenuItemPeer.java b/src/solaris/classes/sun/awt/X11/XMenuItemPeer.java index c679dbecd..ec80cebce 100644 --- a/src/solaris/classes/sun/awt/X11/XMenuItemPeer.java +++ b/src/solaris/classes/sun/awt/X11/XMenuItemPeer.java @@ -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 @@ -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() { diff --git a/src/solaris/classes/sun/awt/X11/XPopupMenuPeer.java b/src/solaris/classes/sun/awt/X11/XPopupMenuPeer.java index 8523bd7ff..55fcfb574 100644 --- a/src/solaris/classes/sun/awt/X11/XPopupMenuPeer.java +++ b/src/solaris/classes/sun/awt/X11/XPopupMenuPeer.java @@ -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 @@ -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() { diff --git a/src/solaris/classes/sun/awt/X11/XTrayIconPeer.java b/src/solaris/classes/sun/awt/X11/XTrayIconPeer.java index c9b9a1abf..5c8ccd029 100644 --- a/src/solaris/classes/sun/awt/X11/XTrayIconPeer.java +++ b/src/solaris/classes/sun/awt/X11/XTrayIconPeer.java @@ -1,5 +1,5 @@ /* - * 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); diff --git a/src/solaris/classes/sun/awt/X11/XWindow.java b/src/solaris/classes/sun/awt/X11/XWindow.java index 9e3c877fa..2d55ef889 100644 --- a/src/solaris/classes/sun/awt/X11/XWindow.java +++ b/src/solaris/classes/sun/awt/X11/XWindow.java @@ -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 @@ -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; diff --git a/src/solaris/classes/sun/awt/X11/XWindowPeer.java b/src/solaris/classes/sun/awt/X11/XWindowPeer.java index 18ccbcba8..c69e8f3a2 100644 --- a/src/solaris/classes/sun/awt/X11/XWindowPeer.java +++ b/src/solaris/classes/sun/awt/X11/XWindowPeer.java @@ -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 @@ -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. -- GitLab