Commit bd930b1fb8fc567b92ef5083bde274cf54f946ff

Authored by Nathanael Jourdane
1 parent 4a9845fd
Exists in master

fix #9

src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/ParamField.java deleted
@@ -1,664 +0,0 @@ @@ -1,664 +0,0 @@
1 -/*  
2 - * This file is a part of EpnTAPClient.  
3 - * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer.  
4 - * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861  
5 - * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie.  
6 - *  
7 - * This program is free software: you can  
8 - * redistribute it and/or modify it under the terms of the GNU General Public License as published  
9 - * by the Free Software Foundation, either version 3 of the License, or (at your option) any later  
10 - * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY  
11 - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR  
12 - * PURPOSE. See the GNU General Public License for more details. You should have received a copy of  
13 - * the GNU General Public License along with this program. If not, see  
14 - * <http://www.gnu.org/licenses/>.  
15 - */  
16 -  
17 -package eu.omp.irap.vespa.epntapclient.gui.requestpanel;  
18 -  
19 -import java.awt.Color;  
20 -import java.awt.Dimension;  
21 -import java.awt.event.ActionEvent;  
22 -import java.awt.event.ActionListener;  
23 -import java.text.DateFormat;  
24 -import java.text.ParseException;  
25 -import java.text.SimpleDateFormat;  
26 -import java.util.ArrayList;  
27 -import java.util.List;  
28 -import java.util.Locale;  
29 -import java.util.logging.Level;  
30 -import java.util.logging.Logger;  
31 -  
32 -import javax.swing.BoxLayout;  
33 -import javax.swing.JComboBox;  
34 -import javax.swing.JLabel;  
35 -import javax.swing.JPanel;  
36 -import javax.swing.JTextField;  
37 -import javax.swing.SwingUtilities;  
38 -import javax.swing.event.DocumentEvent;  
39 -import javax.swing.event.DocumentListener;  
40 -  
41 -import eu.omp.irap.vespa.epntapclient.EpnTapGet;  
42 -import eu.omp.irap.vespa.epntapclient.gui.mainPanel.ViewListener;  
43 -import eu.omp.irap.vespa.votable.utils.CantSendQueryException;  
44 -  
45 -/**  
46 - * A field used to set a service parameter to build the query (in the parameter panel). ParamField  
47 - * is an abstract method and all type of parameter field should extend it. See  
48 - * https://voparis-confluence.obspm.fr/display/VES/4+-+EPN-TAP+queries to get all parameters  
49 - * details.  
50 - *  
51 - * @author N. Jourdane  
52 - */  
53 -public abstract class ParamField extends JPanel {  
54 -  
55 - /** The serial version UID. */  
56 - private static final long serialVersionUID = 1L;  
57 -  
58 - /** The logger for the class ParamField. */  
59 - protected static final Logger logger = Logger.getLogger(ParamField.class.getName());  
60 -  
61 - /** The minimum width of the field. */  
62 - private static final int MIN_FIELD_WIDTH = 30;  
63 -  
64 - /** The preferred field height. */  
65 - private static final int FIELD_HEIGHT = 20;  
66 -  
67 - /** The maximum width of the field. */  
68 - private static final int MAX_FIELD_WIDTH = 400;  
69 -  
70 - /** The preferred label width. */  
71 - private static final int LABEL_WIDTH = 140;  
72 -  
73 - /** The date format used in the DateRange field */  
74 - private static final String DATE_FORMAT = "dd/MM/yyyy";  
75 -  
76 - /** The regex used to validate the Date fields */  
77 - 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)$)";  
78 -  
79 - /** The suffix used in REG-TAP parameters names, indicating that it's a beginning of a range. */  
80 - private static final String MIN_SUFFIX = "min";  
81 -  
82 - /** The suffix used in REG-TAP parameters names, indicating that it is a end of a range. */  
83 - private static final String MAX_SUFFIX = "max";  
84 -  
85 - /** The main view of the application. */  
86 - protected ViewListener viewListener;  
87 -  
88 - /** The parameter name of the field */  
89 - protected String paramName;  
90 -  
91 -  
92 - /**  
93 - * Method constructor for the parameter field abstract class, which do all common action for all  
94 - * type of field, such as displaying the name of the parameter.  
95 - *  
96 - * @param mainView The main view of the application.  
97 - * @param paramName The name of the parameter.  
98 - */  
99 - public ParamField(ViewListener viewListener, String paramName) {  
100 - super();  
101 -  
102 - this.viewListener = viewListener;  
103 - this.paramName = paramName;  
104 -  
105 - buildParamField();  
106 - }  
107 -  
108 - private void buildParamField() {  
109 - setLayout(new BoxLayout(this, BoxLayout.X_AXIS));  
110 -  
111 - setMaximumSize(new Dimension(ParamField.MAX_FIELD_WIDTH, ParamField.FIELD_HEIGHT));  
112 -  
113 - String strLabel = paramName.replaceAll("_", " ").trim();  
114 - JLabel label = new JLabel(strLabel.substring(0, 1).toUpperCase() + strLabel.substring(1));  
115 - label.setPreferredSize(new Dimension(ParamField.LABEL_WIDTH, ParamField.FIELD_HEIGHT));  
116 -  
117 - this.add(label);  
118 - }  
119 -  
120 -  
121 - /**  
122 - * The string field is used for parameter with a `String` class. It is a simple JTextField with  
123 - * no verification. The parameter is sent to the controller each time it is modified.  
124 - *  
125 - * @author N. Jourdane  
126 - */  
127 - public static class StringField extends ParamField implements TextFieldListener {  
128 -  
129 - /** The serial version UID. */  
130 - private static final long serialVersionUID = 1L;  
131 -  
132 - /** The JTextField used to put the parameter value. */  
133 - JTextField field;  
134 -  
135 -  
136 - /**  
137 - * Method constructor for the string field.  
138 - *  
139 - * @param mainView The main view of the application.  
140 - * @param paramName The name of the parameter.  
141 - */  
142 - public StringField(ViewListener viewListener, String paramName) {  
143 - super(viewListener, paramName);  
144 - field = new JTextField();  
145 - ParamField.addChangeListener(this, field);  
146 - this.add(field);  
147 - }  
148 -  
149 - /**  
150 - * This method is called each time the field is modified.  
151 - */  
152 - @Override  
153 - public void update(JTextField textField) {  
154 - if (textField.getText().isEmpty()) {  
155 - viewListener.onParameterChanged(paramName, null);  
156 - } else {  
157 - viewListener.onParameterChanged(paramName, textField.getText());  
158 - }  
159 - }  
160 - }  
161 -  
162 - /**  
163 - * The float field is used for parameter with a `Float` class. It is a JTextField which checks  
164 - * if the content is a valid float. If the parameter is valid or if it is empty, then the float  
165 - * value is sent to the controller.  
166 - *  
167 - * @author N. Jourdane  
168 - */  
169 - public static class FloatField extends ParamField implements TextFieldListener {  
170 -  
171 - /** The serial version UID. */  
172 - private static final long serialVersionUID = 1L;  
173 -  
174 - /** The JTextField used to put the parameter value. */  
175 - JTextField field;  
176 -  
177 -  
178 - /**  
179 - * Method constructor  
180 - *  
181 - * @param mainView The main view of the application.  
182 - * @param paramName The name of the parameter.  
183 - */  
184 - public FloatField(ViewListener viewListener, String paramName) {  
185 - super(viewListener, paramName);  
186 - field = new JTextField();  
187 - ParamField.addChangeListener(this, field);  
188 - this.add(field);  
189 - }  
190 -  
191 - /**  
192 - * This method is called each time the field is modified.  
193 - */  
194 - @Override  
195 - public void update(JTextField textField) {  
196 - if (textField.getText().isEmpty()) {  
197 - textField.setBackground(Color.WHITE);  
198 - viewListener.onParameterRemoved(paramName);  
199 - } else {  
200 - try {  
201 - float value = Float.parseFloat(textField.getText());  
202 - viewListener.onParameterChanged(paramName, value);  
203 - textField.setBackground(Color.WHITE);  
204 - } catch (@SuppressWarnings("unused") NumberFormatException e) {  
205 - textField.setBackground(Color.PINK);  
206 - }  
207 - }  
208 - }  
209 - }  
210 -  
211 - /**  
212 - * The date range field is used for couples of parameter with both a `Date` type (actually only  
213 - * `time_min` and `time_max` parameters is concerned for now). These are JTextFields which check  
214 - * if the content is a valid date, according to DATE_FORMAT. If the parameter is valid or if it  
215 - * is empty, then the dates value are sent to the controller, in Julian Day format.  
216 - *  
217 - * @author N. Jourdane  
218 - */  
219 - public static class DateRangeField extends ParamField implements TextFieldListener {  
220 -  
221 - /** The serial version UID. */  
222 - private static final long serialVersionUID = 1L;  
223 -  
224 - /** The JTextField used to put the parameter minimum value of the range. */  
225 - JTextField fieldMin;  
226 -  
227 - /** The JTextField used to put the parameter maximum value of the range. */  
228 - JTextField fieldMax;  
229 -  
230 -  
231 - /**  
232 - * Method constructor  
233 - *  
234 - * @param mainView The main view of the application.  
235 - * @param paramName The name of the parameter.  
236 - */  
237 - public DateRangeField(ViewListener viewListener, String paramName) {  
238 - super(viewListener, paramName);  
239 - this.add(new JLabel("min "));  
240 - fieldMin = new JTextField();  
241 - fieldMin.setName(ParamField.MIN_SUFFIX);  
242 - fieldMin.setPreferredSize(  
243 - new Dimension(ParamField.MIN_FIELD_WIDTH, ParamField.FIELD_HEIGHT));  
244 - ParamField.addChangeListener(this, fieldMin);  
245 - this.add(fieldMin);  
246 -  
247 - this.add(new JLabel("max "));  
248 - fieldMax = new JTextField();  
249 - fieldMax.setName(ParamField.MAX_SUFFIX);  
250 - fieldMax.setPreferredSize(  
251 - new Dimension(ParamField.MIN_FIELD_WIDTH, ParamField.FIELD_HEIGHT));  
252 - ParamField.addChangeListener(this, fieldMin);  
253 - this.add(fieldMax);  
254 - }  
255 -  
256 - /**  
257 - * This method is called each time the field is modified.  
258 - */  
259 - @Override  
260 - public void update(JTextField field) {  
261 - DateFormat df = new SimpleDateFormat(ParamField.DATE_FORMAT, Locale.ENGLISH);  
262 - if (field.getText().isEmpty()) {  
263 - field.setBackground(Color.WHITE);  
264 - viewListener.onParameterRemoved(paramName + field.getName());  
265 - } else if (field.getText().matches(ParamField.DATE_REGEX)) {  
266 - try {  
267 - long date = df.parse(field.getText()).getTime();  
268 - date = Math.round(date / 86400000.0 + 2440587.5); // to JD  
269 - viewListener.onParameterChanged(paramName + field.getName(),  
270 - date);  
271 - field.setBackground(Color.WHITE);  
272 - } catch (@SuppressWarnings("unused") ParseException e) {  
273 - field.setBackground(Color.PINK);  
274 - }  
275 - // TODO: check if date min < date max  
276 - } else {  
277 - field.setBackground(Color.PINK);  
278 - }  
279 - }  
280 - }  
281 -  
282 - /**  
283 - * The float range field is used for couples of parameter with both a `Float` class. These are  
284 - * JTextFields which check if the content is a valid float. If the parameter is valid or if it  
285 - * is empty, then the float value are sent to the controller.  
286 - *  
287 - * @author N. Jourdane  
288 - */  
289 - public static class FloatRangeField extends ParamField implements TextFieldListener {  
290 -  
291 - /** The serial version UID. */  
292 - private static final long serialVersionUID = 1L;  
293 -  
294 - /** The JTextField used to put the parameter minimum value of the range. */  
295 - JTextField fieldMin;  
296 -  
297 - /** The JTextField used to put the parameter maximum value of the range. */  
298 - JTextField fieldMax;  
299 -  
300 -  
301 - /**  
302 - * Method constructor  
303 - *  
304 - * @param mainView The main view of the application.  
305 - * @param paramName The name of the parameter.  
306 - */  
307 - public FloatRangeField(ViewListener viewListener, String paramName) {  
308 - super(viewListener, paramName);  
309 - fieldMin = new JTextField();  
310 - fieldMin.setName(ParamField.MIN_SUFFIX);  
311 - ParamField.addChangeListener(this, fieldMin);  
312 - this.add(fieldMin);  
313 -  
314 - fieldMax = new JTextField();  
315 - fieldMax.setName(ParamField.MAX_SUFFIX);  
316 - ParamField.addChangeListener(this, fieldMax);  
317 - this.add(fieldMax);  
318 - }  
319 -  
320 - /**  
321 - * This method is called each time the field is modified.  
322 - */  
323 - @Override  
324 - public void update(JTextField field) {  
325 - if (field.getText().isEmpty()) {  
326 - field.setBackground(Color.WHITE);  
327 - viewListener.onParameterRemoved(paramName + field.getName());  
328 - } else {  
329 - try {  
330 - viewListener.onParameterChanged(paramName + field.getName(),  
331 - Float.parseFloat(field.getText()));  
332 - field.setBackground(Color.WHITE);  
333 - } catch (@SuppressWarnings("unused") NumberFormatException e) {  
334 - field.setBackground(Color.PINK);  
335 - }  
336 - }  
337 - }  
338 - }  
339 -  
340 - /**  
341 - * The target name field is used only for the `target_name` parameter. It is a ComboBox which is  
342 - * automatically filled with actual target names which begins by the entered characters, by  
343 - * asking to an online resolver (RESOLVER_URL). The parameter is sent to the controller each  
344 - * time it is updated, so it is possible to enter a parameter that the resolver do not know.  
345 - *  
346 - * @author N. Jourdane  
347 - */  
348 - public static class TargetNameField extends ParamField implements TextFieldListener {  
349 -  
350 - /** The serial version UID. */  
351 - private static final long serialVersionUID = 1L;  
352 -  
353 - /** The comboBox to enter the target_name and display target name propositions. */  
354 - JComboBox<String> comboBox;  
355 -  
356 - /** The JTextField related to the ComboBox, allowing to listen for text content update. */  
357 - JTextField field;  
358 -  
359 - /**  
360 - * The content of the last entered value. It is used to avoid recursions, because each time  
361 - * an update event is detected, the resolver is called and the ComboBox is filled with new  
362 - * values, which trigger a new event.  
363 - */  
364 - String lastContent;  
365 -  
366 - /**  
367 - * This method is called each time the field is modified. A Runnable is used it is  
368 - * impossible to modify the comboBox from a DocumentEvent.  
369 - */  
370 - Runnable updateComboBox = new Runnable() {  
371 -  
372 - @Override  
373 - public void run() {  
374 - String content = field.getText();  
375 - if (!content.equals(lastContent)) {  
376 - if (content.length() >= 2) {  
377 - lastContent = content;  
378 - comboBox.removeAllItems();  
379 - try {  
380 - for (String s : EpnTapGet.getTargetNames(content)) {  
381 - comboBox.addItem(s);  
382 - }  
383 - } catch (CantSendQueryException e) {  
384 - ParamField.logger.log(Level.WARNING,  
385 - "Can't get table names for the resolver", e);  
386 - }  
387 - comboBox.getEditor().setItem(content);  
388 - comboBox.showPopup();  
389 - }  
390 - if (content.isEmpty()) {  
391 - viewListener.onParameterRemoved(paramName);  
392 - } else {  
393 - viewListener.onParameterChanged(paramName, content);  
394 - }  
395 - }  
396 - }  
397 - };  
398 -  
399 -  
400 - /**  
401 - * Method constructor  
402 - *  
403 - * @param mainView The main view of the application.  
404 - * @param paramName The name of the parameter.  
405 - */  
406 - public TargetNameField(ViewListener viewListener, String paramName) {  
407 - super(viewListener, paramName);  
408 - comboBox = new JComboBox<>();  
409 - comboBox.setPreferredSize(  
410 - new Dimension(ParamField.MIN_FIELD_WIDTH, ParamField.FIELD_HEIGHT));  
411 -  
412 - comboBox.setEditable(true);  
413 - field = (JTextField) comboBox.getEditor().getEditorComponent();  
414 - ParamField.addChangeListener(this, field);  
415 - this.add(comboBox);  
416 - }  
417 -  
418 - /**  
419 - * This method is called each time the field is modified.  
420 - */  
421 - @Override  
422 - public void update(JTextField textField) {  
423 - SwingUtilities.invokeLater(updateComboBox);  
424 - }  
425 - }  
426 -  
427 - /**  
428 - * The data product type field is used only for the `dataproduct_type` parameter. It is a  
429 - * ComboBox filled with a list of static data product types (see  
430 - * https://voparis-confluence.obspm.fr/display/VES/4+-+EPN-TAP+queries#id-4-EPN-TAPqueries-  
431 - * __RefHeading__35_312326667_Toc3037660444.2.4DataProductType). The parameter is sent to the  
432 - * controller each time it is updated.  
433 - *  
434 - * @author N. Jourdane  
435 - */  
436 - public static class DataProductTypeField extends ParamField {  
437 -  
438 - /** The serial version UID. */  
439 - private static final long serialVersionUID = 1L;  
440 -  
441 - /** The comboBox used to select the data product type. */  
442 - JComboBox<DataProductType> comboBox;  
443 -  
444 -  
445 - /**  
446 - * An enumeration of all available data product types. Each values comes with an id because  
447 - * EPN-TAP table can possibly be filled with the id instead of the name, so the query have  
448 - * to ask for both of them.  
449 - *  
450 - * @author N. Jourdane  
451 - */  
452 - @SuppressWarnings("javadoc")  
453 - enum DataProductType {  
454 - // @noformat  
455 - ALL("All", "all"), IM("Image", "im"), SP("Spectrum", "sp"),  
456 - DS("Dynamic spectrum", "ds"), SC("Spectral cube", "sc"), PR("Profile", "pr"),  
457 - VO("Volume", "vo"), MO("Movie", "mo"), CU("Cube", "cu"),  
458 - TS("Time series", "ts"), CA("Catalog", "ca"), SV("Spatial vector", "sv");  
459 - // @format  
460 -  
461 - /** The full name of the data product type, such as `Dynamic spectrum`. */  
462 - private String name = "";  
463 -  
464 - /** The id of the data product type, such as `ds`. */  
465 - private String id = "";  
466 -  
467 -  
468 - /**  
469 - * Method constructor for the enumeration.  
470 - *  
471 - * @param name The full name of the data product type, such as `Dynamic spectrum`.  
472 - * @param id The id of the data product type, such as `ds`.  
473 - */  
474 - DataProductType(String name, String id) {  
475 - this.name = name;  
476 - this.id = id;  
477 - }  
478 -  
479 - /**  
480 - * @return A list of two strings, containing the name (formated for the query) and the  
481 - * id, used in the query. A list is used instead of a array because the getQuery  
482 - * function ( @see Queries) needs to know the parameter type.  
483 - */  
484 - public List<String> query() {  
485 - List<String> item = new ArrayList<>();  
486 - item.add(name.replace(" ", "-").toLowerCase());  
487 - item.add(id);  
488 - return item;  
489 - }  
490 -  
491 - @Override  
492 - public String toString() {  
493 - return name;  
494 - }  
495 - }  
496 -  
497 -  
498 - /**  
499 - * Method constructor  
500 - *  
501 - * @param mainView The main view of the application.  
502 - * @param paramName The name of the parameter.  
503 - */  
504 - public DataProductTypeField(ViewListener viewListener, String paramName) {  
505 - super(viewListener, paramName);  
506 - comboBox = new JComboBox<>(DataProductType.values());  
507 - comboBox.setSelectedItem(DataProductType.ALL);  
508 - comboBox.setPreferredSize(  
509 - new Dimension(ParamField.MIN_FIELD_WIDTH, ParamField.FIELD_HEIGHT));  
510 - comboBox.addActionListener(new ActionListener() {  
511 -  
512 - @Override  
513 - public void actionPerformed(ActionEvent e) {  
514 - update();  
515 - }  
516 - });  
517 - this.add(comboBox);  
518 - }  
519 -  
520 - /**  
521 - * This method is called each time the field is modified.  
522 - */  
523 - void update() {  
524 - DataProductType item = (DataProductType) comboBox.getSelectedItem();  
525 - if (DataProductType.ALL.equals(item)) {  
526 - viewListener.onParameterRemoved(paramName);  
527 - } else {  
528 - viewListener.onParameterChanged(paramName, item.query());  
529 - }  
530 - }  
531 - }  
532 -  
533 - /**  
534 - * The target class field is used only for the `target_class` parameter. It is a ComboBox filled  
535 - * with a list of static target classes (see  
536 - * https://voparis-confluence.obspm.fr/display/VES/4+-+EPN-TAP+queries#id-4-EPN-TAPqueries-  
537 - * __RefHeading__39_312326667_Toc3037660464.2.6TargetClass). The parameter is sent to the  
538 - * controller each time it is updated.  
539 - *  
540 - * @author N. Jourdane  
541 - */  
542 - public static class TargetClassField extends ParamField {  
543 -  
544 - /** The serial version UID. */  
545 - private static final long serialVersionUID = 1L;  
546 -  
547 - /** The comboBox used to select the target class. */  
548 - JComboBox<TargetClass> comboBox;  
549 -  
550 -  
551 - /**  
552 - * An enumeration of all available target classes.  
553 - *  
554 - * @author N. Jourdane  
555 - */  
556 - @SuppressWarnings("javadoc")  
557 - enum TargetClass {  
558 - // @noformat  
559 - ALL("All"), COMET("Comet"), EXOPLANET("Exoplanet"), RING("Ring"),  
560 - SAMPLE("Sample"), SKY("Sky"), SPACECRAFT("Spacecraft"), SPACEJUNK("Spacejunk"),  
561 - STAR("Star"), INTERPLANETARY_MEDIUM("Interplanetary medium");  
562 - // @format  
563 -  
564 - /** The name of the target class. */  
565 - String name;  
566 -  
567 -  
568 - /**  
569 - * Method constructor for the enumeration.  
570 - *  
571 - * @param name The name of the target class.  
572 - */  
573 - TargetClass(String name) {  
574 - this.name = name;  
575 - }  
576 -  
577 - /**  
578 - * @return The name formated for the query.  
579 - */  
580 - String query() {  
581 - return name.replace(" ", "_").toLowerCase();  
582 - }  
583 - }  
584 -  
585 -  
586 - /**  
587 - * Method constructor  
588 - *  
589 - * @param mainView The main view of the application.  
590 - * @param paramName The name of the parameter.  
591 - */  
592 - public TargetClassField(ViewListener viewListener, String paramName) {  
593 - super(viewListener, paramName);  
594 - comboBox = new JComboBox<>(TargetClass.values());  
595 - comboBox.setPreferredSize(  
596 - new Dimension(ParamField.MIN_FIELD_WIDTH, ParamField.FIELD_HEIGHT));  
597 - comboBox.addActionListener(new ActionListener() {  
598 -  
599 - @Override  
600 - public void actionPerformed(ActionEvent e) {  
601 - update();  
602 - }  
603 - });  
604 - this.add(comboBox);  
605 - }  
606 -  
607 - /**  
608 - * This method is called each time the field is modified.  
609 - */  
610 - void update() {  
611 - TargetClass value = (TargetClass) comboBox.getSelectedItem();  
612 - if (TargetClass.ALL.equals(value)) {  
613 - viewListener.onParameterRemoved(paramName);  
614 - } else {  
615 - viewListener.onParameterChanged(paramName, value.query());  
616 - }  
617 - }  
618 - }  
619 -  
620 - /**  
621 - * The listener of text field, it aims to provide a simple way to listen a text field without to  
622 - * override removeUpdate(DocumentEvent de), insertUpdate(DocumentEvent de) and  
623 - * changedUpdate(DocumentEvent de) on each field to listen.  
624 - *  
625 - * @author N. Jourdane  
626 - */  
627 - interface TextFieldListener {  
628 -  
629 - /**  
630 - * When the content of the JTextField is updated.  
631 - *  
632 - * @param field The JTextField. Is useful for classes containing several text fields, such  
633 - * as DateRangeField, to know which one triggered the event.  
634 - */  
635 - void update(JTextField field);  
636 - }  
637 -  
638 -  
639 - /**  
640 - * To add the listener. @see TextFieldListener  
641 - *  
642 - * @param changeListener The listener of text fields.  
643 - * @param field The field to listen.  
644 - */  
645 - static void addChangeListener(final TextFieldListener changeListener, final JTextField field) {  
646 - field.getDocument().addDocumentListener(new DocumentListener() {  
647 -  
648 - @Override  
649 - public void removeUpdate(DocumentEvent de) {  
650 - changeListener.update(field);  
651 - }  
652 -  
653 - @Override  
654 - public void insertUpdate(DocumentEvent de) {  
655 - changeListener.update(field);  
656 - }  
657 -  
658 - @Override  
659 - public void changedUpdate(DocumentEvent de) {  
660 - changeListener.update(field);  
661 - }  
662 - });  
663 - }  
664 -}  
665 \ No newline at end of file 0 \ No newline at end of file
src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelView.java
@@ -30,10 +30,11 @@ import javax.swing.JPanel; @@ -30,10 +30,11 @@ import javax.swing.JPanel;
30 import javax.swing.JTextArea; 30 import javax.swing.JTextArea;
31 31
32 import eu.omp.irap.vespa.epntapclient.gui.mainPanel.ViewListener; 32 import eu.omp.irap.vespa.epntapclient.gui.mainPanel.ViewListener;
33 -import eu.omp.irap.vespa.epntapclient.gui.requestpanel.ParamField.DataProductTypeField;  
34 -import eu.omp.irap.vespa.epntapclient.gui.requestpanel.ParamField.DateRangeField;  
35 -import eu.omp.irap.vespa.epntapclient.gui.requestpanel.ParamField.FloatRangeField;  
36 -import eu.omp.irap.vespa.epntapclient.gui.requestpanel.ParamField.TargetNameField; 33 +import eu.omp.irap.vespa.epntapclient.gui.requestpanel.paramfield.DataProductTypeField;
  34 +import eu.omp.irap.vespa.epntapclient.gui.requestpanel.paramfield.DateRangeField;
  35 +import eu.omp.irap.vespa.epntapclient.gui.requestpanel.paramfield.FloatRangeField;
  36 +import eu.omp.irap.vespa.epntapclient.gui.requestpanel.paramfield.ParamField;
  37 +import eu.omp.irap.vespa.epntapclient.gui.requestpanel.paramfield.TargetNameField;
