001: //** Copyright Statement ***************************************************
002: //The Salmon Open Framework for Internet Applications (SOFIA)
003: // Copyright (C) 1999 - 2002, Salmon LLC
004: //
005: // This program is free software; you can redistribute it and/or
006: // modify it under the terms of the GNU General Public License version 2
007: // as published by the Free Software Foundation;
008: //
009: // This program is distributed in the hope that it will be useful,
010: // but WITHOUT ANY WARRANTY; without even the implied warranty of
011: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: // GNU General Public License for more details.
013: //
014: // You should have received a copy of the GNU General Public License
015: // along with this program; if not, write to the Free Software
016: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: //
018: // For more information please visit http://www.salmonllc.com
019: //** End Copyright Statement ***************************************************
020: package com.salmonllc.html;
021:
022: /////////////////////////
023: //$Archive: /SOFIA/SourceCode/com/salmonllc/html/HtmlInlineFrame.java $
024: //$Author: Dan $
025: //$Revision: 14 $
026: //$Modtime: 12/19/03 11:33a $
027: /////////////////////////
028:
029: import java.io.PrintWriter;
030: import java.util.Hashtable;
031: import java.util.Vector;
032:
033: /**
034: * This class will generate the html an InLine Frame.
035: */
036: public class HtmlInlineFrame extends HtmlContainer {
037: public static final int SIZE_PERCENT = 0;
038: public static final int SIZE_PIXELS = 1;
039:
040: int _width = -1;
041: int _height = -1;
042: int _border = 0;
043: int _heightSizeOption = SIZE_PIXELS;
044: int _widthSizeOption = SIZE_PIXELS;
045:
046: String _src = "";
047:
048: /**
049: *Constructs a new InLine Frame
050: * @param name java.lang.String
051: * @param p com.salmonllc.html.HtmlPage
052: */
053: public HtmlInlineFrame(String name, com.salmonllc.html.HtmlPage p) {
054: super (name, p);
055: }
056:
057: /**
058: * This method should not be used. Use setFrameComponent instead.
059: */
060: public void add(HtmlComponent comp) {
061: return;
062: }
063:
064: public void generateHTML(PrintWriter p, int rowNo) throws Exception {
065: generateHTML(p, -999, rowNo);
066: }
067:
068: public void generateHTML(PrintWriter p, int rowStart, int rowEnd)
069: throws Exception {
070: if (_componentsVec == null)
071: return;
072: if (!_visible)
073: return;
074: if (_center)
075: p.print("<CENTER>");
076: if (getPage().getUseIFrames()) {
077: String name = getPage().getClass().getName();
078: int pos = name.lastIndexOf(".");
079: if (pos > -1)
080: name = name.substring(pos + 1);
081: name += "-" + getName() + "FrameComponent";
082: if (_src != null && !_src.equals(""))
083: name = _src;
084: p.print("<IFRAME NAME=\"" + getFullName()
085: + "\" MARGINWIDTH=\"0\" MARGINHEIGHT=\"0\" SRC=\""
086: + name + "\"");
087: p.print(" FRAMEBORDER=\"" + _border + "\"");
088: String heading = "";
089: if (_width > -1) {
090: heading += " WIDTH=\"" + _width;
091: if (_widthSizeOption == SIZE_PERCENT)
092: heading += "%";
093: heading += "\"";
094: }
095: if (_height > -1) {
096: heading += " HEIGHT=\"" + _height;
097: if (_heightSizeOption == SIZE_PERCENT)
098: heading += "%";
099: heading += "\"";
100: }
101: p.print(heading);
102: p.println("></IFRAME>");
103: } else {
104: HtmlComponent h = null;
105: int componentsSize = _componentsVec.size();
106: for (int i = 0; i < componentsSize; i++) {
107: h = (HtmlComponent) _componentsVec.elementAt(i);
108: if (h != null) {
109: if (rowStart == -999)
110: h.generateHTML(p, rowEnd);
111: else
112: h.generateHTML(p, rowStart, rowEnd);
113: }
114: }
115: }
116: if (_center)
117: p.print("</CENTER>");
118: }
119:
120: public void generateInitialHTML(PrintWriter p) throws Exception {
121: if (!_visible || _componentsVec == null)
122: return;
123: if (!getPage().getUseIFrames()) {
124: HtmlComponent h = null;
125: int componentsSize = _componentsVec.size();
126: for (int i = 0; i < componentsSize; i++) {
127: h = (HtmlComponent) _componentsVec.elementAt(i);
128: if (h != null)
129: h.generateInitialHTML(p);
130: }
131: }
132: }
133:
134: /**
135: * Gets the border thickness for the frame.
136: */
137: public int getBorder() {
138: return _border;
139: }
140:
141: /**
142: * This method returns the component in the Inline Frame.
143: */
144: public HtmlComponent getFrameComponent() {
145: if (_componentsVec == null)
146: return null;
147: else {
148: if (_componentsVec.size() == 0)
149: return null;
150:
151: Object o = _componentsVec.elementAt(0);
152: if (o == null)
153: return null;
154: else
155: return (HtmlComponent) o;
156:
157: }
158:
159: }
160:
161: /**
162: * This method gets the minimum height of the frame.
163: */
164: public int getHeight() {
165: return _height;
166: }
167:
168: /**
169: * This method returns the size option for the height of the iframe. Valid return values are SIZE_PIXELS or SIZE_PERCENT.
170: */
171: public int getHeightSizeOption() {
172: return _heightSizeOption;
173: }
174:
175: /**
176: * This method returns the width of the frame.
177: */
178: public int getWidth() {
179: return _width;
180: }
181:
182: /**
183: * This method returns the size option for the width of the iframe. Valid return values are SIZE_PIXELS or SIZE_PERCENT.
184: */
185: public int getWidthSizeOption() {
186: return _widthSizeOption;
187: }
188:
189: public boolean processParms(Hashtable parms, int rowNo)
190: throws Exception {
191:
192: if (getPage().getUseIFrames()
193: && getPage().getSubPageName() != getFullName())
194: return false;
195:
196: return super .processParms(parms, rowNo);
197: }
198:
199: /**
200: * Sets the border width for the table.
201: */
202: public void setBorder(int border) {
203: _border = border;
204: }
205:
206: /**
207: * This method sets the component that will appear within the frame.
208: */
209: public void setFrameComponent(HtmlComponent comp) {
210: if (_componentsVec == null) {
211: _componentsVec = new Vector();
212: } else {
213: _componentsVec.removeAllElements();
214: }
215:
216: getPage().registerSubPage(getName() + "FrameComponent", comp);
217: _componentsVec.addElement(comp);
218: comp.setParent(this );
219: }
220:
221: /**
222: * This method sets the minimum height of the frame.
223: */
224: public void setHeight(int height) {
225: _height = height;
226: }
227:
228: /**
229: * This method sets the size option for the height of the iframe. Valid values are SIZE_PIXELS or SIZE_PERCENT.
230: */
231: public void setHeightSizeOption(int option) {
232: _heightSizeOption = option;
233: }
234:
235: /**
236: * This method sets the width of the frame in either pixels or percent depending on size option.
237: */
238: public void setWidth(int width) {
239: _width = width;
240: }
241:
242: /**
243: * This method sets the size option for the width of the iframe. Valid values are SIZE_PIXELS or SIZE_PERCENT.
244: */
245: public void setWidthSizeOption(int option) {
246: _widthSizeOption = option;
247: }
248:
249: /**
250: * @returns the source of the content of the inline frame
251: */
252: public String getSrc() {
253: return _src;
254: }
255:
256: /**
257: * Sets the source URL for the inline frame
258: */
259: public void setSrc(String string) {
260: _src = string;
261: }
262:
263: }
|