KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > window > session > SessionEntry


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.window.session;
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 import java.text.SimpleDateFormat JavaDoc;
30 import java.util.Date JavaDoc;
31
32 import javax.swing.JLabel JavaDoc;
33 import javax.swing.JPanel JavaDoc;
34
35 import org.openharmonise.swing.FontManager;
36 import org.openharmonise.vfs.*;
37 import org.openharmonise.vfs.event.*;
38 import org.openharmonise.vfs.gui.*;
39
40
41 /**
42  *
43  * @author Matthew Large
44  * @version $Revision: 1.2 $
45  *
46  */

47 public class SessionEntry extends JPanel JavaDoc implements VirtualFileListener, LayoutManager JavaDoc, MouseListener JavaDoc {
48
49     private AbstractVirtualFileSystem m_vfs = null;
50     private String JavaDoc m_sPath = null;
51     
52     private JLabel JavaDoc m_iconNameLabel = null;
53     private JLabel JavaDoc m_syncIcon = null;
54
55     int m_nWidth = 0;
56     
57     private Color JavaDoc m_selectedColor = new Color JavaDoc(173,169,143);
58     private boolean m_bSelected = false;
59     
60     private SessionInformation m_parent = null;
61     
62     private String JavaDoc m_sReason = null;
63     /**
64      *
65      */

66     public SessionEntry(SessionInformation parent, VirtualFile vfFile, String JavaDoc sReason) {
67         super();
68         this.m_parent = parent;
69         this.m_sReason = sReason;
70         this.setup(vfFile);
71     }
72     
73     private void setup(VirtualFile vfFile) {
74         this.setLayout(this);
75         this.setBackground(Color.WHITE);
76         
77         String JavaDoc sDisplayName = "";
78         if(vfFile!=null) {
79             this.m_vfs = vfFile.getVFS();
80             this.m_sPath = vfFile.getFullPath();
81
82             VirtualFile vfDisplay = vfFile.getVFS().getVirtualFile( ((VersionedVirtualFile)vfFile).getLogicalPath() ).getResource();
83             sDisplayName = vfDisplay.getVFS().getVirtualFileSystemView().getDisplayName(vfDisplay);
84         }
85         
86
87 // String fontName = "Dialog";
88
// int fontSize = 11;
89
// Font font = new Font(fontName, Font.PLAIN, fontSize);
90

91         Date JavaDoc dt = new Date JavaDoc();
92         SimpleDateFormat JavaDoc formatter = new SimpleDateFormat JavaDoc("HH:mm");
93         
94         this.m_iconNameLabel = new JLabel JavaDoc(sDisplayName + " - " + this.m_sReason + " at " + formatter.format(dt));
95         this.m_iconNameLabel.setFont( FontManager.getInstance().getFont(FontManager.FONT_RESOURCE_TITLE) );
96         if(vfFile!=null) {
97             this.m_iconNameLabel.setIcon( vfFile.getVFS().getVirtualFileSystemView().getIcon(vfFile) );
98         } else {
99             this.m_iconNameLabel.setIcon( IconManager.getInstance().getIcon("16-document.gif") );
100         }
101         this.m_iconNameLabel.addMouseListener(this);
102         this.add(this.m_iconNameLabel);
103         
104         this.m_syncIcon = new JLabel JavaDoc();
105         if(vfFile!=null && vfFile.isChanged()) {
106             this.m_syncIcon.setIcon( IconManager.getInstance().getIcon("16-command-sync-all.gif") );
107         } else {
108             this.m_syncIcon.setIcon( IconManager.getInstance().getIcon("16-blank.gif") );
109         }
110         this.m_syncIcon.addMouseListener(this);
111         this.add(this.m_syncIcon);
112     }
113     
114     protected boolean isVirtualFileChanged() {
115         if(this.m_vfs!=null && this.m_sPath!=null) {
116             if(this.m_vfs.getVirtualFile(this.m_sPath).getResource().isChanged()) {
117                 return true;
118             } else {
119                 return false;
120             }
121         } else {
122             return false;
123         }
124     }
125
126     /* (non-Javadoc)
127      * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
128      */

129     public void mouseClicked(MouseEvent JavaDoc arg0) {
130         if(this.m_bSelected) {
131             // NO-OP
132
} else {
133             this.selectEntry();
134         }
135     }
136     
137     public AbstractVirtualFileSystem getVFS() {
138         return this.m_vfs;
139     }
140     
141     public String JavaDoc getReason() {
142         return this.m_sReason;
143     }
144     
145     public String JavaDoc getPath() {
146         return this.m_sPath;
147     }
148     
149     public boolean isSelected() {
150         return this.m_bSelected;
151     }
152     
153     protected void selectEntry() {
154         this.setBackground(this.m_selectedColor);
155         this.m_bSelected = true;
156         this.m_parent.entrySelected(this);
157     }
158     
159     protected void deselectEntry() {
160         this.setBackground(Color.WHITE);
161         this.m_bSelected = false;
162     }
163
164     /* (non-Javadoc)
165      * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
166      */

167     public void removeLayoutComponent(Component JavaDoc arg0) {
168         // NO-OP
169
}
170
171     /* (non-Javadoc)
172      * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
173      */

174     public void layoutContainer(Container JavaDoc arg0) {
175         m_nWidth = this.getParent().getParent().getParent().getWidth()-20;
176         this.m_iconNameLabel.setSize(this.getParent().getParent().getParent().getWidth()-40, 20);
177         this.m_iconNameLabel.setLocation(0,0);
178         
179         this.m_syncIcon.setSize(20,20);
180         this.m_syncIcon.setLocation(this.getParent().getParent().getParent().getWidth()-40,0);
181     }
182
183     /* (non-Javadoc)
184      * @see java.awt.Component#getPreferredSize()
185      */

186     public Dimension JavaDoc getPreferredSize() {
187         return new Dimension JavaDoc(m_nWidth, 20);
188     }
189
190     /* (non-Javadoc)
191      * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
192      */

193     public void addLayoutComponent(String JavaDoc arg0, Component JavaDoc arg1) {
194         // NO-OP
195
}
196
197     /* (non-Javadoc)
198      * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
199      */

200     public Dimension JavaDoc minimumLayoutSize(Container JavaDoc arg0) {
201         return this.getPreferredSize();
202     }
203
204     /* (non-Javadoc)
205      * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
206      */

207     public Dimension JavaDoc preferredLayoutSize(Container JavaDoc arg0) {
208         return new Dimension JavaDoc(m_nWidth, 20);
209     }
210
211     /**
212      * @param arg0
213      */

214     private SessionEntry(boolean arg0) {
215         super(arg0);
216     }
217
218     /**
219      * @param arg0
220      */

221     private SessionEntry(LayoutManager JavaDoc arg0) {
222         super(arg0);
223     }
224
225     /**
226      * @param arg0
227      * @param arg1
228      */

229     private SessionEntry(LayoutManager JavaDoc arg0, boolean arg1) {
230         super(arg0, arg1);
231     }
232
233     /* (non-Javadoc)
234      * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
235      */

236     public void mouseEntered(MouseEvent JavaDoc arg0) {
237     }
238
239     /* (non-Javadoc)
240      * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
241      */

242     public void mouseExited(MouseEvent JavaDoc arg0) {
243     }
244
245     /* (non-Javadoc)
246      * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
247      */

248     public void mousePressed(MouseEvent JavaDoc arg0) {
249     }
250
251     /* (non-Javadoc)
252      * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
253      */

254     public void mouseReleased(MouseEvent JavaDoc arg0) {
255     }
256
257     /* (non-Javadoc)
258      * @see com.simulacramedia.vfs.event.VirtualFileListener#virtualFileChanged(com.simulacramedia.vfs.event.VirtualFileEvent)
259      */

260     public void virtualFileChanged(VirtualFileEvent vfe) {
261     }
262 }
263
Popular Tags