1 package cz
.cvut
.promod
.services
.actionService
;
3 import cz
.cvut
.promod
.services
.actionService
.actionUtils
.ProModAction
;
4 import org
.apache
.log4j
.Logger
;
7 import java
.util
.HashMap
;
11 * ProMod, master thesis project
12 * User: Petr Zverina, petr.zverina@gmail.com
13 * Date: 17:19:25, 2.11.2009
17 * Notation specific actions holder.
19 public class NotationSpecificActions
{
21 private final Logger LOG
= Logger
.getLogger(NotationSpecificActions
.class);
23 private final Map
<String
, ProModAction
> notationActionsMap
;
25 private final Map
<String
, ModuleSpecificActions
> moduleActionsMap
;
28 public NotationSpecificActions(){
29 notationActionsMap
= new HashMap
<String
, ProModAction
>();
30 moduleActionsMap
= new HashMap
<String
, ModuleSpecificActions
>();
34 * @param actionIdentifier is the action identifier
35 * @return returns the action is such a action exists, null otherwise
37 public ProModAction
getAction(final String actionIdentifier
) {
38 if(notationActionsMap
.containsKey(actionIdentifier
)){
39 return notationActionsMap
.get(actionIdentifier
);
46 * @param moduleIdentifier is the module identifier
47 * @param actionIdentifier is the action identifier
48 * @return returns the action is such a action exists, null otherwise
50 public ProModAction
getAction(final String moduleIdentifier
, final String actionIdentifier
) {
51 if(moduleActionsMap
.containsKey(moduleIdentifier
)){
52 return moduleActionsMap
.get(moduleIdentifier
).getAction(actionIdentifier
);
60 * @param moduleIdentifier module identifier
61 * @param actionIdentifier action identifier
62 * @param newProModAction the action itself
64 public void setAction(final String moduleIdentifier
, final String actionIdentifier
, final ProModAction newProModAction
) {
65 if(moduleIdentifier
== null){
66 if(notationActionsMap
.containsKey(actionIdentifier
)){
67 LOG
.error("An attempt to insert the same notation action to the notation actions map, action identifier: " + actionIdentifier
+ ".");
69 notationActionsMap
.put(actionIdentifier
, newProModAction
);
73 if(moduleActionsMap
.containsKey(moduleIdentifier
)){
74 moduleActionsMap
.get(moduleIdentifier
).setAction(actionIdentifier
, newProModAction
);
76 final ModuleSpecificActions moduleSpecificActions
= new ModuleSpecificActions();
77 moduleSpecificActions
.setAction(actionIdentifier
, newProModAction
);
78 moduleActionsMap
.put(moduleIdentifier
, moduleSpecificActions
);
84 * Updates the action visibility on the basis of active notation.
85 * @param notationIdentifier is the identifier of active notation.
87 public void updateActionVisibility(final String notationIdentifier
) {
88 for(final ProModAction proModAction
: notationActionsMap
.values()){
89 proModAction
.updateActionVisibility(notationIdentifier
);
92 for(final ModuleSpecificActions moduleSpecificActions
: moduleActionsMap
.values()){
93 moduleSpecificActions
.updateActionVisibility(notationIdentifier
);
98 * Tests whether there is no other already registered action with the same accelerator key definition
99 * by this notation. Additionally, check all registered actions of this notation's modules.
101 * @param keyStroke is the accelerator key to be tested
102 * @return true if there is such a action, false otherwise
104 public boolean existAcceleratorKey(final KeyStroke keyStroke
){
105 for(final ProModAction action
: notationActionsMap
.values()){
106 final KeyStroke key
= (KeyStroke
) action
.getValue(AbstractAction
.ACCELERATOR_KEY
);
108 if(key
!= null && key
.equals(keyStroke
)){
113 for(final ModuleSpecificActions moduleSpecificActions
: moduleActionsMap
.values()){
114 if(moduleSpecificActions
.existAcceleratorKey(keyStroke
)){
123 * Check whether such a action has been already registered by a notation or any of it's modules.
125 * @param action is the action to be checked
126 * @return true if such a actions has been already registered, false otherwise
128 public boolean existAction(final ProModAction action
) {
129 if(notationActionsMap
.values().contains(action
)){
133 for(final ModuleSpecificActions moduleSpecificActions
: moduleActionsMap
.values()){
134 if(moduleSpecificActions
.exist(action
)){