001: /*
002: * Copyright 2000,2005 wingS development team.
003: *
004: * This file is part of wingS (http://wingsframework.org).
005: *
006: * wingS is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * Please see COPYING for the complete licence.
012: */
013: package org.wings.plaf.css;
014:
015: import org.wings.*;
016: import org.wings.io.Device;
017: import org.wings.plaf.Update;
018: import org.wings.resource.ResourceManager;
019:
020: import java.io.IOException;
021: import org.wings.script.JavaScriptEvent;
022: import org.wings.script.JavaScriptListener;
023:
024: public final class RadioButtonCG extends CheckBoxCG implements
025: org.wings.plaf.RadioButtonCG {
026: private static final long serialVersionUID = 1L;
027:
028: protected void installIcons(final SAbstractButton button) {
029: button.setIcon((SIcon) ResourceManager.getObject(
030: "SRadioButton.icon", SIcon.class));
031: button.setSelectedIcon((SIcon) ResourceManager.getObject(
032: "SRadioButton.selectedIcon", SIcon.class));
033: button.setRolloverIcon((SIcon) ResourceManager.getObject(
034: "SRadioButton.rolloverIcon", SIcon.class));
035: button.setRolloverSelectedIcon((SIcon) ResourceManager
036: .getObject("SRadioButton.rolloverSelectedIcon",
037: SIcon.class));
038: button.setPressedIcon((SIcon) ResourceManager.getObject(
039: "SRadioButton.pressedIcon", SIcon.class));
040: button.setDisabledIcon((SIcon) ResourceManager.getObject(
041: "SRadioButton.disabledIcon", SIcon.class));
042: button.setDisabledSelectedIcon((SIcon) ResourceManager
043: .getObject("SRadioButton.disabledSelectedIcon",
044: SIcon.class));
045: }
046:
047: protected void tableClickability(Device device,
048: SAbstractButton button) throws IOException {
049: if (!button.isSelected()) {
050: super .tableClickability(device, button);
051: }
052: }
053:
054: protected void writeInput(Device device, SAbstractButton button)
055: throws IOException {
056: if (button.getShowAsFormComponent() && !useIconsInForms) {
057: Object clientProperty = button
058: .getClientProperty("onChangeSubmitListener");
059: // If the application developer attached any ActionListeners, ItemListeners or
060: // ChangeListeners to this SRadioButton or its ButtonGroup, the surrounding form
061: // gets submitted as soon as the state of this SRadioButton changed.
062: if (button.getActionListeners().length > 0
063: || button.getItemListeners().length > 0
064: || button.getChangeListeners().length > 0
065: || (button.getGroup() != null && button.getGroup()
066: .getActionListeners().length > 0)) {
067: if (clientProperty == null) {
068: String event = JavaScriptEvent.ON_CHANGE;
069: String code = "wingS.request.sendEvent(event, true, "
070: + !button.isReloadForced() + ");";
071: if (Utils.isMSIE(button)) {
072: // In IE the "onchange"-event gets fired when a control loses the
073: // input focus and its value has been modified since gaining focus.
074: // Even though this is actually the correct behavior, we want the
075: // event to get fired immediately - thats why we use a "filtered"
076: // version of IE's proprietary "onpropertychange"-event.
077: event = "onpropertychange";
078: code = "if (event.srcElement.checked) " + code;
079: }
080: JavaScriptListener javaScriptListener = new JavaScriptListener(
081: event, code);
082: button.addScriptListener(javaScriptListener);
083: button.putClientProperty("onChangeSubmitListener",
084: javaScriptListener);
085: }
086: } else if (clientProperty != null
087: && clientProperty instanceof JavaScriptListener) {
088: button
089: .removeScriptListener((JavaScriptListener) clientProperty);
090: button
091: .putClientProperty("onChangeSubmitListener",
092: null);
093: }
094: }
095:
096: device.print("<input type=\"hidden\" name=\"");
097: Utils.write(device, Utils.event(button));
098: device.print("\" value=\"");
099: Utils.write(device, button.getDeselectionParameter());
100: device.print("\"/>");
101:
102: device.print("<input type=\"radio\" name=\"");
103:
104: Utils.write(device, Utils.event(button));
105: device.print("\" value=\"");
106: Utils.write(device, button.getToggleSelectionParameter());
107: device.print("\"");
108: Utils.writeEvents(device, button, null);
109: Utils.optAttribute(device, "tabindex", button
110: .getFocusTraversalIndex());
111:
112: if (!button.isEnabled())
113: device.print(" disabled=\"true\"");
114: if (button.isSelected())
115: device.print(" checked=\"true\"");
116: if (button.isFocusOwner())
117: Utils.optAttribute(device, "foc", button.getName());
118:
119: device.print("/>");
120: }
121:
122: public Update getTextUpdate(SRadioButton radioButton, String text) {
123: return text == null ? null : new TextUpdate(radioButton, text);
124: }
125:
126: public Update getIconUpdate(SRadioButton radioButton, SIcon icon) {
127: return icon == null ? null : new IconUpdate(radioButton, icon);
128: }
129:
130: }
|