# HG changeset patch # User Mario Torre # Date 1379492209 -7200 # Node ID 789a3be5013efa9ea288e5dbf081622a49153992 # Parent 5501717515a717479c28f27300138cd16b5e7fb5 Small changes to the GlassPane review-thread: http://icedtea.classpath.org/pipermail/thermostat/2013-August/007970.html reviewed-by: jerboaa diff -r 5501717515a7 -r 789a3be5013e client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/MainWindow.java --- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/MainWindow.java Tue Sep 17 18:56:24 2013 -0400 +++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/MainWindow.java Wed Sep 18 10:16:49 2013 +0200 @@ -102,12 +102,12 @@ import com.redhat.thermostat.client.swing.components.SearchField.SearchAction; import com.redhat.thermostat.client.swing.components.ThermostatPopupMenu; import com.redhat.thermostat.client.swing.internal.components.DecoratedDefaultMutableTreeNode; +import com.redhat.thermostat.client.swing.internal.components.ThermostatGlassPane; import com.redhat.thermostat.client.swing.internal.progress.AggregateNotificationPanel; import com.redhat.thermostat.client.swing.internal.progress.AggregateProgressBarOverlayLayout; import com.redhat.thermostat.client.swing.internal.progress.ProgressNotificationArea; import com.redhat.thermostat.client.swing.internal.progress.SwingProgressNotifier; import com.redhat.thermostat.client.swing.internal.progress.SwingProgressNotifier.PropertyChange; -import com.redhat.thermostat.client.swing.internal.progress.ThermostatGlassPane; import com.redhat.thermostat.client.ui.ContextAction; import com.redhat.thermostat.client.ui.Decorator; import com.redhat.thermostat.client.ui.DecoratorProvider; @@ -427,7 +427,7 @@ AggregateNotificationPanel aggregateNotificationArea = new AggregateNotificationPanel(); ProgressNotificationArea notificationArea = new ProgressNotificationArea(); - notifier = new SwingProgressNotifier(aggregateNotificationArea, notificationArea, glassPane); + notifier = new SwingProgressNotifier(aggregateNotificationArea, notificationArea); statusBar.add(notificationArea, BorderLayout.CENTER); @@ -436,22 +436,10 @@ final OverlayPanel overlay = new OverlayPanel(title, false); glassPane.add(overlay); - glassPane.addHierarchyListener(new ComponentVisibleListener() { - @Override - public void componentShown(Component component) { - overlay.setOverlayVisible(true); - } - - @Override - public void componentHidden(Component component) { - overlay.setOverlayVisible(false); - } - }); - overlay.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { - glassPane.setVisible(false); + overlay.setOverlayVisible(false); } }); @@ -463,7 +451,7 @@ public void actionPerformed(com.redhat.thermostat.common. ActionEvent actionEvent) { - glassPane.setVisible(false); + overlay.setOverlayVisible(false); } }); @@ -471,7 +459,9 @@ @Override public void mouseClicked(MouseEvent e) { if (notifier.hasTasks()) { - glassPane.setVisible(!glassPane.isVisible()); + // ensure glasspane is visible + glassPane.setVisible(true); + overlay.setOverlayVisible(true); } } }); diff -r 5501717515a7 -r 789a3be5013e client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/components/ThermostatGlassPane.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/components/ThermostatGlassPane.java Wed Sep 18 10:16:49 2013 +0200 @@ -0,0 +1,73 @@ +/* + * Copyright 2012, 2013 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 + * . + * + * 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.internal.components; + +import java.awt.Component; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; + +import javax.swing.JPanel; + +@SuppressWarnings("serial") +public class ThermostatGlassPane extends JPanel { + + public ThermostatGlassPane() { + setOpaque(false); + } + + @Override + protected void addImpl(Component comp, Object constraints, int index) { + comp.addComponentListener(new ComponentAdapter() { + @Override + public void componentHidden(ComponentEvent e) { + // check if every component has been made invisible + boolean keepVisible = false; + for (Component child : ThermostatGlassPane.this.getComponents()){ + if (child.isVisible()) { + keepVisible = true; + break; + } + } + if (!keepVisible) { + ThermostatGlassPane.this.setVisible(false); + } + } + }); + + super.addImpl(comp, constraints, index); + } +} diff -r 5501717515a7 -r 789a3be5013e client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/progress/SwingProgressNotifier.java --- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/progress/SwingProgressNotifier.java Tue Sep 17 18:56:24 2013 -0400 +++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/progress/SwingProgressNotifier.java Wed Sep 18 10:16:49 2013 +0200 @@ -44,6 +44,7 @@ import com.redhat.thermostat.client.core.progress.ProgressHandle; import com.redhat.thermostat.client.core.progress.ProgressNotifier; import com.redhat.thermostat.client.swing.SwingComponent; +import com.redhat.thermostat.client.swing.internal.components.ThermostatGlassPane; import com.redhat.thermostat.common.ActionEvent; import com.redhat.thermostat.common.ActionListener; import com.redhat.thermostat.common.ActionNotifier; @@ -75,10 +76,9 @@ private AggregateNotificationPanel aggregateNotificationArea; public SwingProgressNotifier(AggregateNotificationPanel aggregateNotificationArea, - ProgressNotificationArea notificationArea, - ThermostatGlassPane glassPane) + ProgressNotificationArea notificationArea) { - this(aggregateNotificationArea, notificationArea, glassPane, true); + this(aggregateNotificationArea, notificationArea, true); } /** @@ -87,7 +87,7 @@ */ SwingProgressNotifier(AggregateNotificationPanel aggregateNotificationArea, ProgressNotificationArea notificationArea, - ThermostatGlassPane glassPane, boolean runInEDT) + boolean runInEDT) { this.notificationArea = notificationArea; this.aggregateNotificationArea = aggregateNotificationArea; diff -r 5501717515a7 -r 789a3be5013e client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/progress/ThermostatGlassPane.java --- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/progress/ThermostatGlassPane.java Tue Sep 17 18:56:24 2013 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -/* - * Copyright 2012, 2013 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 - * . - * - * 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.internal.progress; - -import javax.swing.JPanel; - -@SuppressWarnings("serial") -public class ThermostatGlassPane extends JPanel { - - public ThermostatGlassPane() { - setOpaque(false); - } -} diff -r 5501717515a7 -r 789a3be5013e client/swing/src/test/java/com/redhat/thermostat/client/swing/internal/progress/SwingProgressNotifierTest.java --- a/client/swing/src/test/java/com/redhat/thermostat/client/swing/internal/progress/SwingProgressNotifierTest.java Tue Sep 17 18:56:24 2013 -0400 +++ b/client/swing/src/test/java/com/redhat/thermostat/client/swing/internal/progress/SwingProgressNotifierTest.java Wed Sep 18 10:16:49 2013 +0200 @@ -63,7 +63,6 @@ private AggregateNotificationPanel aggregateNotificationArea; private ProgressNotificationArea notificationArea; - private ThermostatGlassPane glassPane; @BeforeClass public static void setUpOnce() { @@ -78,7 +77,6 @@ public void setUp() { aggregateNotificationArea = mock(AggregateNotificationPanel.class); notificationArea = mock(ProgressNotificationArea.class); - glassPane = mock(ThermostatGlassPane.class); } @SuppressWarnings({ "unchecked", "rawtypes" }) @@ -86,7 +84,7 @@ public void testNotifierStartStop() throws InterruptedException { ProgressNotifier notifier = new SwingProgressNotifier(aggregateNotificationArea, - notificationArea, glassPane, false); + notificationArea, false); ProgressHandle handle = mock(ProgressHandle.class); when(handle.getName()).thenReturn(LocalizedString.EMPTY_STRING); @@ -135,7 +133,7 @@ public void testHandleStatusChanges() throws InterruptedException { SwingProgressNotifier notifier = new SwingProgressNotifier(aggregateNotificationArea, - notificationArea, glassPane, false); + notificationArea, false); JProgressBar progressBar = mock(JProgressBar.class); JLabel label = mock(JLabel.class);