001: /*
002: * Copyright Javelin Software, All rights reserved.
003: */
004:
005: package com.javelin.swinglets.plaf.html;
006:
007: import java.awt.*;
008: import java.util.*;
009: import java.io.*;
010:
011: import com.javelin.swinglets.*;
012: import com.javelin.swinglets.plaf.*;
013:
014: /**
015: * HTMLToolBarUI defines a look and feel for default HTML.
016: *
017: * @author Robin Sharp
018: */
019:
020: public class HTMLToolBarUI extends HTMLContainerUI {
021: public final static String HTML_LINK = "_HTML_LINK";
022:
023: /**
024: * Render the UI on the PrintWriter
025: */
026: public void update(PrintWriter out, SComponent c) {
027: if (!c.isVisible())
028: return;
029:
030: SToolBar toolBar = (SToolBar) c;
031:
032: //COMPONENTS IN TOOLBAR
033: if (toolBar.getToolBarPlacement() == SConstants.TOP
034: || toolBar.getToolBarPlacement() == SConstants.BOTTOM) {
035: out.print("<TABLE BORDER=");
036:
037: if (toolBar.isBorderPainted())
038: out.print("1");
039: else
040: out.print("0");
041:
042: out.print(" CELLSPACING=0 CELLPADDING=");
043:
044: if (toolBar.getMargin() == null)
045: out.print("0");
046: else
047: out.print(toolBar.getMargin().width);
048:
049: if (toolBar.getSize() == null
050: || toolBar.getSize().width == 0) {
051: //AUTO
052: }
053: } else {
054: out.print("<TABLE BORDER=");
055:
056: if (toolBar.isBorderPainted())
057: out.print("1");
058: else
059: out.print("0");
060:
061: out.print(" CELLSPACING=0 CELLPADDING=");
062:
063: if (toolBar.getMargin() == null)
064: out.print("0");
065: else
066: out.print(toolBar.getMargin().height);
067:
068: }
069:
070: if (toolBar.getToolBarPlacement() == SConstants.TOP
071: || toolBar.getToolBarPlacement() == SConstants.BOTTOM) {
072: if (toolBar.getSize() == null
073: || toolBar.getSize().width == 0) {
074: //AUTO
075: } else if (toolBar.getSize().width > 0) {
076: out.print(" WIDTH=\"");
077: out.print(toolBar.getSize().width);
078: out.print("\"");
079: } else if (toolBar.getSize().width < 0) {
080: out.print(" WIDTH=\"");
081: out.print((0 - toolBar.getSize().width));
082: out.print("%\"");
083: }
084: }
085:
086: if (toolBar.getToolBarPlacement() == SConstants.LEFT
087: || toolBar.getToolBarPlacement() == SConstants.RIGHT) {
088: if (toolBar.getSize() == null
089: || toolBar.getSize().width == 0) {
090: //AUTO
091: } else if (toolBar.getSize().height > 0) {
092: out.print(" HEIGHT=\"");
093: out.print(toolBar.getSize().height);
094: out.print("\"");
095: } else if (toolBar.getSize().height < 0) {
096: out.print(" HEIGHT=\"");
097: out.print((0 - toolBar.getSize().height));
098: out.print("%\"");
099: }
100: }
101:
102: if (!toolBar.isOpaque()) {
103: } else if (toolBar.getBackground() != null) {
104: out.print(" BGCOLOR=\"#");
105: out.print(SColor.toHexString(toolBar.getBackground()));
106: out.print("\"");
107: } else {
108: out.print(" BGCOLOR=\"#");
109: out.print(SColor
110: .toHexString(getTheme().getMenuBackground()));
111: out.print("\"");
112: }
113:
114: out.println(" >");
115:
116: //FORM - AS NS only shows buttons in a form
117: //WRITE THE FORM INSIDE THE TABLE
118: out.print("<FORM");
119: out.print(" METHOD=\"GET\" ");
120: HTMLUtility.setName(out, toolBar);
121: out.println(">");
122: //WRITE OUT THE FRAME AND COMPONENT AS HIDDEN FIELDS
123: HTMLUtility.setFrameName(out, toolBar.getTopLevelAncestor());
124: HTMLUtility.setComponentName(out, toolBar);
125:
126: out.println("<TR>");
127:
128: //Paint each item in the tool bar
129: for (int index = 0; index < toolBar.getComponentCount(); index++) {
130: out.print("<TD NOWRAP>");
131:
132: toolBar.getComponent(index).paint(out);
133:
134: out.print("</TD>");
135:
136: if (toolBar.getToolBarPlacement() == SConstants.LEFT
137: || toolBar.getToolBarPlacement() == SConstants.RIGHT) {
138: out.println("</TR><TR>");
139: }
140: }
141:
142: if (toolBar.getToolBarPlacement() == SConstants.TOP
143: || toolBar.getToolBarPlacement() == SConstants.BOTTOM) {
144: //Print padding cell for % widths
145: if (toolBar.getSize() != null
146: && toolBar.getSize().width != 0) {
147: out.println("<TD WIDTH=100%> </TD>");
148: }
149: }
150:
151: out.println("</TR>");
152:
153: if (toolBar.getToolBarPlacement() == SConstants.LEFT
154: || toolBar.getToolBarPlacement() == SConstants.RIGHT) {
155: //Print padding cell for % widths
156: if (toolBar.getSize() != null
157: && toolBar.getSize().height != 0) {
158: out.println("<TR><TD HEIGHT=100%> </TD></TR>");
159: }
160: }
161:
162: out.println("</FORM>");
163: out.println("</TABLE>");
164: }
165: }
|