Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvement for Mac OS X. Both the tray menu and the main window were…
… 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
Showing
11 changed files
with
220 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
tomighty-swing/src/main/java/org/tomighty/ui/menu/Exit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
tomighty-swing/src/main/java/org/tomighty/ui/menu/MenuButtonFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
tomighty-swing/src/main/java/org/tomighty/ui/menu/PopupMenuFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.