Blame view

src/main/java/eu/omp/irap/vespa/epntapclient/view/ParamField.java 13 KB
506d0c0b   Nathanael Jourdane   Add licence heade...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*
 * This file is a part of EpnTAPClient.
 * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer.
 * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861
 * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie.
 * 
 * This program is free software: you can
 * redistribute it and/or modify it under the terms of the GNU General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or (at your option) any later
 * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE. See the GNU General Public License for more details. You should have received a copy of
 * the GNU General Public License along with this program. If not, see
 * <http://www.gnu.org/licenses/>.
 */

eb483599   Nathanael Jourdane   Add missing Param...
17
18
19
20
package eu.omp.irap.vespa.epntapclient.view;

import java.awt.Color;
import java.awt.Dimension;
a99d92fa   Nathanael Jourdane   Add JComboBox for...
21
22
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
eb483599   Nathanael Jourdane   Add missing Param...
23
24
25
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
e7647bba   Nathanael Jourdane   change query to g...
26
import java.util.ArrayList;
e7647bba   Nathanael Jourdane   change query to g...
27
import java.util.List;
eb483599   Nathanael Jourdane   Add missing Param...
28
import java.util.Locale;
b6627be6   Nathanael Jourdane   Improve Exceptions
29
import java.util.logging.Level;
5d3c344e   Nathanael Jourdane   Use Java logging ...
30
import java.util.logging.Logger;
eb483599   Nathanael Jourdane   Add missing Param...
31
32

import javax.swing.BoxLayout;
f00cb6bb   Nathanael Jourdane   Add a JComboBox f...
33
import javax.swing.JComboBox;
eb483599   Nathanael Jourdane   Add missing Param...
34
35
36
37
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
eb483599   Nathanael Jourdane   Add missing Param...
38
39
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
eb483599   Nathanael Jourdane   Add missing Param...
40

05b140ed   Nathanael Jourdane   TargetNameField J...
41
42
43
44
45
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableConnection;
b6627be6   Nathanael Jourdane   Improve Exceptions
46
import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException.SendQueryException;
05b140ed   Nathanael Jourdane   TargetNameField J...
47

