KickJava   Java API By Example, From Geeks To Geeks.

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


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;
20
21 import java.awt.Component JavaDoc;
22
23 import javax.swing.JPanel JavaDoc;
24
25 import org.openharmonise.him.metadata.swing.*;
26 import org.openharmonise.vfs.metadata.*;
27
28
29 /**
30  * Abstract class to assist in the creation of {@link org.openharmonise.him.metadata.range.swing.RangeDisplay}
31  * components.
32  *
33  * @author Matthew Large
34  * @version $Revision: 1.1 $
35  *
36  */

37 public abstract class AbstractRangeDisplay extends JPanel JavaDoc {
38
39     /**
40      * Property instance that this component is to display.
41      */

42     private PropertyInstance m_propInstance = null;
43     
44     /**
45      * true if this component should be read only, i.e. disabled.
46      */

47     private boolean m_bReadOnly = false;
48
49     /**
50      * Constructs a new Range Display.
51      *
52      * @param propInstance Property instance that this component is to display
53      */

54     public AbstractRangeDisplay(PropertyInstance propInstance) {
55         super();
56         m_propInstance = propInstance;
57     }
58     
59     /**
60      * Returns the property instance that this component is
61      * displaying.
62      *
63      * @return Property instance this component is displaying
64      */

65     public PropertyInstance getPropertyInstance() {
66         return this.m_propInstance;
67     }
68
69     /* (non-Javadoc)
70      * @see java.awt.Component#setEnabled(boolean)
71      */

72     public void setEnabled(boolean bEnabled) {
73         if(!this.m_bReadOnly) {
74             super.setEnabled(bEnabled);
75             for (int i = 0; i < this.getComponentCount(); i++) {
76                 Component JavaDoc comp = this.getComponent(i);
77                 comp.setEnabled(bEnabled);
78             }
79         } else {
80             super.setEnabled(false);
81             for (int i = 0; i < this.getComponentCount(); i++) {
82                 Component JavaDoc comp = this.getComponent(i);
83                 comp.setEnabled(false);
84             }
85         }
86     }
87     
88     /**
89      * Sets whether this component should be read only, i.e. disabled.
90      *
91      * @param bReadOnly true to make this component read only
92      */

93     public void setReadOnly(boolean bReadOnly) {
94         if(bReadOnly) {
95             this.setEnabled(false);
96             this.m_bReadOnly = true;
97         }
98     }
99     
100     /**
101      * Checks if this component is read only.
102      *
103      * @return true if this component is read only
104      */

105     public boolean isReadOnly() {
106         return this.m_bReadOnly;
107     }
108     
109     /**
110      * Checks if the values entered into this component validate
111      * against the range rules for the property instance which
112      * this component is displaying.
113      *
114      * @return true if the value are valid against the range rules
115      */

116     public abstract boolean isMetadataValid();
117     
118     /**
119      * Tells the tab that this component is in to validate itself.
120      *
121      */

122     protected void validateTab() {
123         Component JavaDoc comp = this;
124         while(comp!=null && !(comp instanceof MetadataTabPanel)) {
125             comp = comp.getParent();
126         }
127         
128         if(comp!=null && comp instanceof MetadataTabPanel) {
129             ((MetadataTabPanel) comp).checkValid();
130         }
131     }
132     
133     /**
134      * Checks if this component is resizable.
135      *
136      * @return true if this component is resizable
137      */

138     public boolean isResizeWidthEnabled() {
139         return true;
140     }
141
142 }
143
Popular Tags