Changes according to IDEA-175743 review comments

- Swap status and color columns
This commit is contained in:
Rustam Vishnyakov
2017-08-04 13:18:45 +03:00
parent acc6fd94ee
commit bb5e057d06
2 changed files with 25 additions and 10 deletions
@@ -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);
}
}
@@ -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 {