1 14 package org.wings.plaf.css; 15 16 17 import org.wings.*; 18 import org.wings.io.Device; 19 import org.wings.plaf.CGManager; 20 21 import java.io.IOException ; 22 23 public class ComboBoxCG extends AbstractComponentCG implements 24 org.wings.plaf.ComboBoxCG { 25 26 public void installCG(final SComponent comp) { 27 super.installCG(comp); 28 final SComboBox component = (SComboBox) comp; 29 final CGManager manager = component.getSession().getCGManager(); 30 Object value; 31 value = manager.getObject("SComboBox.renderer", SDefaultListCellRenderer.class); 32 if (value != null) { 33 component.setRenderer((SDefaultListCellRenderer) value); 34 } 35 } 36 37 38 protected void writeFormComboBox(Device device, SComboBox component) throws IOException { 39 device.print("<select size=\"1\""); 40 Utils.optAttribute(device, "name", Utils.event(component)); 41 Utils.optAttribute(device, "tabindex", component.getFocusTraversalIndex()); 42 43 Utils.printCSSInlineFullSize(device, component.getPreferredSize()); 44 45 if (!component.isEnabled()) 46 device.print(" disabled=\"true\""); 47 if (component.isFocusOwner()) 48 Utils.optAttribute(device, "focus", component.getName()); 49 50 Utils.writeEvents(device, component); 51 52 device.print(">\n"); 53 javax.swing.ComboBoxModel model = component.getModel(); 54 int size = model.getSize(); 55 int selected = component.getSelectedIndex(); 56 57 SListCellRenderer renderer = component.getRenderer(); 58 59 for (int i = 0; i < size; i++) { 60 SComponent cellRenderer = null; 61 if (renderer != null) { 62 cellRenderer = renderer.getListCellRendererComponent(component, model.getElementAt(i), false, i); 63 } else { 64 device.print("<!--renderer==null-->"); 65 } 66 67 68 device.print("<option"); 69 Utils.optAttribute(device, "value", component.getSelectionParameter(i)); 70 if (selected == i) { 71 device.print(" selected=\"selected\""); 72 } 73 74 if (cellRenderer != null) { 75 Utils.optAttribute(device, "title", cellRenderer.getToolTipText()); 76 org.wings.io.StringBufferDevice stringBufferDevice = getStringBufferDevice(); 77 Utils.printCSSInlineStyleAttributes(stringBufferDevice, cellRenderer); 78 Utils.optAttribute(device, "style", stringBufferDevice.toString()); 79 } 80 81 device.print(">\n"); 83 if (cellRenderer != null) { 84 org.wings.io.StringBufferDevice string = getStringBufferDevice(); 86 cellRenderer.write(string); 87 char[] chars = string.toString().toCharArray(); 88 int pos = 0; 89 for (int c = 0; c < chars.length; c++) { 90 switch (chars[c]) { 91 case '<': 92 device.print(chars, pos, c - pos); 93 break; 94 case '>': 95 pos = c + 1; 96 } 97 } 98 device.print(chars, pos, chars.length - pos); 99 } else { 100 device.print("<!--cellrenderer==null, use toString-->"); 101 device.print(model.getElementAt(i).toString()); 102 } 103 104 device.print("</option>"); 105 } 106 107 108 device.print("</select>"); 109 111 device.print("<input type=\"hidden\""); 112 Utils.optAttribute(device, "name", Utils.event(component)); 113 Utils.optAttribute(device, "value", -1); 114 115 device.print("/>"); 116 } 117 118 private org.wings.io.StringBufferDevice stringBufferDevice = null; 119 120 protected org.wings.io.StringBufferDevice getStringBufferDevice() { 121 if (stringBufferDevice == null) { 122 stringBufferDevice = new org.wings.io.StringBufferDevice(); 123 } 124 stringBufferDevice.reset(); 125 return stringBufferDevice; 126 } 127 128 129 131 132 public void writeContent(final Device device, 133 final SComponent _c) 134 throws IOException { 135 final SComboBox component = (SComboBox) _c; 136 137 SComboBox comboBox = (SComboBox) component; 139 writeFormComboBox(device, comboBox); 142 device.print("\n"); 146 147 } 149 } 150 | Popular Tags |