eb483599   Nathanael Jourdane   Add missing Param...
48
public abstract class ParamField extends JPanel {
53d49e83   Nathanael Jourdane   Fix all Eclipse w...
49
50
51
	/**  */
	private static final long serialVersionUID = 6025994164004985362L;

5d3c344e   Nathanael Jourdane   Use Java logging ...
52
	/** The logger for the class ParamField. */
53d49e83   Nathanael Jourdane   Fix all Eclipse w...
53
	static final Logger logger = Logger.getLogger(ParamField.class.getName());
eb483599   Nathanael Jourdane   Add missing Param...
54

68ae1315   Nathanael Jourdane   Improve GUI appar...
55
56
57
58
59
	private static final int MIN_FIELD_WIDTH = 30;
	private static final int FIELD_HEIGHT = 20;
	private static final int MAX_FIELD_WIDTH = 400;
	private static final int LABEL_WIDTH = 140;

05b140ed   Nathanael Jourdane   TargetNameField J...
60
	private static final String RESOLVER_URL = "http://voparis-registry.obspm.fr/ssodnet/1/autocomplete";
eb483599   Nathanael Jourdane   Add missing Param...
61
62
	private static final String DATE_FORMAT = "dd/MM/yyyy";
	private static final String DATE_REGEX = "(^(((0[1-9]|1[0-9]|2[0-8])[\\/](0[1-9]|1[012]))|((29|30|31)[\\/](0[13578]|1[02]))|((29|30)[\\/](0[4,6,9]|11)))[\\/](19|[2-9][0-9])\\d\\d$)|(^29[\\/]02[\\/](19|[2-9][0-9])(00|04|08|12|16|20|24|28|32|36|40|44|48|52|56|60|64|68|72|76|80|84|88|92|96)$)";
eb483599   Nathanael Jourdane   Add missing Param...
63
64
65
	private static final String MIN_SUFFIX = "min";
	private static final String MAX_SUFFIX = "max";

53d49e83   Nathanael Jourdane   Fix all Eclipse w...
66
	protected EpnTapMainView mainView;
eb483599   Nathanael Jourdane   Add missing Param...
67
68
	protected String paramName;

5af53be7   Nathanael Jourdane   Make the applicat...
69
	public ParamField(EpnTapMainView mainView, String paramName) {
eb483599   Nathanael Jourdane   Add missing Param...
70
		super();
5af53be7   Nathanael Jourdane   Make the applicat...
71
72
73
74

		this.mainView = mainView;
		this.paramName = paramName;

eb483599   Nathanael Jourdane   Add missing Param...
75
		this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
68ae1315   Nathanael Jourdane   Improve GUI appar...
76
		this.setMaximumSize(new Dimension(MAX_FIELD_WIDTH, FIELD_HEIGHT));
eb483599   Nathanael Jourdane   Add missing Param...
77
78
		String strLabel = paramName.replaceAll("_", " ").trim();
		JLabel label = new JLabel(strLabel.substring(0, 1).toUpperCase() + strLabel.substring(1));
68ae1315   Nathanael Jourdane   Improve GUI appar...
79
		label.setPreferredSize(new Dimension(LABEL_WIDTH, FIELD_HEIGHT));
eb483599   Nathanael Jourdane   Add missing Param...
80
		this.add(label);
41133475   Nathanael Jourdane   build floatRangeF...
81
		// TODO: Add tooltip text based on rr.table_column.column_description
eb483599   Nathanael Jourdane   Add missing Param...
82
83
	}

e97b40e8   Nathanael Jourdane   Make ParamField c...
84
	public static class StringField extends ParamField implements TextFieldListener {
53d49e83   Nathanael Jourdane   Fix all Eclipse w...
85
86
		/**  */
		private static final long serialVersionUID = 24219488975302068L;
667dd80c   Nathanael Jourdane   JTextField as Par...
87
88
		JTextField field;

5af53be7   Nathanael Jourdane   Make the applicat...
89
90
		public StringField(EpnTapMainView mainView, String paramName) {
			super(mainView, paramName);
667dd80c   Nathanael Jourdane   JTextField as Par...
91
			field = new JTextField();
e97b40e8   Nathanael Jourdane   Make ParamField c...
92
			addChangeListener(this, field);
eb483599   Nathanael Jourdane   Add missing Param...
93
94
95
			this.add(field);
		}

53d49e83   Nathanael Jourdane   Fix all Eclipse w...
96
97
98
		@Override
		public void update(JTextField textField) {
			if ("".equals(textField.getText())) {
5af53be7   Nathanael Jourdane   Make the applicat...
99
				mainView.event(Event.paramChanged, paramName, null);
eb483599   Nathanael Jourdane   Add missing Param...
100
			} else {
53d49e83   Nathanael Jourdane   Fix all Eclipse w...
101
				mainView.event(Event.paramChanged, paramName, textField.getText());
eb483599   Nathanael Jourdane   Add missing Param...
102
103
104
105
			}
		}
	}

e97b40e8   Nathanael Jourdane   Make ParamField c...
106
	public static class FloatField extends ParamField implements TextFieldListener {
53d49e83   Nathanael Jourdane   Fix all Eclipse w...
107
108
		/**  */
		private static final long serialVersionUID = -1880193152285564590L;
667dd80c   Nathanael Jourdane   JTextField as Par...
109
110
		JTextField field;

5af53be7   Nathanael Jourdane   Make the applicat...
111
112
		public FloatField(EpnTapMainView mainView, String paramName) {
			super(mainView, paramName);
667dd80c   Nathanael Jourdane   JTextField as Par...
113
			field = new JTextField();
e97b40e8   Nathanael Jourdane   Make ParamField c...
114
			addChangeListener(this, field);
eb483599   Nathanael Jourdane   Add missing Param...
115
116
117
			this.add(field);
		}

53d49e83   Nathanael Jourdane   Fix all Eclipse w...
118
119
120
121
		@Override
		public void update(JTextField textField) {
			if ("".equals(textField.getText())) {
				textField.setBackground(Color.WHITE);
5af53be7   Nathanael Jourdane   Make the applicat...
122
				mainView.event(Event.paramRemoved, paramName);
eb483599   Nathanael Jourdane   Add missing Param...
123
124
			} else {
				try {
53d49e83   Nathanael Jourdane   Fix all Eclipse w...
125
126
127
128
129
					float value = Float.parseFloat(textField.getText());
					mainView.event(Event.paramChanged, paramName, value);
					textField.setBackground(Color.WHITE);
				} catch (@SuppressWarnings("unused") NumberFormatException e) {
					textField.setBackground(Color.PINK);
eb483599   Nathanael Jourdane   Add missing Param...
130
131
132
133
134
				}
			}
		}
	}

e97b40e8   Nathanael Jourdane   Make ParamField c...
135
	public static class DateRangeField extends ParamField implements TextFieldListener {
53d49e83   Nathanael Jourdane   Fix all Eclipse w...
136
137
		/**  */
		private static final long serialVersionUID = -7781309003911514777L;
667dd80c   Nathanael Jourdane   JTextField as Par...
138
139
140
		JTextField fieldMin;
		JTextField fieldMax;

5af53be7   Nathanael Jourdane   Make the applicat...
141
142
		public DateRangeField(EpnTapMainView mainView, String paramName) {
			super(mainView, paramName);
68ae1315   Nathanael Jourdane   Improve GUI appar...
143
			this.add(new JLabel("min "));
667dd80c   Nathanael Jourdane   JTextField as Par...
144
			fieldMin = new JTextField();
e97b40e8   Nathanael Jourdane   Make ParamField c...
145
			fieldMin.setName(MIN_SUFFIX);
68ae1315   Nathanael Jourdane   Improve GUI appar...
146
			fieldMin.setPreferredSize(new Dimension(MIN_FIELD_WIDTH, FIELD_HEIGHT));
e97b40e8   Nathanael Jourdane   Make ParamField c...
147
			addChangeListener(this, fieldMin);
eb483599   Nathanael Jourdane   Add missing Param...
148
149
			this.add(fieldMin);

68ae1315   Nathanael Jourdane   Improve GUI appar...
150
			this.add(new JLabel("max "));
667dd80c   Nathanael Jourdane   JTextField as Par...
151
			fieldMax = new JTextField();
e97b40e8   Nathanael Jourdane   Make ParamField c...
152
			fieldMax.setName(MAX_SUFFIX);
68ae1315   Nathanael Jourdane   Improve GUI appar...
153
			fieldMax.setPreferredSize(new Dimension(MIN_FIELD_WIDTH, FIELD_HEIGHT));
e97b40e8   Nathanael Jourdane   Make ParamField c...
154
			addChangeListener(this, fieldMin);
eb483599   Nathanael Jourdane   Add missing Param...
155
156
157
			this.add(fieldMax);
		}

53d49e83   Nathanael Jourdane   Fix all Eclipse w...
158
		@Override
e97b40e8   Nathanael Jourdane   Make ParamField c...
159
		public void update(JTextField field) {
eb483599   Nathanael Jourdane   Add missing Param...
160
161
162
			DateFormat df = new SimpleDateFormat(DATE_FORMAT, Locale.ENGLISH);
			if ("".equals(field.getText())) {
				field.setBackground(Color.WHITE);
5af53be7   Nathanael Jourdane   Make the applicat...
163
				mainView.event(Event.paramRemoved, paramName + field.getName());
eb483599   Nathanael Jourdane   Add missing Param...
164
165
166
			} else if (field.getText().matches(DATE_REGEX)) {
				try {
					long date = df.parse(field.getText()).getTime();
5af53be7   Nathanael Jourdane   Make the applicat...
167
168
					date = Math.round((date / 86400000.0) + 2440587.5); // to JD
					mainView.event(Event.paramChanged, paramName + field.getName(), date);
eb483599   Nathanael Jourdane   Add missing Param...
169
					field.setBackground(Color.WHITE);
53d49e83   Nathanael Jourdane   Fix all Eclipse w...
170
				} catch (@SuppressWarnings("unused") ParseException e) {
eb483599   Nathanael Jourdane   Add missing Param...
171
172
173
174
175
176
177
178
179
					field.setBackground(Color.PINK);
				}
				// TODO: check if date min < date max
			} else {
				field.setBackground(Color.PINK);
			}
		}
	}

e97b40e8   Nathanael Jourdane   Make ParamField c...
180
	public static class FloatRangeField extends ParamField implements TextFieldListener {
53d49e83   Nathanael Jourdane   Fix all Eclipse w...
181
182
		/**  */
		private static final long serialVersionUID = 7923358142882329015L;
41133475   Nathanael Jourdane   build floatRangeF...
183
184
		JTextField fieldMin;
		JTextField fieldMax;
eb483599   Nathanael Jourdane   Add missing Param...
185

5af53be7   Nathanael Jourdane   Make the applicat...
186
187
		public FloatRangeField(EpnTapMainView mainView, String paramName) {
			super(mainView, paramName);
41133475   Nathanael Jourdane   build floatRangeF...
188
			fieldMin = new JTextField();
e97b40e8   Nathanael Jourdane   Make ParamField c...
189
190
			fieldMin.setName(MIN_SUFFIX);
			addChangeListener(this, fieldMin);
eb483599   Nathanael Jourdane   Add missing Param...
191
192
			this.add(fieldMin);

41133475   Nathanael Jourdane   build floatRangeF...
193
			fieldMax = new JTextField();
e97b40e8   Nathanael Jourdane   Make ParamField c...
194
195
			fieldMax.setName(MAX_SUFFIX);
			addChangeListener(this, fieldMax);
eb483599   Nathanael Jourdane   Add missing Param...
196
197
			this.add(fieldMax);
		}
41133475   Nathanael Jourdane   build floatRangeF...
198

53d49e83   Nathanael Jourdane   Fix all Eclipse w...
199
		@Override
e97b40e8   Nathanael Jourdane   Make ParamField c...
200
		public void update(JTextField field) {
41133475   Nathanael Jourdane   build floatRangeF...
201
202
			if ("".equals(field.getText())) {
				field.setBackground(Color.WHITE);
5af53be7   Nathanael Jourdane   Make the applicat...
203
				mainView.event(Event.paramRemoved, paramName + field.getName());
41133475   Nathanael Jourdane   build floatRangeF...
204
205
			} else {
				try {
5af53be7   Nathanael Jourdane   Make the applicat...
206
					mainView.event(Event.paramChanged, paramName + field.getName(),
e97b40e8   Nathanael Jourdane   Make ParamField c...
207
							Float.parseFloat(field.getText()));
41133475   Nathanael Jourdane   build floatRangeF...
208
					field.setBackground(Color.WHITE);
53d49e83   Nathanael Jourdane   Fix all Eclipse w...
209
				} catch (@SuppressWarnings("unused") NumberFormatException e) {
41133475   Nathanael Jourdane   build floatRangeF...
210
211
212
213
					field.setBackground(Color.PINK);
				}
			}
		}
eb483599   Nathanael Jourdane   Add missing Param...
214
215
	}

e97b40e8   Nathanael Jourdane   Make ParamField c...
216
	public static class TargetNameField extends ParamField implements TextFieldListener {
53d49e83   Nathanael Jourdane   Fix all Eclipse w...
217
218
		/**  */
		private static final long serialVersionUID = 5136431108894677113L;
f00cb6bb   Nathanael Jourdane   Add a JComboBox f...
219
		JComboBox<String> comboBox;
667dd80c   Nathanael Jourdane   JTextField as Par...
220
		JTextField field;
f00cb6bb   Nathanael Jourdane   Add a JComboBox f...
221
		String lastContent;
667dd80c   Nathanael Jourdane   JTextField as Par...
222

5af53be7   Nathanael Jourdane   Make the applicat...
223
224
		public TargetNameField(EpnTapMainView mainView, String paramName) {
			super(mainView, paramName);
53d49e83   Nathanael Jourdane   Fix all Eclipse w...
225
			comboBox = new JComboBox<>();
68ae1315   Nathanael Jourdane   Improve GUI appar...
226
227
			comboBox.setPreferredSize(new Dimension(MIN_FIELD_WIDTH, FIELD_HEIGHT));

f00cb6bb   Nathanael Jourdane   Add a JComboBox f...
228
229
			comboBox.setEditable(true);
			field = (JTextField) comboBox.getEditor().getEditorComponent();
e97b40e8   Nathanael Jourdane   Make ParamField c...
230
			addChangeListener(this, field);
f00cb6bb   Nathanael Jourdane   Add a JComboBox f...
231
232
233
			this.add(comboBox);
		}

53d49e83   Nathanael Jourdane   Fix all Eclipse w...
234
		static String[] getItems(String begining) throws SendQueryException {
05b140ed   Nathanael Jourdane   TargetNameField J...
235
			StringBuilder resolverResult = null;
b6627be6   Nathanael Jourdane   Improve Exceptions
236
			resolverResult = VOTableConnection.sendGet(RESOLVER_URL, "q=\"" + begining + "\"");
05b140ed   Nathanael Jourdane   TargetNameField J...
237
238
239
240
241
242
243
244
245
			JsonObject root = new JsonParser().parse(resolverResult.toString()).getAsJsonObject();
			int count = Integer.parseInt(root.get("count").toString());
			String[] targetNames = new String[count];
			JsonArray hits = root.getAsJsonArray("hits");
			for (int i = 0; i < count; i++) {
				JsonObject elmt = hits.get(i).getAsJsonObject();
				targetNames[i] = elmt.get("name").toString().replace("\"", "");
				// TODO: Display "[name] ([type])" on the JComboBox, but only "[name]" on the query.
			}
f00cb6bb   Nathanael Jourdane   Add a JComboBox f...
246
			return targetNames;
eb483599   Nathanael Jourdane   Add missing Param...
247
248
		}

e97b40e8   Nathanael Jourdane   Make ParamField c...
249
250
251
		Runnable updateComboBox = new Runnable() {
			@Override
			public void run() {
3d80f3c3   Nathanael Jourdane   bugFix: targetNam...
252
				String content = field.getText();
5af53be7   Nathanael Jourdane   Make the applicat...
253
254
255
256
				if (!content.equals(lastContent)) {
					if (content.length() >= 2) {
						lastContent = content;
						comboBox.removeAllItems();
b6627be6   Nathanael Jourdane   Improve Exceptions
257
258
259
260
261
262
						try {
							for (String s : getItems(content)) {
								comboBox.addItem(s);
							}
						} catch (SendQueryException e) {
							logger.log(Level.WARNING, "Can't get table names for the resolver", e);
5af53be7   Nathanael Jourdane   Make the applicat...
263
264
265
266
267
268
269
						}
						comboBox.getEditor().setItem(content);
					}
					if ("".equals(content)) {
						mainView.event(Event.paramRemoved, paramName);
					} else {
						mainView.event(Event.paramChanged, paramName, content);
3d80f3c3   Nathanael Jourdane   bugFix: targetNam...
270
					}
f00cb6bb   Nathanael Jourdane   Add a JComboBox f...
271
				}
e97b40e8   Nathanael Jourdane   Make ParamField c...
272
273
274
			}
		};

53d49e83   Nathanael Jourdane   Fix all Eclipse w...
275
276
		@Override
		public void update(JTextField textField) {
3d80f3c3   Nathanael Jourdane   bugFix: targetNam...
277
			SwingUtilities.invokeLater(updateComboBox);
eb483599   Nathanael Jourdane   Add missing Param...
278
279
280
281
		}
	}

