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.common.web.template.PageSetupContext;
017: import org.jfolder.common.web.template.SubmitActionContext;
018: import org.jfolder.console.base.BaseSubConsolePageContext;
019: import org.jfolder.console.base.ConsolePageContext;
020: import org.jfolder.console.base.ConsolePageSession;
021:
022: //other classes
023:
024: public abstract class BaseSubPaneConsolePageContext extends
025: BaseSubConsolePageContext {
026:
027: //
028: private final static int BAR_HEIGHT = 20;
029:
030: //
031: private int columnCount = 0;
032: private int upHeight = 0;
033: private int downHeight = 0;
034: //
035: private int barHeight = 0;
036: private int barColumnWidth = 0;
037: private String barIconUrls[] = null;
038: private String barIconLabels[] = null;
039: private SubmitActionContext barSac[] = null;
040: //
041: private String label = null;
042:
043: protected BaseSubPaneConsolePageContext(ConsolePageContext inCpc,
044: String inName, int inColumnCount, int inHeight,
045: int inBarHeight, int inBarColumnWidth,
046: String inBarIconUrls[], String inBarIconLabels[],
047: SubmitActionContext inBarSac[], String inLabel) {
048:
049: //
050: super (inCpc, inName);
051: setColumnWidth(inCpc.getColumnWidth());
052:
053: //
054: this .columnCount = inColumnCount;
055: this .upHeight = BAR_HEIGHT;
056: this .downHeight = inHeight - BAR_HEIGHT;
057: //
058: //this.barHeight = inBarHeight;
059: //this.barColumnWidth = inBarColumnWidth;
060: this .barHeight = BAR_HEIGHT - 2;
061: this .barColumnWidth = BAR_HEIGHT - 2;
062: //
063: this .barIconUrls = inBarIconUrls;
064: this .barIconLabels = inBarIconLabels;
065: this .barSac = inBarSac;
066: //
067: //
068: this .barIconUrls = reverse(inBarIconUrls);
069: this .barIconLabels = reverse(inBarIconLabels);
070: this .barSac = reverse(inBarSac);
071: //
072: //
073: this .label = inLabel;
074: }
075:
076: private final static String[] reverse(String inList[]) {
077:
078: String outValue[] = new String[inList.length];
079:
080: int midPoint = (inList.length / 2);
081: for (int i = 0; i < midPoint; i++) {
082: String inValue1 = inList[i];
083: String inValue2 = inList[inList.length - 1 - i];
084: //
085: outValue[i] = inValue2;
086: outValue[inList.length - 1 - i] = inValue1;
087: }
088:
089: if (((inList.length) % 2) == 1) {
090: outValue[midPoint] = inList[midPoint];
091: }
092:
093: return outValue;
094: }
095:
096: private final static SubmitActionContext[] reverse(
097: SubmitActionContext inList[]) {
098:
099: SubmitActionContext outValue[] = new SubmitActionContext[inList.length];
100:
101: int midPoint = (inList.length / 2);
102: for (int i = 0; i < midPoint; i++) {
103: SubmitActionContext inValue1 = inList[i];
104: SubmitActionContext inValue2 = inList[inList.length - 1 - i];
105: //
106: outValue[i] = inValue2;
107: outValue[inList.length - 1 - i] = inValue1;
108: }
109:
110: if (((inList.length) % 2) == 1) {
111: outValue[midPoint] = inList[midPoint];
112: }
113:
114: return outValue;
115: }
116:
117: //
118: protected void getUpContent() throws IOException {
119:
120: int localBarHeight = this .barHeight;
121: int localTotalBarWidth = this .columnCount * (getColumnWidth())
122: - 2;
123: int localRightBarWidth = (this .barColumnWidth)
124: * (this .barSac.length);
125: int localLeftBarWidth = localTotalBarWidth - localRightBarWidth;
126:
127: printAndIndent("<table cellspacing=\"0\""
128: + " align=\"center\" width=\"" + localTotalBarWidth
129: + "\" height=\"" + localBarHeight
130: + "\" style=\"margin: 0\">");
131: printAndIndent("<tr style=\"margin: 0\">");
132: simpleAndPrint("<td align=\"left\" height=\"" + localBarHeight
133: + "\" width=\"" + localRightBarWidth
134: + "\" style=\"font-family: Arial; color: #333333;"
135: + " font-size: 8pt; margin: 0; padding: 0;\"" + "><b>"
136: + padNbsp(1) + this .label + "</b></td>");
137: printAndIndent("<td align=\"right\" height=\"" + localBarHeight
138: + "\" width=\"" + localLeftBarWidth + "\" style=\""
139: + " padding: 0;" + "\">");
140: BaseSubPaneBarConsolePageContext.newInstance(this ,
141: this .barHeight, this .barColumnWidth, this .barIconUrls,
142: this .barIconLabels, this .barSac);
143: revertAndPrint("</td>");
144: revertAndPrint("</tr>");
145: revertAndPrint("</table>");
146: }
147:
148: public void renderUpSection() throws IOException {
149: HashMap divStyles = new HashMap();
150: divStyles.put("overflow", "visible");
151: divStyles.put("width", "" + this .columnCount
152: * (getColumnWidth()));
153: //
154: divStyles.put("height", "" + this .upHeight);
155: divStyles.put("border-width", "" + 1);
156: divStyles.put("border-color", "#333333");
157: divStyles.put("border-style", "solid");
158: divStyles.put("background-color", "#EEEEEE");
159: //
160: HashMap divAttrs = new HashMap();
161: divAttrs.put("style", XMLHelper.fromStylesToAttr(divStyles));
162: //
163: printAndIndent("<div " + XMLHelper.convertAttrs(divAttrs) + ">");
164: //
165: getUpContent();
166: //
167: revertAndPrint("</div>");
168: }
169:
170: //
171: protected abstract boolean isDownContentIdUsed();
172:
173: protected abstract String getDownContentId();
174:
175: //
176: protected abstract boolean isDownShiftToHighlightHandleUsed();
177:
178: protected abstract String getDownShiftToHighlightHandle();
179:
180: //
181: protected abstract void getDownContent() throws IOException;
182:
183: //
184: public void renderDownSection() throws IOException {
185: HashMap divStyles = new HashMap();
186: divStyles.put("overflow", "scroll");
187: divStyles.put("width", "" + this .columnCount
188: * (getColumnWidth()));
189: //
190: divStyles.put("height", "" + this .downHeight);
191: divStyles.put("border-width", "" + 1);
192: divStyles.put("border-color", "#333333");
193: divStyles.put("border-style", "solid");
194: //
195: HashMap divAttrs = new HashMap();
196: divAttrs.put("style", XMLHelper.fromStylesToAttr(divStyles));
197: divAttrs.put("nowrap", "true");
198: //
199: if (!isMetaMode()) {
200: divAttrs.put("id", getDownContentId());
201: }
202: //
203: printAndIndent("<div " + XMLHelper.convertAttrs(divAttrs) + ">");
204: //
205: getDownContent();
206: //
207: //
208: if (isMetaMode()) {
209: //
210: ConsolePageSession localCps = getConsolePageSession();
211: PageSetupContext localPsc = localCps.getPageSetupContext();
212: //
213: if (isDownContentIdUsed()) {
214: localPsc
215: .addCurrentSubSectionPosition(getDownContentId());
216: } else if (isDownShiftToHighlightHandleUsed()) {
217: localPsc.addShiftSubSectionToHighlightHandle(
218: getDownContentId(),
219: getDownShiftToHighlightHandle());
220: } else {
221: //do nothing
222: }
223: }
224: //
225: revertAndPrint("</div>");
226: }
227:
228: protected void renderConsolePage() throws IOException {
229:
230: //
231: startTable(this .columnCount);
232: //
233: startRow();
234: startCell(this .columnCount);
235: renderUpSection();
236: endCell();
237: endRow();
238: startRow();
239: startCell(this .columnCount);
240: renderDownSection();
241: endCell();
242: endRow();
243: //
244: endTable();
245: //
246: }
247: }
|