From bfa356bc72a4c44cea855c1e78f4b0a83f52d894 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 27 Jun 2011 20:53:17 +0400 Subject: [PATCH] Fix TreeTable row height for GTK+ L&F --- .../src/com/intellij/ui/table/JBTable.java | 20 ++++++------- .../ui/treeStructure/treetable/TreeTable.java | 30 +++++++++---------- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ui/table/JBTable.java b/platform/platform-api/src/com/intellij/ui/table/JBTable.java index 0426c864aed1..c17cd3e582b1 100644 --- a/platform/platform-api/src/com/intellij/ui/table/JBTable.java +++ b/platform/platform-api/src/com/intellij/ui/table/JBTable.java @@ -134,9 +134,9 @@ public class JBTable extends JTable implements ComponentWithEmptyText, Component TableModel model = getModel(); for (int row = 0; row < model.getRowCount(); row++) { for (int column = 0; column < model.getColumnCount(); column++) { - Dimension size = - getCellRenderer(row, column).getTableCellRendererComponent(this, model.getValueAt(row, column), true, true, row, column) - .getPreferredSize(); + Dimension size = getCellRenderer(row, column) + .getTableCellRendererComponent(this, model.getValueAt(row, column), true, true, row, column) + .getPreferredSize(); myRowHeight = Math.max(size.height, myRowHeight); } } @@ -153,18 +153,18 @@ public class JBTable extends JTable implements ComponentWithEmptyText, Component return Math.max(myRowHeight, myMinRowHeight); } - @Override - public void updateUI() { - super.updateUI(); - myMinRowHeight = null; - } - @Override public void setRowHeight(int rowHeight) { myRowHeight = rowHeight; myRowHeightIsExplicitlySet = true; } + @Override + public void updateUI() { + super.updateUI(); + myMinRowHeight = null; + } + private void repaintViewport() { if (!isDisplayable() || !isVisible()) return; @@ -260,7 +260,7 @@ public class JBTable extends JTable implements ComponentWithEmptyText, Component public static DefaultCellEditor createBooleanEditor() { return new DefaultCellEditor(new JCheckBox()) { { - ((JCheckBox)getComponent()).setHorizontalAlignment(JCheckBox.CENTER); + ((JCheckBox)getComponent()).setHorizontalAlignment(SwingConstants.CENTER); } @Override diff --git a/platform/platform-api/src/com/intellij/ui/treeStructure/treetable/TreeTable.java b/platform/platform-api/src/com/intellij/ui/treeStructure/treetable/TreeTable.java index acbc708c571e..acd365b0b9e8 100644 --- a/platform/platform-api/src/com/intellij/ui/treeStructure/treetable/TreeTable.java +++ b/platform/platform-api/src/com/intellij/ui/treeStructure/treetable/TreeTable.java @@ -56,20 +56,18 @@ public class TreeTable extends JBTable { @SuppressWarnings({"MethodOverloadsMethodOfSuperclass"}) public void setModel(TreeTableModel treeTableModel) {// Create the tree. It will be used as a renderer and editor. - if (myTree != null){ + if (myTree != null) { myTree.removePropertyChangeListener(JTree.ROW_HEIGHT_PROPERTY, myTreeRowHeightPropertyListener); } myTree = new TreeTableTree(treeTableModel, this); - if (myTree.getRowHeight() != getRowHeight()){ - setRowHeight(myTree.getRowHeight()); - } + setRowHeight(myTree.getRowHeight()); myTreeRowHeightPropertyListener = new PropertyChangeListener() { - public void propertyChange(PropertyChangeEvent evt) { - int treeRowHeight = myTree.getRowHeight(); - if (treeRowHeight == getRowHeight() - 3) return; - setRowHeight(treeRowHeight); - } - }; + public void propertyChange(PropertyChangeEvent evt) { + int treeRowHeight = myTree.getRowHeight(); + if (treeRowHeight == getRowHeight() - 3) return; + setRowHeight(treeRowHeight); + } + }; myTree.addPropertyChangeListener(JTree.ROW_HEIGHT_PROPERTY, myTreeRowHeightPropertyListener); // Install a tableModel representing the visible rows in the tree. @@ -90,13 +88,13 @@ public class TreeTable extends JBTable { // No intercell spacing setIntercellSpacing(new Dimension(0, 0)); - // And update the height of the trees row to match that of - // the table. + // And update the height of the trees row to match that of the table. if (myTree.getRowHeight() < 1) { - // Metal looks better like this. - setRowHeight(18); + setRowHeight(18); // Metal looks better like this. + } + else { + setRowHeight(getRowHeight()); } - setRowHeight(getRowHeight()); } public TreeTableModel getTableModel() { @@ -122,7 +120,7 @@ public class TreeTable extends JBTable { /** * Overridden to message super and forward the method to the tree. - * Since the tree is not actually in the component hieachy it will + * Since the tree is not actually in the component hierarchy it will * never receive this unless we forward it in this manner. */ public void updateUI() {