Package java.awt

Examples of java.awt.SystemTray


        this.setVisible(false);
        //Verificamos que se soporta TrayIcon en el sistema
        if (SystemTray.isSupported()) {
            System.out.println("Soporte");
            //Recuperamos la barra de trays del sistema
            SystemTray tray = SystemTray.getSystemTray();
            //Se construye la imagen que se va a usar
            ImageIcon imagen1 = new ImageIcon(getClass().getResource("/images/travel-logo.png").getFile());
            Image imagen = imagen1.getImage();
            //El popup que despliega nuestra app
            PopupMenu popup = new PopupMenu();
            //Se agregan los items a nuestra app
            MenuItem item1 = new MenuItem("Exit");
            MenuItem item2 = new MenuItem("Acerca de...");
            MenuItem item3 = new MenuItem("Ayuda");
            //Añadimos los items al popup
            popup.add(item3);
            popup.addSeparator();
            popup.add(item2);
            popup.addSeparator();
            popup.add(item1);
            //Agragamos los eventos
            item1.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    // TODO Auto-generated method stub
                    System.exit(0);
                }
            });
            item2.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    //si todavia no esta creado lo creamos
                    if (aboutUS == null) {
                        aboutUS = new AcercaDeNosotros(null, true);
                        aboutUS.setLocationRelativeTo(null);
                    }
                    aboutUS.setVisible(true);
                }
            });
            //Agragamos los eventos
            item3.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    // TODO Auto-generated method stub
                    try {
                        String fileName = "C:/Program Files/ayuda/AIRResources/AIRResources.exe";
                        File file = new File(fileName);
                        desktop.open(file);
                    } catch (IOException ex) {
                        System.out.println("No se puede abrir el archivo de ayuda");
                        Logger.getLogger(VentanaPrincipal.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            });
            //Construimos el TrayIcon con la imagen y el popup previamente definidos
            trayIcon = new TrayIcon(imagen, "AgenteTuristico", popup);
            trayIcon.setImageAutoSize(true);
            trayIcon.addMouseListener(new MouseListener() {

                @Override
                public void mouseReleased(MouseEvent arg0) {
                    trayIcon.displayMessage("Informacion", "Aplicacion modo normal", TrayIcon.MessageType.INFO);
                }

                @Override
                public void mousePressed(MouseEvent arg0) {
                    // TODO Auto-generated method stub
                    //setVisible(true);
                    //toFront();
                }

                @Override
                public void mouseExited(MouseEvent arg0) {
                    // TODO Auto-generated method stub
                }

                @Override
                public void mouseEntered(MouseEvent arg0) {
                    trayIcon.displayMessage("Informacion", "La aplicación continuara ejcutandose en modo desatendido", TrayIcon.MessageType.INFO);
                }

                @Override
                public void mouseClicked(MouseEvent arg0) {
                    // TODO Auto-generated method stub
                    setVisible(true);
                    toFront();
                }
            });
            try {
                if (!creadoBar) {
                    tray.add(trayIcon);
                    creadoBar = true;
                }
                trayIcon.displayMessage("Informacion", "La aplicación continuara ejcutandose en modo desatendido", TrayIcon.MessageType.INFO);

            } catch (AWTException e) {
View Full Code Here


  public static void main(String[] args) {

    TrayIcon trayIcon = null;
    if (SystemTray.isSupported()) {
      // get the SystemTray instance
      SystemTray tray = SystemTray.getSystemTray();
      // load an image
      Image image = ((ImageIcon) IconFactory.getIconBig("report-80x80.png")).getImage();
      trayIcon = new TrayIcon(image, "Time Reporting", new TrayPopupMenu());
      try {
        tray.add(trayIcon);
      } catch (AWTException e) {
        System.err.println(e);
      }
    } else {
      JOptionPane.showMessageDialog(null, "Tray Icon Not Supported", "Tray Icon Not Supported", JOptionPane.WARNING_MESSAGE);
View Full Code Here

  public final boolean init(final Frame parentFrame) {

    if (!SystemTray.isSupported())
      return false;

    final SystemTray tray = SystemTray.getSystemTray();

    Image icon = parentFrame.getIconImage();
    if(icon == null)
      icon = new BufferedImage(64,64, BufferedImage.TYPE_INT_RGB);

    // create a popup menu
    final ActionListener exitJalk = new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        if(parentFrame != null) {
          parentFrame.dispose();
        }
      }
    };
    popup = new PopupMenu();
    final MenuItem exitItem = new MenuItem("Exit");
    exitItem.addActionListener(exitJalk);
    popup.add(exitItem);

    // construct the TrayIcon
    final ActionListener restoreParentFrame = new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        if(parentFrame != null) {
          parentFrame.setVisible(true);
          parentFrame.setState(Frame.NORMAL);
          parentFrame.toFront();
        }
      }
    };
    trayIcon = new TrayIcon(icon, "Jalk", popup);
    trayIcon.addActionListener(restoreParentFrame);
    try {
      tray.add(trayIcon);
      trayIconAvailable = true;
    } catch (final AWTException e) {
      System.err.println(e);
      return false;
    }
