View Javadoc

1   package com.explosion.expf.supportmodules;
2   
3   /*
4    * =============================================================================
5    * 
6    * Copyright 2004 Stephen Cowx
7    * 
8    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
9    * use this file except in compliance with the License. You may obtain a copy of
10   * the License at
11   * 
12   * http://www.apache.org/licenses/LICENSE-2.0
13   * 
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17   * License for the specific language governing permissions and limitations under
18   * the License.
19   * 
20   * =============================================================================
21   */
22  
23  import java.awt.event.KeyEvent;
24  import java.util.Hashtable;
25  import java.util.Properties;
26  import java.util.Vector;
27  
28  import javax.swing.JButton;
29  import javax.swing.JPanel;
30  import javax.swing.KeyStroke;
31  
32  import org.apache.log4j.LogManager;
33  import org.apache.log4j.Logger;
34  
35  import com.explosion.expf.Application;
36  import com.explosion.expf.ExpActionListener;
37  import com.explosion.expf.ExpConstants;
38  import com.explosion.expf.ExpFrame;
39  import com.explosion.expf.ExpModuleManager;
40  import com.explosion.expf.menusandtools.menu.ExpMenu;
41  import com.explosion.expf.menusandtools.menu.ExpMenuBar;
42  import com.explosion.expf.menusandtools.menu.MenuHelper;
43  import com.explosion.expf.menusandtools.menu.segmented.ExpMenuSegment;
44  import com.explosion.expf.menusandtools.tool.ExpToolBar;
45  import com.explosion.expf.menusandtools.tool.ExpToolBarSegment;
46  import com.explosion.utilities.preferences.Preference;
47  
48  /***
49   * Author: Stephen Cowx Date: Dec 1, 2002 Time: 12:50:18 PM
50   * 
51   * This ExpModuleManager sets up theApplication with support (menu's , button
52   * etc) for editing.
53   */
54  
55  public class EditSupportModule implements ExpModuleManager
56  {
57      private static Logger log = LogManager.getLogger(EditSupportModule.class);
58      private Vector preferences;
59      private Hashtable preferenceHash;
60  
61      public void initialiseGui() throws Exception
62      {
63          ExpMenuBar menuBar = ((ExpFrame) Application.getApplicationFrame()).getExpMenuBar();
64          
65          MenuHelper helper = menuBar.getMenuHelper();
66          ExpMenu menuEdit = menuBar.createExpMenu("Edit", 'e', ExpConstants.MENU_EDIT, 1, true);
67          menuBar.add(menuEdit);
68  
69          /* Edit menu */
70          ExpMenuSegment redo = menuEdit.createNewSegment(ExpMenuSegment.ALWAYS_FIRST_SEGMENT);
71          populateUndoRedoMenuSegment(helper, redo);
72          
73          ExpMenuSegment cutcopy = menuEdit.createNewSegment(ExpMenuSegment.ANY_POSITION);
74          populateCutCopyPasteMenuSegment(helper, cutcopy);
75          
76          ExpMenuSegment selectAndClear = menuEdit.createNewSegment(ExpMenuSegment.ANY_POSITION);
77          populateSelectAndClearSegment(helper, selectAndClear);
78  		
79          /* Toolbar buttons */
80          ExpToolBar toolbar = ((ExpFrame) Application.getApplicationFrame()).getExpToolBar();
81          ExpToolBarSegment editSegment = toolbar.createNewSegment(ExpToolBarSegment.ANY_POSITION);
82  
83          JButton cutButton = toolbar.createExpToolBarItem(ExpConstants.DEFAULT_CUT_ICON, "Cut", ExpConstants.MENU_CUT, 1);
84          JButton copyButton = toolbar.createExpToolBarItem(ExpConstants.DEFAULT_COPY_ICON, "Copy", ExpConstants.MENU_COPY, 1);
85          JButton pasteButton = toolbar.createExpToolBarItem(ExpConstants.DEFAULT_PASTE_ICON, "Paste", ExpConstants.MENU_PASTE, 1);
86          JButton undoButton = toolbar.createExpToolBarItem(ExpConstants.DEFAULT_UNDO_ICON, "Undo", ExpConstants.MENU_UNDO, 1);
87          JButton redoButton = toolbar.createExpToolBarItem(ExpConstants.DEFAULT_REDO_ICON, "Redo", ExpConstants.MENU_REDO, 1);
88  
89          editSegment.addElement(cutButton);
90          editSegment.addElement(copyButton);
91          editSegment.addElement(pasteButton);
92          editSegment.addElement(undoButton);
93          editSegment.addElement(redoButton);
94          editSegment.addElement(null);
95      }
96      
97      /***
98       * This method will populate a menu segment with redo items.
99       * @param helper
100      * @param menuEdit
101      * @throws Exception
102      */
103     public static void populateUndoRedoMenuSegment(MenuHelper helper, ExpMenuSegment segment) throws Exception
104     {
105     	segment.addElement(helper.createMenuItem("Undo", 'u', ExpConstants.MENU_UNDO, KeyStroke.getKeyStroke(KeyEvent.VK_Z, KeyEvent.CTRL_MASK), 1));
106         segment.addElement(helper.createMenuItem("Redo", 'r', ExpConstants.MENU_REDO, KeyStroke.getKeyStroke(KeyEvent.VK_Y, KeyEvent.CTRL_MASK), 1));
107     }
108     
109     /***
110      * This method will populate a menu segment with cut copy items
111      * @param helper
112      * @param menuEdit
113      * @throws Exception
114      */
115     public static void populateCutCopyPasteMenuSegment(MenuHelper helper, ExpMenuSegment segment) throws Exception
116     {
117     	segment.addElement(helper.createMenuItem("Cut", 't', ExpConstants.MENU_CUT, KeyStroke.getKeyStroke(KeyEvent.VK_X, KeyEvent.CTRL_MASK), 1));
118         segment.addElement(helper.createMenuItem("Copy", 'c', ExpConstants.MENU_COPY, KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_MASK), 1));
119         segment.addElement(helper.createMenuItem("Paste", 'p', ExpConstants.MENU_PASTE, KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.CTRL_MASK), 1));
120     }
121     
122     /***
123      * This method will populate a menu segment with selectAndClear items
124      * @param helper
125      * @param menuEdit
126      * @throws Exception
127      */
128     public static void populateSelectAndClearSegment(MenuHelper helper, ExpMenuSegment segment) throws Exception
129     {
130     	segment.addElement(helper.createMenuItem("Select all", 'a', ExpConstants.MENU_SELECTALL, null, 1));
131         segment.addElement(helper.createMenuItem("Clear", 'e', ExpConstants.MENU_CLEAR, null, 1));
132     }
133     
134     public String getVersion()
135     {
136         return "1.0";
137     }
138 
139     public String getName()
140     {
141         return "Editor Support";
142     }
143 
144     public String getDescription()
145     {
146         return "Menu and toolbar support for cut,copy,paste,undo,redo and select all.";
147     }
148 
149     public void initialiseCore(Properties properties)
150     {}
151 
152     public Vector getPreferences()
153     {
154         log.debug("getPreferences called");
155         return preferences;
156     }
157 
158     public Preference getPreference(String preferenceName)
159     {
160         return (Preference) preferenceHash.get(preferenceName);
161     }
162 
163     public JPanel getPreferencesEditor()
164     {
165         return null;
166     }
167 
168     public ExpActionListener getGlobalListener()
169     {
170         return null;
171     }
172 
173 }