37 38
38 /** 39 /**
39 * The view of the panel where the user builds the query. 40 * The view of the panel where the user builds the query.
src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/DataProductTypeField.java 0 → 100644
@@ -0,0 +1,136 @@ @@ -0,0 +1,136 @@
  1 +/*
  2 + * This file is a part of EpnTAPClient.
  3 + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer.
  4 + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861
  5 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie.
  6 + *
  7 + * This program is free software: you can
  8 + * redistribute it and/or modify it under the terms of the GNU General Public License as published
  9 + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later
  10 + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
  11 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12 + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of
  13 + * the GNU General Public License along with this program. If not, see
  14 + * <http://www.gnu.org/licenses/>.
  15 + */
  16 +
  17 +package eu.omp.irap.vespa.epntapclient.gui.requestpanel.paramfield;
  18 +
  19 +import java.awt.Dimension;
  20 +import java.awt.event.ActionEvent;
  21 +import java.awt.event.ActionListener;
  22 +import java.util.ArrayList;
  23 +import java.util.List;
  24 +
  25 +import javax.swing.JComboBox;
  26 +
  27 +import eu.omp.irap.vespa.epntapclient.gui.mainPanel.ViewListener;
  28 +
  29 +/**
  30 + * The data product type field is used only for the `dataproduct_type` parameter. It is a ComboBox
  31 + * filled with a list of static data product types (see
  32 + * https://voparis-confluence.obspm.fr/display/VES/4+-+EPN-TAP+queries#id-4-EPN-TAPqueries-
  33 + * __RefHeading__35_312326667_Toc3037660444.2.4DataProductType). The parameter is sent to the
  34 + * controller each time it is updated.
  35 + *
  36 + * @author N. Jourdane
  37 + */
  38 +public class DataProductTypeField extends ParamField {
  39 +
  40 + /** The serial version UID. */
  41 + private static final long serialVersionUID = 1L;
  42 +
  43 + /** The comboBox used to select the data product type. */
  44 + JComboBox<DataProductType> comboBox;
  45 +
  46 +
  47 + /**
  48 + * Method constructor
  49 + *
  50 + * @param mainView The main view of the application.
  51 + * @param paramName The name of the parameter.
  52 + */
  53 + public DataProductTypeField(ViewListener viewListener, String paramName) {
  54 + super(viewListener, paramName);
  55 + comboBox = new JComboBox<>(DataProductType.values());
  56 + comboBox.setSelectedItem(DataProductType.ALL);
  57 + comboBox.setPreferredSize(
  58 + new Dimension(ParamField.MIN_FIELD_WIDTH, ParamField.FIELD_HEIGHT));
  59 +
  60 + comboBox.addActionListener(new ActionListener() {
  61 +
  62 + @Override
  63 + public void actionPerformed(ActionEvent e) {
  64 + update();
  65 + }
  66 + });
  67 +
  68 + this.add(comboBox);
  69 + }
  70 +
  71 + /**
  72 + * This method is called each time the field is modified.
  73 + */
  74 + public void update() {
  75 + DataProductType item = (DataProductType) comboBox.getSelectedItem();
  76 + if (DataProductType.ALL.equals(item)) {
  77 + viewListener.onParameterRemoved(paramName);
  78 + } else {
  79 + viewListener.onParameterChanged(paramName, item.query());
  80 + }
  81 + }
  82 +
  83 +
  84 + /**
  85 + * An enumeration of all available data product types. Each values comes with an id because
  86 + * EPN-TAP table can possibly be filled with the id instead of the name, so the query have to
  87 + * ask for both of them.
  88 + *
  89 + * @author N. Jourdane
  90 + */
  91 + @SuppressWarnings("javadoc")
  92 + enum DataProductType {
  93 + // @noformat
  94 + ALL("All", "all"), IM("Image", "im"), SP("Spectrum", "sp"),
  95 + DS("Dynamic spectrum", "ds"), SC("Spectral cube", "sc"), PR("Profile", "pr"),
  96 + VO("Volume", "vo"), MO("Movie", "mo"), CU("Cube", "cu"),
  97 + TS("Time series", "ts"), CA("Catalog", "ca"), SV("Spatial vector", "sv");
  98 + // @format
  99 +
  100 + /** The full name of the data product type, such as `Dynamic spectrum`. */
  101 + private String name = "";
  102 +
  103 + /** The id of the data product type, such as `ds`. */
  104 + private String id = "";
  105 +
  106 +
  107 + /**
  108 + * Method constructor for the enumeration.
  109 + *
  110 + * @param name The full name of the data product type, such as `Dynamic spectrum`.
  111 + * @param id The id of the data product type, such as `ds`.
  112 + */
  113 + DataProductType(String name, String id) {
  114 + this.name = name;
  115 + this.id = id;
  116 + }
  117 +
  118 + /**
  119 + * @return A list of two strings, containing the name (formated for the query) and the id,
  120 + * used in the query. A list is used instead of a array because the getQuery
  121 + * function ( @see Queries) needs to know the parameter type.
  122 + */
  123 + public List<String> query() {
  124 + List<String> item = new ArrayList<>();
  125 + item.add(name.replace(" ", "-").toLowerCase());
  126 + item.add(id);
  127 + return item;
  128 + }
  129 +
  130 + @Override
  131 + public String toString() {
  132 + return name;
  133 + }
  134 + }
  135 +
  136 +}
