KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > tribe > demos > draw > WhiteBoardCommand


1 /**
2  * Tribe: Group communication library.
3  * Copyright (C) 2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: tribe@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Bela Ban.
22  * Contributor(s): Emmanuel Cecchet.
23  */

24
25 package org.objectweb.tribe.demos.draw;
26
27 import java.io.Serializable JavaDoc;
28
29 /**
30  * This class defines a WhiteBoardCommand. It is used either for drawing a point
31  * or clearing the display. One should have used 2 separate classes since it is
32  * useless to transport point information just for a clear command, but I have
33  * just reused the code from the JGroups demo.
34  *
35  * @author Bela Ban, 2001
36  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
37  * @version 1.0
38  */

39 public class WhiteBoardCommand implements Serializable JavaDoc
40 {
41   static final int DRAW = 1;
42   static final int CLEAR = 2;
43   int mode;
44   int x = 0;
45   int y = 0;
46   int r = 0;
47   int g = 0;
48   int b = 0;
49
50   /**
51    * Creates a new <code>WhiteBoardCommand</code> object for clearing the
52    * display.
53    */

54   WhiteBoardCommand()
55   {
56     this.mode = CLEAR;
57   }
58
59   /**
60    * Creates a new <code>WhiteBoardCommand</code> object to draw a point.
61    *
62    * @param x x coordinate of the point
63    * @param y y coordinate of the point
64    * @param r red color
65    * @param g green color
66    * @param b blue color
67    */

68   WhiteBoardCommand(int x, int y, int r, int g, int b)
69   {
70     this.mode = DRAW;
71     this.x = x;
72     this.y = y;
73     this.r = r;
74     this.g = g;
75     this.b = b;
76   }
77
78   /**
79    * Copy this object.
80    *
81    * @return A new instance of this object.
82    */

83   WhiteBoardCommand Copy()
84   {
85     if (mode == CLEAR)
86       return new WhiteBoardCommand();
87     else
88       return new WhiteBoardCommand(x, y, r, g, b);
89   }
90
91   /**
92    * @see java.lang.Object#toString()
93    */

94   public String JavaDoc toString()
95   {
96     StringBuffer JavaDoc ret = new StringBuffer JavaDoc();
97     switch (mode)
98     {
99       case DRAW :
100         ret
101             .append("DRAW(" + x + ", " + y + ") [" + r + "|" + g + "|" + b
102                 + "]");
103         break;
104       case CLEAR :
105         ret.append("CLEAR");
106         break;
107       default :
108         return "<undefined>";
109     }
110     return ret.toString();
111   }
112
113 }
Popular Tags