2020import com .intellij .openapi .options .ConfigurationException ;
2121import com .intellij .openapi .options .SearchableConfigurable ;
2222import com .intellij .openapi .project .Project ;
23+ import com .intellij .openapi .ui .ComboBox ;
2324import com .intellij .uiDesigner .core .GridConstraints ;
2425import com .intellij .uiDesigner .core .GridLayoutManager ;
2526import com .intellij .uiDesigner .core .Spacer ;
2627import java .awt .Insets ;
2728import javax .swing .JCheckBox ;
29+ import javax .swing .JComboBox ;
2830import javax .swing .JComponent ;
31+ import javax .swing .JLabel ;
2932import javax .swing .JPanel ;
3033import org .jetbrains .annotations .Nls ;
3134import org .jetbrains .annotations .NotNull ;
3235import org .jetbrains .annotations .Nullable ;
3336
34- class GoogleJavaFormatConfigurable extends BaseConfigurable
35- implements SearchableConfigurable {
37+ class GoogleJavaFormatConfigurable extends BaseConfigurable implements SearchableConfigurable {
3638
3739 private final Project project ;
3840 private JPanel panel ;
3941 private JCheckBox enable ;
42+ private JComboBox styleComboBox ;
4043
4144 public GoogleJavaFormatConfigurable (Project project ) {
4245 this .project = project ;
@@ -74,26 +77,38 @@ public JComponent createComponent() {
7477
7578 @ Override
7679 public void apply () throws ConfigurationException {
77- GoogleJavaFormatSettings .getInstance (project ).setEnabled (enable .isSelected ());
80+ GoogleJavaFormatSettings settings = GoogleJavaFormatSettings .getInstance (project );
81+ settings .setEnabled (enable .isSelected ());
82+ settings .setStyle ((FormatterStyle ) styleComboBox .getSelectedItem ());
7883 }
7984
8085 @ Override
8186 public void reset () {
82- enable .setSelected (GoogleJavaFormatSettings .getInstance (project ).isEnabled ());
87+ GoogleJavaFormatSettings settings = GoogleJavaFormatSettings .getInstance (project );
88+ enable .setSelected (settings .isEnabled ());
89+ styleComboBox .setSelectedItem (settings .getStyle ());
8390 }
8491
8592 @ Override
8693 public boolean isModified () {
87- return enable .isSelected () != GoogleJavaFormatSettings .getInstance (project ).isEnabled ();
94+ GoogleJavaFormatSettings settings = GoogleJavaFormatSettings .getInstance (project );
95+ return enable .isSelected () != settings .isEnabled ()
96+ || !styleComboBox .getSelectedItem ().equals (settings .getStyle ());
8897 }
8998
9099 @ Override
91100 public void disposeUIResources () {}
92101
102+ private void createUIComponents () {
103+ styleComboBox = new ComboBox <>(FormatterStyle .values ());
104+ }
105+
106+ // IntelliJ's UI designer generated this ugly code and then google-java-format made it even
107+ // uglier. C'est la vie.
93108 {
94- // GUI initializer generated by IntelliJ IDEA GUI Designer
95- // >>> IMPORTANT!! <<<
96- // DO NOT EDIT OR ADD ANY CODE HERE!
109+ // GUI initializer generated by IntelliJ IDEA GUI Designer
110+ // >>> IMPORTANT!! <<<
111+ // DO NOT EDIT OR ADD ANY CODE HERE!
97112 $$$setupUI$$$ ();
98113 }
99114
@@ -104,23 +119,81 @@ public void disposeUIResources() {}
104119 * @noinspection ALL
105120 */
106121 private void $$$setupUI$$$ () {
122+ createUIComponents ();
107123 panel = new JPanel ();
108- panel .setLayout (new GridLayoutManager (2 , 1 , new Insets (0 , 0 , 0 , 0 ), -1 , -1 ));
124+ panel .setLayout (new GridLayoutManager (3 , 2 , new Insets (0 , 0 , 0 , 0 ), -1 , -1 ));
109125 enable = new JCheckBox ();
110126 enable .setText ("Enable google-java-format" );
111- panel .add (enable ,
112- new GridConstraints (0 , 0 , 1 , 1 , GridConstraints .ANCHOR_WEST , GridConstraints .FILL_NONE ,
127+ panel .add (
128+ enable ,
129+ new GridConstraints (
130+ 0 ,
131+ 0 ,
132+ 1 ,
133+ 2 ,
134+ GridConstraints .ANCHOR_WEST ,
135+ GridConstraints .FILL_NONE ,
113136 GridConstraints .SIZEPOLICY_CAN_SHRINK | GridConstraints .SIZEPOLICY_CAN_GROW ,
114- GridConstraints .SIZEPOLICY_FIXED , null , null , null , 0 , false ));
137+ GridConstraints .SIZEPOLICY_FIXED ,
138+ null ,
139+ null ,
140+ null ,
141+ 0 ,
142+ false ));
115143 final Spacer spacer1 = new Spacer ();
116- panel .add (spacer1 , new GridConstraints (1 , 0 , 1 , 1 , GridConstraints .ANCHOR_CENTER ,
117- GridConstraints .FILL_VERTICAL , 1 , GridConstraints .SIZEPOLICY_WANT_GROW , null , null , null , 0 ,
118- false ));
144+ panel .add (
145+ spacer1 ,
146+ new GridConstraints (
147+ 2 ,
148+ 0 ,
149+ 1 ,
150+ 2 ,
151+ GridConstraints .ANCHOR_CENTER ,
152+ GridConstraints .FILL_VERTICAL ,
153+ 1 ,
154+ GridConstraints .SIZEPOLICY_WANT_GROW ,
155+ null ,
156+ null ,
157+ null ,
158+ 0 ,
159+ false ));
160+ final JLabel label1 = new JLabel ();
161+ label1 .setText ("Code style" );
162+ panel .add (
163+ label1 ,
164+ new GridConstraints (
165+ 1 ,
166+ 0 ,
167+ 1 ,
168+ 1 ,
169+ GridConstraints .ANCHOR_WEST ,
170+ GridConstraints .FILL_NONE ,
171+ GridConstraints .SIZEPOLICY_FIXED ,
172+ GridConstraints .SIZEPOLICY_FIXED ,
173+ null ,
174+ null ,
175+ null ,
176+ 0 ,
177+ false ));
178+ panel .add (
179+ styleComboBox ,
180+ new GridConstraints (
181+ 1 ,
182+ 1 ,
183+ 1 ,
184+ 1 ,
185+ GridConstraints .ANCHOR_WEST ,
186+ GridConstraints .FILL_HORIZONTAL ,
187+ GridConstraints .SIZEPOLICY_CAN_GROW ,
188+ GridConstraints .SIZEPOLICY_FIXED ,
189+ null ,
190+ null ,
191+ null ,
192+ 1 ,
193+ false ));
119194 }
120195
121- /**
122- * @noinspection ALL
123- */
196+ /** @noinspection ALL */
124197 public JComponent $$$getRootComponent$$$ () {
125198 return panel ;
126199 }
0 commit comments