Skip to content

Commit

Permalink
Improvement for Mac OS X. Both the tray menu and the main window were…
Browse files Browse the repository at this point in the history
… being shown at the same time when the user clicked on the tray icon. All tray menu items were moved from the tray menu to the context menu button of the main window. The tray menu no longer exists.
  • Loading branch information
ccidral committed Nov 18, 2012
1 parent 1849284 commit 51555da
Show file tree
Hide file tree
Showing 11 changed files with 220 additions and 238 deletions.
Expand Up @@ -37,7 +37,6 @@
import org.tomighty.ui.swing.gauge.Gauge;
import org.tomighty.ui.theme.Look;
import org.tomighty.ui.tray.*;
import org.tomighty.ui.tray.menu.DefaultTrayMenu;

import static com.google.inject.Scopes.SINGLETON;

Expand All @@ -50,7 +49,6 @@ protected void configure() {

bind(Tray.class).to(AwtTray.class).in(SINGLETON);
bind(TrayManager.class).in(SINGLETON);
bind(TrayMenu.class).to(DefaultTrayMenu.class).in(SINGLETON);
bind(Window.class).in(SINGLETON);
bind(Gauge.class).in(SINGLETON);
bind(Options.class).in(SINGLETON);
Expand Down
13 changes: 13 additions & 0 deletions tomighty-swing/src/main/java/org/tomighty/ui/menu/Exit.java
@@ -0,0 +1,13 @@
package org.tomighty.ui.menu;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Exit implements ActionListener {

@Override
public void actionPerformed(ActionEvent actionEvent) {
System.exit(0);
}

}
@@ -0,0 +1,31 @@
package org.tomighty.ui.menu;

import org.tomighty.ui.swing.laf.SexyArrowButtonUI;

import javax.inject.Inject;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MenuButtonFactory {

@Inject
private PopupMenuFactory popupMenuFactory;

@Inject
private SexyArrowButtonUI arrowButtonUI;

public JButton create(Action[] actions) {
final JPopupMenu menu = popupMenuFactory.create(actions);
final JButton button = new JButton();
button.setUI(arrowButtonUI);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
menu.show(button, 0, button.getHeight());
}
});
return button;
}

}
@@ -0,0 +1,42 @@
package org.tomighty.ui.menu;

import com.google.inject.Injector;
import org.tomighty.i18n.Messages;

import javax.inject.Inject;
import javax.swing.*;
import java.awt.event.ActionListener;

public class PopupMenuFactory {

@Inject private Injector injector;
@Inject private Messages messages;

public JPopupMenu create(Action[] items) {
JPopupMenu menu = new JPopupMenu();

if(items != null && items.length > 0) {
for(Action action : items) {
injector.injectMembers(action);
JMenuItem item = new JMenuItem(action);
menu.add(item);
}

menu.addSeparator();
}

menu.add(menuItem("Options", injector.getInstance(ShowOptions.class)));
menu.add(menuItem("About", injector.getInstance(ShowAboutWindow.class)));
menu.addSeparator();
menu.add(menuItem("Close", new Exit()));

return menu;
}

private JMenuItem menuItem(String text, ActionListener listener) {
JMenuItem item = new JMenuItem(messages.get(text));
item.addActionListener(listener);
return item;
}

}
@@ -1,4 +1,4 @@
package org.tomighty.ui.tray.menu;
package org.tomighty.ui.menu;

import com.google.inject.Injector;
import org.tomighty.ui.about.AboutDialog;
Expand All @@ -7,13 +7,13 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

class ShowAboutWindow implements ActionListener {
public class ShowAboutWindow implements ActionListener {

@Inject
private Injector injector;

@Override
public void actionPerformed(ActionEvent e) {
public void actionPerformed(ActionEvent actionEvent) {
AboutDialog about = injector.getInstance(AboutDialog.class);
about.showDialog();
}
Expand Down
@@ -1,4 +1,4 @@
package org.tomighty.ui.tray.menu;
package org.tomighty.ui.menu;

import com.google.inject.Injector;
import org.tomighty.ui.options.OptionsDialog;
Expand All @@ -7,13 +7,13 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

class ShowOptions implements ActionListener {
public class ShowOptions implements ActionListener {

@Inject
private Injector injector;

@Override
public void actionPerformed(ActionEvent e) {
public void actionPerformed(ActionEvent actionEvent) {
OptionsDialog dialog = injector.getInstance(OptionsDialog.class);
dialog.showDialog();
}
Expand Down

0 comments on commit 51555da

Please sign in to comment.