0 \ No newline at end of file 137 \ No newline at end of file
src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/DateRangeField.java 0 → 100644
@@ -0,0 +1,106 @@ @@ -0,0 +1,106 @@
  1 +/*
  2 + * This file is a part of EpnTAPClient.
  3 + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer.
  4 + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861
  5 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie.
  6 + *
  7 + * This program is free software: you can
  8 + * redistribute it and/or modify it under the terms of the GNU General Public License as published
  9 + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later
  10 + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
  11 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12 + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of
  13 + * the GNU General Public License along with this program. If not, see
  14 + * <http://www.gnu.org/licenses/>.
  15 + */
  16 +
  17 +package eu.omp.irap.vespa.epntapclient.gui.requestpanel.paramfield;
  18 +
  19 +import java.awt.Color;
  20 +import java.awt.Dimension;
  21 +import java.text.DateFormat;
  22 +import java.text.ParseException;
  23 +import java.text.SimpleDateFormat;
  24 +import java.util.Locale;
  25 +
  26 +import javax.swing.JLabel;
  27 +import javax.swing.JTextField;
  28 +
  29 +import eu.omp.irap.vespa.epntapclient.gui.mainPanel.ViewListener;
  30 +
  31 +/**
  32 + * The date range field is used for couples of parameter with both a `Date` type (actually only
  33 + * `time_min` and `time_max` parameters is concerned for now). These are JTextFields which check if
  34 + * the content is a valid date, according to DATE_FORMAT. If the parameter is valid or if it is
  35 + * empty, then the dates value are sent to the controller, in Julian Day format.
  36 + *
  37 + * @author N. Jourdane
  38 + */
  39 +public class DateRangeField extends ParamField implements TextFieldListener {
  40 +
  41 + /** The serial version UID. */
  42 + private static final long serialVersionUID = 1L;
  43 +
  44 + /** The date format used in the DateRange field */
  45 + private static final String DATE_FORMAT = "dd/MM/yyyy";
  46 +
  47 + /** The regex used to validate the Date fields */
  48 + 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)$)";
  49 +
  50 + /** The JTextField used to put the parameter minimum value of the range. */
  51 + JTextField fieldMin;
  52 +
  53 + /** The JTextField used to put the parameter maximum value of the range. */
  54 + JTextField fieldMax;
  55 +
  56 +
  57 + /**
  58 + * Method constructor
  59 + *
  60 + * @param mainView The main view of the application.
  61 + * @param paramName The name of the parameter.
  62 + */
  63 + public DateRangeField(ViewListener viewListener, String paramName) {
  64 + super(viewListener, paramName);
  65 + this.add(new JLabel("min "));
  66 + fieldMin = new JTextField();
  67 + fieldMin.setName(MIN_SUFFIX);
  68 + fieldMin.setPreferredSize(
  69 + new Dimension(MIN_FIELD_WIDTH, FIELD_HEIGHT));
  70 + addChangeListener(this, fieldMin);
  71 + this.add(fieldMin);
  72 +
  73 + this.add(new JLabel("max "));
  74 + fieldMax = new JTextField();
  75 + fieldMax.setName(MAX_SUFFIX);
  76 + fieldMax.setPreferredSize(
  77 + new Dimension(MIN_FIELD_WIDTH, FIELD_HEIGHT));
  78 + addChangeListener(this, fieldMin);
  79 + this.add(fieldMax);
  80 + }
  81 +
  82 + /**
  83 + * This method is called each time the field is modified.
  84 + */
  85 + @Override
  86 + public void update(JTextField field) {
  87 + DateFormat df = new SimpleDateFormat(DATE_FORMAT, Locale.ENGLISH);
  88 + if (field.getText().isEmpty()) {
  89 + field.setBackground(Color.WHITE);
  90 + viewListener.onParameterRemoved(paramName + field.getName());
  91 + } else if (field.getText().matches(DATE_REGEX)) {
  92 + try {
  93 + long date = df.parse(field.getText()).getTime();
  94 + date = Math.round(date / 86400000.0 + 2440587.5); // to JD
  95 + viewListener.onParameterChanged(paramName + field.getName(),
  96 + date);
  97 + field.setBackground(Color.WHITE);
  98 + } catch (@SuppressWarnings("unused") ParseException e) {
  99 + field.setBackground(Color.PINK);
  100 + }
  101 + // TODO: check if date min < date max
  102 + } else {
  103 + field.setBackground(Color.PINK);
  104 + }
  105 + }
  106 +}
