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.metadata.swing;
020:
021: import java.awt.*;
022:
023: import javax.swing.*;
024:
025: import org.openharmonise.him.authentication.*;
026: import org.openharmonise.swing.FontManager;
027: import org.openharmonise.vfs.*;
028: import org.openharmonise.vfs.context.*;
029: import org.openharmonise.vfs.event.*;
030: import org.openharmonise.vfs.gui.*;
031:
032: /**
033: * @author Matthew Large
034: *
035: */
036: public class FileDetails extends JPanel implements LayoutManager,
037: VirtualFileListener {
038:
039: private AbstractVirtualFileSystem m_vfs = null;
040: private String m_sPath = null;
041:
042: private JLabel m_filename;
043: private JLabel m_pubLabel;
044: private JLabel m_pubDate;
045: private JLabel m_archiveLabel;
046: private JLabel m_archiveDate;
047: private JLabel m_editorLabel;
048: private JLabel m_editorName;
049: private JLabel m_lockIcon;
050:
051: /**
052: *
053: */
054: public FileDetails(AbstractVirtualFileSystem vfs, String sPath) {
055: super (true);
056: this .m_vfs = vfs;
057: this .m_sPath = sPath;
058: this .setup();
059: }
060:
061: /**
062: * @param arg0
063: */
064: private FileDetails(boolean arg0) {
065: super (arg0);
066: }
067:
068: /**
069: * @param arg0
070: */
071: private FileDetails(LayoutManager arg0) {
072: super (arg0);
073: }
074:
075: /**
076: * @param arg0
077: * @param arg1
078: */
079: private FileDetails(LayoutManager arg0, boolean arg1) {
080: super (arg0, arg1);
081: }
082:
083: protected void clearToDestroy() {
084: VirtualFile vfFile = this .m_vfs.getVirtualFile(this .m_sPath)
085: .getResource();
086: if (vfFile != null) {
087: vfFile.removeVirtualFileListener(this );
088: }
089: }
090:
091: private void setup() {
092: this .setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
093: this .setBackground(new Color(173, 169, 143));
094: this .setLayout(this );
095:
096: VirtualFile vfFile = this .m_vfs.getVirtualFile(this .m_sPath)
097: .getResource();
098: vfFile.addVirtualFileListener(this );
099: VirtualFileSystemView vfView = this .m_vfs
100: .getVirtualFileSystemView();
101: m_filename = new JLabel(vfView.getDisplayName(vfFile));
102: m_filename.setIcon(vfView.getIcon(vfFile));
103: m_filename.setFont(FontManager.getInstance().getFont(
104: FontManager.FONT_RESOURCE_TITLE));
105: this .add(m_filename);
106:
107: m_pubLabel = new JLabel("Publication date:");
108: m_pubLabel.setSize(100, 12);
109: m_pubLabel.setFont(FontManager.getInstance().getFont(
110: FontManager.FONT_STANDARD));
111: this .add(m_pubLabel);
112:
113: m_pubDate = new JLabel(this .m_vfs.getVirtualFileSystemView()
114: .getPublicationDate(vfFile));
115: m_pubDate.setFont(FontManager.getInstance().getFont(
116: FontManager.FONT_STANDARD));
117: m_pubDate.setSize(100, 12);
118: this .add(m_pubDate);
119:
120: m_archiveLabel = new JLabel("Archive date:");
121: m_archiveLabel.setSize(75, 12);
122: m_archiveLabel.setFont(FontManager.getInstance().getFont(
123: FontManager.FONT_STANDARD));
124: this .add(m_archiveLabel);
125:
126: m_archiveDate = new JLabel(this .m_vfs
127: .getVirtualFileSystemView().getArchiveDate(vfFile));
128: m_archiveDate.setFont(FontManager.getInstance().getFont(
129: FontManager.FONT_STANDARD));
130: m_archiveDate.setSize(75, 12);
131: this .add(m_archiveDate);
132:
133: m_editorLabel = new JLabel("Current Editor:");
134: m_editorLabel.setSize(85, 12);
135: m_editorLabel.setFont(FontManager.getInstance().getFont(
136: FontManager.FONT_STANDARD));
137: this .add(m_editorLabel);
138:
139: m_editorName = new JLabel("");
140: m_editorName.setFont(FontManager.getInstance().getFont(
141: FontManager.FONT_STANDARD));
142: m_editorName.setSize(75, 12);
143: this .add(m_editorName);
144:
145: if (vfFile.isLocked()) {
146: m_lockIcon = new JLabel(IconManager.getInstance().getIcon(
147: "16-command-lock.gif"));
148: String sEditorName = HarmoniseAuthenticationStore
149: .getUserDisplayName(vfFile.getLockOwner());
150: m_editorName.setText(sEditorName);
151: m_lockIcon.setToolTipText("Resource locked");
152: } else {
153: m_lockIcon = new JLabel(IconManager.getInstance().getIcon(
154: "16-blank.gif"));
155: }
156: m_lockIcon.setSize(15, 20);
157: this .add(m_lockIcon);
158: }
159:
160: /* (non-Javadoc)
161: * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
162: */
163: public void removeLayoutComponent(Component arg0) {
164: }
165:
166: /* (non-Javadoc)
167: * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
168: */
169: public void layoutContainer(Container arg0) {
170: m_filename.setLocation(8, 8);
171: m_filename.setSize(this .getWidth() - 220, 16);
172: m_editorLabel.setLocation(28, 30);
173: m_editorName.setLocation(98, 30);
174: m_lockIcon.setLocation(10, 25);
175: m_archiveLabel.setLocation(this .getWidth() - 200, 30);
176: m_archiveDate.setLocation(this .getWidth() - 130, 30);
177: m_pubLabel.setLocation(this .getWidth() - 200, 10);
178: m_pubDate.setLocation(this .getWidth() - 120, 10);
179: }
180:
181: /* (non-Javadoc)
182: * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
183: */
184: public void addLayoutComponent(String arg0, Component arg1) {
185: }
186:
187: /* (non-Javadoc)
188: * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
189: */
190: public Dimension minimumLayoutSize(Container arg0) {
191: return null;
192: }
193:
194: /* (non-Javadoc)
195: * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
196: */
197: public Dimension preferredLayoutSize(Container arg0) {
198: return null;
199: }
200:
201: /* (non-Javadoc)
202: * @see com.simulacramedia.vfs.event.VirtualFileListener#virtualFileChanged(com.simulacramedia.vfs.event.VirtualFileEvent)
203: */
204: public void virtualFileChanged(VirtualFileEvent vfe) {
205: if (vfe.getEventType() == VirtualFileEvent.FILE_LOCKED) {
206: this .m_lockIcon.setIcon(IconManager.getInstance().getIcon(
207: "16-command-lock.gif"));
208: String sEditorName = HarmoniseAuthenticationStore
209: .getUserDisplayName(this .m_vfs.getVirtualFile(
210: this .m_sPath).getResource().getLockOwner());
211: m_editorName.setText(sEditorName);
212: m_lockIcon.setToolTipText("Resource locked");
213: ContextEvent ce = new ContextEvent(
214: ContextType.CONTEXT_FILES, null, this .m_vfs,
215: this .m_sPath);
216: ContextHandler.getInstance().fireContextEvent(ce);
217: } else if (vfe.getEventType() == VirtualFileEvent.FILE_UNLOCKED) {
218: this .m_lockIcon.setIcon(IconManager.getInstance().getIcon(
219: "16-blank.gif"));
220: m_editorName.setText("");
221: m_lockIcon.setToolTipText("");
222: ContextEvent ce = new ContextEvent(
223: ContextType.CONTEXT_FILES, null, this.m_vfs,
224: this.m_sPath);
225: ContextHandler.getInstance().fireContextEvent(ce);
226: }
227: this.validate();
228: }
229:
230: }
|