Blame view

src/main/java/eu/omp/irap/vespa/epntapclient/view/ParamField.java 13.7 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

a227a22d   Nathanael Jourdane   Add comments.
48
49
50
51
52
/**
 * A field used to set a service parameter to build the query (in the parameter panel).
 * 
 * @author N. Jourdane
 */
eb483599   Nathanael Jourdane   Add missing Param...
53
public abstract class ParamField extends JPanel {
53d49e83   Nathanael Jourdane   Fix all Eclipse w...
54
55
56
	/**  */
	private static final long serialVersionUID = 6025994164004985362L;

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

a227a22d   Nathanael Jourdane   Add comments.
60
	/** The minimum width of the field. */
68ae1315   Nathanael Jourdane   Improve GUI appar...
61
	private static final int MIN_FIELD_WIDTH = 30;
a227a22d   Nathanael Jourdane   Add comments.
62
	/** The preferred field height. */
68ae1315   Nathanael Jourdane   Improve GUI appar...
63
	private static final int FIELD_HEIGHT = 20;
a227a22d   Nathanael Jourdane   Add comments.
64
	/** The maximum width of the field. */
68ae1315   Nathanael Jourdane   Improve GUI appar...
65
	private static final int MAX_FIELD_WIDTH = 400;
a227a22d   Nathanael Jourdane   Add comments.
66
	/** The preferred label width. */
68ae1315   Nathanael Jourdane   Improve GUI appar...
67
68
	private static final int LABEL_WIDTH = 140;

a227a22d   Nathanael Jourdane   Add comments.
69
	/** The URL of the resolver used for the `target name` field. */
05b140ed   Nathanael Jourdane   TargetNameField J...
70
	private static final String RESOLVER_URL = "http://voparis-registry.obspm.fr/ssodnet/1/autocomplete";
a227a22d   Nathanael Jourdane   Add comments.
71
	/** The date format used in the DateRange field */
eb483599   Nathanael Jourdane   Add missing Param...
72
	private static final String DATE_FORMAT = "dd/MM/yyyy";
a227a22d   Nathanael Jourdane   Add comments.
73
	/** The regex used to validate the Date fields */
eb483599   Nathanael Jourdane   Add missing Param...
74
	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)$)";
a227a22d   Nathanael Jourdane   Add comments.
75
	/** The suffix used in REG-TAP parameters names, indicating that it's a beginning of a range. */
eb483599   Nathanael Jourdane   Add missing Param...
76
	private static final String MIN_SUFFIX = "min";
a227a22d   Nathanael Jourdane   Add comments.
77
	/** The suffix used in REG-TAP parameters names, indicating that it is a end of a range. */
eb483599   Nathanael Jourdane   Add missing Param...
78
79
	private static final String MAX_SUFFIX = "max";

a227a22d   Nathanael Jourdane   Add comments.
80
	/** The main view of the application. */
53d49e83   Nathanael Jourdane   Fix all Eclipse w...
81
	protected EpnTapMainView mainView;
a227a22d   Nathanael Jourdane   Add comments.
82
	/** The parameter name of the field */
eb483599   Nathanael Jourdane   Add missing Param...
83
84
	protected String paramName;

5af53be7   Nathanael Jourdane   Make the applicat...
85
	public ParamField(EpnTapMainView mainView, String paramName) {
eb483599   Nathanael Jourdane   Add missing Param...
86
		super();
5af53be7   Nathanael Jourdane   Make the applicat...
87
88
89
90

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

eb483599   Nathanael Jourdane   Add missing Param...
91
		this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
68ae1315   Nathanael Jourdane   Improve GUI appar...
92
		this.setMaximumSize(new Dimension(MAX_FIELD_WIDTH, FIELD_HEIGHT));
eb483599   Nathanael Jourdane   Add missing Param...
93
94
		String strLabel = paramName.replaceAll("_", " ").trim();
		JLabel label = new JLabel(strLabel.substring(0, 1).toUpperCase() + strLabel.substring(1));
68ae1315   Nathanael Jourdane   Improve GUI appar...
95
		label.setPreferredSize(new Dimension(LABEL_WIDTH, FIELD_HEIGHT));
eb483599   Nathanael Jourdane   Add missing Param...
96
		this.add(label);
41133475   Nathanael Jourdane   build floatRangeF...
97
		// TODO: Add tooltip text based on rr.table_column.column_description
eb483599   Nathanael Jourdane   Add missing Param...
98
99
	}

