-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCPL.java
More file actions
2460 lines (2204 loc) · 74.6 KB
/
CPL.java
File metadata and controls
2460 lines (2204 loc) · 74.6 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
import javax.swing.*;
import javax.swing.event.MouseInputAdapter;
import java.awt.*;
import java.util.*;
import java.awt.event.*;
import java.io.File;
import java.io.*;
public class CPL extends JFrame{
final Graph graph = new Graph();
final CommandLine cmdLine = new CommandLine(this);
JFrame parent=this;
String currentfile = "";
String currentpath = "";
String currentcmp = "";
String cmd_ind = "";
String[] cmds = new String[5];
Process child=null;
public CPL(){
super("Charting Patterns on Price History");
final Container pane = getContentPane();
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});
graph.setPreferredSize(new Dimension(800,400));
graph.setBorder(BorderFactory.createEtchedBorder());
//final CommandLine cmdLine = new CommandLine(this);
cmdLine.setPreferredSize(new Dimension(800,200));
//create the menu bar
JMenuBar menuBar = new JMenuBar();
//setJMenuBar(menuBar);
//ceate the first menu (file)
JMenu mFile = new JMenu("File");
mFile.setMnemonic(KeyEvent.VK_F);
mFile.getAccessibleContext().setAccessibleDescription("File Related");
menuBar.add(mFile);
//a group of JMenuItems
/*********************************
Open & Load Original Data
**********************************/
JMenuItem mif_open = new JMenuItem("Open", new ImageIcon("images/open.gif"));
mif_open.setMnemonic(KeyEvent.VK_O);
mFile.add(mif_open);
mif_open.setToolTipText("Open a chart");
mif_open.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser(".//data//ascii");
chooser.addChoosableFileFilter(new DataFilter());
chooser.setAcceptAllFileFilterUsed(false);
int returnVal = chooser.showOpenDialog(pane);
if(returnVal == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
graph.loadChart(file.getAbsolutePath());
graph.IndicatorNo = 0;
graph.resetInit();
cmdLine.setActiveChart(file.getPath());
//System.out.println(file.getPath());
currentfile = file.getName();
currentpath = file.getPath();
StringTokenizer st = new StringTokenizer(currentfile, ".");
currentcmp = st.nextToken();
}
}
});
/**************************************
Exit System
**************************************/
mFile.addSeparator();
JMenuItem mif_exit = new JMenuItem("Exit");
mif_exit.setMnemonic(KeyEvent.VK_E);
mFile.add(mif_exit);
mif_exit.setToolTipText("Exit CPL System");
mif_exit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
cmdLine.runHaskellCmd(":q\n");
System.exit(0);
}
});
//ceate the second menu (View)
JMenu mView = new JMenu("View");
mView.setMnemonic(KeyEvent.VK_V);
mView.getAccessibleContext().setAccessibleDescription("View Related");
menuBar.add(mView);
//a group of JMenuItems
/*************************************
Zoom In Button
*************************************/
JMenuItem miv_in = new JMenuItem("ZoomIn", new ImageIcon("images/zoomin.gif"));
miv_in.setMnemonic(KeyEvent.VK_I);
mView.add(miv_in);
miv_in.setToolTipText("Expand Time Axis");
miv_in.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if (graph.gap < 10){
graph.gap = graph.gap+1;
graph.repaint();
}
}
});
/**********************************
Zoom Out Button
**********************************/
JMenuItem miv_out = new JMenuItem("ZoomOut", new ImageIcon("images/zoomout.gif"));
miv_out.setMnemonic(KeyEvent.VK_O);
mView.add(miv_out);
miv_out.setToolTipText("Compress Time Axis");
miv_out.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if (graph.gap > 1){
graph.gap = graph.gap-1;
graph.repaint();
}
}
});
//ceate the third menu (Indicator)
JMenu mIndicator = new JMenu("Indicator");
mIndicator.setMnemonic(KeyEvent.VK_I);
mIndicator.getAccessibleContext().setAccessibleDescription("Indicator Related");
menuBar.add(mIndicator);
//a group of JMenuItems
/**************************************
Create New Indicator Definition
**************************************/
JMenuItem mii_new = new JMenuItem("New");
mii_new.setMnemonic(KeyEvent.VK_N);
mIndicator.add(mii_new);
mii_new.setToolTipText("Create New Indicator");
mii_new.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
MyEditor dlg = new MyEditor("Indicator");
dlg.setSize(600, 600);
dlg.setTitle("New");
dlg.show();
String cmd = dlg.dlg.getFileName();
if(!cmd.equals("")){
cmdLine.runHaskellCmd(":r\n");
}
}
});
/**************************************
Delete User Created Indicator Button
**************************************/
JMenuItem mii_delete = new JMenuItem("Delete");
mii_delete.setMnemonic(KeyEvent.VK_D);
mIndicator.add(mii_delete);
mii_delete.setToolTipText("Delete Indicator");
mii_delete.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
MySelect dlg = new MySelect("Delete", "Indicator");
dlg.setTitle("Select Indicator");
dlg.setSize(new Dimension(300, 200));
dlg.show();
String cmd = dlg.dlg.getFileName();
if(!cmd.equals("")){
cmdLine.runHaskellCmd(":r\n");
}
}
});
/**************************************
Modify User Created Indicator Button
**************************************/
JMenuItem mii_modify = new JMenuItem("Modify");
mii_modify.setMnemonic(KeyEvent.VK_M);
mIndicator.add(mii_modify);
mii_modify.setToolTipText("Modify Indicator");
mii_modify.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JFileChooser chooser = new JFileChooser(".//Indicators");
chooser.addChoosableFileFilter(new IndicatorFilter());
chooser.setAcceptAllFileFilterUsed(false);
int returnVal = chooser.showOpenDialog(pane);
if(returnVal == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
currentpath = file.getPath();
try{
child = Runtime.getRuntime().exec("D:\\emacs-21.3\\bin\\runemacs.exe " + currentpath);
}catch(IOException runerror){
System.err.println("Test!");
}
}
/*
MySelect dlg = new MySelect("Modify", "Indicator");
dlg.setTitle("Select Indicator");
dlg.setSize(new Dimension(300, 200));
dlg.show();
String cmd = dlg.dlg.getFileName();
if(!cmd.equals("")){
cmdLine.runHaskellCmd(":r\n");
}
*/
}
});
/**************************************
View User Created Indicators
**************************************/
JMenuItem mii_view = new JMenuItem("View");
mii_view.setMnemonic(KeyEvent.VK_V);
mIndicator.add(mii_view);
mii_view.setToolTipText("View Indicator");
mii_view.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
MySelect dlg = new MySelect("View", "Indicator");
dlg.setTitle("Select Indicator");
dlg.setSize(new Dimension(300, 200));
dlg.show();
}
});
/**************************************
View Indicator Graph
**************************************/
JMenuItem mii_viewg = new JMenuItem("View Graph ...");
mii_viewg.setMnemonic(KeyEvent.VK_C);
mIndicator.add(mii_viewg);
mii_viewg.setToolTipText("Combine View Indicator");
mii_viewg.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(graph.hasInd()==false){
Frame parent = new Frame("Parent");
AlertDlg dlg = new AlertDlg(parent, true, 0);
}
else{
int IndicatorNo = graph.getIndicatorNo();
MyIndSaver dlg = new MyIndSaver(currentpath, IndicatorNo, graph.getIndNames(), "view");
dlg.setSize(400, 300);
dlg.setTitle("View Indicator Graph");
dlg.show();
if(dlg.actived){
int[] choice = dlg.getChoice();
String[] ti_names = dlg.getIndNames();
MyDate[] ti_date = graph.getDate();
float[][] ti_datas = graph.getTI();
int noBars = graph.noOfPoints;
combineIndView(ti_datas, ti_date, ti_names, noBars, choice, IndicatorNo);
}
}
}
});
/**************************************
Eval Sub Menu
**************************************/
JMenu mind_sub_eval = new JMenu("Eval");
mind_sub_eval.setMnemonic(KeyEvent.VK_E);
//create the submenu of the menu Indicator (System)
//mIndicator.addSeparator();
JMenu mind_sub_system = new JMenu("System Indicators");
mind_sub_system.setMnemonic(KeyEvent.VK_S);
/*****************************************
Moving Average
*****************************************/
JMenuItem mii_movingavg = new JMenuItem("Moving Average");
mii_movingavg.setMnemonic(KeyEvent.VK_M);
mind_sub_system.add(mii_movingavg);
mii_movingavg.setToolTipText("Calculate Indicator");
mii_movingavg.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(graph.IndicatorNo>=5){
Frame parent = new Frame("Parent");
AlertDlg dlg = new AlertDlg(parent, true, 2);
//dlg.show();
}
else if(currentfile.equals("")){
Frame parent = new Frame("Parent");
AlertDlg dlg = new AlertDlg(parent, true, 1);
//dlg.show();
}
else{
MyMovingAvg dlg = new MyMovingAvg(parent);
dlg.setSize(600, 200);
dlg.setTitle("Moving Average Parameters");
dlg.show();
if(dlg.dlg.thereIsInd){
String Ind_fun = "movingAvg";
String base_day = dlg.dlg.basedays_s;
String base_value = dlg.dlg.basevalue_s;
String cmd = Ind_fun + " " + base_day + " " + base_value;
graph.setIndFunc(cmd);
cmd_ind = "evalDisplay \""+ currentcmp+"/"+currentfile + "\" (" + cmd + ")\n";
cmdLine.runHaskellCmd(cmd_ind);
}
}
}
});
/*
JMenuItem mii_tprice = new JMenuItem("Tprice");
mii_tprice.setMnemonic(KeyEvent.VK_T);
mind_sub_system.add(mii_tprice);
mii_tprice.setToolTipText("Calculate Indicator");
mii_tprice.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(graph.IndicatorNo>=5){
Frame parent = new Frame("Parent");
AlertDlg dlg = new AlertDlg(parent, true, 2);
//dlg.show();
}
else if(currentfile.equals("")){
Frame parent = new Frame("Parent");
AlertDlg dlg = new AlertDlg(parent, true, 1);
//dlg.show();
}
else{
graph.setIndFunc("tprice");
cmd_ind = "evalDisplay \""+ currentcmp+"/"+currentfile + "\" tprice\n";
cmdLine.runHaskellCmd(cmd_ind);
}
}
});
*/
mind_sub_eval.add(mind_sub_system);
//create the menu item of the menu Indicator (User)
JMenuItem mii_user = new JMenuItem("User Defined Indicators");
mii_user.setMnemonic(KeyEvent.VK_U);
mind_sub_eval.add(mii_user);
mii_user.setToolTipText("User Defined Indicator");
mii_user.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(graph.IndicatorNo>=5){
Frame parent = new Frame("Parent");
AlertDlg dlg = new AlertDlg(parent, true, 2);
//dlg.show();
}
else if(currentfile.equals("")){
Frame parent = new Frame("Parent");
AlertDlg dlg = new AlertDlg(parent, true, 1);
//dlg.show();
}
else{
MySelectAction dlg = new MySelectAction(0);
dlg.setTitle("Select Indicator");
dlg.setSize(new Dimension(500, 300));
dlg.show();
if(dlg.dlg.getFunc()!= ""){
graph.setIndFunc(dlg.dlg.getFunc());
cmd_ind = "evalDisplay \""+ currentcmp+"/"+currentfile + "\" " + dlg.dlg.getFunc() + "\n";
cmdLine.runHaskellCmd(cmd_ind);
}
}
}
});
mIndicator.add(mind_sub_eval);
//ceate the fourth menu (Pattern)
JMenu mPattern = new JMenu("Pattern");
mPattern.setMnemonic(KeyEvent.VK_P);
mPattern.getAccessibleContext().setAccessibleDescription("Pattern Related");
menuBar.add(mPattern);
//a group of JMenuItems
/**************************************
Create New Pattern Definition
**************************************/
JMenuItem mip_new = new JMenuItem("New");
mip_new.setMnemonic(KeyEvent.VK_N);
mPattern.add(mip_new);
mip_new.setToolTipText("Create New Pattern");
mip_new.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
MyEditor dlg = new MyEditor("Pattern");
dlg.setSize(600, 600);
dlg.setTitle("New");
dlg.show();
String cmd = dlg.dlg.getFileName();
if(!cmd.equals("")){
cmdLine.runHaskellCmd(":r\n");
}
}
});
/**************************************
Delete User Created Pattern
**************************************/
JMenuItem mip_delete = new JMenuItem("Delete");
mip_delete.setMnemonic(KeyEvent.VK_D);
mPattern.add(mip_delete);
mip_delete.setToolTipText("Delete Pattern");
mip_delete.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
MySelect dlg = new MySelect("Delete", "Pattern");
dlg.setTitle("Select Pattern");
dlg.setSize(new Dimension(300, 200));
dlg.show();
String cmd = dlg.dlg.getFileName();
if(!cmd.equals("")){
cmdLine.runHaskellCmd(":r\n");
}
}
});
/**************************************
Modify User Created Pattern
**************************************/
JMenuItem mip_modify = new JMenuItem("Modify");
mip_modify.setMnemonic(KeyEvent.VK_M);
mPattern.add(mip_modify);
mip_modify.setToolTipText("Modify Pattern");
mip_modify.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JFileChooser chooser = new JFileChooser(".//Patterns");
chooser.addChoosableFileFilter(new IndicatorFilter());
chooser.setAcceptAllFileFilterUsed(false);
int returnVal = chooser.showOpenDialog(pane);
if(returnVal == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
currentpath = file.getPath();
try{
child = Runtime.getRuntime().exec("D:\\emacs-21.3\\bin\\runemacs.exe " + currentpath);
}catch(IOException runerror){
System.err.println("Test!");
}
}
/*
MySelect dlg = new MySelect("Modify", "Pattern");
dlg.setTitle("Select Pattern");
dlg.setSize(new Dimension(300, 200));
dlg.show();
String cmd = dlg.dlg.getFileName();
if(!cmd.equals("")){
cmdLine.runHaskellCmd(":r\n");
}
*/
}
});
/**************************************
View User Created Pattern
**************************************/
JMenuItem mip_view = new JMenuItem("View");
mip_view.setMnemonic(KeyEvent.VK_V);
mPattern.add(mip_view);
mip_view.setToolTipText("View Pattern");
mip_view.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
MySelect dlg = new MySelect("View", "Pattern");
dlg.setSize(new Dimension(300, 200));
dlg.setTitle("Select Pattern");
dlg.show();
}
});
/**************************************
Browse Sub Menu
**************************************/
JMenu mpat_sub_browse = new JMenu("Browse");
mpat_sub_browse.setMnemonic(KeyEvent.VK_B);
//create the submenu of the menu Indicator (System)
//mPattern.addSeparator();
JMenu mpat_sub_system = new JMenu("System Patterns");
mpat_sub_system.setMnemonic(KeyEvent.VK_S);
/***********************************
hdR
***********************************/
JMenuItem mip_hdR = new JMenuItem("header & shoulder");
mip_hdR.setMnemonic(KeyEvent.VK_R);
mpat_sub_system.add(mip_hdR);
mip_hdR.setToolTipText("Find hdR");
mip_hdR.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(currentfile.equals("")){
Frame parent = new Frame("Parent");
AlertDlg dlg = new AlertDlg(parent, true, 1);
//dlg.show();
}
else{
String cmd = "browse hdR \""+ currentcmp+"/"+currentfile + "\"\n";
cmdLine.runHaskellCmd(cmd);
}
}
});
mpat_sub_browse.add(mpat_sub_system);
//create the menu item of the menu Pattern (User)
JMenuItem mip_user = new JMenuItem("User Defined Patterns");
mip_user.setMnemonic(KeyEvent.VK_U);
mpat_sub_browse.add(mip_user);
mip_user.setToolTipText("User Defined Pattern");
mip_user.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(currentfile.equals("")){
Frame parent = new Frame("Parent");
AlertDlg dlg = new AlertDlg(parent, true, 1);
//dlg.show();
}
else{
MySelectAction dlg = new MySelectAction(1);
dlg.setTitle("Select Pattern");
dlg.setSize(new Dimension(500, 300));
dlg.show();
if(dlg.dlg.getFunc()!=""){
cmd_ind = "browse " + dlg.dlg.getFunc() + " \""+ currentcmp+"/"+currentfile + "\"\n";
cmdLine.runHaskellCmd(cmd_ind);
}
}
}
});
mPattern.add(mpat_sub_browse);
//ceate the fifth menu (Indicator Data)
JMenu mData = new JMenu("Data");
mData.setMnemonic(KeyEvent.VK_D);
mData.getAccessibleContext().setAccessibleDescription("Data Related");
menuBar.add(mData);
//a group of JMenuItems
/**************************************
Save to New Data File
**************************************/
JMenuItem mid_saveas = new JMenuItem("Save as ...");
mid_saveas.setMnemonic(KeyEvent.VK_A);
mData.add(mid_saveas);
mid_saveas.setToolTipText("Save Indicator Data to a New File");
mid_saveas.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(graph.hasInd()==false){
Frame parent = new Frame("Parent");
AlertDlg dlg = new AlertDlg(parent, true, 0);
}
else{
int IndicatorNo = graph.getIndicatorNo();
MyIndSaver dlg = new MyIndSaver(currentpath, IndicatorNo, graph.getIndNames());
dlg.setSize(400, 300);
dlg.setTitle("Save Indicator Data");
dlg.show();
if(dlg.actived){
int[] choice = dlg.getChoice();
String[] ind_names = dlg.getIndNames();
String fileDir = dlg.getFiledir();
//String formDir = dlg.getFordir();
int[] enddays = graph.getEndDay();
int[] startdays = graph.getStartDay();
//String[] funcs = graph.getIndFuncs();
MyDate[] dates = graph.getDate();
float[][] ti_datas = graph.getTI();
int min_start = -1;
int max_end = -1;
for(int i = 0; i<IndicatorNo; i++){
if(choice[i] == 1){
if(min_start>startdays[i] || min_start<0)
min_start = startdays[i];
if(max_end<enddays[i] || max_end<0)
max_end = enddays[i];
}
}
try{
BufferedWriter fileout = new BufferedWriter(new FileWriter(fileDir));
BufferedWriter fileout_for = new BufferedWriter(new FileWriter(fileDir+".for"));
String temp = new String();
//String temp_f = new String();
temp = temp.concat("date\t");
for(int i = 0; i< IndicatorNo; i++){
if(choice[i] == 1){
temp = temp.concat(ind_names[i] + "\t");
//temp_f = temp_f.concat(ind_names[i] + " : " + funcs[i] + "\n");
}
}
fileout.write(temp.trim());
fileout.newLine();
for(int i = 0; i<max_end; i++){
temp = new String();
temp = temp.concat(dates[i]+ "\t");
for(int j = 0; j< IndicatorNo; j++){
if(choice[j] == 1){
temp = temp.concat(ti_datas[j][i]+"\t");
}
}
fileout.write(temp.trim());
fileout.newLine();
}
//fileout_for.write(temp_f.trim());
//fileout_for.flush();
//fileout_for.close();
fileout.flush();
fileout.close();
Frame parent = new Frame("Parent");
AlertDlg savenotice = new AlertDlg(parent, true, 6);
graph.ind_names = ind_names;
graph.repaint();
}
catch (Exception er){
System.err.println("Write error: "+er.getMessage());
}
}
}
}
});
/**************************************
Save with Exist File (combine)
**************************************/
JMenuItem mid_savewith = new JMenuItem();
mid_savewith.setText("Save with Original Data as ...");
mid_savewith.setMnemonic(KeyEvent.VK_W);
mData.add(mid_savewith);
mid_savewith.setToolTipText("Save Indicator Data with Original Data to a New File");
mid_savewith.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(graph.hasInd()==false){
Frame parent = new Frame("Parent");
AlertDlg dlg = new AlertDlg(parent, true, 0);
}
else{
int IndicatorNo = graph.getIndicatorNo();
MyIndSaver dlg = new MyIndSaver(currentpath, IndicatorNo, graph.getIndNames());
dlg.setSize(400, 300);
dlg.setTitle("Save Indicator Data");
dlg.show();
if(dlg.actived){
int[] choice = dlg.getChoice();
String[] ind_names = dlg.getIndNames();
String fileDir = dlg.getFiledir();
//String formDir = dlg.getFordir();
int[] enddays = graph.getEndDay();
int[] startdays = graph.getStartDay();
float[][] ti_datas = graph.getTI();
int min_start = -1;
int max_end = -1;
//here may improve... in fact the startdays are all 0
//and the enddays are all the size of the array
for(int i = 0; i<IndicatorNo; i++){
if(choice[i] == 1){
if(min_start>startdays[i] || min_start<0)
min_start = startdays[i];
if(max_end<enddays[i] || max_end<0)
max_end = enddays[i];
}
}
try{
BufferedReader filein = new BufferedReader(new FileReader(currentpath));
BufferedWriter fileout = new BufferedWriter(new FileWriter(fileDir));
String temp = new String();
String original_s = filein.readLine();
StringTokenizer st = new StringTokenizer(original_s);
while(st.hasMoreTokens())
temp = temp.concat(st.nextToken() + "\t");
for(int i = 0; i< IndicatorNo; i++){
if(choice[i] == 1){
temp = temp.concat(ind_names[i] + "\t");
}
}
fileout.write(temp.trim());
fileout.newLine();
for(int i = 0; i<max_end; i++){
original_s = new String();
temp = new String();
original_s = filein.readLine();
st = new StringTokenizer(original_s);
while(st.hasMoreTokens())
temp = temp.concat(st.nextToken() + "\t");
for(int j = 0; j< IndicatorNo; j++){
if(choice[j] == 1){
temp = temp.concat(ti_datas[j][i]+"\t");
}
}
fileout.write(temp.trim());
fileout.newLine();
}
filein.close();
fileout.flush();
fileout.close();
Frame parent = new Frame("Parent");
AlertDlg savenotice = new AlertDlg(parent, true, 6);
graph.ind_names = ind_names;
graph.repaint();
}
catch (Exception er){
System.err.println("Write error: "+er.getMessage());
}
}
}
}
});
/**************************************
Combine 2 Files (Base on Date)
**************************************/
JMenuItem mid_combine = new JMenuItem("Combine ...");
mid_combine.setMnemonic(KeyEvent.VK_C);
mData.add(mid_combine);
mid_combine.setToolTipText("combine 2 Data Files");
mid_combine.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
MyCombineDlg dlg = new MyCombineDlg();
dlg.setSize(new Dimension(600, 250));
dlg.setTitle("Select Files");
dlg.show();
}
});
/**************************************
Load Indicator Data
**************************************/
JMenuItem mid_load = new JMenuItem("Load ...");
mid_load.setMnemonic(KeyEvent.VK_L);
mData.add(mid_load);
mid_load.setToolTipText("Load Formula");
mid_load.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser(".//data//ascii");
chooser.addChoosableFileFilter(new IndDataFilter());
chooser.setAcceptAllFileFilterUsed(false);
int returnVal = chooser.showOpenDialog(pane);
if(returnVal == JFileChooser.APPROVE_OPTION) {
try{
File file = chooser.getSelectedFile();
graph.loadIndicator(file.getAbsolutePath());
}
catch (Exception er){
System.err.println("Write error: "+er.getMessage());
}
}
}
});
/******************************
View Data
******************************/
JMenuItem mid_view = new JMenuItem("View ...");
mid_view.setMnemonic(KeyEvent.VK_V);
mData.add(mid_view);
mid_view.setToolTipText("About The System");
mid_view.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JFileChooser chooser = new JFileChooser(".//data//ascii");
chooser.addChoosableFileFilter(new DataFilter());
chooser.addChoosableFileFilter(new IndDataFilter());
chooser.setAcceptAllFileFilterUsed(false);
int returnVal = chooser.showOpenDialog(pane);
if(returnVal == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
MyTable table = new MyTable(file);
table.setTitle(file.getName());
table.setSize(700, 500);
table.show();
}
}
});
//ceate the sixth menu (Tools)
JMenu mSystem = new JMenu("System");
mSystem.setMnemonic(KeyEvent.VK_S);
mSystem.getAccessibleContext().setAccessibleDescription("System Setting Tools");
menuBar.add(mSystem);
JMenuItem mis_options = new JMenuItem("Options");
mis_options.setMnemonic(KeyEvent.VK_O);
mSystem.add(mis_options);
mis_options.setToolTipText("System Options");
mis_options.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
OptionDlg dlg = new OptionDlg();
dlg.setTitle("System Setting");
dlg.setSize(new Dimension(500, 600));
dlg.show();
if(dlg.actived){
AlertDlg recompile = new AlertDlg(parent, true, 10);
try{
child = Runtime.getRuntime().exec("CPL.bat");
}catch(IOException runerror){
System.err.println("Test!");
}
dispose();
}
}
});
JMenuItem mis_editor = new JMenuItem("Editor");
mis_editor.setMnemonic(KeyEvent.VK_E);
mSystem.add(mis_editor);
mis_editor.setToolTipText("Run Default Editor");
mis_editor.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
try{
child = Runtime.getRuntime().exec("D:\\emacs-21.3\\bin\\runemacs.exe");
}catch(IOException runerror){
System.err.println("Test!");
}
}
});
JMenuItem mis_reboot_c = new JMenuItem("Reboot CPL");
mSystem.add(mis_reboot_c);
mis_reboot_c.setToolTipText("Reboot System");
mis_reboot_c.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
try{
child = Runtime.getRuntime().exec("CPL.bat");
}catch(IOException runerror){
System.err.println("Test!");
}
dispose();
}
});
JMenuItem mis_reboot_h = new JMenuItem("Reboot Haskell");
mSystem.add(mis_reboot_h);
mis_reboot_h.setToolTipText("Reboot Haskell");
mis_reboot_h.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
cmdLine.runHaskellCmd(":r\n");
}
});
//ceate the seventh menu (Help)
JMenu mHelp = new JMenu("Help");
mHelp.setMnemonic(KeyEvent.VK_H);
mHelp.getAccessibleContext().setAccessibleDescription("System Related");
menuBar.add(mHelp);
JMenuItem mih_about = new JMenuItem("About");
mih_about.setMnemonic(KeyEvent.VK_A);
mHelp.add(mih_about);
mih_about.setToolTipText("About The System");
mih_about.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
AlertDlg dlg = new AlertDlg(parent, true, 4);
}
});
pane.add(menuBar, BorderLayout.NORTH);
pane.add(graph, BorderLayout.CENTER);
pane.add(cmdLine,BorderLayout.SOUTH);
pack();
setVisible(true);
MyListener myListener = new MyListener();
graph.addMouseListener(myListener);
graph.addMouseMotionListener(myListener);
}
class MyListener extends MouseInputAdapter {
/*
public void mouseMoved(MouseEvent e) {
saySomething("Mouse moved", e);
}
public void mouseDragged(MouseEvent e) {
saySomething("Mouse dragged", e);
}
public void mousePressed(MouseEvent e) {
saySomething("Mouse pressed", e);
}
public void mouseEntered(MouseEvent e) {
saySomething("Mouse entered", e);
}
void saySomething(String eventDescription, MouseEvent e) {
cmdLine.append(eventDescription
+ " (" + e.getX() + "," + e.getY() + ")"
+ " detected on "
+ e.getComponent().getClass().getName()
+ "\n");
//cmdLine.setCaretPosition(cmdLine.getDocument().getLength());
}
*/
}
public void combineIndView(float[][]ti_datas, MyDate[] ti_date, String[] ti_names,
int noBars, int[]choice, int IndicatorNo){
IndWin indwin = new IndWin(this, ti_datas, ti_date, ti_names, noBars, choice, IndicatorNo, currentpath);
indwin.setSize(new Dimension(608, 462));
//indwin.setSize(new Dimension(630, 480));
indwin.setTitle(currentfile +" - Technical Indicator ");
}
public void actOnDirective(String result){
if(result.equals("Failed")){
Frame parent = new Frame("Parent");
AlertDlg dlg = new AlertDlg(parent, true, 9);
if(dlg.action_a){
try{
BufferedReader stdin_cpl = new BufferedReader(new FileReader(".\\CPL.hs"));
String cpl_content = "";
String temp = stdin_cpl.readLine();
boolean cpl_ok = false;
while(temp != null){
if(!cpl_ok){
if(temp.equals("--user created start--")){
cpl_content = cpl_content + temp + "\n";
temp = stdin_cpl.readLine();
if(temp.equals("--user created end--")){
cpl_content = cpl_content + temp + "\n";
}
cpl_ok = true;
}
else{
cpl_content = cpl_content + temp + "\n";
}
}
else{
cpl_content = cpl_content + temp + "\n";
}
temp = stdin_cpl.readLine();
}
stdin_cpl.close();
BufferedWriter stdout_cpl = new BufferedWriter(new FileWriter(".\\CPL.hs"));
stdout_cpl.write(cpl_content.trim());
stdout_cpl.flush();
stdout_cpl.close();
}
catch (Exception er){
System.err.println("Write error: "+er.getMessage());
}
cmdLine.runHaskellCmd(":r\n");
}
else{}
}
else{
StringTokenizer st = new StringTokenizer(result);
String dir = st.nextToken().substring(11);//11 = length("_DIRECTIVE_")
if(dir.equals("BROWSE")){
if (st.hasMoreTokens()){
Browser browser = new Browser(this,st.nextToken());
}
else cmdLine.append("No pattern instances found\n");
}
else if(dir.equals("TI")){
if (st.hasMoreTokens()){
Techind tech = new Techind(this,st.nextToken());
int noInd = graph.IndicatorNo;
int noBars = graph.noOfPoints;
String ti_name = (graph.getIndNames())[noInd-1];
float[] ti_data = (graph.getTI())[noInd-1];
MyDate[] ti_date = graph.getDate();
IndWin indwin = new IndWin(this, ti_data, ti_date, noBars, ti_name, currentpath);
indwin.setSize(new Dimension(608, 462));
indwin.setTitle(currentfile +" - Technical Indicator " + graph.IndicatorNo);
}
else cmdLine.append("No Indicator instances found\n");
}