jdk/test/java/awt/TrayIcon/UpdatePopupMenu/UpdatePopupMenu.java
author psadhukhan
Wed, 13 Apr 2016 17:04:02 +0530
changeset 37686 1ad88c2dfacd
permissions -rw-r--r--
8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X Reviewed-by: serb, ssadetsky
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37686
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
     1
/*
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
     4
 *
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
     7
 * published by the Free Software Foundation.
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
     8
 *
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    13
 * accompanied this code).
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    14
 *
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    18
 *
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    21
 * questions.
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    22
 */
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    23
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    24
/*
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    25
 @test
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    26
 @bug 8147841
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    27
 @summary Updating Tray Icon popup menu does not update menu items on Mac OS X
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    28
 @run main/manual UpdatePopupMenu
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    29
 */
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    30
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    31
import java.awt.SystemTray;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    32
import java.awt.TrayIcon;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    33
import java.awt.PopupMenu;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    34
import java.awt.MenuItem;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    35
import java.awt.Image;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    36
import java.awt.Graphics2D;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    37
import java.awt.Color;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    38
import java.awt.image.BufferedImage;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    39
import java.awt.RenderingHints;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    40
import java.awt.AWTException;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    41
import java.awt.Button;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    42
import java.awt.Frame;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    43
import java.awt.GridBagConstraints;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    44
import java.awt.GridBagLayout;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    45
import java.awt.Panel;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    46
import java.awt.TextArea;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    47
import java.awt.event.ActionEvent;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    48
import java.awt.event.ActionListener;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    49
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    50
public class UpdatePopupMenu implements ActionListener {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    51
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    52
    private static final int imageSize = 32;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    53
    private static final int imageInset = 4;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    54
    private static GridBagLayout layout;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    55
    private static Panel mainControlPanel;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    56
    private static Panel resultButtonPanel;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    57
    private static TextArea instructionTextArea;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    58
    private static Button passButton;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    59
    private static Button failButton;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    60
    private static Frame mainFrame;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    61
    private static Thread mainThread = null;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    62
    private static boolean testPassed = false;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    63
    private static boolean isInterrupted = false;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    64
    private static final int testTimeOut = 300000;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    65
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    66
    private Image createSystemTrayIconImage() {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    67
        final BufferedImage trayImage = new BufferedImage(
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    68
                imageSize,
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    69
                imageSize,
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    70
                BufferedImage.TYPE_INT_ARGB);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    71
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    72
        final Graphics2D imageGraphics = (Graphics2D) trayImage.getGraphics();
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    73
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    74
        imageGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    75
                RenderingHints.VALUE_ANTIALIAS_ON);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    76
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    77
        imageGraphics.setColor(new Color(255, 255, 255, 0));
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    78
        imageGraphics.fillRect(0, 0, trayImage.getWidth(),
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    79
                trayImage.getHeight());
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    80
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    81
        imageGraphics.setColor(Color.green);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    82
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    83
        int imageWidth = trayImage.getWidth() - 2 * imageInset;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    84
        int imageHeight = trayImage.getHeight() - 2 * imageInset;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    85
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    86
        imageGraphics.fillOval(imageInset, imageInset, imageWidth, imageHeight);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    87
        imageGraphics.setColor(Color.darkGray);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    88
        imageGraphics.drawOval(imageInset, imageInset, imageWidth, imageHeight);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    89
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    90
        return trayImage;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    91
    }
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    92
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    93
    private PopupMenu createPopupMenu(final TrayIcon trayIcon,
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    94
            final int menuCount) {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    95
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    96
        final PopupMenu trayIconPopupMenu = new PopupMenu();
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    97
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    98
        for (int i = 1; i <= menuCount; ++i) {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    99
            final MenuItem popupMenuItem = new MenuItem("MenuItem_" + i);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   100
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   101
            popupMenuItem.addActionListener(new ActionListener() {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   102
                @Override
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   103
                public void actionPerformed(final ActionEvent ae) {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   104
                    trayIcon.setPopupMenu(createPopupMenu(trayIcon,
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   105
                            menuCount + 1));
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   106
                }
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   107
            });
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   108
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   109
            trayIconPopupMenu.add(popupMenuItem);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   110
        }
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   111
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   112
        return trayIconPopupMenu;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   113
    }
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   114
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   115
    private void createSystemTrayIcons() {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   116
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   117
        final TrayIcon trayIcon = new TrayIcon(createSystemTrayIconImage());
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   118
        trayIcon.setImageAutoSize(true);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   119
        trayIcon.setToolTip("Update Popup Menu items");
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   120
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   121
        try {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   122
            trayIcon.setPopupMenu(createPopupMenu(trayIcon, 2));
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   123
            SystemTray.getSystemTray().add(trayIcon);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   124
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   125
        } catch (AWTException ex) {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   126
            throw new RuntimeException("System Tray cration failed");
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   127
        }
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   128
    }
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   129
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   130
    private void createInstructionUI() {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   131
        mainFrame = new Frame("Updating TrayIcon Popup Menu Item Test");
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   132
        layout = new GridBagLayout();
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   133
        mainControlPanel = new Panel(layout);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   134
        resultButtonPanel = new Panel(layout);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   135
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   136
        GridBagConstraints gbc = new GridBagConstraints();
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   137
        String instructions
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   138
                = "INSTRUCTIONS:"
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   139
                + "\n   1. Click on the System Tray Icon"
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   140
                + "\n   2. Click on any of the displayed Menu items"
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   141
                + "\n   3. Repeat step 1 and count the number of items in the "
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   142
                + "Menu"
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   143
                + "\n   4. The number of items in the Menu should increase by 1"
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   144
                + "\n   5. Repeating steps 1, 2 and 3 should not break 4th step"
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   145
                + "\n   6. Click Fail if the 4th step is broken, Otherwise "
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   146
                + "click Pass ";
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   147
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   148
        instructionTextArea = new TextArea();
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   149
        instructionTextArea.setText(instructions);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   150
        instructionTextArea.setEnabled(false);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   151
        instructionTextArea.setBackground(Color.white);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   152
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   153
        gbc.gridx = 0;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   154
        gbc.gridy = 0;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   155
        gbc.fill = GridBagConstraints.HORIZONTAL;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   156
        mainControlPanel.add(instructionTextArea, gbc);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   157
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   158
        passButton = new Button("Pass");
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   159
        passButton.setName("Pass");
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   160
        passButton.addActionListener(this);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   161
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   162
        failButton = new Button("Fail");
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   163
        failButton.setName("Fail");
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   164
        failButton.addActionListener(this);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   165
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   166
        gbc.gridx = 0;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   167
        gbc.gridy = 0;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   168
        resultButtonPanel.add(passButton, gbc);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   169
        gbc.gridx = 1;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   170
        gbc.gridy = 0;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   171
        resultButtonPanel.add(failButton, gbc);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   172
        gbc.gridx = 0;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   173
        gbc.gridy = 1;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   174
        mainControlPanel.add(resultButtonPanel, gbc);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   175
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   176
        mainFrame.add(mainControlPanel);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   177
        mainFrame.pack();
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   178
        mainFrame.setVisible(true);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   179
    }
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   180
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   181
    @Override
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   182
    public void actionPerformed(ActionEvent ae) {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   183
        if (ae.getSource() instanceof Button) {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   184
            Button btn = (Button) ae.getSource();
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   185
            switch (btn.getName()) {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   186
                case "Pass":
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   187
                    testPassed = true;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   188
                    isInterrupted = true;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   189
                    mainThread.interrupt();
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   190
                    break;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   191
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   192
                case "Fail":
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   193
                    testPassed = false;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   194
                    isInterrupted = true;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   195
                    mainThread.interrupt();
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   196
                    break;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   197
            }
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   198
        }
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   199
    }
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   200
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   201
    private static void cleanUp() {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   202
        mainFrame.dispose();
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   203
    }
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   204
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   205
    public static void main(final String[] args) throws Exception {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   206
        if (SystemTray.isSupported()) {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   207
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   208
            UpdatePopupMenu updatePopupMenu = new UpdatePopupMenu();
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   209
            updatePopupMenu.createInstructionUI();
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   210
            updatePopupMenu.createSystemTrayIcons();
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   211
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   212
            mainThread = Thread.currentThread();
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   213
            try {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   214
                mainThread.sleep(testTimeOut);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   215
            } catch (InterruptedException ex) {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   216
                if (!testPassed) {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   217
                    throw new RuntimeException("Updating TrayIcon popup menu"
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   218
                            + " items FAILED");
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   219
                }
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   220
            } finally {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   221
                cleanUp();
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   222
            }
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   223
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   224
            if (!isInterrupted) {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   225
                throw new RuntimeException("Test Timed out after "
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   226
                        + testTimeOut / 1000 + " seconds");
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   227
            }
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   228
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   229
        } else {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   230
            System.out.println("System Tray is not supported on this platform");
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   231
        }
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   232
    }
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   233
}