001: /*
002: * JFolder, Copyright 2001-2006 Gary Steinmetz
003: *
004: * Distributable under LGPL license.
005: * See terms of license at gnu.org.
006: */
007:
008: package org.jfolder.console.base.context;
009:
010: //base classes
011: import java.io.IOException;
012: import java.util.HashMap;
013:
014: //project specific classes
015: import org.jfolder.common.utils.xml.XMLHelper;
016: import org.jfolder.console.base.BaseSubConsolePageContext;
017: import org.jfolder.console.base.ConsolePageContext;
018:
019: //other classes
020:
021: public abstract class BaseSubBoxConsolePageContext extends
022: BaseSubConsolePageContext {
023:
024: private int columnWidth = 0;
025: private int height = 0;
026: private String sideColor = null;
027: private boolean contentWrap = false;
028: private int padding = 0;
029:
030: protected BaseSubBoxConsolePageContext(String inName,
031: int inColumnWidth, int inHeight, String inSideColor,
032: ConsolePageContext inCpc) {
033:
034: super (inCpc, inName);
035: //
036: this .columnWidth = inColumnWidth;
037: this .height = inHeight;
038: this .sideColor = inSideColor;
039:
040: }
041:
042: protected void setTotalColumnWidth(int inWidth) {
043: this .columnWidth = inWidth;
044: }
045:
046: //
047: protected HashMap getMainTableFormat() {
048: return null;
049: }
050:
051: //
052: protected void renderConsolePage() throws IOException {
053: renderPreContent();
054: //getParentCpc().startTable(this.columnWidth);
055: //getParentCpc().startRow();
056: HashMap divStyles = new HashMap();
057: int columnSpan = (this .columnWidth * getColumnWidth())
058: - this .padding;
059: if (this .contentWrap) {
060: divStyles.put("word-wrap", "break-word");
061: }
062: divStyles.put("overflow", "auto");
063: divStyles.put("text-align", "left");
064: if (this .columnWidth > 0) {
065: divStyles.put("width", "" + columnSpan);
066: }
067: //
068: if (this .height > 0) {
069: divStyles.put("height", "" + this .height + "px");
070: }
071: if (this .sideColor != null) {
072: divStyles.put("border-width", "" + 1);
073: divStyles.put("border-color", this .sideColor);
074: divStyles.put("border-style", "solid");
075: }
076: //
077: HashMap divAttrs = new HashMap();
078: divAttrs.put("style", XMLHelper.fromStylesToAttr(divStyles));
079: //
080: getParentCpc()
081: .startCell(this .columnWidth, getMainTableFormat());
082: getParentCpc().printAndIndent(
083: "<div " + XMLHelper.convertAttrs(divAttrs) + ">");
084: //
085: renderContent();
086: //
087: getParentCpc().revertAndPrint("</div>");
088: getParentCpc().endCell();
089: //getParentCpc().endRow();
090: //getParentCpc().endTable();
091: renderPostContent();
092: }
093:
094: protected void setContentWrap(boolean inContentWrap) {
095: this .contentWrap = inContentWrap;
096: }
097:
098: protected void setPadding(int inPadding) {
099: this .padding = inPadding;
100: }
101:
102: protected void renderPreContent() throws IOException {
103: }
104:
105: protected abstract void renderContent() throws IOException;
106:
107: protected void renderPostContent() throws IOException {
108: }
109: }
|