	public static class DataProductTypeField extends ParamField {
53d49e83   Nathanael Jourdane   Fix all Eclipse w...
282
283
		/**  */
		private static final long serialVersionUID = -6362359909898369750L;
77184f22   Nathanael Jourdane   Use enums for Dat...
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
		JComboBox<DataProductType> comboBox;

		enum DataProductType {
			// @noformat
			ALL("All", "all"),
			IM("Image", "im"),
			SP("Spectrum", "sp"),
			DS("Dynamic spectrum", "ds"),
			SC("Spectral cube", "sc"),
			PR("Profile", "pr"),
			VO("Volume", "vo"),
			MO("Movie", "mo"),
			CU("Cube", "cu"),
			TS("Time series", "ts"),
			CA("Catalog", "ca"),
			SV("Spatial vector", "sv");
			// @format

			private String name = "";
			private String id = "";

			DataProductType(String name, String editor) {
				this.name = name;
				this.id = editor;
			}

			public List<String> query() {
				List<String> item = new ArrayList<>();
				item.add(name.replace(" ", "-").toLowerCase());
				item.add(id);
				return item;
			}

			@Override
			public String toString() {
				return name;
			}
		}
667dd80c   Nathanael Jourdane   JTextField as Par...
322

5af53be7   Nathanael Jourdane   Make the applicat...
323
324
		public DataProductTypeField(EpnTapMainView mainView, String paramName) {
			super(mainView, paramName);
77184f22   Nathanael Jourdane   Use enums for Dat...
325
326
			comboBox = new JComboBox<>(DataProductType.values());
			comboBox.setSelectedItem(DataProductType.ALL);
68ae1315   Nathanael Jourdane   Improve GUI appar...
327
			comboBox.setPreferredSize(new Dimension(MIN_FIELD_WIDTH, FIELD_HEIGHT));
a99d92fa   Nathanael Jourdane   Add JComboBox for...
328
329
330
331
332
333
334
335
336
			comboBox.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					onUpdate();
				}
			});
			this.add(comboBox);
		}

