Mercurial > hg > release > thermostat-0.7
changeset 983:cb50a6f7f0d3
Add some separation between fields in Vm Overview
Reviewed-by: neugens
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2013-February/005721.html
PR 1310
author | Omair Majid <omajid@redhat.com> |
---|---|
date | Tue, 19 Feb 2013 12:50:23 -0500 |
parents | 3723566e9c23 |
children | 9bebac5faf9b |
files | vm-overview/client-swing/src/main/java/com/redhat/thermostat/vm/overview/client/swing/internal/ChangeableText.java vm-overview/client-swing/src/main/java/com/redhat/thermostat/vm/overview/client/swing/internal/SimpleTable.java vm-overview/client-swing/src/main/java/com/redhat/thermostat/vm/overview/client/swing/internal/VmOverviewPanel.java |
diffstat | 3 files changed, 159 insertions(+), 435 deletions(-) [+] |
line wrap: on
line diff
--- a/vm-overview/client-swing/src/main/java/com/redhat/thermostat/vm/overview/client/swing/internal/ChangeableText.java Tue Feb 19 12:08:47 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -/* - * Copyright 2012, 2013 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <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); - } - } - -} -
--- a/vm-overview/client-swing/src/main/java/com/redhat/thermostat/vm/overview/client/swing/internal/SimpleTable.java Tue Feb 19 12:08:47 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,293 +0,0 @@ -/* - * Copyright 2012, 2013 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <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.ComponentVisibleListener; -import com.redhat.thermostat.client.swing.components.LabelField; -import com.redhat.thermostat.client.swing.components.SectionHeader; -import com.redhat.thermostat.client.swing.components.ValueField; - -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(new SectionHeader(section.getText()), sectionHeaderConstraints); - for (TableEntry tableEntry : section.getEntries()) { - keyConstraints.gridy = ++valueConstraints.gridy; - container.add(new LabelField(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/internal/VmOverviewPanel.java Tue Feb 19 12:08:47 2013 -0500 +++ b/vm-overview/client-swing/src/main/java/com/redhat/thermostat/vm/overview/client/swing/internal/VmOverviewPanel.java Tue Feb 19 12:50:23 2013 -0500 @@ -37,40 +37,42 @@ package com.redhat.thermostat.vm.overview.client.swing.internal; import java.awt.Component; -import java.util.ArrayList; -import java.util.List; import javax.swing.BorderFactory; +import javax.swing.GroupLayout; import javax.swing.JPanel; import javax.swing.JScrollPane; +import javax.swing.SwingUtilities; +import javax.swing.GroupLayout.Alignment; +import javax.swing.LayoutStyle.ComponentPlacement; import com.redhat.thermostat.client.swing.ComponentVisibleListener; import com.redhat.thermostat.client.swing.SwingComponent; import com.redhat.thermostat.client.swing.components.HeaderPanel; +import com.redhat.thermostat.client.swing.components.LabelField; +import com.redhat.thermostat.client.swing.components.SectionHeader; +import com.redhat.thermostat.client.swing.components.ValueField; import com.redhat.thermostat.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(""); - + private final ValueField pid = new ValueField(""); + private final ValueField startTimeStamp = new ValueField(""); + private final ValueField stopTimeStamp = new ValueField(""); + private final ValueField mainClass = new ValueField(""); + private final ValueField javaCommandLine = new ValueField(""); + private final ValueField javaHome = new ValueField(""); + private final ValueField javaVersion = new ValueField(""); + private final ValueField vmNameAndVersion = new ValueField(""); + private final ValueField vmArguments = new ValueField(""); public VmOverviewPanel() { super(); @@ -99,49 +101,94 @@ } @Override - public void setVmPid(String pid) { - this.pid.setText(pid); + public void setVmPid(final String newPid) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + pid.setText(newPid); + } + }); } @Override - public void setVmStartTimeStamp(String timeStamp) { - this.startTimeStamp.setText(timeStamp); + public void setVmStartTimeStamp(final String newTimeStamp) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + startTimeStamp.setText(newTimeStamp); + } + }); } @Override - public void setVmStopTimeStamp(String timeStamp) { - this.stopTimeStamp.setText(timeStamp); + public void setVmStopTimeStamp(final String newTimeStamp) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + stopTimeStamp.setText(newTimeStamp); + } + }); } @Override - public void setMainClass(String mainClass) { - this.mainClass.setText(mainClass); + public void setMainClass(final String newMainClass) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + mainClass.setText(newMainClass); + } + }); } @Override - public void setJavaCommandLine(String javaCommandLine) { - this.javaCommandLine.setText(javaCommandLine); + public void setJavaCommandLine(final String newJavaCommandLine) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + javaCommandLine.setText(newJavaCommandLine); + } + }); } @Override - public void setJavaHome(String javaHome) { - this.javaHome.setText(javaHome); + public void setJavaHome(final String newJavaHome) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + javaHome.setText(newJavaHome); + } + }); } @Override - public void setJavaVersion(String javaVersion) { - this.javaVersion.setText(javaVersion); + public void setJavaVersion(final String newJavaVersion) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + javaVersion.setText(newJavaVersion); + } + }); } @Override - public void setVmNameAndVersion(String vmNameAndVersion) { - this.vmNameAndVersion.setText(vmNameAndVersion); + public void setVmNameAndVersion(final String newVmNameAndVersion) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + vmNameAndVersion.setText(newVmNameAndVersion); + } + }); } @Override - public void setVmArguments(String vmArguments) { - this.vmArguments.setText(vmArguments); + public void setVmArguments(final String newVmArguments) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + vmArguments.setText(newVmArguments); + } + }); } @Override @@ -154,40 +201,92 @@ visiblePanel.setHeader(translator.localize(LocaleResources.VM_INFO_TITLE)); - TableEntry entry; - List<Section> allSections = new ArrayList<Section>(); + SectionHeader processSection = new SectionHeader(translator.localize(LocaleResources.VM_INFO_SECTION_PROCESS)); + LabelField pidLabel = new LabelField(translator.localize(LocaleResources.VM_INFO_PROCESS_ID)); + LabelField startTimeLabel = new LabelField(translator.localize(LocaleResources.VM_INFO_START_TIME)); + LabelField stopTimeLabel = new LabelField(translator.localize(LocaleResources.VM_INFO_STOP_TIME)); - Section processSection = new Section(translator.localize(LocaleResources.VM_INFO_SECTION_PROCESS)); - allSections.add(processSection); + SectionHeader javaSection = new SectionHeader(translator.localize(LocaleResources.VM_INFO_SECTION_JAVA)); - 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); + LabelField mainClassLabel = new LabelField(translator.localize(LocaleResources.VM_INFO_MAIN_CLASS)); + LabelField javaCommandLineLabel = new LabelField(translator.localize(LocaleResources.VM_INFO_COMMAND_LINE)); + LabelField javaVersionLabel = new LabelField(translator.localize(LocaleResources.VM_INFO_JAVA_VERSION)); + LabelField vmNameAndVersionLabel = new LabelField(translator.localize(LocaleResources.VM_INFO_VM)); + LabelField vmArgumentsLabel = new LabelField(translator.localize(LocaleResources.VM_INFO_VM_ARGUMENTS)); + + JPanel table = new JPanel(); + table.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 15)); + GroupLayout gl = new GroupLayout(table); + table.setLayout(gl); - Section javaSection = new Section(translator.localize(LocaleResources.VM_INFO_SECTION_JAVA)); - allSections.add(javaSection); + gl.setHorizontalGroup(gl.createParallelGroup() + .addComponent(processSection) + .addComponent(javaSection) + .addGroup(gl.createSequentialGroup() + .addContainerGap() + .addGroup(gl.createParallelGroup(Alignment.TRAILING) + .addComponent(pidLabel) + .addComponent(startTimeLabel) + .addComponent(stopTimeLabel) + .addComponent(mainClassLabel) + .addComponent(javaCommandLineLabel) + .addComponent(javaVersionLabel) + .addComponent(vmNameAndVersionLabel) + .addComponent(vmArgumentsLabel)) + .addPreferredGap(ComponentPlacement.RELATED) + .addGroup(gl.createParallelGroup() + .addComponent(pid) + .addComponent(startTimeStamp) + .addComponent(stopTimeStamp) + .addComponent(mainClass) + .addComponent(javaCommandLine) + .addComponent(javaVersion) + .addComponent(vmNameAndVersion) + .addComponent(vmArguments)) + .addContainerGap())); - 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(BorderFactory.createEmptyBorder(5, 5, 5, 5)); + gl.setVerticalGroup(gl.createSequentialGroup() + .addContainerGap() + .addComponent(processSection) + .addPreferredGap(ComponentPlacement.RELATED) + .addGroup(gl.createParallelGroup(Alignment.LEADING, false) + .addComponent(pidLabel) + .addComponent(pid)) + .addPreferredGap(ComponentPlacement.RELATED) + .addGroup(gl.createParallelGroup(Alignment.LEADING, false) + .addComponent(startTimeLabel) + .addComponent(startTimeStamp)) + .addPreferredGap(ComponentPlacement.RELATED) + .addGroup(gl.createParallelGroup(Alignment.LEADING, false) + .addComponent(stopTimeLabel) + .addComponent(stopTimeStamp)) + .addPreferredGap(ComponentPlacement.UNRELATED) + .addComponent(javaSection) + .addPreferredGap(ComponentPlacement.RELATED) + .addGroup(gl.createParallelGroup(Alignment.LEADING, false) + .addComponent(mainClassLabel) + .addComponent(mainClass)) + .addPreferredGap(ComponentPlacement.RELATED) + .addGroup(gl.createParallelGroup(Alignment.LEADING, false) + .addComponent(javaCommandLineLabel) + .addComponent(javaCommandLine)) + .addPreferredGap(ComponentPlacement.RELATED) + .addGroup(gl.createParallelGroup(Alignment.LEADING, false) + .addComponent(javaVersionLabel) + .addComponent(javaVersion)) + .addPreferredGap(ComponentPlacement.RELATED) + .addGroup(gl.createParallelGroup(Alignment.LEADING, false) + .addComponent(vmNameAndVersionLabel) + .addComponent(vmNameAndVersion)) + .addPreferredGap(ComponentPlacement.RELATED) + .addGroup(gl.createParallelGroup(Alignment.LEADING, false) + .addComponent(vmArgumentsLabel) + .addComponent(vmArguments)) + .addGap(0, 0, Short.MAX_VALUE) + .addContainerGap()); container = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); visiblePanel.setContent(container); } } -