KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > console > gui > objects > DatabaseObject


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@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): Nicolas Modrzyk
22  * Contributor(s): ______________________.
23  */

24
25 package org.objectweb.cjdbc.console.gui.objects;
26
27 import java.awt.Color JavaDoc;
28
29 import org.objectweb.cjdbc.console.gui.constants.GuiConstants;
30 import org.objectweb.cjdbc.console.gui.constants.GuiIcons;
31
32 /**
33  * This class defines a DatabaseObject
34  *
35  * @author <a HREF="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
36  * @version 1.0
37  */

38 public class DatabaseObject extends AbstractGuiObject
39 {
40   private String JavaDoc state;
41   private String JavaDoc controllerName;
42   private boolean isDistributed;
43
44   /**
45    * Creates a new <code>ControllerObject</code> object
46    *
47    * @param databaseName the name of the database
48    * @param controllerName the name of the controller the database belongs to
49    * @param isDistributed if the database is distributed set to
50    * <code>true</code>
51    */

52   public DatabaseObject(String JavaDoc databaseName, String JavaDoc controllerName,
53       boolean isDistributed)
54   {
55     super();
56     setText(databaseName);
57     setName(databaseName);
58     this.controllerName = controllerName;
59     this.isDistributed = isDistributed;
60     setBackground(Color.white);
61     if (isDistributed)
62       setIcon(GuiIcons.DATABASE_DISTRIBUTED_ICON);
63     else
64       setIcon(GuiIcons.DATABASE_SINGLE_ICON);
65   }
66
67   /**
68    * Get ip address of this controller
69    *
70    * @return ipAddress
71    */

72   public String JavaDoc getIpAdress()
73   {
74     return controllerName.substring(0, controllerName.indexOf(':'));
75   }
76
77   /**
78    * Get port of this controller
79    *
80    * @return port
81    */

82   public String JavaDoc getPort()
83   {
84     return controllerName.substring(controllerName.indexOf(':') + 1);
85   }
86
87   /**
88    * Get the state of the controller
89    *
90    * @return state of controller as defined in gui constants , null if unknown
91    */

92   public String JavaDoc getState()
93   {
94     return state;
95   }
96
97   /**
98    * Set state of controller and change its icon
99    *
100    * @param state string description of the state
101    */

102   public void setState(String JavaDoc state)
103   {
104     if (state.equals(GuiConstants.CONTROLLER_STATE_UP))
105       setIcon(GuiIcons.CONTROLLER_READY);
106     else
107       setIcon(GuiIcons.CONTROLLER_DOWN);
108     this.state = state;
109   }
110
111   /**
112    * Returns the controllerName value.
113    *
114    * @return Returns the controllerName.
115    */

116   public String JavaDoc getControllerName()
117   {
118     return controllerName;
119   }
120
121   /**
122    * Returns the isDistributed value.
123    *
124    * @return Returns the isDistributed.
125    */

126   public boolean isDistributed()
127   {
128     return isDistributed;
129   }
130
131   /**
132    * Sets the isDistributed value.
133    *
134    * @param isDistributed The isDistributed to set.
135    */

136   public void setDistributed(boolean isDistributed)
137   {
138     this.isDistributed = isDistributed;
139   }
140 }
Popular Tags