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.editors.pagegui;
020:
021: import java.awt.*;
022: import java.awt.event.*;
023:
024: import javax.swing.*;
025:
026: import org.openharmonise.swing.FontManager;
027: import org.openharmonise.vfs.*;
028: import org.openharmonise.vfs.gui.*;
029:
030: /**
031: * Resource field.
032: *
033: * @author Matthew Large
034: * @version $Revision: 1.2 $
035: *
036: */
037: public class ResourceDisplayPanel extends JPanel implements
038: LayoutManager, MouseListener {
039:
040: /**
041: * Full path to resource.
042: */
043: private String m_sFilePath = null;
044:
045: /**
046: * Virtual file system.
047: */
048: private AbstractVirtualFileSystem m_vfs = null;
049:
050: /**
051: * Selected highlight colour.
052: */
053: private Color m_selectedColor = new Color(173, 169, 143);
054:
055: /**
056: * Label.
057: */
058: private JLabel m_label = null;
059:
060: /**
061: *
062: */
063: public ResourceDisplayPanel() {
064: super ();
065: this .setup();
066: }
067:
068: /**
069: * Configures this component.
070: *
071: */
072: private void setup() {
073: this .setLayout(this );
074: this .setBorder(BorderFactory.createEtchedBorder());
075: this .setBackground(Color.WHITE);
076: this .m_label = new JLabel();
077: this .m_label.addMouseListener(this );
078: this .m_label.setIcon(IconManager.getInstance().getIcon(
079: "16-blank.gif"));
080: this .m_label.setFont(FontManager.getInstance().getFont(
081: FontManager.FONT_RESOURCE_TITLE));
082: this .add(m_label);
083: }
084:
085: /**
086: * Sets the resource.
087: *
088: * @param vfFile Virtual file
089: */
090: public void setVirtualFile(VirtualFile vfFile) {
091: if (vfFile != null) {
092: this .m_sFilePath = vfFile.getFullPath();
093: this .m_vfs = vfFile.getVFS();
094: VirtualFileSystemView vfsView = this .m_vfs
095: .getVirtualFileSystemView();
096:
097: this .m_label.setText(vfsView.getDisplayName(vfFile));
098: this .m_label.setIcon(vfsView.getIcon(vfFile));
099: } else {
100: this .m_sFilePath = null;
101: this .m_vfs = null;
102:
103: this .m_label.setText("");
104: this .m_label.setIcon(IconManager.getInstance().getIcon(
105: "16-blank.gif"));
106: }
107:
108: this .setSelected(false);
109:
110: this .validateTree();
111: this .repaint();
112: }
113:
114: /**
115: * Returns the resource.
116: *
117: * @return Virtual file
118: */
119: public VirtualFile getVirtualFile() {
120: if (this .m_vfs != null && this .m_sFilePath != null) {
121: return this .m_vfs.getVirtualFile(m_sFilePath).getResource();
122: } else {
123: return null;
124: }
125: }
126:
127: /* (non-Javadoc)
128: * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
129: */
130: public void mouseClicked(MouseEvent ae) {
131: if (ae.getSource() == this .m_label) {
132: if (this .getBackground() == Color.WHITE) {
133: this .setSelected(true);
134: } else {
135: this .setSelected(false);
136: }
137: this .validateTree();
138: this .repaint();
139: }
140: }
141:
142: /**
143: * Sets whether this field is selected.
144: *
145: * @param bSelected true to set this field as selected
146: */
147: private void setSelected(boolean bSelected) {
148: if (bSelected) {
149: this .setBackground(this .m_selectedColor);
150: this .m_label.setBackground(this .m_selectedColor);
151: } else {
152: this .setBackground(Color.WHITE);
153: this .m_label.setBackground(Color.WHITE);
154: }
155: }
156:
157: /**
158: * Checks if this field is selected.
159: *
160: * @return true if this field is selected
161: */
162: public boolean isSelected() {
163: return this .getBackground() == this .m_selectedColor;
164: }
165:
166: /* (non-Javadoc)
167: * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
168: */
169: public void layoutContainer(Container arg0) {
170: this .m_label.setSize(this .getSize());
171: this .m_label.setLocation(0, 0);
172: }
173:
174: /**
175: * @param arg0
176: */
177: private ResourceDisplayPanel(boolean arg0) {
178: super (arg0);
179: }
180:
181: /**
182: * @param arg0
183: */
184: private ResourceDisplayPanel(LayoutManager arg0) {
185: super (arg0);
186: }
187:
188: /**
189: * @param arg0
190: * @param arg1
191: */
192: private ResourceDisplayPanel(LayoutManager arg0, boolean arg1) {
193: super (arg0, arg1);
194: }
195:
196: /* (non-Javadoc)
197: * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
198: */
199: public void addLayoutComponent(String arg0, Component arg1) {
200: }
201:
202: /* (non-Javadoc)
203: * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
204: */
205: public void removeLayoutComponent(Component arg0) {
206: }
207:
208: /* (non-Javadoc)
209: * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
210: */
211: public Dimension minimumLayoutSize(Container arg0) {
212: return this .getPreferredSize();
213: }
214:
215: /* (non-Javadoc)
216: * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
217: */
218: public Dimension preferredLayoutSize(Container arg0) {
219: return this .getPreferredSize();
220: }
221:
222: /* (non-Javadoc)
223: * @see java.awt.Component#getPreferredSize()
224: */
225: public Dimension getPreferredSize() {
226: return new Dimension(100, 20);
227: }
228:
229: /* (non-Javadoc)
230: * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
231: */
232: public void mouseEntered(MouseEvent arg0) {
233: }
234:
235: /* (non-Javadoc)
236: * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
237: */
238: public void mouseExited(MouseEvent arg0) {
239: }
240:
241: /* (non-Javadoc)
242: * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
243: */
244: public void mousePressed(MouseEvent arg0) {
245: }
246:
247: /* (non-Javadoc)
248: * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
249: */
250: public void mouseReleased(MouseEvent arg0) {
251: }
252:
253: }
|