1 14 package org.wings.plaf.css; 15 16 17 import org.apache.commons.logging.Log; 18 import org.apache.commons.logging.LogFactory; 19 import org.wings.*; 20 import org.wings.event.SInternalFrameEvent; 21 import org.wings.io.Device; 22 import org.wings.plaf.CGManager; 23 import org.wings.session.SessionManager; 24 25 import java.io.IOException ; 26 27 public class InternalFrameCG extends AbstractComponentCG implements 28 org.wings.plaf.InternalFrameCG { 29 private final static transient Log log = LogFactory.getLog(InternalFrameCG.class); 30 protected static final String WINDOWICON_CLASSNAME = "WindowIcon"; 31 protected static final String BUTTONICON_CLASSNAME = "WindowButton"; 32 private SIcon closeIcon; 33 private SIcon deiconifyIcon; 34 private SIcon iconifyIcon; 35 private SIcon maximizeIcon; 36 private SIcon unmaximizeIcon; 37 38 41 public InternalFrameCG() { 42 final CGManager manager = SessionManager.getSession().getCGManager(); 43 44 setCloseIcon((SIcon) manager.getObject("InternalFrameCG.closeIcon", SIcon.class)); 45 setDeiconifyIcon((SIcon) manager.getObject("InternalFrameCG.deiconifyIcon", SIcon.class)); 46 setIconifyIcon((SIcon) manager.getObject("InternalFrameCG.iconifyIcon", SIcon.class)); 47 setMaximizeIcon((SIcon) manager.getObject("InternalFrameCG.maximizeIcon", SIcon.class)); 48 setUnmaximizeIcon((SIcon) manager.getObject("InternalFrameCG.unmaximizeIcon", SIcon.class)); 49 } 50 51 public void installCG(SComponent component) { 52 super.installCG(component); 53 } 54 55 protected void writeIcon(Device device, SIcon icon, String cssClass) throws IOException { 56 device.print("<img"); 57 if (cssClass != null) { 58 device.print(" class=\""); 59 device.print(cssClass); 60 device.print("\""); 61 } 62 Utils.optAttribute(device, "src", icon.getURL()); 63 Utils.optAttribute(device, "width", icon.getIconWidth()); 64 Utils.optAttribute(device, "height", icon.getIconHeight()); 65 device.print(" alt=\""); 66 device.print(icon.getIconTitle()); 67 device.print("\"/>"); 68 } 69 70 protected void writeWindowIcon(Device device, SInternalFrame frame, 71 int event, SIcon icon, String cssClass) throws IOException { 72 boolean showAsFormComponent = frame.getShowAsFormComponent(); 73 74 77 device.print("<a"); 89 if (cssClass != null) { 90 device.print(" class=\""); 91 device.print(cssClass); 92 device.print("\""); 93 } 94 device.print(" HREF=\"").print( 95 frame.getRequestURL().addParameter( 96 Utils.event(frame) + "=" + event).toString()) 97 .print("\">"); 98 writeIcon(device, icon, null); 100 101 device.print("</a>"); 105 } 107 108 109 public void writeContent(final Device device, final SComponent _c) 110 throws IOException { 111 final SInternalFrame component = (SInternalFrame) _c; 112 113 SInternalFrame frame = component; 114 115 writeWindowBar(device, frame); 116 117 if (!frame.isIconified()) { 119 device.print("<div class=\"WindowContent\">"); 120 Utils.renderContainer(device, frame); 121 device.print("</div>"); 122 } 123 } 124 125 132 protected void writeWindowBar(final Device device, SInternalFrame frame) throws IOException { 133 String text = frame.getTitle(); 134 if (text == null) 135 text = "wingS"; 136 device.print("<div class=\"WindowBar\">"); 137 if (frame.isIconified()) { 138 if (frame.getIcon() != null) { 140 writeIcon(device, frame.getIcon(), WINDOWICON_CLASSNAME); 141 } 142 if (deiconifyIcon != null) { 143 device.print(text); 144 writeWindowIcon(device, frame, 145 SInternalFrameEvent.INTERNAL_FRAME_DEICONIFIED, deiconifyIcon, "DeiconifyButton"); 146 } else { 147 device.print("<a HREF=\"").print( 148 frame.getRequestURL().addParameter( 149 Utils.event(frame) + "=" + SInternalFrameEvent.INTERNAL_FRAME_DEICONIFIED).toString()) 150 .print("\">"); 151 device.print(text); 152 device.print("</a>"); 153 } 154 } else { 155 if (frame.isClosable() && closeIcon != null) { 158 writeWindowIcon(device, frame, 159 SInternalFrameEvent.INTERNAL_FRAME_CLOSED, closeIcon, BUTTONICON_CLASSNAME); 160 } 161 if (frame.isIconifyable() && iconifyIcon != null) { 162 writeWindowIcon(device, frame, 163 SInternalFrameEvent.INTERNAL_FRAME_ICONIFIED, iconifyIcon, BUTTONICON_CLASSNAME); 164 } 165 if (frame.isMaximizable() && !frame.isMaximized() && maximizeIcon != null) { 166 writeWindowIcon(device, frame, 167 SInternalFrameEvent.INTERNAL_FRAME_MAXIMIZED, maximizeIcon, BUTTONICON_CLASSNAME); 168 } 169 device.print("<div class=\"WindowBar_title\">"); 170 if (frame.getIcon() != null) { 172 writeIcon(device, frame.getIcon(), WINDOWICON_CLASSNAME); 173 } 174 device.print(text); 175 device.print("</div>"); 176 } 177 device.print("</div>"); 178 } 179 180 private String getIconWidth(SIcon icon) { 181 if (icon.getIconWidth() == -1) 182 return "0%"; 183 else 184 return "" + icon.getIconWidth(); 185 } 186 187 188 public SIcon getCloseIcon() { 189 return closeIcon; 190 } 191 192 public void setCloseIcon(SIcon closeIcon) { 193 this.closeIcon = closeIcon; 194 } 195 196 public SIcon getDeiconifyIcon() { 197 return deiconifyIcon; 198 } 199 200 public void setDeiconifyIcon(SIcon deiconifyIcon) { 201 this.deiconifyIcon = deiconifyIcon; 202 } 203 204 public SIcon getIconifyIcon() { 205 return iconifyIcon; 206 } 207 208 public void setIconifyIcon(SIcon iconifyIcon) { 209 this.iconifyIcon = iconifyIcon; 210 } 211 212 public SIcon getMaximizeIcon() { 213 return maximizeIcon; 214 } 215 216 public void setMaximizeIcon(SIcon maximizeIcon) { 217 this.maximizeIcon = maximizeIcon; 218 } 219 220 public SIcon getUnmaximizeIcon() { 221 return unmaximizeIcon; 222 } 223 224 public void setUnmaximizeIcon(SIcon unmaximizeIcon) { 225 this.unmaximizeIcon = unmaximizeIcon; 226 } 227 228 } 229 | Popular Tags |