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.window.session;
020:
021: import java.awt.Color;
022: import java.awt.Component;
023: import java.awt.Container;
024: import java.awt.Dimension;
025: import java.awt.LayoutManager;
026: import java.util.ArrayList;
027: import java.util.Iterator;
028:
029: import javax.swing.JPanel;
030:
031: import org.openharmonise.vfs.*;
032:
033: /**
034: *
035: * @author Matthew Large
036: * @version $Revision: 1.1 $
037: *
038: */
039: public class SessionInformation extends JPanel implements LayoutManager {
040:
041: ArrayList m_aSessionEntries = new ArrayList();
042:
043: int m_nHeight = 0;
044: int m_nWidth = 200;
045:
046: int m_nCount = 0;
047:
048: /**
049: *
050: */
051: public SessionInformation() {
052: super ();
053: this .setup();
054: }
055:
056: private void setup() {
057: this .setLayout(this );
058: this .setBackground(Color.WHITE);
059:
060: this .setPreferredSize(new Dimension(200, 200));
061: }
062:
063: protected void addEntry(VirtualFile vfFile, String sReason) {
064: boolean bFound = false;
065: for (int i = 0; i < this .getComponentCount(); i++) {
066: SessionEntry entry = (SessionEntry) this .getComponent(i);
067: if (entry != null && entry.getPath() != null
068: && entry.getVFS() != null && vfFile != null
069: && vfFile.getFullPath() != null
070: && vfFile.getVFS() != null) {
071: if (entry.getReason().equals(sReason)
072: && entry.getPath().equals(vfFile.getFullPath())
073: && entry.getVFS() == vfFile.getVFS()) {
074: bFound = true;
075: break;
076: }
077: }
078: }
079: if (!bFound) {
080: SessionEntry entry = new SessionEntry(this , vfFile, sReason);
081: this .add(entry);
082: m_aSessionEntries.add(entry);
083: }
084: }
085:
086: protected void entrySelected(SessionEntry entry) {
087: for (int i = 0; i < this .getComponentCount(); i++) {
088: SessionEntry currentEntry = (SessionEntry) this
089: .getComponent(i);
090: if (currentEntry != entry) {
091: currentEntry.deselectEntry();
092: }
093: }
094: SessionWindow.getInstance().entrySelected(entry);
095: }
096:
097: protected SessionEntry getSelectedEntry() {
098: SessionEntry retn = null;
099: for (int i = 0; i < this .getComponentCount(); i++) {
100: SessionEntry currentEntry = (SessionEntry) this
101: .getComponent(i);
102: if (currentEntry.isSelected()) {
103: retn = currentEntry;
104: break;
105: }
106: }
107: return retn;
108: }
109:
110: /* (non-Javadoc)
111: * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
112: */
113: public void removeLayoutComponent(Component arg0) {
114: // NO-OP
115: }
116:
117: /* (non-Javadoc)
118: * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
119: */
120: public void layoutContainer(Container arg0) {
121: int nHeight = 0;
122: int nWidth = this .getParent().getParent().getWidth() - 20;
123: Iterator itor = this .m_aSessionEntries.iterator();
124: while (itor.hasNext()) {
125: SessionEntry entry = (SessionEntry) itor.next();
126: entry.setSize(this .m_nWidth, 20);
127: entry.setLocation(0, nHeight);
128: nHeight = nHeight + 20;
129: }
130:
131: if (nHeight != m_nHeight || nWidth != m_nWidth) {
132: this .m_nHeight = nHeight;
133: this .m_nWidth = nWidth;
134: this .setPreferredSize(new Dimension(this .m_nWidth,
135: this .m_nHeight));
136: }
137: }
138:
139: /* (non-Javadoc)
140: * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
141: */
142: public void addLayoutComponent(String arg0, Component arg1) {
143: // NO-OP
144: }
145:
146: /* (non-Javadoc)
147: * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
148: */
149: public Dimension minimumLayoutSize(Container arg0) {
150: return null;
151: }
152:
153: /* (non-Javadoc)
154: * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
155: */
156: public Dimension preferredLayoutSize(Container arg0) {
157: return null;
158: }
159:
160: /**
161: * @param arg0
162: */
163: private SessionInformation(boolean arg0) {
164: super (arg0);
165: }
166:
167: /**
168: * @param arg0
169: */
170: private SessionInformation(LayoutManager arg0) {
171: super (arg0);
172: }
173:
174: /**
175: * @param arg0
176: * @param arg1
177: */
178: private SessionInformation(LayoutManager arg0, boolean arg1) {
179: super (arg0, arg1);
180: }
181:
182: /**
183: * @param entry
184: */
185: public void removeEntry(SessionEntry entry) {
186: if (entry != null) {
187: this.remove(entry);
188: this.m_aSessionEntries.remove(entry);
189: this.validate();
190: this.repaint();
191: }
192: }
193:
194: }
|