use of java.awt.PopupMenu in project cryptomator by cryptomator.
the class ExitUtil method createTrayIcon.
private TrayIcon createTrayIcon(Runnable exitCommand) {
final PopupMenu popup = new PopupMenu();
final MenuItem showItem = new MenuItem(localization.getString("tray.menu.open"));
showItem.addActionListener(this::restoreFromTray);
popup.add(showItem);
final MenuItem exitItem = new MenuItem(localization.getString("tray.menu.quit"));
exitItem.addActionListener(e -> exitCommand.run());
popup.add(exitItem);
final Image image;
if (SystemUtils.IS_OS_MAC_OSX && isMacMenuBarDarkMode()) {
image = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/tray_icon_mac_white.png"));
} else if (SystemUtils.IS_OS_MAC_OSX) {
image = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/tray_icon_mac_black.png"));
} else {
image = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/tray_icon.png"));
}
return new TrayIcon(image, localization.getString("app.name"), popup);
}
use of java.awt.PopupMenu in project openblocks by mikaelhg.
the class RenderableBlock method mouseReleased.
public void mouseReleased(MouseEvent e) {
if (SwingUtilities.isLeftMouseButton(e)) {
if (pickedUp) {
dragHandler.mouseReleased(e);
//if the block was dragged before...then
if (dragging) {
//look for nearby link opportunities
BlockLink link = getNearbyLink();
WorkspaceWidget widget = null;
// if a suitable link wasn't found, just drop the block
if (link == null) {
widget = lastDragWidget;
stopDragging(this, widget);
} else // otherwise, if a link WAS found...
{
/* Make sure that no matter who's connecting to whom, the block
* that's being dragged gets dropped on the parent widget of the
* block that's already on the canvas.
*/
if (blockID.equals(link.getSocketBlockID())) {
// dragged block is the socket block, so take plug's parent.
widget = workspace.getEnv().getRenderableBlock(link.getPlugBlockID()).getParentWidget();
} else {
// dragged block is the plug block, so take the socket block's parent.
widget = workspace.getEnv().getRenderableBlock(link.getSocketBlockID()).getParentWidget();
}
// drop the block and connect its link
stopDragging(this, widget);
link.connect();
workspace.notifyListeners(new WorkspaceEvent(workspace, widget, link, WorkspaceEvent.BLOCKS_CONNECTED));
workspace.getEnv().getRenderableBlock(link.getSocketBlockID()).moveConnectedBlocks();
}
//set the locations for X and Y based on zoom at 1.0
this.unzoomedX = this.calculateUnzoomedX(this.getX());
this.unzoomedY = this.calculateUnzoomedY(this.getY());
workspace.notifyListeners(new WorkspaceEvent(workspace, widget, link, WorkspaceEvent.BLOCK_MOVED, true));
if (widget instanceof MiniMap) {
workspace.getMiniMap().animateAutoCenter(this);
}
}
}
}
pickedUp = false;
if (e.isPopupTrigger() || SwingUtilities.isRightMouseButton(e) || e.isControlDown()) {
//add context menu at right click location to provide functionality
//for adding new comments and removing comments
PopupMenu popup = ContextMenu.getContextMenuFor(this);
add(popup);
popup.show(this, e.getX(), e.getY());
}
workspace.getMiniMap().repaint();
}
use of java.awt.PopupMenu in project screenbird by adamhub.
the class ScreenRecorder method createTray.
/**
* Sets up the system tray for screenRecorder application
*/
private void createTray() {
PopupMenu menu = new PopupMenu();
MenuItem aboutItem = new MenuItem("About");
aboutItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(jfRecorderPanel, String.format("Screenbird%nBuild Version %s", RecorderPanel.resources.getString("BUILD")));
}
});
menu.add(aboutItem);
// Open the settings menu
MenuItem settingsItem = new MenuItem("Preferences");
settingsItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (jpRecorderPanel.isRecorderConfigSate())
jpRecorderPanel.showSettingsForm();
}
});
menu.add(settingsItem);
// Hide or show the recorder
MenuItem messageItem = new MenuItem("Hide/Show");
messageItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (jfRecorderPanel.getState() == JFrame.NORMAL) {
jfRecorderPanel.setState(JFrame.ICONIFIED);
} else {
jfRecorderPanel.setState(JFrame.NORMAL);
}
}
});
menu.add(messageItem);
MenuItem closeItem = new MenuItem("Quit/Exit");
closeItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
destroy();
}
});
menu.add(closeItem);
// Loads the pastevid logo
Image icon = Toolkit.getDefaultToolkit().getImage(getClass().getResource(ResourceUtil.LOGO_16));
if (!MediaUtil.osIsWindows()) {
icon = Toolkit.getDefaultToolkit().getImage(getClass().getResource(ResourceUtil.LOGO_24));
}
// Assigns the pastevid logo
TrayIcon tray = new TrayIcon(icon, "Screenbird", menu);
try {
SystemTray.getSystemTray().add(tray);
} catch (AWTException ex) {
log(ex);
}
}
use of java.awt.PopupMenu in project otapij by FellowTraveler.
the class MainPage method setToSystray.
private void setToSystray() {
Image image = null;
System.out.println("creating instance");
if (SystemTray.isSupported()) {
System.out.println("system tray supported");
tray = SystemTray.getSystemTray();
ImageIcon image1 = new javax.swing.ImageIcon(getClass().getResource("/com/moneychanger/ui/images/images.jpeg"));
image = image1.getImage();
ActionListener exitListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("Exiting....");
System.exit(0);
}
};
PopupMenu popup = new PopupMenu();
MenuItem defaultItem = new MenuItem("Exit");
defaultItem.addActionListener(exitListener);
popup.add(defaultItem);
defaultItem = new MenuItem("Open");
defaultItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//tray.remove(trayIcon);
setVisible(true);
repaint();
setVisible(true);
System.out.println("Open");
}
});
popup.add(defaultItem);
trayIcon = new TrayIcon(image, "Moneychanger", popup);
trayIcon.setImageAutoSize(true);
} else {
System.out.println("system tray not supported");
}
final String os = System.getProperty("os.name").toLowerCase();
addWindowStateListener(new WindowStateListener() {
@Override
public void windowStateChanged(WindowEvent e) {
System.out.println("-----:" + e.getNewState());
if (e.getNewState() == ICONIFIED) {
try {
tray.add(trayIcon);
if (os.indexOf("nix") < 0 || os.indexOf("nux") < 0) {
setVisible(false);
}
System.out.println("added to SystemTray");
} catch (AWTException ex) {
System.out.println("unable to add to tray");
}
}
if (e.getNewState() == 7) {
try {
tray.add(trayIcon);
if (!(os.indexOf("nix") >= 0 || os.indexOf("nux") >= 0)) {
setVisible(false);
}
System.out.println("added to SystemTray");
} catch (AWTException ex) {
System.out.println("unable to add to system tray");
}
}
if (e.getNewState() == MAXIMIZED_BOTH) {
tray.remove(trayIcon);
setVisible(true);
System.out.println("Max both");
System.out.println("Tray icon removed");
}
if (e.getNewState() == NORMAL) {
tray.remove(trayIcon);
setVisible(true);
System.out.println("Max NORMAL");
System.out.println("Tray icon removed");
}
}
});
// setIconImage(Toolkit.getDefaultToolkit().getImage("Duke256.png"));
if (image != null) {
setIconImage(image);
}
}
Aggregations