001    package net.sf.tacos.components.scriptaculous;
002    
003    import java.util.HashMap;
004    import java.util.Map;
005    
006    import org.apache.tapestry.BaseComponent;
007    import org.apache.tapestry.IMarkupWriter;
008    import org.apache.tapestry.IRequestCycle;
009    import org.apache.tapestry.IScript;
010    import org.apache.tapestry.TapestryUtils;
011    import org.apache.tapestry.components.Block;
012    import org.apache.tapestry.json.JSONObject;
013    
014    /**
015     * Creates a diashow of provided {@link Block}s.
016     * 
017     * @author Igor Drobiazko
018     *
019     */
020    public abstract class Glider extends BaseComponent {
021            
022            /**
023         * {@inheritDoc}
024         */
025            protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) {
026                    writer.begin("div");
027            renderIdAttribute(writer, cycle);
028            renderInformalParameters(writer, cycle);
029            super.renderComponent(writer, cycle);
030            
031            writer.end();
032            
033            JSONObject json = new JSONObject();
034            json.put("duration", getDuration());
035            
036            Map parms = new HashMap();
037            parms.put("props", json.toString());
038            parms.put("component", this);
039            
040            getScript().execute(this, cycle, TapestryUtils.getPageRenderSupport(cycle, this), parms);
041            }
042        
043        public String getSectionId(int index){
044            return "section"+(++index);
045        }
046    
047            public abstract double getDuration();
048            
049        /** Injected {@link IScript}. */
050        public abstract IScript getScript();
051    
052    }