~ubuntu-branches/ubuntu/lucid/jedit/lucid

« back to all changes in this revision

Viewing changes to jEdit/org/gjt/sp/jedit/JEditActionContext.java

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Hahler
  • Date: 2008-03-18 22:18:17 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080318221817-8pvhmkoy8nkdghy2
Tags: 4.3~pre13.dfsg-0ubuntu1
* New upstream bugfix release (LP: #203713)
* debian/control, debian/rules:
  replace icedtea-java7 references with openjdk-6 references (LP: #203636)
* Reworked (and renamed) patches:
  - 01-debian-menu-file.patch: partly applied upstream
  - 02-desktop-file-icon-file.patch: incorporate previous inline change
    (icon path)
* 03-svn-php_mode_fix_special_comment.patch: Fix regression for special
  comments ("/**/") in PHP mode; can be dropped with the next release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * JEditActionContext.java - For code sharing between jEdit and VFSBrowser
 
3
 * :tabSize=8:indentSize=8:noTabs=false:
 
4
 * :folding=explicit:collapseFolds=1:
 
5
 *
 
6
 * Copyright (C) 1998, 2003 Slava Pestov
 
7
 * Portions copyright (C) 2007 Matthieu Casanova
 
8
 *
 
9
 * This program is free software; you can redistribute it and/or
 
10
 * modify it under the terms of the GNU General Public License
 
11
 * as published by the Free Software Foundation; either version 2
 
12
 * of the License, or any later version.
 
13
 *
 
14
 * This program is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 * GNU General Public License for more details.
 
18
 *
 
19
 * You should have received a copy of the GNU General Public License
 
20
 * along with this program; if not, write to the Free Software
 
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
22
 */
 
23
 
 
24
package org.gjt.sp.jedit;
 
25
 
 
26
import java.lang.reflect.Array;
 
27
import java.util.*;
 
28
 
 
29
/**
 
30
 * Manages a collection of action sets. There are two instances of this class
 
31
 * in jEdit:
 
32
 * <ul>
 
33
 * <li>{@link org.gjt.sp.jedit.jEdit#getActionContext()} - editor actions
 
34
 * <li>{@link org.gjt.sp.jedit.browser.VFSBrowser#getActionContext()} - browser
 
35
 * actions
 
36
 * </ul>
 
37
 *
 
38
 * @since jEdit 4.3pre13
 
39
 * @author Slava Pestov
 
40
 * @version $Id: ActionContext.java 6884 2006-09-06 02:38:55Z ezust $
 
41
 */
 
42
public abstract class JEditActionContext<F extends JEditAbstractEditAction, E extends JEditActionSet<F>>
 
43
{
 
44
        //{{{ invokeAction() method
 
45
        /**
 
46
         * Invokes the given action in response to a user-generated event.
 
47
         * @param evt The event
 
48
         * @param action The action
 
49
         * @since jEdit 4.3pre13
 
50
         */
 
51
        public abstract void invokeAction(EventObject evt, F action);
 
52
        //}}}
 
53
 
 
54
        //{{{ addActionSet() method
 
55
        /**
 
56
         * Adds a new action set to the context.
 
57
         * @since jEdit 4.3pre13
 
58
         */
 
59
        public void addActionSet(E actionSet)
 
60
        {
 
61
                actionNames = null;
 
62
                actionSets.addElement(actionSet);
 
63
                actionSet.context = this;
 
64
                String[] actions = actionSet.getActionNames();
 
65
                for(int i = 0; i < actions.length; i++)
 
66
                {
 
67
                        /* Is it already there? */
 
68
                        if (actionHash.containsKey(actions[i])) 
 
69
                        {
 
70
                                /* Save it for plugin unloading time */
 
71
                                E oldAction = actionHash.get(actions[i]);
 
72
                                overriddenActions.put(actions[i], oldAction);
 
73
                        }
 
74
                        actionHash.put(actions[i],actionSet);
 
75
                }
 
76
        } //}}}
 
77
 
 
78
        //{{{ removeActionSet() method
 
79
        /**
 
80
         * Removes an action set from the context.
 
81
         * @since jEdit 4.23pre13
 
82
         */
 
83
        public void removeActionSet(E actionSet)
 
84
        {
 
85
                actionNames = null;
 
86
                actionSets.removeElement(actionSet);
 
87
                actionSet.context = null;
 
88
                String[] actions = actionSet.getActionNames();
 
89
                for(int i = 0; i < actions.length; i++)
 
90
                {
 
91
                        actionHash.remove(actions[i]);
 
92
                        if (overriddenActions.containsKey(actions[i])) 
 
93
                        {
 
94
                                E oldAction = overriddenActions.remove(actions[i]);
 
95
                                actionHash.put(actions[i], oldAction);
 
96
                        }
 
97
                }
 
98
        } //}}}
 
99
 
 
100
        //{{{ getActionSets() method
 
101
        /**
 
102
         * Returns all registered action sets.
 
103
         * @since jEdit 4.3pre13
 
104
         */
 
105
        public E[] getActionSets()
 
106
        {
 
107
                if (actionSets.isEmpty())
 
108
                        return null;
 
109
                Class clazz = actionSets.get(0).getClass();
 
110
                E[] retVal =(E[]) Array.newInstance(clazz, actionSets.size());
 
111
                actionSets.copyInto(retVal);
 
112
                return retVal;
 
113
        } //}}}
 
114
 
 
115
        //{{{ getAction() method
 
116
        /**
 
117
         * Returns the specified action.
 
118
         * @param name The action name
 
119
         * @return a JEditAbstractEditAction or null if it doesn't exists
 
120
         * @since jEdit 4.3pre13
 
121
         */
 
122
        public F getAction(String name)
 
123
        {
 
124
                E set = actionHash.get(name);
 
125
                if(set == null)
 
126
                        return null;
 
127
                else
 
128
                        return set.getAction(name);
 
129
        } //}}}
 
130
 
 
131
        //{{{ getActionSetForAction() method
 
132
        /**
 
133
         * Returns the action set that contains the specified action.
 
134
         *
 
135
         * @param action The action
 
136
         * @return the actionSet that contains the given action
 
137
         * @since jEdit 4.3pre13
 
138
         */
 
139
        public E getActionSetForAction(String action)
 
140
        {
 
141
                return actionHash.get(action);
 
142
        } //}}}
 
143
 
 
144
        //{{{ getActionNames() method
 
145
        /**
 
146
         * Returns all registered action names.
 
147
         */
 
148
        public String[] getActionNames()
 
149
        {
 
150
                if(actionNames == null)
 
151
                {
 
152
                        List<String> vec = new LinkedList<String>();
 
153
                        for(int i = 0; i < actionSets.size(); i++)
 
154
                                (actionSets.elementAt(i)).getActionNames(vec);
 
155
 
 
156
                        actionNames = vec.toArray(new String[vec.size()]);
 
157
                        Arrays.sort(actionNames,
 
158
                                new MiscUtilities.StringICaseCompare());
 
159
                }
 
160
 
 
161
                return actionNames;
 
162
        } //}}}
 
163
 
 
164
        //{{{ Package-private members
 
165
        String[] actionNames;
 
166
        /** 
 
167
         * This map contains as key an action name, 
 
168
         * and as value the JEditActionSet that contains this action
 
169
         */
 
170
        Hashtable<String, E> actionHash = new Hashtable<String, E>();
 
171
        
 
172
        /** A map of built-in actions that were overridden by plugins. */
 
173
        Hashtable<String, E> overriddenActions = new Hashtable<String, E>(); 
 
174
        //}}}
 
175
 
 
176
        //{{{ Private members
 
177
        private final Vector<E> actionSets = new Vector<E>();
 
178
        //}}}
 
179
}