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: import com.javelin.swinglets.border.*;
014: import com.javelin.swinglets.theme.*;
015:
016: /**
017: * HTMLMatteBorderUI defines a look and feel for default HTML.
018: *
019: * @author Robin Sharp
020: */
021:
022: public class HTMLMatteBorderUI extends HTMLBorderUI {
023: /**
024: * Paint the border header in the specified manner.
025: */
026: public void updateBorderHeader(PrintWriter out, SComponent component) {
027: if (component.getBorder() == null
028: || !(component.getBorder().getBorder() instanceof SMatteBorder)) {
029: return;
030: }
031:
032: SMatteBorder border = (SMatteBorder) component.getBorder()
033: .getBorder();
034:
035: out.print("<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>");
036:
037: //1st row
038: out.print("<TR>");
039: paintCell(out, border.getColor(), border.left, border.top);
040: paintCell(out, border.getColor(), 0, border.top);
041: paintCell(out, border.getColor(), border.right, border.top);
042: out.println("</TR>");
043:
044: //2nd row
045: out.print("<TR>");
046: paintCell(out, border.getColor(), border.left, 0);
047: out.print("<TD");
048:
049: if (border.getBackgroundIcon() != null) {
050: out.print(" BACKGROUND=\""
051: + border.getBackgroundIcon().getUrl() + "\"");
052: } else if (component.getTopLevelAncestor() instanceof SFrame) {
053: //Only set background outside of JSP
054: if (!component.isOpaque()) {
055: } else if (component.getBackground() != null) {
056: out.print(" BGCOLOR=\"#");
057: out
058: .print(SColor.toHexString(component
059: .getBackground()));
060: out.print('"');
061: } else {
062: out.print(" BGCOLOR=\"#");
063: out.print(SColor.toHexString(getTheme()
064: .getWindowBackground()));
065: out.print('"');
066: }
067: }
068:
069: out.print('>');
070:
071: }
072:
073: /**
074: * Paint the border in the specified manner.
075: */
076: public void updateBorder(PrintWriter out, SComponent component) {
077: if (component.getBorder() == null
078: || !(component.getBorder().getBorder() instanceof SMatteBorder)) {
079: return;
080: }
081:
082: //Handle compound borders
083: if (component.getBorder().nextBorder()) {
084: component.getBorder().paint(out, component);
085: } else {
086: component.getUI().update(out, component);
087: }
088: }
089:
090: /**
091: * Paint the border footer in the specified manner.
092: */
093: public void updateBorderFooter(PrintWriter out, SComponent component) {
094: if (component.getBorder() == null
095: || !(component.getBorder().getBorder() instanceof SMatteBorder)) {
096: return;
097: }
098:
099: SMatteBorder border = (SMatteBorder) component.getBorder()
100: .getBorder();
101:
102: SColor color = border.getColor();
103: if (color == null) {
104: color = getTheme().getPrimaryControlShadow();
105: }
106:
107: out.print("</TD>");
108: paintCell(out, color, border.right, 0);
109: out.println("</TR>");
110:
111: //3rd row
112: out.print("<TR>");
113: paintCell(out, color, border.left, border.bottom);
114: paintCell(out, color, 0, border.top);
115: paintCell(out, color, border.right, border.bottom);
116: out.println("</TR></TABLE>");
117:
118: }
119:
120: protected void paintCell(PrintWriter out, SColor color, int width,
121: int height) {
122: out.print("<TD");
123:
124: if (width > 0) {
125: out.print(" WIDTH=\"");
126: out.print(width);
127: out.print("\"");
128: } else if (width < 0) {
129: out.print(" WIDTH=\"");
130: out.print(0 - width);
131: out.print("%\"");
132: }
133:
134: if (height > 0) {
135: out.print(" HEIGHT=\"");
136: out.print(height);
137: out.print("\"");
138: } else if (height < 0) {
139: out.print(" HEIGHT=\"");
140: out.print(0 - height);
141: out.print("%\"");
142: }
143:
144: if (color != null) {
145: out.print(" BGCOLOR=\"#");
146: out.print(SColor.toHexString(color));
147: out.print("\"");
148: }
149: out.print(">");
150:
151: //NS WORK AROUND
152: out
153: .print("<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><TR><TD></TD></TR></TABLE>");
154:
155: out.print("</TD>");
156:
157: }
158:
159: }
|