31
31
32
32
* Removed unuse objects like container, Border emptyBorder
33
33
* Removed unsused imports
34
+ *
35
+ * @Modifiedby Giorgos Pasentsis
36
+
34
37
*/
35
38
package simplejavatexteditor ;
36
39
@@ -55,9 +58,14 @@ public class UI extends JFrame implements ActionListener {
55
58
private final JMenuItem newFile , openFile , saveFile , close , cut , copy , paste , clearFile , selectAll , quickFind ,
56
59
aboutMe , aboutSoftware , wordWrap ;
57
60
private final JToolBar mainToolbar ;
58
- JButton newButton , openButton , saveButton , clearButton , quickButton , aboutMeButton , aboutButton , closeButton ;
61
+ JButton newButton , openButton , saveButton , clearButton , quickButton , aboutMeButton , aboutButton , closeButton , boldButton , italicButton ;
59
62
private final Action selectAllAction ;
60
63
64
+
65
+ //setup icons - Bold and Italic
66
+ private final ImageIcon boldIcon = new ImageIcon ("icons/bold.png" );
67
+ private final ImageIcon italicIcon = new ImageIcon ("icons/italic.png" );
68
+
61
69
// setup icons - File Menu
62
70
private final ImageIcon newIcon = new ImageIcon ("icons/new.png" );
63
71
private final ImageIcon openIcon = new ImageIcon ("icons/open.png" );
@@ -88,7 +96,7 @@ public class UI extends JFrame implements ActionListener {
88
96
public UI () {
89
97
90
98
// Set the initial size of the window
91
- setSize (700 , 500 );
99
+ setSize (800 , 500 );
92
100
93
101
// Set the title of the window
94
102
setTitle ("Untitled | " + SimpleJavaTextEditor .NAME );
@@ -101,9 +109,9 @@ public UI() {
101
109
102
110
// Set a default font for the TextArea
103
111
textArea = new JTextArea ("" , 0 , 0 );
104
- textArea .setFont (new Font ("Century Gothic" , Font .BOLD , 12 ));
112
+ textArea .setFont (new Font ("Century Gothic" , Font .PLAIN , 12 ));
105
113
textArea .setTabSize (2 );
106
- textArea .setFont (new Font ("Century Gothic" , Font .BOLD , 12 ));
114
+ textArea .setFont (new Font ("Century Gothic" , Font .PLAIN , 12 ));
107
115
textArea .setTabSize (2 );
108
116
109
117
/* SETTING BY DEFAULT WORD WRAP ENABLED OR TRUE */
@@ -311,7 +319,18 @@ public void actionPerformed(ActionEvent ev) {
311
319
closeButton .addActionListener (this );
312
320
mainToolbar .add (closeButton );
313
321
mainToolbar .addSeparator ();
314
-
322
+
323
+ boldButton = new JButton (boldIcon );
324
+ boldButton .setToolTipText ("Bold" );
325
+ boldButton .addActionListener (this );
326
+ mainToolbar .add (boldButton );
327
+ mainToolbar .addSeparator ();
328
+
329
+ italicButton = new JButton (italicIcon );
330
+ italicButton .setToolTipText ("Italic" );
331
+ italicButton .addActionListener (this );
332
+ mainToolbar .add (italicButton );
333
+ mainToolbar .addSeparator ();
315
334
/**
316
335
* **************** FONT SETTINGS SECTION **********************
317
336
*/
@@ -485,8 +504,25 @@ else if (e.getSource() == openFile || e.getSource() == openButton) {
485
504
} // If the source of the event was the "save" option
486
505
else if (e .getSource () == saveFile || e .getSource () == saveButton ) {
487
506
saveFile ();
507
+ }// If the source of the event was the "Bold" button
508
+ else if (e .getSource () == boldButton ) {
509
+ if (textArea .getFont ().getStyle () == Font .BOLD ){
510
+ textArea .setFont (textArea .getFont ().deriveFont (Font .PLAIN ));
511
+
512
+ }
513
+ else {
514
+ textArea .setFont (textArea .getFont ().deriveFont (Font .BOLD ));
515
+ }
516
+ }// If the source of the event was the "Italic" button
517
+ else if (e .getSource () == italicButton ) {
518
+ if (textArea .getFont ().getStyle () == Font .ITALIC ){
519
+ textArea .setFont (textArea .getFont ().deriveFont (Font .PLAIN ));
520
+
521
+ }
522
+ else {
523
+ textArea .setFont (textArea .getFont ().deriveFont (Font .ITALIC ));
524
+ }
488
525
}
489
-
490
526
// Clear File (Code)
491
527
if (e .getSource () == clearFile || e .getSource () == clearButton ) {
492
528
0 commit comments