KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > serverconfig > permissions > list > PermissionsSelectionCell


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.list;
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.Font JavaDoc;
26 import java.awt.LayoutManager JavaDoc;
27 import java.awt.event.MouseEvent JavaDoc;
28 import java.awt.event.MouseListener JavaDoc;
29
30 import javax.swing.JLabel JavaDoc;
31 import javax.swing.JPanel JavaDoc;
32
33 import org.openharmonise.vfs.*;
34 import org.openharmonise.vfs.gui.*;
35
36
37 /**
38  * Cell for list of Roles.
39  *
40  * @author Matthew Large
41  * @version $Revision: 1.1 $
42  *
43  */

44 public class PermissionsSelectionCell
45     extends JPanel JavaDoc
46     implements MouseListener JavaDoc, LayoutManager JavaDoc {
47
48         /**
49          * Role name label.
50          */

51         private JLabel JavaDoc m_label = null;
52     
53         /**
54          * Full path to virtual file representing this Role.
55          */

56         private String JavaDoc m_sPath = null;
57         
58         /**
59          * Virtual file system for virtual file representing this Role.
60          */

61         private AbstractVirtualFileSystem m_vfs = null;
62     
63         /**
64          * true if this Role is selected.
65          */

66         private boolean m_bSelected = false;
67     
68         /**
69          * Width of this cell.
70          */

71         private int m_nWidth = 340;
72     
73         /**
74          * List that this cell is in.
75          */

76         private PermissionsSelectionList m_parent = null;
77
78         /**
79          * Constructs a new Role cell.
80          *
81          * @param parent list that this cell is in.
82          * @param sPath full path to virtual file representing this Role.
83          * @param vfs virtual file system for virtual file representing this Role.
84          */

85         public PermissionsSelectionCell(PermissionsSelectionList parent, String JavaDoc sPath, AbstractVirtualFileSystem vfs) {
86             super();
87             this.m_sPath = sPath;
88             this.m_vfs = vfs;
89         
90             this.m_parent = parent;
91             this.setup();
92         }
93
94         /**
95          * Initialises this component.
96          *
97          */

98         private void setup() {
99         
100             VirtualFile vfFile = this.m_vfs.getVirtualFile(this.m_sPath).getResource();
101             VirtualFileSystemView vfsView = this.m_vfs.getVirtualFileSystemView();
102         
103             String JavaDoc fontName = "Dialog";
104             int fontSize = 11;
105             Font JavaDoc font = new Font JavaDoc(fontName, Font.PLAIN, fontSize);
106         
107             this.setLayout(this);
108             this.setBackground(Color.WHITE);
109         
110             this.m_label = new JLabel JavaDoc( vfsView.getDisplayName(vfFile) );
111             this.m_label.addMouseListener(this);
112             this.m_label.setToolTipText( vfFile.getFullPath() );
113             this.m_label.setFont(font);
114             this.m_label.setBackground(Color.WHITE);
115             this.m_label.setIcon( IconManager.getInstance().getIcon("16-user-container.gif") );
116             this.add(this.m_label);
117         }
118
119         /* (non-Javadoc)
120          * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
121          */

122         public void removeLayoutComponent(Component JavaDoc arg0) {
123         }
124
125         /* (non-Javadoc)
126          * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
127          */

128         public void layoutContainer(Container JavaDoc arg0) {
129             this.m_label.setSize(m_nWidth-20, 20);
130             this.m_label.setLocation(0,0);
131         }
132
133         /* (non-Javadoc)
134          * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
135          */

136         public void addLayoutComponent(String JavaDoc arg0, Component JavaDoc arg1) {
137         }
138
139         /* (non-Javadoc)
140          * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
141          */

142         public Dimension JavaDoc minimumLayoutSize(Container JavaDoc arg0) {
143             return this.getPreferredSize();
144         }
145
146         /* (non-Javadoc)
147          * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
148          */

149         public Dimension JavaDoc preferredLayoutSize(Container JavaDoc arg0) {
150             return this.getPreferredSize();
151         }
152
153         /* (non-Javadoc)
154          * @see java.awt.Component#getPreferredSize()
155          */

156         public Dimension JavaDoc getPreferredSize() {
157             return new Dimension JavaDoc(m_nWidth, 20);
158         }
159     
160     
161
162         /* (non-Javadoc)
163          * @see java.lang.Object#equals(java.lang.Object)
164          */

165         public boolean equals(Object JavaDoc obj) {
166             boolean bRetn = false;
167             if(obj instanceof PermissionsSelectionCell) {
168                 PermissionsSelectionCell cell = (PermissionsSelectionCell)obj;
169                 if(cell.getPath().trim().equals(this.m_sPath) &&
170                 cell.getVFS().getInitialPath().trim().equals(this.m_vfs.getInitialPath())) {
171                     bRetn=true;
172                 }
173             }
174             return bRetn;
175         }
176
177         /**
178          * Returns the full path to the virtual file representing
179          * this Role.
180          *
181          * @return full path to the virtual file representing this Role.
182          */

183         public String JavaDoc getPath() {
184             return m_sPath;
185         }
186
187         /**
188          * Virtual file system for the full path to the virtual file representing
189          * this Role.
190          *
191          * @return Virtual file system for the virtual file representing this Role.
192          */

193         public AbstractVirtualFileSystem getVFS() {
194             return m_vfs;
195         }
196
197         /**
198          * Checks is this cell is selected.
199          *
200          * @return true if this cell is selected.
201          */

202         public boolean isSelected() {
203             return m_bSelected;
204         }
205
206         /**
207          * Sets whether this cell is selected.
208          *
209          * @param bSelected true if this cell is selected.
210          */

211         public void setSelected(boolean bSelected) {
212             m_bSelected = bSelected;
213             if(this.m_bSelected) {
214                 this.setBackground( new Color JavaDoc(173, 169, 143));
215             } else {
216                 this.setBackground(Color.WHITE);
217                 this.m_label.setBackground(Color.WHITE);
218             }
219             this.repaint();
220         }
221
222         /* (non-Javadoc)
223          * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
224          */

225         public void mouseClicked(MouseEvent JavaDoc me) {
226             MouseListener JavaDoc[] listeners = this.getMouseListeners();
227             me.setSource(this);
228             for(int i=0; i<listeners.length; i++) {
229                 listeners[i].mouseClicked(me);
230             }
231         }
232
233         /* (non-Javadoc)
234          * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
235          */

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

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

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

254         public void mouseReleased(MouseEvent JavaDoc arg0) {
255         }
256
257     }
258
Popular Tags