1 14 package org.wings; 15 16 17 import org.apache.commons.logging.Log; 18 import org.apache.commons.logging.LogFactory; 19 import org.wings.border.SBorder; 20 import org.wings.event.SComponentEvent; 21 import org.wings.event.SComponentListener; 22 import org.wings.event.SParentFrameEvent; 23 import org.wings.event.SParentFrameListener; 24 import org.wings.event.SRenderEvent; 25 import org.wings.event.SRenderListener; 26 import org.wings.io.Device; 27 import org.wings.plaf.ComponentCG; 28 import org.wings.script.ScriptListener; 29 import org.wings.session.LowLevelEventDispatcher; 30 import org.wings.session.Session; 31 import org.wings.session.SessionManager; 32 import org.wings.style.CSSAttributeSet; 33 import org.wings.style.CSSProperty; 34 import org.wings.style.CSSSelector; 35 import org.wings.style.CSSStyle; 36 import org.wings.style.CSSStyleSheet; 37 import org.wings.style.Style; 38 import org.wings.util.ComponentVisitor; 39 40 import javax.swing.*; 41 import javax.swing.event.EventListenerList ; 42 import java.awt.*; 43 import java.awt.event.ActionEvent ; 44 import java.beans.BeanInfo ; 45 import java.beans.Introspector ; 46 import java.beans.PropertyDescriptor ; 47 import java.io.IOException ; 48 import java.io.Serializable ; 49 import java.lang.reflect.Array ; 50 import java.lang.reflect.Method ; 51 import java.util.ArrayList ; 52 import java.util.Arrays ; 53 import java.util.Collection ; 54 import java.util.Collections ; 55 import java.util.EventListener ; 56 import java.util.HashMap ; 57 import java.util.Iterator ; 58 import java.util.Map ; 59 60 66 public abstract class SComponent 67 implements Cloneable , Serializable , Renderable { 68 private static final Object [] EMPTY_OBJECT_ARRAY = new Object [0]; 69 70 private static final Log log = LogFactory.getLog(SComponent.class); 71 72 73 private String name; 74 75 78 private transient Session session; 79 80 84 protected transient ComponentCG cg; 85 86 89 protected int verticalAlignment = SConstants.NO_ALIGN; 90 91 94 protected int horizontalAlignment = SConstants.NO_ALIGN; 95 96 99 protected String style; 100 101 104 protected Map dynamicStyles; 105 106 109 protected boolean visible = true; 110 111 114 protected boolean enabled = true; 115 116 119 protected SContainer parent; 120 121 124 protected SFrame parentFrame; 125 126 129 protected SBorder border; 130 131 134 protected String tooltip; 135 136 139 protected int focusTraversalIndex = -1; 140 141 144 protected SDimension preferredSize; 145 146 152 private boolean fireComponentChangeEvents = false; 153 154 private boolean fireParentFrameChangeEvents = false; 155 156 private EventListenerList listeners; 157 158 private Boolean useNamedEvents; 159 160 private boolean showAsFormComponent = true; 161 162 private SPopupMenu popupMenu; 163 164 private boolean inheritsPopupMenu; 165 166 private InputMap inputMap; 167 168 private ActionMap actionMap; 169 170 private final Map actionEvents = new HashMap (); 171 172 private final CSSSelector thisComponentCssSelector = new CSSSelector(this); 173 174 178 public SComponent() { 179 updateCG(); 180 } 181 182 public SBorder getBorder() { 183 return border; 184 } 185 186 public void setBorder(SBorder border) { 187 reloadIfChange(this.border, border); 188 this.border = border; 189 } 190 191 196 public final SContainer getParent() { 197 return parent; 198 } 199 200 205 public void setParent(SContainer parent) { 206 reloadIfChange(this.parent, parent); 207 this.parent = parent; 208 if (parent != null) 209 setParentFrame(parent.getParentFrame()); 210 else 211 setParentFrame(null); 212 } 213 214 219 protected void setParentFrame(SFrame parentFrame) { 220 if (this.parentFrame == parentFrame) { 221 return; 222 } 223 224 if (this.parentFrame != null) { 225 unregister(); 226 fireParentFrameEvent(new SParentFrameEvent(this, SParentFrameEvent.PARENTFRAME_REMOVED, this.parentFrame)); 227 } 228 229 this.parentFrame = parentFrame; 230 231 if (this.parentFrame != null) { 232 register(); 233 fireParentFrameEvent(new SParentFrameEvent(this, SParentFrameEvent.PARENTFRAME_ADDED, this.parentFrame)); 235 } 236 237 if (this.popupMenu != null) { 238 popupMenu.setParentFrame(parentFrame); 239 } 240 241 reload(); 242 } 243 244 public void setInheritsPopupMenu(boolean inheritsPopupMenu) { 245 reloadIfChange(this.inheritsPopupMenu, inheritsPopupMenu); 246 this.inheritsPopupMenu = inheritsPopupMenu; 247 } 248 249 public boolean getInheritsPopupMenu() { 250 return inheritsPopupMenu; 251 } 252 253 public void setComponentPopupMenu(SPopupMenu popupMenu) { 254 reloadIfChange(this.popupMenu, popupMenu); 255 if (this.popupMenu != null) 256 this.popupMenu.setParentFrame(null); 257 this.popupMenu = popupMenu; 258 if (this.popupMenu != null) 259 this.popupMenu.setParentFrame(getParentFrame()); 260 } 261 262 public SPopupMenu getComponentPopupMenu() { 263 264 return popupMenu; 282 } 283 284 public boolean hasComponentPopupMenu() { 285 return popupMenu != null; 286 } 287 288 public RequestURL getRequestURL() { 289 SFrame p = getParentFrame(); 290 if (p == null) 291 throw new IllegalStateException ("no parent frame"); 292 293 return p.getRequestURL(); 294 } 295 296 305 public void setPreferredSize(SDimension preferredSize) { 306 reloadIfChange(this.preferredSize, preferredSize); 307 this.preferredSize = preferredSize; 308 } 309 310 315 public SDimension getPreferredSize() { 316 return preferredSize; 317 } 318 319 320 330 public final void addComponentListener(SComponentListener l) { 331 addEventListener(SComponentListener.class, l); 332 fireComponentChangeEvents = true; 333 } 334 335 347 public final void removeComponentListener(SComponentListener l) { 348 removeEventListener(SComponentListener.class, l); 349 } 350 351 361 public final void addParentFrameListener(SParentFrameListener l) { 362 addEventListener(SParentFrameListener.class, l); 363 fireParentFrameChangeEvents = true; 364 } 365 366 378 public final void removeParentFrameListener(SParentFrameListener l) { 379 removeEventListener(SParentFrameListener.class, l); 380 } 381 382 388 protected void fireComponentChangeEvent(SComponentEvent aEvent) { 389 Object [] listeners = getListenerList(); 393 for (int i = listeners.length - 2; i >= 0; i -= 2) { 394 if (listeners[i] == SComponentListener.class) { 395 processComponentEvent((SComponentListener) listeners[i + 1], 397 aEvent); 398 } 399 } 400 401 } 402 403 409 private void fireParentFrameEvent(SParentFrameEvent aEvent) { 410 if (fireParentFrameChangeEvents) { 412 Object [] listeners = getListenerList(); 416 for (int i = listeners.length - 2; i >= 0; i -= 2) { 417 if (listeners[i] == SParentFrameListener.class) { 418 processParentFrameEvent((SParentFrameListener) listeners[i + 1], 420 aEvent); 421 } 422 } 423 } 424 425 } 426 427 434 private void processParentFrameEvent(SParentFrameListener listener, SParentFrameEvent event) { 435 int id = event.getID(); 436 switch (id) { 437 case SParentFrameEvent.PARENTFRAME_ADDED: 438 listener.parentFrameAdded(event); 439 break; 440 case SParentFrameEvent.PARENTFRAME_REMOVED: 441 listener.parentFrameRemoved(event); 442 break; 443 } 444 } 445 446 464 protected void processComponentEvent(SComponentListener listener, SComponentEvent e) { 465 int id = e.getID(); 466 switch (id) { 467 case SComponentEvent.COMPONENT_RESIZED: 468 listener.componentResized(e); 469 break; 470 case SComponentEvent.COMPONENT_MOVED: 471 listener.componentMoved(e); 472 break; 473 case SComponentEvent.COMPONENT_SHOWN: 474 listener.componentShown(e); 475 break; 476 case SComponentEvent.COMPONENT_HIDDEN: 477 listener.componentHidden(e); 478 break; 479 } 480 } 481 482 494 public final void addScriptListener(ScriptListener listener) { 495 ScriptListener[] listeners = getScriptListeners(); 496 for (int i = 0; i < listeners.length; i++) { 497 if (listeners[i].equals(listener)) { 498 return; 499 } 500 } 501 addEventListener(ScriptListener.class, listener); 502 } 503 504 505 517 public final void removeScriptListener(ScriptListener listener) { 518 removeEventListener(ScriptListener.class, listener); 519 } 520 521 public ScriptListener[] getScriptListeners() { 522 return (ScriptListener[]) getListeners(ScriptListener.class); 523 } 524 525 public void setName(String name) { 526 if (name != null) { 527 if (!Character.isJavaIdentifierStart(name.charAt(0)) || name.charAt(0) == '_') 528 throw new IllegalArgumentException (name + " is not a valid identifier"); 529 for (int i=1; i < name.length(); i++) 530 if (!Character.isJavaIdentifierPart(name.charAt(i)) || name.charAt(0) == '_') 531 throw new IllegalArgumentException (name + " is not a valid identifier"); 532 } 533 reloadIfChange(this.name, name); 534 this.name = name; 535 } 536 537 public final String getName() { 538 if (name == null) 539 name = getSession().createUniqueId(); 540 return name; 541 } 542 543 548 public final Session getSession() { 549 if (session == null) { 550 session = SessionManager.getSession(); 551 } 552 553 return session; 554 } 555 556 561 public final LowLevelEventDispatcher getDispatcher() { 562 return getSession().getDispatcher(); 563 } 564 565 569 private final void unregister() { 570 if (getDispatcher() != null && this instanceof LowLevelEventListener) { 571 getDispatcher().unregister((LowLevelEventListener) this); 572 } 573 } 574 575 579 private final void register() { 580 if (getDispatcher() != null && this instanceof LowLevelEventListener) { 581 getDispatcher().register((LowLevelEventListener) this); 582 } 583 } 584 585 590 public void setStyle(String value) { 591 reloadIfChange(style, value); 592 this.style = value; 593 } 594 595 598 public String getStyle() { 599 return style; 600 } 601 602 public void addDynamicStyle(Style style) { 603 if (dynamicStyles == null) 604 dynamicStyles = new HashMap (4); 605 dynamicStyles.put(style.getSelector(), style); 606 reload(); 607 } 608 609 public void removeDynamicStyle(String selector) { 610 if (dynamicStyles == null) 611 return; 612 dynamicStyles.remove(selector); 613 reload(); 614 } 615 616 public Style getDynamicStyle(Object selector) { 617 if (dynamicStyles == null) 618 return null; 619 return (Style) dynamicStyles.get(selector); 620 } 621 622 public void setDynamicStyles(Collection dynamicStyles) { 623 if (dynamicStyles == null) 624 return; 625 if (this.dynamicStyles == null) 626 this.dynamicStyles = new HashMap (4); 627 for (Iterator iterator = dynamicStyles.iterator(); iterator.hasNext();) { 628 Style style = (Style) iterator.next(); 629 this.dynamicStyles.put(style.getSelector(), style); 630 } 631 reload(); 632 } 633 634 public Collection getDynamicStyles() { 635 if (dynamicStyles == null || dynamicStyles.size() == 0) 636 return null; 637 return Collections.unmodifiableCollection(dynamicStyles.values()); 638 } 639 640 641 public void setAttribute(String cssPropertyName, String value) { 642 setAttribute(thisComponentCssSelector, new CSSProperty(cssPropertyName), value); 643 } 644 645 public void setAttribute(CSSProperty property, String propertyValue) { 646 setAttribute(thisComponentCssSelector, property, propertyValue); 647 } 648 649 public void setAttribute(CSSSelector selector, CSSProperty property, SIcon icon) { 650 setAttribute(selector, property, icon != null ? "url('"+icon.getURL().toString()+"')" : "none"); 651 } 652 653 public void setAttribute(CSSSelector selector, CSSProperty property, String propertyValue) { 654 CSSStyle style = (CSSStyle) getDynamicStyle(selector); 655 if (style == null) { 656 addDynamicStyle(new CSSStyle(selector, property, propertyValue)); 657 reload(); 658 } else { 659 String old = style.put(property, propertyValue); 660 reloadIfChange(old, propertyValue); 661 } 662 } 663 664 public void setAttributes(CSSAttributeSet attributes) { 665 log.debug("attributes = " + attributes); 666 setAttributes(thisComponentCssSelector, attributes); 667 } 668 669 public void setAttributes(CSSSelector selector, CSSAttributeSet attributes) { 670 CSSStyle style = (CSSStyle) getDynamicStyle(selector); 671 if (style == null) { 672 addDynamicStyle(new CSSStyle(selector, attributes)); 673 reload(); 674 } else { 675 boolean changed = style.putAll(attributes); 676 if (changed) 677 reload(); 678 } 679 } 680 681 686 public Color getBackground() { 687 return dynamicStyles == null || dynamicStyles.get(thisComponentCssSelector) == null ? null : CSSStyleSheet.getBackground((CSSAttributeSet) dynamicStyles.get(thisComponentCssSelector)); 688 } 689 690 695 public void setBackground(Color color) { 696 setAttribute(thisComponentCssSelector, CSSProperty.BACKGROUND_COLOR, CSSStyleSheet.getAttribute(color)); 697 } 698 699 704 public Color getForeground() { 705 return dynamicStyles == null || dynamicStyles.get(thisComponentCssSelector) == null ? null : CSSStyleSheet.getForeground((CSSAttributeSet) dynamicStyles.get(thisComponentCssSelector)); 706 } 707 708 713 public void setForeground(Color color) { 714 setAttribute(thisComponentCssSelector, CSSProperty.COLOR, CSSStyleSheet.getAttribute(color)); 715 } 716 717 722 public void setFont(SFont font) { 723 setAttributes(thisComponentCssSelector, CSSStyleSheet.getAttributes(font)); 724 } 725 726 731 public SFont getFont() { 732 return dynamicStyles == null || dynamicStyles.get(thisComponentCssSelector) == null ? null : CSSStyleSheet.getFont((CSSAttributeSet) dynamicStyles.get(thisComponentCssSelector)); 733 } 734 735 740 public void setVisible(boolean visible) { 741 boolean old = this.visible; 742 this.visible = visible; 743 if (fireComponentChangeEvents && (visible != old)) { 744 fireComponentChangeEvent(new SComponentEvent(this, visible 745 ? SComponentEvent.COMPONENT_SHOWN 746 : SComponentEvent.COMPONENT_HIDDEN)); 747 } 748 } 749 750 755 public boolean isVisible() { 756 return visible; 757 } 758 759 764 public void setEnabled(boolean enabled) { 765 this.enabled = enabled; 766 } 767 768 773 public boolean isEnabled() { 774 return enabled; 775 } 776 777 781 public final void reload() { 782 getSession().getReloadManager().reload(this); 783 } 784 785 793 protected final void reloadIfChange(Object oldVal, Object newVal) { 794 if (!((oldVal == newVal) || (oldVal != null && oldVal.equals(newVal)))) { 795 reload(); 797 } 798 } 799 800 808 protected final void reloadIfChange(int oldVal, int newVal) { 809 if (oldVal != newVal) { 810 reload(); 811 } 812 } 813 814 822 protected final void reloadIfChange(boolean oldVal, boolean newVal) { 823 if (oldVal != newVal) { 824 reload(); 825 } 826 } 827 828 836 protected final void reloadIfChange(byte oldVal, byte newVal) { 837 if (oldVal != newVal) { 838 reload(); 839 } 840 } 841 842 850 protected final void reloadIfChange(short oldVal, short newVal) { 851 if (oldVal != newVal) { 852 reload(); 853 } 854 } 855 856 864 protected final void reloadIfChange(long oldVal, long newVal) { 865 if (oldVal != newVal) { 866 reload(); 867 } 868 } 869 870 878 protected final void reloadIfChange(float oldVal, float newVal) { 879 if (oldVal != newVal) { 880 reload(); 881 } 882 } 883 884 892 protected final void reloadIfChange(double oldVal, double newVal) { 893 if (oldVal != newVal) { 894 reload(); 895 } 896 } 897 898 906 protected final void reloadIfChange(char oldVal, char newVal) { 907 if (oldVal != newVal) { 908 reload(); 909 } 910 } 911 912 920 public void write(Device s) throws IOException { 921 try { 922 if (visible) 923 cg.write(s, this); 924 } catch (IOException se) { 925 log.debug( "Socket exception during code generation for " + getClass().getName() + se); 927 } catch (Throwable t) { 928 log.warn( "Exception during code generation for " + getClass().getName(), t); 929 } 930 } 931 932 936 public String toString() { 937 return paramString(); 938 } 939 940 941 947 public String paramString() { 948 StringBuffer buffer = new StringBuffer (getClass().getName()); 949 buffer.append("["); 950 951 try { 952 BeanInfo info = Introspector.getBeanInfo(getClass()); 953 PropertyDescriptor [] descriptors = info.getPropertyDescriptors(); 954 955 boolean first = true; 956 for (int i = 0; i < descriptors.length; i++) { 957 try { 958 Method getter = descriptors[i].getReadMethod(); 959 if (getter == null || getter.getName().startsWith("getParent")) 960 continue; 961 Object value = getter.invoke(this, null); 963 if (first) 964 first = false; 965 else 966 buffer.append(","); 967 buffer.append(descriptors[i].getName() + "=" + value); 968 } catch (Exception e) { 969 } 970 } 971 } catch (Exception e) { 972 } 973 974 buffer.append("]"); 975 return buffer.toString(); 976 } 977 978 984 private String encodeLowLevelEventId(String lowLevelEventId) { 985 if (getParentFrame() != null) 986 if (!(this instanceof LowLevelEventListener) || 987 ((LowLevelEventListener) this).isEpochCheckEnabled()) { 988 return (getParentFrame().getEventEpoch() 989 + SConstants.UID_DIVIDER 990 + lowLevelEventId); 991 } 992 return lowLevelEventId; 993 } 994 995 1001 public final String getEncodedLowLevelEventId() { 1002 if (getUseNamedEvents() && getName() != null) 1003 return name; 1004 else 1005 return encodeLowLevelEventId(getLowLevelEventId()); 1006 } 1007 1008 private boolean getUseNamedEvents() { 1009 if (useNamedEvents == null) { 1010 useNamedEvents = ("true".equalsIgnoreCase((String ) getSession().getProperty("wings.event.usenames"))) 1011 ? Boolean.TRUE : Boolean.FALSE; 1012 } 1013 return useNamedEvents.booleanValue(); 1014 } 1015 1016 1020 public String getLowLevelEventId() { 1021 return getName(); 1022 } 1023 1024 1029 public SFrame getParentFrame() { 1030 return parentFrame; 1031 } 1032 1033 1038 public final boolean getResidesInForm() { 1039 SComponent parent = getParent(); 1040 1041 boolean actuallyDoes = false; 1042 while (parent != null && !(actuallyDoes = (parent instanceof SForm))) { 1043 parent = parent.getParent(); 1044 } 1045 1046 return actuallyDoes; 1047 } 1048 1049 1054 public void setToolTipText(String t) { 1055 tooltip = t; 1056 } 1057 1058 1063 public String getToolTipText() { 1064 return tooltip; 1065 } 1066 1067 1080 public void setFocusTraversalIndex(int index) { 1081 focusTraversalIndex = index; 1082 } 1083 1084 1089 public int getFocusTraversalIndex() { 1090 return focusTraversalIndex; 1091 } 1092 1093 1098 public Object clone() { 1099 try { 1100 return super.clone(); 1101 } catch (Exception e) { 1102 e.printStackTrace(); 1103 return null; 1104 } 1105 } 1106 1107 1113 public int getHorizontalAlignment() { 1114 return horizontalAlignment; 1115 } 1116 1117 1123 public void setHorizontalAlignment(int alignment) { 1124 horizontalAlignment = alignment; 1125 } 1126 1127 1133 public void setVerticalAlignment(int alignment) { 1134 verticalAlignment = alignment; 1135 } 1136 1137 1143 public int getVerticalAlignment() { 1144 return verticalAlignment; 1145 } 1146 1147 private Map clientProperties; 1148 1149 1154 private Map getClientProperties() { 1155 if (clientProperties == null) { 1156 clientProperties = new HashMap (2); 1157 } 1158 return clientProperties; 1159 } 1160 1161 1162 1170 public final Object getClientProperty(Object key) { 1171 if (clientProperties == null) { 1172 return null; 1173 } else { 1174 return getClientProperties().get(key); 1175 } 1176 } 1177 1178 1200 public final void putClientProperty(Object key, Object value) { 1201 if (value != null) { 1202 getClientProperties().put(key, value); 1203 } else { 1204 getClientProperties().remove(key); 1205 } 1206 } 1207 1208 1209 1223 public void setCG(ComponentCG newCG) { 1224 1229 if (cg != null) { 1230 cg.uninstallCG(this); 1231 } 1232 ComponentCG oldCG = cg; 1233 cg = newCG; 1234 if (cg != null) { 1235 cg.installCG(this); 1236 } 1237 reloadIfChange(cg, oldCG); 1238 } 1239 1240 1245 public ComponentCG getCG() { 1246 return cg; 1247 } 1248 1249 1254 public void updateCG() { 1255 if (getSession() == null) { 1256 log.warn("no session yet."); 1257 } else if (getSession().getCGManager() == null) { 1258 log.warn("no CGManager"); 1259 } else { 1260 setCG(getSession().getCGManager().getCG(this)); 1261 } 1262 } 1263 1264 1270 public void invite(ComponentVisitor visitor) 1271 throws Exception { 1272 visitor.visit(this); 1273 } 1274 1275 1279 protected static final boolean isDifferent(Object oldObject, 1280 Object newObject) { 1281 if (oldObject == newObject) 1282 return false; 1283 1284 if (oldObject == null) 1285 return true; 1286 1287 return !oldObject.equals(newObject); 1288 } 1289 1290 protected final void addEventListener(Class type, EventListener listener) { 1291 if (listeners == null) { 1292 listeners = new EventListenerList (); 1293 } 1294 listeners.add(type, listener); 1295 } 1296 1297 protected final void removeEventListener(Class type, EventListener listener) { 1298 if (listeners != null) { 1299 listeners.remove(type, listener); 1300 } 1301 } 1302 1303 1310 protected final int getListenerCount(Class type) { 1311 if (listeners != null) { 1312 return listeners.getListenerCount(type); 1313 } else { 1314 return 0; 1315 } 1316 } 1317 1318 1327 protected final Object [] getListenerList() { 1328 if (listeners == null) { 1329 return EMPTY_OBJECT_ARRAY; 1330 } else { 1331 return listeners.getListenerList(); 1332 } } 1334 1335 1342 protected final EventListener [] getListeners(Class type) { 1343 if (listeners != null) { 1344 return listeners.getListeners(type); 1345 } else { 1346 return (EventListener []) Array.newInstance(type, 0); 1347 } 1348 } 1349 1350 1351 private transient SRenderEvent renderEvent; 1352 1353 1356 private boolean fireRenderEvents = false; 1357 1358 public static final int START_RENDERING = 1; 1359 public static final int DONE_RENDERING = 2; 1360 1361 public final void addRenderListener(SRenderListener l) { 1362 addEventListener(SRenderListener.class, l); 1363 fireRenderEvents = true; 1364 } 1365 1366 public final void removeRenderListener(SRenderListener l) { 1367 removeEventListener(SRenderListener.class, l); 1368 } 1369 1370 public final void fireRenderEvent(int type) { 1371 if (fireRenderEvents) { 1372 Object [] listeners = getListenerList(); 1376 for (int i = listeners.length - 2; i >= 0; i -= 2) { 1377 if (listeners[i] == SRenderListener.class) { 1378 if (renderEvent == null) { 1380 renderEvent = new SRenderEvent(this); 1381 } 1383 switch (type) { 1384 case START_RENDERING: 1385 ((SRenderListener) listeners[i + 1]).startRendering(renderEvent); 1386 break; 1387 case DONE_RENDERING: 1388 ((SRenderListener) listeners[i + 1]).doneRendering(renderEvent); 1389 break; 1390 } 1391 } 1392 } 1393 } 1394 } 1395 1396 1404 public void scrollRectToVisible(Rectangle aRect) { 1405 if (parent != null) { 1406 parent.scrollRectToVisible(aRect); 1407 } 1408 } 1409 1410 1413 public void requestFocus() { 1414 if (getParentFrame() != null) { 1415 getParentFrame().setFocus(this); 1416 } 1417 } 1418 1419 public boolean isFocusOwner() { 1420 if (getParentFrame() != null) 1421 return this == getParentFrame().getFocus(); 1422 return false; 1423 } 1424 1425 1436 public void setShowAsFormComponent(boolean showAsFormComponent) { 1437 if (this.showAsFormComponent != showAsFormComponent) { 1438 this.showAsFormComponent = showAsFormComponent; 1439 reload(); 1440 } 1441 } 1442 1443 1449 public boolean getShowAsFormComponent() { 1450 return showAsFormComponent && getResidesInForm(); 1451 } 1452 1453 public void setActionMap(ActionMap actionMap) { 1454 this.actionMap = actionMap; 1455 } 1456 1457 public ActionMap getActionMap() { 1458 if (actionMap == null) 1459 actionMap = new ActionMap(); 1460 return actionMap; 1461 } 1462 1463 public void setInputMap(InputMap inputMap) { 1464 this.inputMap = inputMap; 1465 } 1466 1467 public InputMap getInputMap() { 1468 return inputMap; 1469 } 1470 1471 protected void processLowLevelEvent(String name, String [] values) { 1472 } 1473 1474 protected boolean processKeyEvents(String [] values) { 1475 if (actionMap == null) 1476 return false; 1477 1478 if (log.isDebugEnabled()) 1479 log.debug("processKeyEvents " + Arrays.asList(values)); 1480 1481 boolean arm = false; 1482 for (int i = 0; i < values.length; i++) { 1483 String value = values[i]; 1484 Action action = actionMap.get(value); 1485 if (action != null) { 1486 actionEvents.put(action, new ActionEvent (this, 0, value)); 1487 arm = true; 1488 } 1489 } 1490 if (arm) 1491 SForm.addArmedComponent((LowLevelEventListener) this); 1492 1493 return arm; 1494 } 1495 1496 public void fireFinalEvents() { 1497 fireKeyEvents(); 1498 } 1499 1500 protected void fireKeyEvents() { 1501 for (Iterator iterator = actionEvents.entrySet().iterator(); iterator.hasNext();) { 1502 Map.Entry entry = (Map.Entry ) iterator.next(); 1503 Action action = (Action) entry.getKey(); 1504 ActionEvent event = (ActionEvent ) entry.getValue(); 1505 action.actionPerformed(event); 1506 } 1507 actionEvents.clear(); 1508 } 1509 1510 1514 public void removeNotify() { 1515 } 1516 1517 public ArrayList getMenus() { 1518 ArrayList menus = new ArrayList (); 1519 if (isVisible()) { 1520 SPopupMenu pmenu = getComponentPopupMenu(); 1521 if (pmenu != null) { 1522 menus.add(pmenu); 1523 } 1524 } 1525 return menus; 1526 } 1527} | Popular Tags |