1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.atlassian.theplugin.idea;
18
19 import com.atlassian.theplugin.idea.autoupdate.NewVersionButtonListener;
20 import com.atlassian.theplugin.idea.autoupdate.NewVersionChecker;
21 import com.atlassian.theplugin.idea.config.HTTPProxyDialog;
22 import com.atlassian.theplugin.util.PluginUtil;
23 import com.intellij.uiDesigner.core.GridConstraints;
24 import com.intellij.uiDesigner.core.GridLayoutManager;
25 import com.intellij.uiDesigner.core.Spacer;
26 import com.jgoodies.forms.layout.CellConstraints;
27 import com.jgoodies.forms.layout.FormLayout;
28
29 import javax.swing.*;
30 import static javax.swing.JOptionPane.OK_CANCEL_OPTION;
31 import static javax.swing.JOptionPane.PLAIN_MESSAGE;
32 import javax.swing.event.ChangeEvent;
33 import javax.swing.event.ChangeListener;
34 import java.awt.*;
35 import java.awt.event.ActionEvent;
36 import java.awt.event.ActionListener;
37
38 public class GeneralConfigForm {
39 private JCheckBox chkAutoUpdateEnabled;
40 private JPanel mainPanel;
41 private JButton checkNowButton;
42 private JPanel autoUpdateConfigPanel;
43 private JCheckBox chkUnstableVersionsCheckBox;
44 private JCheckBox reportAnonymousUsageStatisticsCheckBox;
45 private JRadioButton checkNewVersionStable;
46 private JRadioButton checkNewVersionAll;
47 private JPanel httpProxyPanel;
48 private JButton httpProxyButton;
49 private JRadioButton chkNoProxy;
50 private JRadioButton chkUseIdeaProxy;
51 private Boolean isAnonymousFeedbackEnabled;
52
53 public JRadioButton getCheckNewVersionStable() {
54 return checkNewVersionStable;
55 }
56
57 public JRadioButton getCheckNewVersionAll() {
58 return checkNewVersionAll;
59 }
60
61 public GeneralConfigForm(NewVersionChecker checker) {
62
63 checkNowButton.addActionListener(new NewVersionButtonListener(this));
64 chkAutoUpdateEnabled.addActionListener(new ActionListener() {
65 public void actionPerformed(ActionEvent event) {
66 chkUnstableVersionsCheckBox.setEnabled(chkAutoUpdateEnabled.isSelected());
67 }
68 });
69 reportAnonymousUsageStatisticsCheckBox.addActionListener(new ActionListener() {
70 public void actionPerformed(ActionEvent event) {
71 isAnonymousFeedbackEnabled = reportAnonymousUsageStatisticsCheckBox.isSelected();
72 }
73 });
74 httpProxyButton.addActionListener(new ActionListener() {
75 public void actionPerformed(ActionEvent event) {
76 HTTPProxyDialog proxyDialog = new HTTPProxyDialog();
77
78 proxyDialog.pack();
79 int answer = JOptionPane.showConfirmDialog(JOptionPane.getRootFrame(), proxyDialog.getRootPanel(),
80 PluginUtil.getInstance().getName(), OK_CANCEL_OPTION, PLAIN_MESSAGE);
81
82 if (answer == JOptionPane.OK_OPTION) {
83 proxyDialog.getHttpProxyPanel().apply();
84
85 }
86
87 }
88 });
89
90 chkNoProxy.addChangeListener(new ChangeListener() {
91 public void stateChanged(ChangeEvent e) {
92 httpProxyButton.setEnabled(chkUseIdeaProxy.isSelected());
93 }
94 });
95
96 chkUseIdeaProxy.addChangeListener(new ChangeListener() {
97 public void stateChanged(ChangeEvent e) {
98 httpProxyButton.setEnabled(chkUseIdeaProxy.isSelected());
99 }
100 });
101
102 }
103
104 public Component getRootPane() {
105 return mainPanel;
106 }
107
108 public boolean getIsAutoUpdateEnabled() {
109 return chkAutoUpdateEnabled.isSelected();
110 }
111
112 public void setAutoUpdateEnabled(boolean autoUpdateEnabled) {
113 chkAutoUpdateEnabled.setSelected(autoUpdateEnabled);
114 chkUnstableVersionsCheckBox.setEnabled(autoUpdateEnabled);
115 }
116
117 public boolean getIsCheckUnstableVersionsEnabled() {
118 return chkUnstableVersionsCheckBox.isSelected();
119 }
120
121 public void setIsCheckUnstableVersionsEnabled(boolean isCheckUnstableVersionsEnabled) {
122 chkUnstableVersionsCheckBox.setSelected(isCheckUnstableVersionsEnabled);
123 }
124
125 public boolean getIsAnonymousFeedbackEnabled() {
126 return this.isAnonymousFeedbackEnabled;
127 }
128
129 public boolean getUseIdeaProxySettings() {
130 return chkUseIdeaProxy.isSelected();
131 }
132
133 public void setUseIdeaProxySettings(boolean use) {
134 chkUseIdeaProxy.setSelected(use);
135 chkNoProxy.setSelected(!use);
136 httpProxyButton.setEnabled(use);
137 }
138
139 public void setIsAnonymousFeedbackEnabled(Boolean isAnonymousFeedbackEnabled) {
140 this.isAnonymousFeedbackEnabled = isAnonymousFeedbackEnabled;
141 if (isAnonymousFeedbackEnabled == null || !isAnonymousFeedbackEnabled) {
142 reportAnonymousUsageStatisticsCheckBox.setSelected(false);
143 } else {
144 reportAnonymousUsageStatisticsCheckBox.setSelected(true);
145 }
146 }
147
148
149 {
150
151
152
153 $$$setupUI$$$();
154 }
155
156
157
158
159
160
161
162
163 private void $$$setupUI$$$() {
164 mainPanel = new JPanel();
165 mainPanel.setLayout(new FormLayout("fill:d:grow", "center:max(d;4px):noGrow,top:3dlu:noGrow,center:d:grow,top:3dlu:noGrow,center:max(d;4px):noGrow"));
166 mainPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12), null));
167 autoUpdateConfigPanel = new JPanel();
168 autoUpdateConfigPanel.setLayout(new GridLayoutManager(3, 3, new Insets(0, 12, 12, 12), -1, -1));
169 CellConstraints cc = new CellConstraints();
170 mainPanel.add(autoUpdateConfigPanel, cc.xy(1, 1));
171 autoUpdateConfigPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Auto-upgrade"));
172 checkNowButton = new JButton();
173 checkNowButton.setText("Check now");
174 checkNowButton.setMnemonic('C');
175 checkNowButton.setDisplayedMnemonicIndex(0);
176 autoUpdateConfigPanel.add(checkNowButton, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
177 final JPanel panel1 = new JPanel();
178 panel1.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1));
179 autoUpdateConfigPanel.add(panel1, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_VERTICAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
180 chkUnstableVersionsCheckBox = new JCheckBox();
181 chkUnstableVersionsCheckBox.setEnabled(false);
182 chkUnstableVersionsCheckBox.setText("Check snapshot versions");
183 panel1.add(chkUnstableVersionsCheckBox, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
184 final Spacer spacer1 = new Spacer();
185 panel1.add(spacer1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, new Dimension(12, -1), null, null, 0, false));
186 chkAutoUpdateEnabled = new JCheckBox();
187 chkAutoUpdateEnabled.setText("Enabled (stable version)");
188 chkAutoUpdateEnabled.setMnemonic('E');
189 chkAutoUpdateEnabled.setDisplayedMnemonicIndex(0);
190 autoUpdateConfigPanel.add(chkAutoUpdateEnabled, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
191 final Spacer spacer2 = new Spacer();
192 autoUpdateConfigPanel.add(spacer2, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false));
193 checkNewVersionStable = new JRadioButton();
194 checkNewVersionStable.setSelected(true);
195 checkNewVersionStable.setText("Stable only");
196 autoUpdateConfigPanel.add(checkNewVersionStable, new GridConstraints(1, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
197 checkNewVersionAll = new JRadioButton();
198 checkNewVersionAll.setText("Stable + snapshot");
199 autoUpdateConfigPanel.add(checkNewVersionAll, new GridConstraints(2, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
200 reportAnonymousUsageStatisticsCheckBox = new JCheckBox();
201 reportAnonymousUsageStatisticsCheckBox.setEnabled(true);
202 reportAnonymousUsageStatisticsCheckBox.setSelected(false);
203 reportAnonymousUsageStatisticsCheckBox.setText("Report anonymous usage statistics to help us develop a better plugin");
204 reportAnonymousUsageStatisticsCheckBox.setMnemonic('R');
205 reportAnonymousUsageStatisticsCheckBox.setDisplayedMnemonicIndex(0);
206 mainPanel.add(reportAnonymousUsageStatisticsCheckBox, cc.xy(1, 5));
207 httpProxyPanel = new JPanel();
208 httpProxyPanel.setLayout(new GridLayoutManager(2, 2, new Insets(0, 12, 12, 0), -1, -1));
209 mainPanel.add(httpProxyPanel, cc.xy(1, 3, CellConstraints.DEFAULT, CellConstraints.TOP));
210 httpProxyPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "HTTP Proxy"));
211 chkUseIdeaProxy = new JRadioButton();
212 chkUseIdeaProxy.setText("Use IDEA proxy settings");
213 httpProxyPanel.add(chkUseIdeaProxy, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
214 httpProxyButton = new JButton();
215 httpProxyButton.setText("Edit IDEA proxy settings");
216 httpProxyPanel.add(httpProxyButton, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_NORTHWEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
217 chkNoProxy = new JRadioButton();
218 chkNoProxy.setText("Do not use proxy");
219 httpProxyPanel.add(chkNoProxy, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
220 ButtonGroup buttonGroup;
221 buttonGroup = new ButtonGroup();
222 buttonGroup.add(checkNewVersionStable);
223 buttonGroup.add(checkNewVersionAll);
224 buttonGroup = new ButtonGroup();
225 buttonGroup.add(chkNoProxy);
226 buttonGroup.add(chkUseIdeaProxy);
227 }
228
229
230
231
232 public JComponent $$$getRootComponent$$$() {
233 return mainPanel;
234 }
235 }
236