test/java/awt/TrayIcon/DragEventSource/DragEventSource.java

Print this page


   1 /*
   2  * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  47     static Frame frame = new Frame("Test frame");
  48     static Button b1 = new Button("Open file dialog");
  49     static SystemTray tray = null;
  50     static TrayIcon icon = null;
  51     static Image img = null;
  52     static FileDialog fd = null;
  53 
  54     //a method to transfer throwables to the user
  55     public void handle(Throwable e){
  56         Sysout.println("HANDLED BY THE CUSTOM HANDLER !!!!!!"+e);
  57     }
  58 
  59     static class ActionHandler implements ActionListener {
  60         public void actionPerformed (ActionEvent ae) {
  61             FileDialog fd = new FileDialog (frame, "Image Selector", FileDialog.LOAD);
  62             fd.setVisible(true);
  63         }
  64     }
  65 
  66     private static void init() {















  67         String[] instructions =
  68         {
  69             "Use see a Frame with a button in it.",
  70             "Press the button. FileDialog should appear.",
  71             "Drag the mouse from the Tray icon to FileDialog ",
  72             "using left mouse button.",
  73             "If exception happens, the test fails.",
  74             "Otherwise, pass."
  75         };
  76 
  77         Sysout.createDialog( );
  78         Sysout.printInstructions( instructions );
  79 
  80         frame.setLayout(new FlowLayout());
  81         tray = SystemTray.getSystemTray();
  82         boolean isSupported = tray.isSupported();
  83         System.out.println("is SysTray Supported: " + isSupported);
  84         TrayIcon icons[] = tray.getTrayIcons();
  85         System.out.println(icons.length);
  86 
  87         b1.addActionListener(new ActionHandler());
  88 
  89         icon = new TrayIcon(new BufferedImage(20, 20, BufferedImage.TYPE_INT_RGB));
  90         icon.setImageAutoSize(true);
  91 
  92         try {
  93             tray.add(icon);
  94         } catch (Exception e) {
  95             e.printStackTrace();
  96         }
  97 
  98         frame.add(b1);
  99 
 100         frame.setSize(600, 200);
 101         frame.setVisible(true);
 102     }//End  init()
 103 


   1 /*
   2  * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  47     static Frame frame = new Frame("Test frame");
  48     static Button b1 = new Button("Open file dialog");
  49     static SystemTray tray = null;
  50     static TrayIcon icon = null;
  51     static Image img = null;
  52     static FileDialog fd = null;
  53 
  54     //a method to transfer throwables to the user
  55     public void handle(Throwable e){
  56         Sysout.println("HANDLED BY THE CUSTOM HANDLER !!!!!!"+e);
  57     }
  58 
  59     static class ActionHandler implements ActionListener {
  60         public void actionPerformed (ActionEvent ae) {
  61             FileDialog fd = new FileDialog (frame, "Image Selector", FileDialog.LOAD);
  62             fd.setVisible(true);
  63         }
  64     }
  65 
  66     private static void init() {
  67 
  68         boolean isSupported = tray.isSupported();
  69         System.out.println("is SysTray Supported: " + isSupported);
  70 
  71         if (!isSupported) {
  72             String[] instructions =
  73             {
  74               "The test cannot be run because SystemTray is not supported.",
  75               "Simply press PASS button."
  76             };
  77             Sysout.createDialog( );
  78             Sysout.printInstructions( instructions );
  79             return;
  80         }
  81 
  82         String[] instructions =
  83         {
  84             "Use see a Frame with a button in it.",
  85             "Press the button. FileDialog should appear.",
  86             "Drag the mouse from the Tray icon to FileDialog ",
  87             "using left mouse button.",
  88             "If exception happens, the test fails.",
  89             "Otherwise, pass."
  90         };
  91 
  92         Sysout.createDialog( );
  93         Sysout.printInstructions( instructions );
  94 
  95         frame.setLayout(new FlowLayout());
  96         tray = SystemTray.getSystemTray();
  97 
  98 
  99         TrayIcon icons[] = tray.getTrayIcons();
 100         System.out.println(icons.length);
 101 
 102         b1.addActionListener(new ActionHandler());
 103 
 104         icon = new TrayIcon(new BufferedImage(20, 20, BufferedImage.TYPE_INT_RGB));
 105         icon.setImageAutoSize(true);
 106 
 107         try {
 108             tray.add(icon);
 109         } catch (Exception e) {
 110             e.printStackTrace();
 111         }
 112 
 113         frame.add(b1);
 114 
 115         frame.setSize(600, 200);
 116         frame.setVisible(true);
 117     }//End  init()
 118