001 /*
002 * Apache License
003 * Version 2.0, January 2004
004 * http://www.apache.org/licenses/
005 *
006 * Copyright 2008-2010 by chenillekit.org
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 */
014
015 package org.chenillekit.tapestry.core.components;
016
017 import org.apache.tapestry5.BindingConstants;
018 import org.apache.tapestry5.ClientElement;
019 import org.apache.tapestry5.ComponentResources;
020 import org.apache.tapestry5.MarkupWriter;
021 import org.apache.tapestry5.annotations.Environmental;
022 import org.apache.tapestry5.annotations.Import;
023 import org.apache.tapestry5.annotations.Parameter;
024 import org.apache.tapestry5.annotations.SupportsInformalParameters;
025 import org.apache.tapestry5.ioc.annotations.Inject;
026 import org.apache.tapestry5.json.JSONObject;
027 import org.apache.tapestry5.services.javascript.JavaScriptSupport;
028
029 /**
030 * displays a colored container with rounded corners without pics or any mozilla-css goodies.
031 *
032 * @version $Id: RoundCornerContainer.java 674 2010-07-29 12:47:25Z homburgs $
033 */
034 @SupportsInformalParameters
035 @Import(library = {"../Chenillekit.js", "RoundCornerContainer.js"}, stylesheet = {"RoundCornerContainer.css"})
036 public class RoundCornerContainer implements ClientElement
037 {
038 public final static String RENDER_BOTH = "both";
039 public final static String RENDER_TOP = "top";
040 public final static String RENDER_BOTTOM = "bottom";
041
042 /**
043 * parameter let component know, wich part of the container should rendered.
044 * possible values arr "both" by default, "top" or "bottom".
045 */
046 @Parameter(value = RENDER_BOTH, required = false, defaultPrefix = BindingConstants.LITERAL)
047 private String renderPart;
048
049 /**
050 * The id used to generate a page-unique client-side identifier for the component. If a component renders multiple
051 * times, a suffix will be appended to the to id to ensure uniqueness.
052 */
053 @Parameter(value = "prop:componentResources.id", defaultPrefix = BindingConstants.LITERAL)
054 private String clientId;
055
056 /**
057 * the corners background color.
058 */
059 @Parameter(value = "#FFFFFF", required = false, defaultPrefix = BindingConstants.LITERAL)
060 private String bgcolor;
061
062 /**
063 * the corners foreground color.
064 */
065 @Parameter(value = "#9BD1FA", required = false, defaultPrefix = BindingConstants.LITERAL)
066 private String fgcolor;
067
068 /**
069 * the corners radius size (maybe "small" or "big")
070 */
071 @Parameter(value = "", required = false, defaultPrefix = BindingConstants.LITERAL)
072 private String size;
073
074 @Inject
075 private ComponentResources resources;
076
077 @Environmental
078 private JavaScriptSupport javascriptSupport;
079
080 private String assignedClientId;
081
082 void setupRender()
083 {
084 assignedClientId = javascriptSupport.allocateClientId(clientId);
085 }
086
087 void beginRender(MarkupWriter writer)
088 {
089 writer.element("div", "id", getClientId());
090 resources.renderInformalParameters(writer);
091 }
092
093 void afterRender(MarkupWriter writer)
094 {
095 writer.end();
096
097 JSONObject options = new JSONObject();
098 options.put("clientId", getClientId());
099 options.put("bgcolor", bgcolor);
100 options.put("color", fgcolor);
101 options.put("size", size);
102 options.put("render", renderPart);
103
104 javascriptSupport.addInitializerCall("ckroundcornercontainer", options);
105 }
106
107 /**
108 * Returns a unique id for the element. This value will be unique for any given rendering of a
109 * page. This value is intended for use as the id attribute of the client-side element, and will
110 * be used with any DHTML/Ajax related JavaScript.
111 */
112 public String getClientId()
113 {
114 return assignedClientId;
115 }
116 }