1 19 20 package org.netbeans.modules.applemenu; 21 22 import java.awt.Font ; 23 import java.lang.ref.Reference ; 24 import java.lang.ref.ReferenceQueue ; 25 import java.lang.reflect.Field ; 26 27 36 class FontReferenceQueue extends ReferenceQueue { 37 45 public Reference poll() { 46 Reference ref; 47 48 for (;;) { 49 ref = super.poll(); 50 if (ref == null) 51 break; 52 53 Object obj = ref.get(); 54 if (! (obj instanceof Font )) 55 break; 56 } 57 return ref; 58 } 59 60 80 public Reference remove(long timeout) throws IllegalArgumentException , InterruptedException { 81 83 Reference ref; 84 85 for (;;) { 86 ref = super.remove(timeout); 87 if (ref == null) 88 break; 89 90 Object obj = ref.get(); 91 if (! (obj instanceof Font )) 92 break; 93 } 94 return ref; 95 } 96 97 static void install() { 98 try { 99 Class clzz = Class.forName("java.lang.ref.Finalizer"); Field fld = clzz.getDeclaredField("queue"); fld.setAccessible(true); 102 fld.set(null, new FontReferenceQueue()); 103 } catch (NoClassDefFoundError ex) { 104 } catch (ClassNotFoundException ex) { 106 } catch (Exception ex) { 108 } 110 111 } 112 } 113 | Popular Tags |