public static void createWarning(String message) { if (trayIcon != null) { trayIcon.displayMessage( AgentConstants.APP_PUBLIC_NAME, message, TrayIcon.MessageType.WARNING); } Logger.getLogger(SSHAgent.class.getName()).log(Level.WARNING, message); }
public void actionPerformed(ActionEvent e) { trayIcon.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Message Clicked"); } }); trayIcon.displayMessage(title, message, messageType); }
public static void createError(String message, boolean addLogLinkMessage, Throwable ex) { String message2 = message; if (addLogLinkMessage) { message2 = message .concat("\n") .concat(LocalizedLogger.getLocalizedMessage(AgentConstants.LINK_TO_LOG_KEY)); } if (trayIcon != null) { trayIcon.displayMessage(AgentConstants.APP_PUBLIC_NAME, message2, TrayIcon.MessageType.ERROR); } Logger.getLogger(SSHAgent.class.getName()).log(Level.SEVERE, message, ex); }
private void unloadUI() { try { if (ui == null) { if (T.t) { T.info("Subsystem already unloaded."); } return; } if (tray != null && ti != null) { ti.displayMessage( "", Language.getLocalizedString(getClass(), "unloading"), TrayIcon.MessageType.NONE); balloonClickHandler = null; } core.restartProgram(false); } catch (Exception t) { core.reportError(t, this); } }
public void setTray() { if (SystemTray.isSupported()) { Image icon = Toolkit.getDefaultToolkit().getImage("C:/.hack3rClient/sprites/cursors/icon.png"); trayIcon = new TrayIcon(icon, "Vestige-x"); trayIcon.setImageAutoSize(true); try { SystemTray tray = SystemTray.getSystemTray(); tray.add(trayIcon); trayIcon.displayMessage( "Vestige-x", "Vestige-x has been launched!", TrayIcon.MessageType.INFO); PopupMenu menu = new PopupMenu(); final MenuItem minimizeItem = new MenuItem("Hide Vestige-x"); MenuItem BLANK = new MenuItem("-"); MenuItem exitItem = new MenuItem("Quit"); menu.add(minimizeItem); menu.add(BLANK); menu.add(exitItem); trayIcon.setPopupMenu(menu); ActionListener minimizeListener = new ActionListener() { public void actionPerformed(ActionEvent e) { if (frame.isVisible()) { frame.setVisible(false); minimizeItem.setLabel("Show 1# Vestige-x."); } else { frame.setVisible(true); minimizeItem.setLabel("Hide 1# Vestige-x."); } } }; minimizeItem.addActionListener(minimizeListener); ActionListener exitListener = new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }; exitItem.addActionListener(exitListener); } catch (AWTException e) { System.err.println(e); } } }
/** * Upload an object * * @param upload The upload object */ public void upload(final Upload upload) { // Check associations if (!uploaderAssociations.containsKey(upload.getClass())) { icon.displayMessage( Language.getString("noUploaderTitle"), Language.getString("noUploader", upload.getClass().getName()), TrayIcon.MessageType.ERROR); return; } uploadService.execute( new Runnable() { @Override public void run() { icon.setImage(Resources.ICON_BUSY_IMAGE); executeUpload(upload); icon.setImage(Resources.ICON_IMAGE); } }); }
@Override public void actionPerformed(ActionEvent e) { if (e.getSource().equals(help)) try { Desktop.getDesktop().browse(new URI("http://" + Settings.getHost() + "/syncrop.html")); } catch (IOException | URISyntaxException e1) { logger.logError(e1, "occured when trying to load syncrop.html"); } else if (e.getSource().equals(about)) trayIcon.displayMessage( "Syncrop", "Syncrop is a free online syncronization service hosted on Realm of Pi.", TrayIcon.MessageType.NONE); else if (e.getSource().equals(update)) { if (WindowsUpdator.isUpdateAvailable()) WindowsUpdator.update(); } else if (e.getSource().equals(exit)) { logger.log("User terminated Syncrop from the notification area"); System.exit(0); } }
@Override public synchronized void shutdown() { if (tray != null && ti != null) { ti.displayMessage( "", Language.getLocalizedString(getClass(), "shutting"), TrayIcon.MessageType.NONE); balloonClickHandler = null; } if (ui != null) { ui.shutdown(); ui = null; } if (core != null) { core.shutdown(); core = null; } if (tray != null) { tray.remove(ti); } System.exit(0); }
/** Upload content from the clipboard */ public void clipboard() { try { final Object clipboard = ClipboardUtil.getClipboardContents(); if (clipboard == null) { icon.displayMessage( Language.getString("invalidClipboard"), Language.getString("invalidClipboardTitle"), TrayIcon.MessageType.WARNING); return; } if (clipboard instanceof BufferedImage) { upload(new ImageUpload((BufferedImage) clipboard)); } else if (clipboard instanceof File) { final File file = (File) clipboard; final String mime = FileUtils.getMimeType(file.getAbsolutePath()); // A better way to upload images, it'll check the mime type! if (mime.startsWith("image")) { upload(new ImageUpload(ImageIO.read(file))); } else if (mime.startsWith("text") && configuration.getBoolean("plainTextUpload")) { upload(new TextUpload(FileUtils.readFile(file))); } else { upload(new FileUpload(file)); } } else if (clipboard instanceof String) { final String string = clipboard.toString(); if (string.matches("((mailto\\:|(news|(ht|f)tp(s?))\\://){1}\\S+)")) { upload(new URLUpload(clipboard.toString())); } else { upload(new TextUpload(string)); } } } catch (final ClipboardException e) { logger.log(Level.SEVERE, "Unable to get clipboard contents", e); showException(e); } catch (final IOException e) { e.printStackTrace(); } }
public static void main(String[] args) throws Exception { TrayIcon icon = new TrayIcon(getImage(), "This is a Java Tray Icon", createPopupMenu()); icon.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, "Bring Java to the Desktop app"); } }); SystemTray.getSystemTray().add(icon); while (true) { Thread.sleep(10000); icon.displayMessage("Warning", "Click me! =)", TrayIcon.MessageType.WARNING); } }
public void setTray() { boolean showTip = false; if (tray == null) { showTip = true; final Image image = Configuration.getImage(Configuration.Paths.Resources.ICON); tray = new TrayIcon(image, Configuration.NAME, null); tray.setImageAutoSize(true); tray.addMouseListener( new MouseListener() { public void mouseClicked(MouseEvent arg0) {} public void mouseEntered(MouseEvent arg0) {} public void mouseExited(MouseEvent arg0) {} public void mouseReleased(MouseEvent arg0) {} public void mousePressed(MouseEvent arg0) { SystemTray.getSystemTray().remove(tray); setVisible(true); lessCpu(false); } }); } try { SystemTray.getSystemTray().add(tray); if (showTip) { tray.displayMessage( Configuration.NAME + " Hidden", "Bots are still running in the background.\nClick this icon to restore the window.", MessageType.INFO); } } catch (Exception ignored) { log.warning("Unable to hide window"); } setVisible(false); lessCpu(true); }
/** * Execute an upload * * @param object The object to upload */ @SuppressWarnings({"rawtypes", "unchecked"}) public void executeUpload(Upload object) { // Run the object through the filters if (filters.containsKey(object.getClass())) { for (final UploadFilter filter : filters.get(object.getClass())) { try { object = filter.filter(object); } catch (final FilterException e) { // FilterExceptions when thrown should interrupt the upload. showException(e, e.getErrorMessage()); return; } } } // Then upload it final Uploader uploader = uploaderAssociations.get(object.getClass()); if (uploader != null) { try { String url = uploader.upload(object); if (url != null) { if (configuration.getBoolean("shortenurls")) { final Uploader shortener = uploaderAssociations.get(URL.class); if (shortener != null) { url = shortener.upload(new URLUpload(url)); } } if (object instanceof ImageUpload) { if (configuration.getBoolean("savelocal") && !(uploader instanceof ImageLocalFileUploader)) { final FileOutputStream output = new FileOutputStream(getLocalFile(DateUtil.getCurrentDate() + ".png")); try { ImageIO.write(((ImageUpload) object).getImage(), "png", output); } finally { output.close(); } } ((ImageUpload) object).getImage().flush(); ((ImageUpload) object).setImage(null); } url = url.trim(); retries = 0; ClipboardUtil.setClipboard(url); lastUrl = url; history.addEntry(new HistoryEntry(url, uploader.getName())); icon.displayMessage( Language.getString("uploadComplete"), Language.getString("uploadedTo", url), TrayIcon.MessageType.INFO); logger.info("Upload completed, url: " + url); } else { icon.displayMessage( Language.getString("uploadFailed"), Language.getString("uploadFailedError"), TrayIcon.MessageType.ERROR); logger.severe("Upload failed to execute due to an unknown error"); } } catch (final UploaderConfigurationException e) { icon.displayMessage( Language.getString("uploaderConfigError"), Language.getString("uploaderConfigErrorMessage"), TrayIcon.MessageType.ERROR); logger.log(Level.SEVERE, "Upload failed to execute", e); } catch (final Exception e) { // Retry until retries > max final StringBuilder msg = new StringBuilder("The upload failed to execute: "); msg.append(e.getMessage()); final int max = configuration.getInteger("max_retries", Constants.Configuration.DEFAULT_MAX_RETRIES); if (retries++ < max) { logger.info("Retrying upload (" + retries + " of " + max + " retries)..."); msg.append("\nRetrying..."); upload(object); } else { msg.append("\nReached retry limit, upload aborted."); logger.log(Level.SEVERE, "Upload failed to execute, retries: " + retries, e); retries = 0; } icon.displayMessage( Language.getString("uploadFailed"), msg.toString(), TrayIcon.MessageType.ERROR); } } }
/** * Show a TrayIcon message for an exception * * @param e The exception */ public void showException(final Exception e, final String errorMessage) { icon.displayMessage( Language.getString("error"), Language.getString("exceptionCauseWithMessage", errorMessage, e.getMessage()), MessageType.ERROR); }
public void addNotification(String message) { trayIcon.displayMessage("Syncrop", message, TrayIcon.MessageType.INFO); }
@Override public void notification() { tray_icon.displayMessage(definition.name, definition.text, TrayIcon.MessageType.INFO); }
private void init() { final TrayIcon trayIcon; if (SystemTray.isSupported()) { String path = System.getProperty("user.dir"); // log.info(path); SystemTray tray = SystemTray.getSystemTray(); MouseListener mouseListener = new MouseListener() { public void mouseClicked(MouseEvent e) { System.out.println("Tray Icon - Mouse clicked!"); } public void mouseEntered(MouseEvent e) { System.out.println("Tray Icon - Mouse entered!"); } public void mouseExited(MouseEvent e) { System.out.println("Tray Icon - Mouse exited!"); } public void mousePressed(MouseEvent e) { System.out.println("Tray Icon - Mouse pressed!"); } public void mouseReleased(MouseEvent e) { System.out.println("Tray Icon - Mouse released!"); } }; ActionListener exitListener = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Exiting..."); System.exit(0); } }; ActionListener testListener = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Just test..."); System.exit(0); } }; PopupMenu popup = new PopupMenu(); MenuItem defaultItem = new MenuItem("Exit"); defaultItem.addActionListener(exitListener); popup.add(defaultItem); MenuItem defaultItem2 = new MenuItem("test"); defaultItem.addActionListener(testListener); popup.add(defaultItem2); Image image = Toolkit.getDefaultToolkit() .getImage(this.getClass().getClassLoader().getResource("ico.gif")); trayIcon = new TrayIcon(image, "chimera", popup); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent e) { trayIcon.displayMessage( "Action Event", "An Action Event Has Been Peformed!", TrayIcon.MessageType.INFO); } }; trayIcon.setImageAutoSize(true); trayIcon.addActionListener(actionListener); trayIcon.addMouseListener(mouseListener); // Depending on which Mustang build you have, you may need to uncomment // out the following code to check for an AWTException when you add // an image to the system tray. // try { try { tray.add(trayIcon); } catch (AWTException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } // } catch (AWTException e) { // System.err.println("TrayIcon could not be added."); // } trayIcon.displayMessage("chimera", "", TrayIcon.MessageType.INFO); } else { System.err.println("System tray is currently not supported."); } }