KickJava   Java API By Example, From Geeks To Geeks.

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


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.LayoutManager JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.Iterator JavaDoc;
28
29 import javax.swing.JPanel JavaDoc;
30
31 import org.openharmonise.vfs.*;
32
33
34 /**
35  *
36  * @author Matthew Large
37  * @version $Revision: 1.1 $
38  *
39  */

40 public class SessionInformation extends JPanel JavaDoc implements LayoutManager JavaDoc {
41
42     ArrayList JavaDoc m_aSessionEntries = new ArrayList JavaDoc();
43
44     int m_nHeight = 0;
45     int m_nWidth = 200;
46     
47     int m_nCount = 0;
48
49     /**
50      *
51      */

52     public SessionInformation() {
53         super();
54         this.setup();
55     }
56     
57     private void setup() {
58         this.setLayout(this);
59         this.setBackground(Color.WHITE);
60         
61         this.setPreferredSize(new Dimension JavaDoc(200,200));
62     }
63     
64     protected void addEntry(VirtualFile vfFile, String JavaDoc sReason) {
65         boolean bFound=false;
66         for(int i=0; i<this.getComponentCount(); i++) {
67             SessionEntry entry = (SessionEntry) this.getComponent(i);
68             if(entry!=null && entry.getPath()!=null && entry.getVFS()!=null && vfFile!=null && vfFile.getFullPath()!=null&& vfFile.getVFS()!=null) {
69                 if(entry.getReason().equals(sReason) && entry.getPath().equals(vfFile.getFullPath()) && entry.getVFS()==vfFile.getVFS()) {
70                     bFound=true;
71                     break;
72                 }
73             }
74         }
75         if(!bFound) {
76             SessionEntry entry = new SessionEntry(this, vfFile, sReason);
77             this.add( entry );
78             m_aSessionEntries.add( entry );
79         }
80     }
81     
82     protected void entrySelected(SessionEntry entry) {
83         for(int i=0; i<this.getComponentCount(); i++) {
84             SessionEntry currentEntry = (SessionEntry) this.getComponent(i);
85             if(currentEntry!=entry) {
86                 currentEntry.deselectEntry();
87             }
88         }
89         SessionWindow.getInstance().entrySelected(entry);
90     }
91     
92     protected SessionEntry getSelectedEntry() {
93         SessionEntry retn = null;
94         for(int i=0; i<this.getComponentCount(); i++) {
95             SessionEntry currentEntry = (SessionEntry) this.getComponent(i);
96             if(currentEntry.isSelected()) {
97                 retn = currentEntry;
98                 break;
99             }
100         }
101         return retn;
102     }
103
104     /* (non-Javadoc)
105      * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
106      */

107     public void removeLayoutComponent(Component JavaDoc arg0) {
108         // NO-OP
109
}
110
111     /* (non-Javadoc)
112      * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
113      */

114     public void layoutContainer(Container JavaDoc arg0) {
115         int nHeight = 0;
116         int nWidth = this.getParent().getParent().getWidth()-20;
117         Iterator JavaDoc itor = this.m_aSessionEntries.iterator();
118         while(itor.hasNext()) {
119             SessionEntry entry = (SessionEntry)itor.next();
120             entry.setSize(this.m_nWidth, 20);
121             entry.setLocation(0, nHeight);
122             nHeight = nHeight+20;
123         }
124         
125         if(nHeight!=m_nHeight || nWidth!=m_nWidth) {
126             this.m_nHeight = nHeight;
127             this.m_nWidth = nWidth;
128             this.setPreferredSize(new Dimension JavaDoc(this.m_nWidth, this.m_nHeight));
129         }
130     }
131
132     /* (non-Javadoc)
133      * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
134      */

135     public void addLayoutComponent(String JavaDoc arg0, Component JavaDoc arg1) {
136         // NO-OP
137
}
138
139     /* (non-Javadoc)
140      * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
141      */

142     public Dimension JavaDoc minimumLayoutSize(Container JavaDoc arg0) {
143         return null;
144     }
145
146     /* (non-Javadoc)
147      * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
148      */

149     public Dimension JavaDoc preferredLayoutSize(Container JavaDoc arg0) {
150         return null;
151     }
152
153     /**
154      * @param arg0
155      */

156     private SessionInformation(boolean arg0) {
157         super(arg0);
158     }
159
160     /**
161      * @param arg0
162      */

163     private SessionInformation(LayoutManager JavaDoc arg0) {
164         super(arg0);
165     }
166
167     /**
168      * @param arg0
169      * @param arg1
170      */

171     private SessionInformation(LayoutManager JavaDoc arg0, boolean arg1) {
172         super(arg0, arg1);
173     }
174
175     /**
176      * @param entry
177      */

178     public void removeEntry(SessionEntry entry) {
179         if(entry!=null) {
180             this.remove(entry);
181             this.m_aSessionEntries.remove(entry);
182             this.validate();
183             this.repaint();
184         }
185     }
186
187 }
188
Popular Tags