001: package net.xoetrope.swing;
002:
003: import net.xoetrope.xml.XmlElement;
004: import net.xoetrope.xui.XMetaContentHolder;
005: import net.xoetrope.xui.style.XStyleComponent;
006: import java.awt.Color;
007: import java.awt.Font;
008: import javax.swing.JScrollPane;
009: import net.xoetrope.xui.XAttributedComponent;
010:
011: /**
012: * <p>Implements a scrollable holder for a XMetaContent component </p>
013: * <p>Copyright (c) Xoetrope Ltd., 1998-2004<br>
014: * License: see license.txt
015: * $Revision: 1.12 $
016: */
017:
018: public class XScrollableMetaContent extends XScrollPane implements
019: XMetaContentHolder, XStyleComponent, XAttributedComponent {
020: private XMetaContent content;
021:
022: /**
023: * Constrcuts a new container for an XMetaContent component
024: */
025: public XScrollableMetaContent() {
026: content = new XMetaContent();
027: setViewportView(content);
028: setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
029: }
030:
031: /**
032: * Sets the meta content
033: * @param source the location from which the xml was obtained
034: * @param src the new content
035: */
036: public void setContent(String source, XmlElement src) {
037: content.setContent(source, src);
038: doLayout();
039: }
040:
041: /**
042: * Get the meta content's name .
043: * @return the model name of the content
044: */
045: public String getContent() {
046: return content.getContent();
047: }
048:
049: /**
050: * Get the source of the current content
051: * @return
052: */
053: public String getFileName() {
054: if (content != null)
055: return content.getFileName();
056:
057: return null;
058: }
059:
060: /**
061: * Get the source of the current content
062: * @return
063: */
064: public void setFileName(String fileName) {
065: if (content != null)
066: content.setFileName(fileName);
067: }
068:
069: /**
070: * Sets the padding for the content
071: * @param padding
072: */
073: public void setPadding(int padding) {
074: content.setPadding(padding);
075: doLayout();
076: }
077:
078: /**
079: * Set the current style
080: * @param style the new style
081: */
082: public void setStyle(String style) {
083: content.setStyle(style);
084: }
085:
086: /**
087: * Set the background color and that of the content
088: * @param bkColor
089: */
090: public void setBackground(Color bkColor) {
091: super .setBackground(bkColor);
092: if (content != null)
093: content.setBackground(bkColor);
094: }
095:
096: /**
097: * Set the foreground color and that of the content
098: * @param bkColor
099: */
100: public void setForeground(Color fgColor) {
101: super .setForeground(fgColor);
102: if (content != null)
103: content.setForeground(fgColor);
104: }
105:
106: /**
107: * Set the font and that of the content
108: * @param font the new font
109: */
110: public void setFont(Font font) {
111: super .setFont(font);
112: if (content != null)
113: content.setFont(font);
114: }
115:
116: /**
117: * Sets the bounds for this component
118: * @param x
119: * @param y
120: * @param w
121: * @param h
122: */
123: public void setBounds(int x, int y, int w, int h) {
124: content.setBounds(0, 0, w, h);
125: super .setBounds(x, y, w, h);
126: doLayout();
127: content.calcSize();
128: }
129:
130: /**
131: * Set one or more attributes of the component.
132: * <LI>horizontal scrollbar, values=as needed|always|never</LI>
133: * <LI>vertical scrollbar, values=as needed|always|never</LI>
134: * @param attribName the attribute name
135: * @param attribValue the attribute value
136: */
137: public void setAttribute(String attribName, String attribValue) {
138: String attribNameLwr = attribName.toLowerCase();
139: String attribValueLwr = attribValue.toLowerCase();
140: if (attribNameLwr.compareTo("horizontal scrollbar") == 0)
141: setVerticalScrollBarPolicy(attribValueLwr
142: .equals("as needed") ? JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED
143: : attribValueLwr.equals("always") ? JScrollPane.VERTICAL_SCROLLBAR_ALWAYS
144: : JScrollPane.VERTICAL_SCROLLBAR_NEVER);
145: else if (attribNameLwr.compareTo("vertical scrollbar") == 0)
146: setHorizontalScrollBarPolicy(attribValueLwr
147: .equals("as needed") ? JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED
148: : attribValueLwr.equals("always") ? JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS
149: : JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
150: }
151: }
|