19
19
package simplejavatexteditor ;
20
20
21
21
// GUI
22
+
22
23
import javax .swing .*;
23
- import java .awt .BorderLayout ;
24
- import java .awt .Container ;
25
- import java .awt .Font ;
26
- import java .awt .event .*;
27
- // Input Stream
28
- import java .io .*;
29
- // Various
24
+ import javax .swing .border .Border ;
25
+ import java .awt .*;
26
+ import java .awt .event .ActionEvent ;
27
+ import java .awt .event .ActionListener ;
28
+ import java .awt .event .InputEvent ;
29
+ import java .awt .event .KeyEvent ;
30
+ import java .io .BufferedWriter ;
31
+ import java .io .File ;
32
+ import java .io .FileReader ;
33
+ import java .io .FileWriter ;
30
34
import java .util .ArrayList ;
31
- import java .util .EventListener ;
32
35
import java .util .Scanner ;
33
- import javax . swing . border . Border ;
34
- import javax . swing . event . DocumentListener ;
35
- import javax . xml . bind . Marshaller ;
36
+
37
+ // Input Stream
38
+ // Various
36
39
37
40
public class UI extends JFrame implements ActionListener {
38
41
@@ -43,7 +46,11 @@ public class UI extends JFrame implements ActionListener {
43
46
private final JMenu menuFile , menuEdit , menuFind , menuAbout ;
44
47
private final JMenuItem newFile , openFile , saveFile , close , clearFile , quickFind , aboutMe , aboutSoftware ;
45
48
private final JToolBar mainToolbar ;
46
- JButton newButton , openButton , saveButton , clearButton , quickButton , aboutMeButton , aboutButton , closeButton , spaceButton1 , spaceButton2 ;
49
+ JButton newButton , openButton ,
50
+ saveButton , clearButton ,
51
+ quickButton , aboutMeButton ,
52
+ aboutButton , closeButton ,
53
+ spaceButton1 , spaceButton2 ;
47
54
48
55
//setup icons - File Menu
49
56
private final ImageIcon newIcon = new ImageIcon ("icons/new.png" );
@@ -61,8 +68,8 @@ public class UI extends JFrame implements ActionListener {
61
68
private final ImageIcon aboutMeIcon = new ImageIcon ("icons/about_me.png" );
62
69
private final ImageIcon aboutIcon = new ImageIcon ("icons/about.png" );
63
70
64
- private boolean hasListener = false ;
65
- JavaAutoComplete autocomplete ;
71
+ JavaAutoComplete autocomplete ;
72
+ private boolean hasListener = false ;
66
73
67
74
public UI () {
68
75
container = getContentPane ();
@@ -78,14 +85,10 @@ public UI() {
78
85
79
86
// Set a default font for the TextArea
80
87
textArea = new JTextArea ("" , 0 ,0 );
81
- <<<<<<< Updated upstream
82
- textArea .setFont (new Font ("Century Gothic" , Font .BOLD , 12 ));
83
- textArea .setTabSize (2 );
84
- =======
85
88
textArea .setFont (new Font ("Century Gothic" , Font .BOLD , 12 ));
86
89
textArea .setTabSize (2 );
87
-
88
- >>>>>>> Stashed changes
90
+ textArea . setFont ( new Font ( "Century Gothic" , Font . BOLD , 12 ));
91
+ textArea . setTabSize ( 2 );
89
92
90
93
// This is why we didn't have to worry about the size of the TextArea!
91
94
getContentPane ().setLayout (new BorderLayout ()); // the BorderLayout bit makes it fill it automatically
@@ -285,15 +288,24 @@ else if(e.getSource() == saveFile || e.getSource() == saveButton) {
285
288
// Close the file stream
286
289
out .close ();
287
290
291
+ //If the user saves files with supported
292
+ //file types more than once, we need to remove
293
+ //previous listeners to avoid bugs.
288
294
if (hasListener ) {
289
295
textArea .getDocument ().removeDocumentListener (autocomplete );
290
296
hasListener = false ;
291
297
}
292
298
299
+ //With the keywords located in a separate class,
300
+ //we can support multiple languages and not have to do
301
+ //much to add new ones.
293
302
SupportedKeywords kw = new SupportedKeywords ();
294
303
ArrayList <String > arrayList ;
295
304
String [] list = { ".java" , ".cpp" };
296
305
306
+ //Iterate through the list, find the supported
307
+ //file extension, apply the appropriate getter method from
308
+ //the keyword class
297
309
for (int i = 0 ; i < list .length ; i ++) {
298
310
if (file .getName ().endsWith (list [i ])) {
299
311
switch (i ) {
@@ -340,16 +352,4 @@ else if(e.getSource() == aboutSoftware || e.getSource() == aboutButton) {
340
352
}
341
353
342
354
}
343
-
344
- /*
345
- bool hasListener = false
346
-
347
- for..
348
- if..
349
- if(hasListener) {
350
- removeListener
351
- }
352
- switch..
353
- //It has a
354
- */
355
355
}
0 commit comments