f@0
|
1 /*
|
f@0
|
2 CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool
|
f@0
|
3
|
f@0
|
4 Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/)
|
f@0
|
5
|
f@0
|
6 This program is free software: you can redistribute it and/or modify
|
f@0
|
7 it under the terms of the GNU General Public License as published by
|
f@0
|
8 the Free Software Foundation, either version 3 of the License, or
|
f@0
|
9 (at your option) any later version.
|
f@0
|
10
|
f@0
|
11 This program is distributed in the hope that it will be useful,
|
f@0
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
f@0
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
f@0
|
14 GNU General Public License for more details.
|
f@0
|
15
|
f@0
|
16 You should have received a copy of the GNU General Public License
|
f@0
|
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
|
f@0
|
18 */
|
f@0
|
19
|
f@0
|
20 package uk.ac.qmul.eecs.ccmi.network;
|
f@0
|
21
|
f@0
|
22 import uk.ac.qmul.eecs.ccmi.gui.Lock;
|
f@0
|
23
|
f@0
|
24 /**
|
f@0
|
25 * A utility class providing static methods to convert a Lock into the LockMessage
|
f@0
|
26 * conveying it. And the other way around.
|
f@0
|
27 *
|
f@0
|
28 *
|
f@0
|
29 */
|
f@0
|
30 public class LockMessageConverter {
|
f@0
|
31 /**
|
f@0
|
32 * Creates a lock message out of a lock passed as argument
|
f@0
|
33 * @param lock the lock to be converted
|
f@0
|
34 * @param isGet whether it's a "get-lock" or "yield-lock" message
|
f@0
|
35 * @return the lock message
|
f@0
|
36 */
|
f@0
|
37 public static LockMessage.Name getLockMessageNamefromLock(Lock lock, boolean isGet){
|
f@0
|
38 LockMessage.Name name = LockMessage.Name.NONE_L;
|
f@0
|
39 switch (lock){
|
f@0
|
40 case DELETE : name = ((isGet) ? LockMessage.Name.GET_DELETE_L : LockMessage.Name.YIELD_DELETE_L);
|
f@0
|
41 break;
|
f@0
|
42 case NAME : name = (isGet) ? LockMessage.Name.GET_NAME_L : LockMessage.Name.YIELD_NAME_L ;
|
f@0
|
43 break;
|
f@0
|
44 case PROPERTIES : name = (isGet) ? LockMessage.Name.GET_PROPERTIES_L : LockMessage.Name.YIELD_PROPERTIES_L ;
|
f@0
|
45 break;
|
f@0
|
46 case EDGE_END : name = (isGet) ? LockMessage.Name.GET_EDGE_END_L : LockMessage.Name.YIELD_EDGE_END_L ;
|
f@0
|
47 break;
|
f@0
|
48 case MOVE : name = (isGet) ? LockMessage.Name.GET_MOVE_L : LockMessage.Name.YIELD_MOVE_L ;
|
f@0
|
49 break;
|
f@0
|
50 case NOTES : name = (isGet) ? LockMessage.Name.GET_NOTES_L : LockMessage.Name.YIELD_NOTES_L ;
|
f@0
|
51 break;
|
f@0
|
52 case BOOKMARK : name = (isGet) ? LockMessage.Name.GET_BOOKMARK_L : LockMessage.Name.YIELD_BOOKMARK_L ;
|
f@0
|
53 break;
|
f@0
|
54 case MUST_EXIST : name = (isGet) ? LockMessage.Name.GET_MUST_EXIST_L : LockMessage.Name.YIELD_MUST_EXISTS_L;
|
f@0
|
55 break;
|
f@0
|
56 }
|
f@0
|
57 return name;
|
f@0
|
58 }
|
f@0
|
59
|
f@0
|
60 /**
|
f@0
|
61 * Returns the lock conveyed by the lock message passed as argument
|
f@0
|
62 * @param name the lock message name @see LockMessage.Name
|
f@0
|
63 * @return the conveyed lock
|
f@0
|
64 */
|
f@0
|
65 public static Lock getLockFromMessageName(LockMessage.Name name){
|
f@0
|
66 Lock lock = Lock.NONE;
|
f@0
|
67 switch(name){
|
f@0
|
68 case GET_DELETE_L :
|
f@0
|
69 case YIELD_DELETE_L :
|
f@0
|
70 lock = Lock.DELETE;
|
f@0
|
71 break;
|
f@0
|
72 case GET_NAME_L :
|
f@0
|
73 case YIELD_NAME_L :
|
f@0
|
74 lock = Lock.NAME;
|
f@0
|
75 break;
|
f@0
|
76 case GET_PROPERTIES_L :
|
f@0
|
77 case YIELD_PROPERTIES_L :
|
f@0
|
78 lock = Lock.PROPERTIES;
|
f@0
|
79 break;
|
f@0
|
80 case GET_EDGE_END_L :
|
f@0
|
81 case YIELD_EDGE_END_L :
|
f@0
|
82 lock = Lock.EDGE_END;
|
f@0
|
83 break;
|
f@0
|
84 case GET_MOVE_L :
|
f@0
|
85 case YIELD_MOVE_L:
|
f@0
|
86 lock = Lock.MOVE;
|
f@0
|
87 break;
|
f@0
|
88 case GET_NOTES_L :
|
f@0
|
89 case YIELD_NOTES_L :
|
f@0
|
90 lock = Lock.NOTES;
|
f@0
|
91 break;
|
f@0
|
92 case GET_BOOKMARK_L :
|
f@0
|
93 case YIELD_BOOKMARK_L :
|
f@0
|
94 lock = Lock.BOOKMARK;
|
f@0
|
95 break;
|
f@0
|
96 case GET_MUST_EXIST_L :
|
f@0
|
97 case YIELD_MUST_EXISTS_L:
|
f@0
|
98 lock = Lock.MUST_EXIST;
|
f@0
|
99 break;
|
f@0
|
100 }
|
f@0
|
101 return lock;
|
f@0
|
102 }
|
f@0
|
103 }
|