Login | Register
My pages Projects Community openCollabNet

Discussions > commits > svn commit: r1344 - trunk/src/org/tigris/gef/base

gef
Discussion topic

Back to topic list

svn commit: r1344 - trunk/src/org/tigris/gef/base

Author bobtarling
Full name Bob Tarling
Date 2014-06-26 17:18:00 PDT
Message Author: bobtarling
Date: 2014-06-26 17:18:00-0700
New Revision: 1344

Added:
   trunk/src/org/tigris​/gef/base/LayerListe​ner.java
Modified:
   trunk/src/org/tigris​/gef/base/LayerDiagr​am.java

Log:
Fire an event when a Fig is added to a layer

Modified: trunk/src/org/tigris​/gef/base/LayerDiagr​am.java
Url: http://gef.tigris.or​g/source/browse/gef/​trunk/src/org/tigris​/gef/base/LayerDiagr​am.java?view=diff​&pathrev=1344&r​1=1343&r2=1344
====================​====================​====================​==================
--- trunk/src/org/tigris​/gef/base/LayerDiagr​am.java (original)
+++ trunk/src/org/tigris​/gef/base/LayerDiagr​am.java 2014-06-26 17:18:00-0700
@@ -31,6 +31,7 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Enumeration;
+import java.util.EventObject;
 import java.util.List;
 import java.util.Iterator;
 
@@ -51,6 +52,8 @@
 
     private static final long serialVersionUID = 6193765162314431069L;
 
+ private List<LayerListener> listeners = new ArrayList<LayerLi​stener>();
+
     /** The Fig's that are contained in this layer. */
     private List<Fig> contents = new ArrayList<Fig>();
 
@@ -135,10 +138,15 @@
                     "Attempted to add a null fig to a LayerDiagram");
         }
 
- contents.remove(f); // act like a set
- contents.add(f);
- f.setLayer(this);
- f.endTrans();
+ if (!contents.contains(f)) {
+ contents.remove(f); // act like a set
+ contents.add(f);
+ f.setLayer(this);
+ f.endTrans();
+ for (LayerListener listener : listeners) {
+ listener.figAdded(new EventObject(f));
+ }
+ }
     }
 
     /**
@@ -156,10 +164,17 @@
                     "Attempted to insert a null fig to a LayerDiagram");
         }
 
- contents.remove(f); // act like a set
- contents.add(index, f);
- f.setLayer(this);
- f.endTrans();
+ if (contents.indexOf(f) != index) {
+ boolean fireEvent = !contents.remove(f); // act like a set
+ contents.add(index, f);
+ f.setLayer(this);
+ f.endTrans();
+ if (fireEvent) {
+ for (LayerListener listener : listeners) {
+ listener.figAdded(new EventObject(f));
+ }
+ }
+ }
     }
 
     /**
@@ -182,9 +197,14 @@
 
     /** Remove the given Fig from this layer. */
     public void remove(Fig f) {
- contents.remove(f);
- f.endTrans();
- f.setLayer(null);
+ if (contents.contains(f)) {
+ contents.remove(f);
+ f.endTrans();
+ f.setLayer(null);
+ for (LayerListener listener : listeners) {
+ listener.figRemoved(new EventObject(f));
+ }
+ }
     }
 
     /**
@@ -475,4 +495,13 @@
             ((Fig) this.contents.get(i)​).postLoad();
         }
     }
+
+ public void addLayerListener(LayerListener listener) {
+ listeners.add(listener);
+ }
+
+ public void removeLayerListener(​LayerListener listener) {
+ listeners.remove(listener);
+ }
+
 }
\ No newline at end of file

Added: trunk/src/org/tigris​/gef/base/LayerListe​ner.java
Url: http://gef.tigris.or​g/source/browse/gef/​trunk/src/org/tigris​/gef/base/LayerListe​ner.java?view=markup​&pathrev=1344
====================​====================​====================​==================
--- (empty file)
+++ trunk/src/org/tigris​/gef/base/LayerListe​ner.java 2014-06-26 17:18:00-0700
@@ -0,0 +1,11 @@
+package org.tigris.gef.base;
+
+import java.util.EventObject;
+
+public interface LayerListener {
+
+ void figAdded(EventObject event);
+
+ void figRemoved(EventObject event);
+
+}

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

svn commit: r1344 - trunk/src/org/tigris/gef/base bobtarling Bob Tarling 2014-06-26 17:18:00 PDT
Messages per page: