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
| import java.awt.*;
import java.awt.event.*;
import java.lang.reflect.*;
import java.awt.datatransfer.*;
import javax.swing.*;
public class Editor extends Frame implements ActionListener{
private String [] markuplist = {"<B>","</B>","<U>","</U>","<I>","</I>"};
public String copy;
public String [] filelistarray;
public List filelist;
public boolean truth;
private TextArea textField;
//File Menu
private MenuItem exitMenuItem;
private MenuItem resetMenuItem;
//Edit Menu
private MenuItem cutMenuItem;
private MenuItem copyMenuItem;
private MenuItem pasteMenuItem;
private MenuItem deleteMenuItem;
private MenuItem boldMenuItem;
private MenuItem italicMenuItem;
private MenuItem underlineMenuItem;
private CheckboxMenuItem boxMenuItem;
private MenuItem selectallMenuItem;
//Help Menu
private MenuItem helpMenuItem;
private MenuItem aboutMenuItem;
private CloseAction closeAction;
Window window;
public Editor(){
super("AACS GUI Try-out");
setLayout(new BorderLayout(5,5));
MenuBar menuBar = new MenuBar();
//Menu File
Menu fileMenu = new Menu("File");
fileMenu.add(resetMenuItem = new MenuItem("Reset"));
fileMenu.addSeparator();
fileMenu.add(exitMenuItem = new MenuItem("Exit"));
menuBar.add(fileMenu);
//Menu Edit
Menu editMenu = new Menu("Edit");
editMenu.add(cutMenuItem = new MenuItem("Cut"));
editMenu.add(copyMenuItem = new MenuItem("Copy"));
editMenu.add(pasteMenuItem = new MenuItem("Paste"));
editMenu.add(deleteMenuItem = new MenuItem("Delete"));
editMenu.addSeparator();
editMenu.add(boldMenuItem = new MenuItem("Bold"));
editMenu.add(italicMenuItem = new MenuItem("Italic"));
editMenu.add(underlineMenuItem = new MenuItem("Underline"));
editMenu.addSeparator();
editMenu.add(boxMenuItem = new CheckboxMenuItem("Automatische Terugloop",false));
editMenu.add(selectallMenuItem = new MenuItem("Select All"));
menuBar.add(editMenu);
//Menu Help
Menu helpMenu = new Menu("Help");
helpMenu.add(helpMenuItem = new MenuItem("Help"));
helpMenu.addSeparator();
helpMenu.add(aboutMenuItem = new MenuItem("About"));
menuBar.add(helpMenu);
setMenuBar(menuBar);
Button sendButton = new Button("Send");
Button resetButton = new Button("reset");
Button boldButton = new Button("Bold");
Button italicButton = new Button("Italic");
Button underlineButton = new Button("Underline");
Button clearmarkupButton = new Button("Clear Markup");
Button makehtmlButton = new Button("Make HTML");
Button loadButton = new Button("Load");
Button saveButton = new Button("Save");
closeAction = new CloseAction(window);
//ACTIONLISTENERS
//Buttons
loadButton.addActionListener(new LoadAction());
saveButton.addActionListener(new SaveAction());
resetButton.addActionListener(new ResetAction());
boldButton.addActionListener(new BoldAction());
italicButton.addActionListener(new ItalicAction());
underlineButton.addActionListener(new UnderlineAction());
clearmarkupButton.addActionListener(new ClearMarkupAction());
makehtmlButton.addActionListener(new MakehtmlAction());
//File Menu
resetMenuItem.addActionListener(new ResetAction());
exitMenuItem.addActionListener(new ExitAction());
//Edit Menu
cutMenuItem.addActionListener(new CutAction());
copyMenuItem.addActionListener(new CopyAction());
pasteMenuItem.addActionListener(new PasteAction());
deleteMenuItem.addActionListener(new DeleteAction());
boldMenuItem.addActionListener(new BoldAction());
italicMenuItem.addActionListener(new ItalicAction());
underlineMenuItem.addActionListener(new UnderlineAction());
boxMenuItem.addItemListener(new BoxAction());
selectallMenuItem.addActionListener(new SelectAllAction());
//Help Menu
helpMenuItem.addActionListener(new HelpAction());
aboutMenuItem.addActionListener(new AboutAction());
//creating and adding panels
Panel p = new Panel();
p.add(resetButton);
add(BorderLayout.SOUTH, p);
Panel q = new Panel(new StackLayout(3));
q.add(new JLabel("Markup"));
q.add(new JLabel("-----------"));
q.add(boldButton);
q.add(italicButton);
q.add(underlineButton);
q.add(clearmarkupButton);
q.add(makehtmlButton);
add(BorderLayout.EAST, q);
Panel r = new Panel(new StackLayout(3));
filelist = new List(14, false);
r.add(makeList());
Panel rsub = new Panel(new FlowLayout());
rsub.add(loadButton);
rsub.add(saveButton);
r.add(rsub);
add(BorderLayout.WEST, r);
filelist.addActionListener(new LoadAction());
textField = new TextArea(30,70);
add(BorderLayout.CENTER, textField);
setBackground(Color.lightGray);
setSize(600,400);
//Venster positioneren
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = getSize();
if (frameSize.height > screenSize.height){
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width){
frameSize.width = screenSize.width;
}
setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 4);
//EO Venster positioneren
setVisible(true);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
close();
}
});
}
public void actionPerformed(ActionEvent e){}
private void close(){
System.exit(0);
}
//Checks wether a listItem is a file or just a seperator
public boolean validateSelectedItem(){
//empty
boolean condition1 = true;
//total uppercase
boolean condition2 = true;
//just '-'
boolean condition3 = true;
String item = filelist.getSelectedItem();
char[] temp = item.toCharArray();
if(!item.equals("")){
condition1 = false;
}
for(int i=0;i<Array.getLength(temp);i++){
if(Character.isLowerCase(temp[i])){
condition2 = false;
break;
}
}
for(int i=0;i<Array.getLength(temp);i++){
if(temp[i] != '-'){
condition3 = false;
break;
}
}
if(condition1 || condition2 || condition3){
return false;
}
return true;
}
public List makeList(){
filelistarray = MiscFunctions.file2Array("tempfile");
int size = Array.getLength(filelistarray);
for(int i=0;i<size;i++){
filelist.add(filelistarray[i]);
}
return filelist;
}
public CloseAction getCloseAction(){
return closeAction;
}
// liever aparte ActionListeners dan gevalsonderscheid in 1 ActionListener
class CloseAction extends WindowAdapter implements ActionListener{
private Window window;
public CloseAction(Window window){
super();
this.window = window;
}
public void windowClosing(WindowEvent e){
window.setVisible(false); System.exit(0);
}
public void actionPerformed(ActionEvent event){
window.setVisible(false); System.exit(0);
}
}
//********************************************
// SPECIAL ACTION CLASSES!!! //
//********************************************
/* class FilelistAction implements ActionListener{
public void actionPerformed(ActionEvent event){
System.out.println(filelist.getSelectedItem());
}
}
*/
//SOUTH PANEL
class LoadAction implements ActionListener{
public void actionPerformed(ActionEvent event){
if(validateSelectedItem()){
System.out.println("Loading: " +filelist.getSelectedItem());
}
}
}
class SaveAction implements ActionListener{
public void actionPerformed(ActionEvent event){
if(validateSelectedItem()){
System.out.println("Saving: " +filelist.getSelectedItem());
}
}
}
class ResetAction implements ActionListener{
public void actionPerformed(ActionEvent event){
textField.setText("");
}
}
class ExitAction implements ActionListener{
public void actionPerformed(ActionEvent event){
System.exit(0);
}
}
//HELP-BAR OPTIONS
class HelpAction implements ActionListener{
public void actionPerformed(ActionEvent event){
new Help();
}
}
class AboutAction implements ActionListener{
public void actionPerformed(ActionEvent event){
System.out.println("about");
new About();
}
}
//EDIT-BAR OPTIONS
class CutAction implements ActionListener{
public void actionPerformed(ActionEvent event){
int begin = textField.getSelectionStart();
int end = textField.getSelectionEnd();
copy = textField.getSelectedText();
textField.replaceRange("",begin,end);
}
}
class CopyAction implements ActionListener{
public void actionPerformed(ActionEvent event){
int begin = textField.getSelectionStart();
int end = textField.getSelectionEnd();
copy = textField.getSelectedText();
}
}
class PasteAction implements ActionListener{
public void actionPerformed(ActionEvent event){
int begin = textField.getSelectionStart();
int end = textField.getSelectionEnd();
textField.replaceRange(copy,begin,end);
}
}
class DeleteAction implements ActionListener{
public void actionPerformed(ActionEvent event){
int begin = textField.getSelectionStart();
int end = textField.getSelectionEnd();
textField.replaceRange("",begin,end);
}
}
class BoldAction implements ActionListener{
public void actionPerformed(ActionEvent event){
int begin = textField.getSelectionStart();
int end = textField.getSelectionEnd();
textField.insert("</B>",end);
textField.insert("<B>",begin);
}
}
class ItalicAction implements ActionListener{
public void actionPerformed(ActionEvent event){
int begin = textField.getSelectionStart();
int end = textField.getSelectionEnd();
textField.insert("</I>",end);
textField.insert("<I>",begin);
}
}
class UnderlineAction implements ActionListener{
public void actionPerformed(ActionEvent event){
int begin = textField.getSelectionStart();
int end = textField.getSelectionEnd();
textField.insert("</U>",end);
textField.insert("<U>",begin);
}
}
class ClearMarkupAction implements ActionListener{
public void actionPerformed(ActionEvent event){
String text = textField.getText();
for(int i=0;i<Array.getLength(markuplist);i++){
text = MiscFunctions.replace(text,markuplist[i],"");
}
text = MiscFunctions.replace(text,"<BR>","\n");
text = MiscFunctions.replace(text," "," ");
textField.setText(text);
}
}
class MakehtmlAction implements ActionListener{
public void actionPerformed(ActionEvent event){
String text = textField.getText();
text = MiscFunctions.replace(text,"\n","<BR>");
text = MiscFunctions.replace(text," "," ");
textField.setText(text);
}
}
class BoxAction implements ItemListener{
public void itemStateChanged(ItemEvent event){
boxMenuItem.setState(false);
new Help();
}
}
class SelectAllAction implements ActionListener{
public void actionPerformed(ActionEvent event){
textField.selectAll();
}
}
} |