1
2
3
4
5
6
7
8
9
10
11 package de.funfried.netbeans.plugins.external.formatter.css.cssparser.ui;
12
13 import java.awt.event.ActionEvent;
14 import java.awt.event.ActionListener;
15 import java.util.Objects;
16 import java.util.prefs.Preferences;
17
18 import javax.swing.GroupLayout;
19 import javax.swing.JCheckBox;
20 import javax.swing.JLabel;
21 import javax.swing.JSpinner;
22 import javax.swing.LayoutStyle;
23 import javax.swing.SpinnerNumberModel;
24 import javax.swing.event.ChangeEvent;
25 import javax.swing.event.ChangeListener;
26
27 import org.netbeans.api.project.Project;
28 import org.openide.awt.Mnemonics;
29 import org.openide.util.NbBundle;
30
31 import de.funfried.netbeans.plugins.external.formatter.css.cssparser.CssParserFormatterSettings;
32 import de.funfried.netbeans.plugins.external.formatter.ui.options.AbstractFormatterOptionsPanel;
33
34
35
36
37
38 public class CssParserFormatterOptionsPanel extends AbstractFormatterOptionsPanel {
39
40
41
42
43
44
45 public CssParserFormatterOptionsPanel(Project project) {
46 super(project);
47
48 initComponents();
49 }
50
51
52
53
54
55
56
57 @SuppressWarnings("unchecked")
58
59 private void initComponents() {
60
61 rgbAsHexChkBox = new JCheckBox();
62 useSingleQuotesChkBox = new JCheckBox();
63 indentSizeLbl = new JLabel();
64 indentSizeSpn = new JSpinner();
65 useSourceStringValuesChkBox = new JCheckBox();
66
67 rgbAsHexChkBox.setSelected(true);
68 Mnemonics.setLocalizedText(rgbAsHexChkBox, NbBundle.getMessage(CssParserFormatterOptionsPanel.class, "CssParserFormatterOptionsPanel.rgbAsHexChkBox.text"));
69 rgbAsHexChkBox.setToolTipText(NbBundle.getMessage(CssParserFormatterOptionsPanel.class, "CssParserFormatterOptionsPanel.rgbAsHexChkBox.toolTipText"));
70 rgbAsHexChkBox.addActionListener(new ActionListener() {
71 public void actionPerformed(ActionEvent evt) {
72 rgbAsHexChkBoxActionPerformed(evt);
73 }
74 });
75
76 Mnemonics.setLocalizedText(useSingleQuotesChkBox, NbBundle.getMessage(CssParserFormatterOptionsPanel.class, "CssParserFormatterOptionsPanel.useSingleQuotesChkBox.text"));
77 useSingleQuotesChkBox.setToolTipText(NbBundle.getMessage(CssParserFormatterOptionsPanel.class, "CssParserFormatterOptionsPanel.useSingleQuotesChkBox.toolTipText"));
78 useSingleQuotesChkBox.addActionListener(new ActionListener() {
79 public void actionPerformed(ActionEvent evt) {
80 useSingleQuotesChkBoxActionPerformed(evt);
81 }
82 });
83
84 Mnemonics.setLocalizedText(indentSizeLbl, NbBundle.getMessage(CssParserFormatterOptionsPanel.class, "CssParserFormatterOptionsPanel.indentSizeLbl.text"));
85 indentSizeLbl.setToolTipText(NbBundle.getMessage(CssParserFormatterOptionsPanel.class, "CssParserFormatterOptionsPanel.indentSizeLbl.toolTipText"));
86
87 indentSizeSpn.setModel(new SpinnerNumberModel(4, 0, null, 1));
88 indentSizeSpn.addChangeListener(new ChangeListener() {
89 public void stateChanged(ChangeEvent evt) {
90 indentSizeSpnStateChanged(evt);
91 }
92 });
93
94 Mnemonics.setLocalizedText(useSourceStringValuesChkBox, NbBundle.getMessage(CssParserFormatterOptionsPanel.class, "CssParserFormatterOptionsPanel.useSourceStringValuesChkBox.text"));
95 useSourceStringValuesChkBox.setToolTipText(NbBundle.getMessage(CssParserFormatterOptionsPanel.class, "CssParserFormatterOptionsPanel.useSourceStringValuesChkBox.toolTipText"));
96 useSourceStringValuesChkBox.addActionListener(new ActionListener() {
97 public void actionPerformed(ActionEvent evt) {
98 useSourceStringValuesChkBoxActionPerformed(evt);
99 }
100 });
101
102 GroupLayout layout = new GroupLayout(this);
103 this.setLayout(layout);
104 layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
105 .addGroup(layout.createSequentialGroup()
106 .addContainerGap()
107 .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
108 .addComponent(rgbAsHexChkBox)
109 .addComponent(useSingleQuotesChkBox))
110 .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
111 .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
112 .addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
113 .addComponent(indentSizeLbl)
114 .addGap(43, 43, 43)
115 .addComponent(indentSizeSpn, GroupLayout.PREFERRED_SIZE, 84, GroupLayout.PREFERRED_SIZE))
116 .addComponent(useSourceStringValuesChkBox, GroupLayout.Alignment.TRAILING))
117 .addContainerGap())
118 );
119 layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
120 .addGroup(layout.createSequentialGroup()
121 .addContainerGap()
122 .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
123 .addGroup(layout.createSequentialGroup()
124 .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
125 .addComponent(indentSizeLbl)
126 .addComponent(indentSizeSpn, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
127 .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
128 .addComponent(useSourceStringValuesChkBox))
129 .addGroup(layout.createSequentialGroup()
130 .addComponent(rgbAsHexChkBox)
131 .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
132 .addComponent(useSingleQuotesChkBox)))
133 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
134 );
135 }
136
137 private void rgbAsHexChkBoxActionPerformed(ActionEvent evt) {
138 fireChangedListener();
139 }
140
141 private void useSingleQuotesChkBoxActionPerformed(ActionEvent evt) {
142 fireChangedListener();
143 }
144
145 private void indentSizeSpnStateChanged(ChangeEvent evt) {
146 indentSizeSpn.setToolTipText(Objects.toString(indentSizeSpn.getValue(), null));
147
148 fireChangedListener();
149 }
150
151 private void useSourceStringValuesChkBoxActionPerformed(ActionEvent evt) {
152
153 }
154
155
156 private JLabel indentSizeLbl;
157 private JSpinner indentSizeSpn;
158 private JCheckBox rgbAsHexChkBox;
159 private JCheckBox useSingleQuotesChkBox;
160 private JCheckBox useSourceStringValuesChkBox;
161
162
163
164
165
166 @Override
167 public void load(Preferences preferences) {
168 boolean rgbAsHex = preferences.getBoolean(CssParserFormatterSettings.RGB_AS_HEX, CssParserFormatterSettings.RGB_AS_HEX_DEFAULT);
169 boolean useSingleQuotes = preferences.getBoolean(CssParserFormatterSettings.USE_SINGLE_QUOTES, CssParserFormatterSettings.USE_SINGLE_QUOTES_DEFAULT);
170 boolean useSourceStringValues = preferences.getBoolean(CssParserFormatterSettings.USE_SOURCE_STRING_VALUES, CssParserFormatterSettings.USE_SOURCE_STRING_VALUES_DEFAULT);
171 int indentSize = preferences.getInt(CssParserFormatterSettings.INDENT, CssParserFormatterSettings.INDENT_DEFAULT);
172
173 rgbAsHexChkBox.setSelected(rgbAsHex);
174 useSingleQuotesChkBox.setSelected(useSingleQuotes);
175 useSourceStringValuesChkBox.setSelected(useSourceStringValues);
176 indentSizeSpn.setValue(indentSize);
177 indentSizeSpn.setToolTipText(Objects.toString(indentSizeSpn.getValue(), null));
178 }
179
180
181
182
183 @Override
184 public void store(Preferences preferences) {
185 preferences.putBoolean(CssParserFormatterSettings.RGB_AS_HEX, rgbAsHexChkBox.isSelected());
186 preferences.putBoolean(CssParserFormatterSettings.USE_SINGLE_QUOTES, useSingleQuotesChkBox.isSelected());
187 preferences.putBoolean(CssParserFormatterSettings.USE_SOURCE_STRING_VALUES, useSourceStringValuesChkBox.isSelected());
188 preferences.putInt(CssParserFormatterSettings.INDENT, (int) indentSizeSpn.getValue());
189 }
190
191
192
193
194 @Override
195 public boolean valid() {
196 return true;
197 }
198 }