36
36
import java .util .Scanner ;
37
37
import javax .swing .text .DefaultEditorKit ;
38
38
39
- public class UI extends JFrame implements ActionListener {
39
+ public class UI extends JFrame implements ActionListener
40
+ {
41
+
40
42
41
43
private static final long serialVersionUID = 1L ;
42
44
private final Container container ;
43
45
private final JTextArea textArea ;
44
46
private final JMenuBar menuBar ;
45
47
private final JMenu menuFile , menuEdit , menuFind , menuAbout ;
46
48
private final JMenuItem newFile , openFile , saveFile , close , cut , copy , paste , clearFile , selectAll , quickFind ,
47
- aboutMe , aboutSoftware ;
49
+ aboutMe , aboutSoftware , wordWrap ;
48
50
private final JToolBar mainToolbar ;
49
51
JButton newButton , openButton , saveButton , clearButton , quickButton , aboutMeButton , aboutButton , closeButton ,
50
52
spaceButton1 , spaceButton2 ;
@@ -62,6 +64,7 @@ public class UI extends JFrame implements ActionListener {
62
64
private final ImageIcon copyIcon = new ImageIcon ("icons/copy.png" );
63
65
private final ImageIcon pasteIcon = new ImageIcon ("icons/paste.png" );
64
66
private final ImageIcon selectAllIcon = new ImageIcon ("icons/selectall.png" );
67
+ private final ImageIcon wordwrapIcon = new ImageIcon ("icons/wordwrap.png" );
65
68
66
69
// setup icons - Search Menu
67
70
private final ImageIcon searchIcon = new ImageIcon ("icons/search.png" );
@@ -91,6 +94,10 @@ public UI() {
91
94
textArea .setTabSize (2 );
92
95
textArea .setFont (new Font ("Century Gothic" , Font .BOLD , 12 ));
93
96
textArea .setTabSize (2 );
97
+
98
+
99
+ /* SETTING BY DEFAULT WORD WRAP ENABLED OR TRUE*/
100
+ textArea .setLineWrap (true );
94
101
95
102
// This is why we didn't have to worry about the size of the TextArea!
96
103
getContentPane ().setLayout (new BorderLayout ()); // the BorderLayout bit makes it fill it automatically
@@ -175,6 +182,53 @@ public UI() {
175
182
cut .setToolTipText ("Cut" );
176
183
cut .setAccelerator (KeyStroke .getKeyStroke (KeyEvent .VK_X , InputEvent .CTRL_MASK ));
177
184
menuEdit .add (cut );
185
+
186
+ //WordWrap
187
+
188
+ wordWrap = new JMenuItem ();
189
+ wordWrap .setText ("Word Wrap" );
190
+ wordWrap .setIcon (wordwrapIcon );
191
+ wordWrap .setToolTipText ("Word Wrap" );
192
+
193
+ //Short cut key or key stroke
194
+ wordWrap .setAccelerator (KeyStroke .getKeyStroke (KeyEvent .VK_W , InputEvent .CTRL_MASK ));
195
+ menuEdit .add (wordWrap );
196
+
197
+
198
+
199
+ /* CODE FOR WORD WRAP OPERATION
200
+
201
+ START WORDWRAP OPERATION
202
+
203
+ BY DEFAULT WORD WRAPPING IS ENABLED.
204
+
205
+ */
206
+
207
+ wordWrap .addActionListener (new ActionListener ()
208
+ {
209
+ public void actionPerformed (ActionEvent ev )
210
+ {
211
+ // If wrapping is false then after clicking on menuitem the word wrapping will be enabled
212
+ if (textArea .getLineWrap ()==false )
213
+ {
214
+
215
+ /*Setting word wrapping to true*/
216
+ textArea .setLineWrap (true );
217
+
218
+ }
219
+
220
+ // else if wrapping is true then after clicking on menuitem the word wrapping will be disabled
221
+ else
222
+ {
223
+ /*Setting word wrapping to false*/
224
+ textArea .setLineWrap (false );
225
+ }
226
+ }
227
+ });
228
+
229
+
230
+ //END OF THE WORDWRAP OPERATION
231
+
178
232
179
233
// Copy Text
180
234
copy = new JMenuItem (new DefaultEditorKit .CopyAction ());
@@ -280,8 +334,16 @@ public void actionPerformed (ActionEvent e) {
280
334
281
335
// If the source was the "new" file option
282
336
else if (e .getSource () == newFile || e .getSource () == newButton ) {
283
- FEdit .clear (textArea );
337
+ FEdit .clear (textArea );
338
+
284
339
}
340
+
341
+
342
+
343
+
344
+
345
+
346
+
285
347
// If the source was the "open" option
286
348
else if (e .getSource () == openFile || e .getSource () == openButton ) {
287
349
JFileChooser open = new JFileChooser (); // open up a file chooser (a dialog for the user to browse files to open)
0 commit comments