Skip to content

Commit

Permalink
Minimize to tray on window closing #36
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelo Gülle (Windows) committed Jan 2, 2017
1 parent 9583f6c commit dc562f1
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -945,9 +945,8 @@ public void mouseClicked(MouseEvent me) {
* @author aguelle
*
*/
class WindowHideListener extends WindowAdapter {
public class WindowHideListener extends WindowAdapter {

private final String DIALOG_MESSAGE = "The program window will be minimized to the system tray.";
private MainFrame programFrame;

public WindowHideListener(MainFrame programFrame) {
Expand All @@ -959,12 +958,15 @@ public void windowClosing(WindowEvent e) {

if (!programFrame.isExiting()) {

JFrame frame = new JFrame();
JFrame frame = ctx.getBean("trayInfoPaneFrame",
TrayInfoPaneFrame.class);
frame.setAlwaysOnTop(true);

if (System.getProperty("os.name").contains("Windows")) {

// Show dialog
JOptionPane.showMessageDialog(frame, DIALOG_MESSAGE);
JOptionPane.showMessageDialog(frame,
TrayInfoPaneFrame.MESSAGE);

// hide window
programFrame.setVisible(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.midi_automator.view.frames;

import javax.swing.JFrame;

import org.springframework.stereotype.Component;

@Component
public class TrayInfoPaneFrame extends JFrame {

private static final long serialVersionUID = 1L;
public static final String MESSAGE = "The program window will be minimized to the system tray.";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.midi_automator.tests.FunctionalTests;

import static com.midi_automator.tests.utils.GUIAutomations.findTrayInfoPane;

import org.assertj.swing.fixture.JOptionPaneFixture;
import org.junit.Test;

public class CloseProgramFunctionalITCase extends FunctionalBaseCase {

@Test
public void closingProgramShouldShowDialogOnWindows() {

if (System.getProperty("os.name").contains("Windows")) {
startApplication();
window.close();

JOptionPaneFixture trayOptionPane = findTrayInfoPane();
trayOptionPane.requireVisible();
}
}

@Test
public void comittingTrayDialogShouldHideProgramOnWindows() {

if (System.getProperty("os.name").contains("Windows")) {
startApplication();
window.close();

JOptionPaneFixture trayOptionPane = findTrayInfoPane();
trayOptionPane.button().click();

window.requireNotVisible();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
import java.io.IOException;

import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JSpinner;

import org.assertj.swing.core.GenericTypeMatcher;
import org.assertj.swing.core.KeyPressInfo;
import org.assertj.swing.core.MouseButton;
import org.assertj.swing.core.Robot;
import org.assertj.swing.data.TableCell;
import org.assertj.swing.finder.JFileChooserFinder;
import org.assertj.swing.finder.JOptionPaneFinder;
import org.assertj.swing.finder.WindowFinder;
import org.assertj.swing.fixture.AbstractWindowFixture;
import org.assertj.swing.fixture.DialogFixture;
Expand All @@ -22,6 +25,7 @@
import org.assertj.swing.fixture.JLabelFixture;
import org.assertj.swing.fixture.JListFixture;
import org.assertj.swing.fixture.JMenuItemFixture;
import org.assertj.swing.fixture.JOptionPaneFixture;
import org.assertj.swing.fixture.JPopupMenuFixture;
import org.assertj.swing.fixture.JSpinnerFixture;
import org.assertj.swing.fixture.JTableCellFixture;
Expand All @@ -40,6 +44,7 @@
import com.midi_automator.view.frames.EditDialog;
import com.midi_automator.view.frames.MainFrame;
import com.midi_automator.view.frames.PreferencesDialog;
import com.midi_automator.view.frames.TrayInfoPaneFrame;

public class GUIAutomations {

Expand Down Expand Up @@ -77,6 +82,26 @@ public static void openMidiAutomator() throws IOException {
}
}

/**
* Finds the tray info pane
*
* @return The tray info pane
*/
public static JOptionPaneFixture findTrayInfoPane() {

GenericTypeMatcher<JOptionPane> messageMatcher = new GenericTypeMatcher<JOptionPane>(
JOptionPane.class) {

@Override
protected boolean isMatching(JOptionPane optionPane) {
return TrayInfoPaneFrame.MESSAGE
.equals(optionPane.getMessage());
}
};

return JOptionPaneFinder.findOptionPane(messageMatcher).using(robot);
}

/**
* Puts the program to midi learn for the "next" button.
*
Expand Down

0 comments on commit dc562f1

Please sign in to comment.