-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWindow.java
More file actions
1900 lines (1709 loc) · 62.5 KB
/
Copy pathWindow.java
File metadata and controls
1900 lines (1709 loc) · 62.5 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
package plotCAS;
import java.awt.Color;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.BorderFactory;
import javax.swing.JFileChooser;
import javax.swing.JRadioButton;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import java.io.BufferedReader;
import java.io.File;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.OutputStreamWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
public class Window extends JFrame {
private static final long serialVersionUID = 1L;
/* MENU */
JMenu analysis, export, settings;
JMenuItem optcurve, optplot;
/* SUBWINDOWS */
private JPanel container = new JPanel();
private JPanel plotscreen = new JPanel();
private JPanel optionscreen = new JPanel();
private JLabel optiontitle = new JLabel("");
/* Various */
public int ncurve=0;
public File WorkDir;
public ArrayList<Curve> curve = new ArrayList<Curve>();
public ArrayList<JCheckBox> whichcurve = new ArrayList<JCheckBox>();
private CurveSel plotselector=new CurveSel(0);
public Default curDefault=new Default();
public Plotgraph plot;
/* ******************************** */
/* ******* Window ******** */
/* ******************************** */
public Window(){
/* Make work dir */
PlotCAS.nwindow++;
File baseDir = new File(System.getProperty("java.io.tmpdir"));
String baseName = String.valueOf(System.currentTimeMillis());
WorkDir = new File(baseDir, baseName);
System.out.println(WorkDir);
WorkDir.mkdir();
/* Open window */
this.setTitle("plotCAS");
this.setSize(1000, 600);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
WindowListener exitListener = new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
int confirm = JOptionPane.showOptionDialog(null, "Are You Sure you want to exit?", "Exit Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
if (confirm == 0) {
File folder = new File(".");
File fList[] = folder.listFiles();
for (int i = 0; i < fList.length; i++) {
String pes = fList[i].getName();
if (pes.endsWith(".xy")||pes.endsWith(".input")||pes.startsWith("molcas")) {
fList[i].delete();
}
}
Window.this.WorkDir.delete();
dispose();
PlotCAS.nwindow--;
if (PlotCAS.nwindow==0) {System.exit(0);}
}
}
};
this.addWindowListener(exitListener);
plot= new Plotgraph(this);
/* MENU */
JMenuBar menuBar = new JMenuBar();
JMenu input = new JMenu("Input");
JMenuItem inputmolcas = new JMenuItem("MOLCAS file");
JMenuItem inputtrans = new JMenuItem("List of transitions");
JMenuItem inputxy = new JMenuItem("XY curve");
input.add(inputmolcas);
inputmolcas.addActionListener(new Molcasinput());
input.add(inputtrans);
inputtrans.addActionListener(new Transinput());
input.add(inputxy);
inputxy.addActionListener(new XYinput());
menuBar.add(input);
JMenu plotoptions = new JMenu("Plotting");
optcurve = new JMenuItem("Curve options");
optplot = new JMenuItem("General settings");
JMenuItem defaultmenu = new JMenuItem("Manage broadenings");
optcurve.addActionListener(new PlotCurvemenu());
optcurve.setEnabled(false);
plotoptions.add(optcurve);
optplot.addActionListener(new PlotOptmenu());
optplot.setEnabled(false);
plotoptions.add(optplot);
defaultmenu.addActionListener(new defaultmenu());
plotoptions.add(defaultmenu);
menuBar.add(plotoptions);
analysis = new JMenu("Analysis");
analysis.setEnabled(false);
JMenuItem operations = new JMenuItem("Curve operations");
operations.addActionListener(new CurveOp());
analysis.add(operations);
JMenuItem align = new JMenuItem("Align curves");
align.addActionListener(new Align());
analysis.add(align);
JMenuItem intensity = new JMenuItem("Integrated intensity");
intensity.addActionListener(new IntIntens());
analysis.add(intensity);
JMenuItem analorb = new JMenuItem("Orbital contributions");
analorb.addActionListener(new Analorbmenu());
analysis.add(analorb);
JMenuItem similarity = new JMenuItem("Similarity");
similarity.addActionListener(new Similarity());
analysis.add(similarity);
JMenuItem scatter = new JMenuItem("Scattering");
scatter.addActionListener(new Scatter());
analysis.add(scatter);
menuBar.add(analysis);
export = new JMenu("Export");
export.setEnabled(false);
JMenuItem exportxy = new JMenuItem("Curve XY");
exportxy.addActionListener(new ExportXY());
export.add(exportxy);
JMenuItem exportimg = new JMenuItem("Picture");
exportimg.addActionListener(new ExportImg());
export.add(exportimg);
JMenuItem exporttrans = new JMenuItem("List of transitions");
exporttrans.addActionListener(new ExportTrans());
export.add(exporttrans);
menuBar.add(export);
JMenuItem about = new JMenuItem("About");
about.addActionListener(new aboutmenu());
menuBar.add(about);
JMenuItem newapp = new JMenuItem("New window");
newapp.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
new Window();
}
});
menuBar.add(newapp);
setJMenuBar(menuBar);
/* SUBWINDOWS */
JScrollPane optionpanel;
container.setLayout(new BorderLayout());
optionscreen.setBorder(BorderFactory.createMatteBorder(0, 1, 0, 0, Color.black));
optionscreen.setLayout(new BoxLayout(optionscreen, BoxLayout.PAGE_AXIS));
optionpanel = new JScrollPane(optionscreen);
plotscreen.setLayout(new BorderLayout());
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
plotscreen, optionpanel);
splitPane.setResizeWeight(0.7);
container.add(splitPane);
this.setContentPane(container);
this.setVisible(true);
}
/* ******************************** */
/* ******* About ******** */
/* ******************************** */
class aboutmenu implements ActionListener {
public void actionPerformed(ActionEvent arg0){
optionscreen.removeAll();
optiontitle.setText("About");
optionscreen.add(optiontitle);
optionscreen.add(new JLabel("PlotCAS"));
optionscreen.add(new JLabel("A CASSCF/CASPT2 spectrum plotting program"));
optionscreen.add(new JLabel("v"+PlotCAS.currentversion));
optionscreen.add(new JLabel("2014, 4th july"));
optionscreen.add(new JLabel("author : M.G. Delcey"));
optionscreen.add(new JLabel("GNU Lesser General Public License v2.1"));
optionscreen.revalidate();
optionscreen.repaint();
}
}
/* ******************************** */
/* ******* Empty menu ******** */
/* ******************************** */
// A good way to exit a current menu made obsolete
public void emptymenu()
{
optionscreen.removeAll();
optionscreen.revalidate();
optionscreen.repaint();
}
/* ************************************************************ */
/* ************************************************************ */
/* ********************* ********************* */
/* ********************* INPUT ********************* */
/* ********************* ********************* */
/* ************************************************************ */
/* ************************************************************ */
/* ******************************** */
/* ******* MOLCAS input ******** */
/* ******************************** */
class Molcasinput implements ActionListener {
private File selectedFile;
private JLabel filename = new JLabel("");
private JRadioButton SFbutton, SOCbutton;
private JCheckBox dipolebutton, quadrupolebutton, velocbutton,boltzbutton, ETMObutton;
private JTextField ground1, ground2, curvename,boltztemp;
Molcasfile molcasinput;
JPanel smallbox;
public void actionPerformed(ActionEvent arg0){
optionscreen.removeAll();
optiontitle.setText("Input from MOLCAS file");
optionscreen.add(optiontitle);
/* Open file */
filename.setText("");
JButton openbutton = new JButton("Select File");
openbutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setCurrentDirectory(curDefault.get_dfile());
int returnValue = fileChooser.showOpenDialog(null);
if (returnValue == JFileChooser.APPROVE_OPTION) {
selectedFile = fileChooser.getSelectedFile();
filename.setText(selectedFile.getName());
curDefault.set_dfile(selectedFile.getParentFile());
}
}
});
JPanel l1 = new JPanel();
l1.setLayout(new BoxLayout(l1, BoxLayout.LINE_AXIS));
l1.add(openbutton);
l1.add(filename);
optionscreen.add(l1);
/* Which options should be read */
smallbox=new JPanel();
smallbox.setLayout(new BoxLayout(smallbox, BoxLayout.PAGE_AXIS));
JButton loadbutton = new JButton("Load");
optionscreen.add(loadbutton);
loadbutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
molcasinput = new Molcasfile(Window.this.WorkDir,selectedFile);
smallbox.removeAll();
int wf = molcasinput.whichWF();
switch (wf)
{
case 1:
smallbox.add(new JLabel("RASSCF calculation"));
break;
case 2:
smallbox.add(new JLabel("SS-CASPT2 calculation"));
break;
case 3:
smallbox.add(new JLabel("MS-CASPT2 calculation"));
break;
}
if (molcasinput.isRASSI())
{
smallbox.add(new JLabel("RASSI specifications"));
int nrSF=molcasinput.getSFstates();
int nrSOC=molcasinput.getSOCstates();
ButtonGroup SFSOCGroup = new ButtonGroup();
JPanel l2 = new JPanel();
l2.setLayout(new BoxLayout(l2, BoxLayout.LINE_AXIS));
if (nrSF>0)
{
smallbox.add(new JLabel(String.valueOf(nrSF)+" spin-free states"));
SFbutton = new JRadioButton("Spin-Free");
SFSOCGroup.add(SFbutton);
l2.add(SFbutton);
}
if (nrSOC>0)
{
smallbox.add(new JLabel(String.valueOf(nrSOC)+" spin-orbit states"));
SOCbutton = new JRadioButton("Spin-Orbit");
SOCbutton.setSelected(true);
SFSOCGroup.add(SOCbutton);
l2.add(SOCbutton);
}
else
{
SFbutton.setSelected(true);
}
smallbox.add(l2);
ActionListener TMO1 = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
if (ETMObutton.isSelected())
{
if (molcasinput.isdipole()) { dipolebutton.setSelected(false);}
if (molcasinput.isveloc()) { velocbutton.setSelected(false);}
if (molcasinput.isquadrupole()) { quadrupolebutton.setSelected(false);}
}
else
{
if (molcasinput.isdipole()) { dipolebutton.setSelected(true);}
if (molcasinput.isquadrupole()) { quadrupolebutton.setSelected(true);}
}
}
};
ActionListener TMO2 = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
if ((molcasinput.isveloc()&&velocbutton.isSelected()))
{
dipolebutton.setSelected(true);
}
if ((molcasinput.isdipole()&&dipolebutton.isSelected())||(molcasinput.isquadrupole()&&quadrupolebutton.isSelected()))
{
if (molcasinput.isETMO()) { ETMObutton.setSelected(false);}
}
}
};
JPanel l3 = new JPanel();
l3.setLayout(new BoxLayout(l3, BoxLayout.LINE_AXIS));
if (molcasinput.isdipole())
{
dipolebutton = new JCheckBox("Dipole transitions");
dipolebutton.setSelected(true);
dipolebutton.addActionListener(TMO2);
l3.add(dipolebutton);
}
if (molcasinput.isquadrupole())
{
quadrupolebutton = new JCheckBox("Quadrupole transitions");
quadrupolebutton.setSelected(true);
quadrupolebutton.addActionListener(TMO2);
l3.add(quadrupolebutton);
}
if (molcasinput.isveloc())
{
velocbutton = new JCheckBox("Velocity representation");
velocbutton.setSelected(false);
velocbutton.addActionListener(TMO2);
l3.add(velocbutton);
}
smallbox.add(l3);
JPanel l3_2 = new JPanel();
l3_2.setLayout(new BoxLayout(l3_2, BoxLayout.LINE_AXIS));
if (molcasinput.isETMO())
{
ETMObutton = new JCheckBox("Exact transition operator");
ETMObutton.setSelected(false);
ETMObutton.addActionListener(TMO1);
l3_2.add(ETMObutton);
smallbox.add(l3_2);
}
JPanel l4 = new JPanel();
l4.setLayout(new BoxLayout(l4, BoxLayout.LINE_AXIS));
l4.add(new JLabel("Ground states from"));
ground1 = new JTextField("1");
l4.add(ground1);
l4.add(new JLabel("to"));
ground2 = new JTextField("1");
l4.add(ground2);
smallbox.add(l4);
JPanel l5 = new JPanel();
l5.setLayout(new BoxLayout(l5, BoxLayout.LINE_AXIS));
boltzbutton = new JCheckBox("Boltzman distribution");
l5.add(boltzbutton);
boltztemp = new JTextField("298");
l5.add(boltztemp);
l5.add(new JLabel("K"));
smallbox.add(l5);
JPanel l6 = new JPanel();
l6.setLayout(new BoxLayout(l6, BoxLayout.LINE_AXIS));
JButton curvebutton = new JButton("Create curve");
l6.add(curvebutton);
curvename = new JTextField("curve name");
l6.add(curvename);
smallbox.add(l6);
curvebutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
boolean isSF,isSOC,isdip,isveloc,isquad,isETMO;
if (molcasinput.getSFstates()<=0){isSF=false;}
else {isSF=SFbutton.isSelected();}
if (molcasinput.getSOCstates()<=0){isSOC=false;}
else {isSOC=SOCbutton.isSelected();}
if (!molcasinput.isdipole()){isdip=false;}
else {isdip=dipolebutton.isSelected();}
if (!molcasinput.isquadrupole()){isquad=false;}
else {isquad=quadrupolebutton.isSelected();}
if (!molcasinput.isveloc()){isveloc=false;}
else {isveloc=velocbutton.isSelected();}
if (!molcasinput.isETMO()){isETMO=false;}
else {isETMO=ETMObutton.isSelected();}
float temp=0;
if (boltzbutton.isSelected())
{
temp=Float.parseFloat(boltztemp.getText());
}
Transition trans=new Transition(Window.this,molcasinput,isSF,isSOC, isdip,isveloc,isquad,isETMO,boltzbutton.isSelected(),temp,Integer.parseInt(ground1.getText()),Integer.parseInt(ground2.getText()));
addcurve(curvename.getText(),1,trans,"",plot.getunit());
}
});
}
else
{
JOptionPane.showMessageDialog(new JFrame(),
"To plot a spectrum, the input requires a RASSI section.",
"Input error",
JOptionPane.ERROR_MESSAGE);
}
optionscreen.add(smallbox);
optionscreen.revalidate();
optionscreen.repaint();
}
});
optionscreen.revalidate();
optionscreen.repaint();
}
}
/* ******************************** */
/* ******* List input ******** */
/* ******************************** */
class Transinput implements ActionListener {
private JTextArea textArea;
private JTextField curvename;
private JComboBox<String> unitsel;
public void actionPerformed(ActionEvent arg0){
optionscreen.removeAll();
optiontitle.setText("Input from list of transitions");
optionscreen.add(optiontitle);
/* Make text area */
textArea = new JTextArea(
"ntransition\n" +
"energy1 intensity1\n" +
"energy2 intensity2\n" +
"..."
,20,20);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
JScrollPane areaScrollPane = new JScrollPane(textArea);
areaScrollPane.setBorder(BorderFactory.createLineBorder(Color.black));
optionscreen.add(areaScrollPane);
JPanel l0 = new JPanel();
int iunit = plot.getunit();
l0.setLayout(new BoxLayout(l0, BoxLayout.LINE_AXIS));
l0.add(new JLabel("Native unit:"));
unitsel=new JComboBox<String>();
unitsel.addItem("hartree");
unitsel.addItem("eV");
unitsel.addItem("kcal/mol");
unitsel.addItem("kJ/mol");
unitsel.addItem("cm-1");
//unitsel.addItem("nm");
unitsel.setSelectedIndex(iunit);
l0.add(unitsel);
optionscreen.add(l0);
/* What curve name? */
JPanel l1 = new JPanel();
l1.setLayout(new BoxLayout(l1, BoxLayout.LINE_AXIS));
JButton curvebutton = new JButton("Create curve");
l1.add(curvebutton);
curvename = new JTextField("curve name");
l1.add(curvename);
optionscreen.add(l1);
/* Read and put to file */
curvebutton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae) {
Transition trans=new Transition(Window.this,textArea.getText());
addcurve(curvename.getText(),2,trans,"",unitsel.getSelectedIndex());
}
});
optionscreen.revalidate();
optionscreen.repaint();
}
}
/* ******************************** */
/* ******* XY input ******** */
/* ******************************** */
class XYinput implements ActionListener {
private JTextField curvename;
private JTextArea textArea;
private JComboBox<String> unitsel;
public void actionPerformed(ActionEvent arg0){
optionscreen.removeAll();
optiontitle.setText("Input from XY");
optionscreen.add(optiontitle);
/* Make text area */
textArea = new JTextArea(
"x1 y1\n" +
"x2 y2\n" +
"..."
,20,20);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
JScrollPane areaScrollPane = new JScrollPane(textArea);
areaScrollPane.setBorder(BorderFactory.createLineBorder(Color.black));
optionscreen.add(areaScrollPane);
JPanel l0 = new JPanel();
int iunit = plot.getunit();
l0.setLayout(new BoxLayout(l0, BoxLayout.LINE_AXIS));
l0.add(new JLabel("Native unit:"));
unitsel=new JComboBox<String>();
unitsel.addItem("hartree");
unitsel.addItem("eV");
unitsel.addItem("kcal/mol");
unitsel.addItem("kJ/mol");
unitsel.addItem("cm-1");
//unitsel.addItem("nm");
unitsel.setSelectedIndex(iunit);
l0.add(unitsel);
optionscreen.add(l0);
/* What curve name? */
JPanel l1 = new JPanel();
l1.setLayout(new BoxLayout(l1, BoxLayout.LINE_AXIS));
JButton curvebutton = new JButton("Create curve");
l1.add(curvebutton);
curvename = new JTextField("curve name");
l1.add(curvename);
optionscreen.add(l1);
/* Read and put to file */
curvebutton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae) {
Transition trans=new Transition(Window.this,textArea.getText());
addcurve(curvename.getText(),3,trans,"",unitsel.getSelectedIndex());
}
});
optionscreen.revalidate();
optionscreen.repaint();
}
}
/* ******************************** */
/* ******* Add/Delete curve ******* */
/* ******************************** */
public void addcurve(String pname,int ptype,Transition trans, String pinfo, int nativeunit)
{
this.ncurve++;
curve.add(new Curve(pname,ptype,trans,curDefault.get_dbroad(),pinfo,nativeunit));
curve.get(this.ncurve-1).setcolor(Plotgraph.colorseries(this.ncurve-1)); // Get different colors
whichcurve.add(new JCheckBox(pname));
whichcurve.get(this.ncurve-1).setSelected(true);
whichcurve.get(this.ncurve-1).addActionListener(new Refreshplot());
setcurvelist();
if (ptype==3) {
Broadening broad=new Broadening();
broad.set_Broadening(0);
curve.get(this.ncurve-1).setbroad(broad);}
if (this.ncurve==1)
{
init_graph();
new Curveplot(this,0);
new Curveplot(this,1);
plot.set_ascale(plot.mina, plot.maxagap);
// Enable menu
//plotoptions.setEnabled(true);
optcurve.setEnabled(true);
optplot.setEnabled(true);
analysis.setEnabled(true);
export.setEnabled(true);
}
else
{
new Curveplot(this,this.ncurve);
}
plotscreen.add(plot,BorderLayout.CENTER);
plot.repaint();
}
public void curve_delete(int icurve)
{
curve.remove(icurve);
whichcurve.remove(icurve);
plot.delete(icurve);
this.ncurve-=1;
setcurvelist();
if (this.ncurve<1)
{
optcurve.setEnabled(false);
optplot.setEnabled(false);
analysis.setEnabled(false);
export.setEnabled(false);
}
else
{
plot.repaint();
plotscreen.add(plot,BorderLayout.CENTER);
}
}
/* ************************************************************ */
/* ************************************************************ */
/* ********************* ********************* */
/* ********************* PLOT ********************* */
/* ********************* ********************* */
/* ************************************************************ */
/* ************************************************************ */
/* ******************************** */
/* ******* Curve options ******* */
/* ******************************** */
class PlotCurvemenu implements ActionListener {
private int icurve;
private JTextField curvename, offsetfield,yscalefield,colorfield, gausswfield, lorentzfield, lorentz2field, lorentzsplitfield;
private JTextArea InfoArea;
private JComboBox<String> broadsel;
private JPanel l7;
private JPanel l8;
private JPanel l9;
private JButton deletebutton;
private JRadioButton HWHM, Gsigma;
private String[] preflist;
private Broadening broad;
public void actionPerformed(ActionEvent arg0){
optionscreen.removeAll();
optiontitle.setText("Curve specific options");
optionscreen.add(optiontitle);
icurve=plotselector.index();
plotselector=new CurveSel(0);
plotselector.select(icurve);
plotselector.curvesel.addActionListener(new PlotCurvemenu()); // Recursive call
JPanel l0 = new JPanel();
l0.add(new JLabel("Options for curve:"));
l0.add(plotselector.Box());
/* Delete curve */
deletebutton=new JButton("Delete");
deletebutton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0){
icurve=plotselector.index();
int confirm = JOptionPane.showOptionDialog(null, "Are You Sure you want to remove this curve", "Removal Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
if (confirm==0) {
curve_delete(icurve);
emptymenu();
}
}
});
l0.add(deletebutton);
optionscreen.add(l0);
JPanel l1 = new JPanel();
l1.setLayout(new BoxLayout(l1, BoxLayout.LINE_AXIS));
l1.add(new JLabel("Name:"));
curvename = new JTextField(curve.get(icurve).getname());
l1.add(curvename);
optionscreen.add(l1);
optionscreen.add(new JLabel("Informations:"));
InfoArea = new JTextArea(curve.get(icurve).getinfo(),5,10);
optionscreen.add(InfoArea);
JPanel l2 = new JPanel();
l2.setLayout(new BoxLayout(l2, BoxLayout.LINE_AXIS));
l2.add(new JLabel("Horizontal offset:"));
offsetfield = new JTextField(String.valueOf(curve.get(icurve).getxoffset()));
l2.add(offsetfield);
optionscreen.add(l2);
JPanel l3 = new JPanel();
l3.setLayout(new BoxLayout(l3, BoxLayout.LINE_AXIS));
l3.add(new JLabel("Vertical scaling:"));
yscalefield = new JTextField(String.valueOf(curve.get(icurve).getyscale()));
l3.add(yscalefield);
optionscreen.add(l3);
JPanel l4 = new JPanel();
l4.setLayout(new BoxLayout(l4, BoxLayout.LINE_AXIS));
l4.add(new JLabel("Color (hexadecimal):"));
colorfield = new JTextField("#".concat(Integer.toHexString(curve.get(icurve).getcolor().getRGB()).substring(2, 8)));
l4.add(colorfield);
optionscreen.add(l4);
broad=curve.get(icurve).getbroad();
/* Broadening menu */
if (curve.get(icurve).gettype()<=2)
{
optionscreen.add(new JLabel("Broadening"));
JPanel l5 = new JPanel();
l5.add(new JLabel("Broadening type"));
broadsel=new JComboBox<String>();
broadsel.addItem("Gaussian broadening");
broadsel.addItem("Gaussian + Lorentzian broadening");
broadsel.addItem("Gaussian + dual Lorentzian broadening");
preflist=curDefault.get_preflist();
for(int i = 0; i < preflist.length; i++)
{
broadsel.addItem(preflist[i]);
}
l5.add(broadsel);
optionscreen.add(l5);
int ibroad=curve.get(icurve).getbroad().getbroadtype();
broadsel.setSelectedIndex(ibroad);
broadsel.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
int ibroad = broadsel.getSelectedIndex();
if (ibroad>=3)
{
curDefault.readdefaults(preflist[ibroad-3]);
broad=curDefault.get_dbroad();
ibroad=broad.getbroadtype();
gausswfield.setText(String.valueOf(broad.getgaussw()));
lorentzfield.setText(String.valueOf(broad.getlorw1()));
lorentz2field.setText(String.valueOf(broad.getlorw2()));
lorentzsplitfield.setText(String.valueOf(broad.getlorsplit()));
broadsel.setSelectedIndex(ibroad);
}
switch (ibroad)
{
case 0:
l7.setVisible(false);
l8.setVisible(false);
l9.setVisible(false);
break;
case 1:
l7.setVisible(true);
l8.setVisible(false);
l9.setVisible(false);
break;
case 2:
l7.setVisible(true);
l8.setVisible(true);
l9.setVisible(true);
break;
}
}
});
JPanel l6 = new JPanel();
l6.setLayout(new BoxLayout(l6, BoxLayout.LINE_AXIS));
l6.add(new JLabel("Gaussian width:"));
gausswfield = new JTextField(String.valueOf(broad.getgaussw()));
l6.add(gausswfield);
ButtonGroup GunitGroup = new ButtonGroup();
HWHM = new JRadioButton("HWHM");
HWHM.setSelected(true);
GunitGroup.add(HWHM);
l6.add(HWHM);
Gsigma = new JRadioButton("sigma");
GunitGroup.add(Gsigma);
l6.add(Gsigma);
optionscreen.add(l6);
l7 = new JPanel();
l7.setLayout(new BoxLayout(l7, BoxLayout.LINE_AXIS));
l7.add(new JLabel("Lorentzian width (HWHM):"));
lorentzfield = new JTextField(String.valueOf(broad.getlorw1()));
l7.add(lorentzfield);
if (ibroad<1) {l7.setVisible(false);}
optionscreen.add(l7);
l8 = new JPanel();
l8.setLayout(new BoxLayout(l8, BoxLayout.LINE_AXIS));
l8.add(new JLabel("Second lorentzian width:"));
lorentz2field = new JTextField(String.valueOf(broad.getlorw2()));
l8.add(lorentz2field);
if (ibroad<2) {l8.setVisible(false);}
optionscreen.add(l8);
l9 = new JPanel();
l9.setLayout(new BoxLayout(l9, BoxLayout.LINE_AXIS));
l9.add(new JLabel("Lorentzian split energy"));
lorentzsplitfield = new JTextField(String.valueOf(broad.getlorsplit()));
l9.add(lorentzsplitfield);
optionscreen.add(l9);
if (ibroad<2) {l9.setVisible(false);}
}
else if (curve.get(icurve).gettype()==3)
{
JPanel l6 = new JPanel();
l6.setLayout(new BoxLayout(l6, BoxLayout.LINE_AXIS));
l6.add(new JLabel("Gaussian smoothing:"));
gausswfield = new JTextField(String.valueOf(curve.get(icurve).getbroad().getgaussw()));
l6.add(gausswfield);
ButtonGroup GunitGroup = new ButtonGroup();
HWHM = new JRadioButton("HWHM");
HWHM.setSelected(true);
GunitGroup.add(HWHM);
l6.add(HWHM);
Gsigma = new JRadioButton("sigma");
GunitGroup.add(Gsigma);
l6.add(Gsigma);
optionscreen.add(l6);
};
JButton setbutton=new JButton("Save");
/* Change values and replot the curve */
setbutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
icurve=plotselector.index();
curve.get(icurve).setname(curvename.getText());
curve.get(icurve).setinfo(InfoArea.getText());
curve.get(icurve).setxoffset(Float.parseFloat(offsetfield.getText()));
curve.get(icurve).setyscale(Float.parseFloat(yscalefield.getText()));
curve.get(icurve).setcolor(Color.decode(colorfield.getText()));
whichcurve.get(icurve).setText(curvename.getText());
whichcurve.get(icurve).setForeground(curve.get(icurve).getcolor());
Broadening broad=new Broadening();
if (curve.get(icurve).gettype()<=2)
{
float gauss=Float.parseFloat(gausswfield.getText());
if (Gsigma.isSelected())
{
gauss=gauss*(float)Math.sqrt(2.0*Math.log(2));
}
switch (broadsel.getSelectedIndex())
{
case 0:
broad.set_Broadening(gauss);
break;
case 1:
broad.set_Broadening(gauss,Float.parseFloat(lorentzfield.getText()));
break;
case 2:
broad.set_Broadening(gauss,Float.parseFloat(lorentzfield.getText()),Float.parseFloat(lorentzsplitfield.getText()),Float.parseFloat(lorentz2field.getText()));
break;
}
curve.get(icurve).setbroad(broad);
curDefault.set_dbroad(curve.get(icurve).getbroad());
}
else if (curve.get(icurve).gettype()==3)
{
float gauss=Float.parseFloat(gausswfield.getText());
broad.set_Broadening(gauss);
curve.get(icurve).setbroad(broad);
}
new Curveplot(Window.this,icurve+1);
plot.repaint();
}
});
optionscreen.add(setbutton);
optionscreen.revalidate();
optionscreen.repaint();
}
}
class comboitem //Complicated structure to allow curves with same name to be distinguished
{
String name;
int ID;
public comboitem(String pname, int pID){
name=pname;
ID=pID;
}
public int getID(){
return ID;
}
@Override
public String toString() {
return name;
}
}
/* ******************************** */
/* ******* Plotting options ******* */
/* ******************************** */
class PlotOptmenu implements ActionListener {
private JTextField wname;
private JTextField resolinp;
private JTextField E1inp;
private JTextField E2inp;
private JTextField A1inp;
private JTextField A2inp;
private JComboBox<String> unitsel;
public void actionPerformed(ActionEvent arg0){
optionscreen.removeAll();
optiontitle.setText("General plotting options");
optionscreen.add(optiontitle);
JPanel l0 = new JPanel();
l0.setLayout(new BoxLayout(l0, BoxLayout.LINE_AXIS));
l0.add(new JLabel("Name of the window:"));
wname=new JTextField();
l0.add(wname);
optionscreen.add(l0);
JPanel l1 = new JPanel();
l1.setLayout(new BoxLayout(l1, BoxLayout.LINE_AXIS));
l1.add(new JLabel("Number of curve points:"));
resolinp=new JTextField(String.valueOf(plot.resolution));
l1.add(resolinp);
optionscreen.add(l1);
float x1=plot.getx1();
float dE=plot.getxde();
JPanel l2 = new JPanel();
l2.setLayout(new BoxLayout(l2, BoxLayout.LINE_AXIS));
l2.add(new JLabel("Energy range:"));
E1inp=new JTextField(String.valueOf(x1));
l2.add(E1inp);
E2inp=new JTextField(String.valueOf(x1+dE));
l2.add(E2inp);
optionscreen.add(l2);
float A1=plot.geta1();
float dA=plot.getda();
JPanel l3 = new JPanel();
l3.setLayout(new BoxLayout(l3, BoxLayout.LINE_AXIS));
l3.add(new JLabel("Absorption range:"));
A1inp=new JTextField(String.valueOf(A1));
l3.add(A1inp);
A2inp=new JTextField(String.valueOf(A1+dA));
l3.add(A2inp);
JButton ascalebutton = new JButton("Adjust to graph");
ascalebutton.addActionListener(new ActionListener()