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.gui;
021:
022: /////////////////////////
023: //$Archive: /SOFIA/SourceCode/com/salmonllc/gui/Banner.java $
024: //$Author: Srufle $
025: //$Revision: 7 $
026: //$Modtime: 4/15/03 2:24p $
027: /////////////////////////
028:
029: import java.util.Vector;
030:
031: import com.salmonllc.html.*;
032: import com.salmonllc.util.TwoObjectContainer;
033:
034: /**
035: * Create banner of the following form <br>
036: *<br>
037: *<table border="0" cellspacing="0" cellpadding="0" width="100%">
038: * <tr bgcolor="330000"><br>
039: *<td height="52" rowspan="5" width="800"><img src="../../Objectstore/app_name/top_banner.gif" width="800" height="52"></td><br>
040: *<td height="2" width="100%"><img src="../../Objectstore/app_name/spacer.gif" width="12" height="2"></td><br>
041: * </tr><br>
042: * <tr bgcolor="660000"><br>
043: *<td height="21" width="100%"><img src="../../Objectstore/app_name/spacer.gif" width="12" height="21"></td><br>
044: * </tr><br>
045: * <tr bgcolor="330000"><br>
046: *<td width="100%" height="1"><img src="../../Objectstore/app_name/spacer.gif" width="12" height="1"></td><br>
047: * </tr><br>
048: * <tr bgcolor="CC3333"><br>
049: *<td height="1" width="100%"><img src="../../Objectstore/app_name/spacer.gif" width="12" height="1"></td><br>
050: * </tr><br>
051: * <tr bgcolor="990000"><br>
052: *<td height="27" width="100%"><img src="../../Objectstore/app_name/spacer.gif" width="12" height="27"></td><br>
053: * </tr><br>
054: *</table><br>
055: */
056:
057: public class Banner extends HtmlContainer {
058: private HtmlTable _imageTable;
059: //
060: private HtmlImage _bannerImage;
061: private String _bannerImageURL;
062: private int _bannerWidth;
063: private int _bannerHeight;
064: //
065: private String _spacerImageURL;
066: //
067: private Vector _rows = new Vector();
068:
069: /**
070: * Banner constructor
071: * @param name java.lang.String
072: * @param p com.salmonllc.html.HtmlPage
073: * @param spacerImageURL java.lang.String URL of image to use as a spacer.
074: */
075: public Banner(String name, HtmlPage p, String spacerImageURL) {
076: super (name, p);
077: _spacerImageURL = spacerImageURL;
078: //
079: _imageTable = new HtmlTable("_imageTable", p);
080: _imageTable.setCellPadding(0);
081: _imageTable.setCellSpacing(0);
082: _imageTable.setSizeOption(HtmlTable.SIZE_PERCENT);
083: _imageTable.setWidth(100);
084: _imageTable.setAllowNullCells(false);
085: add(_imageTable);
086: }
087:
088: /**
089: * This methos sets the color and height of the right side rows.
090: * @param color java.lang.String
091: * @param height int
092: */
093: public void addRowInfo(String color, int height) {
094: TwoObjectContainer cont = new TwoObjectContainer(color,
095: new Integer(height));
096: _rows.addElement(cont);
097: }
098:
099: /**
100: * Builds the banner according to the information provided prevoiusly.
101: * This should be the last method called.
102: */
103: public void build() {
104: HtmlTableRowProperties tempRowProp = null;
105: HtmlTableCellProperties tempCellProp = null;
106: HtmlImage spacerImage = null;
107: // row 0 has to be done manually
108: HtmlImage bannerImage = new HtmlImage(_bannerImageURL,
109: getPage());
110: bannerImage.setWidth(_bannerWidth);
111: bannerImage.setHeight(_bannerHeight);
112: _bannerImage = bannerImage;
113: //
114: tempCellProp = new HtmlTableCellProperties();
115: tempCellProp.setRowSpan(_rows.size());
116: tempCellProp.setCellWidth(_bannerWidth, HtmlTable.SIZE_PIXELS);
117: tempCellProp
118: .setCellHeight(_bannerHeight, HtmlTable.SIZE_PIXELS);
119: //
120: tempRowProp = new HtmlTableRowProperties();
121: tempRowProp.setBackgroundColor(getRowColor(0));
122: _imageTable.setRowProperty(0, tempRowProp);
123: _imageTable.setComponentAt(0, 0, bannerImage, tempCellProp);
124: spacerImage = new HtmlImage(_spacerImageURL, getPage());
125: spacerImage.setWidth(10);
126: spacerImage.setHeight(getRowHeight(0));
127: //
128: tempCellProp = new HtmlTableCellProperties();
129: tempCellProp.setCellWidth(100, HtmlTable.SIZE_PERCENT);
130: tempCellProp.setCellHeight(getRowHeight(0),
131: HtmlTable.SIZE_PIXELS);
132: //
133: _imageTable.setComponentAt(0, 1, spacerImage, tempCellProp);
134:
135: //
136: int imageCellHeight = -1;
137: String rowColor = null;
138: // rows 1 to max transitions can be done in the loop
139: // for the number of transitions
140: for (int i = 1; i < _rows.size(); i++) {
141: imageCellHeight = getRowHeight(i);
142: rowColor = getRowColor(i);
143: tempRowProp = new HtmlTableRowProperties();
144: tempRowProp.setBackgroundColor(rowColor);
145: _imageTable.setRowProperty(i, tempRowProp);
146: //
147: spacerImage = new HtmlImage(_spacerImageURL, getPage());
148: spacerImage.setWidth(10);
149: spacerImage.setHeight(imageCellHeight);
150: //
151: tempCellProp = new HtmlTableCellProperties();
152: tempCellProp.setCellWidth(100, HtmlTable.SIZE_PERCENT);
153: tempCellProp.setCellHeight(imageCellHeight,
154: HtmlTable.SIZE_PIXELS);
155: //
156: _imageTable.setComponentAt(i, 1, spacerImage, tempCellProp);
157: }
158: }
159:
160: /**
161: * This methos sets the color and height of the right side rows.
162: * @param color java.lang.String
163: * @param height int
164: */
165: public HtmlImage getBannerImage() {
166: return _bannerImage;
167: }
168:
169: /**
170: * This methos sets the color and height of the right side rows.
171: * @param color java.lang.String
172: * @param height int
173: */
174: public String getRowColor(int index) {
175: if (index >= _rows.size()) {
176: return null;
177: }
178: TwoObjectContainer cont = (TwoObjectContainer) _rows
179: .elementAt(index);
180: return (String) cont.getObject1();
181: }
182:
183: /**
184: * This methos sets the color and height of the right side rows.
185: * @param color java.lang.String
186: * @param height int
187: */
188: public int getRowHeight(int index) {
189: if (index >= _rows.size()) {
190: return -1;
191: }
192: TwoObjectContainer cont = (TwoObjectContainer) _rows
193: .elementAt(index);
194: return ((Integer) cont.getObject2()).intValue();
195: }
196:
197: /**
198: * Adds a new html component to the container
199: * @param comp com.salmonllc.html.HtmlComponent
200: */
201: public void setBannerImage(String bannerImageURL, int width,
202: int height) {
203: _bannerImageURL = bannerImageURL;
204: _bannerWidth = width;
205: _bannerHeight = height;
206: }
207:
208: /**
209: * This methos sets the color and height of the right side rows.
210: * @param color java.lang.String
211: * @param height int
212: */
213: public void setRowInfo(String color, int height, int index) {
214: if (index >= _rows.size()) {
215: return;
216: }
217: TwoObjectContainer cont = new TwoObjectContainer(color,
218: new Integer(height));
219: _rows.setElementAt(cont, index);
220: }
221: }
|