0 \ No newline at end of file 107 \ No newline at end of file
src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/FloatField.java 0 → 100644
@@ -0,0 +1,72 @@ @@ -0,0 +1,72 @@
  1 +/*
  2 + * This file is a part of EpnTAPClient.
  3 + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer.
  4 + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861
  5 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie.
  6 + *
  7 + * This program is free software: you can
  8 + * redistribute it and/or modify it under the terms of the GNU General Public License as published
  9 + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later
  10 + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
  11 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12 + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of
  13 + * the GNU General Public License along with this program. If not, see
  14 + * <http://www.gnu.org/licenses/>.
  15 + */
  16 +
  17 +package eu.omp.irap.vespa.epntapclient.gui.requestpanel.paramfield;
  18 +
  19 +import java.awt.Color;
  20 +
  21 +import javax.swing.JTextField;
  22 +
  23 +import eu.omp.irap.vespa.epntapclient.gui.mainPanel.ViewListener;
  24 +
  25 +/**
  26 + * The float field is used for parameter with a `Float` class. It is a JTextField which checks if
  27 + * the content is a valid float. If the parameter is valid or if it is empty, then the float value
  28 + * is sent to the controller.
  29 + *
  30 + * @author N. Jourdane
  31 + */
  32 +public class FloatField extends ParamField implements TextFieldListener {
  33 +
  34 + /** The serial version UID. */
  35 + private static final long serialVersionUID = 1L;
  36 +
  37 + /** The JTextField used to put the parameter value. */
  38 + JTextField field;
  39 +
  40 +
  41 + /**
  42 + * Method constructor
  43 + *
  44 + * @param mainView The main view of the application.
  45 + * @param paramName The name of the parameter.
  46 + */
  47 + public FloatField(ViewListener viewListener, String paramName) {
  48 + super(viewListener, paramName);
  49 + field = new JTextField();
  50 + ParamField.addChangeListener(this, field);
  51 + this.add(field);
  52 + }
  53 +
  54 + /**
  55 + * This method is called each time the field is modified.
  56 + */
  57 + @Override
  58 + public void update(JTextField textField) {
  59 + if (textField.getText().isEmpty()) {
  60 + textField.setBackground(Color.WHITE);
  61 + viewListener.onParameterRemoved(paramName);
  62 + } else {
  63 + try {
  64 + float value = Float.parseFloat(textField.getText());
  65 + viewListener.onParameterChanged(paramName, value);
  66 + textField.setBackground(Color.WHITE);
  67 + } catch (@SuppressWarnings("unused") NumberFormatException e) {
  68 + textField.setBackground(Color.PINK);
  69 + }
  70 + }
  71 + }
  72 +}
