jdk/src/solaris/classes/sun/awt/X11/XAWTXSettings.java
author mchung
Tue, 29 Sep 2009 16:03:03 -0700
changeset 3938 ef327bd847c0
parent 2802 d05a9dcc8296
child 5506 202f599c92aa
permissions -rw-r--r--
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes Summary: Replace calls to Logger with sun.util.logging.PlatformLogger Reviewed-by: prr, art, alexp, dcherepanov, igor, dav, anthony
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
     2
 * Copyright 2003-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
   * This code is ported to XAWT from MAWT based on awt_mgrsel.c
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
   * and XSettings.java code written originally by Valeriy Ushakov
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
   * Author : Bino George
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.awt.XSettings;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
    38
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
class XAWTXSettings extends XSettings implements XMSelectionListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private final XAtom xSettingsPropertyAtom = XAtom.get("_XSETTINGS_SETTINGS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
    45
    private static PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XAWTXSettings");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    /* The maximal length of the property data. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    public static final long MAX_LENGTH = 1000000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    XMSelection settings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    public XAWTXSettings() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        initXSettings();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    void initXSettings() {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
    58
        if (log.isLoggable(PlatformLogger.FINE)) log.fine("Initializing XAWT XSettings");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        settings = new XMSelection("_XSETTINGS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        settings.addSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        initPerScreenXSettings();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        settings.removeSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public void ownerDeath(int screen, XMSelection sel, long deadOwner) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
    69
        if (log.isLoggable(PlatformLogger.FINE)) log.fine("Owner " + deadOwner + " died for selection " + sel + " screen "+ screen);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public void ownerChanged(int screen, XMSelection sel, long newOwner, long data, long timestamp) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
    74
        if (log.isLoggable(PlatformLogger.FINE)) log.fine("New Owner "+ newOwner + " for selection = " + sel + " screen " +screen );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public void selectionChanged(int screen, XMSelection sel, long owner , XPropertyEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        log.fine("Selection changed on sel " + sel + " screen = " + screen + " owner = " + owner + " event = " + event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        updateXSettings(screen,owner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    void initPerScreenXSettings() {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
    83
        if (log.isLoggable(PlatformLogger.FINE)) log.fine("Updating Per XSettings changes");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
         * As toolkit cannot yet cope with per-screen desktop properties,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
         * only report XSETTINGS changes on the default screen.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
         * should be "good enough" for most cases.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        Map updatedSettings = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            long display = XToolkit.getDisplay();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            int screen = (int) XlibWrapper.DefaultScreen(display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            updatedSettings = getUpdatedSettings(settings.getOwner(screen));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        // we must not  invoke this under Awt Lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        ((XToolkit)Toolkit.getDefaultToolkit()).parseXSettings(0,updatedSettings);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private void updateXSettings(int screen, long owner) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        final Map updatedSettings = getUpdatedSettings(owner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        // this method is called under awt lock and usually on toolkit thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        // but parseXSettings() causes public code execution, so we need to transfer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        // this to EDT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        EventQueue.invokeLater( new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                ((XToolkit) Toolkit.getDefaultToolkit()).parseXSettings( 0, updatedSettings);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    private Map getUpdatedSettings(final long owner) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
   117
        if (log.isLoggable(PlatformLogger.FINE)) log.fine("owner =" + owner);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        if (0 == owner) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        Map settings = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            WindowPropertyGetter getter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                new WindowPropertyGetter(owner, xSettingsPropertyAtom, 0, MAX_LENGTH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                        false, xSettingsPropertyAtom.getAtom() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            try {
2802
d05a9dcc8296 6678385: Random java.lang.StackOverflowError from various JDKs
art
parents: 439
diff changeset
   128
                int status = getter.execute(XErrorHandler.IgnoreBadWindowHandler.getInstance());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   130
                if (status != XConstants.Success || getter.getData() == 0) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
   131
                    if (log.isLoggable(PlatformLogger.FINE)) log.fine("OH OH : getter failed  status = " + status );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                    settings = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                long ptr = getter.getData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
   137
                if (log.isLoggable(PlatformLogger.FINE)) log.fine("noItems = " + getter.getNumberOfItems());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                byte array[] = Native.toBytes(ptr,getter.getNumberOfItems());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                if (array != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                    settings = update(array);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                getter.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        return settings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
}