e97b40e8   Nathanael Jourdane   Make ParamField c...
100
	public static class StringField extends ParamField implements TextFieldListener {
53d49e83   Nathanael Jourdane   Fix all Eclipse w...
101
102
		/**  */
		private static final long serialVersionUID = 24219488975302068L;
667dd80c   Nathanael Jourdane   JTextField as Par...
103
104
		JTextField field;

5af53be7   Nathanael Jourdane   Make the applicat...
105
106
		public StringField(EpnTapMainView mainView, String paramName) {
			super(mainView, paramName);
667dd80c   Nathanael Jourdane   JTextField as Par...
107
			field = new JTextField();
e97b40e8   Nathanael Jourdane   Make ParamField c...
108
			addChangeListener(this, field);
eb483599   Nathanael Jourdane   Add missing Param...
109
110
111
			this.add(field);
		}

53d49e83   Nathanael Jourdane   Fix all Eclipse w...
112
113
114
		@Override
		public void update(JTextField textField) {
			if ("".equals(textField.getText())) {
5af53be7   Nathanael Jourdane   Make the applicat...
115
				mainView.event(Event.paramChanged, paramName, null);
eb483599   Nathanael Jourdane   Add missing Param...
116
			} else {
53d49e83   Nathanael Jourdane   Fix all Eclipse w...
117
				mainView.event(Event.paramChanged, paramName, textField.getText());
eb483599   Nathanael Jourdane   Add missing Param...
118
119
120
121
			}
		}
	}

e97b40e8   Nathanael Jourdane   Make ParamField c...
122
	public static class FloatField extends ParamField implements TextFieldListener {
53d49e83   Nathanael Jourdane   Fix all Eclipse w...
123
124
		/**  */
		private static final long serialVersionUID = -1880193152285564590L;
667dd80c   Nathanael Jourdane   JTextField as Par...
125
126
		JTextField field;

5af53be7   Nathanael Jourdane   Make the applicat...
127
128
		public FloatField(EpnTapMainView mainView, String paramName) {
			super(mainView, paramName);
667dd80c   Nathanael Jourdane   JTextField as Par...
129
			field = new JTextField();
e97b40e8   Nathanael Jourdane   Make ParamField c...
130
			addChangeListener(this, field);
eb483599   Nathanael Jourdane   Add missing Param...
131
132
133
			this.add(field);
		}

53d49e83   Nathanael Jourdane   Fix all Eclipse w...
134
135
136
137
		@Override
		public void update(JTextField textField) {
			if ("".equals(textField.getText())) {
				textField.setBackground(Color.WHITE);
5af53be7   Nathanael Jourdane   Make the applicat...
138
				mainView.event(Event.paramRemoved, paramName);
eb483599   Nathanael Jourdane   Add missing Param...
139
140
			} else {
				try {
53d49e83   Nathanael Jourdane   Fix all Eclipse w...
141
142
143
144
145
					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...
146
147
148
149
150
				}
			}
		}
	}

