1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package com.drazzib.netpisteur.ui;
27
28 import java.awt.BorderLayout;
29 import java.awt.Color;
30 import java.awt.GridLayout;
31 import java.awt.event.ItemEvent;
32 import java.awt.event.ItemListener;
33 import java.awt.event.MouseAdapter;
34 import java.awt.event.MouseEvent;
35 import java.awt.event.WindowAdapter;
36 import java.awt.event.WindowEvent;
37
38 import javax.swing.JButton;
39 import javax.swing.JCheckBox;
40 import javax.swing.JLabel;
41 import javax.swing.JPanel;
42 import javax.swing.JTextField;
43 import javax.swing.SwingConstants;
44 import javax.swing.border.BevelBorder;
45 import javax.swing.border.EtchedBorder;
46
47 import com.drazzib.netpisteur.configuration.Configuration;
48 import com.drazzib.netpisteur.util.Messages;
49
50 public class ConfigProxyFrame extends javax.swing.JFrame {
51
52 /**
53 *
54 */
55 private static final long serialVersionUID = 4212668201065130721L;
56
57 private JLabel titreLabel, labelProxyHost, labelProxyPort,
58 utiliserProxyLabel;
59
60 private JPanel conteneurPanel, jPanel1, panel2, panel4, panel5, panel6;
61
62 private JTextField textFieldProxyHost, textFieldProxyPort;
63
64 private JCheckBox utiliserCheckBox;
65
66 private JButton okButton, annulerButton;
67
68 private boolean proxyActif;
69
70 Configuration uneConfiguration;
71
72 /** Creates new form ConfigProxyFrame */
73 public ConfigProxyFrame() {
74 initComponents();
75 }
76
77 /**
78 * This method is called from within the constructor to initialize the form.
79 */
80 private void initComponents() {
81
82 this.uneConfiguration = Configuration.getHandle();
83
84 this.proxyActif = this.uneConfiguration.isProxyActif();
85
86 this.titreLabel = new JLabel();
87 this.conteneurPanel = new JPanel();
88 this.jPanel1 = new JPanel();
89 this.labelProxyHost = new JLabel();
90 this.textFieldProxyHost = new JTextField();
91 this.panel2 = new JPanel();
92 this.labelProxyPort = new JLabel();
93 this.textFieldProxyPort = new JTextField();
94 this.panel4 = new JPanel();
95 this.panel5 = new JPanel();
96 this.utiliserProxyLabel = new JLabel();
97 this.utiliserCheckBox = new JCheckBox();
98 this.panel6 = new JPanel();
99 this.okButton = new JButton();
100 this.annulerButton = new JButton();
101
102 addWindowListener(new WindowAdapter() {
103 public void windowClosing(WindowEvent evt) {
104 exit();
105 }
106 });
107
108 this.titreLabel.setText(Messages
109 .getString("ConfigProxyFrame.CONFIG_PROXY"));
110 this.titreLabel.setForeground(Color.black);
111 this.titreLabel.setBorder(new BevelBorder(BevelBorder.RAISED));
112 getContentPane().add(this.titreLabel, BorderLayout.NORTH);
113
114 this.conteneurPanel.setLayout(new GridLayout(5, 1));
115
116 this.jPanel1.setLayout(new GridLayout(1, 3));
117
118 this.labelProxyHost.setText(Messages
119 .getString("ConfigProxyFrame.PROXY_HOST"));
120 this.labelProxyHost.setForeground(Color.black);
121 this.labelProxyHost.setBorder(new EtchedBorder());
122 this.jPanel1.add(this.labelProxyHost);
123
124 this.textFieldProxyHost.setText(Configuration.getHandle()
125 .getProxyHost());
126 this.jPanel1.add(this.textFieldProxyHost);
127
128 this.conteneurPanel.add(this.jPanel1);
129
130 this.panel2.setLayout(new GridLayout(1, 0));
131
132 this.labelProxyPort.setText(Messages
133 .getString("ConfigProxyFrame.PROXY_PORT"));
134 this.labelProxyPort.setForeground(Color.black);
135 this.labelProxyPort.setBorder(new EtchedBorder());
136 this.panel2.add(this.labelProxyPort);
137 this.textFieldProxyPort.setText(Configuration.getHandle()
138 .getProxyPort());
139 this.panel2.add(this.textFieldProxyPort);
140
141 this.conteneurPanel.add(this.panel2);
142
143 this.conteneurPanel.add(this.panel4);
144
145 this.panel5.setLayout(new GridLayout(1, 0));
146
147 this.utiliserProxyLabel.setText(Messages
148 .getString("ConfigProxyFrame.USE_PROXY"));
149 this.utiliserProxyLabel.setForeground(Color.black);
150 this.utiliserProxyLabel.setBorder(new EtchedBorder());
151 this.panel5.add(this.utiliserProxyLabel);
152
153 this.utiliserCheckBox.setBorder(new EtchedBorder());
154 this.utiliserCheckBox.setHorizontalAlignment(SwingConstants.CENTER);
155 this.utiliserCheckBox.addItemListener(new ItemListener() {
156 public void itemStateChanged(ItemEvent evt) {
157 utiliserCheckBoxActionPerformed(evt);
158 }
159 });
160 if (this.proxyActif) {
161 this.utiliserCheckBox.setSelected(true);
162 } else {
163 this.utiliserCheckBox.setSelected(false);
164 }
165
166 this.panel5.add(this.utiliserCheckBox);
167
168 this.conteneurPanel.add(this.panel5);
169
170 this.panel6.setLayout(new GridLayout(1, 2));
171
172 this.okButton.setText(Messages.getString("ConfigProxyFrame.OK"));
173 this.okButton.setBorder(new BevelBorder(BevelBorder.RAISED));
174 this.okButton.addMouseListener(new MouseAdapter() {
175 public void mouseReleased(MouseEvent evt) {
176 okButtonMouseReleased(evt);
177 }
178 });
179
180 this.panel6.add(this.okButton);
181
182 this.annulerButton.setText(Messages
183 .getString("ConfigProxyFrame.CANCEL"));
184 this.annulerButton.setBorder(new BevelBorder(BevelBorder.RAISED));
185 this.annulerButton.addMouseListener(new MouseAdapter() {
186 public void mouseReleased(MouseEvent evt) {
187 exit();
188 }
189 });
190
191 this.panel6.add(this.annulerButton);
192
193 this.conteneurPanel.add(this.panel6);
194
195 getContentPane().add(this.conteneurPanel, BorderLayout.CENTER);
196
197 pack();
198 }
199
200 void okButtonMouseReleased(MouseEvent evt) {
201
202
203 if (this.proxyActif) {
204 this.uneConfiguration.setProxyHost(this.textFieldProxyHost
205 .getText());
206 this.uneConfiguration.setProxyPort(this.textFieldProxyPort
207 .getText());
208 this.uneConfiguration.setProxyActif(true);
209 } else {
210 this.uneConfiguration.setProxyHost("");
211 this.uneConfiguration.setProxyPort("");
212 this.uneConfiguration.setProxyActif(false);
213 }
214
215
216 this.uneConfiguration.writeProxyConfToDisk();
217
218 dispose();
219
220 }
221
222 void utiliserCheckBoxActionPerformed(ItemEvent evt) {
223 if (evt.getStateChange() == ItemEvent.SELECTED) {
224 this.proxyActif = true;
225 } else {
226 this.proxyActif = false;
227 }
228 }
229
230 /** Exit */
231 void exit() {
232 dispose();
233 }
234
235 }