Skip to content

Commit

Permalink
andrey4623#20 - limit the number of colours used in rendering to firs…
Browse files Browse the repository at this point in the history
…t X (max 10) using configurable value
  • Loading branch information
jcrawford authored and jcrawford committed Jul 28, 2023
1 parent 97cc928 commit 2368d02
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.List;

public class RainbowHighlightVisitor implements HighlightVisitor {
Expand Down Expand Up @@ -80,10 +79,13 @@ public boolean analyze(
@NotNull Runnable action
) {
this.holder = holder;

columnTextAttributes = Arrays.stream(RainbowCsvHelper.TEXT_ATTRIBUTES_KEYS)
.map(t -> this.holder.getColorsScheme().getAttributes(t))
.toArray(TextAttributes[]::new);

columnTextAttributes = new TextAttributes[CsvSettings.getInstance().getTextAttributesSize()];
for (int i = 0; i < CsvSettings.getInstance().getTextAttributesSize(); i++)
{
columnTextAttributes[i] = this.holder.getColorsScheme().getAttributes(RainbowCsvHelper.TEXT_ATTRIBUTES_KEYS[i]);
}

commentLineTextAttributes = this.holder.getColorsScheme().getAttributes(
RainbowCsvHelper.COMMENT_LINE_TEXT_ATTRIBUTES_KEYS
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,10 @@ public void setCommentPrefix(String commentPrefix) {
public String getCommentPrefix() {
return getState().commentPrefix;
}

public void setTextAttributesSize(Integer textAttributesSize) {
getState().textAttributesSize = textAttributesSize;
}
public Integer getTextAttributesSize() { return getState().textAttributesSize; }

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ public class CsvSettingsData {
public boolean highlightComments = false;

public String commentPrefix = "";


public Integer textAttributesSize = 10;

public CsvSettingsData() {
}
}
38 changes: 33 additions & 5 deletions src/main/java/com/andrey4623/rainbowcsv/settings/Settings.form
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@
</hspacer>
</children>
</grid>
<vspacer id="ca024">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<grid id="5e297" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
Expand Down Expand Up @@ -154,6 +149,39 @@
</component>
</children>
</grid>
<grid id="66f68" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="fe9c2" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Number of Colors:"/>
</properties>
</component>
<component id="41d20" class="javax.swing.JTextField" binding="textAttributesSize">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<toolTipText value="Integer between 1 and 10 (inc)"/>
</properties>
</component>
<hspacer id="32caf">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
</children>
</grid>
</children>
</grid>
</form>
29 changes: 24 additions & 5 deletions src/main/java/com/andrey4623/rainbowcsv/settings/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import com.intellij.util.FileContentUtil;

import org.apache.commons.lang3.math.NumberUtils;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -35,7 +37,9 @@ public class Settings implements EditorOptionsProvider {
private JComboBox escapeCharacterComboBox;
private JTextField commentPrefixTextField;
private JCheckBox highlightCommentsCheckBox;


private JTextField textAttributesSize;

@Override
public @NotNull String getId() {
return "RainbowCSV.Settings";
Expand All @@ -54,22 +58,36 @@ public class Settings implements EditorOptionsProvider {
@Override
public boolean isModified() {
CsvSettings settings = CsvSettings.getInstance();

return this.rainbowCSVEnabledCheckBox.isSelected() != settings.isEnabled()
|| !settings.getDelimiter().equals(this.delimiterComboBox.getSelectedItem())
|| !settings.getEscapeCharacter().equals(this.escapeCharacterComboBox.getSelectedItem())
|| !settings.getDelimiter().equals( this.delimiterComboBox.getSelectedItem() )
|| !settings.getEscapeCharacter().equals( this.escapeCharacterComboBox.getSelectedItem() )
|| settings.isHighlightComments() != this.highlightCommentsCheckBox.isSelected()
|| !settings.getCommentPrefix().equals(this.commentPrefixTextField.getText());
|| !settings.getCommentPrefix().equals( this.commentPrefixTextField.getText() )
|| !settings.getTextAttributesSize().toString().equals( textAttributesSize.getText() );
}

@Override
public void apply() throws ConfigurationException {

boolean digits = NumberUtils.isDigits( textAttributesSize.getText() );
if ( !digits )
{
throw new ConfigurationException( "Number of colours must be an integer" );
}
int size = Integer.parseInt( textAttributesSize.getText() );
if ( size > 10 || size < 0 )
{
throw new ConfigurationException( "Number of colors must be between 0 and 10" );
}

CsvSettings settings = CsvSettings.getInstance();
settings.setEnabled(rainbowCSVEnabledCheckBox.isSelected());
settings.setDelimiter((Delimiter) delimiterComboBox.getSelectedItem());
settings.setEscapeCharacter((EscapeCharacter) escapeCharacterComboBox.getSelectedItem());
settings.setHighlightComments(highlightCommentsCheckBox.isSelected());
settings.setCommentPrefix(commentPrefixTextField.getText());
settings.setTextAttributesSize( size );

reparseFiles();
}
Expand Down Expand Up @@ -107,6 +125,7 @@ public void reset() {
escapeCharacterComboBox.setSelectedItem(settings.getEscapeCharacter());
highlightCommentsCheckBox.setSelected(settings.isHighlightComments());
commentPrefixTextField.setText(settings.getCommentPrefix());
textAttributesSize.setText( settings.getTextAttributesSize().toString() );
}

protected void createUIComponents() {
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin require-restart="true">
<id>com.andrey4623.rainbowcsv</id>
<name>Rainbow CSV</name>
<version>2.0.2</version>
<version>2.1.0</version>
<vendor email="andreyka4623@gmail.com" url="https://github.com/andrey4623">Andrey Kolchanov</vendor>

<description><![CDATA[
Expand All @@ -23,6 +23,7 @@
]]></description>

<change-notes><![CDATA[
<p>2.1.0: Supports limited number of colours to use instead of the default 10
<p>2.0.2: 2022.1 Intellij support.</p>
<p>2.0.1: Small improvements.</p>
<p>2.0: Supports custom column colors and a custom comment line prefix.</p>
Expand Down

0 comments on commit 2368d02

Please sign in to comment.