src/java.desktop/unix/classes/sun/awt/X11/XTrayIconPeer.java
author prr
Thu, 01 Nov 2018 13:56:14 -0700
changeset 52535 45a5c4d812d9
parent 47216 71c04702a3d5
permissions -rw-r--r--
8213213: Remove src/java.desktop/unix/classes/sun/awt/X11/keysym2ucs.h Reviewed-by: serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 28231
diff changeset
     2
 * Copyright (c) 2005, 2015, Oracle and/or its affiliates. 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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4371
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4371
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4371
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4371
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4371
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.peer.TrayIconPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import sun.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.image.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.lang.reflect.InvocationTargetException;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2472
diff changeset
    36
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 439
diff changeset
    38
public class XTrayIconPeer implements TrayIconPeer,
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 439
diff changeset
    39
       InfoWindow.Balloon.LiveArguments,
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 439
diff changeset
    40
       InfoWindow.Tooltip.LiveArguments
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 439
diff changeset
    41
{
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2472
diff changeset
    42
    private static final PlatformLogger ctrLog = PlatformLogger.getLogger("sun.awt.X11.XTrayIconPeer.centering");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    TrayIcon target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    TrayIconEventProxy eventProxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    XTrayIconEmbeddedFrame eframe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    TrayIconCanvas canvas;
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 439
diff changeset
    48
    InfoWindow.Balloon balloon;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 439
diff changeset
    49
    InfoWindow.Tooltip tooltip;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    PopupMenu popup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    String tooltipString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    boolean isTrayIconDisplayed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    long eframeParentID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    final XEventDispatcher parentXED, eframeXED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    static final XEventDispatcher dummyXED = new XEventDispatcher() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            public void dispatchEvent(XEvent ev) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    volatile boolean isDisposed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    boolean isParentWindowLocated;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    int old_x, old_y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    int ex_width, ex_height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30469
diff changeset
    66
    static final int TRAY_ICON_WIDTH = 24;
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30469
diff changeset
    67
    static final int TRAY_ICON_HEIGHT = 24;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    XTrayIconPeer(TrayIcon target)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
      throws AWTException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        this.target = target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        eventProxy = new TrayIconEventProxy(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        canvas = new TrayIconCanvas(target, TRAY_ICON_WIDTH, TRAY_ICON_HEIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        eframe = new XTrayIconEmbeddedFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        eframe.setSize(TRAY_ICON_WIDTH, TRAY_ICON_HEIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        eframe.add(canvas);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        // Fix for 6317038: as EmbeddedFrame is instance of Frame, it is blocked
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        // by modal dialogs, but in the case of TrayIcon it shouldn't. So we
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        // set ModalExclusion property on it.
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23647
diff changeset
    86
        AccessController.doPrivileged(new PrivilegedAction<Object>() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                eframe.setModalExclusionType(Dialog.ModalExclusionType.TOOLKIT_EXCLUDE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        if (XWM.getWMID() != XWM.METACITY_WM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            parentXED = dummyXED; // We don't like to leave it 'null'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            parentXED = new XEventDispatcher() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                // It's executed under AWTLock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                public void dispatchEvent(XEvent ev) {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 431
diff changeset
   100
                    if (isDisposed() || ev.get_type() != XConstants.ConfigureNotify) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                    XConfigureEvent ce = ev.get_xconfigure();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   106
                    if (ctrLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 9002
diff changeset
   107
                        ctrLog.fine("ConfigureNotify on parent of {0}: {1}x{2}+{3}+{4} (old: {5}+{6})",
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2472
diff changeset
   108
                                XTrayIconPeer.this, ce.get_width(), ce.get_height(),
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2472
diff changeset
   109
                                ce.get_x(), ce.get_y(), old_x, old_y);
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 9002
diff changeset
   110
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                    // A workaround for Gnome/Metacity (it doesn't affect the behaviour on KDE).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                    // On Metacity the EmbeddedFrame's parent window bounds are larger
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                    // than TrayIcon size required (that is we need a square but a rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                    // is provided by the Panel Notification Area). The parent's background color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                    // differs from the Panel's one. To hide the background we resize parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                    // window so that it fits the EmbeddedFrame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                    // However due to resizing the parent window it loses centering in the Panel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                    // We center it when discovering that some of its side is of size greater
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                    // than the fixed value. Centering is being done by "X" (when the parent's width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                    // is greater) and by "Y" (when the parent's height is greater).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                    // Actually we need this workaround until we could detect taskbar color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                    if (ce.get_height() != TRAY_ICON_HEIGHT && ce.get_width() != TRAY_ICON_WIDTH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                        // If both the height and the width differ from the fixed size then WM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                        // must level at least one side to the fixed size. For some reason it may take
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                        // a few hops (even after reparenting) and we have to skip the intermediate ones.
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   130
                        if (ctrLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 9002
diff changeset
   131
                            ctrLog.fine("ConfigureNotify on parent of {0}. Skipping as intermediate resizing.",
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2472
diff changeset
   132
                                    XTrayIconPeer.this);
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 9002
diff changeset
   133
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                    } else if (ce.get_height() > TRAY_ICON_HEIGHT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   138
                        if (ctrLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 9002
diff changeset
   139
                            ctrLog.fine("ConfigureNotify on parent of {0}. Centering by \"Y\".",
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2472
diff changeset
   140
                                    XTrayIconPeer.this);
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 9002
diff changeset
   141
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                        XlibWrapper.XMoveResizeWindow(XToolkit.getDisplay(), eframeParentID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                                                      ce.get_x(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                                                      ce.get_y()+ce.get_height()/2-TRAY_ICON_HEIGHT/2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                                                      TRAY_ICON_WIDTH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                                                      TRAY_ICON_HEIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                        ex_height = ce.get_height();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                        ex_width = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                    } else if (ce.get_width() > TRAY_ICON_WIDTH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   153
                        if (ctrLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 9002
diff changeset
   154
                            ctrLog.fine("ConfigureNotify on parent of {0}. Centering by \"X\".",
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2472
diff changeset
   155
                                    XTrayIconPeer.this);
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 9002
diff changeset
   156
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                        XlibWrapper.XMoveResizeWindow(XToolkit.getDisplay(), eframeParentID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                                                      ce.get_x()+ce.get_width()/2 - TRAY_ICON_WIDTH/2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                                                      ce.get_y(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                                                      TRAY_ICON_WIDTH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                                                      TRAY_ICON_HEIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                        ex_width = ce.get_width();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                        ex_height = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                    } else if (isParentWindowLocated && ce.get_x() != old_x && ce.get_y() != old_y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                        // If moving by both "X" and "Y".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                        // When some tray icon gets removed from the tray, a Java icon may be repositioned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                        // In this case the parent window also lose centering. We have to restore it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                        if (ex_height != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   173
                            if (ctrLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 9002
diff changeset
   174
                                ctrLog.fine("ConfigureNotify on parent of {0}. Move detected. Centering by \"Y\".",
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2472
diff changeset
   175
                                        XTrayIconPeer.this);
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 9002
diff changeset
   176
                            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                            XlibWrapper.XMoveWindow(XToolkit.getDisplay(), eframeParentID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                                                    ce.get_x(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                                                    ce.get_y() + ex_height/2 - TRAY_ICON_HEIGHT/2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                        } else if (ex_width != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   184
                            if (ctrLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 9002
diff changeset
   185
                                ctrLog.fine("ConfigureNotify on parent of {0}. Move detected. Centering by \"X\".",
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2472
diff changeset
   186
                                        XTrayIconPeer.this);
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 9002
diff changeset
   187
                            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                            XlibWrapper.XMoveWindow(XToolkit.getDisplay(), eframeParentID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                                                    ce.get_x() + ex_width/2 - TRAY_ICON_WIDTH/2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                                                    ce.get_y());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                        } else {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   193
                            if (ctrLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 9002
diff changeset
   194
                                ctrLog.fine("ConfigureNotify on parent of {0}. Move detected. Skipping.",
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2472
diff changeset
   195
                                        XTrayIconPeer.this);
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 9002
diff changeset
   196
                            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                    old_x = ce.get_x();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                    old_y = ce.get_y();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                    isParentWindowLocated = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        eframeXED = new XEventDispatcher() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                // It's executed under AWTLock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                XTrayIconPeer xtiPeer = XTrayIconPeer.this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                public void dispatchEvent(XEvent ev) {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 431
diff changeset
   210
                    if (isDisposed() || ev.get_type() != XConstants.ReparentNotify) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                    XReparentEvent re = ev.get_xreparent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                    eframeParentID = re.get_parent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                    if (eframeParentID == XToolkit.getDefaultRootWindow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                        if (isTrayIconDisplayed) { // most likely Notification Area was removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                            SunToolkit.executeOnEventHandlerThread(xtiPeer.target, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                                    public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                                        SystemTray.getSystemTray().remove(xtiPeer.target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                                });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                    if (!isTrayIconDisplayed) {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 431
diff changeset
   230
                        addXED(eframeParentID, parentXED, XConstants.StructureNotifyMask);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                        isTrayIconDisplayed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                        XToolkit.awtLockNotifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 431
diff changeset
   238
        addXED(getWindow(), eframeXED, XConstants.StructureNotifyMask);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        XSystemTrayPeer.getPeerInstance().addTrayIcon(this); // throws AWTException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        // Wait till the EmbeddedFrame is reparented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        long start = System.currentTimeMillis();
9002
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
   244
        final long PERIOD = XToolkit.getTrayIconDisplayTimeout();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            while (!isTrayIconDisplayed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                    XToolkit.awtLockWait(PERIOD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                if (System.currentTimeMillis() - start > PERIOD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        // This is unlikely to happen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        if (!isTrayIconDisplayed || eframeParentID == 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            eframeParentID == XToolkit.getDefaultRootWindow())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            throw new AWTException("TrayIcon couldn't be displayed.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        eframe.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        updateImage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 439
diff changeset
   271
        balloon = new InfoWindow.Balloon(eframe, target, this);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 439
diff changeset
   272
        tooltip = new InfoWindow.Tooltip(eframe, target, this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        addListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        if (SunToolkit.isDispatchThreadForAppContext(target)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            disposeOnEDT();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                SunToolkit.executeOnEDTAndWait(target, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                            disposeOnEDT();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                    });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            } catch (InterruptedException ie) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            } catch (InvocationTargetException ite) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    private void disposeOnEDT() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        // All actions that is to be synchronized with disposal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        // should be executed either under AWTLock, or on EDT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        // isDisposed value must be checked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        isDisposed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        removeXED(getWindow(), eframeXED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        removeXED(eframeParentID, parentXED);
40425
5f77c9f08911 8039081: [TEST_BUG] Test java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java fails
arapte
parents: 38402
diff changeset
   302
        removeListeners();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        eframe.realDispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        balloon.dispose();
40425
5f77c9f08911 8039081: [TEST_BUG] Test java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java fails
arapte
parents: 38402
diff changeset
   305
        tooltip.dispose();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        isTrayIconDisplayed = false;
40425
5f77c9f08911 8039081: [TEST_BUG] Test java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java fails
arapte
parents: 38402
diff changeset
   307
        canvas.dispose();
5f77c9f08911 8039081: [TEST_BUG] Test java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java fails
arapte
parents: 38402
diff changeset
   308
        canvas = null;
5f77c9f08911 8039081: [TEST_BUG] Test java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java fails
arapte
parents: 38402
diff changeset
   309
        popup = null;
5f77c9f08911 8039081: [TEST_BUG] Test java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java fails
arapte
parents: 38402
diff changeset
   310
        balloon = null;
5f77c9f08911 8039081: [TEST_BUG] Test java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java fails
arapte
parents: 38402
diff changeset
   311
        tooltip = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        XToolkit.targetDisposedPeer(target, this);
40425
5f77c9f08911 8039081: [TEST_BUG] Test java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java fails
arapte
parents: 38402
diff changeset
   313
        target = null;
5f77c9f08911 8039081: [TEST_BUG] Test java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java fails
arapte
parents: 38402
diff changeset
   314
        eframe = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    public static void suppressWarningString(Window w) {
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4366
diff changeset
   318
        AWTAccessor.getWindowAccessor().setTrayIconWindow(w, true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    public void setToolTip(String tooltip) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        tooltipString = tooltip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 439
diff changeset
   325
    public String getTooltipString() {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 439
diff changeset
   326
        return tooltipString;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 439
diff changeset
   327
    }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 439
diff changeset
   328
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    public void updateImage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        Runnable r = new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                    canvas.updateImage(target.getImage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        if (!SunToolkit.isDispatchThreadForAppContext(target)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            SunToolkit.executeOnEventHandlerThread(target, r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            r.run();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    public void displayMessage(String caption, String text, String messageType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        Point loc = getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        Rectangle screen = eframe.getGraphicsConfiguration().getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        // Check if the tray icon is in the bounds of a screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        if (!(loc.x < screen.x || loc.x >= screen.x + screen.width ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
              loc.y < screen.y || loc.y >= screen.y + screen.height))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            balloon.display(caption, text, messageType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    // It's synchronized with disposal by EDT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    public void showPopupMenu(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        if (isDisposed())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        assert SunToolkit.isDispatchThreadForAppContext(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        PopupMenu newPopup = target.getPopupMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        if (popup != newPopup) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            if (popup != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                eframe.remove(popup);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            if (newPopup != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                eframe.add(newPopup);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            popup = newPopup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        if (popup != null) {
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 28231
diff changeset
   374
            final XBaseWindow peer = AWTAccessor.getComponentAccessor()
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 28231
diff changeset
   375
                                                .getPeer(eframe);
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 28231
diff changeset
   376
            Point loc = peer.toLocal(new Point(x, y));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            popup.show(eframe, loc.x, loc.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    // ******************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    // ******************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    private void addXED(long window, XEventDispatcher xed, long mask) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        if (window == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            XlibWrapper.XSelectInput(XToolkit.getDisplay(), window, mask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        XToolkit.addEventDispatcher(window, xed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    private void removeXED(long window, XEventDispatcher xed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        if (window == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            XToolkit.removeEventDispatcher(window, xed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    // Private method for testing purposes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    private Point getLocationOnScreen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        return eframe.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 439
diff changeset
   416
    public Rectangle getBounds() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        Point loc = getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        return new Rectangle(loc.x, loc.y, loc.x + TRAY_ICON_WIDTH, loc.y + TRAY_ICON_HEIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    void addListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        canvas.addMouseListener(eventProxy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        canvas.addMouseMotionListener(eventProxy);
34788
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 32865
diff changeset
   424
        eframe.addMouseListener(eventProxy);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
40425
5f77c9f08911 8039081: [TEST_BUG] Test java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java fails
arapte
parents: 38402
diff changeset
   427
    void removeListeners() {
5f77c9f08911 8039081: [TEST_BUG] Test java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java fails
arapte
parents: 38402
diff changeset
   428
        canvas.removeMouseListener(eventProxy);
5f77c9f08911 8039081: [TEST_BUG] Test java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java fails
arapte
parents: 38402
diff changeset
   429
        canvas.removeMouseMotionListener(eventProxy);
5f77c9f08911 8039081: [TEST_BUG] Test java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java fails
arapte
parents: 38402
diff changeset
   430
        eframe.removeMouseListener(eventProxy);
5f77c9f08911 8039081: [TEST_BUG] Test java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java fails
arapte
parents: 38402
diff changeset
   431
    }
5f77c9f08911 8039081: [TEST_BUG] Test java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java fails
arapte
parents: 38402
diff changeset
   432
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    long getWindow() {
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 28231
diff changeset
   434
        return AWTAccessor.getComponentAccessor()
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 28231
diff changeset
   435
                          .<XEmbeddedFramePeer>getPeer(eframe).getWindow();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 439
diff changeset
   438
    public boolean isDisposed() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        return isDisposed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 439
diff changeset
   442
    public String getActionCommand() {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 439
diff changeset
   443
        return target.getActionCommand();
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 439
diff changeset
   444
    }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 439
diff changeset
   445
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    static class TrayIconEventProxy implements MouseListener, MouseMotionListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        XTrayIconPeer xtiPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        TrayIconEventProxy(XTrayIconPeer xtiPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            this.xtiPeer = xtiPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        public void handleEvent(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            //prevent DRAG events from being posted with TrayIcon source(CR 6565779)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            if (e.getID() == MouseEvent.MOUSE_DRAGGED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            // Event handling is synchronized with disposal by EDT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            if (xtiPeer.isDisposed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            Point coord = XBaseWindow.toOtherWindow(xtiPeer.getWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                                                    XToolkit.getDefaultRootWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                                                    e.getX(), e.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            if (e.isPopupTrigger()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                xtiPeer.showPopupMenu(coord.x, coord.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            e.translatePoint(coord.x - e.getX(), coord.y - e.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            // This is a hack in order to set non-Component source to MouseEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            // instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            // In some cases this could lead to unpredictable result (e.g. when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            // other class tries to cast source field to Component).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            // We already filter DRAG events out (CR 6565779).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            e.setSource(xtiPeer.target);
20144
f998f8dc5b40 7188071: closed/java/awt/TrayIcon/TrayIconSecurity/GrantedTrayIconTest fails
leonidr
parents: 18178
diff changeset
   478
            XToolkit.postEvent(XToolkit.targetToAppContext(e.getSource()), e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        }
43722
25ba19c20260 8143077: Deprecate InputEvent._MASK in favor of InputEvent._DOWN_MASK
serb
parents: 40425
diff changeset
   480
        @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        public void mouseClicked(MouseEvent e) {
38402
8f8ed520c078 6384991: TrayIcon ActionListener called at wrong time
arapte
parents: 34788
diff changeset
   482
            if ((e.getClickCount() == 1 || xtiPeer.balloon.isVisible()) &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                e.getButton() == MouseEvent.BUTTON1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                ActionEvent aev = new ActionEvent(xtiPeer.target, ActionEvent.ACTION_PERFORMED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                                                  xtiPeer.target.getActionCommand(), e.getWhen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                                                  e.getModifiers());
6826
1fc6a05552f2 6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents: 5506
diff changeset
   488
                XToolkit.postEvent(XToolkit.targetToAppContext(aev.getSource()), aev);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            if (xtiPeer.balloon.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                xtiPeer.balloon.hide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            handleEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        public void mouseEntered(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            xtiPeer.tooltip.enter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            handleEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        public void mouseExited(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            xtiPeer.tooltip.exit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            handleEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        public void mousePressed(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            handleEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        public void mouseReleased(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            handleEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        public void mouseDragged(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            handleEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        public void mouseMoved(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            handleEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    // ***************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    // Special embedded frame for tray icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    // ***************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
23647
41d22f2dbeb5 8033712: Fix more serial lint warnings in sun.awt
darcy
parents: 20144
diff changeset
   521
    @SuppressWarnings("serial") // JDK-implementation class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    private static class XTrayIconEmbeddedFrame extends XEmbeddedFrame {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        public XTrayIconEmbeddedFrame(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            super(XToolkit.getDefaultRootWindow(), true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        public boolean isUndecorated() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        public boolean isResizable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        // embedded frame for tray icon shouldn't be disposed by anyone except tray icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        public void dispose(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        public void realDispose(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            super.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    // ***************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    // Classes for painting an image on canvas
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    // ***************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
23647
41d22f2dbeb5 8033712: Fix more serial lint warnings in sun.awt
darcy
parents: 20144
diff changeset
   548
    @SuppressWarnings("serial") // JDK-implementation class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    static class TrayIconCanvas extends IconCanvas {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        TrayIcon target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        boolean autosize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        TrayIconCanvas(TrayIcon target, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            super(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            this.target = target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        // Invoke on EDT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        protected void repaintImage(boolean doClear) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            boolean old_autosize = autosize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            autosize = target.isImageAutoSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            curW = autosize ? width : image.getWidth(observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            curH = autosize ? height : image.getHeight(observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            super.repaintImage(doClear || (old_autosize != autosize));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        }
40425
5f77c9f08911 8039081: [TEST_BUG] Test java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java fails
arapte
parents: 38402
diff changeset
   568
5f77c9f08911 8039081: [TEST_BUG] Test java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java fails
arapte
parents: 38402
diff changeset
   569
        public void dispose() {
5f77c9f08911 8039081: [TEST_BUG] Test java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java fails
arapte
parents: 38402
diff changeset
   570
            super.dispose();
5f77c9f08911 8039081: [TEST_BUG] Test java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java fails
arapte
parents: 38402
diff changeset
   571
            target = null;
5f77c9f08911 8039081: [TEST_BUG] Test java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java fails
arapte
parents: 38402
diff changeset
   572
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
23647
41d22f2dbeb5 8033712: Fix more serial lint warnings in sun.awt
darcy
parents: 20144
diff changeset
   575
    @SuppressWarnings("serial") // JDK-implementation class
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 439
diff changeset
   576
    public static class IconCanvas extends Canvas {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        volatile Image image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        IconObserver observer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        int width, height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        int curW, curH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        IconCanvas(int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            this.width = curW = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            this.height = curH = height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        // Invoke on EDT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        public void updateImage(Image image) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            this.image = image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            if (observer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                observer = new IconObserver();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            repaintImage(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
40425
5f77c9f08911 8039081: [TEST_BUG] Test java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java fails
arapte
parents: 38402
diff changeset
   596
        public void dispose() {
5f77c9f08911 8039081: [TEST_BUG] Test java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java fails
arapte
parents: 38402
diff changeset
   597
            observer = null;
5f77c9f08911 8039081: [TEST_BUG] Test java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java fails
arapte
parents: 38402
diff changeset
   598
        }
5f77c9f08911 8039081: [TEST_BUG] Test java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java fails
arapte
parents: 38402
diff changeset
   599
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        // Invoke on EDT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        protected void repaintImage(boolean doClear) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            Graphics g = getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            if (g != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                    if (isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                        if (doClear) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                            update(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                            paint(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                    g.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        // Invoke on EDT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            if (g != null && curW > 0 && curH > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                BufferedImage bufImage = new BufferedImage(curW, curH, BufferedImage.TYPE_INT_ARGB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                Graphics2D gr = bufImage.createGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                if (gr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                        gr.setColor(getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                        gr.fillRect(0, 0, curW, curH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                        gr.drawImage(image, 0, 0, curW, curH, observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                        gr.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                        g.drawImage(bufImage, 0, 0, curW, curH, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                    } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                        gr.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        class IconObserver implements ImageObserver {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            public boolean imageUpdate(final Image image, final int flags, int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                if (image != IconCanvas.this.image || // if the image has been changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                    !IconCanvas.this.isVisible())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                if ((flags & (ImageObserver.FRAMEBITS | ImageObserver.ALLBITS |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                              ImageObserver.WIDTH | ImageObserver.HEIGHT)) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                    SunToolkit.executeOnEventHandlerThread(IconCanvas.this, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                            public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                                repaintImage(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                return (flags & ImageObserver.ALLBITS) == 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
}