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 import org.wings.session.SessionManager; 21 22 import java.io.IOException ; 23 24 public class ProgressBarCG extends AbstractComponentCG implements 25 org.wings.plaf.ProgressBarCG { 26 27 29 public void installCG(final SComponent comp) { 30 super.installCG(comp); 31 final SProgressBar component = (SProgressBar) comp; 32 final CGManager manager = component.getSession().getCGManager(); 33 Object value; 34 Object previous; 35 value = manager.getObject("SProgressBar.borderColor", java.awt.Color .class); 36 if (value != null) { 37 component.setBorderColor((java.awt.Color ) value); 38 } 39 value = manager.getObject("SProgressBar.filledColor", java.awt.Color .class); 40 if (value != null) { 41 component.setFilledColor((java.awt.Color ) value); 42 } 43 value = manager.getObject("SProgressBar.foreground", java.awt.Color .class); 44 if (value != null) { 45 component.setForeground((java.awt.Color ) value); 46 } 47 value = manager.getObject("SProgressBar.preferredSize", SDimension.class); 48 if (value != null) { 49 component.setPreferredSize((SDimension) value); 50 } 51 value = manager.getObject("SProgressBar.unfilledColor", java.awt.Color .class); 52 if (value != null) { 53 component.setUnfilledColor((java.awt.Color ) value); 54 } 55 } 56 57 public void uninstallCG(final SComponent comp) { 58 } 59 60 private static final SIcon BLIND_ICON = (SIcon) SessionManager.getSession() 62 .getCGManager().getObject("ProgressBarCG.blindIcon", SIcon.class); 63 64 66 67 public void writeContent(final Device device, 68 final SComponent _c) 69 throws IOException { 70 final SProgressBar component = (SProgressBar) _c; 71 72 String style = component.getStyle(); 74 75 82 83 SDimension size = component.getProgressBarDimension(); 84 int width = size != null ? size.getIntWidth() : 200; 85 int height = size != null ? size.getIntHeight() : 5; 86 87 if (component.isBorderPainted()) { 88 device.print("<div style=\"width: 100%;height:100%;border: 1px solid "); 89 Utils.write(device, component.getBorderColor()); 90 device.print(";\">"); 91 width -= 2; height -= 2; 93 } 94 95 device.print("<table class=\"SLayout\"><tr><td class=\"SLayout\""); 96 if (component.getFilledColor() != null) { 97 device.print(" style=\"background-color: "); 98 Utils.write(device, component.getFilledColor()); 99 device.print(";\""); 100 } 101 device.print(">"); 102 final String completeWidth = String.valueOf(Math.round(width * component.getPercentComplete())); 103 device.print("<img"); 104 Utils.optAttribute(device, "src", BLIND_ICON.getURL()); 105 Utils.optAttribute(device, "width", completeWidth); 106 Utils.optAttribute(device, "height", String.valueOf(height)); 107 device.print(" alt=\""); 108 device.print(BLIND_ICON.getIconTitle()); 109 device.print("\"/>"); 110 device.print("</td>"); 111 device.print("<td class=\"SLayout\""); 112 if (component.getUnfilledColor() != null) { 113 device.print(" style=\"background-color: "); 114 Utils.write(device, component.getUnfilledColor()); 115 device.print(";\""); 116 } 117 device.print(">"); 118 final String incompleteWidth = String.valueOf(Math.round(width * (1 - component.getPercentComplete()))); 119 device.print("<img"); 120 Utils.optAttribute(device, "src", BLIND_ICON.getURL()); 121 Utils.optAttribute(device, "width", incompleteWidth); 122 Utils.optAttribute(device, "height", String.valueOf(height)); 123 device.print(" alt=\""); 124 device.print(BLIND_ICON.getIconTitle()); 125 device.print("\"/>"); 126 device.print("</td></tr></table>"); 127 if (component.isBorderPainted()) { 128 device.print("</div>"); 129 } 130 131 if (component.isStringPainted()) { 132 device.print("<div style=\"width: 100%; text-align: center;\""); 133 if (style != null) { 134 device.print(" class=\""); 135 Utils.write(device, style); 136 device.print("_string\""); 137 } 138 device.print(">"); 139 Utils.write(device, component.getString()); 140 device.print("</div>"); 141 } 142 } 144 } 145 | Popular Tags |