Back to index

moin  1.9.0~rc2
FigureChangeEventMulticaster.java
Go to the documentation of this file.
00001 /*
00002  * @(#)FigureChangeEventMulticaster.java 5.1
00003  *
00004  */
00005 
00006 package CH.ifa.draw.standard;
00007 
00008 import CH.ifa.draw.util.*;
00009 import CH.ifa.draw.framework.*;
00010 import java.awt.*;
00011 import java.awt.event.*;
00012 import java.util.*;
00013 import java.io.*;
00014 
00021 public class FigureChangeEventMulticaster extends
00022     AWTEventMulticaster implements FigureChangeListener {
00023 
00024     public FigureChangeEventMulticaster(EventListener a, EventListener b) {
00025        super(a, b);
00026     }
00027 
00028     public void figureInvalidated(FigureChangeEvent e) {
00029         ((FigureChangeListener)a).figureInvalidated(e);
00030         ((FigureChangeListener)b).figureInvalidated(e);
00031     }
00032 
00033     public void figureRequestRemove(FigureChangeEvent e) {
00034         ((FigureChangeListener)a).figureRequestRemove(e);
00035         ((FigureChangeListener)b).figureRequestRemove(e);
00036     }
00037 
00038     public void figureRequestUpdate(FigureChangeEvent e) {
00039         ((FigureChangeListener)a).figureRequestUpdate(e);
00040         ((FigureChangeListener)b).figureRequestUpdate(e);
00041     }
00042 
00043     public void figureChanged(FigureChangeEvent e) {
00044         ((FigureChangeListener)a).figureChanged(e);
00045         ((FigureChangeListener)b).figureChanged(e);
00046     }
00047 
00048     public void figureRemoved(FigureChangeEvent e) {
00049         ((FigureChangeListener)a).figureRemoved(e);
00050         ((FigureChangeListener)b).figureRemoved(e);
00051     }
00052 
00053     public static FigureChangeListener add(FigureChangeListener a, FigureChangeListener b) {
00054         return (FigureChangeListener)addInternal(a, b);
00055     }
00056 
00057 
00058     public static FigureChangeListener remove(FigureChangeListener l, FigureChangeListener oldl) {
00059            return (FigureChangeListener) removeInternal(l, oldl);
00060     }
00061 
00062     protected EventListener remove(EventListener oldl)
00063     {
00064         if (oldl == a)
00065             return b;
00066         if (oldl == b)
00067             return a;
00068         EventListener a2 = removeInternal((FigureChangeListener)a, oldl);
00069         EventListener b2 = removeInternal((FigureChangeListener)b, oldl);
00070         if (a2 == a && b2 == b)
00071             return this;
00072         else
00073             return addInternal((FigureChangeListener)a2, (FigureChangeListener)b2);
00074     }
00075 
00076     protected static EventListener addInternal(FigureChangeListener a, FigureChangeListener b) {
00077            if (a == null)  return b;
00078            if (b == null)  return a;
00079            return new FigureChangeEventMulticaster(a, b);
00080     }
00081 
00082     protected static EventListener removeInternal(EventListener l, EventListener oldl) {
00083        if (l == oldl || l == null) {
00084            return null;
00085        } else if (l instanceof FigureChangeEventMulticaster) {
00086            return ((FigureChangeEventMulticaster)l).remove(oldl);
00087        } else {
00088            return l;        // it's not here
00089        }
00090     }
00091 
00092 }