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/HtmlFrameset.java $
024: //$Author: Srufle $
025: //$Revision: 14 $
026: //$Modtime: 4/15/03 2:24p $
027: /////////////////////////
028:
029: import java.util.Vector;
030:
031: import com.salmonllc.html.events.FramesetListener;
032: import com.salmonllc.html.events.PageEvent;
033:
034: /**
035: * This class implements an Html Frameset. A frameset divides the browser screen into multiple regions. Each region contains a frame.
036: * @see HtmlFrame
037: */
038: public abstract class HtmlFrameset extends HtmlPageBase {
039: public static final int TYPE_VERTICAL = 0;
040: public static final int TYPE_HORIZONTAL = 1;
041:
042: private int _type = TYPE_VERTICAL;
043: private int _borderWidth = 3;
044: private String _borderColor = "";
045: private boolean _border = true;
046:
047: private Vector _frames = new Vector();
048: private Vector _listeners;
049:
050: private String _title;
051:
052: /**
053: * This method adds a new frame to the frameset
054: * @param f The frame to add.
055: */
056: public void addFrame(HtmlFrame f) {
057: _frames.addElement(f);
058: }
059:
060: /**
061: * Adds a new listerner to this page to handle custom page events.
062: */
063: public void addFramesetListener(FramesetListener p) {
064: if (_listeners == null)
065: _listeners = new Vector();
066:
067: for (int i = 0; i < _listeners.size(); i++) {
068: if (((FramesetListener) _listeners.elementAt(i)) == p)
069: return;
070: }
071:
072: _listeners.addElement(p);
073: }
074:
075: public void generateHTML(java.io.PrintWriter p) throws Exception {
076: notifyListeners();
077:
078: String title = _title;
079: if (title == null)
080: title = getApplicationName() + "_" + getPageName();
081:
082: p.println("<HTML><HEAD><TITLE>" + title + "</TITLE>");
083: p.println("<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">");
084: p
085: .println("<META HTTP-EQUIV=\"Cache-Control\" CONTENT=\"no-cache\">");
086: p.println("</HEAD>");
087: String frame = "<FRAMESET ";
088: if (_type == TYPE_VERTICAL)
089: frame += " ROWS=\"";
090: else
091: frame += " COLS=\"";
092:
093: for (int i = 0; i < _frames.size(); i++) {
094: HtmlFrame f = (HtmlFrame) _frames.elementAt(i);
095: if (i > 0)
096: frame += ",";
097:
098: if (f.getSize() <= 0)
099: frame += "*";
100: else {
101: frame += f.getSize();
102: if (f.getSizeMethod() == HtmlFrame.SIZE_PERCENT)
103: frame += "%";
104: }
105: }
106:
107: frame += "\"";
108:
109: if (getBorderColor() != null)
110: if (!getBorderColor().equals(""))
111: frame += " BORDERCOLOR=\"" + getBorderColor() + "\"";
112:
113: if (getBorder()) {
114: frame += " FRAMEBORDER=\"YES\"";
115: frame += " FRAMESPACING=\"" + getBorderWidth() + "\"";
116: if (getBorderWidth() >= 0)
117: frame += " BORDER=\"" + getBorderWidth() + "\"";
118: } else
119: frame += " FRAMEBORDER=\"NO\"";
120:
121: frame += ">";
122:
123: p.println(frame);
124:
125: for (int i = 0; i < _frames.size(); i++) {
126: frame = " <FRAME";
127: HtmlFrame f = (HtmlFrame) _frames.elementAt(i);
128: frame += " NAME=\"" + f.getName() + "\"";
129: frame += " SRC=\"" + f.getURL() + "\"";
130: if (!f.getResize())
131: frame += " NORESIZE";
132:
133: if (f.getScrollBars() == HtmlFrame.SCROLLBARS_NO)
134: frame += " SCROLLING=\"NO\"";
135: else if (f.getScrollBars() == HtmlFrame.SCROLLBARS_YES)
136: frame += " SCROLLING=\"YES\"";
137: else
138: frame += " SCROLLING=\"AUTO\"";
139: frame += ">";
140: p.println(frame);
141: }
142:
143: p.println("</FRAMESET>");
144: p.println("</HTML>");
145:
146: }
147:
148: /**
149: * This method gets whether or not the frames have borders
150: */
151: public boolean getBorder() {
152: return _border;
153: }
154:
155: /**
156: * This method gets the color of the frame borders.
157: */
158: public String getBorderColor() {
159: return _borderColor;
160: }
161:
162: /**
163: * This method gets the width of the frame borders in pixels..
164: */
165: public int getBorderWidth() {
166: return _borderWidth;
167: }
168:
169: /**
170: * This method gets the title of the page displayed in the browser.
171: */
172: public String getTitle() {
173: return _title;
174: }
175:
176: /**
177: * This method gets the type of frameset. Valid values are TYPE_VERTICAL and TYPE_HORIZONTAL
178: */
179: public int getType() {
180: return _type;
181: }
182:
183: /**
184: * This method should be overridden in subclasses of this class. Use this method to set the initial properties for the frameset.
185: */
186: public abstract void initialize();
187:
188: private boolean notifyListeners() throws Exception {
189: if (_listeners == null)
190: return true;
191:
192: PageEvent p = new PageEvent(this );
193:
194: for (int i = 0; i < _listeners.size(); i++) {
195: ((FramesetListener) _listeners.elementAt(i))
196: .pageRequested(p);
197: if (!p.getContinueProcessing())
198: return false;
199: }
200:
201: return true;
202: }
203:
204: public void processParms(java.io.PrintWriter p, boolean iFrame) {
205: }
206:
207: /**
208: * This method removes a listener from the list of listeners that will be notified when a page event is fired.
209: */
210: public void removeFramesetListener(FramesetListener p) {
211: if (_listeners == null)
212: return;
213:
214: for (int i = 0; i < _listeners.size(); i++) {
215: if (((FramesetListener) _listeners.elementAt(i)) == p) {
216: _listeners.removeElementAt(i);
217: return;
218: }
219: }
220: }
221:
222: /**
223: * This method sets whether or not the frames have borders
224: */
225: public void setBorder(boolean border) {
226: _border = border;
227: }
228:
229: /**
230: * This method sets the color of the frame borders.
231: */
232: public void setBorderColor(String borderColor) {
233: _borderColor = borderColor;
234: }
235:
236: /**
237: * This method sets the width of the frame borders in pixels..
238: */
239: public void setBorderWidth(int width) {
240: _borderWidth = width;
241: }
242:
243: /**
244: * This method sets the title of the page displayed in the browser.
245: */
246: public void setTitle(String title) {
247: _title = title;
248: }
249:
250: /**
251: * This method sets the type of frameset. Valid values are TYPE_VERTICAL and TYPE_HORIZONTAL
252: */
253: public void setType(int type) {
254: _type = type;
255: }
256: }
|