Skip to content

Commit 82ee540

Browse files
committed
[INTERNAL] Simplify & Optimize
1 parent dd92ad1 commit 82ee540

File tree

4 files changed

+62
-113
lines changed

4 files changed

+62
-113
lines changed

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

Lines changed: 0 additions & 84 deletions
This file was deleted.

src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvEditorSettingsPanel.form renamed to src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvEditorSettingsProvider.form

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="net.seesharpsoft.intellij.plugins.csv.editor.CsvEditorSettingsPanel">
2+
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="net.seesharpsoft.intellij.plugins.csv.editor.CsvEditorSettingsProvider">
33
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
44
<margin top="0" left="0" bottom="0" right="0"/>
55
<constraints>

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

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,82 @@
22

33
import com.intellij.openapi.options.ConfigurationException;
44
import com.intellij.openapi.options.SearchableConfigurable;
5+
import com.intellij.ui.CheckBoxWithColorChooser;
56
import org.jetbrains.annotations.NotNull;
67
import org.jetbrains.annotations.Nullable;
78

89
import javax.swing.*;
10+
import java.awt.*;
11+
import java.util.Objects;
912

1013
public class CsvEditorSettingsProvider implements SearchableConfigurable {
14+
private JCheckBox cbCaretRowShown;
15+
private JPanel myMainPanel;
16+
private JCheckBox cbUseSoftWraps;
17+
private JCheckBox cbColumnHighlighting;
18+
private JPanel panelHighlighting;
19+
private CheckBoxWithColorChooser cbTabHighlightColor;
1120

12-
private CsvEditorSettingsPanel myCsvEditorSettingsPanel;
21+
@NotNull
22+
@Override
23+
public String getId() {
24+
return "Csv.Editor.Settings";
25+
}
1326

27+
@Override
1428
public String getDisplayName() {
1529
return "CSV/TSV Editor";
1630
}
1731

32+
@Override
1833
public String getHelpTopic() {
1934
return "Editor Options for CSV/TSV files";
2035
}
2136

22-
@NotNull
23-
public String getId() {
24-
return "CSV_EDITOR_OPTIONS";
25-
}
26-
2737
@Nullable
2838
@Override
2939
public JComponent createComponent() {
30-
this.myCsvEditorSettingsPanel = new CsvEditorSettingsPanel();
31-
return this.myCsvEditorSettingsPanel.createComponent();
40+
return myMainPanel;
3241
}
3342

34-
@Override
35-
public boolean isModified() {
36-
return this.myCsvEditorSettingsPanel != null && this.myCsvEditorSettingsPanel.isModified();
43+
// ensure downward compatibility
44+
public boolean isModified(@NotNull JToggleButton toggleButton, boolean value) {
45+
return toggleButton.isSelected() != value;
3746
}
3847

3948
@Override
40-
public void apply() throws ConfigurationException {
41-
if (this.myCsvEditorSettingsPanel != null) {
42-
this.myCsvEditorSettingsPanel.apply();
43-
}
49+
public boolean isModified() {
50+
CsvEditorSettingsExternalizable csvEditorSettingsExternalizable = CsvEditorSettingsExternalizable.getInstance();
51+
return isModified(cbCaretRowShown, csvEditorSettingsExternalizable.isCaretRowShown()) ||
52+
isModified(cbUseSoftWraps, csvEditorSettingsExternalizable.isUseSoftWraps()) ||
53+
isModified(cbColumnHighlighting, csvEditorSettingsExternalizable.isColumnHighlightingEnabled()) ||
54+
cbTabHighlightColor.isSelected() != csvEditorSettingsExternalizable.isHighlightTabSeparator() ||
55+
!Objects.equals(cbTabHighlightColor.getColor(), csvEditorSettingsExternalizable.getTabHighlightColor());
4456
}
4557

4658
@Override
4759
public void reset() {
48-
if (this.myCsvEditorSettingsPanel != null) {
49-
this.myCsvEditorSettingsPanel.reset();
50-
}
60+
CsvEditorSettingsExternalizable csvEditorSettingsExternalizable = CsvEditorSettingsExternalizable.getInstance();
61+
cbCaretRowShown.setSelected(csvEditorSettingsExternalizable.isCaretRowShown());
62+
cbUseSoftWraps.setSelected(csvEditorSettingsExternalizable.isUseSoftWraps());
63+
cbColumnHighlighting.setSelected(csvEditorSettingsExternalizable.isColumnHighlightingEnabled());
64+
cbTabHighlightColor.setSelected(csvEditorSettingsExternalizable.isHighlightTabSeparator());
65+
cbTabHighlightColor.setColor(csvEditorSettingsExternalizable.getTabHighlightColor());
5166
}
5267

5368
@Override
54-
public void disposeUIResources() {
55-
this.myCsvEditorSettingsPanel.disposeUIResources();
56-
this.myCsvEditorSettingsPanel = null;
69+
public void apply() throws ConfigurationException {
70+
CsvEditorSettingsExternalizable csvEditorSettingsExternalizable = CsvEditorSettingsExternalizable.getInstance();
71+
csvEditorSettingsExternalizable.setCaretRowShown(cbCaretRowShown.isSelected());
72+
csvEditorSettingsExternalizable.setUseSoftWraps(cbUseSoftWraps.isSelected());
73+
csvEditorSettingsExternalizable.setColumnHighlightingEnabled(cbColumnHighlighting.isSelected());
74+
csvEditorSettingsExternalizable.setHighlightTabSeparator(cbTabHighlightColor.isSelected());
75+
csvEditorSettingsExternalizable.setTabHighlightColor(cbTabHighlightColor.getColor());
76+
}
77+
78+
79+
private void createUIComponents() {
80+
cbTabHighlightColor = new CheckBoxWithColorChooser("Highlight tab separator ");
81+
cbTabHighlightColor.setColor(Color.CYAN);
5782
}
5883
}

src/test/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvEditorSettingsPanelTest.java renamed to src/test/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvEditorSettingsProviderTest.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import java.awt.*;
77

8-
public class CsvEditorSettingsPanelTest extends LightCodeInsightFixtureTestCase {
8+
public class CsvEditorSettingsProviderTest extends LightCodeInsightFixtureTestCase {
99

1010
@Override
1111
protected String getTestDataPath() {
@@ -18,31 +18,39 @@ protected void setUp() throws Exception {
1818
}
1919

2020
public void testId() {
21-
CsvEditorSettingsPanel editorSettingsPanel = new CsvEditorSettingsPanel();
21+
CsvEditorSettingsProvider editorSettingsPanel = new CsvEditorSettingsProvider();
2222

2323
assertEquals("Csv.Editor.Settings", editorSettingsPanel.getId());
2424

2525
editorSettingsPanel.disposeUIResources();
2626
}
2727

2828
public void testDisplayName() {
29-
CsvEditorSettingsPanel editorSettingsPanel = new CsvEditorSettingsPanel();
29+
CsvEditorSettingsProvider editorSettingsPanel = new CsvEditorSettingsProvider();
3030

31-
assertEquals("CSV/TSV Editor Settings", editorSettingsPanel.getDisplayName());
31+
assertEquals("CSV/TSV Editor", editorSettingsPanel.getDisplayName());
32+
33+
editorSettingsPanel.disposeUIResources();
34+
}
35+
36+
public void testHelpTopic() {
37+
CsvEditorSettingsProvider editorSettingsPanel = new CsvEditorSettingsProvider();
38+
39+
assertEquals("Editor Options for CSV/TSV files", editorSettingsPanel.getHelpTopic());
3240

3341
editorSettingsPanel.disposeUIResources();
3442
}
3543

3644
public void testComponent() {
37-
CsvEditorSettingsPanel editorSettingsPanel = new CsvEditorSettingsPanel();
45+
CsvEditorSettingsProvider editorSettingsPanel = new CsvEditorSettingsProvider();
3846

3947
assertNotNull(editorSettingsPanel.createComponent());
4048

4149
editorSettingsPanel.disposeUIResources();
4250
}
4351

4452
public void testResetAndModified() throws ConfigurationException {
45-
CsvEditorSettingsPanel editorSettingsPanel = new CsvEditorSettingsPanel();
53+
CsvEditorSettingsProvider editorSettingsPanel = new CsvEditorSettingsProvider();
4654

4755
CsvEditorSettingsExternalizable csvEditorSettingsExternalizable = CsvEditorSettingsExternalizable.getInstance();
4856
csvEditorSettingsExternalizable.setCaretRowShown(false);
@@ -66,7 +74,7 @@ public void testResetAndModified() throws ConfigurationException {
6674
}
6775

6876
public void testApply() throws ConfigurationException {
69-
CsvEditorSettingsPanel editorSettingsPanel = new CsvEditorSettingsPanel();
77+
CsvEditorSettingsProvider editorSettingsPanel = new CsvEditorSettingsProvider();
7078

7179
CsvEditorSettingsExternalizable csvEditorSettingsExternalizable = CsvEditorSettingsExternalizable.getInstance();
7280
csvEditorSettingsExternalizable.loadState(new CsvEditorSettingsExternalizable.OptionSet());

0 commit comments

Comments
 (0)