Mercurial > hg > release > thermostat-0.6
changeset 691:44a3fceb264d
Cleanup tables
review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-October/003698.html
reviewed-by: rkennke
line wrap: on
line diff
--- a/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/swing/HistogramPanel.java Tue Oct 09 11:59:26 2012 -0400 +++ b/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/swing/HistogramPanel.java Wed Oct 10 10:16:54 2012 +0200 @@ -57,6 +57,8 @@ import com.redhat.thermostat.common.heap.ObjectHistogram; import com.redhat.thermostat.common.utils.DescriptorConverter; import com.redhat.thermostat.swing.HeaderPanel; +import com.redhat.thermostat.swing.ThermostatTable; +import com.redhat.thermostat.swing.ThermostatTableRenderer; @SuppressWarnings("serial") public class HistogramPanel extends HeapHistogramView implements SwingComponent { @@ -75,17 +77,12 @@ @Override public void display(ObjectHistogram histogram) { - JTable table = new JTable(new HistogramTableModel(histogram)); - - table.setFillsViewportHeight(true); - table.setAutoCreateRowSorter(true); + ThermostatTable table = new ThermostatTable(new HistogramTableModel(histogram)); table.setDefaultRenderer(Long.class, new NiceNumberFormatter()); - - JScrollPane scrollPane = new JScrollPane(table); - headerPanel.setContent(scrollPane); + headerPanel.setContent(table.wrap()); } - private final class NiceNumberFormatter extends DefaultTableCellRenderer { + private final class NiceNumberFormatter extends ThermostatTableRenderer { private final DecimalFormat formatter = new DecimalFormat("###,###.###");
--- a/client/swing-components/src/main/java/com/redhat/thermostat/swing/Palette.java Tue Oct 09 11:59:26 2012 -0400 +++ b/client/swing-components/src/main/java/com/redhat/thermostat/swing/Palette.java Wed Oct 10 10:16:54 2012 +0200 @@ -59,6 +59,8 @@ VIOLET(new Color(112, 48, 160)), EARL_GRAY(new Color(128, 128, 128)), + + PALE_GRAY(new Color(235, 235, 235)), LIGHT_GRAY(new Color(242, 242, 242)), GRAY(new Color(216, 216, 216)), DARK_GRAY(new Color(168, 172, 168)),
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/swing-components/src/main/java/com/redhat/thermostat/swing/ThermostatTable.java Wed Oct 10 10:16:54 2012 +0200 @@ -0,0 +1,71 @@ +/* + * 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.swing; + +import java.awt.Dimension; + +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.table.DefaultTableModel; + +@SuppressWarnings("serial") +public class ThermostatTable extends JTable { + + public ThermostatTable() { + this((DefaultTableModel) null); + } + + public ThermostatTable(DefaultTableModel model) { + super(model); + + setIntercellSpacing(new Dimension(0, 0)); + + setFillsViewportHeight(true); + setAutoCreateRowSorter(true); + + setDefaultRenderer(Object.class, new ThermostatTableRenderer()); + setDefaultRenderer(Double.class, new ThermostatTableRenderer()); + setDefaultRenderer(Long.class, new ThermostatTableRenderer()); + setDefaultRenderer(String.class, new ThermostatTableRenderer()); + setDefaultRenderer(Integer.class, new ThermostatTableRenderer()); + } + + public JScrollPane wrap() { + JScrollPane scrollPane = new JScrollPane(this); + return scrollPane; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/swing-components/src/main/java/com/redhat/thermostat/swing/ThermostatTableRenderer.java Wed Oct 10 10:16:54 2012 +0200 @@ -0,0 +1,66 @@ +/* + * 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.swing; + +import java.awt.Component; + +import javax.swing.JTable; +import javax.swing.table.DefaultTableCellRenderer; + +@SuppressWarnings("serial") +public class ThermostatTableRenderer extends DefaultTableCellRenderer { + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, + boolean isSelected, boolean hasFocus, int row, int column) { + + Component result = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + if (result == null || isSelected) { + // do nothing + } else if (!isEven(row)) { + result.setBackground(Palette.LIGHT_GRAY.getColor()); + } else { + result.setBackground(Palette.WHITE.getColor()); + } + + return result; + } + + private boolean isEven(int row) { + return row % 2 == 0; + } +}
--- a/dolphin/src/main/java/com/redhat/swing/laf/dolphin/DolphinLookAndFeel.java Tue Oct 09 11:59:26 2012 -0400 +++ b/dolphin/src/main/java/com/redhat/swing/laf/dolphin/DolphinLookAndFeel.java Wed Oct 10 10:16:54 2012 +0200 @@ -158,6 +158,10 @@ "TableHeader.font", theme.getTableHeaderFont(), "Table.ascendingSortIcon", new IconUIResource(new DolphinAscendingArrowIcon()), "Table.descendingSortIcon", new IconUIResource(new DolphinDescendingArrowIcon()), + + "Table.selectionBackground", theme.getTableSelectionCellBackground(), + "Table.selectionForeground", theme.getTableSelectionCellForeground(), + "TableHeader.rightAlignSortArrow", true, };
--- a/dolphin/src/main/java/com/redhat/swing/laf/dolphin/themes/DolphinDefaultTheme.java Tue Oct 09 11:59:26 2012 -0400 +++ b/dolphin/src/main/java/com/redhat/swing/laf/dolphin/themes/DolphinDefaultTheme.java Wed Oct 10 10:16:54 2012 +0200 @@ -108,6 +108,8 @@ private static final ColorUIResource SEPARATOR = new ColorUIResource(0xebebeb); + private static final ColorUIResource TABLE_SEPARATOR = new ColorUIResource(0xf2f2f2); + private static final ColorUIResource TABLE_HEADER_FOREGROUND = new ColorUIResource(0x888a85); private static final ColorUIResource ICONS_COLOR = TABLE_HEADER_FOREGROUND; @@ -430,6 +432,16 @@ } @Override + public ColorUIResource getTableSelectionCellBackground() { + return SELECTION_COLOR; + } + + @Override + public ColorUIResource getTableSelectionCellForeground() { + return SELECTION_FOREGROUND; + } + + @Override public void addCustomEntriesToTable(UIDefaults table) { super.addCustomEntriesToTable(table); @@ -465,6 +477,8 @@ "TabbedPane.tabAreaBackground", getTabAreaBackground(), "TabbedPane.background", getTabAreaBackground(), "TabbedPane.foreground", getTabAreaForeground(), + + "Table.gridColor", TABLE_SEPARATOR, }; table.putDefaults(uiDefaults);
--- a/dolphin/src/main/java/com/redhat/swing/laf/dolphin/themes/DolphinTheme.java Tue Oct 09 11:59:26 2012 -0400 +++ b/dolphin/src/main/java/com/redhat/swing/laf/dolphin/themes/DolphinTheme.java Wed Oct 10 10:16:54 2012 +0200 @@ -140,4 +140,6 @@ abstract public int getOneTouchButtonSize(); abstract public int getOneTouchButtonOffset(); + abstract public ColorUIResource getTableSelectionCellBackground(); + abstract public ColorUIResource getTableSelectionCellForeground(); }
--- a/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadTableView.java Tue Oct 09 11:59:26 2012 -0400 +++ b/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadTableView.java Wed Oct 10 10:16:54 2012 +0200 @@ -52,6 +52,7 @@ import com.redhat.thermostat.client.ui.ComponentVisibleListener; import com.redhat.thermostat.client.ui.SwingComponent; +import com.redhat.thermostat.swing.ThermostatTable; import com.redhat.thermostat.thread.client.common.locale.LocaleResources; import com.redhat.thermostat.common.locale.Translate; import com.redhat.thermostat.thread.client.common.ThreadTableBean; @@ -61,7 +62,7 @@ private int currentSelection = -1; - private JTable table; + private ThermostatTable table; private ThreadTable tablePanel; private static final Translate t = LocaleResources.createLocalizer(); @@ -80,7 +81,7 @@ } }); - table = new JTable(new ThreadViewTableModel(new ArrayList<ThreadTableBean>())); + table = new ThermostatTable(new ThreadViewTableModel(new ArrayList<ThreadTableBean>())); table.setName("threadBeansTable"); table.getModel().addTableModelListener(new TableModelListener() { @Override @@ -101,9 +102,7 @@ }); } }); - table.setFillsViewportHeight(true); - table.setAutoCreateRowSorter(true); - tablePanel.setTable(table); + tablePanel.add(table.wrap()); table.addMouseListener(new MouseAdapter() { @Override
--- a/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/ThreadTable.java Tue Oct 09 11:59:26 2012 -0400 +++ b/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/ThreadTable.java Wed Oct 10 10:16:54 2012 +0200 @@ -38,25 +38,13 @@ import javax.swing.JPanel; import javax.swing.BoxLayout; -import javax.swing.JScrollPane; -import javax.swing.JTable; @SuppressWarnings("serial") public class ThreadTable extends JPanel { - - private JScrollPane scrollPane; - /** * Create the panel. */ public ThreadTable() { setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); - - scrollPane = new JScrollPane(); - add(scrollPane); - } - - void setTable(JTable table) { - scrollPane.setViewportView(table); } }