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:
013: //project specific classes
014: import org.jfolder.common.UnexpectedSystemException;
015: import org.jfolder.console.base.ConsolePageContext;
016: import org.jfolder.console.base.NamesForSubCpc;
017: import org.jfolder.console.base.context.BaseSubLeftRightConsolePageContext;
018: import org.jfolder.console.config.ConsoleConfig;
019: import org.jfolder.console.config.ConsoleConfigTagPreferencesHelper;
020:
021: //other classes
022:
023: public class ConfigInstanceForLeftRightContext extends
024: BaseSubLeftRightConsolePageContext {
025:
026: //
027: private RenderConsolePageContextHelper rctph = null;
028: //
029: private ConsoleConfig cc = null;
030: private int section = 0;
031: private int index = 0;
032:
033: private ConfigInstanceForLeftRightContext(
034: RenderConsolePageContextHelper inRctph,
035: ConsolePageContext inCpc, ConsoleConfig inCc,
036: int inSection, int inIndex) {
037:
038: super (inCpc, getLeftName(inSection, inIndex), getRightName(
039: inSection, inIndex));
040: //
041: this .rctph = inRctph;
042: //
043: this .cc = inCc;
044: this .section = inSection;
045: this .index = inIndex;
046: //
047: setColumnWidth(1);
048: }
049:
050: protected final static ConfigInstanceForLeftRightContext newInstance(
051: RenderConsolePageContextHelper inRctph,
052: ConsolePageContext inCpc, ConsoleConfig inCc,
053: int inSection, int inIndex) throws IOException {
054:
055: ConfigInstanceForLeftRightContext outValue = null;
056:
057: if (inCpc.isSubConsolePageContextPresent(NamesForSubCpc
058: .getBaseSubLeftRightCpcName(getLeftName(inSection,
059: inIndex), getRightName(inSection, inIndex)))) {
060: //
061: Object o = inCpc
062: .getSubConsolePageContext(NamesForSubCpc
063: .getBaseSubLeftRightCpcName(getLeftName(
064: inSection, inIndex), getRightName(
065: inSection, inIndex)));
066: outValue = (ConfigInstanceForLeftRightContext) o;
067: } else {
068: outValue = new ConfigInstanceForLeftRightContext(inRctph,
069: inCpc, inCc, inSection, inIndex);
070: inCpc
071: .registerSubConsolePageContext(NamesForSubCpc
072: .getBaseSubLeftRightCpcName(getLeftName(
073: inSection, inIndex), getRightName(
074: inSection, inIndex)), outValue);
075: }
076:
077: outValue.copyFromParent(inCpc);
078: outValue.createConsolePage(inCpc.getWriter(), inCpc
079: .getPageSetupContext());
080:
081: return outValue;
082: }
083:
084: //
085: public int getLeftWidth() {
086:
087: int outValue = 0;
088:
089: if (this .section == RenderConsolePageContextHelper.AREA__TOP) {
090: //
091: int totalWidth = Integer
092: .parseInt(this .cc
093: .getMainProperty(ConsoleConfigTagPreferencesHelper.PROP_NAME__WIDTH));
094: //
095: boolean leftSecInUse = (this .cc.getLeftSectionPaneCount() > 0);
096: boolean centerSecInUse = (this .cc
097: .getCenterSectionPaneCount() > 0);
098: boolean rightSecInUse = (this .cc.getRightSectionPaneCount() > 0);
099: //
100: if (this .index == 0) {
101: if (leftSecInUse && centerSecInUse && rightSecInUse) {
102: int leftSectionWidth = getCumulitiveLeftSectionWidth(
103: this .cc.getLeftSectionPaneCount(), this .cc);
104: //
105: outValue = leftSectionWidth;
106: } else if (!leftSecInUse && centerSecInUse
107: && rightSecInUse) {
108: int centerSectionWidth = Integer
109: .parseInt(this .cc
110: .getCenterSectionPaneProperty(
111: 0,
112: ConsoleConfigTagPreferencesHelper.PROP_NAME__WIDTH));
113: //
114: outValue = centerSectionWidth;
115: } else if (leftSecInUse && !centerSecInUse
116: && rightSecInUse) {
117: int leftSectionWidth = getCumulitiveLeftSectionWidth(
118: this .cc.getLeftSectionPaneCount(), this .cc);
119: //
120: outValue = leftSectionWidth;
121: } else if (leftSecInUse && centerSecInUse
122: && !rightSecInUse) {
123: int leftSectionWidth = getCumulitiveLeftSectionWidth(
124: this .cc.getLeftSectionPaneCount(), this .cc);
125: //
126: outValue = leftSectionWidth;
127: } else {
128: throw UnexpectedSystemException.unknownState();
129: }
130: } else if (this .index == 1) {
131: if (leftSecInUse && centerSecInUse && rightSecInUse) {
132: int centerSectionWidth = Integer
133: .parseInt(this .cc
134: .getCenterSectionPaneProperty(
135: 0,
136: ConsoleConfigTagPreferencesHelper.PROP_NAME__WIDTH));
137: //
138: outValue = centerSectionWidth;
139: } else {
140: throw UnexpectedSystemException.unknownState();
141: }
142: } else {
143: throw UnexpectedSystemException.unknownState();
144: }
145: } else if (this .section == RenderConsolePageContextHelper.AREA__LEFT) {
146: //
147: outValue = Integer
148: .parseInt(this .cc
149: .getLeftSectionPaneProperty(
150: this .index,
151: ConsoleConfigTagPreferencesHelper.PROP_NAME__WIDTH));
152: } else if (this .section == RenderConsolePageContextHelper.AREA__RIGHT) {
153: //
154: outValue = Integer
155: .parseInt(this .cc
156: .getRightSectionPaneProperty(
157: this .index,
158: ConsoleConfigTagPreferencesHelper.PROP_NAME__WIDTH));
159: } else {
160: throw UnexpectedSystemException.unknownState();
161: }
162:
163: outValue = (outValue / getColumnWidth());
164:
165: return outValue;
166: }
167:
168: public void renderLeftPane() throws IOException {
169: //
170: //
171: //
172: if (this .section == RenderConsolePageContextHelper.AREA__TOP) {
173: //
174: //
175: boolean leftSecInUse = (this .cc.getLeftSectionPaneCount() > 0);
176: boolean centerSecInUse = (this .cc
177: .getCenterSectionPaneCount() > 0);
178: boolean rightSecInUse = (this .cc.getRightSectionPaneCount() > 0);
179: //
180: if (this .index == 0) {
181: if (leftSecInUse && centerSecInUse && rightSecInUse) {
182: //
183: if (this .cc.getLeftSectionPaneCount() > 1) {
184: ConfigInstanceForLeftRightContext
185: .newInstance(
186: this .rctph,
187: this ,
188: this .cc,
189: RenderConsolePageContextHelper.AREA__LEFT,
190: RenderConsolePageContextHelper.FIRST_INDEX);
191: } else {
192: this .rctph
193: .renderSubPane(
194: this ,
195: this .cc
196: .getLeftSectionPaneContext(0),
197: this .cc,
198: RenderConsolePageContextHelper.AREA__LEFT,
199: RenderConsolePageContextHelper.FIRST_INDEX);
200: }
201: } else if (!leftSecInUse && centerSecInUse
202: && rightSecInUse) {
203: //
204: //
205: if (this .cc.getCenterSectionPaneCount() > 1) {
206: ConfigInstanceForUpDownContext
207: .newInstance(
208: this .rctph,
209: this ,
210: this .cc,
211: RenderConsolePageContextHelper.AREA__CENTER,
212: RenderConsolePageContextHelper.FIRST_INDEX);
213: } else {
214: this .rctph
215: .renderSubPane(
216: this ,
217: this .cc
218: .getCenterSectionPaneContext(0),
219: this .cc,
220: RenderConsolePageContextHelper.AREA__CENTER,
221: RenderConsolePageContextHelper.FIRST_INDEX);
222: }
223: } else if (leftSecInUse && !centerSecInUse
224: && rightSecInUse) {
225: //
226: //
227: if (this .cc.getLeftSectionPaneCount() > 1) {
228: ConfigInstanceForLeftRightContext
229: .newInstance(
230: this .rctph,
231: this ,
232: this .cc,
233: RenderConsolePageContextHelper.AREA__LEFT,
234: RenderConsolePageContextHelper.FIRST_INDEX);
235: } else {
236: this .rctph
237: .renderSubPane(
238: this ,
239: this .cc
240: .getLeftSectionPaneContext(0),
241: this .cc,
242: RenderConsolePageContextHelper.AREA__LEFT,
243: RenderConsolePageContextHelper.FIRST_INDEX);
244: }
245: } else if (leftSecInUse && centerSecInUse
246: && !rightSecInUse) {
247: //
248: //
249: if (this .cc.getLeftSectionPaneCount() > 1) {
250: ConfigInstanceForLeftRightContext
251: .newInstance(
252: this .rctph,
253: this ,
254: this .cc,
255: RenderConsolePageContextHelper.AREA__LEFT,
256: RenderConsolePageContextHelper.FIRST_INDEX);
257: } else {
258: this .rctph
259: .renderSubPane(
260: this ,
261: this .cc
262: .getLeftSectionPaneContext(0),
263: this .cc,
264: RenderConsolePageContextHelper.AREA__LEFT,
265: RenderConsolePageContextHelper.FIRST_INDEX);
266: }
267: } else {
268: throw UnexpectedSystemException.unknownState();
269: }
270: } else if (this .index == 1) {
271: if (leftSecInUse && centerSecInUse && rightSecInUse) {
272: //
273: //
274: if (this .cc.getCenterSectionPaneCount() > 1) {
275: ConfigInstanceForUpDownContext
276: .newInstance(
277: this .rctph,
278: this ,
279: this .cc,
280: RenderConsolePageContextHelper.AREA__CENTER,
281: RenderConsolePageContextHelper.FIRST_INDEX);
282: } else {
283: this .rctph
284: .renderSubPane(
285: this ,
286: this .cc
287: .getCenterSectionPaneContext(0),
288: this .cc,
289: RenderConsolePageContextHelper.AREA__CENTER,
290: RenderConsolePageContextHelper.FIRST_INDEX);
291: }
292: } else {
293: throw UnexpectedSystemException.unknownState();
294: }
295: } else {
296: throw UnexpectedSystemException.unknownState();
297: }
298: } else if (this .section == RenderConsolePageContextHelper.AREA__LEFT) {
299: //
300: String context = this .cc
301: .getLeftSectionPaneContext(this .index);
302: this .rctph.renderSubPane(this , context, this .cc,
303: this .section, this .index);
304: //throw UnexpectedSystemException.notImplemented();
305: } else if (this .section == RenderConsolePageContextHelper.AREA__RIGHT) {
306: //
307: String context = this .cc
308: .getRightSectionPaneContext(this .index);
309: this .rctph.renderSubPane(this , context, this .cc,
310: this .section, this .index);
311: //throw UnexpectedSystemException.notImplemented();
312: } else {
313: throw UnexpectedSystemException.unknownState();
314: }
315: }
316:
317: //
318: public int getRightWidth() {
319:
320: int outValue = 0;
321:
322: if (this .section == RenderConsolePageContextHelper.AREA__TOP) {
323: //
324: int totalWidth = Integer
325: .parseInt(this .cc
326: .getMainProperty(ConsoleConfigTagPreferencesHelper.PROP_NAME__WIDTH));
327: //
328: boolean leftSecInUse = (this .cc.getLeftSectionPaneCount() > 0);
329: boolean centerSecInUse = (this .cc
330: .getCenterSectionPaneCount() > 0);
331: boolean rightSecInUse = (this .cc.getRightSectionPaneCount() > 0);
332: //
333: if (this .index == 0) {
334: outValue = totalWidth - getLeftWidth();
335: } else if (this .index == 1) {
336: if (leftSecInUse && centerSecInUse && rightSecInUse) {
337: //
338: int rightSectionWidth = getCumulitiveRightSectionWidth(
339: this .cc.getRightSectionPaneCount(), this .cc);
340: //
341: outValue = rightSectionWidth;
342: } else {
343: throw UnexpectedSystemException.unknownState();
344: }
345: } else {
346: throw UnexpectedSystemException.unknownState();
347: }
348: } else if (this .section == RenderConsolePageContextHelper.AREA__LEFT) {
349: //
350: int leftSectionWidth = getCumulitiveLeftSectionWidth(
351: this .cc.getLeftSectionPaneCount(), this .cc);
352: //
353: int leftSectionDeltaWidth = getCumulitiveLeftSectionWidth(
354: (this .index + 1), this .cc);
355: //
356: outValue = leftSectionWidth - leftSectionDeltaWidth;
357: } else if (this .section == RenderConsolePageContextHelper.AREA__RIGHT) {
358: //
359: int rightSectionWidth = getCumulitiveRightSectionWidth(
360: this .cc.getRightSectionPaneCount(), this .cc);
361: //
362: int rightSectionDeltaWidth = getCumulitiveRightSectionWidth(
363: (this .index + 1), this .cc);
364: //
365: outValue = rightSectionWidth - rightSectionDeltaWidth;
366: } else {
367: throw UnexpectedSystemException.unknownState();
368: }
369:
370: outValue = (outValue / getColumnWidth());
371:
372: return outValue;
373: }
374:
375: public void renderRightPane() throws IOException {
376: //
377: //
378: //
379: if (this .section == RenderConsolePageContextHelper.AREA__TOP) {
380: //
381: //
382: boolean leftSecInUse = (this .cc.getLeftSectionPaneCount() > 0);
383: boolean centerSecInUse = (this .cc
384: .getCenterSectionPaneCount() > 0);
385: boolean rightSecInUse = (this .cc.getRightSectionPaneCount() > 0);
386: //
387: if (this .index == 0) {
388: if (leftSecInUse && centerSecInUse && rightSecInUse) {
389: //
390: ConfigInstanceForLeftRightContext.newInstance(
391: this .rctph, this , this .cc,
392: RenderConsolePageContextHelper.AREA__TOP,
393: (this .index + 1));
394: } else if (!leftSecInUse && centerSecInUse
395: && rightSecInUse) {
396: //
397: //
398: //ConfigInstanceForLeftRightContext.newInstance(
399: // this.rctph, this, this.cc,
400: // RenderConsolePageContextHelper.AREA__RIGHT,
401: // RenderConsolePageContextHelper.FIRST_INDEX);
402: if (this .cc.getLeftSectionPaneCount() > 1) {
403: ConfigInstanceForLeftRightContext
404: .newInstance(
405: this .rctph,
406: this ,
407: this .cc,
408: RenderConsolePageContextHelper.AREA__RIGHT,
409: RenderConsolePageContextHelper.FIRST_INDEX);
410: } else {
411: this .rctph
412: .renderSubPane(
413: this ,
414: this .cc
415: .getRightSectionPaneContext(0),
416: this .cc,
417: RenderConsolePageContextHelper.AREA__RIGHT,
418: RenderConsolePageContextHelper.FIRST_INDEX);
419: }
420: } else if (leftSecInUse && !centerSecInUse
421: && rightSecInUse) {
422: //
423: //
424: //ConfigInstanceForLeftRightContext.newInstance(
425: // this.rctph, this, this.cc,
426: // RenderConsolePageContextHelper.AREA__RIGHT,
427: // RenderConsolePageContextHelper.FIRST_INDEX);
428: if (this .cc.getLeftSectionPaneCount() > 1) {
429: ConfigInstanceForLeftRightContext
430: .newInstance(
431: this .rctph,
432: this ,
433: this .cc,
434: RenderConsolePageContextHelper.AREA__RIGHT,
435: RenderConsolePageContextHelper.FIRST_INDEX);
436: } else {
437: this .rctph
438: .renderSubPane(
439: this ,
440: this .cc
441: .getRightSectionPaneContext(0),
442: this .cc,
443: RenderConsolePageContextHelper.AREA__RIGHT,
444: RenderConsolePageContextHelper.FIRST_INDEX);
445: }
446: } else if (leftSecInUse && centerSecInUse
447: && !rightSecInUse) {
448: //
449: //
450: //ConfigInstanceForUpDownContext.newInstance(
451: // this.rctph, this, this.cc,
452: // RenderConsolePageContextHelper.AREA__CENTER,
453: // RenderConsolePageContextHelper.FIRST_INDEX);
454: //
455: if (this .cc.getCenterSectionPaneCount() > 1) {
456: ConfigInstanceForUpDownContext
457: .newInstance(
458: this .rctph,
459: this ,
460: this .cc,
461: RenderConsolePageContextHelper.AREA__CENTER,
462: RenderConsolePageContextHelper.FIRST_INDEX);
463: } else {
464: this .rctph
465: .renderSubPane(
466: this ,
467: this .cc
468: .getCenterSectionPaneContext(0),
469: this .cc,
470: RenderConsolePageContextHelper.AREA__CENTER,
471: RenderConsolePageContextHelper.FIRST_INDEX);
472: }
473: } else {
474: throw UnexpectedSystemException.unknownState();
475: }
476: } else if (this .index == 1) {
477: if (leftSecInUse && centerSecInUse && rightSecInUse) {
478: //
479: //
480: if (this .cc.getRightSectionPaneCount() > 1) {
481: ConfigInstanceForLeftRightContext
482: .newInstance(
483: this .rctph,
484: this ,
485: this .cc,
486: RenderConsolePageContextHelper.AREA__RIGHT,
487: RenderConsolePageContextHelper.FIRST_INDEX);
488: } else {
489: this .rctph
490: .renderSubPane(
491: this ,
492: this .cc
493: .getRightSectionPaneContext(0),
494: this .cc,
495: RenderConsolePageContextHelper.AREA__RIGHT,
496: RenderConsolePageContextHelper.FIRST_INDEX);
497: }
498: } else {
499: throw UnexpectedSystemException.unknownState();
500: }
501: } else {
502: throw UnexpectedSystemException.unknownState();
503: }
504: } else if (this .section == RenderConsolePageContextHelper.AREA__LEFT) {
505: //
506: //throw UnexpectedSystemException.notImplemented();
507: //
508: if ((this .index + 2) < (this .cc.getLeftSectionPaneCount())) {
509: ConfigInstanceForLeftRightContext.newInstance(
510: this .rctph, this , this .cc, this .section,
511: (this .index + 1));
512: } else {
513: String context = this .cc
514: .getLeftSectionPaneContext((this .index + 1));
515: this .rctph.renderSubPane(this , context, this .cc,
516: this .section, (this .index + 1));
517: }
518: } else if (this .section == RenderConsolePageContextHelper.AREA__RIGHT) {
519: //
520: //throw UnexpectedSystemException.notImplemented();
521: //
522: if ((this .index + 2) < (this .cc.getRightSectionPaneCount())) {
523: ConfigInstanceForLeftRightContext.newInstance(
524: this .rctph, this , this .cc, this .section,
525: (this .index + 1));
526: } else {
527: String context = this .cc
528: .getRightSectionPaneContext((this .index + 1));
529: this .rctph.renderSubPane(this , context, this .cc,
530: this .section, (this .index + 1));
531: }
532: } else {
533: throw UnexpectedSystemException.unknownState();
534: }
535: }
536:
537: //
538:
539: private final static String getLeftName(int inSection, int inIndex) {
540: return (inSection + "-" + inIndex + "-" + "L");
541: }
542:
543: private final static String getRightName(int inSection, int inIndex) {
544: return (inSection + "-" + inIndex + "-" + "R");
545: }
546:
547: protected final static int getCumulitiveLeftSectionWidth(
548: int inTotal, ConsoleConfig inCc) {
549: //
550: int outValue = 0;
551:
552: for (int i = 0; i < inTotal; i++) {
553:
554: outValue += Integer
555: .parseInt(inCc
556: .getLeftSectionPaneProperty(
557: i,
558: ConsoleConfigTagPreferencesHelper.PROP_NAME__WIDTH));
559: }
560:
561: return outValue;
562: }
563:
564: protected final static int getCumulitiveCenterSectionHeight(
565: int inTotal, ConsoleConfig inCc) {
566: //
567: int outValue = 0;
568:
569: for (int i = 0; i < inTotal; i++) {
570:
571: outValue += Integer
572: .parseInt(inCc
573: .getCenterSectionPaneProperty(
574: i,
575: ConsoleConfigTagPreferencesHelper.PROP_NAME__HEIGHT));
576: }
577:
578: return outValue;
579: }
580:
581: protected final static int getCumulitiveRightSectionWidth(
582: int inTotal, ConsoleConfig inCc) {
583: //
584: int outValue = 0;
585:
586: for (int i = 0; i < inTotal; i++) {
587:
588: outValue += Integer
589: .parseInt(inCc
590: .getRightSectionPaneProperty(
591: i,
592: ConsoleConfigTagPreferencesHelper.PROP_NAME__WIDTH));
593: }
594:
595: return outValue;
596: }
597: //
598: //
599: //
600: //
601: //
602: //
603: //
604: //
605: //
606: //
607: //
608: //
609: //
610: }
|