KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nextapp > echo2 > webcontainer > syncpeer > TriCellTableConfigurator


1 /*
2  * This file is part of the Echo Web Application Framework (hereinafter "Echo").
3  * Copyright (C) 2002-2005 NextApp, Inc.
4  *
5  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * Alternatively, the contents of this file may be used under the terms of
18  * either the GNU General Public License Version 2 or later (the "GPL"), or
19  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20  * in which case the provisions of the GPL or the LGPL are applicable instead
21  * of those above. If you wish to allow use of your version of this file only
22  * under the terms of either the GPL or the LGPL, and not to allow others to
23  * use your version of this file under the terms of the MPL, indicate your
24  * decision by deleting the provisions above and replace them with the notice
25  * and other provisions required by the GPL or the LGPL. If you do not delete
26  * the provisions above, a recipient may use your version of this file under
27  * the terms of any one of the MPL, the GPL or the LGPL.
28  */

29
30 package nextapp.echo2.webcontainer.syncpeer;
31
32 import nextapp.echo2.app.Alignment;
33 import nextapp.echo2.app.Component;
34
35 /**
36  * Provides utility methods to configure <code>TriCellTable</code> for
37  * text/state positions specified by buttons/labels.
38  */

39 class TriCellTableConfigurator {
40     
41     /**
42      * Converts the value of a <code>textPosition</code> property into a value
43      * suitable to be passed to a <code>TriCellTable</code> as an
44      * <code>orientation</code> constructor parameter.
45      * This method assumes that the <code>TriCellTable</code> is being rendered
46      * with text at index 0 and icon at position 1.
47      *
48      * @param textPosition the <code>Alignment</code>
49      * @param component the component being rendered
50      * @return the <code>orientation</code> value
51      */

52     static int convertIconTextPositionToOrientation(Alignment textPosition, Component component) {
53         if (textPosition.getVertical() == Alignment.DEFAULT) {
54             switch (textPosition.getHorizontal()) {
55             case Alignment.LEFT:
56                 return component.getRenderLayoutDirection().isLeftToRight()
57                         ? TriCellTable.LEADING_TRAILING : TriCellTable.TRAILING_LEADING;
58             case Alignment.RIGHT:
59                 return component.getRenderLayoutDirection().isLeftToRight()
60                         ? TriCellTable.TRAILING_LEADING : TriCellTable.LEADING_TRAILING;
61             case Alignment.LEADING:
62                 return TriCellTable.LEADING_TRAILING;
63             case Alignment.TRAILING:
64                 return TriCellTable.TRAILING_LEADING;
65             default:
66                 // Invalid, return value for TRAILING (default).
67
return TriCellTable.TRAILING_LEADING;
68             }
69         } else {
70             if (textPosition.getVertical() == Alignment.TOP) {
71                 return TriCellTable.TOP_BOTTOM;
72             } else {
73                 return TriCellTable.BOTTOM_TOP;
74             }
75         }
76     }
77     
78     /**
79      * Converts the value of the <code>stateAlignment</code> property of a
80      * <code>ToggleButton</code> into a value suitable to be passed to a
81      * <code>TriCellTable</code> as an <code>orientation</code> constructor
82      * parameter.
83      * This method assumes that the <code>TriCellTable</code> is rendered with
84      * text/icon at lower indices than the state.
85      *
86      * @param statePosition the state position <code>Alignment</code>
87      * @param component the button being rendered
88      * @return the <code>orientation</code> value
89      */

90     static int convertStatePositionToOrientation(Alignment statePosition, Component component) {
91         if (statePosition.getVertical() == Alignment.DEFAULT) {
92             switch (statePosition.getHorizontal()) {
93             case Alignment.LEFT:
94                 return component.getRenderLayoutDirection().isLeftToRight()
95                         ? TriCellTable.TRAILING_LEADING : TriCellTable.LEADING_TRAILING;
96             case Alignment.RIGHT:
97                 return component.getRenderLayoutDirection().isLeftToRight()
98                         ? TriCellTable.LEADING_TRAILING : TriCellTable.TRAILING_LEADING;
99             case Alignment.LEADING:
100                 return TriCellTable.TRAILING_LEADING;
101             case Alignment.TRAILING:
102                 return TriCellTable.LEADING_TRAILING;
103             default:
104                 // Invalid, return value for LEADING (default).
105
return TriCellTable.TRAILING_LEADING;
106             }
107         } else {
108             if (statePosition.getVertical() == Alignment.TOP) {
109                 return TriCellTable.BOTTOM_TOP;
110             } else {
111                 return TriCellTable.TOP_BOTTOM;
112             }
113         }
114     }
115 }
116
Popular Tags