1 19 20 package org.netbeans.modules.javahelp; 21 22 import java.util.*; 23 import java.util.logging.Level ; 24 import javax.swing.SwingUtilities ; 25 import javax.swing.event.ChangeEvent ; 26 import javax.swing.event.ChangeListener ; 27 28 import javax.help.HelpSet; 29 30 import org.openide.util.*; 31 32 import org.netbeans.api.javahelp.Help; 33 34 37 public abstract class AbstractHelp extends Help implements HelpConstants { 38 39 41 protected AbstractHelp() {} 42 43 45 private Lookup.Result<HelpSet> helpsets = null; 46 51 protected final Collection<? extends HelpSet> getHelpSets() { 52 if (helpsets == null) { 53 Installer.log.fine("searching for instances of HelpSet..."); 54 helpsets = Lookup.getDefault().lookupResult(HelpSet.class); 55 helpsets.addLookupListener(new LookupListener() { 56 public void resultChanged(LookupEvent ev) { 57 helpSetsChanged(); 58 } 59 }); 60 fireChangeEvent(); } 62 Collection<? extends HelpSet> c = helpsets.allInstances(); 63 if (Installer.log.isLoggable(Level.FINE)) { 64 List<String > l = new ArrayList<String >(Math.min(1, c.size())); 65 for (HelpSet hs: c) { 66 l.add(hs.getTitle()); 67 } 68 Installer.log.fine("listing helpsets: " + l); 69 } 70 return c; 71 } 72 73 76 protected final boolean helpSetsReady() { 77 return helpsets != null; 78 } 79 80 85 protected final boolean shouldMerge(HelpSet hs) { 86 Boolean b = (Boolean )hs.getKeyData(HELPSET_MERGE_CONTEXT, HELPSET_MERGE_ATTR); 87 return (b == null) || b.booleanValue(); 88 } 89 90 94 protected void helpSetsChanged() { 95 Installer.log.fine("helpSetsChanged"); 96 fireChangeEvent(); 97 } 98 99 public final void addChangeListener(ChangeListener l) { 100 synchronized (listeners) { 101 listeners.add(l); 102 } 103 } 104 105 public final void removeChangeListener(ChangeListener l) { 106 synchronized (listeners) { 107 listeners.remove(l); 108 } 109 } 110 111 113 private final Set<ChangeListener > listeners = new HashSet<ChangeListener >(1); 114 115 117 private final void fireChangeEvent() { 118 if (!SwingUtilities.isEventDispatchThread()) { 119 SwingUtilities.invokeLater(new Runnable () { 120 public void run() { 121 fireChangeEvent(); 122 } 123 }); 124 return; 125 } 126 Set<ChangeListener > lsnrs; 127 synchronized (listeners) { 128 lsnrs = new HashSet<ChangeListener >(listeners); 129 } 130 ChangeEvent ev = new ChangeEvent (this); 131 Installer.log.fine("Help.stateChanged"); 132 for (ChangeListener chl: lsnrs) { 133 chl.stateChanged(ev); 134 } 135 } 136 137 } 138 | Popular Tags |