From bb5e057d06ca8db3422ddc5e11a770a560a28d4c Mon Sep 17 00:00:00 2001 From: Rustam Vishnyakov Date: Fri, 4 Aug 2017 13:01:31 +0300 Subject: [PATCH] Changes according to IDEA-175743 review comments - Swap status and color columns --- .../fileStatus/FileStatusColorsTable.java | 31 ++++++++++++++----- .../FileStatusColorsTableModel.java | 4 +-- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/application/options/colors/fileStatus/FileStatusColorsTable.java b/platform/lang-impl/src/com/intellij/application/options/colors/fileStatus/FileStatusColorsTable.java index 5cf40b08a885..073ec12dd60a 100644 --- a/platform/lang-impl/src/com/intellij/application/options/colors/fileStatus/FileStatusColorsTable.java +++ b/platform/lang-impl/src/com/intellij/application/options/colors/fileStatus/FileStatusColorsTable.java @@ -23,6 +23,7 @@ import com.intellij.ui.ColorPicker; import com.intellij.ui.Gray; import com.intellij.ui.table.JBTable; import com.intellij.util.ui.EmptyIcon; +import com.intellij.util.ui.JBEmptyBorder; import com.intellij.util.ui.JBUI; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; @@ -58,7 +59,7 @@ public class FileStatusColorsTable extends JBTable { @Override public boolean onClick(@NotNull MouseEvent event, int clickCount) { int col = FileStatusColorsTable.this.columnAtPoint(event.getPoint()); - return getModel().getColumnClass(col).equals(Color.class) && setColor(); + return isColorColumn(col) && setColor(); } }.installOn(this); initPopup(); @@ -124,7 +125,7 @@ public class FileStatusColorsTable extends JBTable { private Point getPopupLocation() { int row = getSelectedRow(); if (row >= 0) { - Rectangle cellRect = getCellRect(row, 1, false); + Rectangle cellRect = getCellRect(row, 0, false); return cellRect.getLocation(); } return null; @@ -133,17 +134,18 @@ public class FileStatusColorsTable extends JBTable { private void editColor() { int row = getSelectedRow(); if (row >= 0) { - Color currentColor = (Color)getModel().getValueAt(row, 1); + int colorColumn = getColumn(Color.class); + Color currentColor = (Color)getModel().getValueAt(row, colorColumn); Color color = ColorPicker.showDialog(this, ApplicationBundle.message("title.file.status.color"), currentColor, true, null, false); if (color != null) { - getModel().setValueAt(color, row, 1); + getModel().setValueAt(color, row, colorColumn); } } } public void adjustColumnWidths() { for (int col = 0; col < getColumnCount(); col++) { - int rightGap = col > 0 ? JBUI.size(10,1).width : 0; + int rightGap = isColorColumn(col) ? JBUI.size(10, 1).width : 0; DefaultTableColumnModel colModel = (DefaultTableColumnModel) getColumnModel(); TableColumn column = colModel.getColumn(col); int width = 0; @@ -157,14 +159,26 @@ public class FileStatusColorsTable extends JBTable { } width += rightGap; column.setPreferredWidth(width); - if (col > 0) { + if (isColorColumn(col)) { column.setMinWidth(width); column.setMaxWidth(width); } } } + private boolean isColorColumn(int col) { + return getModel().getColumnClass(col).equals(Color.class); + } + + private int getColumn(@NotNull Class columnClass) { + for (int i = 0; i < getModel().getColumnCount(); i ++) { + if (getModel().getColumnClass(i).equals(columnClass)) return i; + } + return -1; + } + private static class MyColorCellRenderer implements TableCellRenderer { + public static final int RIGHT_GAP = 10; private Color myDefaultColor; public MyColorCellRenderer(@NotNull Color defaultColor) { @@ -175,6 +189,7 @@ public class FileStatusColorsTable extends JBTable { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JLabel colorLabel = new JLabel(); Color c = getDisplayColor(value); + colorLabel.setBorder(new JBEmptyBorder(0, RIGHT_GAP, 0, 0)); colorLabel.setIcon(getIcon(c)); //noinspection StringToUpperCaseOrToLowerCaseWithoutLocale colorLabel.setText(value != null ? "" : ApplicationBundle.message("file.status.color.none")); @@ -219,10 +234,10 @@ public class FileStatusColorsTable extends JBTable { final int size = scaleVal(COLOR_HEIGHT); final int y = j + (iconHeight - size) / 2; - g.fillRect(0, y, iconWidth, size); + g.fillRect(i, y, iconWidth, size); g.setColor(Gray.x00.withAlpha(40)); - g.drawRect(0, y, iconWidth, size); + g.drawRect(i, y, iconWidth, size); } } diff --git a/platform/lang-impl/src/com/intellij/application/options/colors/fileStatus/FileStatusColorsTableModel.java b/platform/lang-impl/src/com/intellij/application/options/colors/fileStatus/FileStatusColorsTableModel.java index f0f78caa4c8c..ba4fee8fce5e 100644 --- a/platform/lang-impl/src/com/intellij/application/options/colors/fileStatus/FileStatusColorsTableModel.java +++ b/platform/lang-impl/src/com/intellij/application/options/colors/fileStatus/FileStatusColorsTableModel.java @@ -37,9 +37,9 @@ public class FileStatusColorsTableModel extends AbstractTableModel { private final static ColumnInfo[] COLUMNS_INFO = { new ColumnInfo( - String.class, ApplicationBundle.message("file.status.colors.header.status"), descriptor -> descriptor.getStatus().getText()), + Color.class, ApplicationBundle.message("file.status.colors.header.color"), descriptor -> descriptor.getColor()), new ColumnInfo( - Color.class, ApplicationBundle.message("file.status.colors.header.color"), descriptor -> descriptor.getColor()) + String.class, ApplicationBundle.message("file.status.colors.header.status"), descriptor -> descriptor.getStatus().getText()) }; private static class ColumnInfo {