1 package com.explosion.expfmodules.texteditor;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.awt.Dimension;
23 import java.awt.event.ActionEvent;
24 import java.io.File;
25 import java.util.HashMap;
26 import java.util.Map;
27
28 import com.explosion.expf.Application;
29 import com.explosion.expf.ExpActionListener;
30 import com.explosion.expf.ExpConstants;
31 import com.explosion.expf.ExpFrame;
32 import com.explosion.utilities.FileSystemUtils;
33
34 /***
35 * @author Stephen Cowx
36 */
37 public class TextEditorListener implements ExpActionListener
38 {
39
40 private HashMap map;
41 private int newDocumentNumbers = 1;
42
43 /***
44 * Constructor for TextEditorListener.
45 */
46 public TextEditorListener()
47 {
48 map = new HashMap();
49 map.put(ExpConstants.MENU_NEW,ExpConstants.MENU_NEW);
50 map.put(ExpConstants.MENU_OPEN,ExpConstants.MENU_OPEN);
51 map.put(ExpConstants.MENU_CLOSEALL,ExpConstants.MENU_CLOSEALL);
52 map.put(ExpConstants.MENU_SAVEALL,ExpConstants.MENU_SAVEALL);
53 }
54
55 /***
56 * @see package com.explosion.expf.Interfaces.ExpActionListener#getListensFor()
57 */
58 public Map getListensFor()
59 {
60 return map;
61 }
62
63 /***
64 * @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
65 */
66 public void actionPerformed(ActionEvent e)
67 {
68 try
69 {
70 if (e.getActionCommand().equals(ExpConstants.MENU_NEW))
71 {
72 TextEditor editor = new TextEditor(newDocumentNumbers++);
73 ((ExpFrame) Application.getApplicationFrame()).createDocumentFrame(editor, new Dimension(500,500), editor.getDocument().getDocumentName(),true);
74 }
75 else if (e.getActionCommand().equals(ExpConstants.MENU_OPEN))
76 {
77 File[] files = FileSystemUtils.chooseFiles(Application.getApplicationFrame(),FileSystemUtils.OPENTYPE,false,null,FileSystemUtils.FILES_ONLY,"Open file");
78 if (files != null && files[0] != null)
79 {
80 TextEditor editor = new TextEditor(files[0]);
81 ((ExpFrame) Application.getApplicationFrame()).createDocumentFrame(editor, new Dimension(500,500), editor.getDocument().getDocumentName(),true);
82 }
83 }
84
85 }
86 catch (Exception ex)
87 {
88 com.explosion.utilities.exception.ExceptionManagerFactory.getExceptionManager().manageException(ex, "Exception caught while responding to SimpleProcess Event." );
89 }
90
91 }
92
93 }