1 14 package org.wings.plaf.css; 15 16 17 import org.wings.*; 18 import org.wings.event.SInternalFrameEvent; 19 import org.wings.io.Device; 20 import org.wings.plaf.CGManager; 21 import org.wings.session.SessionManager; 22 23 import java.io.IOException ; 24 25 public class DialogCG extends org.wings.plaf.css.FormCG implements 26 org.wings.plaf.DialogCG { 27 28 30 private SIcon closeIcon; 32 33 36 public DialogCG() { 37 final CGManager manager = SessionManager.getSession().getCGManager(); 38 setCloseIcon((SIcon) manager.getObject("DialogCG.closeIcon", SIcon.class)); 39 } 40 41 private void writeIcon(Device device, SIcon icon) throws IOException { 42 device.print("<img"); 43 Utils.optAttribute(device, "src", icon.getURL()); 44 Utils.optAttribute(device, "width", icon.getIconWidth()); 45 Utils.optAttribute(device, "height", icon.getIconHeight()); 46 device.print(" alt=\""); 47 device.print(icon.getIconTitle()); 48 device.print("\"/>"); 49 } 50 51 private void writeWindowIcon(Device device, SDialog dialog, 52 int event, SIcon icon) throws IOException { 53 boolean showAsFormComponent = dialog.getShowAsFormComponent(); 54 55 RequestURL addr = dialog.getRequestURL(); 56 addr.addParameter(Utils.event(dialog), event); 57 58 device.print("<th"); 59 Utils.optAttribute(device, "width", getIconWidth(icon)); 60 device.print(">"); 61 62 device.print("<a HREF=\"") 71 .print(dialog.getRequestURL() 72 .addParameter(Utils.event(dialog) + "=" + event).toString()) 73 .print("\">"); 74 75 writeIcon(device, icon); 76 77 device.print("</a>"); 81 82 device.print("</th>"); 83 } 84 85 private String getIconWidth(SIcon icon) { 86 if (icon.getIconWidth() == -1) 87 return "0%"; 88 else 89 return "" + icon.getIconWidth(); 90 } 91 92 public void write(final Device device, final SComponent component) 93 throws IOException { 94 SDialog dialog = (SDialog) component; 95 device.print("<table border=\"0\" width=\"100%\" height=\"100%\" class=\"SLayout\"><tr><td align=\"center\" valign=\"middle\" class=\"SLayout\">"); 96 super.writeContent(device, dialog); 97 device.print("</td></tr></table>\n"); 98 } 99 100 protected void renderContainer(Device device, SForm component) throws IOException { 101 super.write(device, component); 102 } 103 104 protected void writeContent(final Device device, final SComponent component) throws IOException { 105 final SDialog dialog = (SDialog) component; 106 107 String text = dialog.getTitle(); 108 int columns = 0; 109 if (text == null) 110 text = "Dialog"; 111 112 device.print("<table class=\"SLayout\""); 113 Utils.printCSSInlineFullSize(device, component.getPreferredSize()); 114 device.print(">\n<tr>"); 115 116 if (dialog.getIcon() != null) { 118 SIcon icon = dialog.getIcon(); 119 device.print("<th class=\"SLayout\""); 120 Utils.optAttribute(device, "width", getIconWidth(icon)); 121 device.print(">"); 122 writeIcon(device, icon); 123 device.print("</th>"); 124 ++columns; 125 } 126 127 device.print("<th col=\"title\" class=\"SLayout\"> "); 128 Utils.write(device, text); 129 device.print("</th>"); 130 ++columns; 131 132 if (dialog.isClosable() && closeIcon != null) { 133 writeWindowIcon(device, dialog, 134 SInternalFrameEvent.INTERNAL_FRAME_CLOSED, closeIcon); 135 ++columns; 136 } 137 device.print("</tr>"); 138 139 device.print("<tr><td class=\"SLayout\" colspan=\""); 141 device.print(String.valueOf(columns)); 142 device.print("\">"); 143 Utils.renderContainer(device, dialog); 144 device.print("</td></tr>"); 145 device.print("</table>\n"); 146 } 147 148 public SIcon getCloseIcon() { 149 return closeIcon; 150 } 151 152 public void setCloseIcon(SIcon closeIcon) { 153 this.closeIcon = closeIcon; 154 } 155 } 156 | Popular Tags |