Mercurial > hg > release > thermostat-0.5
changeset 843:eee59ae0941e
Allow to access the main frame
review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-December/004502.html
reviewed-by: rkennke
author | Mario Torre <neugens.limasoftware@gmail.com> |
---|---|
date | Tue, 11 Dec 2012 21:38:31 +0100 |
parents | 94bfc70b0da0 |
children | 6944bd0bec20 |
files | client/swing/src/main/java/com/redhat/thermostat/client/swing/MainWindow.java client/swing/src/main/java/com/redhat/thermostat/client/swing/ThermostatSwingUtils.java client/swing/src/test/java/com/redhat/thermostat/client/swing/ThermostatSwingUtilsTest.java |
diffstat | 3 files changed, 159 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/MainWindow.java Tue Dec 11 21:38:31 2012 +0100 +++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/MainWindow.java Tue Dec 11 21:38:31 2012 +0100 @@ -69,7 +69,6 @@ import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JPanel; -import javax.swing.JPopupMenu; import javax.swing.JScrollPane; import javax.swing.JSplitPane; import javax.swing.JTree; @@ -120,6 +119,8 @@ import com.redhat.thermostat.common.utils.StringUtils; public class MainWindow extends JFrame implements MainView { + + public static final String MAIN_WINDOW_NAME = "Thermostat_mainWindo_JFrame_parent#1"; private static final Translate<LocaleResources> translator = LocaleResources.createLocalizer(); @@ -338,6 +339,8 @@ public MainWindow() { super(); + setName(MAIN_WINDOW_NAME); + shutdownAction = new ShutdownClient(); searchField.addActionListener(new ActionListener<SearchAction>() {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/ThermostatSwingUtils.java Tue Dec 11 21:38:31 2012 +0100 @@ -0,0 +1,58 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.client.swing; + +import java.awt.Window; + +import javax.swing.JFrame; + +public class ThermostatSwingUtils { + + /** + * Returns the main Thermostat Frame currently realized, or null if it has + * been disposed or is not showing. + */ + public static JFrame getMainFrame() { + Window[] windows = JFrame.getWindows(); + for (Window window : windows) { + if (window.getName().equals(MainWindow.MAIN_WINDOW_NAME)) { + return (JFrame) window; + } + } + return null; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/swing/src/test/java/com/redhat/thermostat/client/swing/ThermostatSwingUtilsTest.java Tue Dec 11 21:38:31 2012 +0100 @@ -0,0 +1,97 @@ +/* + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.client.swing; + +import static org.junit.Assert.*; + +import javax.swing.JFrame; + +import net.java.openjdk.cacio.ctc.junit.CacioFESTRunner; + +import org.fest.swing.annotation.GUITest; +import org.fest.swing.annotation.RunsInEDT; +import org.fest.swing.edt.FailOnThreadViolationRepaintManager; +import org.fest.swing.edt.GuiActionRunner; +import org.fest.swing.edt.GuiTask; +import org.fest.swing.fixture.FrameFixture; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(CacioFESTRunner.class) +public class ThermostatSwingUtilsTest { + + private JFrame frame; + private FrameFixture frameFixture; + + @BeforeClass + public static void setUpOnce() { + FailOnThreadViolationRepaintManager.install(); + } + + @Before + public void setUp() { + GuiActionRunner.execute(new GuiTask() { + @Override + protected void executeInEDT() throws Throwable { + frame = new JFrame(); + frame.setName(MainWindow.MAIN_WINDOW_NAME); + } + }); + frameFixture = new FrameFixture(frame); + } + + @After + public void tearDown() { + frameFixture.cleanUp(); + frameFixture = null; + } + + @Test + @GUITest + @RunsInEDT + public void testGetMainFrame() { + + frameFixture.show(); + + JFrame result = ThermostatSwingUtils.getMainFrame(); + + assertNotNull(result); + assertEquals(MainWindow.MAIN_WINDOW_NAME, result.getName()); + assertEquals(frame, result); + } +}