Skip to content

Commit 01db0e5

Browse files
committed
[FEATURE] column coloring setting with default "Rainbow"
1 parent 63dfb65 commit 01db0e5

File tree

12 files changed

+259
-85
lines changed

12 files changed

+259
-85
lines changed

src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvAnnotator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void annotate(@NotNull final PsiElement element, @NotNull final Annotatio
6767

6868
Annotation annotation = holder.createAnnotation(CSV_COLUMN_INFO_SEVERITY, textRange, message, tooltip);
6969
annotation.setEnforcedTextAttributes(
70-
CsvEditorSettings.getInstance().isColumnHighlightingEnabled() ?
70+
CsvEditorSettings.getInstance().getColumnColoring() == CsvEditorSettings.ColumnColoring.RAINBOW ?
7171
CsvColorSettings.getTextAttributesOfColumn(columnInfo.getColumnIndex(), holder.getCurrentAnnotationSession()) :
7272
null
7373
);

src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/CsvTableEditorSwing.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.seesharpsoft.intellij.plugins.csv.editor.table.swing;
22

33
import com.intellij.openapi.editor.colors.EditorColorsManager;
4+
import com.intellij.openapi.editor.colors.EditorColorsScheme;
45
import com.intellij.openapi.project.Project;
56
import com.intellij.openapi.vfs.VirtualFile;
67
import com.intellij.psi.PsiElement;
@@ -94,6 +95,8 @@ protected void createUIComponents() {
9495
}
9596

9697
private void initializedUIComponents() {
98+
EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme();
99+
97100
btnRedo.addActionListener(tableEditorActions.redo);
98101
btnUndo.addActionListener(tableEditorActions.undo);
99102
btnAddRow.addActionListener(tableEditorActions.addRow);
@@ -129,6 +132,8 @@ private void initializedUIComponents() {
129132
tblEditor.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
130133
tblEditor.setShowColumns(true);
131134
tblEditor.setFont(getFont());
135+
tblEditor.setBackground(editorColorsScheme.getDefaultBackground());
136+
tblEditor.setForeground(editorColorsScheme.getDefaultForeground());
132137
setTableRowHeight(0);
133138

134139
tblEditor.getColumnModel().addColumnModelListener(tableEditorListener);

src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/MultiLineCellRenderer.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package net.seesharpsoft.intellij.plugins.csv.editor.table.swing;
22

33
import com.intellij.openapi.editor.colors.EditorColorsManager;
4+
import com.intellij.openapi.editor.colors.EditorColorsScheme;
45
import com.intellij.openapi.editor.colors.EditorFontType;
56
import com.intellij.openapi.editor.impl.FontFallbackIterator;
67
import com.intellij.openapi.editor.markup.TextAttributes;
78
import com.intellij.openapi.util.UserDataHolder;
89
import com.intellij.ui.components.JBScrollPane;
910
import com.intellij.util.ui.UIUtil;
10-
import net.seesharpsoft.intellij.plugins.csv.settings.CsvEditorSettings;
1111
import net.seesharpsoft.intellij.plugins.csv.settings.CsvColorSettings;
1212
import org.jetbrains.annotations.NotNull;
1313

@@ -46,10 +46,7 @@ public MultiLineCellRenderer(CsvTableEditorKeyListener keyListener, UserDataHold
4646
}
4747

4848
private TextAttributes getColumnTextAttributes(int column) {
49-
if (CsvEditorSettings.getInstance().isTableColumnHighlightingEnabled()) {
50-
return CsvColorSettings.getTextAttributesOfColumn(column, myUserDataHolder);
51-
}
52-
return null;
49+
return CsvColorSettings.getTextAttributesOfColumn(column, myUserDataHolder);
5350
}
5451

5552
private Color getColumnForegroundColor(int column, Color fallback) {
@@ -64,6 +61,8 @@ private Color getColumnBackgroundColor(int column, Color fallback) {
6461

6562
@Override
6663
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
64+
EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme();
65+
6766
if (isSelected) {
6867
myTextArea.setForeground(table.getSelectionForeground());
6968
myTextArea.setBackground(table.getSelectionBackground());
@@ -74,8 +73,8 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole
7473
if (hasFocus) {
7574
myTextArea.setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
7675
if (table.isCellEditable(row, column)) {
77-
myTextArea.setForeground(UIManager.getColor("Table.focusCellForeground"));
78-
myTextArea.setBackground(UIManager.getColor("Table.focusCellBackground"));
76+
myTextArea.setForeground(UIManager.getColor(editorColorsScheme.getDefaultForeground()));
77+
myTextArea.setBackground(UIManager.getColor(editorColorsScheme.getDefaultBackground()));
7978
}
8079
} else {
8180
myTextArea.setBorder(new EmptyBorder(1, 2, 1, 2));

src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvColorSettings.java

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.intellij.openapi.options.colors.ColorSettingsPage;
1212
import com.intellij.openapi.util.Key;
1313
import com.intellij.openapi.util.UserDataHolder;
14+
import net.seesharpsoft.UnhandledSwitchCaseException;
1415
import net.seesharpsoft.intellij.plugins.csv.CsvIconProvider;
1516
import net.seesharpsoft.intellij.plugins.csv.highlighter.CsvSyntaxHighlighter;
1617
import org.jetbrains.annotations.NotNull;
@@ -25,10 +26,10 @@
2526

2627
public class CsvColorSettings implements ColorSettingsPage {
2728

28-
private static final Integer MAX_COLUMN_HIGHLIGHT_COLORS = 10;
29+
private static final Integer MAX_COLUMN_COLORING_COLORS = 10;
2930
private static final AttributesDescriptor[] DESCRIPTORS;
30-
private static final List<TextAttributesKey> COLUMN_HIGHLIGHT_ATTRIBUTES;
31-
private static final Key<List<TextAttributes>> COLUMN_HIGHLIGHT_TEXT_ATTRIBUTES_KEY = Key.create("CSV_PLUGIN_COLUMN_HIGHLIGHT_ATTRIBUTES");
31+
private static final List<TextAttributesKey> COLUMN_COLORING_ATTRIBUTES;
32+
private static final Key<List<TextAttributes>> COLUMN_COLORING_TEXT_ATTRIBUTES_KEY = Key.create("CSV_PLUGIN_COLUMN_COLORING_ATTRIBUTES");
3233

3334
static {
3435
List<AttributesDescriptor> attributesDescriptors = new ArrayList();
@@ -38,35 +39,51 @@ public class CsvColorSettings implements ColorSettingsPage {
3839
attributesDescriptors.add(new AttributesDescriptor("Escaped Text", CsvSyntaxHighlighter.ESCAPED_TEXT));
3940
attributesDescriptors.add(new AttributesDescriptor("Comment", CsvSyntaxHighlighter.COMMENT));
4041

41-
COLUMN_HIGHLIGHT_ATTRIBUTES = new ArrayList<>();
42-
for (int i = 0; i < MAX_COLUMN_HIGHLIGHT_COLORS; ++i) {
43-
TextAttributesKey textAttributesKey = createTextAttributesKey(String.format("CSV_COLUMN_HIGHLIGHT_ATTRIBUTE_%d", i + 1), DefaultLanguageHighlighterColors.STRING);
44-
COLUMN_HIGHLIGHT_ATTRIBUTES.add(textAttributesKey);
45-
attributesDescriptors.add(new AttributesDescriptor(String.format("Column Highlighting Color %d", i + 1), textAttributesKey));
42+
COLUMN_COLORING_ATTRIBUTES = new ArrayList<>();
43+
for (int i = 0; i < MAX_COLUMN_COLORING_COLORS; ++i) {
44+
TextAttributesKey textAttributesKey = createTextAttributesKey(String.format("CSV_PLUGIN_COLUMN_COLORING_ATTRIBUTE_%d", i + 1), CsvSyntaxHighlighter.TEXT);
45+
COLUMN_COLORING_ATTRIBUTES.add(textAttributesKey);
46+
attributesDescriptors.add(new AttributesDescriptor(String.format("Rainbow column color %d", i + 1), textAttributesKey));
4647
}
4748
DESCRIPTORS = attributesDescriptors.toArray(new AttributesDescriptor[attributesDescriptors.size()]);
4849
}
4950

5051
public static TextAttributes getTextAttributesOfColumn(int columnIndex, UserDataHolder userDataHolder) {
51-
List<TextAttributes> textAttributeList = userDataHolder.getUserData(COLUMN_HIGHLIGHT_TEXT_ATTRIBUTES_KEY);
52+
List<TextAttributes> textAttributeList = userDataHolder.getUserData(COLUMN_COLORING_TEXT_ATTRIBUTES_KEY);
5253
if (textAttributeList == null) {
5354
EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme();
5455
textAttributeList = new ArrayList<>();
5556
int maxIndex = 0;
56-
for (int colorDescriptorIndex = 0; colorDescriptorIndex < MAX_COLUMN_HIGHLIGHT_COLORS; ++colorDescriptorIndex) {
57-
TextAttributesKey textAttributesKey = COLUMN_HIGHLIGHT_ATTRIBUTES.get(colorDescriptorIndex);
58-
TextAttributes textAttributes = editorColorsScheme.getAttributes(textAttributesKey);
59-
textAttributeList.add(textAttributes);
60-
if (!textAttributesKey.getDefaultAttributes().equals(textAttributes)) {
61-
maxIndex = colorDescriptorIndex;
62-
}
57+
switch(CsvEditorSettings.getInstance().getColumnColoring()) {
58+
case RAINBOW:
59+
maxIndex = applyColumnTextAttributes(editorColorsScheme, textAttributeList);
60+
break;
61+
case SIMPLE:
62+
textAttributeList.add(editorColorsScheme.getAttributes(CsvSyntaxHighlighter.TEXT));
63+
break;
64+
default:
65+
throw new UnhandledSwitchCaseException(CsvEditorSettings.getInstance().getColumnColoring());
6366
}
6467
textAttributeList = textAttributeList.subList(0, maxIndex + 1);
65-
userDataHolder.putUserData(COLUMN_HIGHLIGHT_TEXT_ATTRIBUTES_KEY, textAttributeList);
68+
userDataHolder.putUserData(COLUMN_COLORING_TEXT_ATTRIBUTES_KEY, textAttributeList);
6669
}
6770
return textAttributeList.isEmpty() ? null : textAttributeList.get(columnIndex % textAttributeList.size());
6871
}
6972

73+
private static int applyColumnTextAttributes(EditorColorsScheme editorColorsScheme, List<TextAttributes> textAttributeList) {
74+
int maxIndex = 0;
75+
TextAttributes defaultTextAttributes = editorColorsScheme.getAttributes(CsvSyntaxHighlighter.TEXT);
76+
for (int colorDescriptorIndex = 0; colorDescriptorIndex < MAX_COLUMN_COLORING_COLORS; ++colorDescriptorIndex) {
77+
TextAttributesKey textAttributesKey = COLUMN_COLORING_ATTRIBUTES.get(colorDescriptorIndex);
78+
TextAttributes textAttributes = editorColorsScheme.getAttributes(textAttributesKey);
79+
textAttributeList.add(textAttributes);
80+
if (!textAttributes.equals(defaultTextAttributes)) {
81+
maxIndex = colorDescriptorIndex;
82+
}
83+
}
84+
return maxIndex;
85+
}
86+
7087
@Nullable
7188
@Override
7289
public Icon getIcon() {
@@ -85,7 +102,7 @@ public String getDemoText() {
85102
return "1,\"Eldon Base for stackable storage shelf, platinum\",Muhammed MacIntyre,3,-213.25,38.94,35,Nunavut,Storage & Organization,0.8\n" +
86103
"2,\"1.7 Cubic Foot Compact \"\"Cube\"\" Office Refrigerators\",Barry French,293,457.81,208.16,68.02,Nunavut,Appliances,0.58\n" +
87104
"3,\"Cardinal Slant-D® Ring Binder, Heavy Gauge Vinyl\",Barry French,293,46.71,8.69,2.99,Nunavut,Binders and Binder Accessories,0.39\n" +
88-
"4,R380,Clay Rozendal,483,1198.97,195.99,3.99,Nunavut,Telephones and Communication,0.58\n" +
105+
"#4,R380,Clay Rozendal,483,1198.97,195.99,3.99,Nunavut,Telephones and Communication,0.58\n" +
89106
"5,Holmes HEPA Air Purifier,Carlos Soltero,515,30.94,21.78,5.94,Nunavut,Appliances,0.5";
90107
}
91108

src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvEditorSettings.java

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,24 @@ public enum EditorPrio {
4242
TEXT_ONLY
4343
}
4444

45+
public enum ColumnColoring {
46+
RAINBOW("Rainbow (colorful columns)"),
47+
SIMPLE("Simple (single text color)");
48+
49+
private final String display;
50+
51+
ColumnColoring(String displayArg) {
52+
this.display = displayArg;
53+
}
54+
55+
public String getDisplay() {
56+
return this.display;
57+
}
58+
}
59+
4560
public static final class OptionSet {
4661
public boolean CARET_ROW_SHOWN;
4762
public boolean USE_SOFT_WRAP;
48-
public boolean COLUMN_HIGHTLIGHTING = true;
4963
public boolean HIGHTLIGHT_TAB_SEPARATOR = true;
5064
public boolean SHOW_INFO_BALLOON = true;
5165
public String TAB_HIGHLIGHT_COLOR = "-7984";
@@ -54,7 +68,6 @@ public static final class OptionSet {
5468
public int TABLE_AUTO_MAX_COLUMN_WIDTH = TABLE_AUTO_MAX_COLUMN_WIDTH_DEFAULT;
5569
public int TABLE_DEFAULT_COLUMN_WIDTH = TABLE_DEFAULT_COLUMN_WIDTH_DEFAULT;
5670
public boolean TABLE_AUTO_COLUMN_WIDTH_ON_OPEN = false;
57-
public boolean TABLE_COLUMN_HIGHTLIGHTING = true;
5871
public boolean ZERO_BASED_COLUMN_NUMBERING = false;
5972

6073
public boolean SHOW_TABLE_EDITOR_INFO_PANEL = true;
@@ -66,6 +79,7 @@ public static final class OptionSet {
6679
public CsvValueSeparator DEFAULT_VALUE_SEPARATOR = VALUE_SEPARATOR_DEFAULT;
6780
public boolean KEEP_TRAILING_SPACES = false;
6881
public String COMMENT_INDICATOR = COMMENT_INDICATOR_DEFAULT;
82+
public ColumnColoring COLUMN_COLORING = ColumnColoring.RAINBOW;
6983

7084
public OptionSet() {
7185
EditorSettingsExternalizable editorSettingsExternalizable = EditorSettingsExternalizable.getInstance();
@@ -121,14 +135,6 @@ public void setUseSoftWraps(boolean useSoftWraps) {
121135
getState().USE_SOFT_WRAP = useSoftWraps;
122136
}
123137

124-
public boolean isColumnHighlightingEnabled() {
125-
return getState().COLUMN_HIGHTLIGHTING;
126-
}
127-
128-
public void setColumnHighlightingEnabled(boolean columnHighlightingEnabled) {
129-
getState().COLUMN_HIGHTLIGHTING = columnHighlightingEnabled;
130-
}
131-
132138
public boolean isHighlightTabSeparator() {
133139
return getState().HIGHTLIGHT_TAB_SEPARATOR;
134140
}
@@ -193,14 +199,6 @@ public void setQuotingEnforced(boolean quotingEnforced) {
193199
getState().QUOTING_ENFORCED = quotingEnforced;
194200
}
195201

196-
public boolean isTableColumnHighlightingEnabled() {
197-
return getState().TABLE_COLUMN_HIGHTLIGHTING;
198-
}
199-
200-
public void setTableColumnHighlightingEnabled(boolean columnHighlightingEnabled) {
201-
getState().TABLE_COLUMN_HIGHTLIGHTING = columnHighlightingEnabled;
202-
}
203-
204202
public boolean isZeroBasedColumnNumbering() {
205203
return getState().ZERO_BASED_COLUMN_NUMBERING;
206204
}
@@ -286,4 +284,12 @@ public void setCommentIndicator(String commentIndicator) {
286284
public String getCommentIndicator() {
287285
return getState().COMMENT_INDICATOR;
288286
}
287+
288+
public ColumnColoring getColumnColoring() {
289+
return getState().COLUMN_COLORING;
290+
}
291+
292+
public void setColumnColoring(ColumnColoring columnColoring) {
293+
getState().COLUMN_COLORING = columnColoring;
294+
}
289295
}

0 commit comments

Comments
 (0)