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.stringreadonlyhandling;
020:
021: import java.awt.Component;
022: import java.awt.Container;
023: import java.awt.Dimension;
024: import java.awt.Font;
025: import java.awt.LayoutManager;
026: import java.util.List;
027:
028: import javax.swing.JLabel;
029: import javax.swing.JPanel;
030:
031: import org.openharmonise.him.metadata.range.swing.*;
032: import org.openharmonise.vfs.metadata.*;
033: import org.openharmonise.vfs.metadata.value.*;
034:
035: /**
036: *
037: * @author Matthew Large
038: * @version $Revision: 1.1 $
039: *
040: */
041: public class StringReadOnlyRangeDisplay extends AbstractRangeDisplay
042: implements RangeDisplay, LayoutManager {
043:
044: private JLabel m_label = null;
045:
046: /**
047: * @param propInstance
048: */
049: public StringReadOnlyRangeDisplay(PropertyInstance propInstance) {
050: super (propInstance);
051: this .setup();
052: }
053:
054: private void setup() {
055: this .setLayout(this );
056:
057: String sValue = "";
058:
059: List aVals = this .getPropertyInstance().getValues();
060: if (aVals.size() > 0) {
061: StringValue value = (StringValue) aVals.get(0);
062: sValue = value.getValue();
063: }
064:
065: String fontName = "Dialog";
066: int fontSize = 11;
067: Font boldFont = new Font(fontName, Font.BOLD, fontSize);
068:
069: this .m_label = new JLabel(sValue);
070: this .m_label.setFont(boldFont);
071: this .add(this .m_label);
072: }
073:
074: /* (non-Javadoc)
075: * @see com.simulacramedia.contentmanager.metadata.range.swing.AbstractRangeDisplay#isMetadataValid()
076: */
077: public boolean isMetadataValid() {
078: return true;
079: }
080:
081: /* (non-Javadoc)
082: * @see com.simulacramedia.contentmanager.metadata.range.swing.RangeDisplay#getPanel()
083: */
084: public JPanel getPanel() {
085: return this ;
086: }
087:
088: /* (non-Javadoc)
089: * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
090: */
091: public void layoutContainer(Container arg0) {
092: this .m_label.setSize(this .m_label.getPreferredSize());
093: this .m_label.setLocation(20, 0);
094: }
095:
096: /* (non-Javadoc)
097: * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
098: */
099: public void removeLayoutComponent(Component arg0) {
100: // NO-OP
101: }
102:
103: /* (non-Javadoc)
104: * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
105: */
106: public void addLayoutComponent(String arg0, Component arg1) {
107: // NO-OP
108: }
109:
110: /* (non-Javadoc)
111: * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
112: */
113: public Dimension minimumLayoutSize(Container arg0) {
114: return this .getPreferredSize();
115: }
116:
117: /* (non-Javadoc)
118: * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
119: */
120: public Dimension preferredLayoutSize(Container arg0) {
121: return this .getPreferredSize();
122: }
123:
124: /* (non-Javadoc)
125: * @see java.awt.Component#getPreferredSize()
126: */
127: public Dimension getPreferredSize() {
128: this .layoutContainer(null);
129: int nWidth = this .getParent().getWidth() - 25;
130: return new Dimension(nWidth, 25);
131: }
132:
133: }
|