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