0 \ No newline at end of file 73 \ No newline at end of file
src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/FloatRangeField.java 0 → 100644
@@ -0,0 +1,81 @@ @@ -0,0 +1,81 @@
  1 +/*
  2 + * This file is a part of EpnTAPClient.
  3 + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer.
  4 + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861
  5 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie.
  6 + *
  7 + * This program is free software: you can
  8 + * redistribute it and/or modify it under the terms of the GNU General Public License as published
  9 + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later
  10 + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
  11 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12 + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of
  13 + * the GNU General Public License along with this program. If not, see
  14 + * <http://www.gnu.org/licenses/>.
  15 + */
  16 +
  17 +package eu.omp.irap.vespa.epntapclient.gui.requestpanel.paramfield;
  18 +
  19 +import java.awt.Color;
  20 +
  21 +import javax.swing.JTextField;
  22 +
  23 +import eu.omp.irap.vespa.epntapclient.gui.mainPanel.ViewListener;
  24 +
  25 +/**
  26 + * The float range field is used for couples of parameter with both a `Float` class. These are
  27 + * JTextFields which check if the content is a valid float. If the parameter is valid or if it is
  28 + * empty, then the float value are sent to the controller.
  29 + *
  30 + * @author N. Jourdane
  31 + */
  32 +public class FloatRangeField extends ParamField implements TextFieldListener {
  33 +
  34 + /** The serial version UID. */
  35 + private static final long serialVersionUID = 1L;
  36 +
  37 + /** The JTextField used to put the parameter minimum value of the range. */
  38 + JTextField fieldMin;
  39 +
  40 + /** The JTextField used to put the parameter maximum value of the range. */
  41 + JTextField fieldMax;
  42 +
  43 +
  44 + /**
  45 + * Method constructor
  46 + *
  47 + * @param mainView The main view of the application.
  48 + * @param paramName The name of the parameter.
  49 + */
  50 + public FloatRangeField(ViewListener viewListener, String paramName) {
  51 + super(viewListener, paramName);
  52 + fieldMin = new JTextField();
  53 + fieldMin.setName(ParamField.MIN_SUFFIX);
  54 + ParamField.addChangeListener(this, fieldMin);
  55 + this.add(fieldMin);
  56 +
  57 + fieldMax = new JTextField();
  58 + fieldMax.setName(ParamField.MAX_SUFFIX);
  59 + ParamField.addChangeListener(this, fieldMax);
  60 + this.add(fieldMax);
  61 + }
  62 +
  63 + /**
  64 + * This method is called each time the field is modified.
  65 + */
  66 + @Override
  67 + public void update(JTextField field) {
  68 + if (field.getText().isEmpty()) {
  69 + field.setBackground(Color.WHITE);
  70 + viewListener.onParameterRemoved(paramName + field.getName());
  71 + } else {
  72 + try {
  73 + viewListener.onParameterChanged(paramName + field.getName(),
  74 + Float.parseFloat(field.getText()));
  75 + field.setBackground(Color.WHITE);
  76 + } catch (@SuppressWarnings("unused") NumberFormatException e) {
  77 + field.setBackground(Color.PINK);
  78 + }
  79 + }
  80 + }
  81 +}
