KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > metadata > range > swing > range > RangeRangeDisplay


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.range;
20
21 import java.awt.*;
22 import java.awt.event.*;
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.him.metadata.range.swing.range.details.*;
30 import org.openharmonise.vfs.metadata.*;
31 import org.openharmonise.vfs.metadata.range.*;
32 import org.openharmonise.vfs.metadata.value.*;
33
34
35 /**
36  * @author Matthew Large
37  * @version $Revision: 1.1 $
38  *
39  */

40 public class RangeRangeDisplay
41     extends AbstractRangeDisplay
42     implements RangeDisplay, LayoutManager, ActionListener, RangeDetailsListener {
43
44         private int m_nHeight = 400;
45         
46         private RangeTypeChoice m_choice = null;
47         
48         private AbstractRangeDetails m_details = null;
49
50     /**
51      * @param propInstance
52      */

53     public RangeRangeDisplay(PropertyInstance propInstance) {
54         super(propInstance);
55         this.setup();
56     }
57     
58     private void setup() {
59         this.setLayout(this);
60         
61         m_choice = new RangeTypeChoice(this);
62         this.add(m_choice);
63         
64         m_details = this.getDetailsPanel();
65         m_details.addRangeDetailsListener(this);
66         this.add(m_details);
67         
68     }
69     
70     private AbstractRangeDetails getDetailsPanel() {
71         List JavaDoc values = this.getPropertyInstance().getValues();
72         if(values.size()>0) {
73             RangeValue rangeValue = (RangeValue) this.getPropertyInstance().getValues().get(0);
74             Range range = rangeValue.getRange();
75             if((range instanceof DateRange) || (range instanceof DateTimeRange)) {
76                 this.m_choice.selectChoice("Date");
77                 return new DateDetails(this.getPropertyInstance());
78             } else if((range instanceof IntegerRange) || (range instanceof FloatRange)) {
79                 this.m_choice.selectChoice("Number");
80                 return new NumberDetails(this.getPropertyInstance());
81             } else if(range instanceof BooleanRange) {
82                 this.m_choice.selectChoice("Boolean");
83                 return new BooleanDetails(this.getPropertyInstance());
84             } else if(range instanceof URIRange) {
85                 this.m_choice.selectChoice("URI");
86                 return new URIDetails(this.getPropertyInstance());
87             } else if(range instanceof ValueRange) {
88                 this.m_choice.selectChoice("Vocabularies");
89                 return new VocabularyDetails(this.getPropertyInstance());
90             } else if(range instanceof PropertyRange) {
91                 this.m_choice.selectChoice("Compound Property");
92                 return new CompoundDetails(this.getPropertyInstance());
93             } else if((range instanceof ResourceRange) || (range instanceof CollectionRange)) {
94                 this.m_choice.selectChoice("Relationship");
95                 return new RelationshipDetails(this.getPropertyInstance());
96             } else {
97                 this.m_choice.selectChoice("Text");
98                 return new TextDetails(this.getPropertyInstance());
99             }
100         } else {
101             return new BlankDetails(this.getPropertyInstance());
102         }
103     }
104     
105     protected void typeSelected(String JavaDoc sTemp) {
106         AbstractRangeDetails details = null;
107     
108         RangeValue rangeValue = (RangeValue) this.getPropertyInstance().getNewValueInstance();
109         ArrayList aValues = new ArrayList();
110         aValues.add(rangeValue);
111         this.getPropertyInstance().setValues(aValues);
112         
113         if(sTemp.equalsIgnoreCase("Number")) {
114             details = new NumberDetails(this.getPropertyInstance());
115         } else if(sTemp.equalsIgnoreCase("Text")) {
116             details = new TextDetails(this.getPropertyInstance());
117         } else if(sTemp.equalsIgnoreCase("Date")) {
118             details = new DateDetails(this.getPropertyInstance());
119         } else if(sTemp.equalsIgnoreCase("URI")) {
120             details = new URIDetails(this.getPropertyInstance());
121         } else if(sTemp.equalsIgnoreCase("Boolean")) {
122             details = new BooleanDetails(this.getPropertyInstance());
123         } else if(sTemp.equalsIgnoreCase("Vocabularies")) {
124             details = new VocabularyDetails(this.getPropertyInstance());
125         } else if(sTemp.equalsIgnoreCase("Compound Property")) {
126             details = new CompoundDetails(this.getPropertyInstance());
127         } else if(sTemp.equalsIgnoreCase("Relationship")) {
128             details = new RelationshipDetails(this.getPropertyInstance());
129         }
130         
131         if(this.m_details!=null && !this.m_details.getClass().getName().equals(details.getClass().getName())) {
132             this.remove(this.m_details);
133             this.m_details = details;
134             m_details.addRangeDetailsListener(this);
135             this.add(this.m_details);
136             
137             this.validateTree();
138         }
139     }
140
141     /* (non-Javadoc)
142      * @see com.simulacramedia.contentmanager.metadata.range.swing.RangeDisplay#getPanel()
143      */

144     public JPanel getPanel() {
145         return this;
146     }
147
148     /* (non-Javadoc)
149      * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
150      */

151     public void removeLayoutComponent(Component arg0) {
152     }
153
154     /* (non-Javadoc)
155      * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
156      */

157     public void layoutContainer(Container arg0) {
158         this.m_choice.setSize(this.m_choice.getPreferredSize());
159         this.m_choice.setLocation(10, 0);
160         
161         this.m_details.setSize(this.m_details.getPreferredSize());
162         this.m_details.setLocation(10, 0 + this.m_choice.getPreferredSize().height);
163     }
164     
165     public Dimension getPreferredSize() {
166         int nWidth = 10;
167         if(this.m_details.getPreferredSize().width>this.m_choice.getPreferredSize().width) {
168             nWidth = nWidth + this.m_details.getPreferredSize().width;
169         } else {
170             nWidth = nWidth + this.m_choice.getPreferredSize().width;
171         }
172         return new Dimension(nWidth, this.m_details.getPreferredSize().height + this.m_choice.getPreferredSize().height);
173     }
174
175     /* (non-Javadoc)
176      * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
177      */

178     public void addLayoutComponent(String JavaDoc arg0, Component arg1) {
179     }
180
181     /* (non-Javadoc)
182      * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
183      */

184     public Dimension minimumLayoutSize(Container arg0) {
185         return this.getPreferredSize();
186     }
187
188     /* (non-Javadoc)
189      * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
190      */

191     public Dimension preferredLayoutSize(Container arg0) {
192         return this.getPreferredSize();
193     }
194
195     /* (non-Javadoc)
196      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
197      */

198     public void actionPerformed(ActionEvent arg0) {
199     }
200
201     /* (non-Javadoc)
202      * @see com.simulacramedia.contentmanager.metadata.range.swing.range.RangeDetailsListener#RangeDetailsChange(com.simulacramedia.vfs.metadata.value.RangeValue)
203      */

204     public void rangeDetailsChange(RangeValue range) {
205         this.getPropertyInstance().setValue(range);
206     }
207
208     /* (non-Javadoc)
209      * @see com.simulacramedia.contentmanager.metadata.range.swing.AbstractRangeDisplay#isValid()
210      */

211     public boolean isMetadataValid() {
212         return true;
213     }
214
215     /* (non-Javadoc)
216      * @see com.simulacramedia.contentmanager.metadata.range.swing.AbstractRangeDisplay#isWidthResizable()
217      */

218     public boolean isResizeWidthEnabled() {
219         return false;
220     }
221
222 }
223
Popular Tags