e97b40e8   Nathanael Jourdane   Make ParamField c...
151
	public static class DateRangeField extends ParamField implements TextFieldListener {
53d49e83   Nathanael Jourdane   Fix all Eclipse w...
152
153
		/**  */
		private static final long serialVersionUID = -7781309003911514777L;
667dd80c   Nathanael Jourdane   JTextField as Par...
154
155
156
		JTextField fieldMin;
		JTextField fieldMax;

5af53be7   Nathanael Jourdane   Make the applicat...
157
158
		public DateRangeField(EpnTapMainView mainView, String paramName) {
			super(mainView, paramName);
68ae1315   Nathanael Jourdane   Improve GUI appar...
159
			this.add(new JLabel("min "));
667dd80c   Nathanael Jourdane   JTextField as Par...
160
			fieldMin = new JTextField();
e97b40e8   Nathanael Jourdane   Make ParamField c...
161
			fieldMin.setName(MIN_SUFFIX);
68ae1315   Nathanael Jourdane   Improve GUI appar...
162
			fieldMin.setPreferredSize(new Dimension(MIN_FIELD_WIDTH, FIELD_HEIGHT));
e97b40e8   Nathanael Jourdane   Make ParamField c...
163
			addChangeListener(this, fieldMin);
eb483599   Nathanael Jourdane   Add missing Param...
164
165
			this.add(fieldMin);

68ae1315   Nathanael Jourdane   Improve GUI appar...
166
			this.add(new JLabel("max "));
667dd80c   Nathanael Jourdane   JTextField as Par...
167
			fieldMax = new JTextField();
e97b40e8   Nathanael Jourdane   Make ParamField c...
168
			fieldMax.setName(MAX_SUFFIX);
68ae1315   Nathanael Jourdane   Improve GUI appar...
169
			fieldMax.setPreferredSize(new Dimension(MIN_FIELD_WIDTH, FIELD_HEIGHT));
e97b40e8   Nathanael Jourdane   Make ParamField c...
170
			addChangeListener(this, fieldMin);
eb483599   Nathanael Jourdane   Add missing Param...
171
172
173
			this.add(fieldMax);
		}

53d49e83   Nathanael Jourdane   Fix all Eclipse w...
174
		@Override
e97b40e8   Nathanael Jourdane   Make ParamField c...
175
		public void update(JTextField field) {
eb483599   Nathanael Jourdane   Add missing Param...
176
177
178
			DateFormat df = new SimpleDateFormat(DATE_FORMAT, Locale.ENGLISH);
			if ("".equals(field.getText())) {
				field.setBackground(Color.WHITE);
5af53be7   Nathanael Jourdane   Make the applicat...
179
				mainView.event(Event.paramRemoved, paramName + field.getName());
eb483599   Nathanael Jourdane   Add missing Param...
180
181
182
			} else if (field.getText().matches(DATE_REGEX)) {
				try {
					long date = df.parse(field.getText()).getTime();
5af53be7   Nathanael Jourdane   Make the applicat...
183
184
					date = Math.round((date / 86400000.0) + 2440587.5); // to JD
					mainView.event(Event.paramChanged, paramName + field.getName(), date);
eb483599   Nathanael Jourdane   Add missing Param...
185
					field.setBackground(Color.WHITE);
53d49e83   Nathanael Jourdane   Fix all Eclipse w...
186
				} catch (@SuppressWarnings("unused") ParseException e) {
eb483599   Nathanael Jourdane   Add missing Param...
187
188
189
190
191
192
193
194
195
					field.setBackground(Color.PINK);
				}
				// TODO: check if date min < date max
			} else {
				field.setBackground(Color.PINK);
			}
		}
	}

e97b40e8   Nathanael Jourdane   Make ParamField c...
196
	public static class FloatRangeField extends ParamField implements TextFieldListener {
53d49e83   Nathanael Jourdane   Fix all Eclipse w...
197
198
		/**  */
		private static final long serialVersionUID = 7923358142882329015L;
41133475   Nathanael Jourdane   build floatRangeF...
199
200
		JTextField fieldMin;
		JTextField fieldMax;
eb483599   Nathanael Jourdane   Add missing Param...
201

5af53be7   Nathanael Jourdane   Make the applicat...
202
203
		public FloatRangeField(EpnTapMainView mainView, String paramName) {
			super(mainView, paramName);
41133475   Nathanael Jourdane   build floatRangeF...
204
			fieldMin = new JTextField();
e97b40e8   Nathanael Jourdane   Make ParamField c...
205
206
			fieldMin.setName(MIN_SUFFIX);
			addChangeListener(this, fieldMin);
eb483599   Nathanael Jourdane   Add missing Param...
207
208
			this.add(fieldMin);

41133475   Nathanael Jourdane   build floatRangeF...
209
			fieldMax = new JTextField();
e97b40e8   Nathanael Jourdane   Make ParamField c...
210
211
			fieldMax.setName(MAX_SUFFIX);
			addChangeListener(this, fieldMax);
eb483599   Nathanael Jourdane   Add missing Param...
212
213
			this.add(fieldMax);
		}
41133475   Nathanael Jourdane   build floatRangeF...
214

53d49e83   Nathanael Jourdane   Fix all Eclipse w...
215
		@Override
e97b40e8   Nathanael Jourdane   Make ParamField c...
216
		public void update(JTextField field) {
41133475   Nathanael Jourdane   build floatRangeF...
217
218
			if ("".equals(field.getText())) {
				field.setBackground(Color.WHITE);
5af53be7   Nathanael Jourdane   Make the applicat...
219
				mainView.event(Event.paramRemoved, paramName + field.getName());
41133475   Nathanael Jourdane   build floatRangeF...
220
221
			} else {
				try {
5af53be7   Nathanael Jourdane   Make the applicat...
222
					mainView.event(Event.paramChanged, paramName + field.getName(),
e97b40e8   Nathanael Jourdane   Make ParamField c...
223
							Float.parseFloat(field.getText()));
41133475   Nathanael Jourdane   build floatRangeF...
224
					field.setBackground(Color.WHITE);
53d49e83   Nathanael Jourdane   Fix all Eclipse w...
225
				} catch (@SuppressWarnings("unused") NumberFormatException e) {
41133475   Nathanael Jourdane   build floatRangeF...
226
227
228
229
					field.setBackground(Color.PINK);
				}
			}
		}
eb483599   Nathanael Jourdane   Add missing Param...
230
231
	}

