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: * HTMLGridLayoutUI defines a look and feel for default HTML.
016: * <P>
017: * This will set the alignment according to the components
018: * alignment otherwise LEFT, MIDDLE
019: *
020: * @author Robin Sharp
021: */
022:
023: public class HTMLGridLayoutUI extends HTMLLayoutUI {
024: /**
025: * Lays out the container in the specified manner.
026: */
027: public void layoutContainer(SContainer parent, PrintWriter out) {
028: if (parent.getComponentCount() == 0)
029: return;
030:
031: SGridLayout gridLayout = (SGridLayout) parent
032: .getLayoutManager();
033:
034: int columns = gridLayout.getColumns();
035: int rows = gridLayout.getRows();
036:
037: if (columns == 0 && rows == 0) {
038: columns = 2;
039: rows = (parent.getComponentCount() + 1) / columns;
040: } else if (columns == 0 && rows > 0) {
041: columns = (parent.getComponentCount() + 1) / rows;
042: } else if (columns > 0 && rows == 0) {
043: rows = (parent.getComponentCount() + 1) / columns;
044: }
045:
046: out.print("<TABLE BORDER=0 CELLSPACING=");
047: out.print(gridLayout.getGap());
048: out.print(" CELLPADDING=0");
049:
050: if (parent.getSize() != null) {
051: if (parent.getSize().width > 0) {
052: out.print(" WIDTH=");
053: out.print(parent.getSize().width);
054: }
055:
056: if (parent.getSize().height > 0) {
057: out.print(" HEIGHT=");
058: out.print(parent.getSize().height);
059: }
060: }
061:
062: out.println(" >");
063:
064: int width = 100 / columns;
065: int height = 100 / rows;
066:
067: int count = 0;
068: SComponent component = null;
069: for (int row = 0; count < parent.getComponentCount()
070: && row < rows; row++) {
071: out.print("<TR>");
072:
073: for (int column = 0; count < parent.getComponentCount()
074: && column < columns; column++) {
075: out.print("<TD");
076:
077: HTMLUtility.updateHorizontalAlignment(out, component,
078: SConstants.LEFT);
079:
080: HTMLUtility.updateVerticalAlignment(out, component,
081: SConstants.MIDDLE);
082:
083: component = parent.getComponent(count++);
084: if (component.getBackground() != null) {
085: out.print(" BGCOLOR=\"#"
086: + SColor.toHexString(component
087: .getBackground()) + "\"");
088: } else if (parent.getBackground() != null) {
089: out
090: .print(" BGCOLOR=\"#"
091: + SColor.toHexString(parent
092: .getBackground()) + "\"");
093: }
094:
095: //Proportional width and height
096: out.print(" WIDTH=\"");
097: out.print(width);
098: out.print("%\"");
099:
100: //Proportional width and height
101: out.print(" HEIGHT=\"");
102: out.print(height);
103: out.print("%\"");
104:
105: out.print(" >");
106:
107: component.paint(out);
108:
109: out.print("</TD>");
110: }
111:
112: out.println("</TR>");
113: }
114:
115: out.print("</TABLE>");
116: }
117: }
|