KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > metadata > swing > FileDetails


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.swing;
20
21 import java.awt.*;
22
23 import javax.swing.*;
24
25 import org.openharmonise.him.authentication.*;
26 import org.openharmonise.swing.FontManager;
27 import org.openharmonise.vfs.*;
28 import org.openharmonise.vfs.context.*;
29 import org.openharmonise.vfs.event.*;
30 import org.openharmonise.vfs.gui.*;
31
32
33 /**
34  * @author Matthew Large
35  *
36  */

37 public class FileDetails extends JPanel implements LayoutManager, VirtualFileListener {
38
39     private AbstractVirtualFileSystem m_vfs = null;
40     private String JavaDoc m_sPath = null;
41     
42     private JLabel m_filename;
43     private JLabel m_pubLabel;
44     private JLabel m_pubDate;
45     private JLabel m_archiveLabel;
46     private JLabel m_archiveDate;
47     private JLabel m_editorLabel;
48     private JLabel m_editorName;
49     private JLabel m_lockIcon;
50
51     /**
52      *
53      */

54     public FileDetails(AbstractVirtualFileSystem vfs, String JavaDoc sPath) {
55         super(true);
56         this.m_vfs = vfs;
57         this.m_sPath = sPath;
58         this.setup();
59     }
60
61     /**
62      * @param arg0
63      */

64     private FileDetails(boolean arg0) {
65         super(arg0);
66     }
67
68     /**
69      * @param arg0
70      */

71     private FileDetails(LayoutManager arg0) {
72         super(arg0);
73     }
74
75     /**
76      * @param arg0
77      * @param arg1
78      */

79     private FileDetails(LayoutManager arg0, boolean arg1) {
80         super(arg0, arg1);
81     }
82     
83     protected void clearToDestroy() {
84         VirtualFile vfFile = this.m_vfs.getVirtualFile(this.m_sPath).getResource();
85         if(vfFile!=null) {
86             vfFile.removeVirtualFileListener(this);
87         }
88     }
89
90     private void setup() {
91         this.setBorder( BorderFactory.createLineBorder(Color.BLACK,2) );
92         this.setBackground( new Color(173,169,143) );
93         this.setLayout(this);
94
95         
96         VirtualFile vfFile = this.m_vfs.getVirtualFile(this.m_sPath).getResource();
97         vfFile.addVirtualFileListener(this);
98         VirtualFileSystemView vfView = this.m_vfs.getVirtualFileSystemView();
99         m_filename = new JLabel( vfView.getDisplayName(vfFile) );
100         m_filename.setIcon( vfView.getIcon(vfFile) );
101         m_filename.setFont(FontManager.getInstance().getFont(FontManager.FONT_RESOURCE_TITLE));
102         this.add(m_filename);
103         
104         m_pubLabel = new JLabel("Publication date:");
105         m_pubLabel.setSize(100, 12);
106         m_pubLabel.setFont( FontManager.getInstance().getFont(FontManager.FONT_STANDARD) );
107         this.add(m_pubLabel);
108         
109         m_pubDate = new JLabel( this.m_vfs.getVirtualFileSystemView().getPublicationDate(vfFile) );
110         m_pubDate.setFont( FontManager.getInstance().getFont(FontManager.FONT_STANDARD) );
111         m_pubDate.setSize(100, 12);
112         this.add(m_pubDate);
113
114         m_archiveLabel = new JLabel("Archive date:");
115         m_archiveLabel.setSize(75, 12);
116         m_archiveLabel.setFont( FontManager.getInstance().getFont(FontManager.FONT_STANDARD) );
117         this.add(m_archiveLabel);
118
119         m_archiveDate = new JLabel(this.m_vfs.getVirtualFileSystemView().getArchiveDate(vfFile));
120         m_archiveDate.setFont( FontManager.getInstance().getFont(FontManager.FONT_STANDARD) );
121         m_archiveDate.setSize(75, 12);
122         this.add(m_archiveDate);
123
124         m_editorLabel = new JLabel("Current Editor:");
125         m_editorLabel.setSize(85, 12);
126         m_editorLabel.setFont( FontManager.getInstance().getFont(FontManager.FONT_STANDARD) );
127         this.add(m_editorLabel);
128
129         m_editorName = new JLabel("");
130         m_editorName.setFont( FontManager.getInstance().getFont(FontManager.FONT_STANDARD) );
131         m_editorName.setSize(75, 12);
132         this.add(m_editorName);
133         
134         if(vfFile.isLocked()) {
135             m_lockIcon = new JLabel(IconManager.getInstance().getIcon("16-command-lock.gif"));
136             String JavaDoc sEditorName = HarmoniseAuthenticationStore.getUserDisplayName(vfFile.getLockOwner());
137             m_editorName.setText(sEditorName);
138             m_lockIcon.setToolTipText("Resource locked");
139         } else {
140             m_lockIcon = new JLabel(IconManager.getInstance().getIcon("16-blank.gif"));
141         }
142         m_lockIcon.setSize(15,20);
143         this.add(m_lockIcon);
144     }
145
146     /* (non-Javadoc)
147      * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
148      */

149     public void removeLayoutComponent(Component arg0) {
150     }
151
152     /* (non-Javadoc)
153      * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
154      */

155     public void layoutContainer(Container arg0) {
156         m_filename.setLocation(8,8);
157         m_filename.setSize(this.getWidth()-220,16);
158         m_editorLabel.setLocation(28,30);
159         m_editorName.setLocation(98,30);
160         m_lockIcon.setLocation(10, 25);
161         m_archiveLabel.setLocation(this.getWidth()-200,30);
162         m_archiveDate.setLocation(this.getWidth()-130,30);
163         m_pubLabel.setLocation(this.getWidth()-200,10);
164         m_pubDate.setLocation(this.getWidth()-120,10);
165     }
166
167     /* (non-Javadoc)
168      * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
169      */

170     public void addLayoutComponent(String JavaDoc arg0, Component arg1) {
171     }
172
173     /* (non-Javadoc)
174      * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
175      */

176     public Dimension minimumLayoutSize(Container arg0) {
177         return null;
178     }
179
180     /* (non-Javadoc)
181      * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
182      */

183     public Dimension preferredLayoutSize(Container arg0) {
184         return null;
185     }
186
187     /* (non-Javadoc)
188      * @see com.simulacramedia.vfs.event.VirtualFileListener#virtualFileChanged(com.simulacramedia.vfs.event.VirtualFileEvent)
189      */

190     public void virtualFileChanged(VirtualFileEvent vfe) {
191         if(vfe.getEventType()==VirtualFileEvent.FILE_LOCKED) {
192             this.m_lockIcon.setIcon( IconManager.getInstance().getIcon("16-command-lock.gif") );
193             String JavaDoc sEditorName = HarmoniseAuthenticationStore.getUserDisplayName(this.m_vfs.getVirtualFile(this.m_sPath).getResource().getLockOwner());
194             m_editorName.setText(sEditorName);
195             m_lockIcon.setToolTipText("Resource locked");
196             ContextEvent ce = new ContextEvent(ContextType.CONTEXT_FILES, null, this.m_vfs, this.m_sPath);
197             ContextHandler.getInstance().fireContextEvent(ce);
198         } else if(vfe.getEventType()==VirtualFileEvent.FILE_UNLOCKED) {
199             this.m_lockIcon.setIcon( IconManager.getInstance().getIcon("16-blank.gif") );
200             m_editorName.setText("");
201             m_lockIcon.setToolTipText("");
202             ContextEvent ce = new ContextEvent(ContextType.CONTEXT_FILES, null, this.m_vfs, this.m_sPath);
203             ContextHandler.getInstance().fireContextEvent(ce);
204         }
205         this.validate();
206     }
207
208 }
209
Popular Tags