Author: jgao
Date: 2009-08-02 19:41:36 -0700 (Sun, 02 Aug 2009)
New Revision: 17660
Added:
csplugins/trunk/soc/jgao/PluginsCommunication/build.xml
csplugins/trunk/soc/jgao/PluginsCommunication/src/
csplugins/trunk/soc/jgao/PluginsCommunication/src/cytoscape/
csplugins/trunk/soc/jgao/PluginsCommunication/src/cytoscape/util/
csplugins/trunk/soc/jgao/PluginsCommunication/src/cytoscape/util/plugins/
csplugins/trunk/soc/jgao/PluginsCommunication/src/cytoscape/util/plugins/communication/
csplugins/trunk/soc/jgao/PluginsCommunication/src/cytoscape/util/plugins/communication/Message.java
csplugins/trunk/soc/jgao/PluginsCommunication/src/cytoscape/util/plugins/communication/MessageListener.java
csplugins/trunk/soc/jgao/PluginsCommunication/src/cytoscape/util/plugins/communication/PluginsCommunicationSupport.java
csplugins/trunk/soc/jgao/PluginsCommunication/test/
csplugins/trunk/soc/jgao/PluginsCommunication/test/cytoscape/
csplugins/trunk/soc/jgao/PluginsCommunication/test/cytoscape/util/
csplugins/trunk/soc/jgao/PluginsCommunication/test/cytoscape/util/plugins/
csplugins/trunk/soc/jgao/PluginsCommunication/test/cytoscape/util/plugins/communication/
csplugins/trunk/soc/jgao/PluginsCommunication/test/cytoscape/util/plugins/communication/Test.java
Modified:
csplugins/trunk/soc/jgao/PluginsCommunication/
Log:
Inter-plugins communication support (first version)
Property changes on: csplugins/trunk/soc/jgao/PluginsCommunication
___________________________________________________________________
Name: svn:ignore
+ build
nbproject
build_1.xml
cytoscape-plugins-comm.jar
manifest.mf
nbbuild.xml
dist
.project
Added: csplugins/trunk/soc/jgao/PluginsCommunication/build.xml
===================================================================
--- csplugins/trunk/soc/jgao/PluginsCommunication/build.xml
(rev 0)
+++ csplugins/trunk/soc/jgao/PluginsCommunication/build.xml 2009-08-03
02:41:36 UTC (rev 17660)
@@ -0,0 +1,59 @@
+
+
+<project name="CytoscapePluginsCommunication" default="jar" basedir=".">
+ <description>Builds, tests, and runs the project
CytoscapePluginsCommunication</description>
+
+ <!-- =================================================================== -->
+ <!-- Initialization target -->
+ <!-- =================================================================== -->
+ <target name="init">
+ <tstamp/>
+ <property name="src" location="src"/>
+ <property name="cyrelease" value="../cytoscape"/>
+ <property name="build" location="build"/>
+ <property name="build.classes" location="${build}/classes"/>
+ <property name="jar.name" location="cytoscape-plugins-comm.jar"/>
+
+ <!-- Classpath with all lib JAR Files and all Cytoscape Core classes -->
+ <path id="classpath">
+ <!-- include cytoscape.jar, which is it release directory top level -->
+ <fileset dir="${cyrelease}">
+ <include name="*.jar"/>
+ </fileset>
+ </path>
+
+ </target>
+
+ <!-- =================================================================== -->
+ <!-- Compiles the project -->
+ <!-- =================================================================== -->
+ <target name="compile" depends="init">
+ <mkdir dir="${build}"/>
+ <mkdir dir="${build.classes}"/>
+ <javac srcdir="${src}" destdir="${build.classes}">
+ <classpath refid="classpath"/>
+ </javac>
+ </target>
+
+ <!-- =================================================================== -->
+ <!-- Clean up, get back to original state -->
+ <!-- =================================================================== -->
+ <target name="clean" depends="init">
+ <echo message="delete ${build}"/>
+ <delete dir="${build}"/>
+ </target>
+
+ <!-- =================================================================== -->
+ <!-- Creates the project jar file -->
+ <!-- =================================================================== -->
+ <target name="jar" depends="compile">
+ <jar destfile="${jar.name}">
+ <fileset dir= "${build.classes}" />
+ </jar>
+ <copy file="${jar.name}" todir="D:\projects\CyThesaurus\lib" />
+ </target>
+
+</project>
+
+
+
Added:
csplugins/trunk/soc/jgao/PluginsCommunication/src/cytoscape/util/plugins/communication/Message.java
===================================================================
---
csplugins/trunk/soc/jgao/PluginsCommunication/src/cytoscape/util/plugins/communication/Message.java
(rev 0)
+++
csplugins/trunk/soc/jgao/PluginsCommunication/src/cytoscape/util/plugins/communication/Message.java
2009-08-03 02:41:36 UTC (rev 17660)
@@ -0,0 +1,99 @@
+/*
+ Copyright (c) 2006, 2007, 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 cytoscape.util.plugins.communication;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ *
+ * @author gjj
+ */
+public class Message {
+ private static final String MSG_SENDER = "MSG_SENDER";
+ private static final String MSG_RECEIVER = "MSG_RECEIVER";
+ private static final String MSG_TYPE = "MSG_TYPE";
+ private static final String MSG_CONTENT = "MSG_CONTENT";
+ private static final String MSG_ID = "MSG_ID";
+
+ public static final String MSG_TYPE_GENERAL = "GENERAL";
+ public static final String MSG_TYPE_REQUEST = "REQUEST";
+ public static final String MSG_TYPE_RESPONSE = "RESPONSE";
+ public static final String MSG_TYPE_TEST = "TEST";
+
+ private final Map map;
+
+ /**
+ *
+ * @param sender sender plugin name
+ * @param receiver receiver plugin name
+ * @param content message content
+ * @param msgId message identifier
+ */
+ public Message(final String msgId, final String sender, final String
receiver,
+ final String type, final Object content) {
+ map = new HashMap();
+ map.put(MSG_SENDER, sender);
+ map.put(MSG_RECEIVER, receiver);
+ map.put(MSG_CONTENT, content);
+ map.put(MSG_ID, msgId);
+ map.put(MSG_TYPE, type);
+ }
+
+ public String getSender() {
+ return (String)map.get(MSG_SENDER);
+ }
+
+ public String getReceiver() {
+ return (String)map.get(MSG_RECEIVER);
+ }
+
+ public Object getContent() {
+ return map.get(MSG_CONTENT);
+ }
+
+ public String getType() {
+ return (String)map.get(MSG_TYPE);
+ }
+
+ public String getId() {
+ return (String)map.get(MSG_ID);
+ }
+
+ public Object getMessageMap() {
+ return map;
+ }
+}
Added:
csplugins/trunk/soc/jgao/PluginsCommunication/src/cytoscape/util/plugins/communication/MessageListener.java
===================================================================
---
csplugins/trunk/soc/jgao/PluginsCommunication/src/cytoscape/util/plugins/communication/MessageListener.java
(rev 0)
+++
csplugins/trunk/soc/jgao/PluginsCommunication/src/cytoscape/util/plugins/communication/MessageListener.java
2009-08-03 02:41:36 UTC (rev 17660)
@@ -0,0 +1,44 @@
+/*
+ Copyright (c) 2006, 2007, 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 cytoscape.util.plugins.communication;
+
+/**
+ *
+ * @author gjj
+ */
+public interface MessageListener {
+ public void messagedReceived(Message msg);
+}
Added:
csplugins/trunk/soc/jgao/PluginsCommunication/src/cytoscape/util/plugins/communication/PluginsCommunicationSupport.java
===================================================================
---
csplugins/trunk/soc/jgao/PluginsCommunication/src/cytoscape/util/plugins/communication/PluginsCommunicationSupport.java
(rev 0)
+++
csplugins/trunk/soc/jgao/PluginsCommunication/src/cytoscape/util/plugins/communication/PluginsCommunicationSupport.java
2009-08-03 02:41:36 UTC (rev 17660)
@@ -0,0 +1,133 @@
+/*
+ Copyright (c) 2006, 2007, 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 cytoscape.util.plugins.communication;
+
+import cytoscape.Cytoscape;
+
+import java.beans.PropertyChangeSupport;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ *
+ * @author gjj
+ */
+public class PluginsCommunicationSupport {
+ private static final String INTER_PLUGIN_COMMUNICATION =
"INTER_PLUGIN_COMMUNICATION";
+ private static final Map<MessageListener, PropertyChangeListener>
listenerMap = new HashMap();
+
+ public static void sendMessage(final String msgId, final String sender,
+ final String receiver, final String msgType) {
+ sendMessage(msgId, sender, receiver, msgType, null);
+ }
+
+ /**
+ * send a message between plugins
+ * @param sender sender plugin name
+ * @param receiver receiver plugin name
+ * @param content message content
+ */
+ public static void sendMessage(final String msgId, final String sender,
+ final String receiver, final String msgType, final Object content)
{
+ sendMessage(new Message(msgId, sender, receiver, msgType, content));
+ }
+
+ /**
+ * send a message between plugins
+ * @param sender sender plugin name
+ * @param receiver receiver plugin name
+ * @param content message content
+ */
+ public static void sendMessage(final Message msg) {
+ if (msg==null) {
+ throw new java.lang.IllegalArgumentException("Message cannot be
null.");
+ }
+
+ PropertyChangeSupport pcs = Cytoscape.getPropertyChangeSupport();
+ pcs.firePropertyChange(INTER_PLUGIN_COMMUNICATION, null, msg);
+ }
+
+ /**
+ *
+ * @param listener
+ */
+ public static void addMessageListener(final MessageListener listener) {
+ addMessageListener(null, listener);
+ }
+
+ /**
+ * add listener for receiver
+ * @param receiver
+ * @param listener
+ */
+ public static void addMessageListener(final String receiver,
+ final MessageListener listener) {
+ if (listener==null) {
+ throw new java.lang.IllegalArgumentException("listener cannot be
null.");
+ }
+
+ PropertyChangeSupport pcs = Cytoscape.getPropertyChangeSupport();
+ pcs.addPropertyChangeListener(INTER_PLUGIN_COMMUNICATION,
+ new PropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent evt) {
+ Object obj = evt.getNewValue();
+ if (obj==null) return;
+ if (!(obj instanceof Message)) return;
+
+ Message msg = (Message)obj;
+ String msgReceiver = msg.getReceiver();
+
+ if (receiver!=null && msgReceiver!=null
+ && msgReceiver.compareTo(receiver)!=0) return;
+
+ listener.messagedReceived(msg);
+
+ listenerMap.put(listener, this);
+ }
+ });
+ }
+
+ public static void removeMessageListener(final MessageListener listener) {
+ PropertyChangeSupport pcs = Cytoscape.getPropertyChangeSupport();
+ PropertyChangeListener pcl = listenerMap.get(listener);
+ if (pcl!=null) {
+ pcs.removePropertyChangeListener(INTER_PLUGIN_COMMUNICATION, pcl);
+ }
+ }
+}
Added:
csplugins/trunk/soc/jgao/PluginsCommunication/test/cytoscape/util/plugins/communication/Test.java
===================================================================
---
csplugins/trunk/soc/jgao/PluginsCommunication/test/cytoscape/util/plugins/communication/Test.java
(rev 0)
+++
csplugins/trunk/soc/jgao/PluginsCommunication/test/cytoscape/util/plugins/communication/Test.java
2009-08-03 02:41:36 UTC (rev 17660)
@@ -0,0 +1,25 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package cytoscape.util.plugins.communication;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author gjj
+ */
+public class Test extends TestCase {
+
+ public void testComm() {
+ PluginsCommunicationSupport.addMessageListener("receiver1", new
MessageListener() {
+ public void messagedReceived(Message msg) {
+ javax.swing.JOptionPane.showMessageDialog(null, "bingo");
+ }
+ });
+
+ PluginsCommunicationSupport.sendMessage(null,"sender1",
"receiver1",null);
+ }
+}
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---