applied LGPLv3 and source code formatting.
[vamsas.git] / src / uk / ac / vamsas / client / picking / MouseOverMessage.java
1 /*\r
2  * This file is part of the Vamsas Client version 0.1. \r
3  * Copyright 2009 by Jim Procter, Iain Milne, Pierre Marguerite, \r
4  *  Andrew Waterhouse and Dominik Lindner.\r
5  * \r
6  * Earlier versions have also been incorporated into Jalview version 2.4 \r
7  * since 2008, and TOPALi version 2 since 2007.\r
8  * \r
9  * The Vamsas Client is free software: you can redistribute it and/or modify\r
10  * it under the terms of the GNU Lesser General Public License as published by\r
11  * the Free Software Foundation, either version 3 of the License, or\r
12  * (at your option) any later version.\r
13  *  \r
14  * The Vamsas Client is distributed in the hope that it will be useful,\r
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
17  * GNU Lesser General Public License for more details.\r
18  * \r
19  * You should have received a copy of the GNU Lesser General Public License\r
20  * along with the Vamsas Client.  If not, see <http://www.gnu.org/licenses/>.\r
21  */\r
22 package uk.ac.vamsas.client.picking;\r
23 \r
24 /**\r
25  * Message class that can be used to send mouse over events.\r
26  */\r
27 public class MouseOverMessage extends Message {\r
28   private String vorbaID;\r
29 \r
30   private int position;\r
31 \r
32   /**\r
33    * Constructs a new mouse over message.\r
34    * \r
35    * @param vorbaID\r
36    *          the VAMSAS object ID of the event's source (usually an alignment\r
37    *          or alignment sequence)\r
38    * @param position\r
39    *          a position on the source in its coordinate system (ie a column or\r
40    *          nucleotide/residue position)\r
41    */\r
42   public MouseOverMessage(String vorbaID, int position) {\r
43     this.vorbaID = vorbaID;\r
44     this.position = position;\r
45 \r
46     message = "MOUSEOVER\t" + "vorbaID=" + vorbaID + "\t" + "position="\r
47         + position;\r
48   }\r
49 \r
50   /**\r
51    * Constructs a new mouse over message from its underlying string format.\r
52    * \r
53    * @param str\r
54    *          the string representation of an instance of this object\r
55    * @throws java.lang.Exception\r
56    *           if the message cannot be reconstructed\r
57    */\r
58   MouseOverMessage(String str) throws Exception {\r
59     message = str;\r
60 \r
61     String[] elements = str.split("\t");\r
62 \r
63     for (int i = 0; i < elements.length; i++) {\r
64       if (elements[i].startsWith("vorbaID="))\r
65         vorbaID = elements[i].substring(8);\r
66       else if (elements[i].startsWith("position="))\r
67         position = Integer.parseInt(elements[i].substring(9));\r
68     }\r
69   }\r
70 \r
71   /**\r
72    * Returns the VAMSAS object ID associated with this message.\r
73    * \r
74    * @return the VAMSAS object ID associated with this message\r
75    */\r
76   public String getVorbaID() {\r
77     return vorbaID;\r
78   }\r
79 \r
80   /**\r
81    * Returns the position value associated with this message.\r
82    * \r
83    * @return the position value associated with this message\r
84    */\r
85   public int getPosition() {\r
86     return position;\r
87   }\r
88 }\r