Mercurial > hg > release > thermostat-0.5
changeset 835:5d0ca9f27097
Rename *.swing packages to *.swing.internal
This commit very simply renames the swing packages in each of the plugins
I have created, host-{overview,cpu,memory} and
vm-{overview,cpu,gc,memory}, to swing.internal to be consistent with
internal package names used elsewhere in the plugins.
Reviewed-by: omajid, jerboaa
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-December/004462.html
line wrap: on
line diff
--- a/host-cpu/client-swing/pom.xml Mon Dec 10 15:10:21 2012 +0100 +++ b/host-cpu/client-swing/pom.xml Mon Dec 10 10:24:20 2012 -0500 @@ -17,8 +17,8 @@ <extensions>true</extensions> <configuration> <instructions> - <Private-Package>com.redhat.thermostat.host.cpu.client.swing</Private-Package> - <Bundle-Activator>com.redhat.thermostat.host.cpu.client.swing.Activator</Bundle-Activator> + <Private-Package>com.redhat.thermostat.host.cpu.client.swing.internal</Private-Package> + <Bundle-Activator>com.redhat.thermostat.host.cpu.client.swing.internal.Activator</Bundle-Activator> <Bundle-Vendor>Red Hat, Inc.</Bundle-Vendor> <Bundle-SymbolicName>com.redhat.thermostat.host.cpu.client.swing</Bundle-SymbolicName> <!-- Do not autogenerate uses clauses in Manifests -->
--- a/host-cpu/client-swing/src/main/java/com/redhat/thermostat/host/cpu/client/swing/Activator.java Mon Dec 10 15:10:21 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.host.cpu.client.swing; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; - -import com.redhat.thermostat.host.cpu.client.core.HostCpuViewProvider; - -public class Activator implements BundleActivator { - - @Override - public void start(BundleContext context) throws Exception { - HostCpuViewProvider viewProvider = new SwingHostCpuViewProvider(); - // Unregistered on Activator.stop - context.registerService(HostCpuViewProvider.class.getName(), viewProvider, null); - } - - @Override - public void stop(BundleContext context) throws Exception { - } - -} -
--- a/host-cpu/client-swing/src/main/java/com/redhat/thermostat/host/cpu/client/swing/HostCpuPanel.java Mon Dec 10 15:10:21 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,297 +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.host.cpu.client.swing; - -import java.awt.Color; -import java.awt.Component; -import java.awt.FlowLayout; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import javax.swing.GroupLayout; -import javax.swing.GroupLayout.Alignment; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.LayoutStyle.ComponentPlacement; -import javax.swing.SwingUtilities; -import javax.swing.text.JTextComponent; - -import org.jfree.chart.ChartFactory; -import org.jfree.chart.JFreeChart; -import org.jfree.chart.renderer.xy.XYItemRenderer; -import org.jfree.data.time.FixedMillisecond; -import org.jfree.data.time.RegularTimePeriod; -import org.jfree.data.time.TimeSeries; -import org.jfree.data.time.TimeSeriesCollection; - -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.ui.ChartColors; -import com.redhat.thermostat.client.ui.ComponentVisibleListener; -import com.redhat.thermostat.client.ui.RecentTimeSeriesChartController; -import com.redhat.thermostat.common.ActionListener; -import com.redhat.thermostat.common.locale.Translate; -import com.redhat.thermostat.host.cpu.client.core.HostCpuView; -import com.redhat.thermostat.host.cpu.client.locale.LocaleResources; -import com.redhat.thermostat.storage.model.DiscreteTimeData; -import com.redhat.thermostat.swing.components.experimental.WrapLayout; - -public class HostCpuPanel extends HostCpuView implements SwingComponent { - - private static final Translate<LocaleResources> translator = LocaleResources.createLocalizer(); - - private JPanel visiblePanel; - - private final JTextComponent cpuModel = new ValueField("${CPU_MODEL}"); - private final JTextComponent cpuCount = new ValueField("${CPU_COUNT}"); - - private final TimeSeriesCollection datasetCollection = new TimeSeriesCollection(); - private final Map<Integer, TimeSeries> datasets = new HashMap<>(); - private final Map<String, Color> colors = new HashMap<>(); - private final Map<String, JLabel> labels = new HashMap<>(); - - private JFreeChart chart; - - private JPanel legendPanel; - - public HostCpuPanel() { - 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); - } - }); - } - - @Override - public void addActionListener(ActionListener<Action> listener) { - notifier.addActionListener(listener); - } - - @Override - public void removeActionListener(ActionListener<Action> listener) { - notifier.removeActionListener(listener); - } - - @Override - public void setCpuCount(final String count) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - cpuCount.setText(count); - } - }); - } - - @Override - public void setCpuModel(final String model) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - cpuModel.setText(model); - } - }); - } - - @Override - public void addCpuUsageChart(final int cpuIndex, final String humanReadableName) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - TimeSeries series = new TimeSeries(humanReadableName); - Color color = ChartColors.getColor(colors.size()); - colors.put(humanReadableName, color); - - datasets.put(cpuIndex, series); - datasetCollection.addSeries(series); - - updateColors(); - - JLabel label = createLabelWithLegend(humanReadableName, color); - labels.put(humanReadableName, label); - - legendPanel.add(label); - legendPanel.revalidate(); - } - }); - } - - @Override - public void addCpuUsageData(final int cpuIndex, List<DiscreteTimeData<Double>> data) { - final ArrayList<DiscreteTimeData<Double>> copy = new ArrayList<>(data); - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - TimeSeries dataset = datasets.get(cpuIndex); - for (DiscreteTimeData<Double> timeData: copy) { - RegularTimePeriod period = new FixedMillisecond(timeData.getTimeInMillis()); - if (dataset.getDataItem(period) == null) { - dataset.add(period, timeData.getData(), false); - } - } - dataset.fireSeriesChanged(); - } - }); - } - - @Override - public void clearCpuUsageData() { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - for (Iterator<Map.Entry<Integer, TimeSeries>> iter = datasets.entrySet().iterator(); iter.hasNext();) { - Map.Entry<Integer, TimeSeries> entry = iter.next(); - datasetCollection.removeSeries(entry.getValue()); - entry.getValue().clear(); - - iter.remove(); - - } - updateColors(); - } - }); - } - - @Override - public Component getUiComponent() { - return visiblePanel; - } - - private void initializePanel() { - - visiblePanel = new JPanel(); - - JLabel summaryLabel = new SectionHeader(translator.localize(LocaleResources.HOST_CPU_SECTION_OVERVIEW)); - - JLabel cpuModelLabel = new LabelField(translator.localize(LocaleResources.HOST_INFO_CPU_MODEL)); - - JLabel cpuCountLabel = new LabelField(translator.localize(LocaleResources.HOST_INFO_CPU_COUNT)); - - chart = ChartFactory.createTimeSeriesChart( - null, - translator.localize(LocaleResources.HOST_CPU_USAGE_CHART_TIME_LABEL), - translator.localize(LocaleResources.HOST_CPU_USAGE_CHART_VALUE_LABEL), - datasetCollection, - false, false, false); - - chart.getPlot().setBackgroundPaint( new Color(255,255,255,0) ); - chart.getPlot().setBackgroundImageAlpha(0.0f); - chart.getPlot().setOutlinePaint(new Color(0,0,0,0)); - - JPanel chartPanel = new RecentTimeSeriesChartPanel(new RecentTimeSeriesChartController(chart)); - chartPanel.setOpaque(false); - - legendPanel = new JPanel(new WrapLayout(FlowLayout.LEADING)); - legendPanel.setOpaque(false); - - GroupLayout groupLayout = new GroupLayout(visiblePanel); - groupLayout.setHorizontalGroup( - groupLayout.createParallelGroup(Alignment.TRAILING) - .addGroup(groupLayout.createSequentialGroup() - .addContainerGap() - .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) - .addComponent(legendPanel, GroupLayout.DEFAULT_SIZE, 427, Short.MAX_VALUE) - .addComponent(chartPanel, GroupLayout.DEFAULT_SIZE, 427, Short.MAX_VALUE) - .addComponent(summaryLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addGroup(groupLayout.createSequentialGroup() - .addGap(12) - .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) - .addGroup(groupLayout.createSequentialGroup() - .addPreferredGap(ComponentPlacement.RELATED) - .addComponent(cpuCountLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addGap(18) - .addComponent(cpuCount, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGroup(groupLayout.createSequentialGroup() - .addComponent(cpuModelLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addGap(18) - .addComponent(cpuModel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))) - .addGap(11)) - ); - groupLayout.setVerticalGroup( - groupLayout.createParallelGroup(Alignment.LEADING) - .addGroup(groupLayout.createSequentialGroup() - .addContainerGap() - .addComponent(summaryLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(ComponentPlacement.RELATED) - .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE) - .addComponent(cpuModelLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addComponent(cpuModel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) - .addGap(10) - .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE) - .addComponent(cpuCount, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addComponent(cpuCountLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) - .addGap(18) - .addComponent(chartPanel, GroupLayout.DEFAULT_SIZE, 263, Short.MAX_VALUE) - .addPreferredGap(ComponentPlacement.RELATED) - .addComponent(legendPanel, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - ); - visiblePanel.setLayout(groupLayout); - } - - /** - * Adding or removing series to the series collection may change the order - * of existing items. Plus the paint for the index is now out-of-date. So - * let's walk through all the series and set the right paint for those. - */ - private void updateColors() { - XYItemRenderer itemRenderer = chart.getXYPlot().getRenderer(); - for (int i = 0; i < datasetCollection.getSeriesCount(); i++) { - String tag = (String) datasetCollection.getSeriesKey(i); - Color color = colors.get(tag); - itemRenderer.setSeriesPaint(i, color); - } - } - - private JLabel createLabelWithLegend(String text, Color color) { - String hexColor = "#" + Integer.toHexString(color.getRGB() & 0x00ffffff); - return new JLabel("<html> <font color='" + hexColor + "'>\u2588</font> " + text + "</html>"); - } -}
--- a/host-cpu/client-swing/src/main/java/com/redhat/thermostat/host/cpu/client/swing/SwingHostCpuViewProvider.java Mon Dec 10 15:10:21 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +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.host.cpu.client.swing; - -import com.redhat.thermostat.host.cpu.client.core.HostCpuView; -import com.redhat.thermostat.host.cpu.client.core.HostCpuViewProvider; - -public class SwingHostCpuViewProvider implements HostCpuViewProvider { - - @Override - public HostCpuView createView() { - return new HostCpuPanel(); - } - -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/host-cpu/client-swing/src/main/java/com/redhat/thermostat/host/cpu/client/swing/internal/Activator.java Mon Dec 10 10:24:20 2012 -0500 @@ -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.host.cpu.client.swing.internal; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +import com.redhat.thermostat.host.cpu.client.core.HostCpuViewProvider; + +public class Activator implements BundleActivator { + + @Override + public void start(BundleContext context) throws Exception { + HostCpuViewProvider viewProvider = new SwingHostCpuViewProvider(); + // Unregistered on Activator.stop + context.registerService(HostCpuViewProvider.class.getName(), viewProvider, null); + } + + @Override + public void stop(BundleContext context) throws Exception { + } + +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/host-cpu/client-swing/src/main/java/com/redhat/thermostat/host/cpu/client/swing/internal/HostCpuPanel.java Mon Dec 10 10:24:20 2012 -0500 @@ -0,0 +1,297 @@ +/* + * 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.host.cpu.client.swing.internal; + +import java.awt.Color; +import java.awt.Component; +import java.awt.FlowLayout; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.swing.GroupLayout; +import javax.swing.GroupLayout.Alignment; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.LayoutStyle.ComponentPlacement; +import javax.swing.SwingUtilities; +import javax.swing.text.JTextComponent; + +import org.jfree.chart.ChartFactory; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.renderer.xy.XYItemRenderer; +import org.jfree.data.time.FixedMillisecond; +import org.jfree.data.time.RegularTimePeriod; +import org.jfree.data.time.TimeSeries; +import org.jfree.data.time.TimeSeriesCollection; + +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.ui.ChartColors; +import com.redhat.thermostat.client.ui.ComponentVisibleListener; +import com.redhat.thermostat.client.ui.RecentTimeSeriesChartController; +import com.redhat.thermostat.common.ActionListener; +import com.redhat.thermostat.common.locale.Translate; +import com.redhat.thermostat.host.cpu.client.core.HostCpuView; +import com.redhat.thermostat.host.cpu.client.locale.LocaleResources; +import com.redhat.thermostat.storage.model.DiscreteTimeData; +import com.redhat.thermostat.swing.components.experimental.WrapLayout; + +public class HostCpuPanel extends HostCpuView implements SwingComponent { + + private static final Translate<LocaleResources> translator = LocaleResources.createLocalizer(); + + private JPanel visiblePanel; + + private final JTextComponent cpuModel = new ValueField("${CPU_MODEL}"); + private final JTextComponent cpuCount = new ValueField("${CPU_COUNT}"); + + private final TimeSeriesCollection datasetCollection = new TimeSeriesCollection(); + private final Map<Integer, TimeSeries> datasets = new HashMap<>(); + private final Map<String, Color> colors = new HashMap<>(); + private final Map<String, JLabel> labels = new HashMap<>(); + + private JFreeChart chart; + + private JPanel legendPanel; + + public HostCpuPanel() { + 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); + } + }); + } + + @Override + public void addActionListener(ActionListener<Action> listener) { + notifier.addActionListener(listener); + } + + @Override + public void removeActionListener(ActionListener<Action> listener) { + notifier.removeActionListener(listener); + } + + @Override + public void setCpuCount(final String count) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + cpuCount.setText(count); + } + }); + } + + @Override + public void setCpuModel(final String model) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + cpuModel.setText(model); + } + }); + } + + @Override + public void addCpuUsageChart(final int cpuIndex, final String humanReadableName) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + TimeSeries series = new TimeSeries(humanReadableName); + Color color = ChartColors.getColor(colors.size()); + colors.put(humanReadableName, color); + + datasets.put(cpuIndex, series); + datasetCollection.addSeries(series); + + updateColors(); + + JLabel label = createLabelWithLegend(humanReadableName, color); + labels.put(humanReadableName, label); + + legendPanel.add(label); + legendPanel.revalidate(); + } + }); + } + + @Override + public void addCpuUsageData(final int cpuIndex, List<DiscreteTimeData<Double>> data) { + final ArrayList<DiscreteTimeData<Double>> copy = new ArrayList<>(data); + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + TimeSeries dataset = datasets.get(cpuIndex); + for (DiscreteTimeData<Double> timeData: copy) { + RegularTimePeriod period = new FixedMillisecond(timeData.getTimeInMillis()); + if (dataset.getDataItem(period) == null) { + dataset.add(period, timeData.getData(), false); + } + } + dataset.fireSeriesChanged(); + } + }); + } + + @Override + public void clearCpuUsageData() { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + for (Iterator<Map.Entry<Integer, TimeSeries>> iter = datasets.entrySet().iterator(); iter.hasNext();) { + Map.Entry<Integer, TimeSeries> entry = iter.next(); + datasetCollection.removeSeries(entry.getValue()); + entry.getValue().clear(); + + iter.remove(); + + } + updateColors(); + } + }); + } + + @Override + public Component getUiComponent() { + return visiblePanel; + } + + private void initializePanel() { + + visiblePanel = new JPanel(); + + JLabel summaryLabel = new SectionHeader(translator.localize(LocaleResources.HOST_CPU_SECTION_OVERVIEW)); + + JLabel cpuModelLabel = new LabelField(translator.localize(LocaleResources.HOST_INFO_CPU_MODEL)); + + JLabel cpuCountLabel = new LabelField(translator.localize(LocaleResources.HOST_INFO_CPU_COUNT)); + + chart = ChartFactory.createTimeSeriesChart( + null, + translator.localize(LocaleResources.HOST_CPU_USAGE_CHART_TIME_LABEL), + translator.localize(LocaleResources.HOST_CPU_USAGE_CHART_VALUE_LABEL), + datasetCollection, + false, false, false); + + chart.getPlot().setBackgroundPaint( new Color(255,255,255,0) ); + chart.getPlot().setBackgroundImageAlpha(0.0f); + chart.getPlot().setOutlinePaint(new Color(0,0,0,0)); + + JPanel chartPanel = new RecentTimeSeriesChartPanel(new RecentTimeSeriesChartController(chart)); + chartPanel.setOpaque(false); + + legendPanel = new JPanel(new WrapLayout(FlowLayout.LEADING)); + legendPanel.setOpaque(false); + + GroupLayout groupLayout = new GroupLayout(visiblePanel); + groupLayout.setHorizontalGroup( + groupLayout.createParallelGroup(Alignment.TRAILING) + .addGroup(groupLayout.createSequentialGroup() + .addContainerGap() + .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) + .addComponent(legendPanel, GroupLayout.DEFAULT_SIZE, 427, Short.MAX_VALUE) + .addComponent(chartPanel, GroupLayout.DEFAULT_SIZE, 427, Short.MAX_VALUE) + .addComponent(summaryLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addGroup(groupLayout.createSequentialGroup() + .addGap(12) + .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) + .addGroup(groupLayout.createSequentialGroup() + .addPreferredGap(ComponentPlacement.RELATED) + .addComponent(cpuCountLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addGap(18) + .addComponent(cpuCount, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(groupLayout.createSequentialGroup() + .addComponent(cpuModelLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addGap(18) + .addComponent(cpuModel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))) + .addGap(11)) + ); + groupLayout.setVerticalGroup( + groupLayout.createParallelGroup(Alignment.LEADING) + .addGroup(groupLayout.createSequentialGroup() + .addContainerGap() + .addComponent(summaryLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(ComponentPlacement.RELATED) + .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE) + .addComponent(cpuModelLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(cpuModel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) + .addGap(10) + .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE) + .addComponent(cpuCount, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(cpuCountLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) + .addGap(18) + .addComponent(chartPanel, GroupLayout.DEFAULT_SIZE, 263, Short.MAX_VALUE) + .addPreferredGap(ComponentPlacement.RELATED) + .addComponent(legendPanel, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE) + .addContainerGap()) + ); + visiblePanel.setLayout(groupLayout); + } + + /** + * Adding or removing series to the series collection may change the order + * of existing items. Plus the paint for the index is now out-of-date. So + * let's walk through all the series and set the right paint for those. + */ + private void updateColors() { + XYItemRenderer itemRenderer = chart.getXYPlot().getRenderer(); + for (int i = 0; i < datasetCollection.getSeriesCount(); i++) { + String tag = (String) datasetCollection.getSeriesKey(i); + Color color = colors.get(tag); + itemRenderer.setSeriesPaint(i, color); + } + } + + private JLabel createLabelWithLegend(String text, Color color) { + String hexColor = "#" + Integer.toHexString(color.getRGB() & 0x00ffffff); + return new JLabel("<html> <font color='" + hexColor + "'>\u2588</font> " + text + "</html>"); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/host-cpu/client-swing/src/main/java/com/redhat/thermostat/host/cpu/client/swing/internal/SwingHostCpuViewProvider.java Mon Dec 10 10:24:20 2012 -0500 @@ -0,0 +1,49 @@ +/* + * 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.host.cpu.client.swing.internal; + +import com.redhat.thermostat.host.cpu.client.core.HostCpuView; +import com.redhat.thermostat.host.cpu.client.core.HostCpuViewProvider; + +public class SwingHostCpuViewProvider implements HostCpuViewProvider { + + @Override + public HostCpuView createView() { + return new HostCpuPanel(); + } + +}
--- a/host-cpu/client-swing/src/test/java/com/redhat/thermostat/host/cpu/client/swing/ActivatorTest.java Mon Dec 10 15:10:21 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.host.cpu.client.swing; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import com.redhat.thermostat.host.cpu.client.core.HostCpuViewProvider; -import com.redhat.thermostat.test.StubBundleContext; - -public class ActivatorTest { - - @Test - public void verifyStartRegistersViewProvider() throws Exception { - StubBundleContext ctx = new StubBundleContext(); - Activator activator = new Activator(); - activator.start(ctx); - assertTrue(ctx.isServiceRegistered(HostCpuViewProvider.class.getName(), SwingHostCpuViewProvider.class)); - assertEquals(1, ctx.getAllServices().size()); - } - -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/host-cpu/client-swing/src/test/java/com/redhat/thermostat/host/cpu/client/swing/internal/ActivatorTest.java Mon Dec 10 10:24:20 2012 -0500 @@ -0,0 +1,60 @@ +/* + * 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.host.cpu.client.swing.internal; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import com.redhat.thermostat.host.cpu.client.core.HostCpuViewProvider; +import com.redhat.thermostat.host.cpu.client.swing.internal.Activator; +import com.redhat.thermostat.host.cpu.client.swing.internal.SwingHostCpuViewProvider; +import com.redhat.thermostat.test.StubBundleContext; + +public class ActivatorTest { + + @Test + public void verifyStartRegistersViewProvider() throws Exception { + StubBundleContext ctx = new StubBundleContext(); + Activator activator = new Activator(); + activator.start(ctx); + assertTrue(ctx.isServiceRegistered(HostCpuViewProvider.class.getName(), SwingHostCpuViewProvider.class)); + assertEquals(1, ctx.getAllServices().size()); + } + +}
--- a/host-memory/client-swing/pom.xml Mon Dec 10 15:10:21 2012 +0100 +++ b/host-memory/client-swing/pom.xml Mon Dec 10 10:24:20 2012 -0500 @@ -17,8 +17,8 @@ <extensions>true</extensions> <configuration> <instructions> - <Private-Package>com.redhat.thermostat.host.memory.client.swing</Private-Package> - <Bundle-Activator>com.redhat.thermostat.host.memory.client.swing.Activator</Bundle-Activator> + <Private-Package>com.redhat.thermostat.host.memory.client.swing.internal</Private-Package> + <Bundle-Activator>com.redhat.thermostat.host.memory.client.swing.internal.Activator</Bundle-Activator> <Bundle-Vendor>Red Hat, Inc.</Bundle-Vendor> <Bundle-SymbolicName>com.redhat.thermostat.host.memory.client.swing</Bundle-SymbolicName> <!-- Do not autogenerate uses clauses in Manifests -->
--- a/host-memory/client-swing/src/main/java/com/redhat/thermostat/host/memory/client/swing/Activator.java Mon Dec 10 15:10:21 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +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.host.memory.client.swing; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; - -import com.redhat.thermostat.host.memory.client.core.HostMemoryViewProvider; - -public class Activator implements BundleActivator { - - - @Override - public void start(final BundleContext context) throws Exception { - HostMemoryViewProvider viewProvider = new SwingHostMemoryViewProvider(); - // Unregistered on Activator.stop - context.registerService(HostMemoryViewProvider.class.getName(), viewProvider, null); - } - - @Override - public void stop(BundleContext context) throws Exception { - } - -} -
--- a/host-memory/client-swing/src/main/java/com/redhat/thermostat/host/memory/client/swing/HostMemoryPanel.java Mon Dec 10 15:10:21 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,354 +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.host.memory.client.swing; - -import java.awt.Color; -import java.awt.Component; -import java.awt.FlowLayout; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CopyOnWriteArrayList; - -import javax.swing.GroupLayout; -import javax.swing.GroupLayout.Alignment; -import javax.swing.JCheckBox; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.LayoutStyle.ComponentPlacement; -import javax.swing.SwingUtilities; -import javax.swing.text.JTextComponent; - -import org.jfree.chart.ChartFactory; -import org.jfree.chart.JFreeChart; -import org.jfree.chart.axis.NumberAxis; -import org.jfree.chart.renderer.xy.XYItemRenderer; -import org.jfree.data.time.FixedMillisecond; -import org.jfree.data.time.RegularTimePeriod; -import org.jfree.data.time.TimeSeries; -import org.jfree.data.time.TimeSeriesCollection; - -import com.redhat.thermostat.client.swing.SwingComponent; -import com.redhat.thermostat.client.swing.components.Components; -import com.redhat.thermostat.client.swing.components.RecentTimeSeriesChartPanel; -import com.redhat.thermostat.client.swing.components.ValueField; -import com.redhat.thermostat.client.ui.ChartColors; -import com.redhat.thermostat.client.ui.ComponentVisibleListener; -import com.redhat.thermostat.client.ui.RecentTimeSeriesChartController; -import com.redhat.thermostat.common.ActionListener; -import com.redhat.thermostat.common.locale.Translate; -import com.redhat.thermostat.common.utils.DisplayableValues; -import com.redhat.thermostat.common.utils.DisplayableValues.Scale; -import com.redhat.thermostat.host.memory.client.core.HostMemoryView; -import com.redhat.thermostat.host.memory.client.locale.LocaleResources; -import com.redhat.thermostat.storage.model.DiscreteTimeData; -import com.redhat.thermostat.swing.components.experimental.WrapLayout; - -public class HostMemoryPanel extends HostMemoryView implements SwingComponent { - - private static final Translate<LocaleResources> translator = LocaleResources.createLocalizer(); - - private JPanel visiblePanel; - - private final MemoryCheckboxListener memoryCheckboxListener = new MemoryCheckboxListener(); - - private final JTextComponent totalMemory = new ValueField("${TOTAL_MEMORY}"); - - private final JPanel memoryCheckBoxPanel = new JPanel(new WrapLayout(FlowLayout.LEADING)); - private final CopyOnWriteArrayList<GraphVisibilityChangeListener> listeners = new CopyOnWriteArrayList<>(); - private final TimeSeriesCollection memoryCollection = new TimeSeriesCollection(); - private final Map<String, TimeSeries> dataset = new HashMap<>(); - private final Map<String, JCheckBox> checkBoxes = new HashMap<>(); - private final Map<String, Color> colors = new HashMap<>(); - - private JFreeChart chart; - - public HostMemoryPanel() { - 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); - } - }); - } - - @Override - public void setTotalMemory(final String newValue) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - totalMemory.setText(newValue); - } - }); - } - - @Override - public Component getUiComponent() { - return visiblePanel; - } - - @Override - public void addMemoryChart(final String tag, final String humanReadableName) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - int colorIndex = colors.size(); - colors.put(tag, ChartColors.getColor(colorIndex)); - TimeSeries series = new TimeSeries(tag); - dataset.put(tag, series); - JCheckBox newCheckBox = new JCheckBox(createLabelWithLegend(humanReadableName, colors.get(tag))); - newCheckBox.setActionCommand(tag); - newCheckBox.setSelected(true); - newCheckBox.addActionListener(memoryCheckboxListener); - newCheckBox.setOpaque(false); - checkBoxes.put(tag, newCheckBox); - memoryCheckBoxPanel.add(newCheckBox); - - updateColors(); - } - }); - - } - - private String createLabelWithLegend(String text, Color color) { - String hexColor = "#" + Integer.toHexString(color.getRGB() & 0x00ffffff); - return "<html> <font color='" + hexColor + "'>\u2588</font> " + text + "</html>"; - } - - @Override - public void removeMemoryChart(final String tag) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - TimeSeries series = dataset.remove(tag); - memoryCollection.removeSeries(series); - JCheckBox box = checkBoxes.remove(tag); - memoryCheckBoxPanel.remove(box); - - updateColors(); - } - }); - } - - @Override - public void showMemoryChart(final String tag) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - TimeSeries series = dataset.get(tag); - memoryCollection.addSeries(series); - - updateColors(); - } - }); - } - - @Override - public void hideMemoryChart(final String tag) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - TimeSeries series = dataset.get(tag); - memoryCollection.removeSeries(series); - - updateColors(); - } - }); - } - - @Override - public void addMemoryData(final String tag, List<DiscreteTimeData<? extends Number>> data) { - final List<DiscreteTimeData<? extends Number>> copy = new ArrayList<>(data); - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - final TimeSeries series = dataset.get(tag); - for (DiscreteTimeData<? extends Number> timeData: copy) { - RegularTimePeriod period = new FixedMillisecond(timeData.getTimeInMillis()); - if (series.getDataItem(period) == null) { - Long sizeInBytes = (Long) timeData.getData(); - Double sizeInMegaBytes = DisplayableValues.Scale.convertTo(Scale.MiB, sizeInBytes); - series.add(new FixedMillisecond(timeData.getTimeInMillis()), sizeInMegaBytes, false); - } - } - series.fireSeriesChanged(); - } - }); - } - - @Override - public void clearMemoryData(final String tag) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - TimeSeries series = dataset.get(tag); - series.clear(); - } - }); - } - - @Override - public void addGraphVisibilityListener(GraphVisibilityChangeListener listener) { - listeners.add(listener); - } - - @Override - public void removeGraphVisibilityListener(GraphVisibilityChangeListener listener) { - listeners.remove(listener); - } - - @Override - public void addActionListener(ActionListener<Action> listener) { - notifier.addActionListener(listener); - } - - @Override - public void removeActionListener(ActionListener<Action> listener) { - notifier.removeActionListener(listener); - } - - private void initializePanel() { - visiblePanel = new JPanel(); - visiblePanel.setOpaque(false); - - chart = createMemoryChart(); - - JPanel chartPanel = new RecentTimeSeriesChartPanel(new RecentTimeSeriesChartController(chart)); - chartPanel.setOpaque(false); - - JLabel lblMemory = Components.header(translator.localize(LocaleResources.HOST_MEMORY_SECTION_OVERVIEW)); - - JLabel totalMemoryLabel = Components.label(translator.localize(LocaleResources.HOST_INFO_MEMORY_TOTAL)); - - memoryCheckBoxPanel.setOpaque(false); - - GroupLayout groupLayout = new GroupLayout(visiblePanel); - groupLayout.setHorizontalGroup( - groupLayout.createParallelGroup(Alignment.LEADING) - .addGroup(groupLayout.createSequentialGroup() - .addContainerGap() - .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) - .addComponent(chartPanel, GroupLayout.DEFAULT_SIZE, 883, Short.MAX_VALUE) - .addGroup(groupLayout.createSequentialGroup() - .addGap(12) - .addComponent(totalMemoryLabel) - .addPreferredGap(ComponentPlacement.RELATED) - .addComponent(totalMemory, GroupLayout.DEFAULT_SIZE, 751, Short.MAX_VALUE)) - .addComponent(lblMemory) - .addComponent(memoryCheckBoxPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)) - .addContainerGap()) - ); - groupLayout.setVerticalGroup( - groupLayout.createParallelGroup(Alignment.LEADING) - .addGroup(groupLayout.createSequentialGroup() - .addContainerGap() - .addComponent(lblMemory) - .addPreferredGap(ComponentPlacement.RELATED) - .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE) - .addComponent(totalMemory, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addComponent(totalMemoryLabel)) - .addPreferredGap(ComponentPlacement.RELATED) - .addComponent(chartPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) - .addPreferredGap(ComponentPlacement.RELATED) - .addComponent(memoryCheckBoxPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - ); - visiblePanel.setLayout(groupLayout); - } - - private JFreeChart createMemoryChart() { - JFreeChart chart = ChartFactory.createTimeSeriesChart( - translator.localize(LocaleResources.HOST_MEMORY_CHART_TITLE), // Title - translator.localize(LocaleResources.HOST_MEMORY_CHART_TIME_LABEL), // x-axis Label - translator.localize(LocaleResources.HOST_MEMORY_CHART_SIZE_LABEL, Scale.MiB.name()), // y-axis Label - memoryCollection, // Dataset - false, // Show Legend - false, // Use tooltips - false // Configure chart to generate URLs? - ); - - chart.getPlot().setBackgroundPaint( new Color(255,255,255,0) ); - chart.getPlot().setBackgroundImageAlpha(0.0f); - chart.getPlot().setOutlinePaint(new Color(0,0,0,0)); - - NumberAxis rangeAxis = (NumberAxis) chart.getXYPlot().getRangeAxis(); - rangeAxis.setAutoRangeMinimumSize(100); - - return chart; - } - - private void fireShowHideHandlers(boolean show, String tag) { - for (GraphVisibilityChangeListener listener: listeners) { - if (show) { - listener.show(tag); - } else { - listener.hide(tag); - } - } - } - - /** - * Adding or removing series to the series collection may change the order - * of existing items. Plus the paint for the index is now out-of-date. So - * let's walk through all the series and set the right paint for those. - */ - private void updateColors() { - XYItemRenderer itemRenderer = chart.getXYPlot().getRenderer(); - for (int i = 0; i < memoryCollection.getSeriesCount(); i++) { - String tag = (String) memoryCollection.getSeriesKey(i); - Color color = colors.get(tag); - itemRenderer.setSeriesPaint(i, color); - } - } - - private class MemoryCheckboxListener implements java.awt.event.ActionListener { - @Override - public void actionPerformed(java.awt.event.ActionEvent e) { - JCheckBox source = (JCheckBox) e.getSource(); - fireShowHideHandlers(source.isSelected(), source.getActionCommand()); - } - - } -}
--- a/host-memory/client-swing/src/main/java/com/redhat/thermostat/host/memory/client/swing/SwingHostMemoryViewProvider.java Mon Dec 10 15:10:21 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +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.host.memory.client.swing; - -import com.redhat.thermostat.host.memory.client.core.HostMemoryView; -import com.redhat.thermostat.host.memory.client.core.HostMemoryViewProvider; - -public class SwingHostMemoryViewProvider implements HostMemoryViewProvider { - - @Override - public HostMemoryView createView() { - return new HostMemoryPanel(); - } - -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/host-memory/client-swing/src/main/java/com/redhat/thermostat/host/memory/client/swing/internal/Activator.java Mon Dec 10 10:24:20 2012 -0500 @@ -0,0 +1,59 @@ +/* + * 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.host.memory.client.swing.internal; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +import com.redhat.thermostat.host.memory.client.core.HostMemoryViewProvider; + +public class Activator implements BundleActivator { + + + @Override + public void start(final BundleContext context) throws Exception { + HostMemoryViewProvider viewProvider = new SwingHostMemoryViewProvider(); + // Unregistered on Activator.stop + context.registerService(HostMemoryViewProvider.class.getName(), viewProvider, null); + } + + @Override + public void stop(BundleContext context) throws Exception { + } + +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/host-memory/client-swing/src/main/java/com/redhat/thermostat/host/memory/client/swing/internal/HostMemoryPanel.java Mon Dec 10 10:24:20 2012 -0500 @@ -0,0 +1,354 @@ +/* + * 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.host.memory.client.swing.internal; + +import java.awt.Color; +import java.awt.Component; +import java.awt.FlowLayout; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CopyOnWriteArrayList; + +import javax.swing.GroupLayout; +import javax.swing.GroupLayout.Alignment; +import javax.swing.JCheckBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.LayoutStyle.ComponentPlacement; +import javax.swing.SwingUtilities; +import javax.swing.text.JTextComponent; + +import org.jfree.chart.ChartFactory; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.NumberAxis; +import org.jfree.chart.renderer.xy.XYItemRenderer; +import org.jfree.data.time.FixedMillisecond; +import org.jfree.data.time.RegularTimePeriod; +import org.jfree.data.time.TimeSeries; +import org.jfree.data.time.TimeSeriesCollection; + +import com.redhat.thermostat.client.swing.SwingComponent; +import com.redhat.thermostat.client.swing.components.Components; +import com.redhat.thermostat.client.swing.components.RecentTimeSeriesChartPanel; +import com.redhat.thermostat.client.swing.components.ValueField; +import com.redhat.thermostat.client.ui.ChartColors; +import com.redhat.thermostat.client.ui.ComponentVisibleListener; +import com.redhat.thermostat.client.ui.RecentTimeSeriesChartController; +import com.redhat.thermostat.common.ActionListener; +import com.redhat.thermostat.common.locale.Translate; +import com.redhat.thermostat.common.utils.DisplayableValues; +import com.redhat.thermostat.common.utils.DisplayableValues.Scale; +import com.redhat.thermostat.host.memory.client.core.HostMemoryView; +import com.redhat.thermostat.host.memory.client.locale.LocaleResources; +import com.redhat.thermostat.storage.model.DiscreteTimeData; +import com.redhat.thermostat.swing.components.experimental.WrapLayout; + +public class HostMemoryPanel extends HostMemoryView implements SwingComponent { + + private static final Translate<LocaleResources> translator = LocaleResources.createLocalizer(); + + private JPanel visiblePanel; + + private final MemoryCheckboxListener memoryCheckboxListener = new MemoryCheckboxListener(); + + private final JTextComponent totalMemory = new ValueField("${TOTAL_MEMORY}"); + + private final JPanel memoryCheckBoxPanel = new JPanel(new WrapLayout(FlowLayout.LEADING)); + private final CopyOnWriteArrayList<GraphVisibilityChangeListener> listeners = new CopyOnWriteArrayList<>(); + private final TimeSeriesCollection memoryCollection = new TimeSeriesCollection(); + private final Map<String, TimeSeries> dataset = new HashMap<>(); + private final Map<String, JCheckBox> checkBoxes = new HashMap<>(); + private final Map<String, Color> colors = new HashMap<>(); + + private JFreeChart chart; + + public HostMemoryPanel() { + 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); + } + }); + } + + @Override + public void setTotalMemory(final String newValue) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + totalMemory.setText(newValue); + } + }); + } + + @Override + public Component getUiComponent() { + return visiblePanel; + } + + @Override + public void addMemoryChart(final String tag, final String humanReadableName) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + int colorIndex = colors.size(); + colors.put(tag, ChartColors.getColor(colorIndex)); + TimeSeries series = new TimeSeries(tag); + dataset.put(tag, series); + JCheckBox newCheckBox = new JCheckBox(createLabelWithLegend(humanReadableName, colors.get(tag))); + newCheckBox.setActionCommand(tag); + newCheckBox.setSelected(true); + newCheckBox.addActionListener(memoryCheckboxListener); + newCheckBox.setOpaque(false); + checkBoxes.put(tag, newCheckBox); + memoryCheckBoxPanel.add(newCheckBox); + + updateColors(); + } + }); + + } + + private String createLabelWithLegend(String text, Color color) { + String hexColor = "#" + Integer.toHexString(color.getRGB() & 0x00ffffff); + return "<html> <font color='" + hexColor + "'>\u2588</font> " + text + "</html>"; + } + + @Override + public void removeMemoryChart(final String tag) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + TimeSeries series = dataset.remove(tag); + memoryCollection.removeSeries(series); + JCheckBox box = checkBoxes.remove(tag); + memoryCheckBoxPanel.remove(box); + + updateColors(); + } + }); + } + + @Override + public void showMemoryChart(final String tag) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + TimeSeries series = dataset.get(tag); + memoryCollection.addSeries(series); + + updateColors(); + } + }); + } + + @Override + public void hideMemoryChart(final String tag) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + TimeSeries series = dataset.get(tag); + memoryCollection.removeSeries(series); + + updateColors(); + } + }); + } + + @Override + public void addMemoryData(final String tag, List<DiscreteTimeData<? extends Number>> data) { + final List<DiscreteTimeData<? extends Number>> copy = new ArrayList<>(data); + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + final TimeSeries series = dataset.get(tag); + for (DiscreteTimeData<? extends Number> timeData: copy) { + RegularTimePeriod period = new FixedMillisecond(timeData.getTimeInMillis()); + if (series.getDataItem(period) == null) { + Long sizeInBytes = (Long) timeData.getData(); + Double sizeInMegaBytes = DisplayableValues.Scale.convertTo(Scale.MiB, sizeInBytes); + series.add(new FixedMillisecond(timeData.getTimeInMillis()), sizeInMegaBytes, false); + } + } + series.fireSeriesChanged(); + } + }); + } + + @Override + public void clearMemoryData(final String tag) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + TimeSeries series = dataset.get(tag); + series.clear(); + } + }); + } + + @Override + public void addGraphVisibilityListener(GraphVisibilityChangeListener listener) { + listeners.add(listener); + } + + @Override + public void removeGraphVisibilityListener(GraphVisibilityChangeListener listener) { + listeners.remove(listener); + } + + @Override + public void addActionListener(ActionListener<Action> listener) { + notifier.addActionListener(listener); + } + + @Override + public void removeActionListener(ActionListener<Action> listener) { + notifier.removeActionListener(listener); + } + + private void initializePanel() { + visiblePanel = new JPanel(); + visiblePanel.setOpaque(false); + + chart = createMemoryChart(); + + JPanel chartPanel = new RecentTimeSeriesChartPanel(new RecentTimeSeriesChartController(chart)); + chartPanel.setOpaque(false); + + JLabel lblMemory = Components.header(translator.localize(LocaleResources.HOST_MEMORY_SECTION_OVERVIEW)); + + JLabel totalMemoryLabel = Components.label(translator.localize(LocaleResources.HOST_INFO_MEMORY_TOTAL)); + + memoryCheckBoxPanel.setOpaque(false); + + GroupLayout groupLayout = new GroupLayout(visiblePanel); + groupLayout.setHorizontalGroup( + groupLayout.createParallelGroup(Alignment.LEADING) + .addGroup(groupLayout.createSequentialGroup() + .addContainerGap() + .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) + .addComponent(chartPanel, GroupLayout.DEFAULT_SIZE, 883, Short.MAX_VALUE) + .addGroup(groupLayout.createSequentialGroup() + .addGap(12) + .addComponent(totalMemoryLabel) + .addPreferredGap(ComponentPlacement.RELATED) + .addComponent(totalMemory, GroupLayout.DEFAULT_SIZE, 751, Short.MAX_VALUE)) + .addComponent(lblMemory) + .addComponent(memoryCheckBoxPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)) + .addContainerGap()) + ); + groupLayout.setVerticalGroup( + groupLayout.createParallelGroup(Alignment.LEADING) + .addGroup(groupLayout.createSequentialGroup() + .addContainerGap() + .addComponent(lblMemory) + .addPreferredGap(ComponentPlacement.RELATED) + .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE) + .addComponent(totalMemory, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(totalMemoryLabel)) + .addPreferredGap(ComponentPlacement.RELATED) + .addComponent(chartPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) + .addPreferredGap(ComponentPlacement.RELATED) + .addComponent(memoryCheckBoxPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE) + .addContainerGap()) + ); + visiblePanel.setLayout(groupLayout); + } + + private JFreeChart createMemoryChart() { + JFreeChart chart = ChartFactory.createTimeSeriesChart( + translator.localize(LocaleResources.HOST_MEMORY_CHART_TITLE), // Title + translator.localize(LocaleResources.HOST_MEMORY_CHART_TIME_LABEL), // x-axis Label + translator.localize(LocaleResources.HOST_MEMORY_CHART_SIZE_LABEL, Scale.MiB.name()), // y-axis Label + memoryCollection, // Dataset + false, // Show Legend + false, // Use tooltips + false // Configure chart to generate URLs? + ); + + chart.getPlot().setBackgroundPaint( new Color(255,255,255,0) ); + chart.getPlot().setBackgroundImageAlpha(0.0f); + chart.getPlot().setOutlinePaint(new Color(0,0,0,0)); + + NumberAxis rangeAxis = (NumberAxis) chart.getXYPlot().getRangeAxis(); + rangeAxis.setAutoRangeMinimumSize(100); + + return chart; + } + + private void fireShowHideHandlers(boolean show, String tag) { + for (GraphVisibilityChangeListener listener: listeners) { + if (show) { + listener.show(tag); + } else { + listener.hide(tag); + } + } + } + + /** + * Adding or removing series to the series collection may change the order + * of existing items. Plus the paint for the index is now out-of-date. So + * let's walk through all the series and set the right paint for those. + */ + private void updateColors() { + XYItemRenderer itemRenderer = chart.getXYPlot().getRenderer(); + for (int i = 0; i < memoryCollection.getSeriesCount(); i++) { + String tag = (String) memoryCollection.getSeriesKey(i); + Color color = colors.get(tag); + itemRenderer.setSeriesPaint(i, color); + } + } + + private class MemoryCheckboxListener implements java.awt.event.ActionListener { + @Override + public void actionPerformed(java.awt.event.ActionEvent e) { + JCheckBox source = (JCheckBox) e.getSource(); + fireShowHideHandlers(source.isSelected(), source.getActionCommand()); + } + + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/host-memory/client-swing/src/main/java/com/redhat/thermostat/host/memory/client/swing/internal/SwingHostMemoryViewProvider.java Mon Dec 10 10:24:20 2012 -0500 @@ -0,0 +1,49 @@ +/* + * 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.host.memory.client.swing.internal; + +import com.redhat.thermostat.host.memory.client.core.HostMemoryView; +import com.redhat.thermostat.host.memory.client.core.HostMemoryViewProvider; + +public class SwingHostMemoryViewProvider implements HostMemoryViewProvider { + + @Override + public HostMemoryView createView() { + return new HostMemoryPanel(); + } + +}
--- a/host-memory/client-swing/src/test/java/com/redhat/thermostat/host/memory/client/swing/ActivatorTest.java Mon Dec 10 15:10:21 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.host.memory.client.swing; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import com.redhat.thermostat.host.memory.client.core.HostMemoryViewProvider; -import com.redhat.thermostat.test.StubBundleContext; - -public class ActivatorTest { - - @Test - public void verifyStartRegistersViewProvider() throws Exception { - StubBundleContext ctx = new StubBundleContext(); - Activator activator = new Activator(); - activator.start(ctx); - assertTrue(ctx.isServiceRegistered(HostMemoryViewProvider.class.getName(), SwingHostMemoryViewProvider.class)); - assertEquals(1, ctx.getAllServices().size()); - } - -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/host-memory/client-swing/src/test/java/com/redhat/thermostat/host/memory/client/swing/internal/ActivatorTest.java Mon Dec 10 10:24:20 2012 -0500 @@ -0,0 +1,60 @@ +/* + * 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.host.memory.client.swing.internal; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import com.redhat.thermostat.host.memory.client.core.HostMemoryViewProvider; +import com.redhat.thermostat.host.memory.client.swing.internal.Activator; +import com.redhat.thermostat.host.memory.client.swing.internal.SwingHostMemoryViewProvider; +import com.redhat.thermostat.test.StubBundleContext; + +public class ActivatorTest { + + @Test + public void verifyStartRegistersViewProvider() throws Exception { + StubBundleContext ctx = new StubBundleContext(); + Activator activator = new Activator(); + activator.start(ctx); + assertTrue(ctx.isServiceRegistered(HostMemoryViewProvider.class.getName(), SwingHostMemoryViewProvider.class)); + assertEquals(1, ctx.getAllServices().size()); + } + +}
--- a/host-overview/client-swing/pom.xml Mon Dec 10 15:10:21 2012 +0100 +++ b/host-overview/client-swing/pom.xml Mon Dec 10 10:24:20 2012 -0500 @@ -17,8 +17,8 @@ <extensions>true</extensions> <configuration> <instructions> - <Private-Package>com.redhat.thermostat.host.overview.client.swing</Private-Package> - <Bundle-Activator>com.redhat.thermostat.host.overview.client.swing.Activator</Bundle-Activator> + <Private-Package>com.redhat.thermostat.host.overview.client.swing.internal</Private-Package> + <Bundle-Activator>com.redhat.thermostat.host.overview.client.swing.internal.Activator</Bundle-Activator> <Bundle-Vendor>Red Hat, Inc.</Bundle-Vendor> <Bundle-SymbolicName>com.redhat.thermostat.host.overview.client.swing</Bundle-SymbolicName> <!-- Do not autogenerate uses clauses in Manifests -->
--- a/host-overview/client-swing/src/main/java/com/redhat/thermostat/host/overview/client/swing/Activator.java Mon Dec 10 15:10:21 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.host.overview.client.swing; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; - -import com.redhat.thermostat.host.overview.client.core.HostOverviewViewProvider; - -public class Activator implements BundleActivator { - - @Override - public void start(final BundleContext context) throws Exception { - HostOverviewViewProvider viewProvider = new SwingHostOverviewViewProvider(); - // Unregistered on Activator.stop - context.registerService(HostOverviewViewProvider.class.getName(), viewProvider, null); - } - - @Override - public void stop(BundleContext context) throws Exception { - } - -} -
--- a/host-overview/client-swing/src/main/java/com/redhat/thermostat/host/overview/client/swing/HostOverviewPanel.java Mon Dec 10 15:10:21 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,314 +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.host.overview.client.swing; - -import java.awt.BorderLayout; -import java.awt.Component; - -import javax.swing.GroupLayout; -import javax.swing.GroupLayout.Alignment; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.LayoutStyle.ComponentPlacement; -import javax.swing.SwingUtilities; -import javax.swing.table.DefaultTableModel; -import javax.swing.table.JTableHeader; - -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.ui.ComponentVisibleListener; -import com.redhat.thermostat.common.ActionListener; -import com.redhat.thermostat.common.locale.Translate; -import com.redhat.thermostat.host.overview.client.core.HostOverviewView; -import com.redhat.thermostat.host.overview.client.locale.LocaleResources; - -public class HostOverviewPanel extends HostOverviewView implements SwingComponent { - - private static final Translate<LocaleResources> translator = LocaleResources.createLocalizer(); - - private JPanel visiblePanel; - private JScrollPane scrollPane; - - private final ValueField hostname = new ValueField("${hostname}"); - private final ValueField cpuModel = new ValueField("${cpu-model}"); - private final ValueField cpuCount = new ValueField("${cpu-count}"); - private final ValueField totalMemory = new ValueField("${total-memory}"); - private final ValueField osName = new ValueField("${os-name}"); - private final ValueField osKernel = new ValueField("${os-kernel}"); - - private final DefaultTableModel networkTableModel = new DefaultTableModel() { - @Override - public boolean isCellEditable(int row, int column) { - return false; - } - }; - - private Object[] networkTableColumns; - private Object[][] networkTableData; - - public HostOverviewPanel() { - 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); - } - }); - } - - @Override - public void addActionListener(ActionListener<Action> listener) { - notifier.addActionListener(listener); - } - - @Override - public void removeActionListener(ActionListener<Action> listener) { - notifier.removeActionListener(listener); - } - - @Override - public void setHostName(final String newHostName) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - hostname.setText(newHostName); - } - }); - } - - @Override - public void setCpuModel(final String newCpuModel) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - cpuModel.setText(newCpuModel); - } - }); - } - - @Override - public void setCpuCount(final String newCpuCount) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - cpuCount.setText(newCpuCount); - } - }); - } - - @Override - public void setTotalMemory(final String newTotalMemory) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - totalMemory.setText(newTotalMemory); - } - }); - } - - @Override - public void setOsName(final String newOsName) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - osName.setText(newOsName); - } - }); - } - - @Override - public void setOsKernel(final String newOsKernel) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - osKernel.setText(newOsKernel); - } - }); - } - - @Override - public void setNetworkTableColumns(final Object[] columns) { - this.networkTableColumns = columns; - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - networkTableModel.setColumnIdentifiers(networkTableColumns); - } - }); - } - - @Override - public void setInitialNetworkTableData(final Object[][] data) { - this.networkTableData = data; - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - networkTableModel.setDataVector(networkTableData, networkTableColumns); - } - }); - } - - @Override - public void updateNetworkTableData(final int row, final int column, final String data) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - networkTableModel.setValueAt(data, row, column); - } - }); - } - - @Override - public Component getUiComponent() { - return scrollPane; - } - - private void initializePanel() { - visiblePanel = new JPanel(); - SectionHeader overviewSection = new SectionHeader(translator.localize(LocaleResources.HOST_OVERVIEW_SECTION_BASICS)); - LabelField hostnameLabel = new LabelField(translator.localize(LocaleResources.HOST_INFO_HOSTNAME)); - SectionHeader hardwareSection = new SectionHeader(translator.localize(LocaleResources.HOST_OVERVIEW_SECTION_HARDWARE)); - LabelField cpuModelLabel = new LabelField(translator.localize(LocaleResources.HOST_INFO_CPU_MODEL)); - LabelField cpuCountLabel = new LabelField(translator.localize(LocaleResources.HOST_INFO_CPU_COUNT)); - LabelField memoryTotalLabel = new LabelField(translator.localize(LocaleResources.HOST_INFO_MEMORY_TOTAL)); - LabelField networkLabel = new LabelField(translator.localize(LocaleResources.HOST_INFO_NETWORK)); - SectionHeader softwareSection = new SectionHeader(translator.localize(LocaleResources.HOST_OVERVIEW_SECTION_SOFTWARE)); - LabelField osNameLabel = new LabelField(translator.localize(LocaleResources.HOST_INFO_OS_NAME)); - LabelField osKernelLabel = new LabelField(translator.localize(LocaleResources.HOST_INFO_OS_KERNEL)); - - JPanel panel = new JPanel(); - - GroupLayout gl_visiblePanel = new GroupLayout(visiblePanel); - gl_visiblePanel.setHorizontalGroup( - gl_visiblePanel.createParallelGroup(Alignment.LEADING) - .addGroup(gl_visiblePanel.createSequentialGroup() - .addContainerGap() - .addGroup(gl_visiblePanel.createParallelGroup(Alignment.LEADING) - .addComponent(hardwareSection, GroupLayout.DEFAULT_SIZE, 620, Short.MAX_VALUE) - .addComponent(overviewSection, GroupLayout.DEFAULT_SIZE, 620, Short.MAX_VALUE) - .addGroup(gl_visiblePanel.createSequentialGroup() - .addGroup(gl_visiblePanel.createParallelGroup(Alignment.TRAILING, false) - .addGroup(gl_visiblePanel.createSequentialGroup() - .addGap(12) - .addComponent(hostnameLabel, GroupLayout.DEFAULT_SIZE, 134, Short.MAX_VALUE)) - .addComponent(cpuCountLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(cpuModelLabel, GroupLayout.DEFAULT_SIZE, 134, Short.MAX_VALUE) - .addComponent(memoryTotalLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(gl_visiblePanel.createSequentialGroup() - .addGap(12) - .addComponent(networkLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) - .addPreferredGap(ComponentPlacement.RELATED) - .addGroup(gl_visiblePanel.createParallelGroup(Alignment.LEADING) - .addComponent(panel, GroupLayout.DEFAULT_SIZE, 462, Short.MAX_VALUE) - .addComponent(cpuCount, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(cpuModel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(hostname, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(totalMemory, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) - .addComponent(softwareSection, GroupLayout.DEFAULT_SIZE, 620, Short.MAX_VALUE) - .addGroup(gl_visiblePanel.createSequentialGroup() - .addGap(12) - .addGroup(gl_visiblePanel.createParallelGroup(Alignment.LEADING, false) - .addComponent(osKernelLabel, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(osNameLabel, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 129, Short.MAX_VALUE)) - .addPreferredGap(ComponentPlacement.RELATED) - .addGroup(gl_visiblePanel.createParallelGroup(Alignment.LEADING) - .addComponent(osKernel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(osName, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) - .addContainerGap()) - ); - gl_visiblePanel.setVerticalGroup( - gl_visiblePanel.createParallelGroup(Alignment.LEADING) - .addGroup(gl_visiblePanel.createSequentialGroup() - .addContainerGap() - .addComponent(overviewSection, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(ComponentPlacement.RELATED) - .addGroup(gl_visiblePanel.createParallelGroup(Alignment.LEADING, false) - .addComponent(hostname, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE) - .addComponent(hostnameLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(ComponentPlacement.UNRELATED) - .addComponent(hardwareSection, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(ComponentPlacement.RELATED) - .addGroup(gl_visiblePanel.createParallelGroup(Alignment.LEADING, false) - .addComponent(cpuModelLabel, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE) - .addComponent(cpuModel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(ComponentPlacement.RELATED) - .addGroup(gl_visiblePanel.createParallelGroup(Alignment.LEADING, false) - .addComponent(cpuCountLabel, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE) - .addComponent(cpuCount, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(ComponentPlacement.RELATED) - .addGroup(gl_visiblePanel.createParallelGroup(Alignment.LEADING) - .addComponent(memoryTotalLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addComponent(totalMemory, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(ComponentPlacement.RELATED) - .addGroup(gl_visiblePanel.createParallelGroup(Alignment.LEADING) - .addComponent(networkLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addComponent(panel, GroupLayout.PREFERRED_SIZE, 109, GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(ComponentPlacement.RELATED) - .addComponent(softwareSection, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(ComponentPlacement.RELATED) - .addGroup(gl_visiblePanel.createParallelGroup(Alignment.LEADING) - .addComponent(osNameLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addComponent(osName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(ComponentPlacement.RELATED) - .addGroup(gl_visiblePanel.createParallelGroup(Alignment.LEADING) - .addComponent(osKernelLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addComponent(osKernel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) - .addGap(128)) - ); - - panel.setLayout(new BorderLayout(0, 0)); - - JTable networkTable = new JTable(networkTableModel); - panel.add(networkTable); - JTableHeader header = networkTable.getTableHeader(); - panel.add(header, BorderLayout.PAGE_START); - - visiblePanel.setLayout(gl_visiblePanel); - - scrollPane = new JScrollPane(visiblePanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - } -}
--- a/host-overview/client-swing/src/main/java/com/redhat/thermostat/host/overview/client/swing/SwingHostOverviewViewProvider.java Mon Dec 10 15:10:21 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +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.host.overview.client.swing; - -import com.redhat.thermostat.host.overview.client.core.HostOverviewView; -import com.redhat.thermostat.host.overview.client.core.HostOverviewViewProvider; - -public class SwingHostOverviewViewProvider implements HostOverviewViewProvider { - - @Override - public HostOverviewView createView() { - return new HostOverviewPanel(); - } - -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/host-overview/client-swing/src/main/java/com/redhat/thermostat/host/overview/client/swing/internal/Activator.java Mon Dec 10 10:24:20 2012 -0500 @@ -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.host.overview.client.swing.internal; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +import com.redhat.thermostat.host.overview.client.core.HostOverviewViewProvider; + +public class Activator implements BundleActivator { + + @Override + public void start(final BundleContext context) throws Exception { + HostOverviewViewProvider viewProvider = new SwingHostOverviewViewProvider(); + // Unregistered on Activator.stop + context.registerService(HostOverviewViewProvider.class.getName(), viewProvider, null); + } + + @Override + public void stop(BundleContext context) throws Exception { + } + +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/host-overview/client-swing/src/main/java/com/redhat/thermostat/host/overview/client/swing/internal/HostOverviewPanel.java Mon Dec 10 10:24:20 2012 -0500 @@ -0,0 +1,314 @@ +/* + * 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.host.overview.client.swing.internal; + +import java.awt.BorderLayout; +import java.awt.Component; + +import javax.swing.GroupLayout; +import javax.swing.GroupLayout.Alignment; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.LayoutStyle.ComponentPlacement; +import javax.swing.SwingUtilities; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.JTableHeader; + +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.ui.ComponentVisibleListener; +import com.redhat.thermostat.common.ActionListener; +import com.redhat.thermostat.common.locale.Translate; +import com.redhat.thermostat.host.overview.client.core.HostOverviewView; +import com.redhat.thermostat.host.overview.client.locale.LocaleResources; + +public class HostOverviewPanel extends HostOverviewView implements SwingComponent { + + private static final Translate<LocaleResources> translator = LocaleResources.createLocalizer(); + + private JPanel visiblePanel; + private JScrollPane scrollPane; + + private final ValueField hostname = new ValueField("${hostname}"); + private final ValueField cpuModel = new ValueField("${cpu-model}"); + private final ValueField cpuCount = new ValueField("${cpu-count}"); + private final ValueField totalMemory = new ValueField("${total-memory}"); + private final ValueField osName = new ValueField("${os-name}"); + private final ValueField osKernel = new ValueField("${os-kernel}"); + + private final DefaultTableModel networkTableModel = new DefaultTableModel() { + @Override + public boolean isCellEditable(int row, int column) { + return false; + } + }; + + private Object[] networkTableColumns; + private Object[][] networkTableData; + + public HostOverviewPanel() { + 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); + } + }); + } + + @Override + public void addActionListener(ActionListener<Action> listener) { + notifier.addActionListener(listener); + } + + @Override + public void removeActionListener(ActionListener<Action> listener) { + notifier.removeActionListener(listener); + } + + @Override + public void setHostName(final String newHostName) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + hostname.setText(newHostName); + } + }); + } + + @Override + public void setCpuModel(final String newCpuModel) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + cpuModel.setText(newCpuModel); + } + }); + } + + @Override + public void setCpuCount(final String newCpuCount) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + cpuCount.setText(newCpuCount); + } + }); + } + + @Override + public void setTotalMemory(final String newTotalMemory) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + totalMemory.setText(newTotalMemory); + } + }); + } + + @Override + public void setOsName(final String newOsName) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + osName.setText(newOsName); + } + }); + } + + @Override + public void setOsKernel(final String newOsKernel) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + osKernel.setText(newOsKernel); + } + }); + } + + @Override + public void setNetworkTableColumns(final Object[] columns) { + this.networkTableColumns = columns; + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + networkTableModel.setColumnIdentifiers(networkTableColumns); + } + }); + } + + @Override + public void setInitialNetworkTableData(final Object[][] data) { + this.networkTableData = data; + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + networkTableModel.setDataVector(networkTableData, networkTableColumns); + } + }); + } + + @Override + public void updateNetworkTableData(final int row, final int column, final String data) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + networkTableModel.setValueAt(data, row, column); + } + }); + } + + @Override + public Component getUiComponent() { + return scrollPane; + } + + private void initializePanel() { + visiblePanel = new JPanel(); + SectionHeader overviewSection = new SectionHeader(translator.localize(LocaleResources.HOST_OVERVIEW_SECTION_BASICS)); + LabelField hostnameLabel = new LabelField(translator.localize(LocaleResources.HOST_INFO_HOSTNAME)); + SectionHeader hardwareSection = new SectionHeader(translator.localize(LocaleResources.HOST_OVERVIEW_SECTION_HARDWARE)); + LabelField cpuModelLabel = new LabelField(translator.localize(LocaleResources.HOST_INFO_CPU_MODEL)); + LabelField cpuCountLabel = new LabelField(translator.localize(LocaleResources.HOST_INFO_CPU_COUNT)); + LabelField memoryTotalLabel = new LabelField(translator.localize(LocaleResources.HOST_INFO_MEMORY_TOTAL)); + LabelField networkLabel = new LabelField(translator.localize(LocaleResources.HOST_INFO_NETWORK)); + SectionHeader softwareSection = new SectionHeader(translator.localize(LocaleResources.HOST_OVERVIEW_SECTION_SOFTWARE)); + LabelField osNameLabel = new LabelField(translator.localize(LocaleResources.HOST_INFO_OS_NAME)); + LabelField osKernelLabel = new LabelField(translator.localize(LocaleResources.HOST_INFO_OS_KERNEL)); + + JPanel panel = new JPanel(); + + GroupLayout gl_visiblePanel = new GroupLayout(visiblePanel); + gl_visiblePanel.setHorizontalGroup( + gl_visiblePanel.createParallelGroup(Alignment.LEADING) + .addGroup(gl_visiblePanel.createSequentialGroup() + .addContainerGap() + .addGroup(gl_visiblePanel.createParallelGroup(Alignment.LEADING) + .addComponent(hardwareSection, GroupLayout.DEFAULT_SIZE, 620, Short.MAX_VALUE) + .addComponent(overviewSection, GroupLayout.DEFAULT_SIZE, 620, Short.MAX_VALUE) + .addGroup(gl_visiblePanel.createSequentialGroup() + .addGroup(gl_visiblePanel.createParallelGroup(Alignment.TRAILING, false) + .addGroup(gl_visiblePanel.createSequentialGroup() + .addGap(12) + .addComponent(hostnameLabel, GroupLayout.DEFAULT_SIZE, 134, Short.MAX_VALUE)) + .addComponent(cpuCountLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(cpuModelLabel, GroupLayout.DEFAULT_SIZE, 134, Short.MAX_VALUE) + .addComponent(memoryTotalLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(gl_visiblePanel.createSequentialGroup() + .addGap(12) + .addComponent(networkLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) + .addPreferredGap(ComponentPlacement.RELATED) + .addGroup(gl_visiblePanel.createParallelGroup(Alignment.LEADING) + .addComponent(panel, GroupLayout.DEFAULT_SIZE, 462, Short.MAX_VALUE) + .addComponent(cpuCount, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(cpuModel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(hostname, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(totalMemory, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) + .addComponent(softwareSection, GroupLayout.DEFAULT_SIZE, 620, Short.MAX_VALUE) + .addGroup(gl_visiblePanel.createSequentialGroup() + .addGap(12) + .addGroup(gl_visiblePanel.createParallelGroup(Alignment.LEADING, false) + .addComponent(osKernelLabel, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(osNameLabel, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 129, Short.MAX_VALUE)) + .addPreferredGap(ComponentPlacement.RELATED) + .addGroup(gl_visiblePanel.createParallelGroup(Alignment.LEADING) + .addComponent(osKernel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(osName, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) + .addContainerGap()) + ); + gl_visiblePanel.setVerticalGroup( + gl_visiblePanel.createParallelGroup(Alignment.LEADING) + .addGroup(gl_visiblePanel.createSequentialGroup() + .addContainerGap() + .addComponent(overviewSection, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(ComponentPlacement.RELATED) + .addGroup(gl_visiblePanel.createParallelGroup(Alignment.LEADING, false) + .addComponent(hostname, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE) + .addComponent(hostnameLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(ComponentPlacement.UNRELATED) + .addComponent(hardwareSection, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(ComponentPlacement.RELATED) + .addGroup(gl_visiblePanel.createParallelGroup(Alignment.LEADING, false) + .addComponent(cpuModelLabel, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE) + .addComponent(cpuModel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(ComponentPlacement.RELATED) + .addGroup(gl_visiblePanel.createParallelGroup(Alignment.LEADING, false) + .addComponent(cpuCountLabel, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE) + .addComponent(cpuCount, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(ComponentPlacement.RELATED) + .addGroup(gl_visiblePanel.createParallelGroup(Alignment.LEADING) + .addComponent(memoryTotalLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(totalMemory, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(ComponentPlacement.RELATED) + .addGroup(gl_visiblePanel.createParallelGroup(Alignment.LEADING) + .addComponent(networkLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(panel, GroupLayout.PREFERRED_SIZE, 109, GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(ComponentPlacement.RELATED) + .addComponent(softwareSection, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(ComponentPlacement.RELATED) + .addGroup(gl_visiblePanel.createParallelGroup(Alignment.LEADING) + .addComponent(osNameLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(osName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(ComponentPlacement.RELATED) + .addGroup(gl_visiblePanel.createParallelGroup(Alignment.LEADING) + .addComponent(osKernelLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(osKernel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) + .addGap(128)) + ); + + panel.setLayout(new BorderLayout(0, 0)); + + JTable networkTable = new JTable(networkTableModel); + panel.add(networkTable); + JTableHeader header = networkTable.getTableHeader(); + panel.add(header, BorderLayout.PAGE_START); + + visiblePanel.setLayout(gl_visiblePanel); + + scrollPane = new JScrollPane(visiblePanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/host-overview/client-swing/src/main/java/com/redhat/thermostat/host/overview/client/swing/internal/SwingHostOverviewViewProvider.java Mon Dec 10 10:24:20 2012 -0500 @@ -0,0 +1,49 @@ +/* + * 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.host.overview.client.swing.internal; + +import com.redhat.thermostat.host.overview.client.core.HostOverviewView; +import com.redhat.thermostat.host.overview.client.core.HostOverviewViewProvider; + +public class SwingHostOverviewViewProvider implements HostOverviewViewProvider { + + @Override + public HostOverviewView createView() { + return new HostOverviewPanel(); + } + +}
--- a/host-overview/client-swing/src/test/java/com/redhat/thermostat/host/overview/client/swing/ActivatorTest.java Mon Dec 10 15:10:21 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.host.overview.client.swing; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import com.redhat.thermostat.host.overview.client.core.HostOverviewViewProvider; -import com.redhat.thermostat.test.StubBundleContext; - -public class ActivatorTest { - - @Test - public void verifyStartRegistersViewProvider() throws Exception { - StubBundleContext ctx = new StubBundleContext(); - Activator activator = new Activator(); - activator.start(ctx); - assertTrue(ctx.isServiceRegistered(HostOverviewViewProvider.class.getName(), SwingHostOverviewViewProvider.class)); - assertEquals(1, ctx.getAllServices().size()); - } - -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/host-overview/client-swing/src/test/java/com/redhat/thermostat/host/overview/client/swing/internal/ActivatorTest.java Mon Dec 10 10:24:20 2012 -0500 @@ -0,0 +1,60 @@ +/* + * 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.host.overview.client.swing.internal; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import com.redhat.thermostat.host.overview.client.core.HostOverviewViewProvider; +import com.redhat.thermostat.host.overview.client.swing.internal.Activator; +import com.redhat.thermostat.host.overview.client.swing.internal.SwingHostOverviewViewProvider; +import com.redhat.thermostat.test.StubBundleContext; + +public class ActivatorTest { + + @Test + public void verifyStartRegistersViewProvider() throws Exception { + StubBundleContext ctx = new StubBundleContext(); + Activator activator = new Activator(); + activator.start(ctx); + assertTrue(ctx.isServiceRegistered(HostOverviewViewProvider.class.getName(), SwingHostOverviewViewProvider.class)); + assertEquals(1, ctx.getAllServices().size()); + } + +}
--- a/vm-cpu/client-swing/pom.xml Mon Dec 10 15:10:21 2012 +0100 +++ b/vm-cpu/client-swing/pom.xml Mon Dec 10 10:24:20 2012 -0500 @@ -17,8 +17,8 @@ <extensions>true</extensions> <configuration> <instructions> - <Private-Package>com.redhat.thermostat.vm.cpu.client.swing</Private-Package> - <Bundle-Activator>com.redhat.thermostat.vm.cpu.client.swing.Activator</Bundle-Activator> + <Private-Package>com.redhat.thermostat.vm.cpu.client.swing.internal</Private-Package> + <Bundle-Activator>com.redhat.thermostat.vm.cpu.client.swing.internal.Activator</Bundle-Activator> <Bundle-Vendor>Red Hat, Inc.</Bundle-Vendor> <Bundle-SymbolicName>com.redhat.thermostat.vm.cpu.client.swing</Bundle-SymbolicName> <!-- Do not autogenerate uses clauses in Manifests -->
--- a/vm-cpu/client-swing/src/main/java/com/redhat/thermostat/vm/cpu/client/swing/Activator.java Mon Dec 10 15:10:21 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.vm.cpu.client.swing; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; - -import com.redhat.thermostat.vm.cpu.client.core.VmCpuViewProvider; - -public class Activator implements BundleActivator { - - @Override - public void start(final BundleContext context) throws Exception { - VmCpuViewProvider viewProvider = new SwingVmCpuViewProvider(); - // Unregistered on Activator.stop - context.registerService(VmCpuViewProvider.class.getName(), viewProvider, null); - } - - @Override - public void stop(BundleContext context) throws Exception { - } - -} -
--- a/vm-cpu/client-swing/src/main/java/com/redhat/thermostat/vm/cpu/client/swing/SwingVmCpuViewProvider.java Mon Dec 10 15:10:21 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +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.vm.cpu.client.swing; - -import com.redhat.thermostat.vm.cpu.client.core.VmCpuView; -import com.redhat.thermostat.vm.cpu.client.core.VmCpuViewProvider; - -public class SwingVmCpuViewProvider implements VmCpuViewProvider { - - @Override - public VmCpuView createView() { - return new VmCpuPanel(); - } - -}
--- a/vm-cpu/client-swing/src/main/java/com/redhat/thermostat/vm/cpu/client/swing/VmCpuPanel.java Mon Dec 10 15:10:21 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,151 +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.vm.cpu.client.swing; - -import java.awt.Component; -import java.util.ArrayList; -import java.util.List; - -import javax.swing.JPanel; -import javax.swing.SwingUtilities; - -import org.jfree.chart.ChartFactory; -import org.jfree.chart.JFreeChart; -import org.jfree.data.time.FixedMillisecond; -import org.jfree.data.time.RegularTimePeriod; -import org.jfree.data.time.TimeSeries; -import org.jfree.data.time.TimeSeriesCollection; - -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.ui.ComponentVisibleListener; -import com.redhat.thermostat.client.ui.RecentTimeSeriesChartController; -import com.redhat.thermostat.common.ActionListener; -import com.redhat.thermostat.common.locale.Translate; -import com.redhat.thermostat.storage.model.DiscreteTimeData; -import com.redhat.thermostat.vm.cpu.client.core.VmCpuView; -import com.redhat.thermostat.vm.cpu.client.locale.LocaleResources; - -public class VmCpuPanel extends VmCpuView implements SwingComponent { - - private static final Translate<LocaleResources> translator = LocaleResources.createLocalizer(); - - private HeaderPanel visiblePanel; - - private final TimeSeriesCollection data = new TimeSeriesCollection(); - private final TimeSeries cpuTimeSeries = new TimeSeries("cpu-stats"); - - public VmCpuPanel() { - super(); - data.addSeries(cpuTimeSeries); - - 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); - } - }); - } - - @Override - public void addActionListener(ActionListener<Action> listener) { - notifier.addActionListener(listener); - } - - @Override - public void removeActionListener(ActionListener<Action> listener) { - notifier.removeActionListener(listener); - } - - @Override - public Component getUiComponent() { - return visiblePanel; - } - - private void initializePanel() { - visiblePanel = new HeaderPanel(); - visiblePanel.setHeader(translator.localize(LocaleResources.VM_CPU_TITLE)); - - JFreeChart chart = ChartFactory.createTimeSeriesChart( - null, - translator.localize(LocaleResources.VM_CPU_CHART_TIME_LABEL), - translator.localize(LocaleResources.VM_CPU_CHART_LOAD_LABEL), - data, - false, false, false); - - chart.getXYPlot().getRangeAxis().setLowerBound(0.0); - - JPanel chartPanel = new RecentTimeSeriesChartPanel(new RecentTimeSeriesChartController(chart)); - - visiblePanel.setContent(chartPanel); - } - - @Override - public void addData(List<DiscreteTimeData<? extends Number>> data) { - final List<DiscreteTimeData<? extends Number>> copy = new ArrayList<>(data); - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - for (DiscreteTimeData<? extends Number> data: copy) { - RegularTimePeriod period = new FixedMillisecond(data.getTimeInMillis()); - if (cpuTimeSeries.getDataItem(period) == null) { - cpuTimeSeries.add(period, data.getData(), false); - } - } - cpuTimeSeries.fireSeriesChanged(); - } - }); - } - - @Override - public void clearData() { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - cpuTimeSeries.clear(); - } - }); - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-cpu/client-swing/src/main/java/com/redhat/thermostat/vm/cpu/client/swing/internal/Activator.java Mon Dec 10 10:24:20 2012 -0500 @@ -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.vm.cpu.client.swing.internal; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +import com.redhat.thermostat.vm.cpu.client.core.VmCpuViewProvider; + +public class Activator implements BundleActivator { + + @Override + public void start(final BundleContext context) throws Exception { + VmCpuViewProvider viewProvider = new SwingVmCpuViewProvider(); + // Unregistered on Activator.stop + context.registerService(VmCpuViewProvider.class.getName(), viewProvider, null); + } + + @Override + public void stop(BundleContext context) throws Exception { + } + +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-cpu/client-swing/src/main/java/com/redhat/thermostat/vm/cpu/client/swing/internal/SwingVmCpuViewProvider.java Mon Dec 10 10:24:20 2012 -0500 @@ -0,0 +1,49 @@ +/* + * 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.vm.cpu.client.swing.internal; + +import com.redhat.thermostat.vm.cpu.client.core.VmCpuView; +import com.redhat.thermostat.vm.cpu.client.core.VmCpuViewProvider; + +public class SwingVmCpuViewProvider implements VmCpuViewProvider { + + @Override + public VmCpuView createView() { + return new VmCpuPanel(); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-cpu/client-swing/src/main/java/com/redhat/thermostat/vm/cpu/client/swing/internal/VmCpuPanel.java Mon Dec 10 10:24:20 2012 -0500 @@ -0,0 +1,151 @@ +/* + * 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.vm.cpu.client.swing.internal; + +import java.awt.Component; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.JPanel; +import javax.swing.SwingUtilities; + +import org.jfree.chart.ChartFactory; +import org.jfree.chart.JFreeChart; +import org.jfree.data.time.FixedMillisecond; +import org.jfree.data.time.RegularTimePeriod; +import org.jfree.data.time.TimeSeries; +import org.jfree.data.time.TimeSeriesCollection; + +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.ui.ComponentVisibleListener; +import com.redhat.thermostat.client.ui.RecentTimeSeriesChartController; +import com.redhat.thermostat.common.ActionListener; +import com.redhat.thermostat.common.locale.Translate; +import com.redhat.thermostat.storage.model.DiscreteTimeData; +import com.redhat.thermostat.vm.cpu.client.core.VmCpuView; +import com.redhat.thermostat.vm.cpu.client.locale.LocaleResources; + +public class VmCpuPanel extends VmCpuView implements SwingComponent { + + private static final Translate<LocaleResources> translator = LocaleResources.createLocalizer(); + + private HeaderPanel visiblePanel; + + private final TimeSeriesCollection data = new TimeSeriesCollection(); + private final TimeSeries cpuTimeSeries = new TimeSeries("cpu-stats"); + + public VmCpuPanel() { + super(); + data.addSeries(cpuTimeSeries); + + 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); + } + }); + } + + @Override + public void addActionListener(ActionListener<Action> listener) { + notifier.addActionListener(listener); + } + + @Override + public void removeActionListener(ActionListener<Action> listener) { + notifier.removeActionListener(listener); + } + + @Override + public Component getUiComponent() { + return visiblePanel; + } + + private void initializePanel() { + visiblePanel = new HeaderPanel(); + visiblePanel.setHeader(translator.localize(LocaleResources.VM_CPU_TITLE)); + + JFreeChart chart = ChartFactory.createTimeSeriesChart( + null, + translator.localize(LocaleResources.VM_CPU_CHART_TIME_LABEL), + translator.localize(LocaleResources.VM_CPU_CHART_LOAD_LABEL), + data, + false, false, false); + + chart.getXYPlot().getRangeAxis().setLowerBound(0.0); + + JPanel chartPanel = new RecentTimeSeriesChartPanel(new RecentTimeSeriesChartController(chart)); + + visiblePanel.setContent(chartPanel); + } + + @Override + public void addData(List<DiscreteTimeData<? extends Number>> data) { + final List<DiscreteTimeData<? extends Number>> copy = new ArrayList<>(data); + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + for (DiscreteTimeData<? extends Number> data: copy) { + RegularTimePeriod period = new FixedMillisecond(data.getTimeInMillis()); + if (cpuTimeSeries.getDataItem(period) == null) { + cpuTimeSeries.add(period, data.getData(), false); + } + } + cpuTimeSeries.fireSeriesChanged(); + } + }); + } + + @Override + public void clearData() { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + cpuTimeSeries.clear(); + } + }); + } +}
--- a/vm-cpu/client-swing/src/test/java/com/redhat/thermostat/vm/cpu/client/swing/ActivatorTest.java Mon Dec 10 15:10:21 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.vm.cpu.client.swing; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import com.redhat.thermostat.test.StubBundleContext; -import com.redhat.thermostat.vm.cpu.client.core.VmCpuViewProvider; - -public class ActivatorTest { - - @Test - public void verifyStartRegistersViewProvider() throws Exception { - StubBundleContext ctx = new StubBundleContext(); - Activator activator = new Activator(); - activator.start(ctx); - assertTrue(ctx.isServiceRegistered(VmCpuViewProvider.class.getName(), SwingVmCpuViewProvider.class)); - assertEquals(1, ctx.getAllServices().size()); - } - -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-cpu/client-swing/src/test/java/com/redhat/thermostat/vm/cpu/client/swing/internal/ActivatorTest.java Mon Dec 10 10:24:20 2012 -0500 @@ -0,0 +1,60 @@ +/* + * 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.vm.cpu.client.swing.internal; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import com.redhat.thermostat.test.StubBundleContext; +import com.redhat.thermostat.vm.cpu.client.core.VmCpuViewProvider; +import com.redhat.thermostat.vm.cpu.client.swing.internal.Activator; +import com.redhat.thermostat.vm.cpu.client.swing.internal.SwingVmCpuViewProvider; + +public class ActivatorTest { + + @Test + public void verifyStartRegistersViewProvider() throws Exception { + StubBundleContext ctx = new StubBundleContext(); + Activator activator = new Activator(); + activator.start(ctx); + assertTrue(ctx.isServiceRegistered(VmCpuViewProvider.class.getName(), SwingVmCpuViewProvider.class)); + assertEquals(1, ctx.getAllServices().size()); + } + +}
--- a/vm-gc/client-swing/pom.xml Mon Dec 10 15:10:21 2012 +0100 +++ b/vm-gc/client-swing/pom.xml Mon Dec 10 10:24:20 2012 -0500 @@ -17,8 +17,8 @@ <extensions>true</extensions> <configuration> <instructions> - <Private-Package>com.redhat.thermostat.vm.gc.client.swing</Private-Package> - <Bundle-Activator>com.redhat.thermostat.vm.gc.client.swing.Activator</Bundle-Activator> + <Private-Package>com.redhat.thermostat.vm.gc.client.swing.internal</Private-Package> + <Bundle-Activator>com.redhat.thermostat.vm.gc.client.swing.internal.Activator</Bundle-Activator> <Bundle-Vendor>Red Hat, Inc.</Bundle-Vendor> <Bundle-SymbolicName>com.redhat.thermostat.vm.gc.client.swing</Bundle-SymbolicName> <!-- Do not autogenerate uses clauses in Manifests -->
--- a/vm-gc/client-swing/src/main/java/com/redhat/thermostat/vm/gc/client/swing/Activator.java Mon Dec 10 15:10:21 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.vm.gc.client.swing; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; - -import com.redhat.thermostat.vm.gc.client.core.VmGcViewProvider; - -public class Activator implements BundleActivator { - - @Override - public void start(final BundleContext context) throws Exception { - VmGcViewProvider viewProvider = new SwingVmGcViewProvider(); - // Unregistered on Activator.stop - context.registerService(VmGcViewProvider.class.getName(), viewProvider, null); - } - - @Override - public void stop(BundleContext context) throws Exception { - } - -} -
--- a/vm-gc/client-swing/src/main/java/com/redhat/thermostat/vm/gc/client/swing/SwingVmGcViewProvider.java Mon Dec 10 15:10:21 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +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.vm.gc.client.swing; - -import com.redhat.thermostat.vm.gc.client.core.VmGcView; -import com.redhat.thermostat.vm.gc.client.core.VmGcViewProvider; - -public class SwingVmGcViewProvider implements VmGcViewProvider { - - @Override - public VmGcView createView() { - return new VmGcPanel(); - } - -}
--- a/vm-gc/client-swing/src/main/java/com/redhat/thermostat/vm/gc/client/swing/VmGcPanel.java Mon Dec 10 15:10:21 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,250 +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.vm.gc.client.swing; - -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.swing.JPanel; -import javax.swing.SwingUtilities; - -import org.jfree.chart.ChartFactory; -import org.jfree.chart.JFreeChart; -import org.jfree.chart.axis.DateAxis; -import org.jfree.chart.axis.NumberAxis; -import org.jfree.chart.event.ChartProgressEvent; -import org.jfree.chart.event.ChartProgressListener; -import org.jfree.chart.plot.PlotOrientation; -import org.jfree.chart.plot.XYPlot; -import org.jfree.chart.renderer.xy.StandardXYBarPainter; -import org.jfree.chart.renderer.xy.XYBarRenderer; -import org.jfree.data.RangeType; -import org.jfree.data.xy.IntervalXYDataset; - -import com.redhat.thermostat.client.swing.SwingComponent; -import com.redhat.thermostat.client.swing.components.Components; -import com.redhat.thermostat.client.swing.components.HeaderPanel; -import com.redhat.thermostat.client.swing.components.RecentTimeSeriesChartPanel; -import com.redhat.thermostat.client.ui.ComponentVisibleListener; -import com.redhat.thermostat.client.ui.RecentTimeSeriesChartController; -import com.redhat.thermostat.client.ui.SampledDataset; -import com.redhat.thermostat.common.ActionListener; -import com.redhat.thermostat.common.locale.Translate; -import com.redhat.thermostat.storage.model.IntervalTimeData; -import com.redhat.thermostat.vm.gc.client.core.VmGcView; -import com.redhat.thermostat.vm.gc.client.locale.LocaleResources; - -public class VmGcPanel extends VmGcView implements SwingComponent { - - private static final Translate<LocaleResources> translator = LocaleResources.createLocalizer(); - - private HeaderPanel visiblePanel = new HeaderPanel(); - private JPanel realPanel = new JPanel(); - - private final Map<String, SampledDataset> dataset = new HashMap<>(); - private final Map<String, JPanel> subPanels = new HashMap<>(); - - private final GridBagConstraints gcPanelConstraints; - - public VmGcPanel() { - super(); - initializePanel(); - - gcPanelConstraints = new GridBagConstraints(); - gcPanelConstraints.gridx = 0; - gcPanelConstraints.gridy = 0; - gcPanelConstraints.fill = GridBagConstraints.BOTH; - 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); - } - }); - } - - @Override - public void addActionListener(ActionListener<Action> listener) { - notifier.addActionListener(listener); - } - - @Override - public void removeActionListener(ActionListener<Action> listener) { - notifier.removeActionListener(listener); - } - - @Override - public Component getUiComponent() { - return visiblePanel; - } - - private void initializePanel() { - visiblePanel.setContent(realPanel); - visiblePanel.setHeader(translator.localize(LocaleResources.VM_GC_TITLE)); - realPanel.setLayout(new GridBagLayout()); - } - - private JPanel createCollectorDetailsPanel(IntervalXYDataset collectorData, String title, String units) { - JPanel detailsPanel = new JPanel(); - detailsPanel.setBorder(Components.smallBorder()); - detailsPanel.setLayout(new BorderLayout()); - - detailsPanel.add(Components.header(title), BorderLayout.NORTH); - - JFreeChart chart = ChartFactory.createHistogram( - null, - translator.localize(LocaleResources.VM_GC_COLLECTOR_CHART_REAL_TIME_LABEL), - translator.localize(LocaleResources.VM_GC_COLLECTOR_CHART_GC_TIME_LABEL, units), - collectorData, - PlotOrientation.VERTICAL, - false, - false, - false); - - ((XYBarRenderer)(chart.getXYPlot().getRenderer())).setBarPainter(new StandardXYBarPainter()); - - setupPlotAxes(chart.getXYPlot()); - - chart.getXYPlot().setDomainCrosshairLockedOnData(true); - chart.getXYPlot().setDomainCrosshairVisible(true); - - final RecentTimeSeriesChartPanel chartPanel = new RecentTimeSeriesChartPanel(new RecentTimeSeriesChartController(chart)); - - chart.addProgressListener(new ChartProgressListener() { - - @Override - public void chartProgress(ChartProgressEvent event) { - if (event.getType() != ChartProgressEvent.DRAWING_FINISHED) { - return; - } - - double rangeCrossHairValue = event.getChart().getXYPlot().getRangeCrosshairValue(); - chartPanel.setDataInformationLabel(String.valueOf(rangeCrossHairValue)); - } - }); - - detailsPanel.add(chartPanel, BorderLayout.CENTER); - - return detailsPanel; - } - - private void setupPlotAxes(XYPlot plot) { - setupDomainAxis(plot); - setupRangeAxis(plot); - } - - private void setupDomainAxis(XYPlot plot) { - plot.setDomainAxis(new DateAxis()); - } - - private void setupRangeAxis(XYPlot plot) { - NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); - - rangeAxis.setRangeType(RangeType.POSITIVE); - rangeAxis.setAutoRange(true); - rangeAxis.setAutoRangeMinimumSize(1); - } - - @Override - public void addChart(final String tag, final String title, final String units) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - SampledDataset newData = new SampledDataset(); - dataset.put(tag, newData); - JPanel subPanel = createCollectorDetailsPanel(newData, title, units); - subPanels.put(tag, subPanel); - realPanel.add(subPanel, gcPanelConstraints); - gcPanelConstraints.gridy++; - realPanel.revalidate(); - } - }); - } - - @Override - public void removeChart(final String tag) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - dataset.remove(tag); - JPanel subPanel = subPanels.remove(tag); - realPanel.remove(subPanel); - realPanel.revalidate(); - gcPanelConstraints.gridy--; - } - }); - } - - @Override - public void addData(final String tag, List<IntervalTimeData<Double>> data) { - final List<IntervalTimeData<Double>> copy = new ArrayList<>(data); - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - SampledDataset series = dataset.get(tag); - for (IntervalTimeData<Double> timeData: copy) { - series.add(timeData.getStartTimeInMillis(), timeData.getEndTimeInMillis(), timeData.getData()); - } - series.fireSeriesChanged(); - } - }); - } - - @Override - public void clearData(final String tag) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - SampledDataset series = dataset.get(tag); - series.clear(); - } - }); - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-gc/client-swing/src/main/java/com/redhat/thermostat/vm/gc/client/swing/internal/Activator.java Mon Dec 10 10:24:20 2012 -0500 @@ -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.vm.gc.client.swing.internal; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +import com.redhat.thermostat.vm.gc.client.core.VmGcViewProvider; + +public class Activator implements BundleActivator { + + @Override + public void start(final BundleContext context) throws Exception { + VmGcViewProvider viewProvider = new SwingVmGcViewProvider(); + // Unregistered on Activator.stop + context.registerService(VmGcViewProvider.class.getName(), viewProvider, null); + } + + @Override + public void stop(BundleContext context) throws Exception { + } + +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-gc/client-swing/src/main/java/com/redhat/thermostat/vm/gc/client/swing/internal/SwingVmGcViewProvider.java Mon Dec 10 10:24:20 2012 -0500 @@ -0,0 +1,49 @@ +/* + * 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.vm.gc.client.swing.internal; + +import com.redhat.thermostat.vm.gc.client.core.VmGcView; +import com.redhat.thermostat.vm.gc.client.core.VmGcViewProvider; + +public class SwingVmGcViewProvider implements VmGcViewProvider { + + @Override + public VmGcView createView() { + return new VmGcPanel(); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-gc/client-swing/src/main/java/com/redhat/thermostat/vm/gc/client/swing/internal/VmGcPanel.java Mon Dec 10 10:24:20 2012 -0500 @@ -0,0 +1,250 @@ +/* + * 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.vm.gc.client.swing.internal; + +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.swing.JPanel; +import javax.swing.SwingUtilities; + +import org.jfree.chart.ChartFactory; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.DateAxis; +import org.jfree.chart.axis.NumberAxis; +import org.jfree.chart.event.ChartProgressEvent; +import org.jfree.chart.event.ChartProgressListener; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.chart.plot.XYPlot; +import org.jfree.chart.renderer.xy.StandardXYBarPainter; +import org.jfree.chart.renderer.xy.XYBarRenderer; +import org.jfree.data.RangeType; +import org.jfree.data.xy.IntervalXYDataset; + +import com.redhat.thermostat.client.swing.SwingComponent; +import com.redhat.thermostat.client.swing.components.Components; +import com.redhat.thermostat.client.swing.components.HeaderPanel; +import com.redhat.thermostat.client.swing.components.RecentTimeSeriesChartPanel; +import com.redhat.thermostat.client.ui.ComponentVisibleListener; +import com.redhat.thermostat.client.ui.RecentTimeSeriesChartController; +import com.redhat.thermostat.client.ui.SampledDataset; +import com.redhat.thermostat.common.ActionListener; +import com.redhat.thermostat.common.locale.Translate; +import com.redhat.thermostat.storage.model.IntervalTimeData; +import com.redhat.thermostat.vm.gc.client.core.VmGcView; +import com.redhat.thermostat.vm.gc.client.locale.LocaleResources; + +public class VmGcPanel extends VmGcView implements SwingComponent { + + private static final Translate<LocaleResources> translator = LocaleResources.createLocalizer(); + + private HeaderPanel visiblePanel = new HeaderPanel(); + private JPanel realPanel = new JPanel(); + + private final Map<String, SampledDataset> dataset = new HashMap<>(); + private final Map<String, JPanel> subPanels = new HashMap<>(); + + private final GridBagConstraints gcPanelConstraints; + + public VmGcPanel() { + super(); + initializePanel(); + + gcPanelConstraints = new GridBagConstraints(); + gcPanelConstraints.gridx = 0; + gcPanelConstraints.gridy = 0; + gcPanelConstraints.fill = GridBagConstraints.BOTH; + 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); + } + }); + } + + @Override + public void addActionListener(ActionListener<Action> listener) { + notifier.addActionListener(listener); + } + + @Override + public void removeActionListener(ActionListener<Action> listener) { + notifier.removeActionListener(listener); + } + + @Override + public Component getUiComponent() { + return visiblePanel; + } + + private void initializePanel() { + visiblePanel.setContent(realPanel); + visiblePanel.setHeader(translator.localize(LocaleResources.VM_GC_TITLE)); + realPanel.setLayout(new GridBagLayout()); + } + + private JPanel createCollectorDetailsPanel(IntervalXYDataset collectorData, String title, String units) { + JPanel detailsPanel = new JPanel(); + detailsPanel.setBorder(Components.smallBorder()); + detailsPanel.setLayout(new BorderLayout()); + + detailsPanel.add(Components.header(title), BorderLayout.NORTH); + + JFreeChart chart = ChartFactory.createHistogram( + null, + translator.localize(LocaleResources.VM_GC_COLLECTOR_CHART_REAL_TIME_LABEL), + translator.localize(LocaleResources.VM_GC_COLLECTOR_CHART_GC_TIME_LABEL, units), + collectorData, + PlotOrientation.VERTICAL, + false, + false, + false); + + ((XYBarRenderer)(chart.getXYPlot().getRenderer())).setBarPainter(new StandardXYBarPainter()); + + setupPlotAxes(chart.getXYPlot()); + + chart.getXYPlot().setDomainCrosshairLockedOnData(true); + chart.getXYPlot().setDomainCrosshairVisible(true); + + final RecentTimeSeriesChartPanel chartPanel = new RecentTimeSeriesChartPanel(new RecentTimeSeriesChartController(chart)); + + chart.addProgressListener(new ChartProgressListener() { + + @Override + public void chartProgress(ChartProgressEvent event) { + if (event.getType() != ChartProgressEvent.DRAWING_FINISHED) { + return; + } + + double rangeCrossHairValue = event.getChart().getXYPlot().getRangeCrosshairValue(); + chartPanel.setDataInformationLabel(String.valueOf(rangeCrossHairValue)); + } + }); + + detailsPanel.add(chartPanel, BorderLayout.CENTER); + + return detailsPanel; + } + + private void setupPlotAxes(XYPlot plot) { + setupDomainAxis(plot); + setupRangeAxis(plot); + } + + private void setupDomainAxis(XYPlot plot) { + plot.setDomainAxis(new DateAxis()); + } + + private void setupRangeAxis(XYPlot plot) { + NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); + + rangeAxis.setRangeType(RangeType.POSITIVE); + rangeAxis.setAutoRange(true); + rangeAxis.setAutoRangeMinimumSize(1); + } + + @Override + public void addChart(final String tag, final String title, final String units) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + SampledDataset newData = new SampledDataset(); + dataset.put(tag, newData); + JPanel subPanel = createCollectorDetailsPanel(newData, title, units); + subPanels.put(tag, subPanel); + realPanel.add(subPanel, gcPanelConstraints); + gcPanelConstraints.gridy++; + realPanel.revalidate(); + } + }); + } + + @Override + public void removeChart(final String tag) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + dataset.remove(tag); + JPanel subPanel = subPanels.remove(tag); + realPanel.remove(subPanel); + realPanel.revalidate(); + gcPanelConstraints.gridy--; + } + }); + } + + @Override + public void addData(final String tag, List<IntervalTimeData<Double>> data) { + final List<IntervalTimeData<Double>> copy = new ArrayList<>(data); + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + SampledDataset series = dataset.get(tag); + for (IntervalTimeData<Double> timeData: copy) { + series.add(timeData.getStartTimeInMillis(), timeData.getEndTimeInMillis(), timeData.getData()); + } + series.fireSeriesChanged(); + } + }); + } + + @Override + public void clearData(final String tag) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + SampledDataset series = dataset.get(tag); + series.clear(); + } + }); + } +}
--- a/vm-gc/client-swing/src/test/java/com/redhat/thermostat/vm/gc/client/swing/ActivatorTest.java Mon Dec 10 15:10:21 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.vm.gc.client.swing; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import com.redhat.thermostat.test.StubBundleContext; -import com.redhat.thermostat.vm.gc.client.core.VmGcViewProvider; - -public class ActivatorTest { - - @Test - public void verifyStartRegistersViewProvider() throws Exception { - StubBundleContext ctx = new StubBundleContext(); - Activator activator = new Activator(); - activator.start(ctx); - assertTrue(ctx.isServiceRegistered(VmGcViewProvider.class.getName(), SwingVmGcViewProvider.class)); - assertEquals(1, ctx.getAllServices().size()); - } - -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-gc/client-swing/src/test/java/com/redhat/thermostat/vm/gc/client/swing/internal/ActivatorTest.java Mon Dec 10 10:24:20 2012 -0500 @@ -0,0 +1,60 @@ +/* + * 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.vm.gc.client.swing.internal; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import com.redhat.thermostat.test.StubBundleContext; +import com.redhat.thermostat.vm.gc.client.core.VmGcViewProvider; +import com.redhat.thermostat.vm.gc.client.swing.internal.Activator; +import com.redhat.thermostat.vm.gc.client.swing.internal.SwingVmGcViewProvider; + +public class ActivatorTest { + + @Test + public void verifyStartRegistersViewProvider() throws Exception { + StubBundleContext ctx = new StubBundleContext(); + Activator activator = new Activator(); + activator.start(ctx); + assertTrue(ctx.isServiceRegistered(VmGcViewProvider.class.getName(), SwingVmGcViewProvider.class)); + assertEquals(1, ctx.getAllServices().size()); + } + +}
--- a/vm-memory/client-swing/pom.xml Mon Dec 10 15:10:21 2012 +0100 +++ b/vm-memory/client-swing/pom.xml Mon Dec 10 10:24:20 2012 -0500 @@ -18,9 +18,9 @@ <configuration> <instructions> <Private-Package> - com.redhat.thermostat.vm.memory.client.swing + com.redhat.thermostat.vm.memory.client.swing.internal </Private-Package> - <Bundle-Activator>com.redhat.thermostat.vm.memory.client.swing.Activator</Bundle-Activator> + <Bundle-Activator>com.redhat.thermostat.vm.memory.client.swing.internal.Activator</Bundle-Activator> <Bundle-Vendor>Red Hat, Inc.</Bundle-Vendor> <Bundle-SymbolicName>com.redhat.thermostat.vm.memory.client.swing</Bundle-SymbolicName> <!-- Do not autogenerate uses clauses in Manifests -->
--- a/vm-memory/client-swing/src/main/java/com/redhat/thermostat/vm/memory/client/swing/Activator.java Mon Dec 10 15:10:21 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +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.vm.memory.client.swing; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; - -import com.redhat.thermostat.vm.memory.client.core.MemoryStatsViewProvider; - -public class Activator implements BundleActivator { - - @Override - public void start(BundleContext context) throws Exception { - MemoryStatsViewProvider provider = new SwingMemoryStatsViewProvider(); - // Automatically unregistered on Activator.stop - context.registerService(MemoryStatsViewProvider.class.getName(), provider, null); - } - - @Override - public void stop(BundleContext context) throws Exception { - } -}
--- a/vm-memory/client-swing/src/main/java/com/redhat/thermostat/vm/memory/client/swing/MemoryGraphPanel.java Mon Dec 10 15:10:21 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,85 +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.vm.memory.client.swing; - -import java.awt.Dimension; -import java.beans.Transient; - -import javax.swing.BoxLayout; -import javax.swing.JPanel; - -import com.redhat.thermostat.vm.memory.client.core.MemoryMeter; -import com.redhat.thermostat.vm.memory.client.core.Payload; - -@SuppressWarnings("serial") -class MemoryGraphPanel extends JPanel { - - private MemoryMeter meter; - - /** - * Create the panel. - */ - public MemoryGraphPanel() { - setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); - meter = new MemoryMeter(); - add(meter); - } - - public void setMemoryGraphProperties(Payload region) { - - meter.getPrimaryModel().setMinimum(0); - meter.getPrimaryModel().setMaximum(region.getMaxUsed()); - meter.getPrimaryModel().setValue(region.getUsed()); - - meter.getSecondaryModel().setMinimum(0); - meter.getSecondaryModel().setMaximum(region.getMaxCapacity()); - meter.getSecondaryModel().setValue(region.getCapacity()); - - meter.setToolTipText(region.getTooltip()); - - meter.setPrimaryScaleUnit(region.getUsedUnit().toString()); - meter.setSecondayScaleUnit(region.getCapacityUnit().toString()); - - meter.setStats(region.getModel()); - } - - @Override - @Transient - public Dimension getPreferredSize() { - return meter.getPreferredSize(); - } -}
--- a/vm-memory/client-swing/src/main/java/com/redhat/thermostat/vm/memory/client/swing/MemoryStatsViewImpl.java Mon Dec 10 15:10:21 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,174 +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.vm.memory.client.swing; - -import java.awt.Component; -import java.awt.Dimension; -import java.beans.Transient; -import java.util.HashMap; -import java.util.Map; - -import javax.swing.Box; -import javax.swing.BoxLayout; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.SwingUtilities; - -import com.redhat.thermostat.client.core.views.BasicView; -import com.redhat.thermostat.client.swing.SwingComponent; -import com.redhat.thermostat.client.swing.components.HeaderPanel; -import com.redhat.thermostat.client.ui.ComponentVisibleListener; -import com.redhat.thermostat.common.ActionListener; -import com.redhat.thermostat.gc.remote.client.common.RequestGCAction; -import com.redhat.thermostat.gc.remote.client.swing.ToolbarGCButton; -import com.redhat.thermostat.gc.remote.common.command.GCCommand; -import com.redhat.thermostat.vm.memory.client.core.MemoryStatsView; -import com.redhat.thermostat.vm.memory.client.core.Payload; - -public class MemoryStatsViewImpl extends MemoryStatsView implements SwingComponent { - - private static final long REPAINT_DELAY = 500; - private long lastRepaint; - - private HeaderPanel visiblePanel; - private JPanel realPanel; - - private final Map<String, MemoryGraphPanel> regions; - - private RequestGCAction toobarButtonAction; - - private Dimension preferredSize; - - public MemoryStatsViewImpl() { - super(); - visiblePanel = new HeaderPanel(); - regions = new HashMap<>(); - - preferredSize = new Dimension(0, 0); - - visiblePanel.setHeader("Memory Regions"); - - visiblePanel.addHierarchyListener(new ComponentVisibleListener() { - @Override - public void componentShown(Component component) { - notifier.fireAction(Action.VISIBLE); - } - - @Override - public void componentHidden(Component component) { - notifier.fireAction(Action.HIDDEN); - } - }); - - realPanel = new JPanel(); - realPanel.setLayout(new BoxLayout(realPanel, BoxLayout.Y_AXIS)); - visiblePanel.setContent(realPanel); - - toobarButtonAction = new RequestGCAction(); - visiblePanel.addToolBarButton(new ToolbarGCButton(toobarButtonAction)); - } - - @Transient - public Dimension getPreferredSize() { - return new Dimension(preferredSize); - } - - @Override - public void updateRegion(final Payload region) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - MemoryGraphPanel memoryGraphPanel = regions.get(region.getName()); - memoryGraphPanel.setMemoryGraphProperties(region); - } - }); - } - - @Override - public void addGCActionListener(ActionListener<GCCommand> listener) { - toobarButtonAction.addActionListener(listener); - } - - @Override - public void addRegion(final Payload region) { - - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - MemoryGraphPanel memoryGraphPanel = new MemoryGraphPanel(); - - realPanel.add(memoryGraphPanel); - realPanel.add(Box.createRigidArea(new Dimension(5,5))); - regions.put(region.getName(), memoryGraphPanel); - - // components are stacked up vertically in this panel - Dimension memoryGraphPanelMinSize = memoryGraphPanel.getMinimumSize(); - preferredSize.height += memoryGraphPanelMinSize.height + 5; - if (preferredSize.width < (memoryGraphPanelMinSize.width + 5)) { - preferredSize.width = memoryGraphPanelMinSize.width + 5; - } - - updateRegion(region); - realPanel.revalidate(); - } - }); - } - - @Override - public void displayWarning(String string) { - JOptionPane.showMessageDialog(visiblePanel, string, "Warning", JOptionPane.WARNING_MESSAGE); - } - - @Override - public Component getUiComponent() { - return visiblePanel; - } - - @Override - public void requestRepaint() { - // really only repaint every REPAINT_DELAY milliseconds - long now = System.currentTimeMillis(); - if (now - lastRepaint > REPAINT_DELAY) { - visiblePanel.repaint(); - lastRepaint = System.currentTimeMillis(); - } - } - - public BasicView getView() { - return this; - } -}
--- a/vm-memory/client-swing/src/main/java/com/redhat/thermostat/vm/memory/client/swing/SwingMemoryStatsViewProvider.java Mon Dec 10 15:10:21 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +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.vm.memory.client.swing; - -import com.redhat.thermostat.vm.memory.client.core.MemoryStatsView; -import com.redhat.thermostat.vm.memory.client.core.MemoryStatsViewProvider; - -public class SwingMemoryStatsViewProvider implements MemoryStatsViewProvider { - - @Override - public MemoryStatsView createView() { - return new MemoryStatsViewImpl(); - } - -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-memory/client-swing/src/main/java/com/redhat/thermostat/vm/memory/client/swing/internal/Activator.java Mon Dec 10 10:24:20 2012 -0500 @@ -0,0 +1,56 @@ +/* + * 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.vm.memory.client.swing.internal; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +import com.redhat.thermostat.vm.memory.client.core.MemoryStatsViewProvider; + +public class Activator implements BundleActivator { + + @Override + public void start(BundleContext context) throws Exception { + MemoryStatsViewProvider provider = new SwingMemoryStatsViewProvider(); + // Automatically unregistered on Activator.stop + context.registerService(MemoryStatsViewProvider.class.getName(), provider, null); + } + + @Override + public void stop(BundleContext context) throws Exception { + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-memory/client-swing/src/main/java/com/redhat/thermostat/vm/memory/client/swing/internal/MemoryGraphPanel.java Mon Dec 10 10:24:20 2012 -0500 @@ -0,0 +1,85 @@ +/* + * 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.vm.memory.client.swing.internal; + +import java.awt.Dimension; +import java.beans.Transient; + +import javax.swing.BoxLayout; +import javax.swing.JPanel; + +import com.redhat.thermostat.vm.memory.client.core.MemoryMeter; +import com.redhat.thermostat.vm.memory.client.core.Payload; + +@SuppressWarnings("serial") +class MemoryGraphPanel extends JPanel { + + private MemoryMeter meter; + + /** + * Create the panel. + */ + public MemoryGraphPanel() { + setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); + meter = new MemoryMeter(); + add(meter); + } + + public void setMemoryGraphProperties(Payload region) { + + meter.getPrimaryModel().setMinimum(0); + meter.getPrimaryModel().setMaximum(region.getMaxUsed()); + meter.getPrimaryModel().setValue(region.getUsed()); + + meter.getSecondaryModel().setMinimum(0); + meter.getSecondaryModel().setMaximum(region.getMaxCapacity()); + meter.getSecondaryModel().setValue(region.getCapacity()); + + meter.setToolTipText(region.getTooltip()); + + meter.setPrimaryScaleUnit(region.getUsedUnit().toString()); + meter.setSecondayScaleUnit(region.getCapacityUnit().toString()); + + meter.setStats(region.getModel()); + } + + @Override + @Transient + public Dimension getPreferredSize() { + return meter.getPreferredSize(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-memory/client-swing/src/main/java/com/redhat/thermostat/vm/memory/client/swing/internal/MemoryStatsViewImpl.java Mon Dec 10 10:24:20 2012 -0500 @@ -0,0 +1,174 @@ +/* + * 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.vm.memory.client.swing.internal; + +import java.awt.Component; +import java.awt.Dimension; +import java.beans.Transient; +import java.util.HashMap; +import java.util.Map; + +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; + +import com.redhat.thermostat.client.core.views.BasicView; +import com.redhat.thermostat.client.swing.SwingComponent; +import com.redhat.thermostat.client.swing.components.HeaderPanel; +import com.redhat.thermostat.client.ui.ComponentVisibleListener; +import com.redhat.thermostat.common.ActionListener; +import com.redhat.thermostat.gc.remote.client.common.RequestGCAction; +import com.redhat.thermostat.gc.remote.client.swing.ToolbarGCButton; +import com.redhat.thermostat.gc.remote.common.command.GCCommand; +import com.redhat.thermostat.vm.memory.client.core.MemoryStatsView; +import com.redhat.thermostat.vm.memory.client.core.Payload; + +public class MemoryStatsViewImpl extends MemoryStatsView implements SwingComponent { + + private static final long REPAINT_DELAY = 500; + private long lastRepaint; + + private HeaderPanel visiblePanel; + private JPanel realPanel; + + private final Map<String, MemoryGraphPanel> regions; + + private RequestGCAction toobarButtonAction; + + private Dimension preferredSize; + + public MemoryStatsViewImpl() { + super(); + visiblePanel = new HeaderPanel(); + regions = new HashMap<>(); + + preferredSize = new Dimension(0, 0); + + visiblePanel.setHeader("Memory Regions"); + + visiblePanel.addHierarchyListener(new ComponentVisibleListener() { + @Override + public void componentShown(Component component) { + notifier.fireAction(Action.VISIBLE); + } + + @Override + public void componentHidden(Component component) { + notifier.fireAction(Action.HIDDEN); + } + }); + + realPanel = new JPanel(); + realPanel.setLayout(new BoxLayout(realPanel, BoxLayout.Y_AXIS)); + visiblePanel.setContent(realPanel); + + toobarButtonAction = new RequestGCAction(); + visiblePanel.addToolBarButton(new ToolbarGCButton(toobarButtonAction)); + } + + @Transient + public Dimension getPreferredSize() { + return new Dimension(preferredSize); + } + + @Override + public void updateRegion(final Payload region) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + MemoryGraphPanel memoryGraphPanel = regions.get(region.getName()); + memoryGraphPanel.setMemoryGraphProperties(region); + } + }); + } + + @Override + public void addGCActionListener(ActionListener<GCCommand> listener) { + toobarButtonAction.addActionListener(listener); + } + + @Override + public void addRegion(final Payload region) { + + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + MemoryGraphPanel memoryGraphPanel = new MemoryGraphPanel(); + + realPanel.add(memoryGraphPanel); + realPanel.add(Box.createRigidArea(new Dimension(5,5))); + regions.put(region.getName(), memoryGraphPanel); + + // components are stacked up vertically in this panel + Dimension memoryGraphPanelMinSize = memoryGraphPanel.getMinimumSize(); + preferredSize.height += memoryGraphPanelMinSize.height + 5; + if (preferredSize.width < (memoryGraphPanelMinSize.width + 5)) { + preferredSize.width = memoryGraphPanelMinSize.width + 5; + } + + updateRegion(region); + realPanel.revalidate(); + } + }); + } + + @Override + public void displayWarning(String string) { + JOptionPane.showMessageDialog(visiblePanel, string, "Warning", JOptionPane.WARNING_MESSAGE); + } + + @Override + public Component getUiComponent() { + return visiblePanel; + } + + @Override + public void requestRepaint() { + // really only repaint every REPAINT_DELAY milliseconds + long now = System.currentTimeMillis(); + if (now - lastRepaint > REPAINT_DELAY) { + visiblePanel.repaint(); + lastRepaint = System.currentTimeMillis(); + } + } + + public BasicView getView() { + return this; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-memory/client-swing/src/main/java/com/redhat/thermostat/vm/memory/client/swing/internal/SwingMemoryStatsViewProvider.java Mon Dec 10 10:24:20 2012 -0500 @@ -0,0 +1,49 @@ +/* + * 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.vm.memory.client.swing.internal; + +import com.redhat.thermostat.vm.memory.client.core.MemoryStatsView; +import com.redhat.thermostat.vm.memory.client.core.MemoryStatsViewProvider; + +public class SwingMemoryStatsViewProvider implements MemoryStatsViewProvider { + + @Override + public MemoryStatsView createView() { + return new MemoryStatsViewImpl(); + } + +}
--- a/vm-memory/client-swing/src/test/java/com/redhat/thermostat/vm/memory/client/swing/ActivatorTest.java Mon Dec 10 15:10:21 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +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.vm.memory.client.swing; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import com.redhat.thermostat.test.StubBundleContext; -import com.redhat.thermostat.vm.memory.client.core.MemoryStatsViewProvider; -import com.redhat.thermostat.vm.memory.client.swing.Activator; -import com.redhat.thermostat.vm.memory.client.swing.SwingMemoryStatsViewProvider; - -public class ActivatorTest { - - @Test - public void verifyStartRegistersViewProvider() throws Exception { - StubBundleContext ctx = new StubBundleContext(); - Activator activator = new Activator(); - activator.start(ctx); - assertTrue(ctx.isServiceRegistered(MemoryStatsViewProvider.class.getName(), SwingMemoryStatsViewProvider.class)); - assertEquals(1, ctx.getAllServices().size()); - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-memory/client-swing/src/test/java/com/redhat/thermostat/vm/memory/client/swing/internal/ActivatorTest.java Mon Dec 10 10:24:20 2012 -0500 @@ -0,0 +1,59 @@ +/* + * 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.vm.memory.client.swing.internal; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import com.redhat.thermostat.test.StubBundleContext; +import com.redhat.thermostat.vm.memory.client.core.MemoryStatsViewProvider; +import com.redhat.thermostat.vm.memory.client.swing.internal.Activator; +import com.redhat.thermostat.vm.memory.client.swing.internal.SwingMemoryStatsViewProvider; + +public class ActivatorTest { + + @Test + public void verifyStartRegistersViewProvider() throws Exception { + StubBundleContext ctx = new StubBundleContext(); + Activator activator = new Activator(); + activator.start(ctx); + assertTrue(ctx.isServiceRegistered(MemoryStatsViewProvider.class.getName(), SwingMemoryStatsViewProvider.class)); + assertEquals(1, ctx.getAllServices().size()); + } +}
--- a/vm-overview/client-swing/pom.xml Mon Dec 10 15:10:21 2012 +0100 +++ b/vm-overview/client-swing/pom.xml Mon Dec 10 10:24:20 2012 -0500 @@ -17,8 +17,8 @@ <extensions>true</extensions> <configuration> <instructions> - <Private-Package>com.redhat.thermostat.vm.overview.client.swing</Private-Package> - <Bundle-Activator>com.redhat.thermostat.vm.overview.client.swing.Activator</Bundle-Activator> + <Private-Package>com.redhat.thermostat.vm.overview.client.swing.internal</Private-Package> + <Bundle-Activator>com.redhat.thermostat.vm.overview.client.swing.internal.Activator</Bundle-Activator> <Bundle-Vendor>Red Hat, Inc.</Bundle-Vendor> <Bundle-SymbolicName>com.redhat.thermostat.vm.overview.client.swing</Bundle-SymbolicName> <!-- Do not autogenerate uses clauses in Manifests -->
--- a/vm-overview/client-swing/src/main/java/com/redhat/thermostat/vm/overview/client/swing/Activator.java Mon Dec 10 15:10:21 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.vm.overview.client.swing; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; - -import com.redhat.thermostat.vm.overview.client.core.VmOverviewViewProvider; - -public class Activator implements BundleActivator { - - @Override - public void start(final BundleContext context) throws Exception { - VmOverviewViewProvider viewProvider = new SwingVmOverviewViewProvider(); - // Unregistered on Activator.stop - context.registerService(VmOverviewViewProvider.class.getName(), viewProvider, null); - } - - @Override - public void stop(BundleContext context) throws Exception { - } - -} -
--- a/vm-overview/client-swing/src/main/java/com/redhat/thermostat/vm/overview/client/swing/ChangeableText.java Mon Dec 10 15:10:21 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,81 +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.vm.overview.client.swing; - -import java.util.HashSet; -import java.util.Set; - -public class ChangeableText { - - private final Set<TextListener> listeners = new HashSet<TextListener>(); - private String text; - - public static interface TextListener { - public void textChanged(ChangeableText text); - } - - public ChangeableText(String text) { - this.text = text; - } - - public synchronized void setText(String text) { - if (this.text.equals(text)) { - return; - } - this.text = text; - fireChanged(); - } - - public synchronized String getText() { - return text; - } - - public synchronized void addListener(TextListener listener) { - this.listeners.add(listener); - } - - public synchronized void removeListener(TextListener listener) { - this.listeners.remove(listener); - } - - private void fireChanged() { - for (TextListener listener: listeners) { - listener.textChanged(this); - } - } - -}
--- a/vm-overview/client-swing/src/main/java/com/redhat/thermostat/vm/overview/client/swing/SimpleTable.java Mon Dec 10 15:10:21 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,291 +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.vm.overview.client.swing; - -import java.awt.Component; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -import javax.swing.Box; -import javax.swing.JComponent; -import javax.swing.JEditorPane; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JTextArea; -import javax.swing.JTextField; -import javax.swing.SwingUtilities; - -import com.redhat.thermostat.client.swing.components.Components; -import com.redhat.thermostat.client.swing.components.ValueField; -import com.redhat.thermostat.client.ui.ComponentVisibleListener; - -public class SimpleTable implements ChangeableText.TextListener { - - Map<ChangeableText, Set<JComponent>> updateMap = new HashMap<ChangeableText, Set<JComponent>>(); - - public static class Section { - private final String sectionName; - private final List<TableEntry> tableEntries = new ArrayList<TableEntry>(); - - public Section(String name) { - this.sectionName = name; - } - - public String getText() { - return sectionName; - } - - public void add(TableEntry entry) { - tableEntries.add(entry); - } - - public void add(Key key, List<Value> values) { - tableEntries.add(new TableEntry(key, values)); - } - - public void add(Key key, Value value) { - tableEntries.add(new TableEntry(key, value)); - } - - public TableEntry[] getEntries() { - return tableEntries.toArray(new TableEntry[0]); - } - } - - public static class TableEntry { - private final Key key; - private final List<Value> values; - - public TableEntry(String key, ChangeableText value) { - this(new Key(key), new Value(value)); - } - - public TableEntry(Key key, Value value) { - this.key = key; - this.values = new ArrayList<Value>(); - this.values.add(value); - } - - public TableEntry(Key key, List<Value> values) { - this.key = key; - this.values = new ArrayList<Value>(values); - } - - public Key getKey() { - return key; - } - - public Value[] getValues() { - return values.toArray(new Value[0]); - } - } - - public static class Key { - private final String text; - - public Key(String text) { - this.text = text; - } - - public String getText() { - return text; - } - } - - public static class Value { - private final ChangeableText text; - private final Component actualComponent; - - public Value(String text) { - this(new ChangeableText(text)); - } - - public Value(ChangeableText text) { - this.text = text; - this.actualComponent = null; - } - - public Value(Component component) { - this.actualComponent = component; - this.text = null; - } - - public Component getComponent() { - return actualComponent; - } - - public ChangeableText getChangeableText() { - return text; - } - } - - public JPanel createTable(List<Section> sections) { - final int SECTION_TOP_GAP = 10; - final int ROW_VERTICAL_GAP = 0; - final int ROW_HORIZONTAL_GAP = 10; - - Insets sectionHeaderInsets = new Insets(SECTION_TOP_GAP, 0, 0, 0); - Insets rowInsets = new Insets(ROW_VERTICAL_GAP, ROW_HORIZONTAL_GAP, ROW_VERTICAL_GAP, ROW_HORIZONTAL_GAP); - - JPanel container = new JPanel(); - container.setLayout(new GridBagLayout()); - - GridBagConstraints keyConstraints = new GridBagConstraints(); - GridBagConstraints valueConstraints = new GridBagConstraints(); - GridBagConstraints sectionHeaderConstraints = new GridBagConstraints(); - - keyConstraints.insets = valueConstraints.insets = rowInsets; - keyConstraints.gridy = valueConstraints.gridy = 0; - keyConstraints.gridx = 0; - keyConstraints.anchor = GridBagConstraints.FIRST_LINE_END; - valueConstraints.gridx = 1; - keyConstraints.fill = valueConstraints.fill = GridBagConstraints.HORIZONTAL; - - sectionHeaderConstraints.gridx = 0; - sectionHeaderConstraints.gridwidth = GridBagConstraints.REMAINDER; - sectionHeaderConstraints.fill = GridBagConstraints.HORIZONTAL; - sectionHeaderConstraints.insets = sectionHeaderInsets; - - for (Section section : sections) { - sectionHeaderConstraints.gridy = keyConstraints.gridy = ++valueConstraints.gridy; - container.add(Components.header(section.getText()), sectionHeaderConstraints); - for (TableEntry tableEntry : section.getEntries()) { - keyConstraints.gridy = ++valueConstraints.gridy; - container.add(Components.label(tableEntry.getKey().getText()), keyConstraints); - - for (Value value : tableEntry.getValues()) { - if (value.getComponent() == null) { - ChangeableText text = value.getChangeableText(); - JComponent valueLabel = new ValueField(text.getText()); - if (updateMap.containsKey(text)) { - updateMap.get(text).add(valueLabel); - } else { - Set<JComponent> set = new HashSet<JComponent>(); - set.add(valueLabel); - updateMap.put(text, set); - } - container.add(valueLabel, valueConstraints); - } else { - container.add(value.getComponent(), valueConstraints); - } - keyConstraints.gridy = ++valueConstraints.gridy; - } - } - } - - GridBagConstraints glueConstraints = new GridBagConstraints(); - glueConstraints.gridy = keyConstraints.gridy + 1; - glueConstraints.gridx = 0; - glueConstraints.weightx = 1; - glueConstraints.weighty = 1; - glueConstraints.fill = GridBagConstraints.BOTH; - glueConstraints.gridheight = GridBagConstraints.REMAINDER; - glueConstraints.gridwidth = GridBagConstraints.REMAINDER; - Component filler = Box.createGlue(); - container.add(filler, glueConstraints); - - container.addHierarchyListener(new ComponentVisibleListener() { - @Override - public void componentShown(Component c) { - updateAllValues(); - addAllListeners(); - } - - @Override - public void componentHidden(Component c) { - removeAllListeners(); - } - }); - - return container; - } - - - private void updateAllValues() { - for (Entry<ChangeableText, Set<JComponent>> entry: updateMap.entrySet()) { - for (JComponent label: entry.getValue()) { - setText(label, entry.getKey().getText()); - } - } - } - - private static void setText(JComponent target, String text) { - if (target instanceof JLabel) { - ((JLabel)target).setText(text); - } else if (target instanceof JTextField) { - ((JTextField)target).setText(text); - } else if (target instanceof JTextArea) { - ((JTextArea)target).setText(text); - } else if (target instanceof JEditorPane) { - ((JEditorPane)target).setText(text); - } - } - - @Override - public void textChanged(final ChangeableText text) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - String newValue = text.getText(); - for (JComponent label: updateMap.get(text)) { - setText(label, newValue); - } - } - }); - } - - public void addAllListeners() { - for (ChangeableText text : updateMap.keySet()) { - text.addListener(this); - } - } - - public void removeAllListeners() { - for (ChangeableText text : updateMap.keySet()) { - text.removeListener(this); - } - } - -}
--- a/vm-overview/client-swing/src/main/java/com/redhat/thermostat/vm/overview/client/swing/SwingVmOverviewViewProvider.java Mon Dec 10 15:10:21 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +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.vm.overview.client.swing; - -import com.redhat.thermostat.vm.overview.client.core.VmOverviewView; -import com.redhat.thermostat.vm.overview.client.core.VmOverviewViewProvider; - -public class SwingVmOverviewViewProvider implements VmOverviewViewProvider { - - @Override - public VmOverviewView createView() { - return new VmOverviewPanel(); - } - -}
--- a/vm-overview/client-swing/src/main/java/com/redhat/thermostat/vm/overview/client/swing/VmOverviewPanel.java Mon Dec 10 15:10:21 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,197 +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.vm.overview.client.swing; - -import java.awt.Component; -import java.awt.Point; -import java.awt.Rectangle; -import java.util.ArrayList; -import java.util.List; - -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.SwingUtilities; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; - -import com.redhat.thermostat.client.swing.SwingComponent; -import com.redhat.thermostat.client.swing.components.Components; -import com.redhat.thermostat.client.swing.components.HeaderPanel; -import com.redhat.thermostat.client.ui.ComponentVisibleListener; -import com.redhat.thermostat.common.ActionListener; -import com.redhat.thermostat.common.locale.Translate; -import com.redhat.thermostat.vm.overview.client.core.VmOverviewView; -import com.redhat.thermostat.vm.overview.client.locale.LocaleResources; -import com.redhat.thermostat.vm.overview.client.swing.SimpleTable.Section; -import com.redhat.thermostat.vm.overview.client.swing.SimpleTable.TableEntry; - -public class VmOverviewPanel extends VmOverviewView implements SwingComponent { - - private static final Translate<LocaleResources> translator = LocaleResources.createLocalizer(); - - private HeaderPanel visiblePanel; - private JScrollPane container; - - private final ChangeableText pid = new ChangeableText(""); - private final ChangeableText startTimeStamp = new ChangeableText(""); - private final ChangeableText stopTimeStamp = new ChangeableText(""); - private final ChangeableText mainClass = new ChangeableText(""); - private final ChangeableText javaCommandLine = new ChangeableText(""); - private final ChangeableText javaHome = new ChangeableText(""); - private final ChangeableText javaVersion = new ChangeableText(""); - private final ChangeableText vmNameAndVersion = new ChangeableText(""); - private final ChangeableText vmArguments = new ChangeableText(""); - - - 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); - } - }); - } - - @Override - public void addActionListener(ActionListener<Action> listener) { - notifier.addActionListener(listener); - } - - @Override - public void removeActionListener(ActionListener<Action> listener) { - notifier.removeActionListener(listener); - } - - @Override - public void setVmPid(String pid) { - this.pid.setText(pid); - } - - @Override - public void setVmStartTimeStamp(String timeStamp) { - this.startTimeStamp.setText(timeStamp); - } - - @Override - public void setVmStopTimeStamp(String timeStamp) { - this.stopTimeStamp.setText(timeStamp); - } - - @Override - public void setMainClass(String mainClass) { - this.mainClass.setText(mainClass); - } - - @Override - public void setJavaCommandLine(String javaCommandLine) { - this.javaCommandLine.setText(javaCommandLine); - } - - @Override - public void setJavaHome(String javaHome) { - this.javaHome.setText(javaHome); - - } - - @Override - public void setJavaVersion(String javaVersion) { - this.javaVersion.setText(javaVersion); - } - - @Override - public void setVmNameAndVersion(String vmNameAndVersion) { - this.vmNameAndVersion.setText(vmNameAndVersion); - } - - @Override - public void setVmArguments(String vmArguments) { - this.vmArguments.setText(vmArguments); - } - - @Override - public Component getUiComponent() { - return visiblePanel; - } - - private void initializePanel() { - visiblePanel = new HeaderPanel(); - - visiblePanel.setHeader(translator.localize(LocaleResources.VM_INFO_TITLE)); - - TableEntry entry; - List<Section> allSections = new ArrayList<Section>(); - - Section processSection = new Section(translator.localize(LocaleResources.VM_INFO_SECTION_PROCESS)); - allSections.add(processSection); - - entry = new TableEntry(translator.localize(LocaleResources.VM_INFO_PROCESS_ID), pid); - processSection.add(entry); - entry = new TableEntry(translator.localize(LocaleResources.VM_INFO_START_TIME), startTimeStamp); - processSection.add(entry); - entry = new TableEntry(translator.localize(LocaleResources.VM_INFO_STOP_TIME), stopTimeStamp); - processSection.add(entry); - - Section javaSection = new Section(translator.localize(LocaleResources.VM_INFO_SECTION_JAVA)); - allSections.add(javaSection); - - entry = new TableEntry(translator.localize(LocaleResources.VM_INFO_MAIN_CLASS), mainClass); - javaSection.add(entry); - entry = new TableEntry(translator.localize(LocaleResources.VM_INFO_COMMAND_LINE), javaCommandLine); - javaSection.add(entry); - entry = new TableEntry(translator.localize(LocaleResources.VM_INFO_JAVA_VERSION), javaVersion); - javaSection.add(entry); - entry = new TableEntry(translator.localize(LocaleResources.VM_INFO_VM), vmNameAndVersion); - javaSection.add(entry); - entry = new TableEntry(translator.localize(LocaleResources.VM_INFO_VM_ARGUMENTS), vmArguments); - javaSection.add(entry); - - SimpleTable simpleTable = new SimpleTable(); - JPanel table = simpleTable.createTable(allSections); - table.setBorder(Components.smallBorder()); - - container = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); - - visiblePanel.setContent(container); - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-overview/client-swing/src/main/java/com/redhat/thermostat/vm/overview/client/swing/internal/Activator.java Mon Dec 10 10:24:20 2012 -0500 @@ -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.vm.overview.client.swing.internal; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +import com.redhat.thermostat.vm.overview.client.core.VmOverviewViewProvider; + +public class Activator implements BundleActivator { + + @Override + public void start(final BundleContext context) throws Exception { + VmOverviewViewProvider viewProvider = new SwingVmOverviewViewProvider(); + // Unregistered on Activator.stop + context.registerService(VmOverviewViewProvider.class.getName(), viewProvider, null); + } + + @Override + public void stop(BundleContext context) throws Exception { + } + +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-overview/client-swing/src/main/java/com/redhat/thermostat/vm/overview/client/swing/internal/ChangeableText.java Mon Dec 10 10:24:20 2012 -0500 @@ -0,0 +1,81 @@ +/* + * 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.vm.overview.client.swing.internal; + +import java.util.HashSet; +import java.util.Set; + +public class ChangeableText { + + private final Set<TextListener> listeners = new HashSet<TextListener>(); + private String text; + + public static interface TextListener { + public void textChanged(ChangeableText text); + } + + public ChangeableText(String text) { + this.text = text; + } + + public synchronized void setText(String text) { + if (this.text.equals(text)) { + return; + } + this.text = text; + fireChanged(); + } + + public synchronized String getText() { + return text; + } + + public synchronized void addListener(TextListener listener) { + this.listeners.add(listener); + } + + public synchronized void removeListener(TextListener listener) { + this.listeners.remove(listener); + } + + private void fireChanged() { + for (TextListener listener: listeners) { + listener.textChanged(this); + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-overview/client-swing/src/main/java/com/redhat/thermostat/vm/overview/client/swing/internal/SimpleTable.java Mon Dec 10 10:24:20 2012 -0500 @@ -0,0 +1,291 @@ +/* + * 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.vm.overview.client.swing.internal; + +import java.awt.Component; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import javax.swing.Box; +import javax.swing.JComponent; +import javax.swing.JEditorPane; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.SwingUtilities; + +import com.redhat.thermostat.client.swing.components.Components; +import com.redhat.thermostat.client.swing.components.ValueField; +import com.redhat.thermostat.client.ui.ComponentVisibleListener; + +public class SimpleTable implements ChangeableText.TextListener { + + Map<ChangeableText, Set<JComponent>> updateMap = new HashMap<ChangeableText, Set<JComponent>>(); + + public static class Section { + private final String sectionName; + private final List<TableEntry> tableEntries = new ArrayList<TableEntry>(); + + public Section(String name) { + this.sectionName = name; + } + + public String getText() { + return sectionName; + } + + public void add(TableEntry entry) { + tableEntries.add(entry); + } + + public void add(Key key, List<Value> values) { + tableEntries.add(new TableEntry(key, values)); + } + + public void add(Key key, Value value) { + tableEntries.add(new TableEntry(key, value)); + } + + public TableEntry[] getEntries() { + return tableEntries.toArray(new TableEntry[0]); + } + } + + public static class TableEntry { + private final Key key; + private final List<Value> values; + + public TableEntry(String key, ChangeableText value) { + this(new Key(key), new Value(value)); + } + + public TableEntry(Key key, Value value) { + this.key = key; + this.values = new ArrayList<Value>(); + this.values.add(value); + } + + public TableEntry(Key key, List<Value> values) { + this.key = key; + this.values = new ArrayList<Value>(values); + } + + public Key getKey() { + return key; + } + + public Value[] getValues() { + return values.toArray(new Value[0]); + } + } + + public static class Key { + private final String text; + + public Key(String text) { + this.text = text; + } + + public String getText() { + return text; + } + } + + public static class Value { + private final ChangeableText text; + private final Component actualComponent; + + public Value(String text) { + this(new ChangeableText(text)); + } + + public Value(ChangeableText text) { + this.text = text; + this.actualComponent = null; + } + + public Value(Component component) { + this.actualComponent = component; + this.text = null; + } + + public Component getComponent() { + return actualComponent; + } + + public ChangeableText getChangeableText() { + return text; + } + } + + public JPanel createTable(List<Section> sections) { + final int SECTION_TOP_GAP = 10; + final int ROW_VERTICAL_GAP = 0; + final int ROW_HORIZONTAL_GAP = 10; + + Insets sectionHeaderInsets = new Insets(SECTION_TOP_GAP, 0, 0, 0); + Insets rowInsets = new Insets(ROW_VERTICAL_GAP, ROW_HORIZONTAL_GAP, ROW_VERTICAL_GAP, ROW_HORIZONTAL_GAP); + + JPanel container = new JPanel(); + container.setLayout(new GridBagLayout()); + + GridBagConstraints keyConstraints = new GridBagConstraints(); + GridBagConstraints valueConstraints = new GridBagConstraints(); + GridBagConstraints sectionHeaderConstraints = new GridBagConstraints(); + + keyConstraints.insets = valueConstraints.insets = rowInsets; + keyConstraints.gridy = valueConstraints.gridy = 0; + keyConstraints.gridx = 0; + keyConstraints.anchor = GridBagConstraints.FIRST_LINE_END; + valueConstraints.gridx = 1; + keyConstraints.fill = valueConstraints.fill = GridBagConstraints.HORIZONTAL; + + sectionHeaderConstraints.gridx = 0; + sectionHeaderConstraints.gridwidth = GridBagConstraints.REMAINDER; + sectionHeaderConstraints.fill = GridBagConstraints.HORIZONTAL; + sectionHeaderConstraints.insets = sectionHeaderInsets; + + for (Section section : sections) { + sectionHeaderConstraints.gridy = keyConstraints.gridy = ++valueConstraints.gridy; + container.add(Components.header(section.getText()), sectionHeaderConstraints); + for (TableEntry tableEntry : section.getEntries()) { + keyConstraints.gridy = ++valueConstraints.gridy; + container.add(Components.label(tableEntry.getKey().getText()), keyConstraints); + + for (Value value : tableEntry.getValues()) { + if (value.getComponent() == null) { + ChangeableText text = value.getChangeableText(); + JComponent valueLabel = new ValueField(text.getText()); + if (updateMap.containsKey(text)) { + updateMap.get(text).add(valueLabel); + } else { + Set<JComponent> set = new HashSet<JComponent>(); + set.add(valueLabel); + updateMap.put(text, set); + } + container.add(valueLabel, valueConstraints); + } else { + container.add(value.getComponent(), valueConstraints); + } + keyConstraints.gridy = ++valueConstraints.gridy; + } + } + } + + GridBagConstraints glueConstraints = new GridBagConstraints(); + glueConstraints.gridy = keyConstraints.gridy + 1; + glueConstraints.gridx = 0; + glueConstraints.weightx = 1; + glueConstraints.weighty = 1; + glueConstraints.fill = GridBagConstraints.BOTH; + glueConstraints.gridheight = GridBagConstraints.REMAINDER; + glueConstraints.gridwidth = GridBagConstraints.REMAINDER; + Component filler = Box.createGlue(); + container.add(filler, glueConstraints); + + container.addHierarchyListener(new ComponentVisibleListener() { + @Override + public void componentShown(Component c) { + updateAllValues(); + addAllListeners(); + } + + @Override + public void componentHidden(Component c) { + removeAllListeners(); + } + }); + + return container; + } + + + private void updateAllValues() { + for (Entry<ChangeableText, Set<JComponent>> entry: updateMap.entrySet()) { + for (JComponent label: entry.getValue()) { + setText(label, entry.getKey().getText()); + } + } + } + + private static void setText(JComponent target, String text) { + if (target instanceof JLabel) { + ((JLabel)target).setText(text); + } else if (target instanceof JTextField) { + ((JTextField)target).setText(text); + } else if (target instanceof JTextArea) { + ((JTextArea)target).setText(text); + } else if (target instanceof JEditorPane) { + ((JEditorPane)target).setText(text); + } + } + + @Override + public void textChanged(final ChangeableText text) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + String newValue = text.getText(); + for (JComponent label: updateMap.get(text)) { + setText(label, newValue); + } + } + }); + } + + public void addAllListeners() { + for (ChangeableText text : updateMap.keySet()) { + text.addListener(this); + } + } + + public void removeAllListeners() { + for (ChangeableText text : updateMap.keySet()) { + text.removeListener(this); + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-overview/client-swing/src/main/java/com/redhat/thermostat/vm/overview/client/swing/internal/SwingVmOverviewViewProvider.java Mon Dec 10 10:24:20 2012 -0500 @@ -0,0 +1,49 @@ +/* + * 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.vm.overview.client.swing.internal; + +import com.redhat.thermostat.vm.overview.client.core.VmOverviewView; +import com.redhat.thermostat.vm.overview.client.core.VmOverviewViewProvider; + +public class SwingVmOverviewViewProvider implements VmOverviewViewProvider { + + @Override + public VmOverviewView createView() { + return new VmOverviewPanel(); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-overview/client-swing/src/main/java/com/redhat/thermostat/vm/overview/client/swing/internal/VmOverviewPanel.java Mon Dec 10 10:24:20 2012 -0500 @@ -0,0 +1,197 @@ +/* + * 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.vm.overview.client.swing.internal; + +import java.awt.Component; +import java.awt.Point; +import java.awt.Rectangle; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.SwingUtilities; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +import com.redhat.thermostat.client.swing.SwingComponent; +import com.redhat.thermostat.client.swing.components.Components; +import com.redhat.thermostat.client.swing.components.HeaderPanel; +import com.redhat.thermostat.client.ui.ComponentVisibleListener; +import com.redhat.thermostat.common.ActionListener; +import com.redhat.thermostat.common.locale.Translate; +import com.redhat.thermostat.vm.overview.client.core.VmOverviewView; +import com.redhat.thermostat.vm.overview.client.locale.LocaleResources; +import com.redhat.thermostat.vm.overview.client.swing.internal.SimpleTable.Section; +import com.redhat.thermostat.vm.overview.client.swing.internal.SimpleTable.TableEntry; + +public class VmOverviewPanel extends VmOverviewView implements SwingComponent { + + private static final Translate<LocaleResources> translator = LocaleResources.createLocalizer(); + + private HeaderPanel visiblePanel; + private JScrollPane container; + + private final ChangeableText pid = new ChangeableText(""); + private final ChangeableText startTimeStamp = new ChangeableText(""); + private final ChangeableText stopTimeStamp = new ChangeableText(""); + private final ChangeableText mainClass = new ChangeableText(""); + private final ChangeableText javaCommandLine = new ChangeableText(""); + private final ChangeableText javaHome = new ChangeableText(""); + private final ChangeableText javaVersion = new ChangeableText(""); + private final ChangeableText vmNameAndVersion = new ChangeableText(""); + private final ChangeableText vmArguments = new ChangeableText(""); + + + 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); + } + }); + } + + @Override + public void addActionListener(ActionListener<Action> listener) { + notifier.addActionListener(listener); + } + + @Override + public void removeActionListener(ActionListener<Action> listener) { + notifier.removeActionListener(listener); + } + + @Override + public void setVmPid(String pid) { + this.pid.setText(pid); + } + + @Override + public void setVmStartTimeStamp(String timeStamp) { + this.startTimeStamp.setText(timeStamp); + } + + @Override + public void setVmStopTimeStamp(String timeStamp) { + this.stopTimeStamp.setText(timeStamp); + } + + @Override + public void setMainClass(String mainClass) { + this.mainClass.setText(mainClass); + } + + @Override + public void setJavaCommandLine(String javaCommandLine) { + this.javaCommandLine.setText(javaCommandLine); + } + + @Override + public void setJavaHome(String javaHome) { + this.javaHome.setText(javaHome); + + } + + @Override + public void setJavaVersion(String javaVersion) { + this.javaVersion.setText(javaVersion); + } + + @Override + public void setVmNameAndVersion(String vmNameAndVersion) { + this.vmNameAndVersion.setText(vmNameAndVersion); + } + + @Override + public void setVmArguments(String vmArguments) { + this.vmArguments.setText(vmArguments); + } + + @Override + public Component getUiComponent() { + return visiblePanel; + } + + private void initializePanel() { + visiblePanel = new HeaderPanel(); + + visiblePanel.setHeader(translator.localize(LocaleResources.VM_INFO_TITLE)); + + TableEntry entry; + List<Section> allSections = new ArrayList<Section>(); + + Section processSection = new Section(translator.localize(LocaleResources.VM_INFO_SECTION_PROCESS)); + allSections.add(processSection); + + entry = new TableEntry(translator.localize(LocaleResources.VM_INFO_PROCESS_ID), pid); + processSection.add(entry); + entry = new TableEntry(translator.localize(LocaleResources.VM_INFO_START_TIME), startTimeStamp); + processSection.add(entry); + entry = new TableEntry(translator.localize(LocaleResources.VM_INFO_STOP_TIME), stopTimeStamp); + processSection.add(entry); + + Section javaSection = new Section(translator.localize(LocaleResources.VM_INFO_SECTION_JAVA)); + allSections.add(javaSection); + + entry = new TableEntry(translator.localize(LocaleResources.VM_INFO_MAIN_CLASS), mainClass); + javaSection.add(entry); + entry = new TableEntry(translator.localize(LocaleResources.VM_INFO_COMMAND_LINE), javaCommandLine); + javaSection.add(entry); + entry = new TableEntry(translator.localize(LocaleResources.VM_INFO_JAVA_VERSION), javaVersion); + javaSection.add(entry); + entry = new TableEntry(translator.localize(LocaleResources.VM_INFO_VM), vmNameAndVersion); + javaSection.add(entry); + entry = new TableEntry(translator.localize(LocaleResources.VM_INFO_VM_ARGUMENTS), vmArguments); + javaSection.add(entry); + + SimpleTable simpleTable = new SimpleTable(); + JPanel table = simpleTable.createTable(allSections); + table.setBorder(Components.smallBorder()); + + container = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + + visiblePanel.setContent(container); + } +}
--- a/vm-overview/client-swing/src/test/java/com/redhat/thermostat/vm/overview/client/swing/ActivatorTest.java Mon Dec 10 15:10:21 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.vm.overview.client.swing; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import com.redhat.thermostat.test.StubBundleContext; -import com.redhat.thermostat.vm.overview.client.core.VmOverviewViewProvider; - -public class ActivatorTest { - - @Test - public void verifyStartRegistersViewProvider() throws Exception { - StubBundleContext ctx = new StubBundleContext(); - Activator activator = new Activator(); - activator.start(ctx); - assertTrue(ctx.isServiceRegistered(VmOverviewViewProvider.class.getName(), SwingVmOverviewViewProvider.class)); - assertEquals(1, ctx.getAllServices().size()); - } - -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-overview/client-swing/src/test/java/com/redhat/thermostat/vm/overview/client/swing/internal/ActivatorTest.java Mon Dec 10 10:24:20 2012 -0500 @@ -0,0 +1,60 @@ +/* + * 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.vm.overview.client.swing.internal; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import com.redhat.thermostat.test.StubBundleContext; +import com.redhat.thermostat.vm.overview.client.core.VmOverviewViewProvider; +import com.redhat.thermostat.vm.overview.client.swing.internal.Activator; +import com.redhat.thermostat.vm.overview.client.swing.internal.SwingVmOverviewViewProvider; + +public class ActivatorTest { + + @Test + public void verifyStartRegistersViewProvider() throws Exception { + StubBundleContext ctx = new StubBundleContext(); + Activator activator = new Activator(); + activator.start(ctx); + assertTrue(ctx.isServiceRegistered(VmOverviewViewProvider.class.getName(), SwingVmOverviewViewProvider.class)); + assertEquals(1, ctx.getAllServices().size()); + } + +}