0 \ No newline at end of file 82 \ No newline at end of file
src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/ParamField.java 0 → 100644
@@ -0,0 +1,127 @@ @@ -0,0 +1,127 @@
  1 +/*
  2 + * This file is a part of EpnTAPClient.
  3 + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer.
  4 + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861
  5 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie.
  6 + *
  7 + * This program is free software: you can
  8 + * redistribute it and/or modify it under the terms of the GNU General Public License as published
  9 + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later
  10 + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
  11 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12 + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of
  13 + * the GNU General Public License along with this program. If not, see
  14 + * <http://www.gnu.org/licenses/>.
  15 + */
  16 +
  17 +package eu.omp.irap.vespa.epntapclient.gui.requestpanel.paramfield;
  18 +
  19 +import java.awt.Dimension;
  20 +import java.util.logging.Logger;
  21 +
  22 +import javax.swing.BoxLayout;
  23 +import javax.swing.JLabel;
  24 +import javax.swing.JPanel;
  25 +import javax.swing.JTextField;
  26 +import javax.swing.event.DocumentEvent;
  27 +import javax.swing.event.DocumentListener;
  28 +
  29 +import eu.omp.irap.vespa.epntapclient.gui.mainPanel.ViewListener;
  30 +
  31 +/**
  32 + * A field used to set a service parameter to build the query (in the parameter panel). ParamField
  33 + * is an abstract method and all type of parameter field should extend it. See
  34 + * https://voparis-confluence.obspm.fr/display/VES/4+-+EPN-TAP+queries to get all parameters
  35 + * details.
  36 + *
  37 + * @author N. Jourdane
  38 + */
  39 +public abstract class ParamField extends JPanel {
  40 +
  41 + /** The serial version UID. */
  42 + private static final long serialVersionUID = 1L;
  43 +
  44 + /** The logger for the class ParamField. */
  45 + static final Logger logger = Logger.getLogger(ParamField.class.getName());
  46 +
  47 + /** The minimum width of the field. */
  48 + static final int MIN_FIELD_WIDTH = 30;
  49 +
  50 + /** The preferred field height. */
  51 + static final int FIELD_HEIGHT = 20;
  52 +
  53 + /** The maximum width of the field. */
  54 + static final int MAX_FIELD_WIDTH = 400;
  55 +
  56 + /** The preferred label width. */
  57 + static final int LABEL_WIDTH = 140;
  58 +
  59 + /** The suffix used in REG-TAP parameters names, indicating that it's a beginning of a range. */
  60 + static final String MIN_SUFFIX = "min";
  61 +
  62 + /** The suffix used in REG-TAP parameters names, indicating that it is a end of a range. */
  63 + static final String MAX_SUFFIX = "max";
  64 +
  65 + /** The main view of the application. */
  66 + ViewListener viewListener;
  67 +
  68 + /** The parameter name of the field */
  69 + String paramName;
  70 +
  71 +
  72 + /**
  73 + * Method constructor for the parameter field abstract class, which do all common action for all
  74 + * type of field, such as displaying the name of the parameter.
  75 + *
  76 + * @param mainView The main view of the application.
  77 + * @param paramName The name of the parameter.
  78 + */
  79 + public ParamField(ViewListener viewListener, String paramName) {
  80 + super();
  81 +
  82 + this.viewListener = viewListener;
  83 + this.paramName = paramName;
  84 +
  85 + buildParamField();
  86 + }
  87 +
  88 + private void buildParamField() {
  89 + setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
  90 +
  91 + setMaximumSize(new Dimension(ParamField.MAX_FIELD_WIDTH, ParamField.FIELD_HEIGHT));
  92 +
  93 + String strLabel = paramName.replaceAll("_", " ").trim();
  94 + JLabel label = new JLabel(strLabel.substring(0, 1).toUpperCase() + strLabel.substring(1));
  95 + label.setPreferredSize(new Dimension(ParamField.LABEL_WIDTH, ParamField.FIELD_HEIGHT));
  96 +
  97 + this.add(label);
  98 + }
  99 +
  100 + /**
  101 + * To add the listener. @see TextFieldListener
  102 + *
  103 + * @param changeListener The listener of text fields.
  104 + * @param field The field to listen.
  105 + */
  106 + static void addChangeListener(final TextFieldListener changeListener, final JTextField field) {
  107 +
  108 + field.getDocument().addDocumentListener(new DocumentListener() {
  109 +
  110 + @Override
  111 + public void removeUpdate(DocumentEvent de) {
  112 + changeListener.update(field);
  113 + }
  114 +
  115 + @Override
  116 + public void insertUpdate(DocumentEvent de) {
  117 + changeListener.update(field);
  118 + }
  119 +
  120 + @Override
  121 + public void changedUpdate(DocumentEvent de) {
  122 + changeListener.update(field);
  123 + }
  124 +
  125 + });
  126 + }
  127 +}
