KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > serverconfig > permissions > tree > PermissionsTreeCell


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.him.serverconfig.permissions.tree;
20
21 import java.awt.Color JavaDoc;
22 import java.awt.Component JavaDoc;
23 import java.awt.Container JavaDoc;
24 import java.awt.Dimension JavaDoc;
25 import java.awt.LayoutManager JavaDoc;
26 import java.awt.event.MouseEvent JavaDoc;
27 import java.awt.event.MouseListener JavaDoc;
28
29 import javax.swing.Icon JavaDoc;
30 import javax.swing.JCheckBox JavaDoc;
31 import javax.swing.JLabel JavaDoc;
32 import javax.swing.JPanel JavaDoc;
33 import javax.swing.UIManager JavaDoc;
34
35 import org.openharmonise.vfs.metadata.value.*;
36
37
38 /**
39  * Cell component for the permissions tree.
40  *
41  * @author Matthew Large
42  * @version $Revision: 1.1 $
43  *
44  */

45 public class PermissionsTreeCell
46     extends JPanel JavaDoc
47     implements MouseListener JavaDoc, LayoutManager JavaDoc {
48
49         /**
50          * Icon for the cell.
51          */

52         private Icon JavaDoc m_icon = null;
53         
54         /**
55          * Name of the object/permission.
56          */

57         private String JavaDoc m_sText = null;
58     
59         /**
60          * Cell icon label.
61          */

62         private JLabel JavaDoc m_iconLabel = new JLabel JavaDoc();
63         
64         /**
65          * Cell text label.
66          */

67         private JLabel JavaDoc m_textLabel = new JLabel JavaDoc();
68         
69         /**
70          * Checkbox.
71          */

72         private JCheckBox JavaDoc m_checkBox = new JCheckBox JavaDoc();
73     
74         /**
75          * Tree node this cell is for.
76          */

77         private PermissionsTreeNode m_node = null;
78
79         /**
80          * Constructs a new permissions tree cell.
81          *
82          * @param node tree node this cell is for.
83          * @param icon icon for this cell.
84          * @param sText name of the object/permission.
85          */

86         public PermissionsTreeCell(PermissionsTreeNode node, Icon JavaDoc icon, String JavaDoc sText) {
87             super();
88             this.m_node = node;
89             this.m_icon = icon;
90             this.m_sText = sText;
91             this.setup();
92         }
93
94         /**
95          * @param arg0
96          */

97         private PermissionsTreeCell(boolean arg0) {
98             super(arg0);
99         }
100
101         /**
102          * @param arg0
103          */

104         private PermissionsTreeCell(LayoutManager JavaDoc arg0) {
105             super(arg0);
106         }
107
108         /**
109          * @param arg0
110          * @param arg1
111          */

112         private PermissionsTreeCell(LayoutManager JavaDoc arg0, boolean arg1) {
113             super(arg0, arg1);
114         }
115     
116         /**
117          * Initialises this component.
118          *
119          */

120         private void setup() {
121         
122             boolean bChecked = false;
123         
124             this.setLayout(this);
125             this.setBackground(Color.WHITE);
126             this.m_textLabel.setFont( UIManager.getFont("Tree.font") );
127         
128             this.m_textLabel.setEnabled(this.m_node.getEnabled());
129         
130             this.m_iconLabel.setIcon(this.m_icon);
131             this.m_iconLabel.setPreferredSize(new Dimension JavaDoc(20,20));
132             this.add(this.m_iconLabel);
133             if(this.m_node.isLeaf()) {
134                 this.m_textLabel.setText(this.m_sText);
135             } else {
136                 this.m_textLabel.setText(this.m_node.getDisplayName());
137             }
138             this.m_textLabel.setPreferredSize(new Dimension JavaDoc(this.m_textLabel.getPreferredSize().width,20));
139             this.add(this.m_textLabel);
140             this.m_checkBox.setPreferredSize(new Dimension JavaDoc(17,20));
141
142             this.m_checkBox.setBackground(Color.WHITE);
143             if(this.m_node.isLeaf()) {
144                 this.add(this.m_checkBox);
145             }
146             if(this.m_node.isLeaf()) {
147                 ValueValue valInst = (ValueValue) this.m_node.getPropertyInstance().getNewValueInstance();
148                 valInst.setValue(this.m_node.getValue().getHREF());
149                 bChecked = this.m_node.getPropertyInstance().getValues().contains( valInst );
150                 if(bChecked) {
151                     this.m_checkBox.setSelected(true);
152                 }
153             } else if(!this.m_node.isLeaf()) {
154
155             }
156         }
157     
158     
159
160         /* (non-Javadoc)
161          * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
162          */

163         public void removeLayoutComponent(Component JavaDoc arg0) {
164         }
165
166         /* (non-Javadoc)
167          * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
168          */

169         public void layoutContainer(Container JavaDoc arg0) {
170             int nWidth = 0;
171             if(this.m_node.isLeaf()) {
172                 this.m_checkBox.setSize( 20,20 );
173             }
174             this.m_textLabel.setSize( this.m_textLabel.getPreferredSize() );
175             this.m_iconLabel.setSize( this.m_iconLabel.getPreferredSize() );
176
177             this.m_iconLabel.setLocation(0,0);
178             nWidth = nWidth + 17;
179             if(this.m_node.isLeaf()) {
180                 this.m_checkBox.setLocation(nWidth,0);
181                 nWidth = nWidth + 22;
182             }
183             this.m_textLabel.setLocation(nWidth,0);
184         }
185
186         /* (non-Javadoc)
187          * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
188          */

189         public void addLayoutComponent(String JavaDoc arg0, Component JavaDoc arg1) {
190         }
191
192         /* (non-Javadoc)
193          * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
194          */

195         public Dimension JavaDoc minimumLayoutSize(Container JavaDoc arg0) {
196             return this.getPreferredSize();
197         }
198
199         /* (non-Javadoc)
200          * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
201          */

202         public Dimension JavaDoc preferredLayoutSize(Container JavaDoc arg0) {
203             return this.getPreferredSize();
204         }
205
206         /* (non-Javadoc)
207          * @see java.awt.Component#getPreferredSize()
208          */

209         public Dimension JavaDoc getPreferredSize() {
210             int nWidth = this.m_checkBox.getPreferredSize().width + this.m_iconLabel.getPreferredSize().width + this.m_textLabel.getPreferredSize().width;
211             return new Dimension JavaDoc(nWidth+3, 20);
212         }
213
214         /* (non-Javadoc)
215          * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
216          */

217         public void mouseClicked(MouseEvent JavaDoc me) {
218             if(me.getPoint().x > this.m_checkBox.getLocation().x
219                 && me.getPoint().x < this.m_checkBox.getLocation().x + this.m_checkBox.getWidth()
220                 && me.getPoint().y > this.m_checkBox.getLocation().y
221                 && me.getPoint().y < this.m_checkBox.getLocation().y + this.m_checkBox.getHeight()) {
222                     if(this.m_checkBox.isSelected()) {
223                         this.m_checkBox.setSelected(false);
224                     } else {
225                         this.m_checkBox.setSelected(true);
226                     }
227                 }
228         }
229
230         /* (non-Javadoc)
231          * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
232          */

233         public void mouseEntered(MouseEvent JavaDoc arg0) {
234         }
235
236         /* (non-Javadoc)
237          * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
238          */

239         public void mouseExited(MouseEvent JavaDoc arg0) {
240         }
241
242         /* (non-Javadoc)
243          * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
244          */

245         public void mousePressed(MouseEvent JavaDoc arg0) {
246         }
247
248         /* (non-Javadoc)
249          * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
250          */

251         public void mouseReleased(MouseEvent JavaDoc arg0) {
252         }
253
254     }
255
Popular Tags