53d49e83   Nathanael Jourdane   Fix all Eclipse w...
337
		void onUpdate() {
77184f22   Nathanael Jourdane   Use enums for Dat...
338
339
			DataProductType item = (DataProductType) comboBox.getSelectedItem();
			if (DataProductType.ALL.equals(item)) {
5af53be7   Nathanael Jourdane   Make the applicat...
340
341
				mainView.event(Event.paramRemoved, paramName);
			} else {
77184f22   Nathanael Jourdane   Use enums for Dat...
342
				mainView.event(Event.paramChanged, paramName, item.query());
5af53be7   Nathanael Jourdane   Make the applicat...
343
			}
eb483599   Nathanael Jourdane   Add missing Param...
344
345
346
347
		}
	}

	public static class TargetClassField extends ParamField {
53d49e83   Nathanael Jourdane   Fix all Eclipse w...
348
349
		/**  */
		private static final long serialVersionUID = 6439475087727685080L;
77184f22   Nathanael Jourdane   Use enums for Dat...
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
		JComboBox<TargetClass> comboBox;

		enum TargetClass {
			// @noformat
			ALL("All"),
			COMET("Comet"),
			EXOPLANET("Exoplanet"),
			INTERPLANETARY_MEDIUM("Interplanetary medium"),
			RING("Ring"), SAMPLE("Sample"),
			SKY("Sky"),
			SPACECRAFT("Spacecraft"),
			SPACEJUNK("Spacejunk"),
			STAR("Star");
			// @format

			String name;

			TargetClass(String name) {
				this.name = name;
			}

			String query() {
				return name.replace(" ", "_").toLowerCase();
			}
		}
667dd80c   Nathanael Jourdane   JTextField as Par...
375

5af53be7   Nathanael Jourdane   Make the applicat...
376
377
		public TargetClassField(EpnTapMainView mainView, String paramName) {
			super(mainView, paramName);
77184f22   Nathanael Jourdane   Use enums for Dat...
378
			comboBox = new JComboBox<>(TargetClass.values());
68ae1315   Nathanael Jourdane   Improve GUI appar...
379
			comboBox.setPreferredSize(new Dimension(MIN_FIELD_WIDTH, FIELD_HEIGHT));
a99d92fa   Nathanael Jourdane   Add JComboBox for...
380
381
382
383
384
385
386
387
388
			comboBox.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					onUpdate();
				}
			});
			this.add(comboBox);
		}

