View Javadoc

1   package com.explosion.expfmodules.texteditor;
2   
3   /* =============================================================================
4    *       
5    *     Copyright 2004 Stephen Cowx
6    *
7    *     Licensed under the Apache License, Version 2.0 (the "License");
8    *     you may not use this file except in compliance with the License.
9    *     You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   *     Unless required by applicable law or agreed to in writing, software
14   *     distributed under the License is distributed on an "AS IS" BASIS,
15   *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   *     See the License for the specific language governing permissions and
17   *     limitations under the License.
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  }