Skip to content

Commit

Permalink
Add nicer method to JMenuItemBuilder.
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Holmes committed Jan 20, 2015
1 parent cb2a8d4 commit bd87450
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,20 @@ private void initChannelMenu() {
join = JMenuItemBuilder.create()
.setText("Join Channel...")
.setMnemonic('j')
.addActionListener(e -> joinChannel())
.addActionMethod(this::joinChannel)
.build();
add(join);

csd = JMenuItemBuilder.create()
.setMnemonic('c')
.setText("Channel Settings")
.addActionListener(l -> showChannelSettings()).build();
.addActionMethod(this::showChannelSettings).build();
add(csd);

list = JMenuItemBuilder.create()
.setText("List channels...")
.setMnemonic('l')
.addActionListener(e -> channelListDialogProvider.displayOrRequestFocus())
.build();
.addActionMethod(channelListDialogProvider::displayOrRequestFocus).build();
add(list);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,16 @@ private void initHelpMenu() {
add(JMenuItemBuilder.create()
.setMnemonic('j')
.setText("Join Dev channel")
.addActionListener(e -> connectionManager.joinDevChat())
.addActionMethod(connectionManager::joinDevChat)
.build());
add(JMenuItemBuilder.create().setMnemonic('f')
.setText("Send Feedback")
.addActionListener(e -> feedbackDialogProvider.displayOrRequestFocus())
.build());
.addActionMethod(feedbackDialogProvider::displayOrRequestFocus).build());
if (!Apple.isAppleUI()) {
add(JMenuItemBuilder.create()
.setMnemonic('a')
.setText("About")
.addActionListener(e -> aboutDialogProvider.displayOrRequestFocus())
.build());
.addActionMethod(aboutDialogProvider::displayOrRequestFocus).build());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public JMenuItemBuilder addActionListener(final ActionListener listener) {
return this;
}

public JMenuItemBuilder addActionMethod(final Runnable runnable) {
menuItem.addActionListener(e -> runnable.run());
return this;
}

public JMenuItem build() {
return menuItem;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ private void initServerMenu() {
add(JMenuItemBuilder.create()
.setText("New Server...")
.setMnemonic('n')
.addActionListener(e -> newServerProvider.displayOrRequestFocus())
.addActionMethod(newServerProvider::displayOrRequestFocus)
.build());

disconnect = JMenuItemBuilder.create()
.setText("Disconnect")
.setMnemonic('d')
.addActionListener(
e -> activeFrameManager.getActiveFrame().map(TextFrame::getContainer)
.addActionMethod(() ->
activeFrameManager.getActiveFrame().map(TextFrame::getContainer)
.flatMap(WindowModel::getConnection)
.ifPresent(Connection::disconnect))
.build();
Expand All @@ -113,7 +113,7 @@ private void initServerMenu() {
ssd = JMenuItemBuilder.create()
.setMnemonic('s')
.setText("Server settings")
.addActionListener(e -> activeFrameManager.getActiveFrame().ifPresent(
.addActionMethod(() -> activeFrameManager.getActiveFrame().ifPresent(
f -> f.getContainer().getConnection()
.ifPresent(ssdProvider::displayOrRequestFocus)))
.build();
Expand All @@ -123,8 +123,8 @@ private void initServerMenu() {
add(JMenuItemBuilder.create()
.setText("Exit")
.setMnemonic('x')
.addActionListener(
e -> UIUtilities.invokeOffEDTNoLogging(lifecycleController::quit))
.addActionMethod(
() -> UIUtilities.invokeOffEDTNoLogging(lifecycleController::quit))
.build());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ public SettingsMenu(
private void initSettingsMenu() {
if (!Apple.isAppleUI()) {
add(JMenuItemBuilder.create().setText("Preferences").setMnemonic('p')
.addActionListener(e -> prefsDialogProvider.displayOrRequestFocus()).build());
.addActionMethod(prefsDialogProvider::displayOrRequestFocus)
.build());
}
add(JMenuItemBuilder.create()
.setMnemonic('p')
.addActionListener(e -> profileDialogProvider.displayOrRequestFocus())
.addActionMethod(profileDialogProvider::displayOrRequestFocus)
.setText("Profile Manager")
.build());
add(JMenuItemBuilder.create()
.setMnemonic('a')
.setText("Alias Manager")
.addActionListener(e -> aliasDialogProvider.displayOrRequestFocus())
.setMnemonic('a').setText("Alias Manager")
.addActionMethod(aliasDialogProvider::displayOrRequestFocus)
.build());
}

Expand Down

0 comments on commit bd87450

Please sign in to comment.