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