Mercurial > hg > release > thermostat-1.2
changeset 1550:96b8227008fa
Move swing component visiblity handling into common class
Reviewed-by: neugens
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2014-November/thread.html
line wrap: on
line diff
--- a/client/swing/pom.xml Tue Nov 18 17:30:12 2014 +0100 +++ b/client/swing/pom.xml Tue Nov 18 12:37:38 2014 -0500 @@ -161,6 +161,7 @@ <Bundle-SymbolicName>com.redhat.thermostat.client.swing</Bundle-SymbolicName> <Export-Package> com.redhat.thermostat.client.swing, + com.redhat.thermostat.client.swing.experimental, com.redhat.thermostat.client.swing.components, com.redhat.thermostat.client.swing.components.models, com.redhat.thermostat.client.swing.components.experimental,
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/experimental/ComponentVisibilityNotifier.java Tue Nov 18 12:37:38 2014 -0500 @@ -0,0 +1,84 @@ +/* + * Copyright 2012-2014 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.experimental; + +import java.awt.Component; +import java.awt.event.HierarchyListener; + +import javax.swing.JComponent; + +import com.redhat.thermostat.client.core.views.BasicView; +import com.redhat.thermostat.client.core.views.BasicView.Action; +import com.redhat.thermostat.client.swing.ComponentVisibleListener; +import com.redhat.thermostat.common.ActionNotifier; + +/** + * Attach a listener to a swing Component that will automatically fire + * appropriate {@link Action} events. + */ +public class ComponentVisibilityNotifier { + + private HierarchyListener listener; + + public ComponentVisibilityNotifier() { + // nothing to do + } + + public void initialize(final JComponent swingComponent, final ActionNotifier<BasicView.Action> notifier) { + if (listener != null) { + throw new IllegalStateException("Already initialized"); + } + + listener = new ComponentVisibleListener() { + @Override + public void componentShown(Component component) { + notifier.fireAction(Action.VISIBLE); + } + @Override + public void componentHidden(Component component) { + notifier.fireAction(Action.HIDDEN); + } + }; + swingComponent.addHierarchyListener(listener); + } + + public void dispose(final JComponent swingComponent) { + if (listener != null) { + swingComponent.removeHierarchyListener(listener); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/swing/src/test/java/com/redhat/thermostat/client/swing/experimental/ComponentVisibilityNotifierTest.java Tue Nov 18 12:37:38 2014 -0500 @@ -0,0 +1,113 @@ +/* + * Copyright 2012-2014 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.experimental; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +import javax.swing.JFrame; + +import net.java.openjdk.cacio.ctc.junit.CacioFESTRunner; + +import org.fest.swing.annotation.GUITest; +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.experimental.categories.Category; +import org.junit.runner.RunWith; + +import com.redhat.thermostat.client.core.views.BasicView; +import com.redhat.thermostat.client.core.views.BasicView.Action; +import com.redhat.thermostat.client.swing.experimental.ComponentVisibilityNotifier; +import com.redhat.thermostat.common.ActionNotifier; + +@GUITest +@Category(GUITest.class) +@RunWith(CacioFESTRunner.class) +public class ComponentVisibilityNotifierTest { + + private JFrame window; + private FrameFixture frameFixture; + + @BeforeClass + public static void setUpOnce() { + FailOnThreadViolationRepaintManager.install(); + } + + @Before + public void setUp() { + GuiActionRunner.execute(new GuiTask() { + @Override + protected void executeInEDT() throws Throwable { + window = new JFrame(); + window.pack(); + } + }); + + frameFixture = new FrameFixture(window); + } + + @After + public void tearDown() { + frameFixture.cleanUp(); + frameFixture = null; + window = null; + } + + @Category(GUITest.class) + @Test + public void listenerInvoked() { + @SuppressWarnings("unchecked") + ActionNotifier<BasicView.Action> notifier = mock(ActionNotifier.class); + + ComponentVisibilityNotifier visibilityNotifier = new ComponentVisibilityNotifier(); + visibilityNotifier.initialize(window.getRootPane(), notifier); + + frameFixture.show(); + + verify(notifier).fireAction(Action.VISIBLE); + + frameFixture.close(); + + verify(notifier).fireAction(Action.HIDDEN); + } +}
--- a/host-cpu/client-swing/src/main/java/com/redhat/thermostat/host/cpu/client/swing/internal/HostCpuPanel.java Tue Nov 18 17:30:12 2014 +0100 +++ b/host-cpu/client-swing/src/main/java/com/redhat/thermostat/host/cpu/client/swing/internal/HostCpuPanel.java Tue Nov 18 12:37:38 2014 -0500 @@ -60,12 +60,12 @@ import org.jfree.data.time.TimeSeries; import org.jfree.data.time.TimeSeriesCollection; -import com.redhat.thermostat.client.swing.ComponentVisibleListener; import com.redhat.thermostat.client.swing.SwingComponent; import com.redhat.thermostat.client.swing.components.LabelField; import com.redhat.thermostat.client.swing.components.RecentTimeSeriesChartPanel; import com.redhat.thermostat.client.swing.components.SectionHeader; import com.redhat.thermostat.client.swing.components.ValueField; +import com.redhat.thermostat.client.swing.experimental.ComponentVisibilityNotifier; import com.redhat.thermostat.client.ui.ChartColors; import com.redhat.thermostat.client.ui.RecentTimeSeriesChartController; import com.redhat.thermostat.common.ActionListener; @@ -98,16 +98,7 @@ super(); initializePanel(); - visiblePanel.addHierarchyListener(new ComponentVisibleListener() { - @Override - public void componentShown(Component component) { - notifier.fireAction(Action.VISIBLE); - } - @Override - public void componentHidden(Component component) { - notifier.fireAction(Action.HIDDEN); - } - }); + new ComponentVisibilityNotifier().initialize(visiblePanel, notifier); } @Override
--- a/host-memory/client-swing/src/main/java/com/redhat/thermostat/host/memory/client/swing/internal/HostMemoryPanel.java Tue Nov 18 17:30:12 2014 +0100 +++ b/host-memory/client-swing/src/main/java/com/redhat/thermostat/host/memory/client/swing/internal/HostMemoryPanel.java Tue Nov 18 12:37:38 2014 -0500 @@ -62,12 +62,12 @@ import org.jfree.data.time.TimeSeries; import org.jfree.data.time.TimeSeriesCollection; -import com.redhat.thermostat.client.swing.ComponentVisibleListener; import com.redhat.thermostat.client.swing.SwingComponent; import com.redhat.thermostat.client.swing.components.LabelField; import com.redhat.thermostat.client.swing.components.RecentTimeSeriesChartPanel; import com.redhat.thermostat.client.swing.components.SectionHeader; import com.redhat.thermostat.client.swing.components.ValueField; +import com.redhat.thermostat.client.swing.experimental.ComponentVisibilityNotifier; import com.redhat.thermostat.client.ui.ChartColors; import com.redhat.thermostat.client.ui.RecentTimeSeriesChartController; import com.redhat.thermostat.common.ActionListener; @@ -102,16 +102,7 @@ super(); initializePanel(); - visiblePanel.addHierarchyListener(new ComponentVisibleListener() { - @Override - public void componentShown(Component component) { - notifier.fireAction(Action.VISIBLE); - } - @Override - public void componentHidden(Component component) { - notifier.fireAction(Action.HIDDEN); - } - }); + new ComponentVisibilityNotifier().initialize(visiblePanel, notifier); } @Override
--- a/host-overview/client-swing/src/main/java/com/redhat/thermostat/host/overview/client/swing/internal/HostOverviewPanel.java Tue Nov 18 17:30:12 2014 +0100 +++ b/host-overview/client-swing/src/main/java/com/redhat/thermostat/host/overview/client/swing/internal/HostOverviewPanel.java Tue Nov 18 12:37:38 2014 -0500 @@ -51,19 +51,22 @@ import javax.swing.table.TableCellRenderer; import javax.swing.table.TableColumnModel; -import com.redhat.thermostat.client.swing.ComponentVisibleListener; import com.redhat.thermostat.client.swing.SwingComponent; import com.redhat.thermostat.client.swing.components.LabelField; import com.redhat.thermostat.client.swing.components.SectionHeader; import com.redhat.thermostat.client.swing.components.ValueField; +import com.redhat.thermostat.client.swing.experimental.ComponentVisibilityNotifier; import com.redhat.thermostat.common.ActionListener; import com.redhat.thermostat.host.overview.client.core.HostOverviewView; import com.redhat.thermostat.host.overview.client.locale.LocaleResources; import com.redhat.thermostat.shared.locale.Translate; import com.redhat.thermostat.swing.components.experimental.dial.RadialControl; + import javax.swing.border.TitledBorder; import javax.swing.border.LineBorder; + import java.awt.Color; + import javax.swing.JLabel; import javax.swing.SwingConstants; @@ -100,17 +103,7 @@ super(); initializePanel(); - visiblePanel.addHierarchyListener(new ComponentVisibleListener() { - @Override - public void componentShown(Component component) { - notifier.fireAction(Action.VISIBLE); - } - - @Override - public void componentHidden(Component component) { - notifier.fireAction(Action.HIDDEN); - } - }); + new ComponentVisibilityNotifier().initialize(visiblePanel, notifier); } @Override
--- a/numa/client-swing/src/main/java/com/redhat/thermostat/numa/client/swing/internal/NumaPanel.java Tue Nov 18 17:30:12 2014 +0100 +++ b/numa/client-swing/src/main/java/com/redhat/thermostat/numa/client/swing/internal/NumaPanel.java Tue Nov 18 12:37:38 2014 -0500 @@ -64,10 +64,10 @@ import org.jfree.data.time.TimeSeries; import org.jfree.data.time.TimeSeriesCollection; -import com.redhat.thermostat.client.swing.ComponentVisibleListener; import com.redhat.thermostat.client.swing.SwingComponent; import com.redhat.thermostat.client.swing.components.RecentTimeSeriesChartPanel; import com.redhat.thermostat.client.swing.components.SectionHeader; +import com.redhat.thermostat.client.swing.experimental.ComponentVisibilityNotifier; import com.redhat.thermostat.client.ui.ChartColors; import com.redhat.thermostat.client.ui.RecentTimeSeriesChartController; import com.redhat.thermostat.common.ActionListener; @@ -99,16 +99,7 @@ super(); initializePanel(); - visiblePanel.addHierarchyListener(new ComponentVisibleListener() { - @Override - public void componentShown(Component component) { - notifier.fireAction(Action.VISIBLE); - } - @Override - public void componentHidden(Component component) { - notifier.fireAction(Action.HIDDEN); - } - }); + new ComponentVisibilityNotifier().initialize(visiblePanel, notifier); } @Override
--- a/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadCountView.java Tue Nov 18 17:30:12 2014 +0100 +++ b/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadCountView.java Tue Nov 18 12:37:38 2014 -0500 @@ -41,9 +41,9 @@ import javax.swing.JPanel; import javax.swing.SwingUtilities; -import com.redhat.thermostat.client.swing.ComponentVisibleListener; import com.redhat.thermostat.client.swing.SwingComponent; import com.redhat.thermostat.client.swing.components.ChartPanel; +import com.redhat.thermostat.client.swing.ComponentVisibleListener; import com.redhat.thermostat.thread.client.common.chart.LivingDaemonThreadDifferenceChart; import com.redhat.thermostat.thread.client.common.view.ThreadCountView; import javax.swing.SwingWorker;
--- a/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadTableView.java Tue Nov 18 17:30:12 2014 +0100 +++ b/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadTableView.java Tue Nov 18 12:37:38 2014 -0500 @@ -50,9 +50,9 @@ import javax.swing.event.TableModelListener; import javax.swing.table.DefaultTableModel; -import com.redhat.thermostat.client.swing.ComponentVisibleListener; import com.redhat.thermostat.client.swing.SwingComponent; import com.redhat.thermostat.client.swing.components.ThermostatTable; +import com.redhat.thermostat.client.swing.experimental.ComponentVisibilityNotifier; import com.redhat.thermostat.shared.locale.Translate; import com.redhat.thermostat.thread.client.common.locale.LocaleResources; import com.redhat.thermostat.thread.client.common.view.ThreadTableView; @@ -71,17 +71,7 @@ public SwingThreadTableView() { tablePanel = new ThreadTable(); - tablePanel.addHierarchyListener(new ComponentVisibleListener() { - @Override - public void componentShown(Component component) { - SwingThreadTableView.this.notify(Action.VISIBLE); - } - - @Override - public void componentHidden(Component component) { - SwingThreadTableView.this.notify(Action.HIDDEN); - } - }); + new ComponentVisibilityNotifier().initialize(tablePanel, notifier); table = new ThermostatTable(new ThreadViewTableModel(new ArrayList<ThreadTableBean>())); table.setName("threadBeansTable");
--- a/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadTimelineView.java Tue Nov 18 17:30:12 2014 +0100 +++ b/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadTimelineView.java Tue Nov 18 12:37:38 2014 -0500 @@ -40,6 +40,7 @@ import com.redhat.thermostat.client.swing.SwingComponent; import com.redhat.thermostat.client.swing.UIDefaults; import com.redhat.thermostat.client.swing.components.ThermostatScrollPane; +import com.redhat.thermostat.client.swing.experimental.ComponentVisibilityNotifier; import com.redhat.thermostat.common.model.Range; import com.redhat.thermostat.thread.client.common.model.timeline.Timeline; import com.redhat.thermostat.thread.client.common.model.timeline.TimelineGroupDataModel; @@ -53,6 +54,7 @@ import com.redhat.thermostat.thread.client.swing.impl.timeline.scrollbar.SwingTimelineScrollBarController; import com.redhat.thermostat.thread.client.swing.impl.timeline.scrollbar.TimelineScrollBar; import com.redhat.thermostat.thread.model.ThreadHeader; + import java.awt.BorderLayout; import java.awt.Component; import java.awt.event.ComponentAdapter; @@ -60,6 +62,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; + import javax.swing.DefaultListModel; import javax.swing.JList; import javax.swing.JPanel; @@ -93,18 +96,17 @@ groupDataModel = new TimelineGroupThreadConverter(realGDM); contentPane = new JPanel(); + new ComponentVisibilityNotifier().initialize(contentPane, notifier); contentPane.addHierarchyListener(new ComponentVisibleListener() { @Override public void componentShown(Component component) { - SwingThreadTimelineView.this.notify(Action.VISIBLE); - // TODO: this should be retrieved from state properties requestFollowMode(); } @Override public void componentHidden(Component component) { - SwingThreadTimelineView.this.notify(Action.HIDDEN); + // TODO should requestFollowMode be disabled? } });
--- a/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadView.java Tue Nov 18 17:30:12 2014 +0100 +++ b/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadView.java Tue Nov 18 12:37:38 2014 -0500 @@ -51,11 +51,13 @@ import com.redhat.thermostat.thread.client.common.view.ThreadView; import com.redhat.thermostat.thread.client.common.view.VmDeadLockView; import com.redhat.thermostat.thread.client.swing.impl.timeline.SwingTimelineDimensionModel; + import java.awt.Component; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; + import javax.swing.JOptionPane; import javax.swing.JSplitPane; import javax.swing.JTabbedPane; @@ -92,6 +94,8 @@ this.dimensionModel = dimensionModel; panel = new ThreadMainPanel(); + // TODO use ComponentVisiblityNotifier instead + // sadly, the BasicView.notifier field can not be accessed here panel.addHierarchyListener(new ComponentVisibleListener() { @Override
--- a/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/SwingVmDeadLockView.java Tue Nov 18 17:30:12 2014 +0100 +++ b/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/SwingVmDeadLockView.java Tue Nov 18 12:37:38 2014 -0500 @@ -48,8 +48,8 @@ import javax.swing.JTextArea; import javax.swing.SwingUtilities; -import com.redhat.thermostat.client.swing.ComponentVisibleListener; import com.redhat.thermostat.client.swing.SwingComponent; +import com.redhat.thermostat.client.swing.experimental.ComponentVisibilityNotifier; import com.redhat.thermostat.shared.locale.Translate; import com.redhat.thermostat.thread.client.common.locale.LocaleResources; import com.redhat.thermostat.thread.client.common.view.VmDeadLockView; @@ -86,17 +86,7 @@ JScrollPane scrollPane = new JScrollPane(description); actualComponent.add(scrollPane, c); - actualComponent.addHierarchyListener(new ComponentVisibleListener() { - @Override - public void componentShown(Component component) { - notifier.fireAction(Action.VISIBLE); - } - - @Override - public void componentHidden(Component component) { - notifier.fireAction(Action.VISIBLE); - } - }); + new ComponentVisibilityNotifier().initialize(actualComponent, notifier); } @Override
--- a/vm-classstat/client-swing/src/main/java/com/redhat/thermostat/vm/classstat/client/swing/VmClassStatPanel.java Tue Nov 18 17:30:12 2014 +0100 +++ b/vm-classstat/client-swing/src/main/java/com/redhat/thermostat/vm/classstat/client/swing/VmClassStatPanel.java Tue Nov 18 12:37:38 2014 -0500 @@ -54,10 +54,10 @@ import org.jfree.data.time.TimeSeries; import org.jfree.data.time.TimeSeriesCollection; -import com.redhat.thermostat.client.swing.ComponentVisibleListener; import com.redhat.thermostat.client.swing.SwingComponent; import com.redhat.thermostat.client.swing.components.HeaderPanel; import com.redhat.thermostat.client.swing.components.RecentTimeSeriesChartPanel; +import com.redhat.thermostat.client.swing.experimental.ComponentVisibilityNotifier; import com.redhat.thermostat.client.ui.RecentTimeSeriesChartController; import com.redhat.thermostat.common.ActionListener; import com.redhat.thermostat.common.ActionNotifier; @@ -108,17 +108,7 @@ visiblePanel.setContent(chartPanel); - visiblePanel.addHierarchyListener(new ComponentVisibleListener() { - @Override - public void componentShown(Component component) { - notifier.fireAction(Action.VISIBLE); - } - - @Override - public void componentHidden(Component component) { - notifier.fireAction(Action.HIDDEN); - } - }); + new ComponentVisibilityNotifier().initialize(visiblePanel, notifier); } @Override
--- a/vm-cpu/client-swing/src/main/java/com/redhat/thermostat/vm/cpu/client/swing/internal/VmCpuPanel.java Tue Nov 18 17:30:12 2014 +0100 +++ b/vm-cpu/client-swing/src/main/java/com/redhat/thermostat/vm/cpu/client/swing/internal/VmCpuPanel.java Tue Nov 18 12:37:38 2014 -0500 @@ -52,9 +52,9 @@ import org.jfree.data.time.TimeSeries; import org.jfree.data.time.TimeSeriesCollection; -import com.redhat.thermostat.client.swing.ComponentVisibleListener; import com.redhat.thermostat.client.swing.SwingComponent; import com.redhat.thermostat.client.swing.components.HeaderPanel; +import com.redhat.thermostat.client.swing.experimental.ComponentVisibilityNotifier; import com.redhat.thermostat.common.ActionListener; import com.redhat.thermostat.common.ActionNotifier; import com.redhat.thermostat.common.model.Range; @@ -89,17 +89,7 @@ initializePanel(); - visiblePanel.addHierarchyListener(new ComponentVisibleListener() { - @Override - public void componentShown(Component component) { - notifier.fireAction(Action.VISIBLE); - } - - @Override - public void componentHidden(Component component) { - notifier.fireAction(Action.HIDDEN); - } - }); + new ComponentVisibilityNotifier().initialize(visiblePanel, notifier); } @Override
--- a/vm-gc/client-swing/src/main/java/com/redhat/thermostat/vm/gc/client/swing/internal/VmGcPanel.java Tue Nov 18 17:30:12 2014 +0100 +++ b/vm-gc/client-swing/src/main/java/com/redhat/thermostat/vm/gc/client/swing/internal/VmGcPanel.java Tue Nov 18 12:37:38 2014 -0500 @@ -62,11 +62,11 @@ import org.jfree.data.RangeType; import org.jfree.data.xy.IntervalXYDataset; -import com.redhat.thermostat.client.swing.ComponentVisibleListener; import com.redhat.thermostat.client.swing.SwingComponent; import com.redhat.thermostat.client.swing.components.HeaderPanel; import com.redhat.thermostat.client.swing.components.RecentTimeSeriesChartPanel; import com.redhat.thermostat.client.swing.components.SectionHeader; +import com.redhat.thermostat.client.swing.experimental.ComponentVisibilityNotifier; import com.redhat.thermostat.client.ui.RecentTimeSeriesChartController; import com.redhat.thermostat.client.ui.SampledDataset; import com.redhat.thermostat.common.ActionListener; @@ -99,17 +99,7 @@ gcPanelConstraints.weightx = 1; gcPanelConstraints.weighty = 1; - visiblePanel.addHierarchyListener(new ComponentVisibleListener() { - @Override - public void componentShown(Component component) { - notifier.fireAction(Action.VISIBLE); - } - - @Override - public void componentHidden(Component component) { - notifier.fireAction(Action.HIDDEN); - } - }); + new ComponentVisibilityNotifier().initialize(visiblePanel, notifier); } @Override
--- a/vm-heap-analysis/client-swing/src/main/java/com/redhat/thermostat/vm/heap/analysis/client/swing/internal/HeapSwingView.java Tue Nov 18 17:30:12 2014 +0100 +++ b/vm-heap-analysis/client-swing/src/main/java/com/redhat/thermostat/vm/heap/analysis/client/swing/internal/HeapSwingView.java Tue Nov 18 12:37:38 2014 -0500 @@ -55,7 +55,6 @@ import javax.swing.SwingUtilities; import com.redhat.thermostat.client.core.views.BasicView; -import com.redhat.thermostat.client.swing.ComponentVisibleListener; import com.redhat.thermostat.client.swing.IconResource; import com.redhat.thermostat.client.swing.SwingComponent; import com.redhat.thermostat.client.swing.components.ActionButton; @@ -63,6 +62,7 @@ import com.redhat.thermostat.client.swing.components.HeaderPanel; import com.redhat.thermostat.client.swing.components.Icon; import com.redhat.thermostat.client.swing.components.OverlayPanel; +import com.redhat.thermostat.client.swing.experimental.ComponentVisibilityNotifier; import com.redhat.thermostat.shared.locale.LocalizedString; import com.redhat.thermostat.shared.locale.Translate; import com.redhat.thermostat.vm.heap.analysis.client.core.HeapDumpListView; @@ -143,7 +143,7 @@ overlay.setAlignmentY(1.f); overview.setContent(stack); - overview.addHierarchyListener(new ViewVisibleListener()); + new ComponentVisibilityNotifier().initialize(overview, notifier); Icon takeDumpIcon = new Icon(HeapIconResources.getIcon(HeapIconResources.TRIGGER_HEAP_DUMP)); takeDumpIconButton = new ActionButton(takeDumpIcon, translator.localize(LocaleResources.TRIGGER_HEAP_DUMP)); @@ -191,18 +191,6 @@ fileChooser = new JFileChooser(); fileChooser.setName("EXPORT_HEAP_DUMP_FILE_CHOOSER"); } - - private class ViewVisibleListener extends ComponentVisibleListener { - @Override - public void componentShown(Component component) { - HeapSwingView.this.notify(Action.VISIBLE); - } - - @Override - public void componentHidden(Component component) { - HeapSwingView.this.notify(Action.HIDDEN); - } - } @Override public void setModel(final OverviewChart model) {
--- a/vm-jmx/client-swing/src/main/java/com/redhat/thermostat/vm/jmx/client/swing/internal/JmxNotificationsSwingView.java Tue Nov 18 17:30:12 2014 +0100 +++ b/vm-jmx/client-swing/src/main/java/com/redhat/thermostat/vm/jmx/client/swing/internal/JmxNotificationsSwingView.java Tue Nov 18 12:37:38 2014 -0500 @@ -64,7 +64,6 @@ import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; -import com.redhat.thermostat.client.swing.ComponentVisibleListener; import com.redhat.thermostat.client.swing.IconResource; import com.redhat.thermostat.client.swing.SwingComponent; import com.redhat.thermostat.client.swing.components.ActionToggleButton; @@ -73,6 +72,7 @@ import com.redhat.thermostat.client.swing.components.experimental.EventTimeline; import com.redhat.thermostat.client.swing.components.experimental.EventTimelineRangeChangeListener; import com.redhat.thermostat.client.swing.components.experimental.Timeline; +import com.redhat.thermostat.client.swing.experimental.ComponentVisibilityNotifier; import com.redhat.thermostat.client.ui.Palette; import com.redhat.thermostat.common.ActionEvent; import com.redhat.thermostat.common.ActionListener; @@ -153,17 +153,7 @@ contents.add(timeline, c); - contents.addHierarchyListener(new ComponentVisibleListener() { - @Override - public void componentShown(Component component) { - notifier.fireAction(Action.VISIBLE); - } - - @Override - public void componentHidden(Component component) { - notifier.fireAction(Action.HIDDEN); - } - }); + new ComponentVisibilityNotifier().initialize(contents, notifier); toolbarButton = new ActionToggleButton(IconResource.SAMPLE.getIcon(), translate.localize(LocaleResources.NOTIFICATIONS_ENABLE)); toolbarButton.setName("toggleNotifications");
--- a/vm-memory/client-swing/src/main/java/com/redhat/thermostat/vm/memory/client/swing/internal/MemoryStatsViewImpl.java Tue Nov 18 17:30:12 2014 +0100 +++ b/vm-memory/client-swing/src/main/java/com/redhat/thermostat/vm/memory/client/swing/internal/MemoryStatsViewImpl.java Tue Nov 18 12:37:38 2014 -0500 @@ -62,9 +62,9 @@ import javax.swing.text.Document; import com.redhat.thermostat.client.core.views.BasicView; -import com.redhat.thermostat.client.swing.ComponentVisibleListener; import com.redhat.thermostat.client.swing.SwingComponent; import com.redhat.thermostat.client.swing.components.HeaderPanel; +import com.redhat.thermostat.client.swing.experimental.ComponentVisibilityNotifier; import com.redhat.thermostat.common.ActionListener; import com.redhat.thermostat.common.ActionNotifier; import com.redhat.thermostat.gc.remote.client.common.RequestGCAction; @@ -111,17 +111,7 @@ visiblePanel.setHeader(t.localize(LocaleResources.MEMORY_REGIONS_HEADER)); - visiblePanel.addHierarchyListener(new ComponentVisibleListener() { - @Override - public void componentShown(Component component) { - notifier.fireAction(Action.VISIBLE); - } - - @Override - public void componentHidden(Component component) { - notifier.fireAction(Action.HIDDEN); - } - }); + new ComponentVisibilityNotifier().initialize(visiblePanel, notifier); graphPanel = new JPanel(); graphPanel.setLayout(new BoxLayout(graphPanel, BoxLayout.Y_AXIS));
--- a/vm-overview/client-swing/src/main/java/com/redhat/thermostat/vm/overview/client/swing/internal/VmOverviewPanel.java Tue Nov 18 17:30:12 2014 +0100 +++ b/vm-overview/client-swing/src/main/java/com/redhat/thermostat/vm/overview/client/swing/internal/VmOverviewPanel.java Tue Nov 18 12:37:38 2014 -0500 @@ -46,12 +46,12 @@ import javax.swing.GroupLayout.Alignment; import javax.swing.LayoutStyle.ComponentPlacement; -import com.redhat.thermostat.client.swing.ComponentVisibleListener; import com.redhat.thermostat.client.swing.SwingComponent; import com.redhat.thermostat.client.swing.components.HeaderPanel; import com.redhat.thermostat.client.swing.components.LabelField; import com.redhat.thermostat.client.swing.components.SectionHeader; import com.redhat.thermostat.client.swing.components.ValueField; +import com.redhat.thermostat.client.swing.experimental.ComponentVisibilityNotifier; import com.redhat.thermostat.common.ActionListener; import com.redhat.thermostat.shared.locale.Translate; import com.redhat.thermostat.vm.overview.client.core.VmOverviewView; @@ -78,17 +78,8 @@ public VmOverviewPanel() { super(); initializePanel(); - visiblePanel.addHierarchyListener(new ComponentVisibleListener() { - @Override - public void componentShown(Component component) { - notifier.fireAction(Action.VISIBLE); - } - @Override - public void componentHidden(Component component) { - notifier.fireAction(Action.HIDDEN); - } - }); + new ComponentVisibilityNotifier().initialize(visiblePanel, notifier); } @Override