KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > metadata > range > swing > stringreadonlyhandling > StringReadOnlyRangeDisplay


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.stringreadonlyhandling;
20
21 import java.awt.Component JavaDoc;
22 import java.awt.Container JavaDoc;
23 import java.awt.Dimension JavaDoc;
24 import java.awt.Font JavaDoc;
25 import java.awt.LayoutManager JavaDoc;
26 import java.util.List JavaDoc;
27
28 import javax.swing.JLabel JavaDoc;
29 import javax.swing.JPanel JavaDoc;
30
31 import org.openharmonise.him.metadata.range.swing.*;
32 import org.openharmonise.vfs.metadata.*;
33 import org.openharmonise.vfs.metadata.value.*;
34
35
36 /**
37  *
38  * @author Matthew Large
39  * @version $Revision: 1.1 $
40  *
41  */

42 public class StringReadOnlyRangeDisplay extends AbstractRangeDisplay implements
43         RangeDisplay, LayoutManager JavaDoc {
44
45     private JLabel JavaDoc m_label = null;
46     
47     /**
48      * @param propInstance
49      */

50     public StringReadOnlyRangeDisplay(PropertyInstance propInstance) {
51         super(propInstance);
52         this.setup();
53     }
54     
55     private void setup() {
56         this.setLayout(this);
57         
58         String JavaDoc sValue = "";
59         
60         List JavaDoc aVals = this.getPropertyInstance().getValues();
61         if(aVals.size()>0) {
62             StringValue value = (StringValue) aVals.get(0);
63             sValue = value.getValue();
64         }
65         
66         String JavaDoc fontName = "Dialog";
67         int fontSize = 11;
68         Font JavaDoc boldFont = new Font JavaDoc(fontName, Font.BOLD, fontSize);
69         
70         this.m_label = new JLabel JavaDoc(sValue);
71         this.m_label.setFont(boldFont);
72         this.add(this.m_label);
73     }
74
75     /* (non-Javadoc)
76      * @see com.simulacramedia.contentmanager.metadata.range.swing.AbstractRangeDisplay#isMetadataValid()
77      */

78     public boolean isMetadataValid() {
79         return true;
80     }
81
82     /* (non-Javadoc)
83      * @see com.simulacramedia.contentmanager.metadata.range.swing.RangeDisplay#getPanel()
84      */

85     public JPanel JavaDoc getPanel() {
86         return this;
87     }
88
89     /* (non-Javadoc)
90      * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
91      */

92     public void layoutContainer(Container JavaDoc arg0) {
93         this.m_label.setSize(this.m_label.getPreferredSize());
94         this.m_label.setLocation(20, 0);
95     }
96
97     /* (non-Javadoc)
98      * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
99      */

100     public void removeLayoutComponent(Component JavaDoc arg0) {
101         // NO-OP
102
}
103
104     /* (non-Javadoc)
105      * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
106      */

107     public void addLayoutComponent(String JavaDoc arg0, Component JavaDoc arg1) {
108         // NO-OP
109
}
110
111     /* (non-Javadoc)
112      * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
113      */

114     public Dimension JavaDoc minimumLayoutSize(Container JavaDoc arg0) {
115         return this.getPreferredSize();
116     }
117
118     /* (non-Javadoc)
119      * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
120      */

121     public Dimension JavaDoc preferredLayoutSize(Container JavaDoc arg0) {
122         return this.getPreferredSize();
123     }
124
125     /* (non-Javadoc)
126      * @see java.awt.Component#getPreferredSize()
127      */

128     public Dimension JavaDoc getPreferredSize() {
129         this.layoutContainer(null);
130         int nWidth = this.getParent().getWidth()-25;
131         return new Dimension JavaDoc(nWidth, 25);
132     }
133
134 }
135
Popular Tags