Skip to content

Commit

Permalink
Added a clear log menu action and added accelerators to help menu items
Browse files Browse the repository at this point in the history
  • Loading branch information
zaplatynski committed Apr 27, 2016
1 parent 058c5a0 commit 2937482
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>de.marza.firstspirit.modules</groupId>
<artifactId>the-second-hand-log</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>
<packaging>jar</packaging>
<name>The Second-Hand Log</name>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import javax.swing.*;
import javax.swing.text.JTextComponent;
import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.util.Locale;
import java.util.ResourceBundle;

Expand All @@ -16,6 +18,7 @@ public class ConsoleWindow {
private final ResourceBundle menuLabels;
private JFrame window;
private MessageConsole console;
private JTextComponent textComponent;

@NotNull
public static ConsoleWindow getInstance() {
Expand All @@ -35,9 +38,9 @@ public JFrame getFrame() {

setupMenu();

final JTextComponent textComponent = setupUI();
textComponent = setupUI();

setupConsole(textComponent);
setupConsole();

window.pack();
}
Expand Down Expand Up @@ -74,6 +77,17 @@ private void setupMenu() {
close.setMnemonic(isGerman() ? 'S' : 'C');
close.setAccelerator(KeyStroke.getKeyStroke("alt F4"));

final JMenu edit = new JMenu(menuLabels.getString("editMenu"));
menubar.add(edit);
edit.setMnemonic(isGerman() ? 'B' : 'E');

final JMenuItem clear = new JMenuItem(menuLabels.getString("clearLog"));
edit.add(clear);
clear.setActionCommand(MenuActions.CLEAR_LOG.name());
clear.addActionListener(menuActionLisener);
clear.setMnemonic(isGerman() ? 'L' : 'C');
clear.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));

final JMenu helpMenu = new JMenu(menuLabels.getString("helpMenu"));
menubar.add(helpMenu);
helpMenu.setMnemonic('H');
Expand All @@ -82,11 +96,13 @@ private void setupMenu() {
helpMenu.add(contents);
contents.addActionListener(menuActionLisener);
contents.setActionCommand(MenuActions.SHOW_HELP_CONTENTS.name());
contents.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));

final JMenuItem report = new JMenuItem(menuLabels.getString("report.a.bug.or.feature"));
helpMenu.add(report);
report.addActionListener(menuActionLisener);
report.setActionCommand(MenuActions.SHOW_BUGS_FEATURES.name());
report.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, InputEvent.CTRL_MASK));

helpMenu.addSeparator();

Expand All @@ -111,7 +127,7 @@ private JTextComponent setupUI() {
return textComponent;
}

private void setupConsole(final JTextComponent textComponent) {
private void setupConsole() {
console = new MessageConsole(textComponent);
console.redirectOut(null, System.out);
console.redirectErr(Color.RED, System.err);
Expand Down Expand Up @@ -144,4 +160,8 @@ public ImageIcon getImageIconPressed() {
public ResourceBundle getMenuLabels() {
return menuLabels;
}

public void clearLog() {
textComponent.setText("");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

public enum MenuActions {

CLOSE, SHOW_INFO, SHOW_HELP_CONTENTS, SHOW_BUGS_FEATURES
CLOSE, CLEAR_LOG, SHOW_INFO, SHOW_HELP_CONTENTS, SHOW_BUGS_FEATURES

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,20 @@ public void run() {
case CLOSE:
parent.setVisible(false);
break;
case CLEAR_LOG:
consoleWindow.clearLog();
break;
case SHOW_INFO:
final String title = consoleWindow.getMenuLabels().getString("aboutItem");
JOptionPane.showMessageDialog(parent, readAboutText(), title, JOptionPane.PLAIN_MESSAGE);
break;
case SHOW_BUGS_FEATURES:
HyperlinkExecutor.browseTo(URI.create("https://github.com/zaplatynski/second-hand-log/issues"));
final URI issues = URI.create("https://github.com/zaplatynski/second-hand-log/issues");
HyperlinkExecutor.browseTo(issues);
break;
case SHOW_HELP_CONTENTS:
HyperlinkExecutor.browseTo(URI.create("https://github.com/zaplatynski/second-hand-log/wiki"));
final URI wiki = URI.create("https://github.com/zaplatynski/second-hand-log/wiki");
HyperlinkExecutor.browseTo(wiki);
break;
default:
final String errorMessage = consoleWindow.getMenuLabels().getString("missing.menu.action");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ helpMenu=Help
contents=Contents...
report.a.bug.or.feature=Report a bug or feature...
missing.menu.action=Missing menu action!
unkown.menu.command=Unkown Menu Command
unkown.menu.command=Unkown Menu Command
editMenu=Edit
clearLog=Clear log messages
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
aboutItem=\u00DCber
clearLog=L\u00F6sche Lognachrichten
closeItem=Schlie\u00DFen
contents=Inhalt...
editMenu=Bearbeiten
fileMenu=Datei
helpMenu=Hilfe
missing.menu.action=Fehlende Men\u00FCaktion!
Expand Down

0 comments on commit 2937482

Please sign in to comment.