001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.him.serverconfig.permissions.list;
020:
021: import java.awt.Color;
022: import java.awt.Component;
023: import java.awt.Container;
024: import java.awt.Dimension;
025: import java.awt.Font;
026: import java.awt.LayoutManager;
027: import java.awt.event.MouseEvent;
028: import java.awt.event.MouseListener;
029:
030: import javax.swing.JLabel;
031: import javax.swing.JPanel;
032:
033: import org.openharmonise.vfs.*;
034: import org.openharmonise.vfs.gui.*;
035:
036: /**
037: * Cell for list of Roles.
038: *
039: * @author Matthew Large
040: * @version $Revision: 1.1 $
041: *
042: */
043: public class PermissionsSelectionCell extends JPanel implements
044: MouseListener, LayoutManager {
045:
046: /**
047: * Role name label.
048: */
049: private JLabel m_label = null;
050:
051: /**
052: * Full path to virtual file representing this Role.
053: */
054: private String m_sPath = null;
055:
056: /**
057: * Virtual file system for virtual file representing this Role.
058: */
059: private AbstractVirtualFileSystem m_vfs = null;
060:
061: /**
062: * true if this Role is selected.
063: */
064: private boolean m_bSelected = false;
065:
066: /**
067: * Width of this cell.
068: */
069: private int m_nWidth = 340;
070:
071: /**
072: * List that this cell is in.
073: */
074: private PermissionsSelectionList m_parent = null;
075:
076: /**
077: * Constructs a new Role cell.
078: *
079: * @param parent list that this cell is in.
080: * @param sPath full path to virtual file representing this Role.
081: * @param vfs virtual file system for virtual file representing this Role.
082: */
083: public PermissionsSelectionCell(PermissionsSelectionList parent,
084: String sPath, AbstractVirtualFileSystem vfs) {
085: super ();
086: this .m_sPath = sPath;
087: this .m_vfs = vfs;
088:
089: this .m_parent = parent;
090: this .setup();
091: }
092:
093: /**
094: * Initialises this component.
095: *
096: */
097: private void setup() {
098:
099: VirtualFile vfFile = this .m_vfs.getVirtualFile(this .m_sPath)
100: .getResource();
101: VirtualFileSystemView vfsView = this .m_vfs
102: .getVirtualFileSystemView();
103:
104: String fontName = "Dialog";
105: int fontSize = 11;
106: Font font = new Font(fontName, Font.PLAIN, fontSize);
107:
108: this .setLayout(this );
109: this .setBackground(Color.WHITE);
110:
111: this .m_label = new JLabel(vfsView.getDisplayName(vfFile));
112: this .m_label.addMouseListener(this );
113: this .m_label.setToolTipText(vfFile.getFullPath());
114: this .m_label.setFont(font);
115: this .m_label.setBackground(Color.WHITE);
116: this .m_label.setIcon(IconManager.getInstance().getIcon(
117: "16-user-container.gif"));
118: this .add(this .m_label);
119: }
120:
121: /* (non-Javadoc)
122: * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
123: */
124: public void removeLayoutComponent(Component arg0) {
125: }
126:
127: /* (non-Javadoc)
128: * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
129: */
130: public void layoutContainer(Container arg0) {
131: this .m_label.setSize(m_nWidth - 20, 20);
132: this .m_label.setLocation(0, 0);
133: }
134:
135: /* (non-Javadoc)
136: * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
137: */
138: public void addLayoutComponent(String arg0, Component arg1) {
139: }
140:
141: /* (non-Javadoc)
142: * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
143: */
144: public Dimension minimumLayoutSize(Container arg0) {
145: return this .getPreferredSize();
146: }
147:
148: /* (non-Javadoc)
149: * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
150: */
151: public Dimension preferredLayoutSize(Container arg0) {
152: return this .getPreferredSize();
153: }
154:
155: /* (non-Javadoc)
156: * @see java.awt.Component#getPreferredSize()
157: */
158: public Dimension getPreferredSize() {
159: return new Dimension(m_nWidth, 20);
160: }
161:
162: /* (non-Javadoc)
163: * @see java.lang.Object#equals(java.lang.Object)
164: */
165: public boolean equals(Object 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(
171: this .m_vfs.getInitialPath())) {
172: bRetn = true;
173: }
174: }
175: return bRetn;
176: }
177:
178: /**
179: * Returns the full path to the virtual file representing
180: * this Role.
181: *
182: * @return full path to the virtual file representing this Role.
183: */
184: public String getPath() {
185: return m_sPath;
186: }
187:
188: /**
189: * Virtual file system for the full path to the virtual file representing
190: * this Role.
191: *
192: * @return Virtual file system for the virtual file representing this Role.
193: */
194: public AbstractVirtualFileSystem getVFS() {
195: return m_vfs;
196: }
197:
198: /**
199: * Checks is this cell is selected.
200: *
201: * @return true if this cell is selected.
202: */
203: public boolean isSelected() {
204: return m_bSelected;
205: }
206:
207: /**
208: * Sets whether this cell is selected.
209: *
210: * @param bSelected true if this cell is selected.
211: */
212: public void setSelected(boolean bSelected) {
213: m_bSelected = bSelected;
214: if (this .m_bSelected) {
215: this .setBackground(new Color(173, 169, 143));
216: } else {
217: this .setBackground(Color.WHITE);
218: this .m_label.setBackground(Color.WHITE);
219: }
220: this .repaint();
221: }
222:
223: /* (non-Javadoc)
224: * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
225: */
226: public void mouseClicked(MouseEvent me) {
227: MouseListener[] listeners = this .getMouseListeners();
228: me.setSource(this );
229: for (int i = 0; i < listeners.length; i++) {
230: listeners[i].mouseClicked(me);
231: }
232: }
233:
234: /* (non-Javadoc)
235: * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
236: */
237: public void mouseEntered(MouseEvent arg0) {
238: }
239:
240: /* (non-Javadoc)
241: * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
242: */
243: public void mouseExited(MouseEvent arg0) {
244: }
245:
246: /* (non-Javadoc)
247: * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
248: */
249: public void mousePressed(MouseEvent arg0) {
250: }
251:
252: /* (non-Javadoc)
253: * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
254: */
255: public void mouseReleased(MouseEvent arg0) {
256: }
257:
258: }
|