e97b40e8   Nathanael Jourdane   Make ParamField c...
232
	public static class TargetNameField extends ParamField implements TextFieldListener {
53d49e83   Nathanael Jourdane   Fix all Eclipse w...
233
234
		/**  */
		private static final long serialVersionUID = 5136431108894677113L;
f00cb6bb   Nathanael Jourdane   Add a JComboBox f...
235
		JComboBox<String> comboBox;
667dd80c   Nathanael Jourdane   JTextField as Par...
236
		JTextField field;
f00cb6bb   Nathanael Jourdane   Add a JComboBox f...
237
		String lastContent;
667dd80c   Nathanael Jourdane   JTextField as Par...
238

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

f00cb6bb   Nathanael Jourdane   Add a JComboBox f...
244
245
			comboBox.setEditable(true);
			field = (JTextField) comboBox.getEditor().getEditorComponent();
e97b40e8   Nathanael Jourdane   Make ParamField c...
246
			addChangeListener(this, field);
f00cb6bb   Nathanael Jourdane   Add a JComboBox f...
247
248
249
			this.add(comboBox);
		}

53d49e83   Nathanael Jourdane   Fix all Eclipse w...
250
		static String[] getItems(String begining) throws SendQueryException {
05b140ed   Nathanael Jourdane   TargetNameField J...
251
			StringBuilder resolverResult = null;
b6627be6   Nathanael Jourdane   Improve Exceptions
252
			resolverResult = VOTableConnection.sendGet(RESOLVER_URL, "q=\"" + begining + "\"");
05b140ed   Nathanael Jourdane   TargetNameField J...
253
254
255
256
257
258
259
260
261
			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...
262
			return targetNames;
eb483599   Nathanael Jourdane   Add missing Param...
263
264
		}

e97b40e8   Nathanael Jourdane   Make ParamField c...
265
266
267
		Runnable updateComboBox = new Runnable() {
			@Override
			public void run() {
3d80f3c3   Nathanael Jourdane   bugFix: targetNam...
268
				String content = field.getText();
5af53be7   Nathanael Jourdane   Make the applicat...
269
270
271
272
				if (!content.equals(lastContent)) {
					if (content.length() >= 2) {
						lastContent = content;
						comboBox.removeAllItems();
b6627be6   Nathanael Jourdane   Improve Exceptions
273
274
275
276
277
278
						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...
279
280
281
282
283
284
285
						}
						comboBox.getEditor().setItem(content);
					}
					if ("".equals(content)) {
						mainView.event(Event.paramRemoved, paramName);
					} else {
						mainView.event(Event.paramChanged, paramName, content);
3d80f3c3   Nathanael Jourdane   bugFix: targetNam...
286
					}
f00cb6bb   Nathanael Jourdane   Add a JComboBox f...
287
				}
e97b40e8   Nathanael Jourdane   Make ParamField c...
288
289
290
			}
		};

53d49e83   Nathanael Jourdane   Fix all Eclipse w...
291
292
		@Override
		public void update(JTextField textField) {
3d80f3c3   Nathanael Jourdane   bugFix: targetNam...
293
			SwingUtilities.invokeLater(updateComboBox);
eb483599   Nathanael Jourdane   Add missing Param...
294
295
296
297
		}
	}

	public static class DataProductTypeField extends ParamField {
53d49e83   Nathanael Jourdane   Fix all Eclipse w...
298
299
		/**  */
		private static final long serialVersionUID = -6362359909898369750L;
77184f22   Nathanael Jourdane   Use enums for Dat...
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
		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...
338

5af53be7   Nathanael Jourdane   Make the applicat...
339
340
		public DataProductTypeField(EpnTapMainView mainView, String paramName) {
			super(mainView, paramName);
77184f22   Nathanael Jourdane   Use enums for Dat...
341
342
			comboBox = new JComboBox<>(DataProductType.values());
			comboBox.setSelectedItem(DataProductType.ALL);
68ae1315   Nathanael Jourdane   Improve GUI appar...
343
			comboBox.setPreferredSize(new Dimension(MIN_FIELD_WIDTH, FIELD_HEIGHT));
a99d92fa   Nathanael Jourdane   Add JComboBox for...
344
345
346
347
348
349
350
351
352
			comboBox.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					onUpdate();
				}
			});
			this.add(comboBox);
		}

