1 package org.wings.plaf.css; 14 15 import org.apache.commons.logging.Log; 16 import org.apache.commons.logging.LogFactory; 17 import org.wings.LowLevelEventListener; 18 import org.wings.SComponent; 19 import org.wings.SConstants; 20 import org.wings.SDimension; 21 import org.wings.SPopupMenu; 22 import org.wings.border.STitledBorder; 23 import org.wings.io.Device; 24 import org.wings.plaf.ComponentCG; 25 26 import javax.swing.*; 27 import java.io.IOException ; 28 29 32 public class PrefixAndSuffixDelegate implements org.wings.plaf.PrefixAndSuffixDelegate { 33 private final static transient Log log = LogFactory.getLog(PrefixAndSuffixDelegate.class); 34 35 public PrefixAndSuffixDelegate() {} 36 37 public void writePrefix(Device device, SComponent component) throws IOException { 38 SDimension prefSize = component.getPreferredSize(); 39 Utils.printDebugNewline(device, component); 40 Utils.printDebug(device, "<!-- ").print(component.getName()).print(" -->"); 41 device.print("<div"); 42 if (component.getStyle() != null && component.getStyle().length() > 0) { 43 device.print(" class=\""); 44 device.print(component.getStyle()); 45 device.print("_Box\""); 46 } 47 48 boolean isHeightPercentage = prefSize != null && prefSize.height != null && prefSize.height.indexOf("%") != -1; 50 boolean isWidthPercentage = prefSize != null && prefSize.width != null && prefSize.width.indexOf("%") != -1; 51 boolean isVAligned = (component.getVerticalAlignment() == SConstants.CENTER || component.getVerticalAlignment() == SConstants.BOTTOM ); 53 54 if ( isHeightPercentage || isWidthPercentage ) { 55 device.print(" style=\""); 56 if (isHeightPercentage && isVAligned == false) { 57 device.print("height:100%;"); 58 } 59 if (isWidthPercentage) { 60 device.print("width:100%;"); 61 } 62 device.print("\""); 63 } 64 65 device.print(">"); 66 device.print("<div id=\"").print(component.getName()).print("\""); 67 Utils.optAttribute(device, "class", component.getStyle()); 68 Utils.printCSSInlinePreferredSize(device, prefSize); 69 70 if (component instanceof LowLevelEventListener) { 71 LowLevelEventListener lowLevelEventListener = (LowLevelEventListener) component; 72 device.print(" eid=\"") 73 .print(lowLevelEventListener.getEncodedLowLevelEventId()).print("\""); 74 } 75 76 String toolTip = component.getToolTipText(); 77 if (toolTip != null) 78 device.print(" onmouseover=\"return makeTrue(domTT_activate(this, event, 'content', '") 79 .print(toolTip) 80 .print("', 'predefined', 'default'));\""); 81 82 InputMap inputMap = component.getInputMap(); 83 if (inputMap != null && !(inputMap instanceof VersionedInputMap)) { 84 log.debug("inputMap = " + inputMap); 85 inputMap = new VersionedInputMap(inputMap); 86 component.setInputMap(inputMap); 87 } 88 89 if (inputMap != null) { 90 VersionedInputMap versionedInputMap = (VersionedInputMap) inputMap; 91 Integer inputMapVersion = (Integer ) component.getClientProperty("inputMapVersion"); 92 if (inputMapVersion == null || versionedInputMap.getVersion() != inputMapVersion.intValue()) { 93 log.debug("inputMapVersion = " + inputMapVersion); 94 InputMapScriptListener.install(component); 95 component.putClientProperty("inputMapVersion", new Integer (versionedInputMap.getVersion())); 96 } 97 } 98 99 SPopupMenu menu = component.getComponentPopupMenu(); 100 if (menu != null) { 101 ComponentCG menuCG = menu.getCG(); 102 String componentId = menu.getName(); 103 String popupId = componentId + "_pop"; 104 device.print(" onContextMenu=\"javascript:return wpm_menuPopup(event, '"); 105 device.print(popupId); 106 device.print("');\" onMouseDown=\"javascript:return wpm_menuPopup(event, '"); 107 device.print(popupId); 108 device.print("');\""); 109 } 110 111 device.print(">"); 113 if (component.getBorder() instanceof STitledBorder) { 115 STitledBorder titledBorder = (STitledBorder) component.getBorder(); 116 device.print("<div class=\"STitledBorderLegend\" style=\""); 117 titledBorder.getTitleAttributes().write(device); 118 device.print("\">"); 119 device.print(titledBorder.getTitle()); 120 device.print("</div>"); 121 } 122 123 component.fireRenderEvent(SComponent.START_RENDERING); 124 } 125 126 public void writeSuffix(Device device, SComponent component) throws IOException { 127 component.fireRenderEvent(SComponent.DONE_RENDERING); 128 device.print("</div></div>"); 129 Utils.printDebug(device, "<!-- /").print(component.getName()).print(" -->"); 130 } 131 132 } 133 | Popular Tags |