001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.him.metadata.range.swing;
020:
021: import java.awt.Component;
022:
023: import javax.swing.JPanel;
024:
025: import org.openharmonise.him.metadata.swing.*;
026: import org.openharmonise.vfs.metadata.*;
027:
028: /**
029: * Abstract class to assist in the creation of {@link org.openharmonise.him.metadata.range.swing.RangeDisplay}
030: * components.
031: *
032: * @author Matthew Large
033: * @version $Revision: 1.1 $
034: *
035: */
036: public abstract class AbstractRangeDisplay extends JPanel {
037:
038: /**
039: * Property instance that this component is to display.
040: */
041: private PropertyInstance m_propInstance = null;
042:
043: /**
044: * true if this component should be read only, i.e. disabled.
045: */
046: private boolean m_bReadOnly = false;
047:
048: /**
049: * Constructs a new Range Display.
050: *
051: * @param propInstance Property instance that this component is to display
052: */
053: public AbstractRangeDisplay(PropertyInstance propInstance) {
054: super ();
055: m_propInstance = propInstance;
056: }
057:
058: /**
059: * Returns the property instance that this component is
060: * displaying.
061: *
062: * @return Property instance this component is displaying
063: */
064: public PropertyInstance getPropertyInstance() {
065: return this .m_propInstance;
066: }
067:
068: /* (non-Javadoc)
069: * @see java.awt.Component#setEnabled(boolean)
070: */
071: public void setEnabled(boolean bEnabled) {
072: if (!this .m_bReadOnly) {
073: super .setEnabled(bEnabled);
074: for (int i = 0; i < this .getComponentCount(); i++) {
075: Component comp = this .getComponent(i);
076: comp.setEnabled(bEnabled);
077: }
078: } else {
079: super .setEnabled(false);
080: for (int i = 0; i < this .getComponentCount(); i++) {
081: Component comp = this .getComponent(i);
082: comp.setEnabled(false);
083: }
084: }
085: }
086:
087: /**
088: * Sets whether this component should be read only, i.e. disabled.
089: *
090: * @param bReadOnly true to make this component read only
091: */
092: public void setReadOnly(boolean bReadOnly) {
093: if (bReadOnly) {
094: this .setEnabled(false);
095: this .m_bReadOnly = true;
096: }
097: }
098:
099: /**
100: * Checks if this component is read only.
101: *
102: * @return true if this component is read only
103: */
104: public boolean isReadOnly() {
105: return this .m_bReadOnly;
106: }
107:
108: /**
109: * Checks if the values entered into this component validate
110: * against the range rules for the property instance which
111: * this component is displaying.
112: *
113: * @return true if the value are valid against the range rules
114: */
115: public abstract boolean isMetadataValid();
116:
117: /**
118: * Tells the tab that this component is in to validate itself.
119: *
120: */
121: protected void validateTab() {
122: Component comp = this ;
123: while (comp != null && !(comp instanceof MetadataTabPanel)) {
124: comp = comp.getParent();
125: }
126:
127: if (comp != null && comp instanceof MetadataTabPanel) {
128: ((MetadataTabPanel) comp).checkValid();
129: }
130: }
131:
132: /**
133: * Checks if this component is resizable.
134: *
135: * @return true if this component is resizable
136: */
137: public boolean isResizeWidthEnabled() {
138: return true;
139: }
140:
141: }
|