Author: clopes
Date: 2012-05-02 12:24:19 -0700 (Wed, 02 May 2012)
New Revision: 29079
Added:
core3/api/trunk/vizmap-api/src/main/java/org/cytoscape/view/vizmap/events/VisualStyleSetEvent.java
core3/api/trunk/vizmap-api/src/main/java/org/cytoscape/view/vizmap/events/VisualStyleSetListener.java
Modified:
core3/api/trunk/vizmap-api/src/test/java/org/cytoscape/view/vizmap/VizmapEventsTest.java
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/VisualMappingManagerImpl.java
Log:
Fixes #937 : VisualMappingManager.setVisualStyle() does not fire any event
Added:
core3/api/trunk/vizmap-api/src/main/java/org/cytoscape/view/vizmap/events/VisualStyleSetEvent.java
===================================================================
---
core3/api/trunk/vizmap-api/src/main/java/org/cytoscape/view/vizmap/events/VisualStyleSetEvent.java
(rev 0)
+++
core3/api/trunk/vizmap-api/src/main/java/org/cytoscape/view/vizmap/events/VisualStyleSetEvent.java
2012-05-02 19:24:19 UTC (rev 29079)
@@ -0,0 +1,80 @@
+/*
+ Copyright (c) 2008, The Cytoscape Consortium (www.cytoscape.org)
+
+ The Cytoscape Consortium is:
+ - Institute for Systems Biology
+ - University of California San Diego
+ - Memorial Sloan-Kettering Cancer Center
+ - Institut Pasteur
+ - Agilent Technologies
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications. In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage. See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+package org.cytoscape.view.vizmap.events;
+
+import org.cytoscape.event.AbstractCyEvent;
+import org.cytoscape.view.model.CyNetworkView;
+import org.cytoscape.view.vizmap.VisualMappingManager;
+import org.cytoscape.view.vizmap.VisualStyle;
+
+/**
+ * Event fired when a {@link VisualStyle} is set to a network view through
+ * {@linkplain VisualMappingManager#setVisualStyle(VisualStyle,
org.cytoscape.view.model.CyNetworkView)}.
+ * @CyAPI.Final.Class
+ */
+public final class VisualStyleSetEvent extends
AbstractCyEvent<VisualMappingManager> {
+
+ private final VisualStyle style;
+ private final CyNetworkView view;
+
+ /**
+ * Creates the event.
+ *
+ * @param source Source of this event. This is always {@link
VisualMappingManager}.
+ * @param style The VisualStyle that was set to the network view.
+ * @param view The target CyNetworkView.
+ */
+ public VisualStyleSetEvent(final VisualMappingManager source, final
VisualStyle style, CyNetworkView view) {
+ super(source, VisualStyleSetListener.class);
+ this.style = style;
+ this.view = view;
+ }
+
+ /**
+ * Get the VisualStyle that was set to the network view.
+ * @return The VisualStyle that was set to the network view.
+ */
+ public VisualStyle getVisualStyle() {
+ return style;
+ }
+
+ /**
+ * Get the The target network view model.
+ * @return The target CyNetworkView.
+ */
+ public CyNetworkView getNetworkView() {
+ return view;
+ }
+}
Added:
core3/api/trunk/vizmap-api/src/main/java/org/cytoscape/view/vizmap/events/VisualStyleSetListener.java
===================================================================
---
core3/api/trunk/vizmap-api/src/main/java/org/cytoscape/view/vizmap/events/VisualStyleSetListener.java
(rev 0)
+++
core3/api/trunk/vizmap-api/src/main/java/org/cytoscape/view/vizmap/events/VisualStyleSetListener.java
2012-05-02 19:24:19 UTC (rev 29079)
@@ -0,0 +1,53 @@
+/*
+ Copyright (c) 2008, The Cytoscape Consortium (www.cytoscape.org)
+
+ The Cytoscape Consortium is:
+ - Institute for Systems Biology
+ - University of California San Diego
+ - Memorial Sloan-Kettering Cancer Center
+ - Institut Pasteur
+ - Agilent Technologies
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications. In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage. See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+package org.cytoscape.view.vizmap.events;
+
+import org.cytoscape.event.CyListener;
+import org.cytoscape.view.model.CyNetworkView;
+
+/**
+ * Listener for {@linkplain VisualStyleSetEvent}.
+ * @CyAPI.Spi.Interface
+ */
+public interface VisualStyleSetListener extends CyListener {
+
+ /**
+ * Do something after a {@linkplain
org.cytoscape.view.vizmap.VisualStyle} is set to a {@linkplain CyNetworkView}.
+ * Usually, GUI components and managers executes this method to update
their states.
+ *
+ * @param e
+ */
+ void handleEvent(final VisualStyleSetEvent e);
+}
Modified:
core3/api/trunk/vizmap-api/src/test/java/org/cytoscape/view/vizmap/VizmapEventsTest.java
===================================================================
---
core3/api/trunk/vizmap-api/src/test/java/org/cytoscape/view/vizmap/VizmapEventsTest.java
2012-05-02 18:54:58 UTC (rev 29078)
+++
core3/api/trunk/vizmap-api/src/test/java/org/cytoscape/view/vizmap/VizmapEventsTest.java
2012-05-02 19:24:19 UTC (rev 29079)
@@ -1,12 +1,13 @@
package org.cytoscape.view.vizmap;
+import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import org.cytoscape.view.model.CyNetworkView;
+import org.cytoscape.view.vizmap.events.VisualStyleAboutToBeRemovedEvent;
import org.cytoscape.view.vizmap.events.VisualStyleAddedEvent;
-import org.cytoscape.view.vizmap.events.VisualStyleAboutToBeRemovedEvent;
+import org.cytoscape.view.vizmap.events.VisualStyleSetEvent;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -29,15 +30,21 @@
@Test
public void testVisualStyleCreatedEvent() {
final VisualStyleAddedEvent event = new
VisualStyleAddedEvent(manager, style);
- assertNotNull(event);
assertEquals(style, event.getVisualStyleAdded());
}
@Test
public void testVisualStyleDestroyedEvent() {
final VisualStyleAboutToBeRemovedEvent event = new
VisualStyleAboutToBeRemovedEvent(manager, style);
- assertNotNull(event);
assertEquals(style, event.getVisualStyleToBeRemoved());
}
+
+ @Test
+ public void testVisualStyleSetEvent() {
+ final CyNetworkView view = mock(CyNetworkView.class);
+ final VisualStyleSetEvent event = new
VisualStyleSetEvent(manager, style, view);
+ assertEquals(style, event.getVisualStyle());
+ assertEquals(view, event.getNetworkView());
+ }
}
Modified:
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/VisualMappingManagerImpl.java
===================================================================
---
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/VisualMappingManagerImpl.java
2012-05-02 18:54:58 UTC (rev 29078)
+++
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/VisualMappingManagerImpl.java
2012-05-02 19:24:19 UTC (rev 29079)
@@ -49,6 +49,7 @@
import org.cytoscape.view.vizmap.VisualStyleFactory;
import org.cytoscape.view.vizmap.events.VisualStyleAboutToBeRemovedEvent;
import org.cytoscape.view.vizmap.events.VisualStyleAddedEvent;
+import org.cytoscape.view.vizmap.events.VisualStyleSetEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -142,13 +143,20 @@
if (nv == null)
throw new NullPointerException("Network view is null.");
- if (vs == null)
- network2VisualStyleMap.remove(nv);
- else
- network2VisualStyleMap.put(nv, vs);
+ boolean changed = false;
+
+ if (vs == null) {
+ changed = network2VisualStyleMap.remove(nv) != null;
+ } else {
+ final VisualStyle previousStyle =
network2VisualStyleMap.put(nv, vs);
+ changed = !vs.equals(previousStyle);
+ }
if (this.visualStyles.contains(vs) == false)
this.visualStyles.add(vs);
+
+ if (changed)
+ cyEventHelper.fireEvent(new VisualStyleSetEvent(this,
vs, nv));
}
/**
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.