0 \ No newline at end of file 128 \ No newline at end of file
src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/StringField.java 0 → 100644
@@ -0,0 +1,62 @@ @@ -0,0 +1,62 @@
  1 +/*
  2 + * This file is a part of EpnTAPClient.
  3 + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer.
  4 + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861
  5 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie.
  6 + *
  7 + * This program is free software: you can
  8 + * redistribute it and/or modify it under the terms of the GNU General Public License as published
  9 + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later
  10 + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
  11 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12 + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of
  13 + * the GNU General Public License along with this program. If not, see
  14 + * <http://www.gnu.org/licenses/>.
  15 + */
  16 +
  17 +package eu.omp.irap.vespa.epntapclient.gui.requestpanel.paramfield;
  18 +
  19 +import javax.swing.JTextField;
  20 +
  21 +import eu.omp.irap.vespa.epntapclient.gui.mainPanel.ViewListener;
  22 +
  23 +/**
  24 + * The string field is used for parameter with a `String` class. It is a simple JTextField with no
  25 + * verification. The parameter is sent to the controller each time it is modified.
  26 + *
  27 + * @author N. Jourdane
  28 + */
  29 +public class StringField extends ParamField implements TextFieldListener {
  30 +
  31 + /** The serial version UID. */
  32 + private static final long serialVersionUID = 1L;
  33 +
  34 + /** The JTextField used to put the parameter value. */
  35 + JTextField field;
  36 +
  37 +
  38 + /**
  39 + * Method constructor for the string field.
  40 + *
  41 + * @param mainView The main view of the application.
  42 + * @param paramName The name of the parameter.
  43 + */
  44 + public StringField(ViewListener viewListener, String paramName) {
  45 + super(viewListener, paramName);
  46 + field = new JTextField();
  47 + ParamField.addChangeListener(this, field);
  48 + this.add(field);
  49 + }
  50 +
  51 + /**
  52 + * This method is called each time the field is modified.
  53 + */
  54 + @Override
  55 + public void update(JTextField textField) {
  56 + if (textField.getText().isEmpty()) {
  57 + viewListener.onParameterChanged(paramName, null);
  58 + } else {
  59 + viewListener.onParameterChanged(paramName, textField.getText());
  60 + }
  61 + }
  62 +}
0 \ No newline at end of file 63 \ No newline at end of file
src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/TargetClassField.java 0 → 100644
@@ -0,0 +1,113 @@ @@ -0,0 +1,113 @@
  1 +/*
  2 + * This file is a part of EpnTAPClient.
  3 + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer.
  4 + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861
  5 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie.
  6 + *
  7 + * This program is free software: you can
  8 + * redistribute it and/or modify it under the terms of the GNU General Public License as published
  9 + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later
  10 + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
  11 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12 + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of
  13 + * the GNU General Public License along with this program. If not, see
  14 + * <http://www.gnu.org/licenses/>.
  15 + */
  16 +
  17 +package eu.omp.irap.vespa.epntapclient.gui.requestpanel.paramfield;
  18 +
  19 +import java.awt.Dimension;
  20 +import java.awt.event.ActionEvent;
  21 +import java.awt.event.ActionListener;
  22 +
  23 +import javax.swing.JComboBox;
  24 +
  25 +import eu.omp.irap.vespa.epntapclient.gui.mainPanel.ViewListener;
  26 +
  27 +/**
  28 + * The target class field is used only for the `target_class` parameter. It is a ComboBox filled
  29 + * with a list of static target classes (see
  30 + * https://voparis-confluence.obspm.fr/display/VES/4+-+EPN-TAP+queries#id-4-EPN-TAPqueries-
  31 + * __RefHeading__39_312326667_Toc3037660464.2.6TargetClass). The parameter is sent to the controller
  32 + * each time it is updated.
  33 + *
  34 + * @author N. Jourdane
  35 + */
  36 +public class TargetClassField extends ParamField {
  37 +
  38 + /** The serial version UID. */
  39 + private static final long serialVersionUID = 1L;
  40 +
  41 + /** The comboBox used to select the target class. */
  42 + JComboBox<TargetClass> comboBox;
  43 +
  44 +
  45 + /**
  46 + * Method constructor
  47 + *
  48 + * @param mainView The main view of the application.
  49 + * @param paramName The name of the parameter.
  50 + */
  51 + public TargetClassField(ViewListener viewListener, String paramName) {
  52 + super(viewListener, paramName);
  53 + comboBox = new JComboBox<>(TargetClass.values());
  54 + comboBox.setPreferredSize(
  55 + new Dimension(ParamField.MIN_FIELD_WIDTH, ParamField.FIELD_HEIGHT));
  56 + comboBox.addActionListener(new ActionListener() {
  57 +
  58 + @Override
  59 + public void actionPerformed(ActionEvent e) {
  60 + update();
  61 + }
  62 + });
  63 + this.add(comboBox);
  64 + }
  65 +
  66 + /**
  67 + * This method is called each time the field is modified.
  68 + */
  69 + public void update() {
  70 + TargetClass value = (TargetClass) comboBox.getSelectedItem();
  71 + if (TargetClass.ALL.equals(value)) {
  72 + viewListener.onParameterRemoved(paramName);
  73 + } else {
  74 + viewListener.onParameterChanged(paramName, value.query());
  75 + }
  76 + }
  77 +
  78 +
  79 + /**
  80 + * An enumeration of all available target classes.
  81 + *
  82 + * @author N. Jourdane
  83 + */
  84 + @SuppressWarnings("javadoc")
  85 + enum TargetClass {
  86 + // @noformat
  87 + ALL("All"), COMET("Comet"), EXOPLANET("Exoplanet"), RING("Ring"),
  88 + SAMPLE("Sample"), SKY("Sky"), SPACECRAFT("Spacecraft"), SPACEJUNK("Spacejunk"),
  89 + STAR("Star"), INTERPLANETARY_MEDIUM("Interplanetary medium");
  90 + // @format
  91 +
  92 + /** The name of the target class. */
  93 + String name;
  94 +
  95 +
  96 + /**
  97 + * Method constructor for the enumeration.
  98 + *
  99 + * @param name The name of the target class.
  100 + */
  101 + TargetClass(String name) {
  102 + this.name = name;
  103 + }
  104 +
  105 + /**
  106 + * @return The name formated for the query.
  107 + */
  108 + String query() {
  109 + return name.replace(" ", "_").toLowerCase();
  110 + }
  111 + }
  112 +
  113 +}
