f@0: /* f@0: CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool f@0: f@0: Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/) f@0: f@0: This program is free software: you can redistribute it and/or modify f@0: it under the terms of the GNU General Public License as published by f@0: the Free Software Foundation, either version 3 of the License, or f@0: (at your option) any later version. f@0: f@0: This program is distributed in the hope that it will be useful, f@0: but WITHOUT ANY WARRANTY; without even the implied warranty of f@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the f@0: GNU General Public License for more details. f@0: f@0: You should have received a copy of the GNU General Public License f@0: along with this program. If not, see . f@0: */ f@0: f@0: package uk.ac.qmul.eecs.ccmi.network; f@0: f@0: import uk.ac.qmul.eecs.ccmi.gui.Lock; f@0: f@0: /** f@0: * A utility class providing static methods to convert a Lock into the LockMessage f@0: * conveying it. And the other way around. f@0: * f@0: * f@0: */ f@0: public class LockMessageConverter { f@0: /** f@0: * Creates a lock message out of a lock passed as argument f@0: * @param lock the lock to be converted f@0: * @param isGet whether it's a "get-lock" or "yield-lock" message f@0: * @return the lock message f@0: */ f@0: public static LockMessage.Name getLockMessageNamefromLock(Lock lock, boolean isGet){ f@0: LockMessage.Name name = LockMessage.Name.NONE_L; f@0: switch (lock){ f@0: case DELETE : name = ((isGet) ? LockMessage.Name.GET_DELETE_L : LockMessage.Name.YIELD_DELETE_L); f@0: break; f@0: case NAME : name = (isGet) ? LockMessage.Name.GET_NAME_L : LockMessage.Name.YIELD_NAME_L ; f@0: break; f@0: case PROPERTIES : name = (isGet) ? LockMessage.Name.GET_PROPERTIES_L : LockMessage.Name.YIELD_PROPERTIES_L ; f@0: break; f@0: case EDGE_END : name = (isGet) ? LockMessage.Name.GET_EDGE_END_L : LockMessage.Name.YIELD_EDGE_END_L ; f@0: break; f@0: case MOVE : name = (isGet) ? LockMessage.Name.GET_MOVE_L : LockMessage.Name.YIELD_MOVE_L ; f@0: break; f@0: case NOTES : name = (isGet) ? LockMessage.Name.GET_NOTES_L : LockMessage.Name.YIELD_NOTES_L ; f@0: break; f@0: case BOOKMARK : name = (isGet) ? LockMessage.Name.GET_BOOKMARK_L : LockMessage.Name.YIELD_BOOKMARK_L ; f@0: break; f@0: case MUST_EXIST : name = (isGet) ? LockMessage.Name.GET_MUST_EXIST_L : LockMessage.Name.YIELD_MUST_EXISTS_L; f@0: break; f@0: } f@0: return name; f@0: } f@0: f@0: /** f@0: * Returns the lock conveyed by the lock message passed as argument f@0: * @param name the lock message name @see LockMessage.Name f@0: * @return the conveyed lock f@0: */ f@0: public static Lock getLockFromMessageName(LockMessage.Name name){ f@0: Lock lock = Lock.NONE; f@0: switch(name){ f@0: case GET_DELETE_L : f@0: case YIELD_DELETE_L : f@0: lock = Lock.DELETE; f@0: break; f@0: case GET_NAME_L : f@0: case YIELD_NAME_L : f@0: lock = Lock.NAME; f@0: break; f@0: case GET_PROPERTIES_L : f@0: case YIELD_PROPERTIES_L : f@0: lock = Lock.PROPERTIES; f@0: break; f@0: case GET_EDGE_END_L : f@0: case YIELD_EDGE_END_L : f@0: lock = Lock.EDGE_END; f@0: break; f@0: case GET_MOVE_L : f@0: case YIELD_MOVE_L: f@0: lock = Lock.MOVE; f@0: break; f@0: case GET_NOTES_L : f@0: case YIELD_NOTES_L : f@0: lock = Lock.NOTES; f@0: break; f@0: case GET_BOOKMARK_L : f@0: case YIELD_BOOKMARK_L : f@0: lock = Lock.BOOKMARK; f@0: break; f@0: case GET_MUST_EXIST_L : f@0: case YIELD_MUST_EXISTS_L: f@0: lock = Lock.MUST_EXIST; f@0: break; f@0: } f@0: return lock; f@0: } f@0: }