1 19 package org.openide.awt; 20 21 import org.openide.util.Lookup; 22 23 import java.util.*; 24 25 import javax.swing.event.ChangeEvent ; 26 import javax.swing.event.ChangeListener ; 27 28 29 34 public abstract class StatusDisplayer { 35 private static StatusDisplayer INSTANCE = null; 36 37 38 protected StatusDisplayer() { 39 } 40 41 44 public static synchronized StatusDisplayer getDefault() { 45 if (INSTANCE == null) { 46 INSTANCE = (StatusDisplayer) Lookup.getDefault().lookup(StatusDisplayer.class); 47 48 if (INSTANCE == null) { 49 INSTANCE = new Trivial(); 50 } 51 } 52 53 return INSTANCE; 54 } 55 56 63 public abstract String getStatusText(); 64 65 76 public abstract void setStatusText(String text); 77 78 81 public abstract void addChangeListener(ChangeListener l); 82 83 86 public abstract void removeChangeListener(ChangeListener l); 87 88 92 private static final class Trivial extends StatusDisplayer { 93 private List<ChangeListener > listeners = null; 94 private String text = ""; 96 public synchronized String getStatusText() { 97 return text; 98 } 99 100 public synchronized void setStatusText(String text) { 101 if (text.equals(this.text)) { 102 return; 103 } 104 105 this.text = text; 106 107 if (text.length() > 0) { 108 System.err.println("(" + text + ")"); } 110 111 fireChange(); 112 } 113 114 public synchronized void addChangeListener(ChangeListener l) { 115 if (listeners == null) { 116 listeners = new ArrayList<ChangeListener >(); 117 } 118 119 listeners.add(l); 120 } 121 122 public synchronized void removeChangeListener(ChangeListener l) { 123 if (listeners != null) { 124 listeners.remove(l); 125 } 126 } 127 128 protected final void fireChange() { 129 if ((listeners != null) && !listeners.isEmpty()) { 130 ChangeEvent ev = new ChangeEvent (this); 131 Iterator<ChangeListener > it = listeners.iterator(); 132 133 while (it.hasNext()) { 134 it.next().stateChanged(ev); 135 } 136 } 137 } 138 } 139 } 140 | Popular Tags |