-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewApplication.java
More file actions
1075 lines (948 loc) · 49.2 KB
/
NewApplication.java
File metadata and controls
1075 lines (948 loc) · 49.2 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 java.awt.Desktop;
import java.awt.HeadlessException;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ScrollPaneConstants;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JViewport;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import javax.swing.event.UndoableEditEvent;
import javax.swing.event.UndoableEditListener;
import javax.swing.undo.CannotRedoException;
import javax.swing.undo.CannotUndoException;
import javax.swing.undo.UndoManager;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author user
*/
public class NewApplication extends javax.swing.JFrame {
public File s;
private Vector v = new Vector(); // v stores all saved Files
public String latestCompiled;
public File latestCompiledFilePath;
UndoManager undo = new UndoManager();
public Vector compiledCFilePaths = new Vector(); // this vector stores all compiled files
File filePath;
public int flag; //flag check what user want ,it will be 1 when compile ,2 when run only , 3 when compile and run
int flagOngoing = 0;
// public String cutString; //stores cut string from JTextArea
public String selectedString; //stores selected String
/**
* Creates new form NewApplication
*/
public NewApplication() {
initComponents();
flag = 1;
}
boolean isValid(String nameFile) {
String g = ""; // g is just a temporary string
int l = nameFile.lastIndexOf('.');
if (l == -1) {
return false;
}
g = nameFile.substring(l + 1, nameFile.length());
if (g.equals("c") || g.equals("cpp") || g.equals("java")) { // checking validity of file
return true;
} else {
return false;
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
popupMenu1 = new javax.swing.JPopupMenu();
changeFont = new javax.swing.JMenuItem();
cutButton = new javax.swing.JMenuItem();
copyButton = new javax.swing.JMenuItem();
pasteButton = new javax.swing.JMenuItem();
close = new javax.swing.JPopupMenu();
closeTab = new javax.swing.JMenuItem();
jDesktopPane1 = new javax.swing.JDesktopPane();
jLabel1 = new javax.swing.JLabel();
jTabbedPane = new javax.swing.JTabbedPane();
outputAndCompileLog = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
consoleWindow = new javax.swing.JTextArea();
jScrollPane2 = new javax.swing.JScrollPane();
inputArea = new javax.swing.JTextArea();
jLabel4 = new javax.swing.JLabel();
cursor = new javax.swing.JLabel();
label = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
menuBar = new javax.swing.JMenuBar();
fileMenu = new javax.swing.JMenu();
jMenu1 = new javax.swing.JMenu();
newFile = new javax.swing.JMenuItem();
openMenuItem = new javax.swing.JMenuItem();
saveMenuItem = new javax.swing.JMenuItem();
saveAsMenuItem = new javax.swing.JMenuItem();
exitMenuItem = new javax.swing.JMenuItem();
editMenu = new javax.swing.JMenu();
cutMenuItem = new javax.swing.JMenuItem();
copyMenuItem = new javax.swing.JMenuItem();
pasteMenuItem = new javax.swing.JMenuItem();
undoIt = new javax.swing.JMenuItem();
redoIt = new javax.swing.JMenuItem();
jMenuItem1 = new javax.swing.JMenuItem();
deleteMenuItem = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
compileMe = new javax.swing.JMenuItem();
runMe = new javax.swing.JMenuItem();
compileAndRunMe = new javax.swing.JMenuItem();
jMenu4 = new javax.swing.JMenu();
closeAll = new javax.swing.JMenuItem();
helpMenu = new javax.swing.JMenu();
jMenu3 = new javax.swing.JMenu();
openGeeks = new javax.swing.JMenuItem();
openCodechef = new javax.swing.JMenuItem();
stackOverflow = new javax.swing.JMenuItem();
aboutMenuItem = new javax.swing.JMenuItem();
changeFont.setText("Change Font");
changeFont.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
changeFontActionPerformed(evt);
}
});
popupMenu1.add(changeFont);
cutButton.setText("jMenuItem4");
cutButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cutButtonActionPerformed(evt);
}
});
popupMenu1.add(cutButton);
copyButton.setText("jMenuItem5");
copyButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
copyButtonActionPerformed(evt);
}
});
popupMenu1.add(copyButton);
pasteButton.setText("jMenuItem6");
popupMenu1.add(pasteButton);
closeTab.setText("Close");
closeTab.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
closeTabActionPerformed(evt);
}
});
close.add(closeTab);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("IDE");
jLabel1.setFont(new java.awt.Font("Tahoma", 3, 18)); // NOI18N
jLabel1.setText("Happy Coding!!!");
jTabbedPane.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseReleased(java.awt.event.MouseEvent evt) {
jTabbedPaneMouseReleased(evt);
}
});
outputAndCompileLog.setText("Compilation Log");
consoleWindow.setEditable(false);
consoleWindow.setColumns(20);
consoleWindow.setRows(5);
jScrollPane1.setViewportView(consoleWindow);
inputArea.setColumns(20);
inputArea.setRows(5);
jScrollPane2.setViewportView(inputArea);
jLabel4.setText("Input");
jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
jLabel2.setText("Mouse Moving At :");
jDesktopPane1.setLayer(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane1.setLayer(jTabbedPane, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane1.setLayer(outputAndCompileLog, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane1.setLayer(jScrollPane1, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane1.setLayer(jScrollPane2, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane1.setLayer(jLabel4, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane1.setLayer(cursor, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane1.setLayer(label, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane1.setLayer(jLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);
javax.swing.GroupLayout jDesktopPane1Layout = new javax.swing.GroupLayout(jDesktopPane1);
jDesktopPane1.setLayout(jDesktopPane1Layout);
jDesktopPane1Layout.setHorizontalGroup(
jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jDesktopPane1Layout.createSequentialGroup()
.addGroup(jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1)
.addComponent(outputAndCompileLog, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(label, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane2)))
.addGroup(jDesktopPane1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 163, Short.MAX_VALUE)
.addGap(18, 18, 18)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(cursor, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addComponent(jTabbedPane)
);
jDesktopPane1Layout.setVerticalGroup(
jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jDesktopPane1Layout.createSequentialGroup()
.addGroup(jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(cursor, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(label, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jDesktopPane1Layout.createSequentialGroup()
.addComponent(outputAndCompileLog, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(4, 4, 4)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jScrollPane1)
.addComponent(jScrollPane2)))
);
fileMenu.setMnemonic('f');
fileMenu.setText("File");
jMenu1.setText("New");
newFile.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
newFile.setText("New File");
newFile.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
newFileActionPerformed(evt);
}
});
jMenu1.add(newFile);
fileMenu.add(jMenu1);
openMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
openMenuItem.setMnemonic('o');
openMenuItem.setText("Open");
openMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
openMenuItemActionPerformed(evt);
}
});
fileMenu.add(openMenuItem);
saveMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
saveMenuItem.setMnemonic('s');
saveMenuItem.setText("Save");
saveMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
saveMenuItemActionPerformed(evt);
}
});
fileMenu.add(saveMenuItem);
saveAsMenuItem.setMnemonic('a');
saveAsMenuItem.setText("Save As ...");
saveAsMenuItem.setDisplayedMnemonicIndex(5);
saveAsMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
saveAsMenuItemActionPerformed(evt);
}
});
fileMenu.add(saveAsMenuItem);
exitMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
exitMenuItem.setMnemonic('x');
exitMenuItem.setText("Exit");
exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
exitMenuItemActionPerformed(evt);
}
});
fileMenu.add(exitMenuItem);
menuBar.add(fileMenu);
editMenu.setMnemonic('e');
editMenu.setText("Edit");
cutMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
cutMenuItem.setMnemonic('t');
cutMenuItem.setText("Cut");
cutMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cutMenuItemActionPerformed(evt);
}
});
editMenu.add(cutMenuItem);
copyMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
copyMenuItem.setMnemonic('y');
copyMenuItem.setText("Copy");
copyMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
copyMenuItemActionPerformed(evt);
}
});
editMenu.add(copyMenuItem);
pasteMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.CTRL_MASK));
pasteMenuItem.setMnemonic('p');
pasteMenuItem.setText("Paste");
pasteMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
pasteMenuItemActionPerformed(evt);
}
});
editMenu.add(pasteMenuItem);
undoIt.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Z, java.awt.event.InputEvent.CTRL_MASK));
undoIt.setText("Undo");
undoIt.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
undoItActionPerformed(evt);
}
});
editMenu.add(undoIt);
redoIt.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Y, java.awt.event.InputEvent.CTRL_MASK));
redoIt.setText("Redo");
redoIt.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
redoItActionPerformed(evt);
}
});
editMenu.add(redoIt);
jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_SLASH, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem1.setText("Comment");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});
editMenu.add(jMenuItem1);
deleteMenuItem.setMnemonic('d');
deleteMenuItem.setText("Delete");
deleteMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
deleteMenuItemActionPerformed(evt);
}
});
editMenu.add(deleteMenuItem);
menuBar.add(editMenu);
jMenu2.setText("Execute");
compileMe.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F9, 0));
compileMe.setText("Compile");
compileMe.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
compileMeActionPerformed(evt);
}
});
jMenu2.add(compileMe);
runMe.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F6, java.awt.event.InputEvent.SHIFT_MASK));
runMe.setText("Run");
runMe.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
runMeActionPerformed(evt);
}
});
jMenu2.add(runMe);
compileAndRunMe.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F11, 0));
compileAndRunMe.setText("Compile & Run");
compileAndRunMe.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
compileAndRunMeActionPerformed(evt);
}
});
jMenu2.add(compileAndRunMe);
menuBar.add(jMenu2);
jMenu4.setText("Windows");
closeAll.setText("Close All");
closeAll.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
closeAllActionPerformed(evt);
}
});
jMenu4.add(closeAll);
menuBar.add(jMenu4);
helpMenu.setMnemonic('h');
helpMenu.setText("Help");
jMenu3.setText("Contents");
openGeeks.setText("C++");
openGeeks.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
openGeeksActionPerformed(evt);
}
});
jMenu3.add(openGeeks);
openCodechef.setText("Codechef");
openCodechef.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
openCodechefActionPerformed(evt);
}
});
jMenu3.add(openCodechef);
helpMenu.add(jMenu3);
stackOverflow.setText("Stack Overflow");
stackOverflow.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
stackOverflowActionPerformed(evt);
}
});
helpMenu.add(stackOverflow);
aboutMenuItem.setMnemonic('a');
aboutMenuItem.setText("About Developers");
aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
aboutMenuItemActionPerformed(evt);
}
});
helpMenu.add(aboutMenuItem);
menuBar.add(helpMenu);
setJMenuBar(menuBar);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jDesktopPane1, javax.swing.GroupLayout.Alignment.TRAILING)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jDesktopPane1)
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
if (jTabbedPane.getTabCount() >= 1) {
int t = jTabbedPane.getTabCount();
int dialogButton2 = JOptionPane.YES_NO_OPTION;
JOptionPane.showConfirmDialog(null, "Safe Files Or Not?", null, dialogButton2); //showing dialog box to save files
if (dialogButton2 == JOptionPane.YES_OPTION) {
for (int i = 0; i < t; i++) {
int dialogButton = JOptionPane.YES_NO_OPTION;
JOptionPane.showConfirmDialog(null, "Would you like to save your file," + jTabbedPane.getTitleAt(jTabbedPane.getSelectedIndex()) + "?", "Warning", dialogButton);
if (dialogButton == JOptionPane.YES_OPTION) {
saveMenuItemActionPerformed(evt);
}
jTabbedPane.removeTabAt(jTabbedPane.getSelectedIndex());
jTabbedPane.setSelectedIndex(jTabbedPane.getTabCount() - 1);
}
}
}
System.exit(0);
}//GEN-LAST:event_exitMenuItemActionPerformed
private void newFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newFileActionPerformed
ClassForCodeAreaTab newTab = new ClassForCodeAreaTab(this);
final JTextArea editArea = newTab.codeArea;
newTab.codeArea.addCaretListener(new CaretListener() { //to tell position of caret
public void caretUpdate(CaretEvent e) {
int linenum = 0, columnnum = 0;
try {
linenum = 1;
columnnum = 1;
} catch (Exception exp) {
exp.printStackTrace();
}
try {
int caretpos = editArea.getCaretPosition();
linenum = editArea.getLineOfOffset(caretpos);
columnnum = caretpos - editArea.getLineStartOffset(linenum);
linenum += 1;
} catch (Exception ex) {
ex.printStackTrace();
}
updateStatus(linenum, columnnum);
}
});
// newTab.codeArea.removeCaretListener();
updateStatus(1, 1);
JScrollPane scroll;
scroll = new JScrollPane(newTab.codeArea);
scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
JViewport viewport = scroll.getViewport(); // first extract viewport from scrollpane then extract JTextArea from Viewport
JTextArea area = (JTextArea) viewport.getView();
jTabbedPane.addTab("Untitled" + (jTabbedPane.getTabCount() + 1), scroll);
jTabbedPane.setSelectedIndex(jTabbedPane.getTabCount() - 1);
consoleWindow.setText("");
scroll = (JScrollPane) jTabbedPane.getSelectedComponent();
viewport = scroll.getViewport(); // first extract viewport from scrollpane then extract JTextArea from Viewport
area = (JTextArea) viewport.getView();
area.getDocument().addUndoableEditListener(
new UndoableEditListener() {
@Override
public void undoableEditHappened(UndoableEditEvent e) {
undo.addEdit(e.getEdit());
}
});
}//GEN-LAST:event_newFileActionPerformed
private void updateStatus(int linenumber, int columnnumber) { //update label of line and column number
label.setText("Line: " + linenumber + " Column: " + columnnumber);
}
private void copyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_copyButtonActionPerformed
}//GEN-LAST:event_copyButtonActionPerformed
private void cutButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cutButtonActionPerformed
}//GEN-LAST:event_cutButtonActionPerformed
private void changeFontActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_changeFontActionPerformed
}//GEN-LAST:event_changeFontActionPerformed
private void saveMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveMenuItemActionPerformed
if (jTabbedPane.getTabCount() != 0) {
try {
JScrollPane scroll = (JScrollPane) jTabbedPane.getSelectedComponent();
JViewport viewport = scroll.getViewport(); // first extract viewport from scrollpane then extract JTextArea from Viewport
JTextArea area = (JTextArea) viewport.getView();
String currentTitle = jTabbedPane.getTitleAt(jTabbedPane.getSelectedIndex());
int found = 0;
try {
Iterator<File> itr = v.iterator();
while (itr.hasNext()) {
if (itr.next().getName().equals(currentTitle)) {
found = 1;
}
}
} catch (Exception e) {
e.printStackTrace();
}
if (found == 0) {
JFileChooser chooser = new JFileChooser();
int chooserValue = 0; //show dialog box
chooserValue = chooser.showSaveDialog(this);
try {
s = chooser.getSelectedFile(); // s will be selected file
if (s.getName() != null) {
while (!isValid(s.getName())) {
JOptionPane.showMessageDialog(this, "Enter Valid Extension!!");
chooserValue = chooser.showSaveDialog(this);
s = chooser.getSelectedFile();
}
if (chooserValue == JFileChooser.APPROVE_OPTION) {
try {
PrintWriter fout = new PrintWriter(s);
fout.print(area.getText());
fout.close();
v.addElement(s);
jTabbedPane.setTitleAt(jTabbedPane.getSelectedIndex(), s.getName());
} catch (FileNotFoundException ex) {
Logger.getLogger(NewApplication.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
} catch (HeadlessException e) {
}
} else {
PrintWriter fout = null;
try {
fout = new PrintWriter(s);
// System.out.println(area.getText());
fout.print(area.getText());
fout.close();
} catch (FileNotFoundException ex) {
Logger.getLogger(NewApplication.class.getName()).log(Level.SEVERE, null, ex);
}
fout.close();//just save matter
}
} catch (HeadlessException e) { //Thrown when code that is dependent on a keyboard, display, or mouse is called in an environment that does not support a keyboard, display, or mouse.
}
}
}//GEN-LAST:event_saveMenuItemActionPerformed
private void saveAsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveAsMenuItemActionPerformed
if (jTabbedPane.getTabCount() != 0) {
try {
JScrollPane scroll = (JScrollPane) jTabbedPane.getSelectedComponent();
JViewport viewport = scroll.getViewport(); // first extract viewport from scrollpane then extract JTextArea from Viewport
JTextArea area = (JTextArea) viewport.getView();
JFileChooser chooser = new JFileChooser();
int chooserValue;
chooserValue = chooser.showSaveDialog(this);
s = chooser.getSelectedFile();
if (s != null) {
while (!isValid(s.getName())) {
JOptionPane.showMessageDialog(this, "Enter Valid Extension!!");
chooserValue = chooser.showSaveDialog(this);
s = chooser.getSelectedFile();
}
if (!v.contains(s)) {
v.addElement(s);
jTabbedPane.setTitleAt(jTabbedPane.getSelectedIndex(), s.getName());
}
if (chooserValue == JFileChooser.APPROVE_OPTION) {
try {
try (PrintWriter fout = new PrintWriter(s)) {
fout.print(area.getText());
}
} catch (FileNotFoundException ex) {
Logger.getLogger(NewApplication.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
} catch (HeadlessException e) {
}
}
}//GEN-LAST:event_saveAsMenuItemActionPerformed
private void openMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openMenuItemActionPerformed
JFileChooser chooser = new JFileChooser();
int chooserValue = chooser.showOpenDialog(this);
if (chooserValue == JFileChooser.APPROVE_OPTION) {
try {
Scanner fin = new Scanner(chooser.getSelectedFile());
s = chooser.getSelectedFile();
v.add(s);
ClassForCodeAreaTab area = new ClassForCodeAreaTab(this);
area.codeArea.addCaretListener(new CaretListener() {
public void caretUpdate(CaretEvent e) {
JTextArea editArea = (JTextArea) e.getSource();
int linenum = 1;
int columnnum = 1;
try {
int caretpos = editArea.getCaretPosition();
linenum = editArea.getLineOfOffset(caretpos);
columnnum = caretpos - editArea.getLineStartOffset(linenum);
linenum += 1;
} catch (Exception ex) {
}
// Once we know the position of the line and the column, pass it to a helper function for updating the status bar.
updateStatus(linenum, columnnum);
}
});
updateStatus(1, 1);
JScrollPane scroll = new JScrollPane(area.codeArea);
jTabbedPane.addTab(s.getName(), scroll);
jTabbedPane.setSelectedIndex(jTabbedPane.getTabCount() - 1);
scroll = (JScrollPane) jTabbedPane.getSelectedComponent();
JViewport viewport = scroll.getViewport(); // first extract viewport from scrollpane then extract JTextArea from Viewport
area.codeArea = (JTextArea) viewport.getView();
area.codeArea.getDocument().addUndoableEditListener(
new UndoableEditListener() {
@Override
public void undoableEditHappened(UndoableEditEvent e) {
undo.addEdit(e.getEdit());
}
});
String buffer = "";
while (fin.hasNext()) {
buffer += fin.nextLine() + "\n";
}
area.codeArea.setText(buffer);
} catch (FileNotFoundException ex) {
JOptionPane.showMessageDialog(this, "File Not Found!");
}
}
consoleWindow.setText("");
}//GEN-LAST:event_openMenuItemActionPerformed
private void compileMeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_compileMeActionPerformed
if (flagOngoing == 0) {
flagOngoing = 1; // flagOngoing is 0 when compilation is not going on any other thread
saveMenuItemActionPerformed(evt);
if (s != null) {
String fileName = s.getName();
String filePath = s.getPath(); //s is lastest file saved
consoleWindow.setText("");
outputAndCompileLog.setText("Compilation Log");
if (fileName.charAt(fileName.length() - 1) == 'c') {
try {
consoleWindow.setText("Compiling.....");
CompileCProgram(s, fileName);
} catch (IOException | InterruptedException ex) {
Logger.getLogger(NewApplication.class.getName()).log(Level.SEVERE, null, ex);
}
} else if (fileName.charAt(fileName.length() - 1) == 'p') {
try {
consoleWindow.setText("Compiling.....");
CompileCplusplusProgram(fileName, filePath, s);
} catch (IOException | InterruptedException ex) {
Logger.getLogger(NewApplication.class.getName()).log(Level.SEVERE, null, ex);
}
} else if (fileName.charAt(fileName.length() - 1) == 'a') {
consoleWindow.setText("Compiling.....");
CompileJAVAProgram(fileName, filePath, s);
} else {
consoleWindow.setText("File Format Not Supported .");
}
}
}//GEN-LAST:event_compileMeActionPerformed
}
private void runMeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_runMeActionPerformed
Iterator<File> itr = null; //to iterate over vector
flag = 2;
File latest = null;
try {
String currentTitle = jTabbedPane.getTitleAt(jTabbedPane.getSelectedIndex());
int found = 0;
try {
itr = compiledCFilePaths.iterator();
do {
File p = itr.next();
if (p.getName().equals(currentTitle)) {
latest = p;
found = 1;
}
} while (itr.hasNext());
} catch (Exception e) {
}
if (found == 0) {
int dialogButton2 = JOptionPane.YES_NO_OPTION;
JOptionPane.showConfirmDialog(null, "Source File Not Compiled Yet!!\n Compile Now?", null, dialogButton2);
if (dialogButton2 == JOptionPane.YES_OPTION) {
consoleWindow.setText("Compiling........");
// System.out.println("ddddd");
flag = 3;
compileMeActionPerformed(evt);
}
} else {
flag = 2;
int yahaTak = jTabbedPane.getTitleAt(jTabbedPane.getSelectedIndex()).lastIndexOf(".");
String temp = jTabbedPane.getTitleAt(jTabbedPane.getSelectedIndex()).substring(0, yahaTak);
if (temp != null && jTabbedPane.getTabCount() > 0) {
consoleWindow.setText("");
outputAndCompileLog.setText("Output");
temp = latest.getName();
if (temp.endsWith("cpp")) {
compileAndRun runob = new compileAndRun(latest, this, "C++");
} else if (temp.endsWith("c")) {
compileAndRun runob = new compileAndRun(latest, this, "C");
} else if (temp.endsWith("java")) {
compileAndRun runob = new compileAndRun(latest, this, "JAVA");
}
}
}
} catch (HeadlessException e) {
e.printStackTrace();
}
}//GEN-LAST:event_runMeActionPerformed
public void openURL(String URL) {
try {
Desktop.getDesktop().browse(new URL(URL).toURI());
} catch (MalformedURLException ex) {
Logger.getLogger(NewApplication.class.getName()).log(Level.SEVERE, null, ex);
} catch (URISyntaxException | IOException ex) {
Logger.getLogger(NewApplication.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void stackOverflowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stackOverflowActionPerformed
openURL("https://stackoverflow.com/");
}//GEN-LAST:event_stackOverflowActionPerformed
private void openGeeksActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openGeeksActionPerformed
openURL("http://www.geeksforgeeks.org/c-plus-plus/");
}//GEN-LAST:event_openGeeksActionPerformed
private void openCodechefActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openCodechefActionPerformed
openURL("https://www.codechef.com/");
}//GEN-LAST:event_openCodechefActionPerformed
private void closeAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeAllActionPerformed
jTabbedPane.removeAll();
updateStatus(0, 0); // update Label of line & column
cursor.setText("");
}//GEN-LAST:event_closeAllActionPerformed
private void jTabbedPaneMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTabbedPaneMouseReleased
if (jTabbedPane.getTabCount() > 0) {
if (evt.isPopupTrigger()) {
close.show(this, evt.getXOnScreen(), evt.getYOnScreen());
}
evt.consume();
}
}//GEN-LAST:event_jTabbedPaneMouseReleased
private void closeTabActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeTabActionPerformed
jTabbedPane.remove(jTabbedPane.getSelectedIndex());
if (jTabbedPane.getTabCount() == 0) {
cursor.setText("");
label.setText("");
}
}//GEN-LAST:event_closeTabActionPerformed
private void undoItActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_undoItActionPerformed
try {
undo.undo();
} catch (CannotUndoException e) {
}
}//GEN-LAST:event_undoItActionPerformed
private void redoItActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_redoItActionPerformed
try {
undo.redo();
} catch (CannotRedoException e) {
}
}//GEN-LAST:event_redoItActionPerformed
private void compileAndRunMeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_compileAndRunMeActionPerformed
flag = 3;
compileMeActionPerformed(evt);
}//GEN-LAST:event_compileAndRunMeActionPerformed
private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutMenuItemActionPerformed
openURL("https://www.linkedin.com/in/aayush-chauhan-3b3116131/");
openURL("https://l.facebook.com/l.php?u=https%3A%2F%2Fwww.linkedin.com%2Fin%2Fvijay-krishan-pandey-225a5014b%2F&h=ATM-ptT8pEr02MIWYSErHiqjfcOmaCNNC8HrwMtxIlEkV98Cj8MwdVhW9sPlyREMbgfRZXfkok_sgRgs3RCGzA9KrRvzy8vRi1WjevCPPhOCBqW92k3PgjME4WKkNrJewCeW2_ag7Q4YzA\n");
}//GEN-LAST:event_aboutMenuItemActionPerformed
private void cutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cutMenuItemActionPerformed
try {
try {
JScrollPane scroll = (JScrollPane) jTabbedPane.getSelectedComponent();
JViewport viewport = scroll.getViewport(); // first extract viewport from scrollpane then extract JTextArea from Viewport
JTextArea area = (JTextArea) viewport.getView();
selectedString = area.getSelectedText();
area.replaceSelection("");
} catch (Exception e) {
}
} catch (Exception e) {
e.printStackTrace();
}
}//GEN-LAST:event_cutMenuItemActionPerformed
private void copyMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_copyMenuItemActionPerformed
try {
JScrollPane scroll = (JScrollPane) jTabbedPane.getSelectedComponent();
JViewport viewport = scroll.getViewport(); // first extract viewport from scrollpane then extract JTextArea from Viewport
JTextArea area = (JTextArea) viewport.getView();
selectedString = area.getSelectedText();
//System.out.println(selectedString);
} catch (Exception e) {
}
}//GEN-LAST:event_copyMenuItemActionPerformed
private void pasteMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pasteMenuItemActionPerformed
try {
JScrollPane scroll = (JScrollPane) jTabbedPane.getSelectedComponent();
JViewport viewport = scroll.getViewport(); // first extract viewport from scrollpane then extract JTextArea from Viewport
JTextArea area = (JTextArea) viewport.getView();
area.insert(selectedString, area.getCaretPosition());
} catch (Exception e) {
}
}//GEN-LAST:event_pasteMenuItemActionPerformed
private void deleteMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteMenuItemActionPerformed
try {
JScrollPane scroll = (JScrollPane) jTabbedPane.getSelectedComponent();
JViewport viewport = scroll.getViewport(); // first extract viewport from scrollpane then extract JTextArea from Viewport
JTextArea area = (JTextArea) viewport.getView();
area.replaceSelection("");
} catch (Exception e) {
JOptionPane.showMessageDialog(this, "No Text Selected!!!");
}
}//GEN-LAST:event_deleteMenuItemActionPerformed
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
JScrollPane scroll = (JScrollPane) jTabbedPane.getSelectedComponent();
JViewport viewport = scroll.getViewport(); // first extract viewport from scrollpane then extract JTextArea from Viewport
JTextArea area = (JTextArea) viewport.getView();
selectedString = area.getSelectedText();
String input="";
input=area.getText();
String input2=input.substring(0,input.length());
int pos=input2.indexOf(selectedString);
String [] s=selectedString.split("\n");
String ans="";
for(int i=0;i<s.length;i++)
{
if(i==s.length-1){
ans+="//"+s[i];
}
else
ans+="//"+s[i]+"\n";
}
area.replaceSelection(ans);
// input = findReplace.jframe.jTabbedPane.setSelectedIndex(findReplace.jframe.jTabbedPane.getSelectedIndex()).getText();
// if (pos != -1) {
//
// String s1 = input.substring(0,pos);
// int len = selectedString.length(); //farzi string ki length
// String s2 = input.substring(pos + len, input.length()); // farzi string
// String s3 = s1 + "//"+selectedString +"\n" + s2; // farzi string
// String temporaryString=s3;
// area.insert(temporaryString,area.getCaretPosition());
//
// }
}//GEN-LAST:event_jMenuItem1ActionPerformed
public void CompileCProgram(File isko, String inputAreaString) throws IOException, InterruptedException {
//CCompilationThread cProgram = new CCompilationThread("cWalaThread", this, fileName, filePath, isko,inputAreaString);
compileAndRun car = new compileAndRun(isko, this, "C");
}
public void CompileCplusplusProgram(String fileName, String filePath, File isko) throws IOException, InterruptedException {
//CPlusPlusCompilationThread cPlusplusCode = new CPlusPlusCompilationThread("cPlusPlusWalaThread", this, fileName, filePath, isko);
compileAndRun cplusplus = new compileAndRun(isko, this, "C++");
}
public void CompileJAVAProgram(String fileName, String filePath, File isko) {
compileAndRun java = new compileAndRun(isko, this, "JAVA");
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(NewApplication.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}