View Full Code Here

    return trayIconAvailable;
  }

  public final void exit() {
    if(trayIcon != null && SystemTray.isSupported()) {
      final SystemTray tray = SystemTray.getSystemTray();
      tray.remove(trayIcon);
      trayIcon = null;
    }
  }
View Full Code Here

            // If System Tray has already been initialized
            if(trayIcon!=null) {
                return (isEnabled = true);
            }

            SystemTray systemTray = SystemTray.getSystemTray();

            Image iconImage = IconManager.getIcon(IconManager.MUCOMMANDER_ICON_SET, TRAY_ICON_NAME).getImage();
            Dimension trayIconSize = systemTray.getTrayIconSize();
            // If the sytem tray icon size is larger than the icon size, center the icon as the default is to display
            // the icon in the top left corner which is plain ugly
            if(trayIconSize.width>TRAY_ICON_WIDTH || trayIconSize.height>TRAY_ICON_HEIGHT) {
                // The buffered image uses ARGB for transparency
                BufferedImage bi = new BufferedImage(trayIconSize.width, trayIconSize.height, BufferedImage.TYPE_INT_ARGB);
                bi.getGraphics().drawImage(iconImage, (trayIconSize.width-TRAY_ICON_WIDTH)/2, (trayIconSize.height-TRAY_ICON_HEIGHT)/2, null);
                iconImage = bi;
            }

            // Create the tray icon and disable image auto-size which shouldn't be used anyway but just in case
            trayIcon = new TrayIcon(iconImage);
            trayIcon.setImageAutoSize(false);

            // Create the popup (AWT!) menu. Note there is no way with java.awt.Menu to know when the menu is selected
            // and thus it makes it hard to have contextual menu items such as the list of open windows.
            PopupMenu menu = new PopupMenu();
            addMenuItem(menu, NewWindowAction.Descriptor.ACTION_ID);
            addMenuItem(menu, BringAllToFrontAction.Descriptor.ACTION_ID);
            menu.addSeparator();
            addMenuItem(menu, QuitAction.Descriptor.ACTION_ID);

            trayIcon.setPopupMenu(menu);

            // Add the tray icon to the system tray. If an exception is caught, clean things up and leave this notifier
            // disabled.
            try {
                systemTray.add(trayIcon);
                // Tray icon was added OK, listen to action events
                trayIcon.addActionListener(this);

                return (isEnabled = true);
            }
