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 * Created by IntelliJ IDEA. 029 * User: bommel 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 }