0 \ No newline at end of file 114 \ No newline at end of file
src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/TargetNameField.java 0 → 100644
@@ -0,0 +1,116 @@ @@ -0,0 +1,116 @@
  1 +/*
  2 + * This file is a part of EpnTAPClient.
  3 + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer.
  4 + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861
  5 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie.
  6 + *
  7 + * This program is free software: you can
  8 + * redistribute it and/or modify it under the terms of the GNU General Public License as published
  9 + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later
  10 + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
  11 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12 + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of
  13 + * the GNU General Public License along with this program. If not, see
  14 + * <http://www.gnu.org/licenses/>.
  15 + */
  16 +
  17 +package eu.omp.irap.vespa.epntapclient.gui.requestpanel.paramfield;
  18 +
  19 +import java.awt.Dimension;
  20 +import java.util.logging.Level;
  21 +
  22 +import javax.swing.JComboBox;
  23 +import javax.swing.JTextField;
  24 +import javax.swing.SwingUtilities;
  25 +
  26 +import eu.omp.irap.vespa.epntapclient.EpnTapGet;
  27 +import eu.omp.irap.vespa.epntapclient.gui.mainPanel.ViewListener;
  28 +import eu.omp.irap.vespa.votable.utils.CantSendQueryException;
  29 +
  30 +/**
  31 + * The target name field is used only for the `target_name` parameter. It is a ComboBox which is
  32 + * automatically filled with actual target names which begins by the entered characters, by asking
  33 + * to an online resolver (RESOLVER_URL). The parameter is sent to the controller each time it is
  34 + * updated, so it is possible to enter a parameter that the resolver do not know.
  35 + *
  36 + * @author N. Jourdane
  37 + */
  38 +public class TargetNameField extends ParamField implements TextFieldListener {
  39 +
  40 + /** The serial version UID. */
  41 + private static final long serialVersionUID = 1L;
  42 +
  43 + /** The comboBox to enter the target_name and display target name propositions. */
  44 + JComboBox<String> comboBox;
  45 +
  46 + /** The JTextField related to the ComboBox, allowing to listen for text content update. */
  47 + JTextField field;
  48 +
  49 + /**
  50 + * The content of the last entered value. It is used to avoid recursions, because each time an
  51 + * update event is detected, the resolver is called and the ComboBox is filled with new values,
  52 + * which trigger a new event.
  53 + */
  54 + String lastContent;
  55 +
  56 +
  57 + /**
  58 + * Method constructor
  59 + *
  60 + * @param mainView The main view of the application.
  61 + * @param paramName The name of the parameter.
  62 + */
  63 + public TargetNameField(ViewListener viewListener, String paramName) {
  64 + super(viewListener, paramName);
  65 + comboBox = new JComboBox<>();
  66 + comboBox.setPreferredSize(
  67 + new Dimension(ParamField.MIN_FIELD_WIDTH, ParamField.FIELD_HEIGHT));
  68 +
  69 + comboBox.setEditable(true);
  70 + field = (JTextField) comboBox.getEditor().getEditorComponent();
  71 + ParamField.addChangeListener(this, field);
  72 + this.add(comboBox);
  73 + }
  74 +
  75 + /**
  76 + * This method is called each time the field is modified.
  77 + */
  78 + @Override
  79 + public void update(JTextField textField) {
  80 + SwingUtilities.invokeLater(updateComboBox);
  81 + }
  82 +
  83 +
  84 + /**
  85 + * This method is called each time the field is modified. A Runnable is used it is impossible to
  86 + * modify the comboBox from a DocumentEvent.
  87 + */
  88 + Runnable updateComboBox = new Runnable() {
  89 +
  90 + @Override
  91 + public void run() {
  92 + String content = field.getText();
  93 + if (!content.equals(lastContent)) {
  94 + if (content.length() >= 2) {
  95 + lastContent = content;
  96 + comboBox.removeAllItems();
  97 + try {
  98 + for (String s : EpnTapGet.getTargetNames(content)) {
  99 + comboBox.addItem(s);
  100 + }
  101 + } catch (CantSendQueryException e) {
  102 + ParamField.logger.log(Level.WARNING,
  103 + "Can't get table names for the resolver", e);
  104 + }
  105 + comboBox.getEditor().setItem(content);
  106 + comboBox.showPopup();
  107 + }
  108 + if (content.isEmpty()) {
  109 + viewListener.onParameterRemoved(paramName);
  110 + } else {
  111 + viewListener.onParameterChanged(paramName, content);
  112 + }
  113 + }
  114 + }
  115 + };
  116 +}
0 \ No newline at end of file 117 \ No newline at end of file
src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/TextFieldListener.java 0 → 100644
@@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
  1 +/*
  2 + * This file is a part of EpnTAPClient.
  3 + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer.
  4 + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861
  5 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie.
  6 + *
  7 + * This program is free software: you can
  8 + * redistribute it and/or modify it under the terms of the GNU General Public License as published
  9 + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later
  10 + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
  11 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12 + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of
  13 + * the GNU General Public License along with this program. If not, see
  14 + * <http://www.gnu.org/licenses/>.
  15 + */
  16 +
  17 +package eu.omp.irap.vespa.epntapclient.gui.requestpanel.paramfield;
  18 +
  19 +import javax.swing.JTextField;
  20 +
  21 +/**
  22 + * The listener of text field, it aims to provide a simple way to listen a text field without to
  23 + * override removeUpdate(DocumentEvent de), insertUpdate(DocumentEvent de) and
  24 + * changedUpdate(DocumentEvent de) on each field to listen.
  25 + *
  26 + * @author N. Jourdane
  27 + */
  28 +interface TextFieldListener {
  29 +
  30 + /**
  31 + * When the content of the JTextField is updated.
  32 + *
  33 + * @param field The JTextField. Is useful for classes containing several text fields, such as
  34 + * DateRangeField, to know which one triggered the event.
  35 + */
  36 + void update(JTextField field);
  37 +}
0 \ No newline at end of file 38 \ No newline at end of file