test/jdk/java/awt/TrayIcon/UpdatePopupMenu/UpdatePopupMenu.java
author serb
Wed, 21 Feb 2018 12:49:00 -0800
changeset 49096 eaef201ec301
parent 47216 71c04702a3d5
permissions -rw-r--r--
8198333: ProblemList should be updated for headless mode Reviewed-by: psadhukhan, prr
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
49096
eaef201ec301 8198333: ProblemList should be updated for headless mode
serb
parents: 47216
diff changeset
    27
 @key headful
37686
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    28
 @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
    29
 @run main/manual UpdatePopupMenu
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
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    32
import java.awt.SystemTray;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    33
import java.awt.TrayIcon;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    34
import java.awt.PopupMenu;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    35
import java.awt.MenuItem;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    36
import java.awt.Image;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    37
import java.awt.Graphics2D;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    38
import java.awt.Color;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    39
import java.awt.image.BufferedImage;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    40
import java.awt.RenderingHints;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    41
import java.awt.AWTException;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    42
import java.awt.Button;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    43
import java.awt.Frame;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    44
import java.awt.GridBagConstraints;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    45
import java.awt.GridBagLayout;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    46
import java.awt.Panel;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    47
import java.awt.TextArea;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    48
import java.awt.event.ActionEvent;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    49
import java.awt.event.ActionListener;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    50
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    51
public class UpdatePopupMenu implements ActionListener {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    52
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    53
    private static final int imageSize = 32;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    54
    private static final int imageInset = 4;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    55
    private static GridBagLayout layout;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    56
    private static Panel mainControlPanel;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    57
    private static Panel resultButtonPanel;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    58
    private static TextArea instructionTextArea;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    59
    private static Button passButton;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    60
    private static Button failButton;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    61
    private static Frame mainFrame;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    62
    private static Thread mainThread = null;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    63
    private static boolean testPassed = false;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    64
    private static boolean isInterrupted = false;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    65
    private static final int testTimeOut = 300000;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    66
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    67
    private Image createSystemTrayIconImage() {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    68
        final BufferedImage trayImage = new BufferedImage(
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
                imageSize,
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    71
                BufferedImage.TYPE_INT_ARGB);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    72
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    73
        final Graphics2D imageGraphics = (Graphics2D) trayImage.getGraphics();
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    74
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    75
        imageGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    76
                RenderingHints.VALUE_ANTIALIAS_ON);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    77
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    78
        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
    79
        imageGraphics.fillRect(0, 0, trayImage.getWidth(),
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    80
                trayImage.getHeight());
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    81
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    82
        imageGraphics.setColor(Color.green);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    83
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    84
        int imageWidth = trayImage.getWidth() - 2 * imageInset;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    85
        int imageHeight = trayImage.getHeight() - 2 * imageInset;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    86
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    87
        imageGraphics.fillOval(imageInset, imageInset, imageWidth, imageHeight);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    88
        imageGraphics.setColor(Color.darkGray);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    89
        imageGraphics.drawOval(imageInset, imageInset, imageWidth, imageHeight);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    90
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    91
        return trayImage;
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
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    94
    private PopupMenu createPopupMenu(final TrayIcon trayIcon,
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    95
            final int menuCount) {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    96
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    97
        final PopupMenu trayIconPopupMenu = new PopupMenu();
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    98
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
    99
        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
   100
            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
   101
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   102
            popupMenuItem.addActionListener(new ActionListener() {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   103
                @Override
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   104
                public void actionPerformed(final ActionEvent ae) {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   105
                    trayIcon.setPopupMenu(createPopupMenu(trayIcon,
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   106
                            menuCount + 1));
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
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   110
            trayIconPopupMenu.add(popupMenuItem);
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
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   113
        return trayIconPopupMenu;
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
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   116
    private void createSystemTrayIcons() {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   117
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   118
        final TrayIcon trayIcon = new TrayIcon(createSystemTrayIconImage());
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   119
        trayIcon.setImageAutoSize(true);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   120
        trayIcon.setToolTip("Update Popup Menu items");
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   121
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   122
        try {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   123
            trayIcon.setPopupMenu(createPopupMenu(trayIcon, 2));
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   124
            SystemTray.getSystemTray().add(trayIcon);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   125
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   126
        } catch (AWTException ex) {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   127
            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
   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
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   131
    private void createInstructionUI() {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   132
        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
   133
        layout = new GridBagLayout();
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   134
        mainControlPanel = new Panel(layout);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   135
        resultButtonPanel = new Panel(layout);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   136
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   137
        GridBagConstraints gbc = new GridBagConstraints();
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   138
        String instructions
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   139
                = "INSTRUCTIONS:"
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   140
                + "\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
   141
                + "\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
   142
                + "\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
   143
                + "Menu"
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   144
                + "\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
   145
                + "\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
   146
                + "\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
   147
                + "click Pass ";
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   148
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   149
        instructionTextArea = new TextArea();
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   150
        instructionTextArea.setText(instructions);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   151
        instructionTextArea.setEnabled(false);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   152
        instructionTextArea.setBackground(Color.white);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   153
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   154
        gbc.gridx = 0;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   155
        gbc.gridy = 0;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   156
        gbc.fill = GridBagConstraints.HORIZONTAL;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   157
        mainControlPanel.add(instructionTextArea, gbc);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   158
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   159
        passButton = new Button("Pass");
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   160
        passButton.setName("Pass");
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   161
        passButton.addActionListener(this);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   162
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   163
        failButton = new Button("Fail");
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   164
        failButton.setName("Fail");
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   165
        failButton.addActionListener(this);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   166
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   167
        gbc.gridx = 0;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   168
        gbc.gridy = 0;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   169
        resultButtonPanel.add(passButton, gbc);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   170
        gbc.gridx = 1;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   171
        gbc.gridy = 0;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   172
        resultButtonPanel.add(failButton, gbc);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   173
        gbc.gridx = 0;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   174
        gbc.gridy = 1;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   175
        mainControlPanel.add(resultButtonPanel, gbc);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   176
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   177
        mainFrame.add(mainControlPanel);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   178
        mainFrame.pack();
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   179
        mainFrame.setVisible(true);
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
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   182
    @Override
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   183
    public void actionPerformed(ActionEvent ae) {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   184
        if (ae.getSource() instanceof Button) {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   185
            Button btn = (Button) ae.getSource();
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   186
            switch (btn.getName()) {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   187
                case "Pass":
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   188
                    testPassed = true;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   189
                    isInterrupted = true;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   190
                    mainThread.interrupt();
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   191
                    break;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   192
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   193
                case "Fail":
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   194
                    testPassed = false;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   195
                    isInterrupted = true;
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   196
                    mainThread.interrupt();
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   197
                    break;
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
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   202
    private static void cleanUp() {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   203
        mainFrame.dispose();
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
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   206
    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
   207
        if (SystemTray.isSupported()) {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   208
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   209
            UpdatePopupMenu updatePopupMenu = new UpdatePopupMenu();
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   210
            updatePopupMenu.createInstructionUI();
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   211
            updatePopupMenu.createSystemTrayIcons();
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   212
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   213
            mainThread = Thread.currentThread();
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   214
            try {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   215
                mainThread.sleep(testTimeOut);
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   216
            } catch (InterruptedException ex) {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   217
                if (!testPassed) {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   218
                    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
   219
                            + " items FAILED");
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   220
                }
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   221
            } finally {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   222
                cleanUp();
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
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   225
            if (!isInterrupted) {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   226
                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
   227
                        + testTimeOut / 1000 + " seconds");
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
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   230
        } else {
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   231
            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
   232
        }
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   233
    }
1ad88c2dfacd 8147841: [macosx] Updating TrayIcons popup menu does not work on Mac OS X
psadhukhan
parents:
diff changeset
   234
}