KickJava   Java API By Example, From Geeks To Geeks.

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


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
20 package org.openharmonise.him.metadata.swing;
21
22 import java.awt.*;
23
24 import javax.swing.*;
25 import javax.swing.border.*;
26
27 import org.openharmonise.commons.xml.namespace.*;
28 import org.openharmonise.him.metadata.range.swing.*;
29 import org.openharmonise.vfs.metadata.*;
30
31
32 /**
33  * @author Matthew Large
34  *
35  */

36 public class PropertyPanel extends JPanel implements LayoutManager {
37
38     private PropertyInstance m_propertyInstance = null;
39     private String JavaDoc m_sName = null;
40     
41     private boolean m_bResizeWidth = true;
42     
43     private HelpIcon m_helpIcon = null;
44     
45     private JLabel m_titleLabel = null;
46
47     /**
48      *
49      */

50     public PropertyPanel(PropertyInstance propertyInstance, boolean bResizeWidth) {
51         super();
52         this.m_propertyInstance = propertyInstance;
53         this.m_bResizeWidth = bResizeWidth;
54         this.setup();
55     }
56     /**
57     *
58     */

59    public PropertyPanel(String JavaDoc sName, boolean bResizeWidth) {
60        super();
61        this.m_sName = sName;
62         this.m_bResizeWidth = bResizeWidth;
63        this.setup();
64    }
65    
66    public Property getProperty() {
67         Property prop = null;
68         
69         if(this.m_propertyInstance!=null && this.m_propertyInstance.getDefinition()!=null) {
70             prop = this.m_propertyInstance.getDefinition();
71         }
72         
73         return prop;
74    }
75
76     /**
77      * @param arg0
78      */

79     private PropertyPanel(boolean arg0) {
80         super(arg0);
81     }
82
83     /**
84      * @param arg0
85      */

86     private PropertyPanel(LayoutManager arg0) {
87         super(arg0);
88     }
89
90     /**
91      * @param arg0
92      * @param arg1
93      */

94     private PropertyPanel(LayoutManager arg0, boolean arg1) {
95         super(arg0, arg1);
96     }
97     
98     private void setup() {
99         this.setLayout(this);
100         
101         TitledBorder border = null;
102         
103         if(this.m_propertyInstance!=null) {
104             if(this.m_propertyInstance.getNamespaceURI().equals(NamespaceType.OHRM.getURI()) && this.m_propertyInstance.getName().equals("title")) {
105                 this.m_titleLabel = new JLabel("Title");
106             } else {
107                 this.m_titleLabel = new JLabel(this.m_propertyInstance.getDefinition().getDisplayName());
108             }
109         } else if(this.m_sName!=null) {
110             this.m_titleLabel = new JLabel(this.m_sName);
111         }
112         String JavaDoc fontName = "Dialog";
113         int fontSize = 13;
114         Font font = new Font(fontName, Font.BOLD, fontSize);
115         this.m_titleLabel.setFont(font);
116         this.add(m_titleLabel);
117         
118         if(this.m_propertyInstance!=null && this.m_propertyInstance.getDefinition()!=null) {
119             if(this.m_propertyInstance.getName().equals("domain")) {
120                 this.m_helpIcon = new HelpIcon("Domain", "Domain is used to restrict a Property's use (and occurrence) to a particular set of Collections or Resources, for example you could restrict the Property \"Location\" to the Resources within the Collection \"Case Study\" and restrict the number of locations to \"one\". This would mean that when tagging a Case Study document the vocabularies within Location (e.g. South East, Midlands etc.) would be available to the user and that they need to define one Location.");
121                 this.add(m_helpIcon);
122             } else if(this.m_propertyInstance.getName().equals("range")) {
123                 this.m_helpIcon = new HelpIcon("Range", "The Range of a Property is description of its allowable Values.");
124                 this.add(m_helpIcon);
125             } else {
126                 this.m_helpIcon = new HelpIcon(this.m_propertyInstance.getDefinition());
127                 this.add(m_helpIcon);
128             }
129         }
130     }
131     
132     
133
134     /* (non-Javadoc)
135      * @see java.awt.Component#getPreferredSize()
136      */

137     public Dimension getPreferredSize() {
138         int nHeight = 0;
139         int nCount = this.getComponentCount();
140         int nWidth = 0;
141         for(int i=0; i<nCount; i++) {
142             Component comp = this.getComponent(i);
143             int nDepth = comp.getLocation().y + comp.getPreferredSize().height;
144             int nCurrWidth = comp.getLocation().x + comp.getPreferredSize().width;
145             if(nDepth > nHeight) {
146                 nHeight = nDepth;
147             }
148             if(nCurrWidth > nWidth) {
149                 nWidth = nCurrWidth;
150             }
151         }
152         
153         if(this.m_bResizeWidth) {
154             return new Dimension( this.getParent().getWidth()-20, nHeight+5);
155         } else {
156             return new Dimension( nWidth, nHeight+5);
157         }
158     }
159
160     /* (non-Javadoc)
161      * @see java.awt.Component#setEnabled(boolean)
162      */

163     public void setEnabled(boolean bEnabled) {
164         for (int i = 0; i < this.getComponentCount(); i++) {
165             Component comp = this.getComponent(i);
166             comp.setEnabled(bEnabled);
167         }
168         super.setEnabled(bEnabled);
169     }
170
171     public AbstractRangeDisplay getRangeDisplay() {
172         for (int i = 0; i < this.getComponentCount(); i++) {
173             Component comp = this.getComponent(i);
174             if(comp instanceof AbstractRangeDisplay) {
175                 return (AbstractRangeDisplay) comp;
176             }
177         }
178         return null;
179     }
180     /* (non-Javadoc)
181      * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
182      */

183     public void layoutContainer(Container arg0) {
184         int nHeight = 35;
185         for (int i = 0; i < this.getComponentCount(); i++) {
186             Component comp = this.getComponent(i);
187             if(comp instanceof AbstractRangeDisplay) {
188                 comp.setSize(comp.getPreferredSize());
189                 comp.setLocation(5, nHeight);
190             } else if(comp instanceof HelpIcon) {
191                 comp.setSize(20, 20);
192                 comp.setLocation(this.m_titleLabel.getPreferredSize().width+15, 10);
193             } else if(comp==this.m_titleLabel) {
194                 comp.setSize(this.m_titleLabel.getPreferredSize().width, 30);
195                 comp.setLocation(5, 5);
196             }
197         }
198     }
199     
200     /* (non-Javadoc)
201      * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
202      */

203     public void removeLayoutComponent(Component arg0) {
204     }
205     
206     /* (non-Javadoc)
207      * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
208      */

209     public void addLayoutComponent(String JavaDoc arg0, Component arg1) {
210     }
211     
212     /* (non-Javadoc)
213      * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
214      */

215     public Dimension minimumLayoutSize(Container arg0) {
216         return this.getPreferredSize();
217     }
218     
219     /* (non-Javadoc)
220      * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
221      */

222     public Dimension preferredLayoutSize(Container arg0) {
223         return this.getPreferredSize();
224     }
225 }
226
Popular Tags