KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > metadata > range > swing > relatedevents > RelatedEventApproxDate


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.range.swing.relatedevents;
20
21 import java.awt.*;
22 import java.beans.*;
23 import java.util.*;
24 import java.util.List JavaDoc;
25
26 import javax.swing.*;
27
28 import org.openharmonise.him.metadata.range.swing.*;
29 import org.openharmonise.vfs.metadata.*;
30 import org.openharmonise.vfs.metadata.range.*;
31 import org.openharmonise.vfs.metadata.value.*;
32
33
34 /**
35  * @author Michael Bell
36  * @version $Revision: 1.1 $
37  *
38  */

39 public class RelatedEventApproxDate extends AbstractRangeDisplay implements RangeDisplay, LayoutManager {
40
41     private RelatedEventDate m_dateSpinner = null;
42     private RelatedEventCertainty m_checkbox = null;
43     private JLabel m_checkLabel = null;
44     private int m_nSpacing = 5;
45
46     private PropertyValue m_propValue = null;
47
48     
49     /**
50      * @param propInst
51      */

52     public RelatedEventApproxDate(PropertyInstance propInst) {
53         super(propInst);
54         
55         List JavaDoc vals = propInst.getValues();
56         
57         if(vals.size() > 0) {
58             m_propValue = (PropertyValue) vals.get(0);
59         } else {
60             m_propValue = (PropertyValue) propInst.getNewValueInstance();
61             propInst.addValueWithoutFiringVirtualFileEvent(m_propValue);
62         }
63         
64         setup();
65     }
66
67     /**
68      *
69      */

70     private void setup() {
71         this.setLayout(this);
72         
73         PropertyInstance propInst = getPropertyInstance();
74         
75         
76         PropertyRange range =
77                     (PropertyRange) propInst
78                         .getDefinition()
79                         .getRange();
80
81         List JavaDoc props = range.getProperties();
82         
83         List JavaDoc propInstances = this.m_propValue.getValue();
84
85         ArrayList aFillingPropInstances = new ArrayList();
86         aFillingPropInstances.addAll(propInstances);
87
88         
89         Iterator iter = props.iterator();
90         
91         while (iter.hasNext()) {
92             Property tmpProp = (Property) iter.next();
93             String JavaDoc sPropName = tmpProp.getName();
94             PropertyInstance tmpPropInst = getPropertyInstance(tmpProp);
95             
96             if(tmpPropInst==null) {
97                 tmpPropInst = new PropertyInstance(tmpProp.getNamespace(), tmpProp.getName());
98                 aFillingPropInstances.add(tmpPropInst);
99                 
100                 if(propInst.getVirtualFile() == null) {
101                     throw new NullPointerException JavaDoc();
102                 }
103
104                 tmpPropInst.setVirtualFile(propInst.getVirtualFile());
105
106                 PropertyValue val = (PropertyValue) propInst.getNewValueInstance();
107             }
108             
109             if(sPropName.equals("date")) {
110                 m_dateSpinner = new RelatedEventDate(tmpPropInst);
111                 this.add(m_dateSpinner);
112             } else if(sPropName.equals("certainty")) {
113                 m_checkbox = new RelatedEventCertainty(tmpPropInst);
114                 m_checkLabel = new JLabel(tmpPropInst.getName() + ":");
115                 
116                 this.add(m_checkLabel);
117                 this.add(m_checkbox);
118             }
119         }
120         
121         if(aFillingPropInstances.size()>propInstances.size()) {
122             this.m_propValue.setValue(aFillingPropInstances);
123         }
124         
125     }
126
127     /* (non-Javadoc)
128      * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
129      */

130     public void removeLayoutComponent(Component comp) {
131     }
132
133     /* (non-Javadoc)
134      * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
135      */

136     public void layoutContainer(Container parent) {
137         int nYpos = 0;
138         int nXpos = 0;
139         
140         m_dateSpinner.setLocation(nXpos, nYpos);
141         m_dateSpinner.setSize(m_dateSpinner.getPreferredSize().width, m_dateSpinner.getPreferredSize().height+3);
142         
143         nYpos = nYpos + m_dateSpinner.getSize().height + m_nSpacing;
144         
145         m_checkLabel.setLocation(nXpos, nYpos);
146         m_checkLabel.setSize(m_checkLabel.getPreferredSize());
147         
148         nXpos = nXpos + m_checkLabel.getSize().width + m_nSpacing;
149         
150         m_checkbox.setLocation(nXpos, nYpos);
151         m_checkbox.setSize(m_checkbox.getPreferredSize());
152         
153     }
154
155     /* (non-Javadoc)
156      * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
157      */

158     public void addLayoutComponent(String JavaDoc name, Component comp) {
159     }
160
161     /* (non-Javadoc)
162      * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
163      */

164     public Dimension minimumLayoutSize(Container arg0) {
165         return this.getPreferredSize();
166     }
167
168
169
170     /* (non-Javadoc)
171      * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
172      */

173     public Dimension preferredLayoutSize(Container arg0) {
174         return this.getPreferredSize();
175     }
176
177     /* (non-Javadoc)
178      * @see java.awt.Component#getPreferredSize()
179      */

180     public Dimension getPreferredSize() {
181         int nHeight = m_dateSpinner.getPreferredSize().height;
182         nHeight = nHeight + m_checkbox.getPreferredSize().height;
183         nHeight = nHeight + m_nSpacing;
184         
185         int nWidth = m_dateSpinner.getPreferredSize().width;
186         
187         return new Dimension(nWidth,nHeight);
188     }
189     
190
191
192     /* (non-Javadoc)
193      * @see com.simulacramedia.contentmanager.metadata.range.swing.AbstractRangeDisplay#isValid()
194      */

195     public boolean isMetadataValid() {
196         boolean bIsValid = false;
197         
198         bIsValid = (m_dateSpinner.isMetadataValid()
199                     && m_checkbox.isMetadataValid());
200         
201         return bIsValid;
202     }
203     
204     /**
205      * @param prop
206      * @return
207      */

208     private PropertyInstance getPropertyInstance(Property prop) {
209         PropertyInstance propInst = null;
210     
211         List JavaDoc propInstances = this.m_propValue.getValue();
212     
213         Iterator iter = propInstances.iterator();
214     
215         while(iter.hasNext()) {
216             PropertyInstance propInstTemp = (PropertyInstance)iter.next();
217             if(prop.getName().equals(propInstTemp.getName()) && prop.getNamespace().equals(propInstTemp.getNamespaceURI())) {
218                 propInst = propInstTemp;
219             }
220         }
221     
222         return propInst;
223     }
224
225     /* (non-Javadoc)
226      * @see com.simulacramedia.contentmanager.metadata.range.swing.RangeDisplay#getPanel()
227      */

228     public JPanel getPanel() {
229         
230         return this;
231     }
232     
233
234     /* (non-Javadoc)
235      * @see java.awt.Component#addPropertyChangeListener(java.beans.PropertyChangeListener)
236      */

237     public synchronized void addPropertyChangeListener(PropertyChangeListener listener) {
238         super.addPropertyChangeListener(listener);
239         this.m_dateSpinner.addPropertyChangeListener(listener);
240         this.m_checkbox.addPropertyChangeListener(listener);
241     }
242
243 }
244
Popular Tags