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.metadata.swing;
020:
021: import java.awt.*;
022: import java.util.*;
023:
024: import javax.swing.*;
025:
026: import org.openharmonise.him.metadata.range.swing.resourcehandling.*;
027: import org.openharmonise.vfs.*;
028: import org.openharmonise.vfs.metadata.*;
029:
030: /**
031: * @author Matthew Large
032: * @version $Revision: 1.1 $
033: */
034: public class MetadataTabPanel extends JPanel implements LayoutManager {
035:
036: private ResourceRangeDisplay m_relationships = null;
037:
038: private VirtualFile m_vfPropGroup = null;
039:
040: private HashMap m_pathOrderMapping = new HashMap();
041:
042: private SortedSet m_propPanels = new TreeSet();
043:
044: private int m_nNextOrderVal = 1;
045:
046: /**
047: *
048: */
049: public MetadataTabPanel() {
050: super ();
051: this .setup();
052: }
053:
054: /**
055: *
056: */
057: public MetadataTabPanel(VirtualFile vfPropGroup) {
058: super ();
059: this .m_vfPropGroup = vfPropGroup;
060: this .setup();
061: }
062:
063: private void setup() {
064: this .setLayout(this );
065:
066: this .m_pathOrderMapping.put("/webdav/SYSTEM_PROPS/title",
067: new Integer(1));
068: this .m_pathOrderMapping.put("/webdav/SYSTEM_PROPS/description",
069: new Integer(2));
070: int nCount = 3;
071:
072: if (this .m_vfPropGroup != null) {
073: Iterator itor = this .m_vfPropGroup.getChildren().iterator();
074: while (itor.hasNext()) {
075: String sPath = (String) itor.next();
076: this .m_pathOrderMapping.put(sPath, new Integer(nCount));
077: nCount++;
078: }
079: }
080: this .m_nNextOrderVal = nCount;
081: }
082:
083: public void addPropertyPanel(PropertyPanel propPanel) {
084: Property prop = propPanel.getProperty();
085: if (prop != null
086: && this .m_pathOrderMapping.get(prop.getHREF()) != null) {
087: int nOrder = ((Integer) this .m_pathOrderMapping.get(prop
088: .getHREF())).intValue();
089: OrderedProp orderedProp = new OrderedProp(nOrder, propPanel);
090: this .m_propPanels.add(orderedProp);
091: } else {
092: OrderedProp orderedProp = new OrderedProp(
093: this .m_nNextOrderVal, propPanel);
094: this .m_nNextOrderVal++;
095: this .m_propPanels.add(orderedProp);
096: }
097: this .add(propPanel);
098: }
099:
100: protected void clearToDestroy() {
101: this .m_relationships = null;
102: this .removeAll();
103: }
104:
105: /**
106: * @param arg0
107: */
108: private MetadataTabPanel(boolean arg0) {
109: super (arg0);
110: }
111:
112: /**
113: * @param arg0
114: */
115: private MetadataTabPanel(LayoutManager arg0) {
116: super (arg0);
117: }
118:
119: /**
120: * @param arg0
121: * @param arg1
122: */
123: private MetadataTabPanel(LayoutManager arg0, boolean arg1) {
124: super (arg0, arg1);
125: }
126:
127: /**
128: * @return
129: */
130: public ResourceRangeDisplay getRelationships() {
131: return m_relationships;
132: }
133:
134: public boolean hasRelationships() {
135: return (this .m_relationships != null);
136: }
137:
138: /* (non-Javadoc)
139: * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
140: */
141: public void layoutContainer(Container arg0) {
142: int nHeight = 0;
143: Iterator itor = this .m_propPanels.iterator();
144: while (itor.hasNext()) {
145: OrderedProp orderedProp = (OrderedProp) itor.next();
146: PropertyPanel propPanel = orderedProp.getPropPanel();
147:
148: propPanel.setSize(propPanel.getPreferredSize());
149: propPanel.setLocation(0, nHeight);
150: nHeight = nHeight + propPanel.getSize().height;
151: }
152: }
153:
154: /**
155: * @param display
156: */
157: public void setRelationships(ResourceRangeDisplay display) {
158: if (this .m_relationships == null) {
159: m_relationships = display;
160: PropertyPanel propPanel = new PropertyPanel(
161: "Relationships", false);
162: propPanel.add(m_relationships);
163: OrderedProp orderedProp = new OrderedProp(
164: this .m_nNextOrderVal, propPanel);
165: this .m_nNextOrderVal++;
166: this .m_propPanels.add(orderedProp);
167: this .add(propPanel);
168: }
169: }
170:
171: public void addRelationship(ResourceRangeDisplay display) {
172: this .m_relationships.addRelationship(display);
173: }
174:
175: /* (non-Javadoc)
176: * @see java.awt.Component#setEnabled(boolean)
177: */
178: public void setEnabled(boolean bEnabled) {
179: for (int i = 0; i < this .getComponentCount(); i++) {
180: Component comp = this .getComponent(i);
181: comp.setEnabled(bEnabled);
182: }
183: super .setEnabled(bEnabled);
184: }
185:
186: public void checkValid() {
187: boolean bValid = true;
188: for (int i = 0; i < this .getComponentCount() && bValid == true; i++) {
189: Component comp = this .getComponent(i);
190: if (comp instanceof PropertyPanel) {
191: if (!((PropertyPanel) comp).getRangeDisplay()
192: .isMetadataValid()) {
193: bValid = false;
194: }
195: }
196: }
197:
198: MetadataTabs tabs = this .getTabs();
199: tabs.setValid(bValid, this );
200: }
201:
202: private MetadataTabs getTabs() {
203: Component comp = this ;
204: while (comp != null && !(comp instanceof MetadataTabs)) {
205: comp = comp.getParent();
206: }
207:
208: if (comp != null && comp instanceof MetadataTabs) {
209: return (MetadataTabs) comp;
210: } else {
211: return null;
212: }
213: }
214:
215: /* (non-Javadoc)
216: * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
217: */
218: public void removeLayoutComponent(Component arg0) {
219: }
220:
221: /* (non-Javadoc)
222: * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
223: */
224: public void addLayoutComponent(String arg0, Component arg1) {
225: }
226:
227: /* (non-Javadoc)
228: * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
229: */
230: public Dimension minimumLayoutSize(Container arg0) {
231: return this .getPreferredSize();
232: }
233:
234: /* (non-Javadoc)
235: * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
236: */
237: public Dimension preferredLayoutSize(Container arg0) {
238: return this .getPreferredSize();
239: }
240:
241: /* (non-Javadoc)
242: * @see java.awt.Component#getPreferredSize()
243: */
244: public Dimension getPreferredSize() {
245: int nHeight = 0;
246: int nCount = this .getComponentCount();
247: int nWidth = 0;
248: for (int i = 0; i < nCount; i++) {
249: Component comp = this .getComponent(i);
250: int nDepth = comp.getLocation().y
251: + comp.getPreferredSize().height;
252: int nCurrWidth = comp.getLocation().x
253: + comp.getPreferredSize().width;
254: if (nDepth > nHeight) {
255: nHeight = nDepth;
256: }
257: if (nCurrWidth > nWidth) {
258: nWidth = nCurrWidth;
259: }
260: }
261:
262: return new Dimension(nWidth, nHeight + 5);
263: }
264:
265: }
|