KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > editors > pagegui > ResourceDisplayPanel


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.editors.pagegui;
20
21 import java.awt.*;
22 import java.awt.event.*;
23
24 import javax.swing.*;
25
26 import org.openharmonise.swing.FontManager;
27 import org.openharmonise.vfs.*;
28 import org.openharmonise.vfs.gui.*;
29
30
31 /**
32  * Resource field.
33  *
34  * @author Matthew Large
35  * @version $Revision: 1.2 $
36  *
37  */

38 public class ResourceDisplayPanel extends JPanel implements LayoutManager, MouseListener {
39
40     /**
41      * Full path to resource.
42      */

43     private String JavaDoc m_sFilePath = null;
44     
45     /**
46      * Virtual file system.
47      */

48     private AbstractVirtualFileSystem m_vfs = null;
49     
50     /**
51      * Selected highlight colour.
52      */

53     private Color m_selectedColor = new Color(173,169,143);
54
55     /**
56      * Label.
57      */

58     private JLabel m_label = null;
59
60     /**
61      *
62      */

63     public ResourceDisplayPanel() {
64         super();
65         this.setup();
66     }
67     
68     /**
69      * Configures this component.
70      *
71      */

72     private void setup() {
73         this.setLayout(this);
74         this.setBorder(BorderFactory.createEtchedBorder());
75         this.setBackground(Color.WHITE);
76         this.m_label = new JLabel();
77         this.m_label.addMouseListener(this);
78         this.m_label.setIcon( IconManager.getInstance().getIcon("16-blank.gif") );
79         this.m_label.setFont( FontManager.getInstance().getFont(FontManager.FONT_RESOURCE_TITLE) );
80         this.add(m_label);
81     }
82     
83     /**
84      * Sets the resource.
85      *
86      * @param vfFile Virtual file
87      */

88     public void setVirtualFile(VirtualFile vfFile) {
89         if(vfFile!=null) {
90             this.m_sFilePath = vfFile.getFullPath();
91             this.m_vfs = vfFile.getVFS();
92             VirtualFileSystemView vfsView = this.m_vfs.getVirtualFileSystemView();
93         
94             this.m_label.setText( vfsView.getDisplayName(vfFile) );
95             this.m_label.setIcon( vfsView.getIcon(vfFile) );
96         } else {
97             this.m_sFilePath = null;
98             this.m_vfs = null;
99             
100             this.m_label.setText( "" );
101             this.m_label.setIcon( IconManager.getInstance().getIcon("16-blank.gif") );
102         }
103         
104         this.setSelected(false);
105         
106         this.validateTree();
107         this.repaint();
108     }
109     
110     /**
111      * Returns the resource.
112      *
113      * @return Virtual file
114      */

115     public VirtualFile getVirtualFile() {
116         if(this.m_vfs!=null && this.m_sFilePath!=null) {
117             return this.m_vfs.getVirtualFile(m_sFilePath).getResource();
118         } else {
119             return null;
120         }
121     }
122
123     /* (non-Javadoc)
124      * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
125      */

126     public void mouseClicked(MouseEvent ae) {
127         if(ae.getSource()==this.m_label) {
128             if(this.getBackground()==Color.WHITE) {
129                 this.setSelected(true);
130             } else {
131                 this.setSelected(false);
132             }
133             this.validateTree();
134             this.repaint();
135         }
136     }
137     
138     /**
139      * Sets whether this field is selected.
140      *
141      * @param bSelected true to set this field as selected
142      */

143     private void setSelected(boolean bSelected) {
144         if(bSelected) {
145             this.setBackground(this.m_selectedColor);
146             this.m_label.setBackground(this.m_selectedColor);
147         } else {
148             this.setBackground(Color.WHITE);
149             this.m_label.setBackground(Color.WHITE);
150         }
151     }
152     
153     /**
154      * Checks if this field is selected.
155      *
156      * @return true if this field is selected
157      */

158     public boolean isSelected() {
159         return this.getBackground()==this.m_selectedColor;
160     }
161
162     /* (non-Javadoc)
163      * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
164      */

165     public void layoutContainer(Container arg0) {
166         this.m_label.setSize(this.getSize());
167         this.m_label.setLocation(0, 0);
168     }
169
170     /**
171      * @param arg0
172      */

173     private ResourceDisplayPanel(boolean arg0) {
174         super(arg0);
175     }
176
177     /**
178      * @param arg0
179      */

180     private ResourceDisplayPanel(LayoutManager arg0) {
181         super(arg0);
182     }
183
184     /**
185      * @param arg0
186      * @param arg1
187      */

188     private ResourceDisplayPanel(LayoutManager arg0, boolean arg1) {
189         super(arg0, arg1);
190     }
191
192     /* (non-Javadoc)
193      * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
194      */

195     public void addLayoutComponent(String JavaDoc arg0, Component arg1) {
196     }
197
198     /* (non-Javadoc)
199      * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
200      */

201     public void removeLayoutComponent(Component arg0) {
202     }
203
204     /* (non-Javadoc)
205      * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
206      */

207     public Dimension minimumLayoutSize(Container arg0) {
208         return this.getPreferredSize();
209     }
210
211     /* (non-Javadoc)
212      * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
213      */

214     public Dimension preferredLayoutSize(Container arg0) {
215         return this.getPreferredSize();
216     }
217
218     /* (non-Javadoc)
219      * @see java.awt.Component#getPreferredSize()
220      */

221     public Dimension getPreferredSize() {
222         return new Dimension(100, 20);
223     }
224
225     /* (non-Javadoc)
226      * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
227      */

228     public void mouseEntered(MouseEvent arg0) {
229     }
230
231     /* (non-Javadoc)
232      * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
233      */

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

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

246     public void mouseReleased(MouseEvent arg0) {
247     }
248
249 }
250
Popular Tags