KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > core > comp > renderer > html > HTMLToggleRenderer


1 /*
2  * Copyright (C) 2003 Christian Cryder [christianc@granitepeaks.com]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: HTMLToggleRenderer.java,v 1.10 2004/02/01 05:16:27 christianc Exp $
19  */

20 package org.enhydra.barracuda.core.comp.renderer.html;
21
22 import java.util.*;
23
24 import org.apache.log4j.*;
25 import org.w3c.dom.*;
26 import org.w3c.dom.html.*;
27
28 import org.enhydra.barracuda.core.comp.*;
29 import org.enhydra.barracuda.core.comp.renderer.*;
30 import org.enhydra.barracuda.core.util.dom.*;
31 import org.enhydra.barracuda.plankton.*;
32
33 /**
34  * This class handles the default rendering of a list in an HTML view.
35  */

36 public class HTMLToggleRenderer extends HTMLInputRenderer {
37
38     protected static final Logger logger = Logger.getLogger(HTMLToggleRenderer.class.getName());
39     
40     protected BToggleButton btbcomp = null;
41     
42     /**
43      *
44      */

45     public void renderComponent(BComponent comp, View view, ViewContext vc) throws RenderException {
46         //make sure the component is a list component
47
if (!(comp instanceof BToggleButton)) throw new NoSuitableRendererException("This renderer can only render BToggleButton components; comp is of type:"+comp.getClass().getName());
48         btbcomp = (BToggleButton) comp;
49         Node node = view.getNode();
50
51         //show what we're doing
52
if (logger.isDebugEnabled()) showNodeInterfaces(view, logger);
53
54         //first, allow the parent class to do anything it needs to
55
super.renderComponent(comp, view, vc);
56
57         //..HTMLInputElement - set the "selected" attribute
58
if (node instanceof HTMLInputElement) {
59             if (logger.isInfoEnabled()) logger.info("Rendering based on HTMLInputElement interface...");
60             HTMLInputElement el = (HTMLInputElement) node;
61
62             //set selected
63
el.setChecked(btbcomp.isSelected());
64
65         } else {
66             String JavaDoc errmsg = "Node does not implement HTMLInputElement and cannot be rendered: "+node;
67             logger.warn(errmsg);
68             throw new NoSuitableRendererException(errmsg);
69         }
70     }
71 }
Popular Tags