53d49e83   Nathanael Jourdane   Fix all Eclipse w...
389
		void onUpdate() {
77184f22   Nathanael Jourdane   Use enums for Dat...
390
391
			TargetClass value = (TargetClass) comboBox.getSelectedItem();
			if (TargetClass.ALL.equals(value)) {
5af53be7   Nathanael Jourdane   Make the applicat...
392
393
				mainView.event(Event.paramRemoved, paramName);
			} else {
77184f22   Nathanael Jourdane   Use enums for Dat...
394
				mainView.event(Event.paramChanged, paramName, value.query());
5af53be7   Nathanael Jourdane   Make the applicat...
395
			}
eb483599   Nathanael Jourdane   Add missing Param...
396
397
398
		}
	}

e97b40e8   Nathanael Jourdane   Make ParamField c...
399
400
401
	interface TextFieldListener {
		void update(JTextField field);
	}
eb483599   Nathanael Jourdane   Add missing Param...
402

42819b99   Nathanael Jourdane   Make EpnTAPClient...
403
	static void addChangeListener(final TextFieldListener changeListener, final JTextField field) {
e97b40e8   Nathanael Jourdane   Make ParamField c...
404
		field.getDocument().addDocumentListener(new DocumentListener() {
53d49e83   Nathanael Jourdane   Fix all Eclipse w...
405
			@Override
e97b40e8   Nathanael Jourdane   Make ParamField c...
406
407
			public void removeUpdate(DocumentEvent de) {
				changeListener.update(field);
eb483599   Nathanael Jourdane   Add missing Param...
408
409
			}

53d49e83   Nathanael Jourdane   Fix all Eclipse w...
410
			@Override
e97b40e8   Nathanael Jourdane   Make ParamField c...
411
412
			public void insertUpdate(DocumentEvent de) {
				changeListener.update(field);
eb483599   Nathanael Jourdane   Add missing Param...
413
414
			}

53d49e83   Nathanael Jourdane   Fix all Eclipse w...
415
			@Override
e97b40e8   Nathanael Jourdane   Make ParamField c...
416
417
			public void changedUpdate(DocumentEvent de) {
				changeListener.update(field);
eb483599   Nathanael Jourdane   Add missing Param...
418
			}
eb483599   Nathanael Jourdane   Add missing Param...
419
		});
eb483599   Nathanael Jourdane   Add missing Param...
420
421
	}
}