001: /*
002: * This file is part of the Echo Web Application Framework (hereinafter "Echo").
003: * Copyright (C) 2002-2005 NextApp, Inc.
004: *
005: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
006: *
007: * The contents of this file are subject to the Mozilla Public License Version
008: * 1.1 (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: * http://www.mozilla.org/MPL/
011: *
012: * Software distributed under the License is distributed on an "AS IS" basis,
013: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
014: * for the specific language governing rights and limitations under the
015: * License.
016: *
017: * Alternatively, the contents of this file may be used under the terms of
018: * either the GNU General Public License Version 2 or later (the "GPL"), or
019: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
020: * in which case the provisions of the GPL or the LGPL are applicable instead
021: * of those above. If you wish to allow use of your version of this file only
022: * under the terms of either the GPL or the LGPL, and not to allow others to
023: * use your version of this file under the terms of the MPL, indicate your
024: * decision by deleting the provisions above and replace them with the notice
025: * and other provisions required by the GPL or the LGPL. If you do not delete
026: * the provisions above, a recipient may use your version of this file under
027: * the terms of any one of the MPL, the GPL or the LGPL.
028: */
029:
030: package nextapp.echo2.webcontainer.syncpeer;
031:
032: import nextapp.echo2.app.Alignment;
033: import nextapp.echo2.app.Component;
034:
035: /**
036: * Provides utility methods to configure <code>TriCellTable</code> for
037: * text/state positions specified by buttons/labels.
038: */
039: class TriCellTableConfigurator {
040:
041: /**
042: * Converts the value of a <code>textPosition</code> property into a value
043: * suitable to be passed to a <code>TriCellTable</code> as an
044: * <code>orientation</code> constructor parameter.
045: * This method assumes that the <code>TriCellTable</code> is being rendered
046: * with text at index 0 and icon at position 1.
047: *
048: * @param textPosition the <code>Alignment</code>
049: * @param component the component being rendered
050: * @return the <code>orientation</code> value
051: */
052: static int convertIconTextPositionToOrientation(
053: Alignment textPosition, Component component) {
054: if (textPosition.getVertical() == Alignment.DEFAULT) {
055: switch (textPosition.getHorizontal()) {
056: case Alignment.LEFT:
057: return component.getRenderLayoutDirection()
058: .isLeftToRight() ? TriCellTable.LEADING_TRAILING
059: : TriCellTable.TRAILING_LEADING;
060: case Alignment.RIGHT:
061: return component.getRenderLayoutDirection()
062: .isLeftToRight() ? TriCellTable.TRAILING_LEADING
063: : TriCellTable.LEADING_TRAILING;
064: case Alignment.LEADING:
065: return TriCellTable.LEADING_TRAILING;
066: case Alignment.TRAILING:
067: return TriCellTable.TRAILING_LEADING;
068: default:
069: // Invalid, return value for TRAILING (default).
070: return TriCellTable.TRAILING_LEADING;
071: }
072: } else {
073: if (textPosition.getVertical() == Alignment.TOP) {
074: return TriCellTable.TOP_BOTTOM;
075: } else {
076: return TriCellTable.BOTTOM_TOP;
077: }
078: }
079: }
080:
081: /**
082: * Converts the value of the <code>stateAlignment</code> property of a
083: * <code>ToggleButton</code> into a value suitable to be passed to a
084: * <code>TriCellTable</code> as an <code>orientation</code> constructor
085: * parameter.
086: * This method assumes that the <code>TriCellTable</code> is rendered with
087: * text/icon at lower indices than the state.
088: *
089: * @param statePosition the state position <code>Alignment</code>
090: * @param component the button being rendered
091: * @return the <code>orientation</code> value
092: */
093: static int convertStatePositionToOrientation(
094: Alignment statePosition, Component component) {
095: if (statePosition.getVertical() == Alignment.DEFAULT) {
096: switch (statePosition.getHorizontal()) {
097: case Alignment.LEFT:
098: return component.getRenderLayoutDirection()
099: .isLeftToRight() ? TriCellTable.TRAILING_LEADING
100: : TriCellTable.LEADING_TRAILING;
101: case Alignment.RIGHT:
102: return component.getRenderLayoutDirection()
103: .isLeftToRight() ? TriCellTable.LEADING_TRAILING
104: : TriCellTable.TRAILING_LEADING;
105: case Alignment.LEADING:
106: return TriCellTable.TRAILING_LEADING;
107: case Alignment.TRAILING:
108: return TriCellTable.LEADING_TRAILING;
109: default:
110: // Invalid, return value for LEADING (default).
111: return TriCellTable.TRAILING_LEADING;
112: }
113: } else {
114: if (statePosition.getVertical() == Alignment.TOP) {
115: return TriCellTable.BOTTOM_TOP;
116: } else {
117: return TriCellTable.TOP_BOTTOM;
118: }
119: }
120: }
121: }
|