changeset 845:fae254369e34

About dialog patch (part 2) review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-December/004620.html reviewed-by: omajid
author Mario Torre <neugens.limasoftware@gmail.com>
date Tue, 11 Dec 2012 23:28:21 +0100
parents 6944bd0bec20
children c4f4b6c7ecad
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/main/java/com/redhat/thermostat/client/swing/internal/AboutDialog.java client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/MainView.java client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/MainWindowControllerImpl.java client/swing/src/test/java/com/redhat/thermostat/client/swing/ThermostatSwingUtilsTest.java
diffstat 6 files changed, 12 insertions(+), 167 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 23:28:21 2012 +0100
@@ -678,6 +678,11 @@
     }
 
     @Override
+    public JFrame getTopFrame() {
+        return this;
+    }
+    
+    @Override
     public void addActionListener(ActionListener<Action> l) {
         actionNotifier.addActionListener(l);
     }
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/ThermostatSwingUtils.java	Tue Dec 11 21:38:31 2012 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,58 +0,0 @@
-/*
- * 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;
-    }
-}
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/AboutDialog.java	Tue Dec 11 21:38:31 2012 +0100
+++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/AboutDialog.java	Tue Dec 11 23:28:21 2012 +0100
@@ -51,6 +51,7 @@
 import javax.swing.Icon;
 import javax.swing.JButton;
 import javax.swing.JDialog;
+import javax.swing.JFrame;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
 import javax.swing.LayoutStyle.ComponentPlacement;
@@ -60,7 +61,6 @@
 
 import com.redhat.thermostat.client.locale.LocaleResources;
 import com.redhat.thermostat.client.swing.IconResource;
-import com.redhat.thermostat.client.swing.ThermostatSwingUtils;
 import com.redhat.thermostat.client.swing.UIResources;
 import com.redhat.thermostat.common.ApplicationInfo;
 import com.redhat.thermostat.common.locale.Translate;
@@ -87,9 +87,7 @@
      * @param applicationInfo 
      */
     public AboutDialog(ApplicationInfo appInfo) {
-        
-        super(ThermostatSwingUtils.getMainFrame(), true);
-        
+       
         setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
         setResizable(false);
         
@@ -105,14 +103,6 @@
         initComponents();
     }
 
-    @Override
-    public void setVisible(boolean b) {
-        if (b) {
-            setLocationRelativeTo(ThermostatSwingUtils.getMainFrame());
-        }
-        super.setVisible(b);
-    }
-    
     private void initComponents() {
         setBounds(100, 100, 450, 338);
         
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/MainView.java	Tue Dec 11 21:38:31 2012 +0100
+++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/MainView.java	Tue Dec 11 23:28:21 2012 +0100
@@ -39,6 +39,8 @@
 import java.awt.event.MouseEvent;
 import java.util.List;
 
+import javax.swing.JFrame;
+
 import com.redhat.thermostat.client.core.HostFilter;
 import com.redhat.thermostat.client.core.VmFilter;
 import com.redhat.thermostat.client.core.views.BasicView;
@@ -99,4 +101,6 @@
     void removeMenu(MenuAction action);
 
     void showVMContextActions(List<VMContextAction> actions, MouseEvent e);
+    
+    JFrame getTopFrame();
 }
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/MainWindowControllerImpl.java	Tue Dec 11 21:38:31 2012 +0100
+++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/MainWindowControllerImpl.java	Tue Dec 11 23:28:21 2012 +0100
@@ -398,6 +398,7 @@
         AboutDialog aboutDialog = new AboutDialog(appInfo);
         aboutDialog.setModal(true);
         aboutDialog.pack();
+        aboutDialog.setLocationRelativeTo(view.getTopFrame());
         aboutDialog.setVisible(true);
     }
 
--- a/client/swing/src/test/java/com/redhat/thermostat/client/swing/ThermostatSwingUtilsTest.java	Tue Dec 11 21:38:31 2012 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,97 +0,0 @@
-/*
- * 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);
-    }
-}