Skip to content

Commit

Permalink
Add a combo box to reset with default colors
Browse files Browse the repository at this point in the history
  • Loading branch information
junichi11 committed Sep 29, 2018
1 parent 2ee44fa commit a1f8bff
Show file tree
Hide file tree
Showing 7 changed files with 242 additions and 57 deletions.
Binary file modified images/netbeans-rainbow-braces-options.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions nbproject/genfiles.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ build.xml.script.CRC32=333fcb91
build.xml.stylesheet.CRC32=15ca8a54@2.75
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=d891b2f3
nbproject/build-impl.xml.data.CRC32=771cfbd1
nbproject/build-impl.xml.script.CRC32=db8adf4e
nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.72.1
nbproject/build-impl.xml.stylesheet.CRC32=49aa68b0@2.75
8 changes: 8 additions & 0 deletions nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@
<specification-version>7.67.1</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.dialogs</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>7.42.1</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.modules</code-name-base>
<build-prerequisite/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ RainbowBracesOptionsPanel.parenthesisCheckBox.text=Parenthesis: ()
RainbowBracesOptionsPanel.bracketsCheckBox.text=Brackets: []
RainbowBracesOptionsPanel.bracesCheckBox.text=Braces: {}
RainbowBracesOptionsPanel.errorLabel.text=ERROR
RainbowBracesOptionsPanel.resetColorsButton.text=Reset Colors
RainbowBracesOptionsPanel.resetColorsButton.text=Reset
RainbowBracesOptionsPanel.resetColorsLabel.text=Color set to reset:
RainbowBracesOptionsPanel.resetColorsBarLabel.text=COLOR BAR
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
*/
package com.junichi11.netbeans.modules.rainbow.braces.options;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.prefs.Preferences;
import org.openide.util.NbPreferences;

Expand All @@ -26,6 +30,7 @@
*/
public final class RainbowBracesOptions {

private static final Map<String, List<String>> DEFAULT_COLORS = new HashMap<>();
private static final List<String> DEFAULT_COLORS1 = Arrays.asList(
"#d03a27", // NOI18N
"#4d9e3e", // NOI18N
Expand All @@ -38,8 +43,8 @@ public final class RainbowBracesOptions {
"#f2df00" // NOI18N
);
private static final List<String> DEFAULT_COLORS2 = Arrays.asList(
"#d03a27", // NOI18N
"#af3480", // NOI18N
"#d02742", // NOI18N
"#7f34af", // NOI18N
"#1881bf", // NOI18N
"#00aebb", // NOI18N
"#4d9e3e", // NOI18N
Expand All @@ -49,7 +54,7 @@ public final class RainbowBracesOptions {
"#f2df00" // NOI18N
);
private static final List<String> DEFAULT_COLORS3 = Arrays.asList(
"#f19db5", // NOI18N
"#e79df1", // NOI18N
"#ee858b", // NOI18N
"#f5a33b", // NOI18N
"#fedc5e", // NOI18N
Expand All @@ -70,6 +75,12 @@ public final class RainbowBracesOptions {
private static final String DEFAULT_COLOR = "#000000"; // NOI18N
private static final RainbowBracesOptions INSTANCE = new RainbowBracesOptions();

static {
DEFAULT_COLORS.put("Default 1", DEFAULT_COLORS1); // NOI18N
DEFAULT_COLORS.put("Default 2", DEFAULT_COLORS2); // NOI18N
DEFAULT_COLORS.put("Default 3", DEFAULT_COLORS3); // NOI18N
}

private RainbowBracesOptions() {
}

Expand Down Expand Up @@ -133,8 +144,19 @@ public void setColorCode(int number, String color) {
getPreferences().put(String.format(COLOR_CODE, number), color);
}

public String getDefaultColorCode(String name, int number) {
List<String> defaultColors = DEFAULT_COLORS.get(name);
if (defaultColors == null || defaultColors.isEmpty()) {
defaultColors = DEFAULT_COLORS1;
}
if (number <= 0 || defaultColors.size() < number) {
return DEFAULT_COLOR;
}
return defaultColors.get(number - 1);
}

public String getDefaultColorCode(int number) {
if (number <= 0 || 10 <= number) {
if (number <= 0 || DEFAULT_COLORS1.size() < number) {
return DEFAULT_COLOR;
}
return DEFAULT_COLORS1.get(number - 1);
Expand All @@ -143,4 +165,18 @@ public String getDefaultColorCode(int number) {
private Preferences getPreferences() {
return NbPreferences.forModule(RainbowBracesOptions.class);
}

public static List<String> getDefaultColorNames() {
ArrayList names = new ArrayList(DEFAULT_COLORS.keySet());
Collections.sort(names);
return names;
}

public static List<String> getDefaultColors(String name) {
List<String> defaultColors = DEFAULT_COLORS.get(name);
if (defaultColors == null) {
return Collections.emptyList();
}
return defaultColors;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,36 @@
</Group>
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="colorCheckBox4" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="colorCheckBox1" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="colorCheckBox7" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="parenthesisCheckBox" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="colorComboBox1" alignment="0" max="32767" attributes="0"/>
<Component id="colorComboBox4" alignment="0" max="32767" attributes="0"/>
<Component id="colorComboBox7" alignment="0" max="32767" attributes="0"/>
</Group>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="bracketsCheckBox" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="bracesCheckBox" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="enabledCheckBox" alignment="0" min="-2" max="-2" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="colorCheckBox5" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="colorCheckBox2" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="colorCheckBox8" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="errorLabel" min="-2" max="-2" attributes="0"/>
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="colorCheckBox4" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="colorCheckBox1" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="colorCheckBox7" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="colorComboBox1" alignment="0" max="32767" attributes="0"/>
<Component id="colorComboBox4" alignment="0" max="32767" attributes="0"/>
<Component id="colorComboBox7" alignment="0" max="32767" attributes="0"/>
</Group>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="colorCheckBox5" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="colorCheckBox2" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="colorCheckBox8" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
Expand All @@ -61,15 +74,14 @@
</Group>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="parenthesisCheckBox" min="-2" max="-2" attributes="0"/>
<Component id="resetColorsLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="bracketsCheckBox" min="-2" max="-2" attributes="0"/>
<Component id="resetColorsComboBox" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="bracesCheckBox" min="-2" max="-2" attributes="0"/>
<Component id="resetColorsBarLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="resetColorsButton" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="enabledCheckBox" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="errorLabel" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="resetColorsButton" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
Expand Down Expand Up @@ -122,7 +134,12 @@
<Component id="colorComboBox9" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="resetColorsButton" min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="resetColorsButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="resetColorsComboBox" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="resetColorsLabel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="resetColorsBarLabel" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
<Component id="errorLabel" min="-2" max="-2" attributes="0"/>
</Group>
Expand Down Expand Up @@ -270,5 +287,29 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="resetColorsButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JComboBox" name="resetColorsComboBox">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="0"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
</AuxValues>
</Component>
<Component class="javax.swing.JLabel" name="resetColorsLabel">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/junichi11/netbeans/modules/rainbow/braces/options/Bundle.properties" key="RainbowBracesOptionsPanel.resetColorsLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="resetColorsBarLabel">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/junichi11/netbeans/modules/rainbow/braces/options/Bundle.properties" key="RainbowBracesOptionsPanel.resetColorsBarLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
</SubComponents>
</Form>
Loading

0 comments on commit a1f8bff

Please sign in to comment.