1 19 20 package org.netbeans.spi.looks; 21 22 import java.awt.Component ; 23 import java.awt.datatransfer.Transferable ; 24 import java.io.IOException ; 25 import java.util.ArrayList ; 26 import java.util.Arrays ; 27 import java.util.Collection ; 28 import java.util.Enumeration ; 29 import java.util.HashMap ; 30 import java.util.Iterator ; 31 import java.util.LinkedList ; 32 import java.util.List ; 33 import javax.swing.Action ; 34 import org.netbeans.modules.looks.LookListener; 35 import org.netbeans.modules.looks.LookEvent; 36 import org.openide.nodes.Node; 37 import org.openide.nodes.Sheet; 38 import org.openide.util.Enumerations; 39 import org.openide.util.HelpCtx; 40 import org.openide.util.Lookup; 41 import org.openide.util.datatransfer.NewType; 42 import org.openide.util.datatransfer.PasteType; 43 44 71 public abstract class ProxyLook extends Look { 72 73 private final LookSelector content; 74 75 private ProxyLookEventTranslator eventTranslator = new ProxyLookEventTranslator(); 76 77 81 public ProxyLook( String name, LookSelector content ) { 82 super( name ); 83 this.content = content; 84 org.netbeans.modules.looks.Accessor.DEFAULT.addSelectorListener( content, eventTranslator ); 87 88 } 89 90 106 protected boolean delegateTo( long method, Look look, Object representedObject ) { 107 return true; 108 } 109 110 private Enumeration delegateTo (final long method, final Object representedObject ) { 111 return Enumerations.filter(content.getLooks(delegateObject(representedObject)), new Enumerations.Processor() { 112 public Object process(Object object, Collection ignore) { 113 if (!(object instanceof Look)) { 114 return null; 115 } else { 116 return delegateTo(method, (Look) object, representedObject) ? object : null; 117 } 118 } 119 }); 120 } 121 122 123 124 137 protected boolean delegateAll (long method, Object representedObject) { 138 return true; 139 } 140 141 153 protected Object delegateObject (Object representedObject) { 154 return representedObject; 155 } 156 157 167 protected Object undelegateObject( Object delegate ) { 168 return delegate; 169 } 170 171 173 174 private static Look extractLook (Enumeration en) { 175 Object obj = en.nextElement(); 176 return obj instanceof Look ? (Look)obj : null; 177 } 178 179 180 182 public Collection getLookupItems(Object representedObject, Lookup oldEnv ) { 183 Enumeration delegates = delegateTo (GET_LOOKUP_ITEMS, representedObject ); 184 185 if (delegates == null) { 186 return null; 187 } 188 189 boolean merge = delegateAll (GET_LOOKUP_ITEMS, representedObject ); 190 191 Collection lookupItems = null; 192 193 for (int i[] = { 0 }; delegates.hasMoreElements(); i[0]++) { 195 Look delegate = extractLook (delegates); 196 if (delegate == null) { 197 continue; 198 } 199 200 Look look = (Look)delegate; 201 202 Collection data = look.getLookupItems (delegateObject( representedObject ), oldEnv ); 203 if (data == null || data.size() == 0 ) { 204 continue; 205 } 206 207 if (!merge) { 208 return data; 210 } 211 212 if ( lookupItems == null ) { 214 lookupItems = new LinkedList ( data ); 215 } else { 216 lookupItems.addAll( data ); 217 } 218 } 219 220 return lookupItems; 221 } 222 223 225 232 public String getDisplayName(Object representedObject, Lookup env ) { 233 Enumeration delegates = delegateTo (GET_DISPLAY_NAME, representedObject ); 234 if (delegates != null) { 235 for ( int i[] = { 0 }; delegates.hasMoreElements(); i[0]++ ) { 236 Look delegate = extractLook (delegates); 237 if (delegate != null) { 238 String h = ((Look)delegate).getDisplayName (delegateObject( representedObject ), env ); 239 if (h != null) { 240 return h; 241 } 242 } 243 } 244 } 245 return null; 246 } 247 248 255 public String getName(Object representedObject, Lookup env ) { 256 Enumeration delegates = delegateTo (GET_NAME, representedObject ); 257 if (delegates != null) { 258 for (int i[] = { 0 }; delegates.hasMoreElements(); i[0]++) { 259 Look delegate = extractLook (delegates); 260 if (delegate != null) { 261 String h = ((Look)delegate).getName (delegateObject( representedObject ), env ); 262 if (h != null) { 263 return h; 264 } 265 } 266 } 267 } 268 return null; 269 } 270 271 272 279 public void rename(Object representedObject, String newName, Lookup env ) throws IOException { 280 Enumeration delegates = delegateTo (RENAME, representedObject ); 281 if (delegates != null) { 282 for (int i[] = { 0 }; delegates.hasMoreElements(); i[0]++) { 283 Look delegate = extractLook (delegates); 284 if (delegate != null) { 285 ((Look)delegate).rename (delegateObject( representedObject ), newName, env ); 286 } 287 } 288 } 289 } 290 291 298 public String getShortDescription(Object representedObject, Lookup env ) { 299 Enumeration delegates = delegateTo (GET_SHORT_DESCRIPTION, representedObject ); 300 if (delegates != null) { 301 for (int i[] = { 0 }; delegates.hasMoreElements(); i[0]++) { 302 Look delegate = extractLook (delegates); 303 if (delegate != null) { 304 String h = ((Look)delegate).getShortDescription (delegateObject( representedObject ), env ); 305 if (h != null) { 306 return h; 307 } 308 } 309 } 310 } 311 return null; 312 } 313 314 322 public java.awt.Image getIcon(Object representedObject, int type, Lookup env) { 323 Enumeration delegates = delegateTo (GET_ICON, representedObject ); 324 if (delegates != null) { 325 for (int i[] = { 0 }; delegates.hasMoreElements(); i[0]++) { 326 Look delegate = extractLook (delegates); 327 if (delegate != null) { 328 java.awt.Image h = ((Look)delegate).getIcon (delegateObject( representedObject ), type, env ); 329 if (h != null) { 330 return h; 331 } 332 } 333 } 334 } 335 return null; 336 } 337 338 346 public java.awt.Image getOpenedIcon(Object representedObject, int type, Lookup env) { 347 Enumeration delegates = delegateTo (GET_OPENED_ICON, representedObject ); 348 if (delegates != null) { 349 for (int i[] = { 0 }; delegates.hasMoreElements(); i[0]++) { 350 Look delegate = extractLook (delegates); 351 if (delegate != null) { 352 java.awt.Image h = ((Look)delegate).getOpenedIcon (delegateObject( representedObject ), type, env ); 353 if (h != null) { 354 return h; 355 } 356 } 357 } 358 } 359 return null; 360 } 361 362 369 public HelpCtx getHelpCtx(Object representedObject, Lookup env ) { 370 Enumeration delegates = delegateTo (GET_HELP_CTX, representedObject ); 371 if (delegates != null) { 372 for (int i[] = { 0 }; delegates.hasMoreElements(); i[0]++) { 373 Look delegate = extractLook (delegates); 374 if (delegate != null) { 375 HelpCtx h = ((Look)delegate).getHelpCtx (delegateObject( representedObject ), env ); 376 if (h != null) { 377 return h; 378 } 379 } 380 } 381 } 382 return null; 383 } 384 385 387 398 public List getChildObjects(Object representedObject, Lookup env ) { 399 Enumeration delegates = delegateTo (GET_CHILD_OBJECTS, representedObject ); 400 401 if (delegates == null) { 402 return null; 403 } 404 405 boolean merge = delegateAll (GET_CHILD_OBJECTS, representedObject ); 406 407 List children = null; 408 409 for (int i[] = { 0 }; delegates.hasMoreElements(); i[0]++) { 411 Look delegate = extractLook (delegates); 412 if (delegate == null) { 413 continue; 414 } 415 416 Look look = (Look)delegate; 417 418 List data = look.getChildObjects (delegateObject( representedObject ), env ); 419 if (data == null || data.size() == 0 ) { 420 continue; 421 } 422 423 if (!merge) { 424 return data; 426 } 427 428 if ( children == null ) { 430 children = new ArrayList ( data ); 431 } else { 432 children.addAll( data ); 433 } 434 } 435 436 return children; 437 } 438 439 453 public boolean isLeaf(Object representedObject, Lookup env ) { 454 Enumeration delegates = delegateTo (GET_CHILD_OBJECTS, representedObject ); 455 if (delegates != null) { 456 for (int i[] = { 0 }; delegates.hasMoreElements(); i[0]++) { 457 Look delegate = extractLook (delegates); 458 if (delegate != null) { 459 if ( !((Look)delegate).isLeaf (delegateObject( representedObject ), env )) { 460 return false; 461 } 462 } 463 } 464 } 465 return true; 466 } 467 468 470 481 public NewType[] getNewTypes(Object representedObject, Lookup env ) { 482 Enumeration delegates = delegateTo (GET_NEW_TYPES, representedObject ); 483 484 if (delegates == null) { 485 return null; 486 } 487 488 boolean merge = delegateAll (GET_NEW_TYPES, representedObject ); 489 490 Object arrays = null; 491 492 for (int i[] = { 0 }; delegates.hasMoreElements(); i[0]++) { 494 Look delegate = extractLook (delegates); 495 if (delegate == null) { 496 continue; 497 } 498 499 Look look = (Look)delegate; 500 501 NewType[] data = look.getNewTypes (delegateObject( representedObject ), env ); 502 if (data == null || data.length == 0 ) { 503 continue; 504 } 505 506 if (!merge) { 507 return data; 509 } 510 511 if (arrays == null) { 513 arrays = data; 514 } else { 515 ArrayList l; 516 if (arrays instanceof Object []) { 517 Object [] arr = (Object [])arrays; 519 l = new ArrayList (arr.length * 2); 520 l.addAll (Arrays.asList (arr)); 521 arrays = l; 522 } else { 523 l = (ArrayList )arrays; 524 } 525 l.addAll (Arrays.asList (data)); 526 } 527 } 528 529 if (arrays == null) { 530 return null; 532 } 533 534 return arrays instanceof NewType[] ? (NewType[])arrays : (NewType[])((ArrayList )arrays).toArray (new NewType[0]); 535 } 536 537 547 public Action [] getActions(Object representedObject, Lookup env ) { 548 Enumeration delegates = delegateTo (GET_ACTIONS, representedObject ); 549 550 if (delegates == null) { 551 return null; 552 } 553 554 boolean merge = delegateAll (GET_ACTIONS, representedObject); 555 556 Object arrays = null; 557 558 for (int i[] = { 0 };delegates.hasMoreElements(); i[0]++) { 560 Look delegate = extractLook (delegates); 561 if (delegate == null) { 562 continue; 563 } 564 565 Look look = (Look)delegate; 566 567 Action [] data = look.getActions (delegateObject( representedObject ), env ); 568 if (data == null || data.length == 0 ) { 569 continue; 570 } 571 572 if (!merge) { 573 return data; 575 } 576 577 if (arrays == null) { 579 arrays = data; 580 } else { 581 ArrayList l; 582 if (arrays instanceof Object []) { 583 Object [] arr = (Object [])arrays; 585 l = new ArrayList (arr.length * 2); 586 l.addAll (Arrays.asList (arr)); 587 arrays = l; 588 } else { 589 l = (ArrayList )arrays; 590 } 591 l.addAll (Arrays.asList (data)); 592 } 593 } 594 595 if (arrays == null) { 596 return null; 598 } 599 600 return arrays instanceof Action [] ? (Action [])arrays : (Action [])((ArrayList )arrays).toArray (new Action [0]); 601 } 602 603 613 public Action [] getContextActions(Object representedObject, Lookup env ) { 614 Enumeration delegates = delegateTo (GET_CONTEXT_ACTIONS, representedObject ); 615 616 if (delegates == null) { 617 return null; 618 } 619 620 boolean merge = delegateAll (GET_CONTEXT_ACTIONS, representedObject ); 621 622 Object arrays = null; 623 624 for (int i[] = { 0 }; delegates.hasMoreElements(); i[0]++) { 626 Look delegate = extractLook (delegates); 627 if (delegate == null) { 628 continue; 629 } 630 631 Look look = (Look)delegate; 632 633 Action [] data = look.getContextActions (delegateObject( representedObject ), env ); 634 if (data == null || data.length == 0 ) { 635 continue; 636 } 637 638 if (!merge) { 639 return data; 641 } 642 643 if (arrays == null) { 645 arrays = data; 646 } else { 647 ArrayList l; 648 if (arrays instanceof Object []) { 649 Object [] arr = (Object [])arrays; 651 l = new ArrayList (arr.length * 2); 652 l.addAll (Arrays.asList (arr)); 653 arrays = l; 654 } else { 655 l = (ArrayList )arrays; 656 } 657 l.addAll (Arrays.asList (data)); 658 } 659 } 660 661 if (arrays == null) { 662 return null; 664 } 665 666 return arrays instanceof Action [] ? (Action [])arrays : (Action [])((ArrayList )arrays).toArray (new Action [0]); 667 } 668 669 676 public Action getDefaultAction(Object representedObject, Lookup env ) { 677 Enumeration delegates = delegateTo (GET_DEFAULT_ACTION, representedObject ); 678 if (delegates != null) { 679 for (int i[] = { 0 }; delegates.hasMoreElements(); i[0]++) { 680 Look delegate = extractLook (delegates); 681 if (delegate != null) { 682 Action h = ((Look)delegate).getDefaultAction (delegateObject( representedObject ), env ); 683 if (h != null) { 684 return h; 685 } 686 } 687 } 688 } 689 return null; 690 } 691 692 694 708 public Node.PropertySet[] getPropertySets(Object representedObject, Lookup env ) { 709 Enumeration delegates = delegateTo (GET_PROPERTY_SETS, representedObject ); 710 711 if (delegates == null) { 712 return null; 713 } 714 715 delegates = Enumerations.filter(delegates, new Enumerations.Processor() { 716 public Object process(Object o, Collection ignore) { 717 return o; } 719 }); 720 721 boolean merge = delegateAll (GET_PROPERTY_SETS, representedObject ); 722 723 ArrayList setsList = null; 724 HashMap nameMap = null; 725 726 for (int index[] = { 0 } ; delegates.hasMoreElements(); index[0]++) { 728 Look delegate = extractLook (delegates); 729 if (delegate == null) { 730 continue; 731 } 732 733 Look look = (Look)delegate; 734 735 Node.PropertySet[] sets = look.getPropertySets(delegateObject( representedObject ), env ); 736 if ( sets == null || sets.length == 0 ) { 737 continue; } 739 740 if (!merge) { 741 return sets; 743 } 744 745 if (setsList == null) { 746 if ( !delegates.hasMoreElements() ) { 747 return sets; 749 } 750 751 setsList = new ArrayList (); 752 nameMap = new HashMap (37); 753 } 754 755 756 for ( int i = 0; i < sets.length; i++ ) { 759 if ( sets[i].getName() == null ) { 760 continue; } 762 Sheet.Set es = (Sheet.Set)nameMap.get( sets[i].getName() ); 763 if ( es == null ) { es = new Sheet.Set( ); 765 es.setName( sets[i].getName() ); 766 es.setDisplayName( sets[i].getDisplayName() ); 767 es.setShortDescription( sets[i].getShortDescription() ); 768 es.put( sets[i].getProperties() ); 769 setsList.add( es ); 770 nameMap.put( sets[i].getName(), es ); 771 } 772 else { Node.Property[] props = sets[i].getProperties(); 774 if ( props == null || props.length == 0 ) { 775 continue; 776 } 777 else { 778 es.put( sets[i].getProperties() ); 779 } 780 } 781 } 782 } 783 784 if ( setsList == null || setsList.size() == 0 ) { 785 return null; 786 } 787 else { 788 Node.PropertySet[] result = new Node.PropertySet[ setsList.size() ]; 789 setsList.toArray( result ); 790 return result; 791 } 792 } 793 794 801 public Component getCustomizer(Object representedObject, Lookup env ) { 802 Enumeration delegates = delegateTo (GET_CUSTOMIZER, representedObject ); 803 if (delegates != null) { 804 for (int i[] = { 0 }; delegates.hasMoreElements(); i[0]++) { 805 Look delegate = extractLook (delegates); 806 if (delegate != null) { 807 Component h = ((Look)delegate).getCustomizer (delegateObject( representedObject ), env ); 808 if (h != null) { 809 return h; 810 } 811 } 812 } 813 } 814 return null; 815 } 816 817 825 public boolean hasCustomizer(Object representedObject, Lookup env ) { 826 Enumeration delegates = delegateTo (HAS_CUSTOMIZER, representedObject ); 827 if (delegates != null) { 828 for (int i[] = { 0 }; delegates.hasMoreElements(); i[0]++) { 829 Look delegate = extractLook (delegates); 830 if (delegate != null) { 831 if ( ((Look)delegate).hasCustomizer (delegateObject( representedObject ), env )) { 832 return true; 833 } 834 } 835 } 836 } 837 return false; 838 } 839 841 849 public boolean canRename(Object representedObject, Lookup env ) { 850 Enumeration delegates = delegateTo (CAN_RENAME, representedObject ); 851 if (delegates != null) { 852 for (int i[] = { 0 }; delegates.hasMoreElements(); i[0]++) { 853 Look delegate = extractLook (delegates); 854 if (delegate != null) { 855 boolean b = ((Look)delegate).canRename (delegateObject( representedObject ), env ); 856 if (b) { 857 return true; 858 } 859 } 860 } 861 } 862 return false; 863 } 864 865 873 public boolean canDestroy(Object representedObject, Lookup env ) { 874 Enumeration delegates = delegateTo (CAN_DESTROY, representedObject ); 875 if (delegates != null) { 876 for (int i[] = { 0 }; delegates.hasMoreElements(); i[0]++) { 877 Look delegate = extractLook (delegates); 878 if (delegate != null) { 879 boolean b = ((Look)delegate).canDestroy (delegateObject( representedObject ), env ); 880 if (b) { 881 return true; 882 } 883 } 884 } 885 } 886 return false; 887 } 888 889 897 public boolean canCopy(Object representedObject, Lookup env ) { 898 Enumeration delegates = delegateTo (CAN_COPY, representedObject ); 899 if (delegates != null) { 900 for (int i[] = { 0 }; delegates.hasMoreElements(); i[0]++) { 901 Look delegate = extractLook (delegates); 902 if (delegate != null) { 903 boolean b = ((Look)delegate).canCopy (delegateObject( representedObject ), env ); 904 if (b) { 905 return true; 906 } 907 } 908 } 909 } 910 return false; 911 } 912 913 921 public boolean canCut(Object representedObject, Lookup env ) { 922 Enumeration delegates = delegateTo (CAN_CUT, representedObject ); 923 if (delegates != null) { 924 for (int i[] = { 0 }; delegates.hasMoreElements(); i[0]++) { 925 Look delegate = extractLook (delegates); 926 if (delegate != null) { 927 boolean b = ((Look)delegate).canCut (delegateObject( representedObject ), env ); 928 if (b) { 929 return true; 930 } 931 } 932 } 933 } 934 return false; 935 } 936 937 948 public PasteType[] getPasteTypes(Object representedObject, Transferable t, Lookup env ) { 949 Enumeration delegates = delegateTo (GET_PASTE_TYPES, representedObject ); 950 951 if (delegates == null) { 952 return null; 953 } 954 955 boolean merge = delegateAll (GET_PASTE_TYPES, representedObject ); 956 957 Object arrays = null; 958 959 for (int i[] = { 0 }; delegates.hasMoreElements(); i[0]++) { 961 Look delegate = extractLook (delegates); 962 if (delegate == null) { 963 continue; 964 } 965 966 Look look = (Look)delegate; 967 968 PasteType[] data = look.getPasteTypes (delegateObject( representedObject ), t, env ); 969 if (data == null || data.length == 0 ) { 970 continue; 971 } 972 973 if (!merge) { 974 return data; 976 } 977 978 if (arrays == null) { 980 arrays = data; 981 } else { 982 ArrayList l; 983 if (arrays instanceof Object []) { 984 Object [] arr = (Object [])arrays; 986 l = new ArrayList (arr.length * 2); 987 l.addAll (Arrays.asList (arr)); 988 arrays = l; 989 } else { 990 l = (ArrayList )arrays; 991 } 992 l.addAll (Arrays.asList (data)); 993 } 994 } 995 996 if (arrays == null) { 997 return null; 999 } 1000 1001 return arrays instanceof PasteType[] ? (PasteType[])arrays : (PasteType[])((ArrayList )arrays).toArray (new PasteType[0]); 1002 } 1003 1004 1016 public PasteType getDropType(Object representedObject, Transferable t, int action, int index, Lookup env ) { 1017 Enumeration delegates = delegateTo (GET_DROP_TYPE, representedObject ); 1018 if (delegates != null) { 1019 for (int i[] = { 0 }; delegates.hasMoreElements(); i[0]++) { 1020 Look delegate = extractLook (delegates); 1021 if (delegate != null) { 1022 PasteType b = ((Look)delegate).getDropType (delegateObject( representedObject ), t, action, index, env ); 1023 if (b != null) { 1024 return b; 1025 } 1026 } 1027 } 1028 } 1029 return null; 1030 } 1031 1032 1041 public Transferable clipboardCopy(Object representedObject, Lookup env ) throws IOException { 1042 Enumeration delegates = delegateTo (CLIPBOARD_COPY, representedObject ); 1043 if (delegates != null) { 1044 for (int i[] = { 0 }; delegates.hasMoreElements(); i[0]++) { 1045 Look delegate = extractLook (delegates); 1046 if (delegate != null) { 1047 Transferable b = ((Look)delegate).clipboardCopy (delegateObject( representedObject ), env ); 1048 if (b != null) { 1049 return b; 1050 } 1051 } 1052 } 1053 } 1054 return null; 1055 } 1056 1057 1066 public Transferable clipboardCut(Object representedObject, Lookup env ) throws IOException { 1067 Enumeration delegates = delegateTo (CLIPBOARD_CUT, representedObject ); 1068 if (delegates != null) { 1069 for (int i[] = { 0 }; delegates.hasMoreElements(); i[0]++) { 1070 Look delegate = extractLook (delegates); 1071 if (delegate != null) { 1072 Transferable b = ((Look)delegate).clipboardCut (delegateObject( representedObject ), env ); 1073 if (b != null) { 1074 return b; 1075 } 1076 } 1077 } 1078 } 1079 return null; 1080 } 1081 1082 1091 public Transferable drag(Object representedObject, Lookup env ) throws IOException { 1092 Enumeration delegates = delegateTo (DRAG, representedObject ); 1093 if (delegates != null) { 1094 for (int i[] = { 0 }; delegates.hasMoreElements(); i[0]++) { 1095 Look delegate = extractLook (delegates); 1096 if (delegate != null) { 1097 Transferable b = ((Look)delegate).drag (delegateObject( representedObject ), env ); 1098 if (b != null) { 1099 return b; 1100 } 1101 } 1102 } 1103 } 1104 return null; 1105 } 1106 1107 1114 public void destroy(Object representedObject, Lookup env ) throws IOException { 1115 Enumeration delegates = delegateTo (DESTROY, representedObject ); 1116 if (delegates != null) { 1117 for (int i[] = { 0 }; delegates.hasMoreElements(); i[0]++) { 1118 Look delegate = extractLook (delegates); 1119 if (delegate != null) { 1120 ((Look)delegate).destroy (delegateObject( representedObject ), env ); 1121 } 1122 } 1123 } 1124 } 1125 1126 1128 1129 void addLookListener( Object representedObject, LookListener listener ) { 1130 1131 Object dObject = null; 1132 Enumeration delegates = null; 1133 1134 if ( representedObject != null ) { 1135 dObject = delegateObject( representedObject ); 1136 delegates = content.getLooks( dObject ); 1137 } 1138 1139 synchronized ( this ) { 1140 super.addLookListener( representedObject, listener ); 1141 1142 1145 if (representedObject != null) { 1146 1148 List dList = new ArrayList (); 1149 if (delegates != null) { 1150 for ( int i[] = { 0 }; delegates.hasMoreElements(); i[0]++ ) { 1151 Look delegate = extractLook (delegates); 1152 if (delegate != null) { 1153 RuntimeException ex = null; 1154 try { ((Look)delegate).addLookListener( dObject, null ); 1156 ((Look)delegate).addLookListener( null, eventTranslator ); 1157 dList.add( delegate ); 1158 } 1159 catch ( ClassCastException e ) { 1160 ex = e; 1161 } 1162 catch ( IllegalArgumentException e ) { 1163 ex = e; 1164 } 1165 if ( ex != null ) { for( Iterator it = dList.iterator(); it.hasNext(); ) { 1168 Look l = (Look)it.next(); 1169 l.removeLookListener( dObject, null ); 1170 l.removeLookListener( null, eventTranslator ); 1171 } 1172 throw ex; 1174 } 1175 } 1176 } 1177 } 1178 } 1179 } 1180 } 1181 1182 void removeLookListener( Object representedObject, LookListener listener ) { 1183 1184 Object dObject = null; 1185 Enumeration delegates = null; 1186 1187 if ( representedObject != null ) { 1188 dObject = delegateObject( representedObject ); 1189 delegates = content.getLooks( dObject ); 1190 } 1191 1192 synchronized ( this ) { 1193 if (representedObject != null) { 1194 if (delegates != null) { 1196 for ( int i[] = { 0 }; delegates.hasMoreElements(); i[0]++ ) { 1197 Look delegate = extractLook (delegates); 1198 if (delegate != null) { 1199 delegate.removeLookListener( dObject, null ); 1200 } 1201 } 1202 } 1203 } 1204 1205 1208 super.removeLookListener( representedObject, listener ); 1209 } 1210 } 1211 1212 1213 1215 1217 private class ProxyLookEventTranslator implements LookListener, org.netbeans.modules.looks.SelectorListener { 1218 1219 public void change( LookEvent evt ) { 1220 fireChange( undelegateObject( evt.getSource() ), evt.getMask() ); 1221 } 1222 public void propertyChange( LookEvent evt ) { 1223 firePropertyChange( undelegateObject( evt.getSource() ), evt.getPropertyName() ); 1224 } 1225 1226 1228 public void contentsChanged( org.netbeans.modules.looks.SelectorEvent evt ) { 1229 1230 long mask = Look.ALL_METHODS; 1232 mask &= ~( Look.DESTROY | Look.RENAME ); 1233 1234 Object objects[] = getAllObjects(); if ( objects == null ) { 1236 return; } 1238 1239 for( int i = 0; i < objects.length; i++ ) { 1240 Object dObject = delegateObject( objects[i] ); 1241 Collection removedLooks = evt.getRemovedLooks( objects[i] ); 1242 if ( !removedLooks.isEmpty() ) { 1243 for( Iterator it = removedLooks.iterator(); it.hasNext(); ) { 1245 ((Look)it.next()).removeLookListener( dObject, null ); 1246 } 1247 } 1248 1249 Collection addedLooks = evt.getAddedLooks( objects[i] ); 1250 if ( !addedLooks.isEmpty() ) { 1251 for( Iterator it = addedLooks.iterator(); it.hasNext(); ) { 1253 ((Look)it.next()).addLookListener( dObject, null ); 1254 } 1255 } 1256 } 1257 1258 1259 fireChange( null, mask ); 1260 firePropertyChange( null, null ); 1261 } 1262 1263 } 1264 1265} 1266 | Popular Tags |