001    package org.apache.myfaces.tobago.component;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one or more
005     * contributor license agreements.  See the NOTICE file distributed with
006     * this work for additional information regarding copyright ownership.
007     * The ASF licenses this file to You under the Apache License, Version 2.0
008     * (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     *
011     *      http://www.apache.org/licenses/LICENSE-2.0
012     *
013     * Unless required by applicable law or agreed to in writing, software
014     * distributed under the License is distributed on an "AS IS" BASIS,
015     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016     * See the License for the specific language governing permissions and
017     * limitations under the License.
018     */
019    
020    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ORIENTATION;
021    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ICON_SIZE;
022    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_LABEL_POSITION;
023    
024    import javax.faces.el.ValueBinding;
025    import javax.faces.context.FacesContext;
026    
027    /*
028     * Date: 11.02.2006
029     * Time: 14:48:46
030     */
031    public class UIToolBar extends javax.faces.component.UIPanel {
032    
033      public static final String LABEL_BOTTOM = "bottom";
034      public static final String LABEL_RIGHT = "right";
035      public static final String LABEL_OFF = "off";
036    
037      public static final String ICON_SMALL = "small";
038      public static final String ICON_BIG = "big";
039      public static final String ICON_OFF = "off";
040    
041      public static final String ORIENTATION_LEFT = "left";
042      public static final String ORIENTATION_RIGHT = "right";
043    
044      public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.ToolBar";
045    
046      private String labelPosition;
047      private String iconSize;
048      private String orientation;
049    
050      public String getLabelPosition() {
051        if (labelPosition != null) {
052          return labelPosition;
053        }
054        ValueBinding vb = getValueBinding(ATTR_LABEL_POSITION);
055        if (vb != null) {
056          return (String) vb.getValue(getFacesContext());
057        } else {
058          return LABEL_BOTTOM;
059        }
060      }
061    
062      public void setLabelPosition(String labelPosition) {
063        this.labelPosition = labelPosition;
064      }
065    
066      public String getIconSize() {
067        if (iconSize != null) {
068          return iconSize;
069        }
070        ValueBinding vb = getValueBinding(ATTR_ICON_SIZE);
071        if (vb != null) {
072          return (String) vb.getValue(getFacesContext());
073        } else {
074          return ICON_SMALL;
075        }
076      }
077    
078      public void setIconSize(String iconSize) {
079        this.iconSize = iconSize;
080      }
081    
082    
083      public String getOrientation() {
084        if (orientation != null) {
085          return orientation;
086        }
087        ValueBinding vb = getValueBinding(ATTR_ORIENTATION);
088        if (vb != null) {
089          return (String) vb.getValue(getFacesContext());
090        } else {
091          return ORIENTATION_LEFT;
092        }
093    
094      }
095    
096      public void setOrientation(String orientation) {
097        this.orientation = orientation;
098      }
099    
100      public Object saveState(FacesContext context) {
101        Object[] saveState = new Object[4];
102        saveState[0] = super.saveState(context);
103        saveState[1] = labelPosition;
104        saveState[2] = iconSize;
105        saveState[3] = orientation;
106        return saveState;
107      }
108    
109      public void restoreState(FacesContext context, Object savedState) {
110        Object[] values = (Object[]) savedState;
111        super.restoreState(context, values[0]);
112        labelPosition = (String) values[1];
113        iconSize = (String) values[2];
114        orientation = (String) values[3];
115      }
116    }