?? changesupport.java
字號:
/** * ListenerSupport.java * Copyright 2005 Carlos Silva A. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */package jgantt.model;import java.util.Enumeration;import java.util.Vector;/** * ListenerSupport, permite Agregar o remover listener a una lista de suscritos. * Ademas, permite definir bloques de cambios que deben despacharse * todos juntos al final del bloque. * <p>El ultimo mensaje del bloque se envia con la marca:<code>isLast</code>.</p> * * <p>$Date: 2004/04/25 03:00:08 $</p> * @version $Revision: 1.2 $ * @author Carlos Silva */abstract public class ChangeSupport { Vector listeners = new Vector(); boolean dispatchChanges = true; Vector eventQueue = new Vector(); // metodos publicos /** * Agrega un escuchador * @param o listener */ public void addListener(Object o) { if (!listeners.contains(o)) listeners.addElement(o); } /** * Elimina un escuchador * @param o listener */ public void removeListener(Object o) { listeners.remove(o); } /** * No envia las notificaciones automaticamente. * */ public void beginBlockChanges() { dispatchChanges = false; } /** * Envia todos los mensajes pendientes. * */ public void commitBlockChanges() { dispatchChanges = true; while (!eventQueue.isEmpty()) { Change c = (Change) eventQueue.remove(0); if (eventQueue.isEmpty()) c.setNotLast(); notifyChange(c); } } public void sendChange(Change c) { if (dispatchChanges) { notifyChange(c); } else eventQueue.add(c); } // funciones protegidas protected void notifyChange(Change c) { for (Enumeration e = listeners.elements(); e.hasMoreElements();) { Object l = e.nextElement(); notifyListener(l, c); } } /** * * @param listener Objeto a notificar * @param change Cambio que ha sido realizado */ abstract protected void notifyListener(Object listener, Change change);}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -