KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > metadata > range > swing > range > details > RangeSelectionCell


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.metadata.range.swing.range.details;
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  * @author Matthew Large
39  * @version $Revision: 1.1 $
40  *
41  */

42 public class RangeSelectionCell extends JPanel JavaDoc
43                            implements MouseListener JavaDoc, LayoutManager JavaDoc {
44
45     private JLabel JavaDoc m_label = null;
46     
47     private String JavaDoc m_sPath = null;
48     private AbstractVirtualFileSystem m_vfs = null;
49     
50     private boolean m_bSelected = false;
51     
52     private int m_nWidth = 135;
53     
54     private RangeSelectionList m_parent = null;
55     
56     private JLabel JavaDoc m_errorLabel = null;
57
58     /**
59      *
60      */

61     public RangeSelectionCell(RangeSelectionList parent, String JavaDoc sPath, AbstractVirtualFileSystem vfs) {
62         super();
63         this.m_sPath = sPath;
64         this.m_vfs = vfs;
65         
66         this.m_parent = parent;
67         this.setup();
68     }
69
70     private void setup() {
71         
72         VirtualFile vfFile = this.m_vfs.getVirtualFile(this.m_sPath).getResource();
73         VirtualFileSystemView vfsView = this.m_vfs.getVirtualFileSystemView();
74         
75         String JavaDoc fontName = "Dialog";
76         int fontSize = 11;
77         Font JavaDoc font = new Font JavaDoc(fontName, Font.PLAIN, fontSize);
78         
79         this.setLayout(this);
80         this.setBackground(Color.WHITE);
81         
82         this.m_label = new JLabel JavaDoc( vfsView.getDisplayName(vfFile) );
83         this.m_label.addMouseListener(this);
84         this.m_label.setToolTipText( vfFile.getFullPath() );
85         this.m_label.setFont(font);
86         this.m_label.setBackground(Color.WHITE);
87         this.m_label.setIcon( vfsView.getIcon(vfFile) );
88         this.add(this.m_label);
89         
90         this.m_errorLabel = new JLabel JavaDoc();
91         this.m_errorLabel.setIcon( IconManager.getInstance().getIcon("16-message-error.gif") );
92         this.add(this.m_errorLabel);
93         
94         this.setValidStatus(false);
95     }
96
97     /* (non-Javadoc)
98      * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
99      */

100     public void removeLayoutComponent(Component JavaDoc arg0) {
101     }
102
103     /* (non-Javadoc)
104      * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
105      */

106     public void layoutContainer(Container JavaDoc arg0) {
107         this.m_label.setSize(m_nWidth-20, 20);
108         this.m_label.setLocation(0,0);
109         this.m_errorLabel.setSize(20,20);
110         this.m_errorLabel.setLocation(m_nWidth-20, 0);
111     }
112
113     /* (non-Javadoc)
114      * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
115      */

116     public void addLayoutComponent(String JavaDoc arg0, Component JavaDoc arg1) {
117     }
118
119     /* (non-Javadoc)
120      * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
121      */

122     public Dimension JavaDoc minimumLayoutSize(Container JavaDoc arg0) {
123         return this.getPreferredSize();
124     }
125
126     /* (non-Javadoc)
127      * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
128      */

129     public Dimension JavaDoc preferredLayoutSize(Container JavaDoc arg0) {
130         return this.getPreferredSize();
131     }
132
133     /* (non-Javadoc)
134      * @see java.awt.Component#getPreferredSize()
135      */

136     public Dimension JavaDoc getPreferredSize() {
137         return new Dimension JavaDoc(m_nWidth, 20);
138     }
139     
140     
141
142     /* (non-Javadoc)
143      * @see java.lang.Object#equals(java.lang.Object)
144      */

145     public boolean equals(Object JavaDoc obj) {
146         boolean bRetn = false;
147         if(obj instanceof RangeSelectionCell) {
148             RangeSelectionCell cell = (RangeSelectionCell)obj;
149             if(cell.getPath().trim().equals(this.m_sPath) &&
150             cell.getVFS().getInitialPath().trim().equals(this.m_vfs.getInitialPath())) {
151                 bRetn=true;
152             }
153         }
154         return bRetn;
155     }
156
157     /**
158      * @return
159      */

160     public String JavaDoc getPath() {
161         return m_sPath;
162     }
163
164     /**
165      * @return
166      */

167     public AbstractVirtualFileSystem getVFS() {
168         return m_vfs;
169     }
170
171     /**
172      * @return
173      */

174     public boolean isSelected() {
175         return m_bSelected;
176     }
177     
178     public void setValidStatus(boolean bValid) {
179         this.m_label.setForeground(Color.BLACK);
180         this.m_errorLabel.setIcon( IconManager.getInstance().getIcon("16-message-confirm.gif") );
181     }
182     
183     public boolean getValidStatus() {
184         return this.m_label.getForeground()==Color.BLACK;
185     }
186
187     /**
188      * @param b
189      */

190     public void setSelected(boolean b) {
191         m_bSelected = b;
192         if(this.m_bSelected) {
193             this.setBackground( new Color JavaDoc(173, 169, 143));
194         } else {
195             this.setBackground(Color.WHITE);
196             this.m_label.setBackground(Color.WHITE);
197         }
198         this.repaint();
199     }
200
201     /* (non-Javadoc)
202      * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
203      */

204     public void mouseClicked(MouseEvent JavaDoc me) {
205         MouseListener JavaDoc[] listeners = this.getMouseListeners();
206         me.setSource(this);
207         for(int i=0; i<listeners.length; i++) {
208             listeners[i].mouseClicked(me);
209         }
210     }
211
212     /* (non-Javadoc)
213      * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
214      */

215     public void mouseEntered(MouseEvent JavaDoc arg0) {
216     }
217
218     /* (non-Javadoc)
219      * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
220      */

221     public void mouseExited(MouseEvent JavaDoc arg0) {
222     }
223
224     /* (non-Javadoc)
225      * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
226      */

227     public void mousePressed(MouseEvent JavaDoc arg0) {
228     }
229
230     /* (non-Javadoc)
231      * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
232      */

233     public void mouseReleased(MouseEvent JavaDoc arg0) {
234     }
235
236 }
237
Popular Tags