KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > plaf > css > ClickableCG


1 /*
2  * $Id: ClickableCG.java,v 1.15 2005/05/26 13:18:09 neurolabs Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings.plaf.css;
15
16
17 import java.io.IOException JavaDoc;
18
19 import org.wings.SClickable;
20 import org.wings.SComponent;
21 import org.wings.SIcon;
22 import org.wings.io.Device;
23
24 public class ClickableCG extends LabelCG implements org.wings.plaf.ButtonCG {
25
26     public void writeContent(final Device device, final SComponent component)
27             throws IOException JavaDoc {
28         final SClickable button = (SClickable) component;
29
30         if (button.getShowAsFormComponent()) {
31             writeButtonStart(device, button);
32             device.print(" name=\"");
33             Utils.write(device, button.getEventTarget().getEncodedLowLevelEventId());
34             device.print("\" value=\"");
35             Utils.write(device, button.getEvent());
36             device.print("\"");
37             Utils.optAttribute(device, "tabindex", button.getFocusTraversalIndex());
38         } else {
39             device.print("<a HREF=\"");
40             Utils.write(device, button.getURL());
41             device.print("\"");
42         }
43
44         if (!button.isEnabled())
45             device.print(" disabled=\"true\"");
46
47         Utils.writeEvents(device, button);
48         device.print(">");
49
50         final String JavaDoc text = button.getText();
51         final SIcon icon = getIcon(button);
52
53         if (icon == null && text != null)
54             writeText(device, text);
55         else if (icon != null && text == null)
56             writeIcon(device, icon);
57         else if (icon != null && text != null) {
58             new IconTextCompound() {
59                 protected void text(Device d) throws IOException JavaDoc {
60                     writeText(d, text);
61                 }
62
63                 protected void icon(Device d) throws IOException JavaDoc {
64                     writeIcon(d, icon);
65                 }
66             }.writeCompound(device, component, button.getHorizontalTextPosition(), button.getVerticalTextPosition());
67         }
68
69         if (button.getShowAsFormComponent())
70             device.print("</button>");
71         else
72             device.print("</a>");
73     }
74
75     protected void writeButtonStart(Device device, SClickable button) throws IOException JavaDoc {
76         device.print("<button");
77     }
78
79     protected SIcon getIcon(SClickable abstractButton) {
80         if (abstractButton.isSelected()) {
81             return abstractButton.isEnabled()
82                     ? abstractButton.getSelectedIcon()
83                     : abstractButton.getDisabledSelectedIcon();
84         } else {
85             return abstractButton.isEnabled()
86                     ? abstractButton.getIcon()
87                     : abstractButton.getDisabledIcon();
88         }
89     }
90 }
91
Popular Tags