01: //** Copyright Statement ***************************************************
02: //The Salmon Open Framework for Internet Applications (SOFIA)
03: // Copyright (C) 1999 - 2002, Salmon LLC
04: //
05: // This program is free software; you can redistribute it and/or
06: // modify it under the terms of the GNU General Public License version 2
07: // as published by the Free Software Foundation;
08: //
09: // This program is distributed in the hope that it will be useful,
10: // but WITHOUT ANY WARRANTY; without even the implied warranty of
11: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: // GNU General Public License for more details.
13: //
14: // You should have received a copy of the GNU General Public License
15: // along with this program; if not, write to the Free Software
16: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17: //
18: // For more information please visit http://www.salmonllc.com
19: //** End Copyright Statement ***************************************************
20: package com.salmonllc.html;
21:
22: /////////////////////////
23: //$Archive: /JADE/SourceCode/com/salmonllc/html/HtmlStyle.java $
24: //$Author: Dan $
25: //$Revision: 11 $
26: //$Modtime: 10/30/02 2:58p $
27: /////////////////////////
28:
29: /**
30: * This type can be used to add a CSS style to an HTML page
31: */
32: public class HtmlStyle extends HtmlComponent {
33: String _type;
34: String _style;
35: String _stylename;
36: public final static String ANCHOR_TYPE = "A";
37: public final static String TEXT_TYPE = "";
38: public final static String LAYER_TYPE = "#";
39: public final static String TABLE_CELL_TYPE = "TD";
40:
41: /**
42: * Constructs a new style to place in the page.
43: * @param name of style to create.
44: * @param type of style to create. e.g. A, H1, TD etc.
45: * @param style this is the style attribute String. e.g. COLOR: #000000; BACKGROUND: #ffffff; ...
46: */
47: public HtmlStyle(String name, String type, String style, HtmlPage p) {
48: super (name, p);
49: _type = type;
50: _style = style;
51: _stylename = name;
52: }
53:
54: public void generateHTML(java.io.PrintWriter p, int rowNo) {
55: if (!getVisible())
56: return;
57:
58: if (_style == null || _style.trim().equals(""))
59: return;
60:
61: p.println("<STYLE>");
62: String sStart = ".";
63: if (_type != null && !_type.trim().equals("")) {
64: p.print(_type);
65: if (_type.equals("#"))
66: sStart = "";
67: }
68: if (_name != null && !_name.trim().equals(""))
69: p.println(sStart + _stylename);
70:
71: p.println("{");
72: p.println(_style);
73: p.println("}");
74: p.println("</STYLE>");
75: }
76:
77: /**
78: * This method returns the style in the component.
79: */
80: public String getStyle() {
81: return _style;
82: }
83:
84: /**
85: * This method returns the name of the style
86: */
87: public String getStyleName() {
88: return _stylename;
89: }
90:
91: /**
92: * This method sets the stylet that the componnt will generate.
93: */
94: public void setStyle(String style) {
95: _style = style;
96: }
97: }
|