-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLineSearchPanel.java
More file actions
2997 lines (2612 loc) · 103 KB
/
Copy pathLineSearchPanel.java
File metadata and controls
2997 lines (2612 loc) · 103 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* $Id $
*
* Copyright (c) 2006
* Sergio Martin Ruiz, Madrid, Spain
*/
package es.smr.slim;
import herschel.share.unit.Speed;
import herschel.share.unit.Unit;
import ij.IJ;
import ij.Prefs;
import ij.WindowManager;
import ij.io.OpenDialog;
import javax.swing.*;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import javax.swing.filechooser.FileFilter;
import es.cab.astronomical.AstronomicalChangeUnit;
import es.cab.astronomical.AstronomicalImagePlus;
import es.cab.astronomical.AstronomicalPlotWindow;
import es.cab.astronomical.components.AstronomicalJFrameMASSA;
import es.cab.astronomical.components.AstronomicalJTableMASSA;
import es.cab.astronomical.utils.AstronomicalFunctionsGenerics;
import es.cab.madcuba.log.Log;
import es.cab.madcuba.tools.PropertiesLastConfig;
import es.cab.madcuba.utils.MyConstants;
import es.cab.madcuba.utils.MyUtilities;
import es.cab.plugins.ListPluginsNames;
import es.cab.plugins.SynchronizeCubePlugin;
import es.cab.swing.gui.EditorInformationMADCUBA;
import es.smr.slim.beans.SearchSlimParams;
import es.smr.slim.components.PanelListMolecules;
import es.smr.slim.components.qnlte.SimFitCollisionMoleculePanel;
import es.smr.slim.components.qnlte.SimFitSourceParametersPanel;
import es.smr.slim.plugins.ListPluginsNamesSlim;
import es.smr.slim.plugins.SLIMFRAME;
import es.smr.slim.plugins.SLIMSearch;
import es.smr.slim.utils.SlimConstants;
import es.smr.slim.utils.SlimUtilities;
import es.smr.slim.utils.SlimUtilitiesFiles;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.Dimension;
import java.io.File;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* Class creating the GUI to access the database.<br>
* This class allows:<br>
* - Catalog Selection<br>
* - Frequency/Wavelenght search constraint<br>
* - Additional selection criteria for each particular catalog
*
* @author Sergio Martin Ruiz
*
*/
@SuppressWarnings("serial")
public class LineSearchPanel extends JPanel implements KeyListener {
public static final String SELECTED_DATA = "selected_data";
public static final String SELECTED_WINDOW = "selected_window";
public static final String SELECTED_WHOLE_RANGE = "whole";
public static final String CUBE_CONTAINER = "cube_container";
private static final String COMBO_HZMM_GENERATE = "HzmmGenerate";
private static final String COMBO_HZMM_CRITERIA = "HzmmCriteria";
public static final int RANGE_USER_DEFINED = 2;
public static final int RANGE_WINDOW = 1;
public static final int RANGE_WHOLE_FREQ = 3;
/*
* Creates a LineSearchResults Window Invisible until Search Button is pressed
*/
public LineSearchResultsDialog dialogResults;
private int panelWidth = 850;
/*
* The Database Object and the Array of ResultSets
*/
private static DbHSQLDBCreate db = null;
protected static Log _log = Log.getInstance();
// CONSTANST
/*
* Panels defined: - Search Button - Catalog Selection Panel - Frequency
* Selection Panel - Criteria Panel
*/
private JButton bOKJPL = null;
private JButton bOKRecom = null;
/*
* private JButton bLineSearch = new JButton(); private JButton bClearSearch =
* new JButton(); private JRadioButton radioNew = new JRadioButton("New");
* private JRadioButton radioAddCurrent = new JRadioButton("Add Current");
* private JPanel jPanelUpperButtons = new JPanel();
*/
private JPanel jPanelFrequency = new JPanel();
private JPanel jPanelCriteria = new JPanel();
private JPanel jPanelCriteriaDefault = null;
private JPanel jPanelCriteriaJPLCDMS = null;
private JPanel jPanelCriteriaRECOMB = null;
private JPanel jPanelGenerateSpectra = new JPanel();
private SimFitCollisionMoleculePanel jPanelCollisionMolecule = null;
private SimFitSourceParametersPanel jPanelParametersSource = null;
/*
* Definition of components of Panel Catalog
*/
private static PanelListMolecules jpListMolecules = null;// new PanelListMolecules();
/*
* Definition of components of Panel Frequency
*/
private JPanel jpRangeCriteria = new JPanel();
private JPanel jpGenerateSpectraCriteria1 = new JPanel();
private JPanel jpGenerateSpectraCriteria2 = new JPanel();
private JPanel jpGenerateSpectraCriteria3 = new JPanel();
private static JComboBox selectTypeRange = new JComboBox();
// private static JCheckBox checkBoxFreq = new JCheckBox("Auto", true);
// private static JCheckBox checkBoxWindow = new JCheckBox("Window", false);
private static JTextField tfBoxNoise = new JTextField(3);
private static JComboBox cBoxNuLambda = new JComboBox();
private static JComboBox cBoxNuLambdaGenerateSpectra = new JComboBox();
// private static JLabel lVeloSpectral = new JLabel("");
private static JLabel lFreqMin = new JLabel("From");
private static JLabel lFreqMax = new JLabel("To");
private static JTextField tfFreqMin = new JTextField(5);
private static JTextField tfFreqMax = new JTextField(5);
private static JTextField tfFreqMinGenerate = new JTextField(5);
private static JTextField tfFreqMaxGenerate = new JTextField(5);
private static JLabel lResolution = new JLabel("LineWidth");
// private static JTextField tfResolutionMin = new JTextField(5);
// private static JTextField tfResolutionMax = new JTextField(5);
private static JTextField tfLineWidth = new JTextField(5);
// private static JLabel lRestFrequency = new JLabel("Rest.Freq/Wave");
//private static JTextField tfRestFrequency = new JTextField(5);
private static JLabel lBeamSize = new JLabel("Beam Size");
private static JTextField tfBeamSize = new JTextField(3);
private JComboBox cBoxHzmm = new JComboBox();
private JComboBox cBoxHzmmGenerateSpectra = new JComboBox();
private JComboBox cBoxVelocityGenerateSpectra = new JComboBox(new String[] { "m/s", "km/s" });
private int cBoxNuLambdaSelected;
private int cBoxHzmmSelected;
private int cBoxNuLambdaGenerateSelected;
private int cBoxHzmmGenerateSelected;
private JComboBox cBoxUnitsIntesity = new JComboBox(new String[] { "K", "Jy" });
private JComboBox cBoxTempscalIntensity = new JComboBox(new String[] { "TMB", "TA*" });
private final String[] arrayHz = new String[] { "THz", "GHz", "MHz", "Hz" };
private final double[] arrayHzFactor = new double[] { 1000000, 1000, 1, 0.000001 };
private final int FREQ_DEFAULT_COMBO = 2; // Default scale of Frequency
private final int FREQ_HZ_POS_COMBO = 3; // Where Hz is the array arrayHz (used for conversions)
private final int FREQ_MHZ = 2;
private final String[] arrayMm = new String[] { "cm", "mm", "\u03BCm", "nm", "\u00C5" };
private final double[] arrayMmFactor = new double[] { 10000, 1000, 1, 0.001, 0.0001 };
private final int WAVE_DEFAULT_COMBO = 1; // Default scale of Wavelenght
private final int WAVE_CM_POS_COMBO = 0; // Where cm is in the array arrayMm (used for conversions)
private final int WAVE_MM_DEFAULT = 1;
/*
* Definition of components of Panel Criteria
*/
private JPanel jpCritLine1 = new JPanel();
private JPanel jpCritLine2 = new JPanel();
// DEFAULT PANEL
private JLabel lInitText;
// JPL & CDMS
private JLabel lEnergy;// = new JLabel("<html><i>E</i><sub>low</sub> </html>"); //Lower level energy
// range ");
private JLabel lEnergyunits;// = new JLabel("<html>cm<sup>-1</sup> </html>");
private JLabel lIntensity;// = new JLabel("<html>log<sub>10</sub>(I)</html>");
private JLabel lIntensityAt;// = new JLabel("@");
private JLabel lIntensityK;// = new JLabel("K");
private JTextField tfEnergy;// = new JTextField(5);
private JTextField tfEnergy2;// = new JTextField(5);
private JTextField tfIntensity;// = new JTextField(5);
private JTextField tfIntensityT;// = new JTextField(5);
// RECOMBINATION LINES
private JLabel lDeltaN;
private JTextField tfDeltaN;
// RANGE SEARCH
private String rangeSearch = null;
private String[] nameFileMADCUBA = new String[2];
// FORMAT
private DecimalFormat format = null;
private DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.US);
boolean isMakeEventChangeNuLambda = true;
boolean isMakeEventChangeNuLambdaGenerate = true;
boolean isMakeEventChangeHzmm = true;
boolean isMakeEventChangeHzmmGenerate = true;
/**
* Class Constructor:<br>
*
* @param PathDB -- String Absolute path to DB.
* @param lsrd -- LineSearchResultsDialog
*/
public LineSearchPanel(String PathDB, LineSearchResultsDialog lsrd) {
Log.getInstance();
initDBConnection(PathDB);
//
// Log.getInstance().logger.debug(System.getProperty("user.dir")+"=USERDIR no");
// Log.getInstance().logger.debug(PathDB+"=PathDB");
initGUI();
dialogResults = lsrd;
initialsParams();
}
/**
* Default Class Constructor:<br>
* The DataBase is assumed to be located where the program is running
*/
public LineSearchPanel(LineSearchResultsDialog lsrd) {
Log.getInstance();
Log.getInstance().logger.debug(System.getProperty("user.dir")+"=USERDIR");
initDBConnection(System.getProperty("user.dir") + "/"+MyConstants.PATH_DIRECTORY_CATALOG + SlimConstants.NAME_FILES_BD);
initGUI();
dialogResults = lsrd;
if (isMADCUBA_IJconnected()) {
selectTypeRange.setSelectedIndex(0);
}
}
/**
* Connects to the database
*/
private void initDBConnection(String databasePath) {
try {
// _log.setLevel(Level.WARN);
_log.logger.debug(" CreateDbHSQLDB: " + databasePath);
db = new DbHSQLDBCreate(databasePath);
} catch (Exception ex) {
Log.getInstance().logger.error("Error initDBConnection ");
ex.printStackTrace();
}
}
/**
* Filling Combo Box with available Catalogs from the DataBase<br>
* Long names of Catalogs are read from the TableIndex in DataBase
*
* @param args Selected Type of Catalog to Search
*/
public void fillcBoxCatalog(String args) {
ResultSet dbresult = null;
String sqlcommand;
sqlcommand = "SELECT id_tablelongname FROM TableIndex";
if (!args.toUpperCase().equals("ALL"))
sqlcommand = sqlcommand.concat(" WHEREd id_tabletype = \"").concat(args).concat("\"");
try {
dbresult = db.query(sqlcommand);
jpListMolecules.getComboCatalog().removeAllItems();
if(db.db_exists(false))
for (; dbresult.next();) {
jpListMolecules.getComboCatalog().addItem(dbresult.getObject(1).toString());
}
} catch (SQLException ex3) {
Log.getInstance().logger.error("Error fillcBoxCatalog ");
ex3.printStackTrace();
} catch (NullPointerException ex) {
_log.logger.warn("Database not available: " + "" + ex.getMessage());
}
try {
// Check if USER DB exists. If so, add the USER inputs (currently there should be only one.
if(db.st_user!=null && db.db_exists(true)){
dbresult = db.query(true,sqlcommand);
for (; dbresult.next();) {
jpListMolecules.getComboCatalog().addItem(dbresult.getObject(1).toString());
}
}
} catch (SQLException ex3) {
Log.getInstance().logger.error("Error fillcBoxCatalog ");
ex3.printStackTrace();
} catch (NullPointerException ex) {
_log.logger.warn("Database not available: " + "" + ex.getMessage());
}
jpListMolecules.getComboCatalog().addItem("Recomb. Lines");
}
/**
* Filling Combo box with available Molecules/Atoms in the DataBase according to
* the Catalog selected.<br>
* - Allows writing in the Combo Box to constraint the species shown when
* ComboBox is opened<br>
* - Species are ordered alphabetically
*
* @param args Selected Species or string contained in the species name
*/
public void fillcBoxSpecies(String args) {
// Temporary solution to add the Recombination lines
if (jpListMolecules.getComboCatalog().getSelectedItem().equals("Recomb. Lines")) {
jpListMolecules.getListModelIn().removeAllElements();
jpListMolecules.getListModelIn().addElement("H");
jpListMolecules.getListModelIn().addElement("He");
jpListMolecules.getListModelIn().addElement("C");
jpListMolecules.getListModelIn().addElement("S");
} else {
////// REMOVE THISSSS
jpListMolecules.getButtonLineSearch().setEnabled(true);
/////
ResultSet dbresult = null;
String sqlcommand;
try {
/*
* First gets the name of the table in DB corresponding to the Long Name
* selected in the Catalog Combo Box
*/
sqlcommand = "SELECT id_tablename FROM TableIndex WHERE id_tablelongname = '"
.concat(jpListMolecules.getComboCatalog().getSelectedItem().toString()).concat("'");
dbresult = db.query(sqlcommand);
dbresult.next();
String row = dbresult.getObject(1).toString();
/*
* If JPL, changes JPL to JPLcat (same with CDMS and USER), where the list of
* molecules is located
*/
// row = row.replace((String) SlimConstants.CATALOG_JPL, (String) "JPLcat");
// row = row.replace((String) SlimConstants.CATALOG_CDMS, (String) "CDMScat");
// row = row.replace((String) SlimConstants.CATALOG_USER, (String) SlimConstants.CATALOG_USER+"cat");
// Log.getInstance().logger.debug(row+"="+Arrays.binarySearch(SlimConstants.CATALOG_LIST_NO_RECOMB, row));
if(Arrays.binarySearch(SlimConstants.CATALOG_LIST_NO_RECOMB, row)>=0)
row = row+"cat";
// Log.getInstance().logger.debug(row+"=2="+Arrays.binarySearch(SlimConstants.CATALOG_LIST_NO_RECOMB, row));
sqlcommand = "SELECT DISTINCT id_formula FROM ".concat(row);
/*
* If selected something different to ALL or [empty], the combo will only
* display the species whose name contain the string written by the user.
*/
if (!args.toUpperCase().equals("ALL") && !args.equals(""))
sqlcommand = sqlcommand.concat(" WHERE id_formula LIKE '%" + args.replace("*", "") + "%' ");
sqlcommand = sqlcommand.concat(" ORDER BY id_formula ASC");
// System.out.println(sqlcommand);
dbresult = db.query(sqlcommand);
// cBoxSpecies.removeAllItems();
// cBoxSpecies.addItem("ALL"); // ALL always at the beginning of the list
/*
* Filling of the Combo box with the search results
*/
/*
* for( ; dbresult.next() ; ){
* cBoxSpecies.addItem(dbresult.getObject(1).toString()); }
* cBoxSpecies.setSelectedItem(args); cBoxSpecies.setAutocomplete();
*/
jpListMolecules.getListModelIn().removeAllElements();
for (; dbresult.next();) {
// Eduardo Toledo Dec 2024
// Traza para depurar problema con nuevas moleculas
//String value = dbresult.getObject(1).toString();
//System.out.println("Value: " + value);
//
jpListMolecules.getListModelIn().addElement(dbresult.getObject(1).toString());
}
} catch (SQLException ex3) {
Log.getInstance().logger.error("Error fillcBoxSpecies ");
ex3.printStackTrace();
}
}
jpListMolecules.autoFilter();
}
/**
* Filling Combo Box with the units of Frequency or Wavelength
*
* @param items Array of values
* @param selItem Integer of the position of the selected item in the array to
* be displayed
* @param cBoxHzmm JComboBox
*/
public void fillcBoxHzmm(String[] items, int selItem, JComboBox cBoxHzmm) {
cBoxHzmm.removeAllItems();
int i;
for (i = 0; i < items.length; i++)
cBoxHzmm.addItem(items[i]);
cBoxHzmm.setSelectedIndex(selItem);
if (cBoxHzmm.getName().equals(COMBO_HZMM_CRITERIA))
cBoxHzmmSelected = selItem;
else if (cBoxHzmm.getName().equals(COMBO_HZMM_GENERATE))
cBoxHzmmGenerateSelected = selItem;
}
public void fillcBoxHzmmFreqCriteriaDefault() {
fillcBoxHzmmFreqDefault(cBoxHzmm);
}
public void fillcBoxHzmmFreqGenerateDefault() {
fillcBoxHzmmFreqDefault(cBoxHzmmGenerateSpectra);
}
public void fillcBoxHzmmFreqDefault(JComboBox cBoxHzmm) {
fillcBoxHzmm(arrayHz, FREQ_DEFAULT_COMBO, cBoxHzmm);
}
public void fillcBoxHzmmWaveCriteriaDefault() {
fillcBoxHzmmWaveDefault(cBoxHzmm);
}
public void fillcBoxHzmmWaveGenerateDefault() {
fillcBoxHzmmWaveDefault(cBoxHzmmGenerateSpectra);
}
public void fillcBoxHzmmWaveDefault(JComboBox cBoxHzmm) {
fillcBoxHzmm(arrayMm, WAVE_DEFAULT_COMBO, cBoxHzmm);
}
/**
* Creates the Default Selection Criteria Panel. Displays a text with no options
*
* @param cataSelected Selected Catalog
*/
private JPanel createJPanelCriteriaDefault(String cataSelected) {
if (jPanelCriteriaDefault == null) {
jPanelCriteriaDefault = new JPanel();
lInitText = new JLabel("No Search Criteria for Catalog " + cataSelected);
jPanelCriteriaDefault.add(lInitText);
// lInitText.setVisible(true);
}
return jPanelCriteriaDefault;
}
/*
* JPL - Posibility to select in: - Energies of lower level (cm-1) - Intensities
* (For different Temperatures)
*/
public JPanel createJPanelCriteriaJPLCDMS(String cataSelected) {
if (jPanelCriteriaJPLCDMS == null) {
jPanelCriteriaJPLCDMS = new JPanel();
jpCritLine1 = new JPanel();
jpCritLine2 = new JPanel();
lEnergy = new JLabel("<html><i>E</i><sub>low</sub> </html>"); // Lower level energy range ");
lEnergyunits = new JLabel("<html>cm<sup>-1</sup> </html>");
lIntensity = new JLabel("<html>log<sub>10</sub>(I)</html>");
lIntensityAt = new JLabel("@");
lIntensityK = new JLabel("K");
tfEnergy = new JTextField(5);
tfEnergy2 = new JTextField(5);
tfIntensity = new JTextField(5);
tfIntensityT = new JTextField(5);
jpCritLine1.add(new JLabel("Energy from"));
jpCritLine1.add(tfEnergy);
tfEnergy.setText("Any");
jpCritLine1.add(new JLabel("to"));
jpCritLine1.add(tfEnergy2);
tfEnergy2.setText("Any");
jpCritLine1.add(lEnergyunits);
jpCritLine2.add(lIntensity);
jpCritLine2.add(tfIntensity);
jpCritLine2.add(lIntensityAt);
jpCritLine2.add(tfIntensityT);
jpCritLine2.add(lEnergy);
jpCritLine2.add(lIntensityK);
if (bOKJPL == null)
createButtonOkJPL();
jpCritLine2.add(bOKJPL);
tfIntensity.setText("Any");
tfIntensityT.setText("300");
tfIntensityT.setEditable(false);
jPanelCriteriaJPLCDMS.add(jpCritLine1);
jPanelCriteriaJPLCDMS.add(jpCritLine2);
}
return jPanelCriteriaJPLCDMS;
}
public SimFitCollisionMoleculePanel createJPanelCollisionCatalog() {
if (jPanelCollisionMolecule == null) {
jPanelCollisionMolecule = new SimFitCollisionMoleculePanel(false);
int panelHeight = 50;
jPanelCollisionMolecule. setPreferredSize(new Dimension(panelWidth, panelHeight));
jPanelCollisionMolecule. setMinimumSize(new Dimension(panelWidth, panelHeight));
jPanelCollisionMolecule. setMaximumSize(new Dimension(panelWidth, panelHeight));
//
}
return jPanelCollisionMolecule;
}
public JPanel createJPanelParametersSource() {
JPanel jPanelParameters= new JPanel();
// if (jPanelParametersSource == null) {
jPanelParametersSource = new SimFitSourceParametersPanel(false,true,true);
int panelHeight = 100;
jPanelParametersSource. setPreferredSize(new Dimension(panelWidth, panelHeight));
jPanelParametersSource. setMinimumSize(new Dimension(panelWidth, panelHeight));
jPanelParametersSource. setMaximumSize(new Dimension(panelWidth, panelHeight));
// }
jPanelParameters.setBorder(javax.swing.BorderFactory.createTitledBorder(
javax.swing.BorderFactory.createLineBorder(new java.awt.Color(153, 153, 153), 1), "SOURCE PARAMETERS",
javax.swing.border.TitledBorder.LEADING, javax.swing.border.TitledBorder.TOP,
new java.awt.Font("SansSerif", java.awt.Font.BOLD, 11), new java.awt.Color(60, 60, 60)));
JButton bParametersSource = new JButton("Source Parameters");
bParametersSource.setActionCommand("showPrameters");
// bSyntheticSpectra.setEnabled(false);
ActionListener alGenerateSpectra = new ActionListener() {
public void actionPerformed(ActionEvent ev) {
if (ev.getActionCommand() != null && ev.getActionCommand().equals("showPrameters")) {
panelSourceParametersVisible(!jPanelParametersSource.isVisible());
}
}
};
bParametersSource.addActionListener(alGenerateSpectra);
jPanelParameters.add(bParametersSource);
jPanelParameters.add(jPanelParametersSource);
panelSourceParametersVisible(false);
return jPanelParameters;
}
private void createButtonOkJPL() {
bOKJPL = new JButton("OK");
bOKJPL.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
jpListMolecules.copyCriteriaCatalogToTable();
}
});
}
private void createButtonOkRecomb() {
bOKRecom = new JButton("OK");
bOKRecom.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
jpListMolecules.copyCriteriaCatalogToTable();
}
});
}
public JPanel createJPanelCriteriaRECOMB(String cataSelected) {
if (jPanelCriteriaRECOMB == null) {
jPanelCriteriaRECOMB = new JPanel();
jpCritLine1 = new JPanel();
if (IJ.isMacintosh() || IJ.isMacOSX())
lDeltaN = new JLabel(
"Max. " + SlimConstants.COLUMN_DELTA_n_RECOMB_MAC + MyConstants.LABEL_MINOR_EQUAL_MAC);
else
lDeltaN = new JLabel(
"Max. " + SlimConstants.COLUMN_DELTA_n_RECOMB + MyConstants.LABEL_MINOR_EQUAL_NO_MAC);
tfDeltaN = new JTextField(2);
jpCritLine1.add(lDeltaN);
jpCritLine1.add(tfDeltaN);
jpCritLine2 = new JPanel();
if (bOKRecom == null)
createButtonOkRecomb();
jpCritLine2.add(bOKRecom);
tfDeltaN.setText("2");
jPanelCriteriaRECOMB.add(jpCritLine1);
jPanelCriteriaRECOMB.add(jpCritLine2);
}
return jPanelCriteriaRECOMB;
}
/**
* Creates the Selection Criteria Panel. Only for selected catalogs, otherwise
* empty.
*
* @param cataSelected Selected Catalog
*/
public void fillPanelCriteria(String cataSelected) {
jPanelCriteria.removeAll();
jPanelCriteria.setBorder(javax.swing.BorderFactory.createTitledBorder(
javax.swing.BorderFactory.createLineBorder(new java.awt.Color(153, 153, 153), 1),
"SPECTROSCOPIC CRITERIA"/* + cataSelected */, javax.swing.border.TitledBorder.LEADING,
javax.swing.border.TitledBorder.TOP, new java.awt.Font("SansSerif", java.awt.Font.BOLD, 11),
new java.awt.Color(60, 60, 60)));
if (cataSelected.equals("Lovas 1992") || cataSelected.equals("Lovas 2003")
|| cataSelected.equals("Big Lovas")) {
jPanelCriteria.add(createJPanelCriteriaDefault(cataSelected));
//20220113 poniendo mire en lista
}else if( Arrays.binarySearch(SlimConstants.CATALOG_LIST_NO_RECOMB,cataSelected.toString().replace(" ", ""))>=0) {
// } else if (cataSelected.toString().replace(" ", "").equals(SlimConstants.CATALOG_JPL) ||
//
// cataSelected.toString().replace(" ", "").equals(SlimConstants.CATALOG_CDMS) ||
//
// cataSelected.toString().replace(" ", "").equals(SlimConstants.CATALOG_USER)) {
jPanelCriteria.add(createJPanelCriteriaJPLCDMS(cataSelected));
} else if (cataSelected.toString().toUpperCase().contains(SlimConstants.CATALOG_RECOMBINE.toUpperCase())) {
jPanelCriteria.add(createJPanelCriteriaRECOMB(cataSelected));
}
}
/**
* Changes the Scale of Frenquecy/Wavelength in the Range Selection SubPanel
*
* @param convTable Conversion table used to convert units
* @param from Position in the array of the original units
* @param to Position in the array of the new units
* @return double[] Converted units
* TBD--------------------------------------------------- This should
* receive as input parameters the values to be converted.
*/
public double[] unitConversionMinMax(double[] valueMinMax,double[] convTable, int from, int to) {
double[] convertedUnits = valueMinMax;
convertedUnits[0] = convertedUnits[0] * convTable[from] / convTable[to];
convertedUnits[1] = convertedUnits[1] * convTable[from] / convTable[to];
// System.out.println("From " + from + "to" + to + "---" +ConvertedUnits[0] + "
// " + ConvertedUnits[1]);
return convertedUnits;
}
public double unitConversionResolutionOld(String resolution, double[] convTable, int from, int to) {
if (!resolution.equals("")) {
try {
double convertedUnits = Double.parseDouble(resolution);
convertedUnits = convertedUnits * convTable[from] / convTable[to];
// System.out.println("From " + from + "to" + to + "---" +ConvertedUnits[0] + "
// " + ConvertedUnits[1]);
return convertedUnits;
} catch (Exception e) {
// TODO: handle exception
}
}
return Double.NaN;
}
/**
* Changes from Frequency to Wavelength and viceversa
*
* @param to Indicates to which scale the units will be changed
* @return double[] Converted units. Frequency in MHz and Wavelength in mm
* TBD--------------------------------------------------- This should
* receive as input parameters the values to be converted.
*/
public double[] unitConversionMinMax(double[] valueMinMax, String to,JComboBox cBoxHzmm)
{
double[] convertedUnits = new double[] { 0, 0 };
if (to.equals("Frequency")) {
convertedUnits = unitConversionMinMax(valueMinMax,arrayMmFactor, cBoxHzmm.getSelectedIndex(), WAVE_CM_POS_COMBO);
convertedUnits[0] = 2.9979247E+10 / convertedUnits[0] / 1E+6;
convertedUnits[1] = 2.9979247E+10 / convertedUnits[1] / 1E+6;
//DEVUELTE EL VALOR EN FREQUENCIA, PERO EN LA QUE VOY A MOSTRAR EN EL COMBo, ESTO ES
//EN MHz
} else if (to.equals("Wavelength")) {
convertedUnits = unitConversionMinMax(valueMinMax,arrayHzFactor, cBoxHzmm.getSelectedIndex(), FREQ_HZ_POS_COMBO);
convertedUnits[0] = 2.9979247E+10 / convertedUnits[0] * 10;
convertedUnits[1] = 2.9979247E+10 / convertedUnits[1] * 10;
}
return convertedUnits;
}
public double unitConversionLineWidth(String resolution, String to) {
double convertedUnits = Double.NaN;
try {
convertedUnits = new Double(resolution);
}catch (NumberFormatException e) {
// TODO: handle exception
}
if (to.equals("km/s")) {
// convertedUnits = unitConversionResolution(resolution, cBoxHzmmGenerateSpectra.getSelectedIndex());
convertedUnits = convertedUnits / 1E+3;
// System.out.println(ConvertedUnits[0] + " " + ConvertedUnits[1]);
} else if (to.equals("m/s")) {
convertedUnits = convertedUnits* 1000;
}
return convertedUnits;
}
public double unitConversionResolutionOld(String resolution, String to) {
double convertedUnits = 0;
if (to.equals("Frequency")) {
convertedUnits = unitConversionResolutionOld(resolution, arrayMmFactor, cBoxHzmmGenerateSpectra.getSelectedIndex(),
WAVE_CM_POS_COMBO);
convertedUnits = 2.9979247E+10 / convertedUnits / 1E+6;
// System.out.println(ConvertedUnits[0] + " " + ConvertedUnits[1]);
} else if (to.equals("Wavelength")) {
convertedUnits = unitConversionResolutionOld(resolution, arrayHzFactor, cBoxHzmmGenerateSpectra.getSelectedIndex(),
FREQ_HZ_POS_COMBO);
convertedUnits = 2.9979247E+10 / convertedUnits * 10;
}
return convertedUnits;
}
/**
* Gets the frequency ranges covered by the selected spectra.
*
* @return String with range
*/
public String getStringFrequencyRangeSelected() throws Exception {
String stringRange = new String();
String unit = "";
String label = "";
String returnArgRange = "";
// if (!checkBoxFreq.isSelected())
if (selectTypeRange.getSelectedIndex() == RANGE_USER_DEFINED) // USED DEFINED
{
stringRange = tfFreqMin.getText() + MyConstants.SEPARATOR_NIVEL_1 + tfFreqMax.getText()
+ MyConstants.SEPARATOR_NIVEL_1;
unit = cBoxHzmm.getSelectedItem() + "";
if (unit.equals("\u03BCm"))
unit = "micrometer";
else if (unit.equals("\u00C5"))
unit = "angstrom";
label = cBoxNuLambda.getSelectedItem() + "";
rangeSearch = null;
returnArgRange = " range='" + stringRange + "' axislabel='" + label + "' axisunit='" + unit + "'";
} else {
if (!isMADCUBA_IJconnected()) {
if (rangeSearch != null && !rangeSearch.equals("")) {// GET RANGE OPEN PRODUCT
stringRange = rangeSearch;
unit = "MHz";
label = "Frequency";
returnArgRange = " range='" + stringRange + "' axislabel='" + label + "' axisunit='" + unit + "'";
} else
JOptionPane.showMessageDialog(this, "IT IS NOT OPENED: A MASSAJ TABLE OR SPECTRAL");
} else {
if (selectTypeRange.getSelectedIndex() == RANGE_WINDOW) {
stringRange = SELECTED_WINDOW;
} else if (selectTypeRange.getSelectedIndex() == RANGE_WHOLE_FREQ) {
stringRange = SELECTED_WHOLE_RANGE;
} else {
stringRange = SELECTED_DATA;
}
returnArgRange = " range='" + stringRange + "'";
}
}
return returnArgRange;
}
/**
* Gets the frequency ranges covered by the selected spectra.
*
* @return String with range
*/
public String getStringFrequencyRangeGenerateSpectra() {
String stringRange = new String();
String unit = "";
String label = "";
stringRange = tfFreqMinGenerate.getText() + MyConstants.SEPARATOR_NIVEL_1 + tfFreqMaxGenerate.getText()
+ MyConstants.SEPARATOR_NIVEL_1;
unit = cBoxHzmmGenerateSpectra.getSelectedItem() + "";
if (unit.equals("\u03BCm"))
unit = "micrometer";
else if (unit.equals("\u00C5"))
unit = "angstrom";
label = cBoxNuLambdaGenerateSpectra.getSelectedItem() + "";
rangeSearch = null;
return " range='" + stringRange + "' axislabel='" + label + "' axisunit='" + unit + "'";
}
private String generateStringMoleculesCommand(String tablename) {
// TODO CUANDO VAYA A ANADIR LAS MOLECULAS SI DE DIGO ADD; NO BUSQUE LAS QUE
// EXISTAN
String commandMolecules = new String();
if (jpListMolecules.getTableSpecies().getRowCount() > 0) {
if (jpListMolecules.getTableSpecies().getRowCount() > 4
&& jpListMolecules.getTableSpecies().getRowCount() == jpListMolecules.getListModelIn().size())
{
if (!MyUtilities.showMessageWithNoYesOption(this,
"Selected ALL molecules for searching?.\n Do you want to continue?",
"WARNING: Search All MOlecules"))
return null;
}
String sForm = null;
String sCatalog = null;
for (int irow = 0; irow < jpListMolecules.getTableSpecies().getRowCount(); irow++) {
// System.out.println("S: ---" + jtTableSpecies.getValueAt(irow, 0) + "--- C:
// ---" + jtTableSpecies.getValueAt(irow, 1) + "---");
sForm = jpListMolecules.getTableSpecies().getValueAt(irow, 0) + "";
sCatalog = jpListMolecules.getTableSpecies().getValueAt(irow, 1).toString();
String command = generateCommandSearchCriteria(irow, sCatalog);
commandMolecules += sCatalog + MyConstants.SEPARATOR_NIVEL_2 + sForm + MyConstants.SEPARATOR_NIVEL_2
+ command + MyConstants.SEPARATOR_NIVEL_1;
}
} else {
String commandCriteria = generateCommandSearchCriteria(false);
if (jpListMolecules.getListIn().getSelectedIndex() >= 0) {
for (int iSel = 0; iSel < jpListMolecules.getListIn().getSelectedValues().length; iSel++) {
commandMolecules += tablename + MyConstants.SEPARATOR_NIVEL_2
+ jpListMolecules.getListIn().getSelectedValues()[iSel] + MyConstants.SEPARATOR_NIVEL_2
+ commandCriteria + MyConstants.SEPARATOR_NIVEL_1;
}
} else if (!jpListMolecules.getTextMolecules().getText().equals("")) {
commandMolecules += tablename + MyConstants.SEPARATOR_NIVEL_2
+ jpListMolecules.getTextMolecules().getText() + MyConstants.SEPARATOR_NIVEL_2 + commandCriteria
+ MyConstants.SEPARATOR_NIVEL_1;
}
} return commandMolecules;
}
private String generateCommandSearchCriteria(boolean isAllCriteria) {
String commandCriteria = "";
/*
* IF THERE ARE ENERGY CONSTRAINTS
*/
/*
* IF THERE ARE INTENSITY CONSTRAINTS
*/
if (jPanelCriteriaJPLCDMS!=null&& jPanelCriteriaJPLCDMS.getParent()!=null&& jPanelCriteriaJPLCDMS.isVisible()) {
if (isAllCriteria)
commandCriteria += "1" + MyConstants.SEPARATOR_NIVEL_2;
if (tfEnergy.getText().equals(""))
commandCriteria += "Any" + MyConstants.SEPARATOR_NIVEL_2;
else
commandCriteria += tfEnergy.getText() + MyConstants.SEPARATOR_NIVEL_2;
if (tfEnergy2.getText().equals(""))
commandCriteria += "Any" + MyConstants.SEPARATOR_NIVEL_2;
else
commandCriteria += tfEnergy2.getText() + MyConstants.SEPARATOR_NIVEL_2;
if (tfIntensity.getText().equals(""))
commandCriteria += "Any" + MyConstants.SEPARATOR_NIVEL_2;
else
commandCriteria += tfIntensity.getText() + MyConstants.SEPARATOR_NIVEL_2;
} else if (jPanelCriteriaRECOMB!=null&&jPanelCriteriaRECOMB.getParent()!=null &&jPanelCriteriaRECOMB.isVisible()) {
// commandCriteria += tfDeltaN.getText() + MyConstants.SEPARATOR_NIVEL_2;
try {
if (Integer.parseInt(tfDeltaN.getText()) < 1 || Integer.parseInt(tfDeltaN.getText()) > 12) {
if (Integer.parseInt(tfDeltaN.getText()) < 1) {
JOptionPane.showMessageDialog(this,
MyConstants.LABEL_DELTA_NO_MAC + " has to be larger than 1. \n Value set to 2.",
"Search Error", JOptionPane.ERROR_MESSAGE);
tfDeltaN.setText("2");
} else {
JOptionPane.showMessageDialog(this,
MyConstants.LABEL_DELTA_NO_MAC + " is currently limited to 12. \n Value set to 12.",
"Search Error", JOptionPane.ERROR_MESSAGE);
tfDeltaN.setText("12");
}
commandCriteria = tfDeltaN.getText();
} else if (!tfDeltaN.getText().equals("")) {
commandCriteria = tfDeltaN.getText();
}
} catch (NumberFormatException e) {
tfDeltaN.setText("2");
commandCriteria = tfDeltaN.getText();
}
}
return commandCriteria;
}
private String generateCommandSearchCriteria(int irow, String catalog) {
/*
* IF THERE ARE ENERGY CONSTRAINTS
*/
String commandCriteria = "";
int iRowModel = jpListMolecules.getTableSpecies().convertRowIndexToModel(irow);
if (catalog.toUpperCase().startsWith(SlimConstants.CATALOG_RECOMBINE.toUpperCase())) {
if (jpListMolecules.getTableSpecies().getModel().getValueAt(iRowModel,
SlimConstants.POS_COLUMN_TMOLEC_DELTA_N) != null)
commandCriteria = jpListMolecules.getTableSpecies().getModel()
.getValueAt(iRowModel, SlimConstants.POS_COLUMN_TMOLEC_DELTA_N).toString();
else
commandCriteria = "1";
} else {
String energy = "Any";
if (jpListMolecules.getTableSpecies().getModel().getValueAt(iRowModel,
SlimConstants.POS_COLUMN_TMOLEC_ELOW) != null
&& !jpListMolecules.getTableSpecies().getModel()
.getValueAt(iRowModel, SlimConstants.POS_COLUMN_TMOLEC_ELOW).toString().equals(""))
energy = jpListMolecules.getTableSpecies().getModel()
.getValueAt(iRowModel, SlimConstants.POS_COLUMN_TMOLEC_ELOW).toString();
String energy2 = "Any";
if (jpListMolecules.getTableSpecies().getModel().getValueAt(iRowModel,
SlimConstants.POS_COLUMN_TMOLEC_CM_1) != null
&& !jpListMolecules.getTableSpecies().getModel()
.getValueAt(iRowModel, SlimConstants.POS_COLUMN_TMOLEC_CM_1).toString().equals(""))
energy2 = jpListMolecules.getTableSpecies().getModel()
.getValueAt(iRowModel, SlimConstants.POS_COLUMN_TMOLEC_CM_1).toString();
commandCriteria += energy + MyConstants.SEPARATOR_NIVEL_2 + energy2 + MyConstants.SEPARATOR_NIVEL_2;
/*
* IF THERE ARE INTENSITY CONSTRAINTS
*/
String intensity = "Any";
if (jpListMolecules.getTableSpecies().getModel().getValueAt(iRowModel,
SlimConstants.POS_COLUMN_TMOLEC_LOG) != null
&& !jpListMolecules.getTableSpecies().getModel()
.getValueAt(iRowModel, SlimConstants.POS_COLUMN_TMOLEC_LOG).toString().equals(""))
intensity = jpListMolecules.getTableSpecies().getModel()
.getValueAt(iRowModel, SlimConstants.POS_COLUMN_TMOLEC_LOG).toString();
commandCriteria += intensity + MyConstants.SEPARATOR_NIVEL_2;
}
return commandCriteria;
}
/**
* Sends the search query to the DB according to the selected criteria
* *
* @param isGenerateSpectra-- indicated it is generate a new spectrum or only make search
*/
public void doSearch(boolean isGenerateSpectra) {
/*
* TODO ESTO DEBERIA IR EN EL PLUGIN PARAMS A PASAR CATALOGO parametros que use
* para genererar sql command
*/
String argsPlugin = "";
try {
// TODO THIS SHOULD NOT BE NEEDED. DB SHOULD BE MODIFIED SO NO DIFFERENT NAMES
// ARE NEEDED
/*
* First gets the name of the table in DB corresponding to the Long Name
* selected in the Catalog Combo Box
*/
String comboCatalog = jpListMolecules.getComboCatalog().getSelectedItem().toString();
/*
* String sqlcommand = "SELECT id_tablename FROM TableIndex "+
* "WHERE id_tablelongname = '".concat(comboCatalog).concat("'");
*
* ResultSet dbresult = db.query(sqlcommand); dbresult.next(); comboCatalog =
* dbresult.getObject(1).toString();
*/
// argsPlugin = "catalog='"+comboCatalog+"'";
// RANGE FREQUENCY / WAQVELENGTH
if (isGenerateSpectra)
argsPlugin += getStringFrequencyRangeGenerateSpectra();
else {
try {
argsPlugin += getStringFrequencyRangeSelected();
} catch (Exception e) {
IJ.showMessage(e.getMessage());
return;
}
}
// IS NEW SEARCH OR EXITS SEARCH
if (jpListMolecules.getRadioAddCurrent().isSelected() && !isGenerateSpectra)
argsPlugin += " searchtype=add";
else if (jpListMolecules.getRadioUpdate().isSelected() && !isGenerateSpectra)
argsPlugin += " searchtype=update_transitions";
String molecules = generateStringMoleculesCommand(comboCatalog);
/*
* if (molecules == null) { dbresult.close(); System.gc(); return; }
*/
if (!molecules.equals("")) {
argsPlugin += " molecules='" + molecules + "'";
} else {
argsPlugin += " criteria='" + generateCommandSearchCriteria(true) + "'";
}
/* dbresult.close(); */