001    // Copyright 2004, 2005 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry.contrib.inspector;
016    
017    import org.apache.tapestry.BaseComponent;
018    import org.apache.tapestry.IAsset;
019    
020    /**
021     * Component of the {@link Inspector} page used to select the view.
022     * 
023     * @author Howard Lewis Ship
024     */
025    
026    public abstract class ViewTabs extends BaseComponent
027    {
028        private static String[] _views =
029        { View.SPECIFICATION, View.TEMPLATE, View.PROPERTIES, View.ENGINE };
030    
031        public String[] getViews()
032        {
033            return _views;
034        }
035    
036        public abstract void setView(String value);
037    
038        public abstract String getView();
039    
040        private IAsset getImageForView(boolean focus)
041        {
042            Inspector inspector = (Inspector) getPage();
043    
044            String view = getView();
045    
046            boolean selected = view.equals(inspector.getView());
047    
048            StringBuffer buffer = new StringBuffer(view);
049    
050            if (selected)
051                buffer.append("_selected");
052    
053            if (focus)
054                buffer.append("_focus");
055    
056            String key = buffer.toString();
057            
058            return (IAsset) getAssets().get(key);
059        }
060    
061        public IAsset getViewImage()
062        {
063            return getImageForView(false);
064        }
065    
066        public IAsset getFocusImage()
067        {
068            return getImageForView(true);
069        }
070    
071        public IAsset getBannerImage()
072        {
073            Inspector inspector = (Inspector) getPage();
074            String selectedView = inspector.getView();
075            
076            String key = selectedView + "_banner";
077            
078            return (IAsset) getAssets().get(key);
079        }
080    
081        public void selectTab(String view)
082        {
083            Inspector inspector = (Inspector) getPage();
084            inspector.setView(view);
085        }
086    }