KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.*;
23
24 import javax.swing.*;
25
26 import org.openharmonise.him.metadata.range.swing.resourcehandling.*;
27 import org.openharmonise.vfs.*;
28 import org.openharmonise.vfs.metadata.*;
29
30
31 /**
32  * @author Matthew Large
33  * @version $Revision: 1.1 $
34  */

35 public class MetadataTabPanel extends JPanel implements LayoutManager {
36
37     private ResourceRangeDisplay m_relationships = null;
38     
39     private VirtualFile m_vfPropGroup = null;
40
41     private HashMap m_pathOrderMapping = new HashMap();
42
43     private SortedSet m_propPanels = new TreeSet();
44     
45     private int m_nNextOrderVal = 1;
46
47     /**
48      *
49      */

50     public MetadataTabPanel() {
51         super();
52         this.setup();
53     }
54
55     /**
56      *
57      */

58     public MetadataTabPanel(VirtualFile vfPropGroup) {
59         super();
60         this.m_vfPropGroup = vfPropGroup;
61         this.setup();
62     }
63     
64     private void setup() {
65         this.setLayout(this);
66
67         this.m_pathOrderMapping.put("/webdav/SYSTEM_PROPS/title", new Integer JavaDoc(1));
68         this.m_pathOrderMapping.put("/webdav/SYSTEM_PROPS/description", new Integer JavaDoc(2));
69         int nCount = 3;
70         
71         if(this.m_vfPropGroup!=null) {
72             Iterator itor = this.m_vfPropGroup.getChildren().iterator();
73             while (itor.hasNext()) {
74                 String JavaDoc sPath = (String JavaDoc) itor.next();
75                 this.m_pathOrderMapping.put(sPath, new Integer JavaDoc(nCount));
76                 nCount++;
77             }
78         }
79         this.m_nNextOrderVal = nCount;
80     }
81     
82     public void addPropertyPanel(PropertyPanel propPanel) {
83         Property prop = propPanel.getProperty();
84         if(prop!=null && this.m_pathOrderMapping.get(prop.getHREF())!=null) {
85             int nOrder = ((Integer JavaDoc)this.m_pathOrderMapping.get(prop.getHREF())).intValue();
86             OrderedProp orderedProp = new OrderedProp(nOrder, propPanel);
87             this.m_propPanels.add(orderedProp);
88         } else {
89             OrderedProp orderedProp = new OrderedProp(this.m_nNextOrderVal, propPanel);
90             this.m_nNextOrderVal++;
91             this.m_propPanels.add(orderedProp);
92         }
93         this.add(propPanel);
94     }
95     
96     protected void clearToDestroy() {
97         this.m_relationships = null;
98         this.removeAll();
99     }
100
101     /**
102      * @param arg0
103      */

104     private MetadataTabPanel(boolean arg0) {
105         super(arg0);
106     }
107
108     /**
109      * @param arg0
110      */

111     private MetadataTabPanel(LayoutManager arg0) {
112         super(arg0);
113     }
114
115     /**
116      * @param arg0
117      * @param arg1
118      */

119     private MetadataTabPanel(LayoutManager arg0, boolean arg1) {
120         super(arg0, arg1);
121     }
122
123     /**
124      * @return
125      */

126     public ResourceRangeDisplay getRelationships() {
127         return m_relationships;
128     }
129     
130     public boolean hasRelationships() {
131         return (this.m_relationships!=null);
132     }
133
134     /* (non-Javadoc)
135      * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
136      */

137     public void layoutContainer(Container arg0) {
138         int nHeight = 0;
139         Iterator itor = this.m_propPanels.iterator();
140         while (itor.hasNext()) {
141             OrderedProp orderedProp = (OrderedProp) itor.next();
142             PropertyPanel propPanel = orderedProp.getPropPanel();
143
144
145             propPanel.setSize(propPanel.getPreferredSize());
146             propPanel.setLocation(0, nHeight);
147             nHeight = nHeight + propPanel.getSize().height;
148         }
149     }
150
151     /**
152      * @param display
153      */

154     public void setRelationships(ResourceRangeDisplay display) {
155         if( this.m_relationships==null ) {
156             m_relationships = display;
157             PropertyPanel propPanel = new PropertyPanel("Relationships", false);
158             propPanel.add(m_relationships);
159             OrderedProp orderedProp = new OrderedProp(this.m_nNextOrderVal, propPanel);
160             this.m_nNextOrderVal++;
161             this.m_propPanels.add(orderedProp);
162             this.add(propPanel);
163         }
164     }
165     
166     public void addRelationship(ResourceRangeDisplay display) {
167         this.m_relationships.addRelationship(display);
168     }
169     
170     
171
172     /* (non-Javadoc)
173      * @see java.awt.Component#setEnabled(boolean)
174      */

175     public void setEnabled(boolean bEnabled) {
176         for (int i = 0; i < this.getComponentCount(); i++) {
177             Component comp = this.getComponent(i);
178             comp.setEnabled(bEnabled);
179         }
180         super.setEnabled(bEnabled);
181     }
182     
183     public void checkValid() {
184         boolean bValid = true;
185         for (int i = 0; i < this.getComponentCount() && bValid == true; i++) {
186             Component comp = this.getComponent(i);
187             if(comp instanceof PropertyPanel) {
188                 if(!((PropertyPanel)comp).getRangeDisplay().isMetadataValid()) {
189                     bValid=false;
190                 }
191             }
192         }
193
194         MetadataTabs tabs = this.getTabs();
195         tabs.setValid(bValid, this);
196     }
197     
198     private MetadataTabs getTabs() {
199         Component comp = this;
200         while(comp!=null && !(comp instanceof MetadataTabs)) {
201             comp = comp.getParent();
202         }
203         
204         if(comp!=null && comp instanceof MetadataTabs) {
205             return (MetadataTabs) comp;
206         } else {
207             return null;
208         }
209     }
210
211     /* (non-Javadoc)
212      * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
213      */

214     public void removeLayoutComponent(Component arg0) {
215     }
216
217     /* (non-Javadoc)
218      * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
219      */

220     public void addLayoutComponent(String JavaDoc arg0, Component arg1) {
221     }
222
223     /* (non-Javadoc)
224      * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
225      */

226     public Dimension minimumLayoutSize(Container arg0) {
227         return this.getPreferredSize();
228     }
229
230     /* (non-Javadoc)
231      * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
232      */

233     public Dimension preferredLayoutSize(Container arg0) {
234         return this.getPreferredSize();
235     }
236
237     /* (non-Javadoc)
238      * @see java.awt.Component#getPreferredSize()
239      */

240     public Dimension getPreferredSize() {
241         int nHeight = 0;
242         int nCount = this.getComponentCount();
243         int nWidth = 0;
244         for(int i=0; i<nCount; i++) {
245             Component comp = this.getComponent(i);
246             int nDepth = comp.getLocation().y + comp.getPreferredSize().height;
247             int nCurrWidth = comp.getLocation().x + comp.getPreferredSize().width;
248             if(nDepth > nHeight) {
249                 nHeight = nDepth;
250             }
251             if(nCurrWidth > nWidth) {
252                 nWidth = nCurrWidth;
253             }
254         }
255         
256         return new Dimension( nWidth, nHeight+5);
257     }
258
259 }
260
Popular Tags