1 14 package org.wings; 15 16 import org.apache.commons.logging.Log; 17 import org.apache.commons.logging.LogFactory; 18 import org.wings.plaf.DialogCG; 19 import org.wings.session.SessionManager; 20 21 29 public class SDialog extends SForm { 30 private final transient static Log log = LogFactory.getLog(SDialog.class); 31 32 35 public static final String CLOSE_ACTION = "CLOSE"; 36 37 40 public static final String DEFAULT_ACTION = "DEFAULT"; 41 42 45 protected String title; 46 47 protected SIcon icon = null; 48 49 private boolean closable = true; 50 private boolean closed = false; 51 52 55 protected SRootContainer owner = null; 56 57 58 62 public SDialog() { 63 } 64 65 66 71 public SDialog(SFrame owner) { 72 this.owner = owner; 73 } 74 75 81 public SDialog(SFrame owner, String title) { 82 this.owner = owner; 83 this.title = title; 84 } 85 86 public void setTitle(String t) { 87 String oldTitle = title; 88 title = t; 89 if ((title == null && oldTitle != null) || 90 (title != null && !title.equals(oldTitle))) 91 reload(); 92 } 93 94 public String getTitle() { 95 return title; 96 } 97 98 99 public void setIcon(SIcon i) { 100 if (i != icon || i != null && !i.equals(icon)) { 101 icon = i; 102 reload(); 103 } 104 } 105 106 107 public SIcon getIcon() { 108 return icon; 109 } 110 111 public void setClosable(boolean v) { 112 boolean old = closable; 113 closable = v; 114 if (old != closable) 115 reload(); 116 } 117 118 public boolean isClosable() { 119 return closable; 120 } 121 122 public void setClosed(boolean v) { 123 v &= isClosable(); 124 boolean old = closed; 125 closed = v; 126 if (old != closed) 127 reload(); 128 } 129 130 public boolean isClosed() { 131 return closed; 132 } 133 134 137 public void dispose() { 138 if (visible) 139 hide(); 140 removeAll(); 141 } 142 143 146 public void hide() { 147 log.debug("hide dialog"); 148 if (owner != null) 149 owner.popDialog(); 150 visible = false; 151 } 152 153 public void setVisible(boolean visible) { 154 if (visible) { 155 if (owner != null) show(owner); 156 } else { 157 if (isVisible()) hide(); 158 } 159 super.setVisible(visible); 160 } 161 162 165 protected void setFrame(SRootContainer f) { 166 owner = f; 167 } 168 169 177 public void show(SComponent c) { 178 log.debug("show dialog"); 179 if (c == null) 180 c = SessionManager.getSession().getRootFrame(); 181 182 SContainer frame = null; 183 if (c instanceof SContainer) 184 frame = (SContainer) c; 185 else 186 frame = c.getParent(); 187 188 while (frame != null && !(frame instanceof SRootContainer)) { 190 frame = frame.getParent(); 191 } 192 193 if (frame == null) { 194 frame = SessionManager.getSession().getRootFrame(); 195 } 196 197 if (frame == null) { 198 throw new IllegalArgumentException ("Component has no root container"); 199 } 200 owner = (SRootContainer) frame; 201 owner.pushDialog(this); 202 } 203 204 public void processLowLevelEvent(String action, String [] values) { 206 processKeyEvents(values); 207 208 try { 210 switch (new Integer (values[0]).intValue()) { 211 case org.wings.event.SInternalFrameEvent.INTERNAL_FRAME_CLOSED: 212 setClosed(true); 213 actionCommand = CLOSE_ACTION; 214 break; 215 216 default: 217 actionCommand = DEFAULT_ACTION; 219 } 220 } catch (NumberFormatException ex) { 221 } 223 SForm.addArmedComponent(this); } 225 226 public void fireFinalEvents() { 227 } 228 229 public void setCG(DialogCG cg) { 230 super.setCG(cg); 231 } 232 } 233 | Popular Tags |