View Full Code Here

    }

    public void createSystemTray() {

        if (SystemTray.isSupported()) {
            SystemTray tray = SystemTray.getSystemTray();
            Image createImage = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/de/chucknorris/client/images/chuck_norris.png"));
            trayIcon = new TrayIcon(createImage, "Chuck Norris Citations", createPopupMenu());
            trayIcon.setImageAutoSize(true);
            trayIcon.addActionListener(this);
            trayIcon.setActionCommand(Constants.CITATION);

            try {
                tray.add(trayIcon);
            } catch (AWTException e) {
                LOGGER.error("TrayIcon could not be added.", e);
            }
        } else{
            JOptionPane.showMessageDialog(null,
View Full Code Here

        if (SystemTray.isSupported()) {
            // allow proper shutdown
            System.setProperty("org.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES","false");


            SystemTray tray = SystemTray.getSystemTray();

            // create menu
            PopupMenu popup = new PopupMenu();


            //MenuItem mainPage = createMenuItem("Start Page", "http://"+getServerName()+":"+getServerPort()+"/");
            //popup.add(mainPage);

            popup.addSeparator();


            // launch browser action
            MenuItem admin = createMenuItem("Administration","http://"+getServerName()+":"+getServerPort()+"/");
            popup.add(admin);

            // admin links

            for(final Map.Entry<String,String> linkEntry : adminLinks.entrySet()) {
                MenuItem entry = createMenuItem(linkEntry.getKey(),linkEntry.getValue());
                popup.add(entry);
            }

            // shutdown action
            MenuItem shutdown = new MenuItem("Shutdown");
            try {
                Class.forName("org.apache.catalina.mbeans.MBeanUtils");
                ActionListener stopListener = new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        performServerShutdown();
                    }
                };
                shutdown.addActionListener(stopListener);
            } catch (ClassNotFoundException e) {
                shutdown.setEnabled(false);
            }
            popup.add(shutdown);

            popup.addSeparator();

            for(final Map.Entry<String,String> linkEntry : demoLinks.entrySet()) {
                boolean containsEntry = false;
                for(int i = 0; i < popup.getItemCount(); i++) {
                    MenuItem item = popup.getItem(i);
                    if(item.getLabel().equals(linkEntry.getKey())) {
                        containsEntry = true;
                        break;
                    }
                }

                if(!containsEntry) {
                    MenuItem entry = createMenuItem(linkEntry.getKey(),linkEntry.getValue());
                    popup.add(entry);
                }
            }

            popup.addSeparator();

            MenuItem about = new MenuItem("About");
            about.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    TaskDialogs.inform(null,
                            "About Apache Marmotta \n",
                            "(c)2013 The Apache Software Foundation \n" +
                            "Visit http://marmotta.apache.org for further details");
                }
            });
            popup.add(about);

            MenuItem issues = createMenuItem("Issues Reports", "https://issues.apache.org/jira/browse/MARMOTTA");
            popup.add(issues);

            MenuItem homepage = createMenuItem("Project Homepage", "http://marmotta.apache.org");
            popup.add(homepage);


            // load icon image
            try {
                Image image = ImageIO.read(SystrayListener.class.getResource("systray.png"));
                icon = new TrayIcon(image,"Apache Marmotta",popup);
                icon.setImageAutoSize(true);
                tray.add(icon);

            } catch (IOException e) {
                log.error("SYSTRAY: could not load the logo for system tray",e);
            } catch (AWTException e) {
                log.error("SYSTRAY: tray icon could not be added");
View Full Code Here

            Mediator.getLogger(DaemonManager.class.getName()).log(Level.INFO, "SystemTray is not supported");
            return;
        }
        final PopupMenu popup = new PopupMenu();
        final TrayIcon trayIcon = new TrayIcon(Toolkit.getDefaultToolkit().getImage("tray.gif"), "OECSM", popup);//new TrayIcon(createImage("images/bulb.gif", "tray icon"));
        final SystemTray tray = SystemTray.getSystemTray();

        MenuItem showItem = new MenuItem("Show");
        MenuItem hideItem = new MenuItem("Hide");
        MenuItem exitItem = new MenuItem("Exit");

        showItem.addActionListener(showListener);
        hideItem.addActionListener(hideListener);
        exitItem.addActionListener(exitListener);

        popup.add(showItem);
        popup.addSeparator();
        popup.add(hideItem);
        popup.addSeparator();
        popup.add(exitItem);

        trayIcon.setPopupMenu(popup);

        try {
            tray.add(trayIcon);
        } catch (AWTException ex) {
            Mediator.getLogger(DaemonManager.class.getName()).log(Level.INFO, null, ex);
        }
    }
View Full Code Here

            baseImage = createImage("/plate.png");
        } else {
            this.baseImage = icon.getImage();
        }
        this.appName = appName;
        SystemTray tray = SystemTray.getSystemTray();
        if (!SystemTray.isSupported()) {
            throw new RuntimeException("Tray is not supported");
        }
        trayIcon = new TrayIcon(baseImage, appName);
        final PopupMenu popup = createMenu(popupItems);
        trayIcon.setPopupMenu(popup);
        trayIcon.addMouseListener(new MouseListener() {

            @Override
            public void mouseClicked(MouseEvent e) {
                    if (MouseEvent.BUTTON3 == e.getButton()) return;
                    try {
                        Robot robot = new Robot();
                        // RIGHT CLICK
                        robot.mousePress(InputEvent.BUTTON3_MASK);
                        robot.mouseRelease(InputEvent.BUTTON3_MASK);
                    } catch (Exception exe) {
                        System.out.println("error=" + exe);
                    }
            }

            @Override
            public void mousePressed(MouseEvent e) {
              
            }

            @Override
            public void mouseReleased(MouseEvent e) {
              
            }

            @Override
            public void mouseEntered(MouseEvent e) {
               
            }

            @Override
            public void mouseExited(MouseEvent e) {
               
            }
        });

        try {
            tray.add(trayIcon);
            registerEvents();
        } catch (AWTException e) {
            throw new RuntimeException("Cant start tray");
        }
View Full Code Here

        });

        EventBus.subscribeStrongly(ExitApplicationMessage.class, new EventSubscriber<ExitApplicationMessage>() {
            @Override
            public void onEvent(ExitApplicationMessage t) {
                SystemTray tray = SystemTray.getSystemTray();
                tray.remove(trayIcon);
            }
        });
        EventBus.subscribeStrongly(AddMenuItemEvent.class, new EventSubscriber<AddMenuItemEvent>() {
            @Override
            public void onEvent(AddMenuItemEvent t) {
View Full Code Here

TOP

Related Classes of java.awt.SystemTray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.