KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > wcf > toolbar > ImgButton


1 /*
2  * ====================================================================
3  * This software is subject to the terms of the Common Public License
4  * Agreement, available at the following URL:
5  * http://www.opensource.org/licenses/cpl.html .
6  * Copyright (C) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  *
12  */

13 package com.tonbeller.wcf.toolbar;
14
15 import java.text.MessageFormat JavaDoc;
16
17 import org.w3c.dom.Element JavaDoc;
18
19 import com.tonbeller.wcf.controller.RequestContext;
20 import com.tonbeller.wcf.utils.DomUtils;
21
22 public class ImgButton extends ToolBarComponentSupport {
23
24   private ToolBar tbar;
25   /**
26    * @param tbar
27    */

28   public ImgButton(ToolBar tbar) {
29     this.tbar = tbar;
30   }
31
32   private String JavaDoc tooltip;
33   // URL
34
private String JavaDoc href;
35   // browser window name, see HTML spec
36
private String JavaDoc target;
37   // Image URL
38
private String JavaDoc img;
39
40   /**
41    * @see com.tonbeller.wcf.toolbar.ToolBarComponent#render(com.tonbeller.wcf.controller.RequestContext, org.w3c.dom.Document)
42    */

43   public void render(RequestContext context, Element JavaDoc parent) throws Exception JavaDoc {
44     Element JavaDoc btn = DomUtils.appendElement(parent, "img-button");
45     btn.setAttribute("img", img +"-up");
46     btn.setAttribute("id", getId());
47     btn.setAttribute("href", makeHref(context));
48     if(target!=null && target.length()!=0)
49       btn.setAttribute("target", target);
50     btn.setAttribute("title", tbar.getTooltip(tooltip));
51   }
52
53   String JavaDoc makeHref(RequestContext context) {
54     Object JavaDoc[] args = {context.getRequest().getContextPath(), DomUtils.randomId()};
55     return MessageFormat.format(href, args);
56   }
57   
58   public void initialize(RequestContext context, ToolBar owner) {
59   }
60
61   public String JavaDoc getHref() {
62     return href;
63   }
64
65   public String JavaDoc getImg() {
66     return img;
67   }
68
69   public String JavaDoc getTarget() {
70     return target;
71   }
72
73   public void setHref(String JavaDoc href) {
74     this.href = href;
75   }
76
77   public void setImg(String JavaDoc img) {
78     this.img = img;
79   }
80
81   public void setTarget(String JavaDoc target) {
82     this.target = target;
83   }
84
85   public void setTooltip(String JavaDoc tooltip) {
86     this.tooltip = tooltip;
87   }
88
89   public boolean isSeparator() {
90     return false;
91   }
92
93 }
94
Popular Tags