53d49e83   Nathanael Jourdane   Fix all Eclipse w...
353
		void onUpdate() {
77184f22   Nathanael Jourdane   Use enums for Dat...
354
355
			DataProductType item = (DataProductType) comboBox.getSelectedItem();
			if (DataProductType.ALL.equals(item)) {
5af53be7   Nathanael Jourdane   Make the applicat...
356
357
				mainView.event(Event.paramRemoved, paramName);
			} else {
77184f22   Nathanael Jourdane   Use enums for Dat...
358
				mainView.event(Event.paramChanged, paramName, item.query());
5af53be7   Nathanael Jourdane   Make the applicat...
359
			}
eb483599   Nathanael Jourdane   Add missing Param...
360
361
362
363
		}
	}

	public static class TargetClassField extends ParamField {
53d49e83   Nathanael Jourdane   Fix all Eclipse w...
364
365
		/**  */
		private static final long serialVersionUID = 6439475087727685080L;
77184f22   Nathanael Jourdane   Use enums for Dat...
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
		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...
391

5af53be7   Nathanael Jourdane   Make the applicat...
392
393
		public TargetClassField(EpnTapMainView mainView, String paramName) {
			super(mainView, paramName);
77184f22   Nathanael Jourdane   Use enums for Dat...
394
			comboBox = new JComboBox<>(TargetClass.values());
68ae1315   Nathanael Jourdane   Improve GUI appar...
395
			comboBox.setPreferredSize(new Dimension(MIN_FIELD_WIDTH, FIELD_HEIGHT));
a99d92fa   Nathanael Jourdane   Add JComboBox for...
396
397
398
399
400
401
402
403
404
			comboBox.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					onUpdate();
				}
			});
			this.add(comboBox);
		}

53d49e83   Nathanael Jourdane   Fix all Eclipse w...
405
		void onUpdate() {
77184f22   Nathanael Jourdane   Use enums for Dat...
406
407
			TargetClass value = (TargetClass) comboBox.getSelectedItem();
			if (TargetClass.ALL.equals(value)) {
5af53be7   Nathanael Jourdane   Make the applicat...
408
409
				mainView.event(Event.paramRemoved, paramName);
			} else {
77184f22   Nathanael Jourdane   Use enums for Dat...
410
				mainView.event(Event.paramChanged, paramName, value.query());
5af53be7   Nathanael Jourdane   Make the applicat...
411
			}
eb483599   Nathanael Jourdane   Add missing Param...
412
413
414
		}
	}

e97b40e8   Nathanael Jourdane   Make ParamField c...
415
416
417
	interface TextFieldListener {
		void update(JTextField field);
	}
eb483599   Nathanael Jourdane   Add missing Param...
418

42819b99   Nathanael Jourdane   Make EpnTAPClient...
419
	static void addChangeListener(final TextFieldListener changeListener, final JTextField field) {
e97b40e8   Nathanael Jourdane   Make ParamField c...
420
		field.getDocument().addDocumentListener(new DocumentListener() {
53d49e83   Nathanael Jourdane   Fix all Eclipse w...
421
			@Override
e97b40e8   Nathanael Jourdane   Make ParamField c...
422
423
			public void removeUpdate(DocumentEvent de) {
				changeListener.update(field);
eb483599   Nathanael Jourdane   Add missing Param...
424
425
			}

53d49e83   Nathanael Jourdane   Fix all Eclipse w...
426
			@Override
e97b40e8   Nathanael Jourdane   Make ParamField c...
427
428
			public void insertUpdate(DocumentEvent de) {
				changeListener.update(field);
eb483599   Nathanael Jourdane   Add missing Param...
429
430
			}

53d49e83   Nathanael Jourdane   Fix all Eclipse w...
431
			@Override
e97b40e8   Nathanael Jourdane   Make ParamField c...
432
433
			public void changedUpdate(DocumentEvent de) {
				changeListener.update(field);
eb483599   Nathanael Jourdane   Add missing Param...
434
			}
eb483599   Nathanael Jourdane   Add missing Param...
435
		});
eb483599   Nathanael Jourdane   Add missing Param...
436
437
	}
}