Skip to content

Commit

Permalink
Resolve issue #9
Browse files Browse the repository at this point in the history
  • Loading branch information
zaplatynski committed May 8, 2016
1 parent bee8d2d commit 3e3f7bc
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 14 deletions.
14 changes: 13 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>de.marza.firstspirit.modules</groupId>
<artifactId>the-second-hand-log</artifactId>
<version>1.0.7</version>
<version>1.0.8</version>
<packaging>jar</packaging>

<name>The Second-Hand Log</name>
Expand Down Expand Up @@ -41,6 +41,18 @@
</developerConnection>
</scm>

<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>


<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ private static boolean isGerman() {
/**
* Gets frame.
*
* @param projectName the FirstSpirit project name
* @return the frame
*/
@NotNull
public JFrame getFrame() {
public JFrame getFrame(final String projectName) {
if (window == null) {
window = setupFrame();
window = setupFrame(projectName);

setupMenu();

Expand All @@ -79,8 +80,9 @@ public JFrame getFrame() {
}

@NotNull
private JFrame setupFrame() {
final JFrame frame = new JFrame(menuLabels.getString("appName"));
private JFrame setupFrame(final String projectName) {
final JFrame frame = new JFrame(menuLabels.getString("appName")
+ (projectName != null ? " / " + projectName : ""));
frame.setIconImage(icon.getImage());
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);

Expand Down Expand Up @@ -194,8 +196,8 @@ private void setupConsole() {
/**
* Show.
*/
public void show() {
getFrame();
public void show(final String projectName) {
getFrame(projectName);
window.setVisible(true);
window.requestFocus();
}
Expand All @@ -207,7 +209,7 @@ public void show() {
*/
@NotNull
public MessageConsole getConsole() {
getFrame();
getFrame(null);
return console;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public MenuController(final ActionEvent event) {
@Override
public void run() {
final ConsoleWindow consoleWindow = ConsoleWindow.getInstance();
final JFrame parent = consoleWindow.getFrame();
final JFrame parent = consoleWindow.getFrame(null);
final MenuActions menuAction = MenuActions.valueOf(event.getActionCommand());
switch (menuAction) {
case CLOSE:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package de.marza.firstspirit.modules.logging.toolbar;

import de.espirit.firstspirit.agency.ProjectAgent;
import de.espirit.firstspirit.client.plugin.toolbar.ExecutableToolbarItem;
import de.espirit.firstspirit.client.plugin.toolbar.ToolbarContext;
import de.marza.firstspirit.modules.logging.console.ConsoleWindow;

import org.jetbrains.annotations.NotNull;

import java.util.ResourceBundle;

import javax.swing.Icon;


Expand All @@ -14,14 +17,25 @@
*/
public class LoggingViewToolbarItem implements ExecutableToolbarItem {

private final ResourceBundle menuLabels;

/**
* Instantiates a new Logging view toolbar item.
*/
public LoggingViewToolbarItem() {
this.menuLabels = ResourceBundle.getBundle(
"de.marza.firstspirit.modules.logging.MenuLabels");
}

@Override
public void execute(@NotNull final ToolbarContext context) {
ConsoleWindow.getInstance().show();
final ProjectAgent projectAgent = context.requireSpecialist(ProjectAgent.TYPE);
ConsoleWindow.getInstance().show(projectAgent.getName());
}

@Override
public String getLabel(@NotNull final ToolbarContext context) {
return "The Second-Hand Log";
return menuLabels.getString("appName");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
package de.marza.firstspirit.modules.logging.console;

import org.junit.Test;

import java.awt.GraphicsEnvironment;
import java.util.Random;
import java.util.ResourceBundle;

import javax.swing.JFrame;
import javax.swing.WindowConstants;

import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assume.assumeThat;

/**
* The type Console window test.
*/
public class ConsoleWindowTest {

private ResourceBundle menuLabels = ResourceBundle.getBundle("de.marza.firstspirit.modules" +
".logging.MenuLabels");

/**
* Main.
*
Expand All @@ -18,11 +29,12 @@ public class ConsoleWindowTest {
*/
public static void main(final String[] args) throws Exception {

ConsoleWindow.getInstance().getFrame().setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
ConsoleWindow.getInstance().getFrame("Test").setDefaultCloseOperation(WindowConstants
.EXIT_ON_CLOSE);

ConsoleWindow.getInstance().show();
ConsoleWindow.getInstance().show(null);

simulateLogEvents(ConsoleWindow.getInstance().getFrame());
simulateLogEvents(ConsoleWindow.getInstance().getFrame(null));
}

private static void simulateLogEvents(final JFrame frame) throws InterruptedException {
Expand All @@ -37,4 +49,14 @@ private static void simulateLogEvents(final JFrame frame) throws InterruptedExce
}
}
}

@Test
public <T> void testWindowTitleWithCustomPart() throws Exception {
assumeThat(GraphicsEnvironment.isHeadless(), is(false));

final JFrame frame = ConsoleWindow.getInstance().getFrame("Part of Window Tile");

final String expectedTitle = menuLabels.getString("appName") + " / Part of Window Tile";
assertThat(frame.getTitle(), is(expectedTitle));
}
}

0 comments on commit 3e3f7bc

Please sign in to comment.