Author: kono
Date: 2009-12-03 18:23:36 -0800 (Thu, 03 Dec 2009)
New Revision: 18653

Added:
   csplugins/trunk/ucsd/kono/JRubyEngine/build.xml
   csplugins/trunk/ucsd/kono/JRubyEngine/images/
   csplugins/trunk/ucsd/kono/JRubyEngine/images/ruby.png
   csplugins/trunk/ucsd/kono/JRubyEngine/images/ruby22x22.png
   csplugins/trunk/ucsd/kono/JRubyEngine/lib/
   csplugins/trunk/ucsd/kono/JRubyEngine/lib/ScriptEngineManager.jar
   csplugins/trunk/ucsd/kono/JRubyEngine/lib/jruby-complete-1.4.0.jar
   csplugins/trunk/ucsd/kono/JRubyEngine/lib/jruby-embed-0.1.3.jar
   csplugins/trunk/ucsd/kono/JRubyEngine/plugin.props
   csplugins/trunk/ucsd/kono/JRubyEngine/src/
   csplugins/trunk/ucsd/kono/JRubyEngine/src/edu/
   csplugins/trunk/ucsd/kono/JRubyEngine/src/edu/ucsd/
   csplugins/trunk/ucsd/kono/JRubyEngine/src/edu/ucsd/bioeng/
   csplugins/trunk/ucsd/kono/JRubyEngine/src/edu/ucsd/bioeng/idekerlab/
   
csplugins/trunk/ucsd/kono/JRubyEngine/src/edu/ucsd/bioeng/idekerlab/rubyengine/
   
csplugins/trunk/ucsd/kono/JRubyEngine/src/edu/ucsd/bioeng/idekerlab/rubyengine/RubyEnginePlugin.java
   
csplugins/trunk/ucsd/kono/JRubyEngine/src/edu/ucsd/bioeng/idekerlab/rubyengine/console/
   
csplugins/trunk/ucsd/kono/JRubyEngine/src/edu/ucsd/bioeng/idekerlab/rubyengine/console/CyIRBConsole.java
   
csplugins/trunk/ucsd/kono/JRubyEngine/src/edu/ucsd/bioeng/idekerlab/rubyengine/console/IRBConsoleDialog.java
   
csplugins/trunk/ucsd/kono/JRubyEngine/src/edu/ucsd/bioeng/idekerlab/rubyengine/console/TextAreaReadLine2.java
   csplugins/trunk/ucsd/kono/JRubyEngine/testscripts/
   csplugins/trunk/ucsd/kono/JRubyEngine/testscripts/all_subnetworks.rb
   csplugins/trunk/ucsd/kono/JRubyEngine/testscripts/ba_model_generator.rb
   csplugins/trunk/ucsd/kono/JRubyEngine/testscripts/binary_matrix.rb
   csplugins/trunk/ucsd/kono/JRubyEngine/testscripts/hello_world.rb
   csplugins/trunk/ucsd/kono/JRubyEngine/testscripts/kegg_relation_mapper.rb
   csplugins/trunk/ucsd/kono/JRubyEngine/testscripts/load_multiple_networks.rb
   csplugins/trunk/ucsd/kono/JRubyEngine/testscripts/load_networks.rb
   csplugins/trunk/ucsd/kono/JRubyEngine/utilscripts/
   csplugins/trunk/ucsd/kono/JRubyEngine/utilscripts/biorubyshell.rb
Log:
New JRuby Scripting Engine for Cytoscape 2.7.

Added: csplugins/trunk/ucsd/kono/JRubyEngine/build.xml
===================================================================
--- csplugins/trunk/ucsd/kono/JRubyEngine/build.xml                             
(rev 0)
+++ csplugins/trunk/ucsd/kono/JRubyEngine/build.xml     2009-12-04 02:23:36 UTC 
(rev 18653)
@@ -0,0 +1,109 @@
+<?xml version="1.0"?>
+<!-- 
+
+       Ruby script engine for Cytoscape by Kei Ono 
+       
+       To build this plugin, you need to download JRuby separately.
+       
+-->
+
+<project name="RubyScriptingEngine" default="all" basedir=".">
+
+       <property name="jruby.version" value="jruby-1.4.0" />
+
+       <!-- You need modify this to your Cytoscape -->
+       <property name="cytoscape.dir" value="../workspaceC2/cytoscape" />
+
+       <!-- All files generated by ant go here -->
+       <property name="build.dir" value="${basedir}/build" />
+
+       <!-- The java source directory-->
+       <property name="src.dir" value="${basedir}/src" />
+
+       <property name="project.jar" value="RubyScriptingEngine.jar" />
+
+       <!--  ============ Compilation Control Options ======================= 
-->
+       <property name="compile.debug" value="true" />
+       <property name="compile.deprecation" value="true" />
+       <property name="compile.optimize" value="true" />
+
+
+       <!-- ==================== Compilation Classpath ====================== 
-->
+       <path id="compile.classpath">
+               <fileset dir="${cytoscape.dir}">
+                       <include name="cytoscape.jar" />
+               </fileset>
+               <fileset dir="${basedir}/lib">
+                       <include name="*.jar" />
+               </fileset>
+               <!--fileset dir="../ScriptEngine1">
+                                       <include name="ScriptEngineManager.jar" 
/>
+               </fileset-->
+       </path>
+
+       <!-- ==================== Clean Target =============================== 
-->
+       <target name="clean" description="Deletes all build files and starts 
fresh">
+               <delete dir="${build.dir}" />
+               <delete file="${project.jar}" />
+       </target>
+
+       <!-- ==================== Compile Target 
==============================-->
+       <target name="compile" depends="prepare" description="Compiles all Java 
source files">
+               <mkdir dir="${build.dir}/classes" />
+               <javac srcdir="${src.dir}" source="1.5" target="1.5" 
destdir="${build.dir}/classes" debug="${compile.debug}" 
deprecation="${compile.deprecation}" optimize="${compile.optimize}">
+                       <classpath refid="compile.classpath" />
+               </javac>
+       </target>
+
+       <!-- ==================== Jar Target ============================== -->
+       <target name="jar" depends="compile" description="Creates Plugin Jar:  
${project.jar}">
+
+               <unjar dest="${build.dir}/classes">
+
+                       <fileset dir="${basedir}/lib">
+                               <include name="*.jar" />
+                       </fileset>
+               </unjar>
+
+               <copy 
todir="${build.dir}/classes/edu/ucsd/bioeng/idekerlab/rubyengine" 
file="${basedir}/plugin.props" />
+
+               <copy todir="${build.dir}/classes/images">
+                       <fileset dir="${basedir}/images" />
+               </copy>
+
+               <copy todir="${build.dir}/classes/utilscripts">
+                       <fileset dir="${basedir}/utilscripts" />
+               </copy>
+
+
+
+               <jar destfile="${project.jar}" basedir="${build.dir}/classes">
+
+                       <manifest>
+                               <attribute name="Cytoscape-Plugin" 
value="edu.ucsd.bioeng.idekerlab.rubyengine.RubyEnginePlugin" />
+                       </manifest>
+
+               </jar>
+       </target>
+
+       <!-- ==================== Build and test jar 
============================== -->
+       <target name="all" depends="jar" />
+
+       <!-- ==================== Prepare Target ============================== 
-->
+       <target name="prepare">
+               <!-- Create build directories as needed -->
+               <mkdir dir="${build.dir}" />
+               <mkdir dir="${build.dir}/classes" />
+
+       </target>
+
+       <!-- ==================== JUnit Test Target =========================== 
-->
+       <target name="test" description="Runs all JUnit tests" 
depends="compile">
+               <junit printsummary="yes" fork="yes" haltonfailure="yes">
+                       <formatter type="plain" usefile="false" />
+                       <test name="cytoscape.test.AllTest" />
+                       <classpath refid="compile.classpath" />
+               </junit>
+       </target>
+
+</project>

Added: csplugins/trunk/ucsd/kono/JRubyEngine/images/ruby.png
===================================================================
(Binary files differ)


Property changes on: csplugins/trunk/ucsd/kono/JRubyEngine/images/ruby.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: csplugins/trunk/ucsd/kono/JRubyEngine/images/ruby22x22.png
===================================================================
(Binary files differ)


Property changes on: csplugins/trunk/ucsd/kono/JRubyEngine/images/ruby22x22.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: csplugins/trunk/ucsd/kono/JRubyEngine/lib/ScriptEngineManager.jar
===================================================================
(Binary files differ)


Property changes on: 
csplugins/trunk/ucsd/kono/JRubyEngine/lib/ScriptEngineManager.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: csplugins/trunk/ucsd/kono/JRubyEngine/lib/jruby-complete-1.4.0.jar
===================================================================
(Binary files differ)


Property changes on: 
csplugins/trunk/ucsd/kono/JRubyEngine/lib/jruby-complete-1.4.0.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: csplugins/trunk/ucsd/kono/JRubyEngine/lib/jruby-embed-0.1.3.jar
===================================================================
(Binary files differ)


Property changes on: 
csplugins/trunk/ucsd/kono/JRubyEngine/lib/jruby-embed-0.1.3.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: csplugins/trunk/ucsd/kono/JRubyEngine/plugin.props
===================================================================
--- csplugins/trunk/ucsd/kono/JRubyEngine/plugin.props                          
(rev 0)
+++ csplugins/trunk/ucsd/kono/JRubyEngine/plugin.props  2009-12-04 02:23:36 UTC 
(rev 18653)
@@ -0,0 +1,22 @@
+# -- The following properties are REQUIRED -- #
+
+# The plugin name that will be displayed to users
+pluginName=RubyScriptingEngine
+
+# Description used to give users information about the plugin such as what it 
does.  
+# Html tags are encouraged for formatting purposes.
+pluginDescription=<p>Scripting Engine based on jruby 1.4.0 implementation.  
The console is now integrated with BioRuby Shell.</p><p><strong><font 
color="red">This plugin is for technology evaluation purpose ONLY!  Totally 
experimental.</font></strong>
+
+# Plugin version number, this must be two numbers separated by a decimlal.  
Ex. 0.2, 14.03
+pluginVersion=0.20
+
+# Compatible Cytoscape version
+cytoscapeVersion=2.7
+
+# Category, use one of the categories listed on the website or create your own
+pluginCategory=Communication/Scripting
+
+
+# List of authors.  Note each author and institution pair are separated by a : 
(colon)
+# each additional author institution pair must be separated from other pairs 
bye a ; (semicolon)
+pluginAuthorsIntsitutions=Keiichiro Ono:UCSD Department of Medicine
\ No newline at end of file

Added: 
csplugins/trunk/ucsd/kono/JRubyEngine/src/edu/ucsd/bioeng/idekerlab/rubyengine/RubyEnginePlugin.java
===================================================================
--- 
csplugins/trunk/ucsd/kono/JRubyEngine/src/edu/ucsd/bioeng/idekerlab/rubyengine/RubyEnginePlugin.java
                                (rev 0)
+++ 
csplugins/trunk/ucsd/kono/JRubyEngine/src/edu/ucsd/bioeng/idekerlab/rubyengine/RubyEnginePlugin.java
        2009-12-04 02:23:36 UTC (rev 18653)
@@ -0,0 +1,155 @@
+/*
+ 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 edu.ucsd.bioeng.idekerlab.rubyengine;
+
+import java.awt.event.ActionEvent;
+import java.beans.PropertyChangeEvent;
+import java.io.IOException;
+import java.lang.reflect.Method;
+
+import javax.swing.AbstractAction;
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+import javax.swing.JMenuItem;
+
+import org.apache.bsf.BSFManager;
+import org.jruby.embed.ScriptingContainer;
+
+import cytoscape.Cytoscape;
+import cytoscape.logger.CyLogger;
+import cytoscape.plugin.CytoscapePlugin;
+import edu.ucsd.bioeng.idekerlab.rubyengine.console.CyIRBConsole;
+import edu.ucsd.bioeng.idekerlab.scriptenginemanager.ScriptEngineManagerPlugin;
+import edu.ucsd.bioeng.idekerlab.scriptenginemanager.engine.ScriptingEngine;
+
+
+/**
+ *
+ */
+public class RubyEnginePlugin extends CytoscapePlugin implements 
ScriptingEngine {
+       private static final String ENGINE_NAME = "jruby";
+       private static final String ENGINE_DISPLAY_NAME = "Ruby Scripting 
Engine (based on JRuby v1.4.0)";
+       private static final Icon ICON = new 
ImageIcon(RubyEnginePlugin.class.getResource("/images/ruby.png"));
+       private static final RubyEnginePlugin engine = new RubyEnginePlugin();
+
+       /**
+        * Creates a new RubyEnginePlugin object.
+        */
+       public RubyEnginePlugin() {
+               
Cytoscape.getPropertyChangeSupport().addPropertyChangeListener(this);
+       }
+
+       /**
+        *  DOCUMENT ME!
+        *
+        * @return  DOCUMENT ME!
+        */
+       public String getDisplayName() {
+               // TODO Auto-generated method stub
+               return ENGINE_DISPLAY_NAME;
+       }
+
+       /**
+        *  DOCUMENT ME!
+        *
+        * @return  DOCUMENT ME!
+        */
+       public Icon getIcon() {
+               // TODO Auto-generated method stub
+               return ICON;
+       }
+
+       /**
+        *  DOCUMENT ME!
+        *
+        * @return  DOCUMENT ME!
+        */
+       public String getIdentifier() {
+               // TODO Auto-generated method stub
+               return ENGINE_NAME;
+       }
+
+       /**
+        *  DOCUMENT ME!
+        */
+       public static void register() {
+//             System.setProperty("jruby.home", 
"/Users/kono/Library/jruby-1.4.0");
+               ScriptingContainer container = new ScriptingContainer();
+               
+               BSFManager.registerScriptingEngine("jruby", 
"org.jruby.embed.bsf.JRubyEngine", new String[] {ENGINE_NAME});
+
+               System.out.println("*JRuby scripting engine loaded!");
+
+               try {
+                       final Class<?> engineClass = 
Class.forName("edu.ucsd.bioeng.idekerlab.scriptenginemanager.ScriptEngineManager");
+                       Method method = engineClass.getMethod("registerEngine",
+                                                             new Class[] { 
String.class, ScriptingEngine.class });
+                       method.invoke(null, new Object[] { ENGINE_NAME, engine 
});
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+
+               final JMenuItem consoleMenuItem = new JMenuItem(new 
AbstractAction("Open Ruby Console") {
+                               public void actionPerformed(ActionEvent e) {
+                                       try {
+                                               CyIRBConsole.showConsole();
+                                       } catch (IOException e1) {
+                                               
CyLogger.getLogger().error("Ruby Colsone Error", e1);
+                                       }
+                               }
+                       });
+
+               consoleMenuItem.setIcon(new 
ImageIcon(RubyEnginePlugin.class.getResource("/images/ruby22x22.png")));
+
+               
ScriptEngineManagerPlugin.getManager().addConsoleMenu(consoleMenuItem);
+
+               CyLogger.getLogger().info("Ruby scripting engine registered 
successfully.");
+       }
+
+       /**
+        *  DOCUMENT ME!
+        *
+        * @param e DOCUMENT ME!
+        */
+       public void propertyChange(PropertyChangeEvent e) {
+               if 
(ScriptEngineManagerPlugin.getManager().getEngine(ENGINE_NAME) != null)
+                       return;
+
+               if 
(e.getPropertyName().equals(Cytoscape.CYTOSCAPE_INITIALIZED)) {
+                       // Register this to ScriptEngineManager.
+                       register();
+               }
+       }
+}

Added: 
csplugins/trunk/ucsd/kono/JRubyEngine/src/edu/ucsd/bioeng/idekerlab/rubyengine/console/CyIRBConsole.java
===================================================================
--- 
csplugins/trunk/ucsd/kono/JRubyEngine/src/edu/ucsd/bioeng/idekerlab/rubyengine/console/CyIRBConsole.java
                            (rev 0)
+++ 
csplugins/trunk/ucsd/kono/JRubyEngine/src/edu/ucsd/bioeng/idekerlab/rubyengine/console/CyIRBConsole.java
    2009-12-04 02:23:36 UTC (rev 18653)
@@ -0,0 +1,231 @@
+/*
+ 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 edu.ucsd.bioeng.idekerlab.rubyengine.console;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.GraphicsEnvironment;
+import java.awt.Insets;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import javax.swing.BorderFactory;
+import javax.swing.ImageIcon;
+import javax.swing.JEditorPane;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTextPane;
+import javax.swing.SwingConstants;
+
+import org.jruby.Ruby;
+import org.jruby.RubyInstanceConfig;
+import org.jruby.internal.runtime.ValueAccessor;
+
+import cytoscape.Cytoscape;
+import cytoscape.view.cytopanels.CytoPanelState;
+import edu.ucsd.bioeng.idekerlab.rubyengine.RubyEnginePlugin;
+
+/**
+ * Ruby Console for Cytoscape based on demo code in JRuby distribution.
+ * 
+ * @author Keiichiro Ono
+ */
+public class CyIRBConsole extends JPanel {
+       private static CyIRBConsole console = null;
+       private static Ruby runtime = null;
+       private static final ExecutorService consoleService = Executors
+                       .newCachedThreadPool();
+       private static final String BIORUBY_SCRIPT_LOCATION = 
"/utilscripts/biorubyshell.rb";
+       private static String startScript;
+
+       private static final ImageIcon tabIcon = new ImageIcon(
+                       
RubyEnginePlugin.class.getResource("/images/ruby22x22.png"));
+
+       /**
+        * Creates a new CyIRBConsole object.
+        * 
+        * @param title
+        *            DOCUMENT ME!
+        * @throws IOException
+        */
+       public CyIRBConsole(String title) throws IOException {
+               // super(title);
+
+               InputStreamReader in = null;
+               StringBuilder builder = new StringBuilder();
+
+               in = new InputStreamReader(RubyEnginePlugin.class.getResource(
+                               BIORUBY_SCRIPT_LOCATION).openStream());
+
+               BufferedReader br = new BufferedReader(in);
+
+               String line;
+
+               while ((line = br.readLine()) != null) {
+                       builder.append(line + "\n");
+               }
+
+               br.close();
+               in.close();
+
+               br = null;
+               in = null;
+
+               startScript = builder.toString();
+       }
+
+       /**
+        * DOCUMENT ME!
+        * 
+        * @throws IOException
+        */
+       public static void showConsole() throws IOException {
+               if (console == null) {
+                       // Initialize console
+                       if (runtime == null)
+                               runtime = Ruby.newInstance();
+
+                       console = new CyIRBConsole("Cytoscape-Ruby Interactive 
Console");
+                       buildConsole(null);
+
+                       
Cytoscape.getDesktop().getCytoPanel(SwingConstants.EAST).add(
+                                       "Cytoscape-BioRuby Console", tabIcon, 
console);
+
+                       
Cytoscape.getDesktop().getCytoPanel(SwingConstants.EAST).setState(
+                                       CytoPanelState.DOCK);
+               }
+
+               consoleService.execute(new Runnable() {
+                       public void run() {
+                               runtime.evalScriptlet(startScript);
+
+                               
Cytoscape.getDesktop().getCytoPanel(SwingConstants.EAST)
+                                               .remove(console);
+                               if 
(Cytoscape.getDesktop().getCytoPanel(SwingConstants.EAST)
+                                               .getCytoPanelComponentCount() 
== 0)
+                                       
Cytoscape.getDesktop().getCytoPanel(SwingConstants.EAST)
+                                                       
.setState(CytoPanelState.HIDE);
+                               runtime.tearDown();
+                               console = null;
+                               System.out.println("Console terminated!");
+                       }
+               });
+
+       }
+
+       /**
+        * DOCUMENT ME!
+        * 
+        * @param args
+        *            DOCUMENT ME!
+        */
+       public static void buildConsole(final String[] args) {
+               console.setLayout(new BorderLayout());
+               console.setPreferredSize(new Dimension(500, 600));
+
+               final JEditorPane text = new JTextPane();
+               text.setMargin(new Insets(8, 8, 8, 8));
+               text.setCaretColor(new Color(0xa4, 0x00, 0x00));
+               text.setBackground(Color.white);
+               text.setForeground(Color.red);
+
+               final Font font = console.findFont("Monospaced", Font.PLAIN, 14,
+                               new String[] { "Monaco", "Andale Mono" });
+               text.setFont(font);
+
+               final JScrollPane pane = new JScrollPane();
+               pane.setViewportView(text);
+               pane.setBorder(BorderFactory.createLineBorder(Color.darkGray));
+               console.add(pane);
+               console.validate();
+
+               final TextAreaReadLine2 tar = new TextAreaReadLine2(text,
+                               " Welcome to CyRuby Console \n"
+                                               + " Starting BioRuby Shell.  
Please wait...\n\n");
+
+               final RubyInstanceConfig config = new RubyInstanceConfig() {
+
+                       {
+                               setInput(tar.getInputStream());
+                               setOutput(new 
PrintStream(tar.getOutputStream()));
+                               setError(new 
PrintStream(tar.getOutputStream()));
+                               setObjectSpaceEnabled(true); // useful for code 
completion
+                               // inside the IRB
+                               // setArgv(args);
+                       }
+               };
+
+               runtime = Ruby.newInstance(config);
+
+               runtime.getGlobalVariables().defineReadonly(
+                               "$$",
+                               new ValueAccessor(runtime.newFixnum(System
+                                               .identityHashCode(runtime))));
+               runtime.getLoadService().init(new ArrayList());
+
+               tar.hookIntoRuntime(runtime);
+
+       }
+
+       private Font findFont(String otherwise, int style, int size,
+                       String[] families) {
+               String[] fonts = 
GraphicsEnvironment.getLocalGraphicsEnvironment()
+                               .getAvailableFontFamilyNames();
+               Arrays.sort(fonts);
+
+               Font font = null;
+
+               for (int i = 0; i < families.length; i++) {
+                       if (Arrays.binarySearch(fonts, families[i]) >= 0) {
+                               font = new Font(families[i], style, size);
+
+                               break;
+                       }
+               }
+
+               if (font == null)
+                       font = new Font(otherwise, style, size);
+
+               return font;
+       }
+}

Added: 
csplugins/trunk/ucsd/kono/JRubyEngine/src/edu/ucsd/bioeng/idekerlab/rubyengine/console/IRBConsoleDialog.java
===================================================================
--- 
csplugins/trunk/ucsd/kono/JRubyEngine/src/edu/ucsd/bioeng/idekerlab/rubyengine/console/IRBConsoleDialog.java
                                (rev 0)
+++ 
csplugins/trunk/ucsd/kono/JRubyEngine/src/edu/ucsd/bioeng/idekerlab/rubyengine/console/IRBConsoleDialog.java
        2009-12-04 02:23:36 UTC (rev 18653)
@@ -0,0 +1,124 @@
+package edu.ucsd.bioeng.idekerlab.rubyengine.console;
+
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.Insets;
+import java.awt.Rectangle;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+
+import javax.swing.BorderFactory;
+import javax.swing.JDialog;
+import javax.swing.JScrollPane;
+import javax.swing.JTextPane;
+import javax.swing.SwingUtilities;
+import javax.swing.UIManager;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.JTextComponent;
+
+import org.jruby.Ruby;
+import org.jruby.demo.TextAreaReadline;
+
+import sun.misc.RequestProcessor;
+
+import com.sun.jmx.snmp.tasks.Task;
+
+public class IRBConsoleDialog extends JDialog {
+
+       private boolean finished = true;
+    private JTextPane text;
+
+       
+       public void createTerminal() {
+        text = new JTextPane();
+
+        text.setMargin(new Insets(8,8,8,8));
+        text.setCaretColor(new Color(0xa4, 0x00, 0x00));
+        text.setBackground(new Color(0xf2, 0xf2, 0xf2));
+        text.setForeground(new Color(0xa4, 0x00, 0x00));
+        
+        // From core/output2/**/AbstractOutputPane
+        Integer i = (Integer) UIManager.get("customFontSize"); //NOI18N
+        int size;
+        if (i != null) {
+            size = i.intValue();
+        } else {
+            Font f = (Font) UIManager.get("controlFont"); // NOI18N
+            size = f != null ? f.getSize() : 11;
+        }
+        text.setFont(new Font ("Monospaced", Font.PLAIN, size)); //NOI18N
+        //setBorder (BorderFactory.createEmptyBorder());
+        
+        // Try to initialize colors from NetBeans properties, see core/output2
+        Color c = UIManager.getColor("nb.output.selectionBackground"); // 
NOI18N
+        if (c != null) {
+            text.setSelectionColor(c);
+        }
+        
+      
+        
+        
+        JScrollPane pane = new JScrollPane();
+        pane.setViewportView(text);
+        pane.setBorder(BorderFactory.createLineBorder(Color.darkGray));
+        add(pane);
+        validate();
+
+        final Ruby runtime = getRuntime(text);
+//        startIRB(runtime);
+        
+//        RequestProcessor.Task task = 
RequestProcessor.getDefault().create(new Runnable() {
+//        //RequestProcessor.getDefault().post(new Runnable() {
+//            public void run() {
+//                
+//            }
+//        });
+//        task.addTaskListener(new TaskListener() {
+//            public void taskFinished(Task task) {
+//                finished = true;
+//                //tar.writeMessage(" " + 
NbBundle.getMessage(IrbTopComponent.class, "IrbGoodbye") + " "); // NOI18N
+//                text.setEditable(false);
+//                SwingUtilities.invokeLater(new Runnable() {
+//                    public void run() {
+//                        IrbTopComponent.this.close();
+//                        IrbTopComponent.this.removeAll();
+//                        text = null;
+//                    }
+//                });
+//            }
+//        });
+//        task.schedule(10);
+        
+       }
+       
+       
+       static Ruby getRuntime(final JTextComponent text) {
+//            final TextAreaReadline tar = new TextAreaReadline(text,
+//                    " " + NbBundle.getMessage(IrbTopComponent.class, 
"IrbWelcome") + " \n\n"); // NOI18N
+//            // Ensure that ClassPath can find libraries etc.
+//            RubyInstallation.getInstance().setJRubyLoadPaths();
+//
+//            final PipedInputStream pipeIn = new PipedInputStream();
+//            final RubyInstanceConfig config = new RubyInstanceConfig() {{
+//                setInput(pipeIn);
+//                setOutput(new PrintStream(tar));
+//                setError(new PrintStream(tar));
+//                setObjectSpaceEnabled(false);
+//                //setArgv(args);
+//            }};
+//            final Ruby runtime = Ruby.newInstance(config);
+//
+//            runtime.getGlobalVariables().defineReadonly("$$", new 
ValueAccessor(runtime.newFixnum(System.identityHashCode(runtime))));
+//            runtime.getLoadService().init(new ArrayList());
+//
+//            tar.hookIntoRuntime(runtime);
+//            return runtime;
+//        }
+//        
+//        private static void startIRB(final Ruby runtime) {
+//            runtime.evalScriptlet("require 'irb'; require 'irb/completion'; 
IRB.start"); // NOI18N
+//        }
+//     
+               return null;
+       }
+}

Added: 
csplugins/trunk/ucsd/kono/JRubyEngine/src/edu/ucsd/bioeng/idekerlab/rubyengine/console/TextAreaReadLine2.java
===================================================================
--- 
csplugins/trunk/ucsd/kono/JRubyEngine/src/edu/ucsd/bioeng/idekerlab/rubyengine/console/TextAreaReadLine2.java
                               (rev 0)
+++ 
csplugins/trunk/ucsd/kono/JRubyEngine/src/edu/ucsd/bioeng/idekerlab/rubyengine/console/TextAreaReadLine2.java
       2009-12-04 02:23:36 UTC (rev 18653)
@@ -0,0 +1,667 @@
+
+/*
+ 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 edu.ucsd.bioeng.idekerlab.rubyengine.console;
+
+import org.jruby.Ruby;
+import org.jruby.RubyModule;
+import org.jruby.RubyString;
+
+import org.jruby.ext.Readline;
+
+import org.jruby.runtime.Arity;
+import org.jruby.runtime.Block;
+import org.jruby.runtime.builtin.IRubyObject;
+import org.jruby.runtime.callback.Callback;
+
+import java.awt.Color;
+import java.awt.EventQueue;
+import java.awt.Point;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+import javax.swing.DefaultListCellRenderer;
+import javax.swing.JComboBox;
+import javax.swing.plaf.basic.BasicComboPopup;
+import javax.swing.text.AbstractDocument;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.DocumentFilter;
+import javax.swing.text.JTextComponent;
+import javax.swing.text.MutableAttributeSet;
+import javax.swing.text.SimpleAttributeSet;
+import javax.swing.text.StyleConstants;
+
+
+/**
+ *
+ */
+public class TextAreaReadLine2 implements KeyListener {
+       private static final String EMPTY_LINE = "";
+       private JTextComponent area;
+       private int startPos;
+       private String currentLine;
+
+       /**
+        * 
+        */
+       public volatile MutableAttributeSet promptStyle;
+
+       /**
+        * 
+        */
+       public volatile MutableAttributeSet inputStyle;
+
+       /**
+        * 
+        */
+       public volatile MutableAttributeSet outputStyle;
+
+       /**
+        * 
+        */
+       public volatile MutableAttributeSet resultStyle;
+       private JComboBox completeCombo;
+       private BasicComboPopup completePopup;
+       private int start;
+       private int end;
+       private volatile boolean finished = false;
+       private final InputStream inputStream = new Input();
+       private final OutputStream outputStream = new Output();
+       private volatile BlockingQueue<String> pendingLines = new 
LinkedBlockingQueue<String>();
+
+       /**
+        * Creates a new TextAreaReadLine2 object.
+        *
+        * @param area  DOCUMENT ME!
+        */
+       public TextAreaReadLine2(JTextComponent area) {
+               this(area, null);
+       }
+
+       /**
+        * Creates a new TextAreaReadLine2 object.
+        *
+        * @param area  DOCUMENT ME!
+        * @param message  DOCUMENT ME!
+        */
+       public TextAreaReadLine2(JTextComponent area, final String message) {
+               this.area = area;
+
+               area.addKeyListener(this);
+
+               // No editing before startPos
+               if (area.getDocument() instanceof AbstractDocument)
+                       ((AbstractDocument) 
area.getDocument()).setDocumentFilter(new DocumentFilter() {
+                                       public void 
insertString(DocumentFilter.FilterBypass fb, int offset,
+                                                                String string, 
AttributeSet attr)
+                                           throws BadLocationException {
+                                               if (offset >= startPos)
+                                                       super.insertString(fb, 
offset, string, attr);
+                                       }
+
+                                       public void 
remove(DocumentFilter.FilterBypass fb, int offset, int length)
+                                           throws BadLocationException {
+                                               if (offset >= startPos)
+                                                       super.remove(fb, 
offset, length);
+                                       }
+
+                                       public void 
replace(DocumentFilter.FilterBypass fb, int offset, int length,
+                                                           String text, 
AttributeSet attrs)
+                                           throws BadLocationException {
+                                               if (offset >= startPos)
+                                                       super.replace(fb, 
offset, length, text, attrs);
+                                       }
+                               });
+
+
+               promptStyle = new SimpleAttributeSet();
+               StyleConstants.setForeground(promptStyle, new Color(0xa4, 0x00, 
0x00));
+
+               inputStyle = new SimpleAttributeSet();
+               StyleConstants.setForeground(inputStyle, new Color(0x20, 0x4a, 
0x87));
+
+               outputStyle = new SimpleAttributeSet();
+               StyleConstants.setForeground(outputStyle, Color.darkGray);
+
+               resultStyle = new SimpleAttributeSet();
+               StyleConstants.setItalic(resultStyle, true);
+               StyleConstants.setForeground(resultStyle, new Color(0x20, 0x4a, 
0x87));
+
+               completeCombo = new JComboBox();
+               completeCombo.setRenderer(new DefaultListCellRenderer()); // no 
silly ticks!
+               completePopup = new BasicComboPopup(completeCombo);
+
+               if (message != null) {
+                       final MutableAttributeSet messageStyle = new 
SimpleAttributeSet();
+                       StyleConstants.setBackground(messageStyle, 
area.getForeground());
+                       StyleConstants.setForeground(messageStyle, 
area.getBackground());
+                       append(message, messageStyle);
+               }
+
+               startPos = area.getDocument().getLength();
+       }
+
+       /**
+        *  DOCUMENT ME!
+        *
+        * @return  DOCUMENT ME!
+        */
+       public InputStream getInputStream() {
+               return inputStream;
+       }
+
+       /**
+        *  DOCUMENT ME!
+        *
+        * @return  DOCUMENT ME!
+        */
+       public OutputStream getOutputStream() {
+               return outputStream;
+       }
+
+       private Ruby runtime;
+
+       /**
+        *  DOCUMENT ME!
+        *
+        * @param runtime DOCUMENT ME!
+        */
+       public void hookIntoRuntime(final Ruby runtime) {
+               this.runtime = runtime;
+               /* Hack in to replace usual readline with this */
+               runtime.getLoadService().require("readline");
+
+               RubyModule readlineM = runtime.fastGetModule("Readline");
+
+               readlineM.defineModuleFunction("readline",
+                                              new Callback() {
+                               public IRubyObject execute(IRubyObject recv, 
IRubyObject[] args, Block block) {
+                                       String line = 
readLine(args[0].toString());
+
+                                       if (line != null) {
+                                               return 
RubyString.newUnicodeString(runtime, line);
+                                       } else {
+                                               return runtime.getNil();
+                                       }
+                               }
+
+                               public Arity getArity() {
+                                       return Arity.twoArguments();
+                               }
+                       });
+       }
+
+       protected void completeAction(KeyEvent event) {
+               if (Readline.getCompletor(Readline.getHolder(runtime)) == null)
+                       return;
+
+               event.consume();
+
+               if (completePopup.isVisible())
+                       return;
+
+               List candidates = new LinkedList();
+               String bufstr = null;
+
+               try {
+                       bufstr = area.getText(startPos, area.getCaretPosition() 
- startPos);
+               } catch (BadLocationException e) {
+                       return;
+               }
+
+               int cursor = area.getCaretPosition() - startPos;
+
+               int position = 
Readline.getCompletor(Readline.getHolder(runtime))
+                                      .complete(bufstr, cursor, candidates);
+
+               // no candidates? Fail.
+               if (candidates.isEmpty())
+                       return;
+
+               if (candidates.size() == 1) {
+                       replaceText(startPos + position, 
area.getCaretPosition(), (String) candidates.get(0));
+
+                       return;
+               }
+
+               start = startPos + position;
+               end = area.getCaretPosition();
+
+               Point pos = area.getCaret().getMagicCaretPosition();
+
+               // bit risky if someone changes completor, but useful for 
method calls
+               int cutoff = bufstr.substring(position).lastIndexOf('.') + 1;
+               start += cutoff;
+
+               if (candidates.size() < 10)
+                       
completePopup.getList().setVisibleRowCount(candidates.size());
+               else
+                       completePopup.getList().setVisibleRowCount(10);
+
+               completeCombo.removeAllItems();
+
+               for (Iterator i = candidates.iterator(); i.hasNext();) {
+                       String item = (String) i.next();
+
+                       if (cutoff != 0)
+                               item = item.substring(cutoff);
+
+                       completeCombo.addItem(item);
+               }
+
+               completePopup.show(area, pos.x, pos.y + 
area.getFontMetrics(area.getFont()).getHeight());
+       }
+
+       protected void backAction(KeyEvent event) {
+               if (area.getCaretPosition() <= startPos)
+                       event.consume();
+       }
+
+       protected void upAction(KeyEvent event) {
+               event.consume();
+
+               if (completePopup.isVisible()) {
+                       int selected = completeCombo.getSelectedIndex() - 1;
+
+                       if (selected < 0)
+                               return;
+
+                       completeCombo.setSelectedIndex(selected);
+
+                       return;
+               }
+
+               if (!Readline.getHistory(Readline.getHolder(runtime)).next()) 
// at end
+                       currentLine = getLine();
+               else
+                       
Readline.getHistory(Readline.getHolder(runtime)).previous(); // undo check
+
+               if 
(!Readline.getHistory(Readline.getHolder(runtime)).previous())
+                       return;
+
+               String oldLine = 
Readline.getHistory(Readline.getHolder(runtime)).current().trim();
+               replaceText(startPos, area.getDocument().getLength(), oldLine);
+       }
+
+       protected void downAction(KeyEvent event) {
+               event.consume();
+
+               if (completePopup.isVisible()) {
+                       int selected = completeCombo.getSelectedIndex() + 1;
+
+                       if (selected == completeCombo.getItemCount())
+                               return;
+
+                       completeCombo.setSelectedIndex(selected);
+
+                       return;
+               }
+
+               if (!Readline.getHistory(Readline.getHolder(runtime)).next())
+                       return;
+
+               String oldLine;
+
+               if (!Readline.getHistory(Readline.getHolder(runtime)).next()) 
// at end
+                       oldLine = currentLine;
+               else {
+                       
Readline.getHistory(Readline.getHolder(runtime)).previous(); // undo check
+                       oldLine = 
Readline.getHistory(Readline.getHolder(runtime)).current().trim();
+               }
+
+               replaceText(startPos, area.getDocument().getLength(), oldLine);
+       }
+
+       protected void replaceText(int start, int end, String replacement) {
+               try {
+                       area.getDocument().remove(start, end - start);
+                       area.getDocument().insertString(start, replacement, 
inputStyle);
+               } catch (BadLocationException e) {
+                       e.printStackTrace();
+               }
+       }
+
+       protected String getLine() {
+               try {
+                       return area.getText(startPos, 
area.getDocument().getLength() - startPos);
+               } catch (BadLocationException e) {
+                       e.printStackTrace();
+               }
+
+               return null;
+       }
+
+       protected void enterAction(KeyEvent event) {
+               event.consume();
+
+               if (completePopup.isVisible()) {
+                       if (completeCombo.getSelectedItem() != null)
+                               replaceText(start, end, (String) 
completeCombo.getSelectedItem());
+
+                       completePopup.setVisible(false);
+
+                       return;
+               }
+
+               append("\n", null);
+
+               if (!finished) {
+                       String line = getLine();
+                       startPos = area.getDocument().getLength();
+                       pendingLines.offer(line);
+               }
+       }
+
+       /**
+        *  DOCUMENT ME!
+        *
+        * @param prompt DOCUMENT ME!
+        *
+        * @return  DOCUMENT ME!
+        */
+       public String readLine(final String prompt) {
+               if (EventQueue.isDispatchThread()) {
+                       throw runtime.newThreadError("Cannot call readline from 
event dispatch thread");
+               }
+
+               EventQueue.invokeLater(new Runnable() {
+                               public void run() {
+                                       append(prompt.trim(), promptStyle);
+                                       append(" ", inputStyle); // hack to get 
right style for input
+                                       
area.setCaretPosition(area.getDocument().getLength());
+                                       startPos = 
area.getDocument().getLength();
+                                       
Readline.getHistory(Readline.getHolder(runtime)).moveToEnd();
+                               }
+                       });
+
+               try {
+                       String line = pendingLines.take();
+
+                       if (line.length() > 0) {
+                               return line.trim();
+                       } else {
+                               if (finished) {
+                                       pendingLines.offer(EMPTY_LINE);
+                               }
+
+                               return null;
+                       }
+               } catch (InterruptedException e) {
+                       Thread.currentThread().interrupt();
+
+                       return null;
+               }
+       }
+
+       /**
+        *  DOCUMENT ME!
+        *
+        * @param event DOCUMENT ME!
+        */
+       public void keyPressed(KeyEvent event) {
+               int code = event.getKeyCode();
+
+               switch (code) {
+                       case KeyEvent.VK_TAB:
+                               completeAction(event);
+
+                               break;
+
+                       case KeyEvent.VK_LEFT:
+                       case KeyEvent.VK_BACK_SPACE:
+                               backAction(event);
+
+                               break;
+
+                       case KeyEvent.VK_UP:
+                               upAction(event);
+
+                               break;
+
+                       case KeyEvent.VK_DOWN:
+                               downAction(event);
+
+                               break;
+
+                       case KeyEvent.VK_ENTER:
+                               enterAction(event);
+
+                               break;
+
+                       case KeyEvent.VK_HOME:
+                               event.consume();
+                               area.setCaretPosition(startPos);
+
+                               break;
+               }
+
+               if (completePopup.isVisible() && (code != KeyEvent.VK_TAB) && 
(code != KeyEvent.VK_UP)
+                   && (code != KeyEvent.VK_DOWN))
+                       completePopup.setVisible(false);
+       }
+
+       /**
+        *  DOCUMENT ME!
+        *
+        * @param arg0 DOCUMENT ME!
+        */
+       public void keyReleased(KeyEvent arg0) {
+       }
+
+       /**
+        *  DOCUMENT ME!
+        *
+        * @param arg0 DOCUMENT ME!
+        */
+       public void keyTyped(KeyEvent arg0) {
+       }
+
+       /** Output methods **/
+       protected void append(String toAppend, AttributeSet style) {
+               try {
+                       
area.getDocument().insertString(area.getDocument().getLength(), toAppend, 
style);
+               } catch (BadLocationException e) {
+               }
+       }
+
+       private void writeLineUnsafe(final String line) {
+               if (line.startsWith("=>"))
+                       append(line, resultStyle);
+               else
+                       append(line, outputStyle);
+
+               startPos = area.getDocument().getLength();
+       }
+
+       private void writeLine(final String line) {
+               if (EventQueue.isDispatchThread()) {
+                       writeLineUnsafe(line);
+               } else {
+                       EventQueue.invokeLater(new Runnable() {
+                                       public void run() {
+                                               writeLineUnsafe(line);
+                                       }
+                               });
+               }
+       }
+
+       private class Input extends InputStream {
+               private byte[] bytes = null;
+               private int offset = 0;
+
+               @Override
+               public synchronized int available() {
+                       if (bytes != null) {
+                               return bytes.length - offset;
+                       } else {
+                               return 0;
+                       }
+               }
+
+               private boolean ensureBytes() throws IOException {
+                       if (bytes == null) {
+                               String line;
+
+                               try {
+                                       line = pendingLines.take();
+                               } catch (InterruptedException e) {
+                                       IOException ioEx = new 
IOException("Interrupted");
+                                       ioEx.initCause(e);
+                                       throw ioEx;
+                               }
+
+                               if (line.length() > 0) {
+                                       try {
+                                               bytes = line.getBytes("UTF-8");
+                                       } catch (UnsupportedEncodingException 
e) {
+                                               bytes = line.getBytes();
+                                       }
+                               } else if (finished) {
+                                       pendingLines.offer(EMPTY_LINE);
+                               }
+                       }
+
+                       return bytes != null;
+               }
+
+               @Override
+               public synchronized int read() throws IOException {
+                       if (EventQueue.isDispatchThread()) {
+                               throw new IOException("Cannot call read from 
event dispatch thread");
+                       }
+
+                       if (ensureBytes()) {
+                               assert bytes.length > 0;
+
+                               int b = bytes[offset];
+
+                               if (++offset == bytes.length) {
+                                       offset = 0;
+                                       bytes = null;
+                               }
+
+                               return b;
+                       } else {
+                               return -1;
+                       }
+               }
+
+               @Override
+               public synchronized int read(byte[] b, int off, int len) throws 
IOException {
+                       if (EventQueue.isDispatchThread()) {
+                               throw new IOException("Cannot call read from 
event dispatch thread");
+                       }
+
+                       if (b == null) {
+                               throw new NullPointerException();
+                       }
+
+                       if ((off < 0) || (len < 0) || ((off + len) > b.length)) 
{
+                               throw new IndexOutOfBoundsException();
+                       }
+
+                       if (len == 0) {
+                               return 0;
+                       }
+
+                       if (ensureBytes()) {
+                               final int remaining = bytes.length - offset;
+
+                               if (len > remaining) {
+                                       len = remaining;
+                               }
+
+                               System.arraycopy(bytes, offset, b, off, len);
+                               offset += len;
+
+                               if (len == remaining) {
+                                       offset = 0;
+                                       bytes = null;
+                               }
+
+                               return len;
+                       } else {
+                               return -1;
+                       }
+               }
+
+               @Override
+               public synchronized void close() {
+                       offset = 0;
+                       bytes = null;
+                       finished = true;
+                       pendingLines.clear();
+                       pendingLines.offer(EMPTY_LINE);
+               }
+       }
+
+       private class Output extends OutputStream {
+               @Override
+               public void write(int b) throws IOException {
+                       writeLine("" + b);
+               }
+
+               @Override
+               public void write(byte[] b, int off, int len) {
+                       try {
+                               writeLine(new String(b, off, len, "UTF-8"));
+                       } catch (UnsupportedEncodingException ex) {
+                               writeLine(new String(b, off, len));
+                       }
+               }
+
+               @Override
+               public void write(byte[] b) {
+                       try {
+                               writeLine(new String(b, "UTF-8"));
+                       } catch (UnsupportedEncodingException ex) {
+                               writeLine(new String(b));
+                       }
+               }
+       }
+}

Added: csplugins/trunk/ucsd/kono/JRubyEngine/testscripts/all_subnetworks.rb
===================================================================
--- csplugins/trunk/ucsd/kono/JRubyEngine/testscripts/all_subnetworks.rb        
                        (rev 0)
+++ csplugins/trunk/ucsd/kono/JRubyEngine/testscripts/all_subnetworks.rb        
2009-12-04 02:23:36 UTC (rev 18653)
@@ -0,0 +1,16 @@
+require 'java'
+
+include_class 'cytoscape.Cytoscape'
+include_class 'cytoscape.CyNetwork'
+include_class 'java.util.ArrayList'
+
+# Nodes in current network
+net = Cytoscape.getCurrentNetwork
+nodes =  Cytoscape.getCurrentNetwork.nodesList
+subnet = ArrayList.new
+
+nodes.each do |node|
+ 
+  subnet.add(node)
+  puts net.getConnectingEdges(subnet)
+end
\ No newline at end of file

Added: csplugins/trunk/ucsd/kono/JRubyEngine/testscripts/ba_model_generator.rb
===================================================================
--- csplugins/trunk/ucsd/kono/JRubyEngine/testscripts/ba_model_generator.rb     
                        (rev 0)
+++ csplugins/trunk/ucsd/kono/JRubyEngine/testscripts/ba_model_generator.rb     
2009-12-04 02:23:36 UTC (rev 18653)
@@ -0,0 +1,60 @@
+require 'java'
+
+include_class 'cytoscape.Cytoscape'
+include_class 'cytoscape.CyNode'
+include_class 'cytoscape.CyEdge'
+include_class 'cytoscape.CyNetwork'
+include_class 'cytoscape.layout.CyLayouts'
+include_class 'java.lang.Integer'
+
+ORIGINAL_NODES = 2
+MAX_LOOP = 1000 - ORIGINAL_NODES
+EACH_TRIAL = 2
+
+# Create network
+graph = Cytoscape.createNetwork("Barabasi-Albert Scale Free Network");
+
+nodes = Array.new
+
+#Create seed graph
+node1 = Cytoscape.getCyNode("Seed 1", true)
+node2 = Cytoscape.getCyNode("Seed 2", true)
+nodes << node1
+nodes << node2
+graph.addNode(node1)
+graph.addNode(node2)
+edge = Cytoscape.getCyEdge(node1, node2, "interaction", "-", true);
+graph.addEdge(edge);
+
+degree = 0.0
+prob = 0.0
+i = 0
+
+# Grow the seed graph
+while i<MAX_LOOP do
+       newNode = Cytoscape.getCyNode("Node " + Integer.toString(i), true)
+       graph.addNode(newNode)
+       
+       j = 0
+       while j<EACH_TRIAL do   
+               created = false
+               while created == false do
+                       selectedNode = nodes[rand(nodes.length)]
+                       degree = graph.getDegree(selectedNode)
+                       prob = (degree + 1.0) / (graph.getNodeCount() + 
graph.getEdgeCount() - 1.0)
+                       if prob >= rand && newNode.getIdentifier != 
selectedNode.getIdentifier
+                               created = true;
+                       end                     
+               end
+               
+               edge = Cytoscape.getCyEdge(newNode, selectedNode, 
"interaction", "-", true);
+               graph.addEdge(edge);
+               nodes << newNode
+               j = j+1         
+       end     
+       i = i+1
+end
+
+# Layout nodes
+CyLayouts.getLayout("force-directed").doLayout();
+Cytoscape.getCurrentNetworkView().redrawGraph(false, true);

Added: csplugins/trunk/ucsd/kono/JRubyEngine/testscripts/binary_matrix.rb
===================================================================
--- csplugins/trunk/ucsd/kono/JRubyEngine/testscripts/binary_matrix.rb          
                (rev 0)
+++ csplugins/trunk/ucsd/kono/JRubyEngine/testscripts/binary_matrix.rb  
2009-12-04 02:23:36 UTC (rev 18653)
@@ -0,0 +1,32 @@
+require 'java'
+
+include_class 'cytoscape.Cytoscape'
+include_class 'cytoscape.CyNetwork'
+include_class 'cytoscape.CyNode'
+
+net = Cytoscape.getCurrentNetwork
+source =  net.nodesList
+
+line = ','
+source.each do |column|
+  line << column.getIdentifier << ','
+end
+
+fileName = net.getTitle + "_matrix.csv"
+File.open(fileName, "w") {|file|
+
+  file.puts line
+  
+  source.each do |s|
+    line = s.getIdentifier + ','
+    targets = net.nodesList
+    targets.each do |t|
+      if net.edgeExists(s, t)
+        line << '1,'
+      else
+        line << '0,'
+      end
+    end
+    file.puts line
+  end
+}

Added: csplugins/trunk/ucsd/kono/JRubyEngine/testscripts/hello_world.rb
===================================================================
--- csplugins/trunk/ucsd/kono/JRubyEngine/testscripts/hello_world.rb            
                (rev 0)
+++ csplugins/trunk/ucsd/kono/JRubyEngine/testscripts/hello_world.rb    
2009-12-04 02:23:36 UTC (rev 18653)
@@ -0,0 +1,7 @@
+$LOAD_PATH << ENV['JRUBY_HOME'] + '/lib/ruby/gems/1.8/gems/bio-1.3.1/lib'
+puts "LOAD_PATH: " + $:.inspect
+
+
+require 'csv'
+require 'bio'
+puts 'Hello, Cytoscape.'
\ No newline at end of file

Added: csplugins/trunk/ucsd/kono/JRubyEngine/testscripts/kegg_relation_mapper.rb
===================================================================
--- csplugins/trunk/ucsd/kono/JRubyEngine/testscripts/kegg_relation_mapper.rb   
                        (rev 0)
+++ csplugins/trunk/ucsd/kono/JRubyEngine/testscripts/kegg_relation_mapper.rb   
2009-12-04 02:23:36 UTC (rev 18653)
@@ -0,0 +1,3 @@
+pathway_id = ARGV.sift
+
+puts 'Got ID: ' + pathway_id

Added: 
csplugins/trunk/ucsd/kono/JRubyEngine/testscripts/load_multiple_networks.rb
===================================================================
--- csplugins/trunk/ucsd/kono/JRubyEngine/testscripts/load_multiple_networks.rb 
                        (rev 0)
+++ csplugins/trunk/ucsd/kono/JRubyEngine/testscripts/load_multiple_networks.rb 
2009-12-04 02:23:36 UTC (rev 18653)
@@ -0,0 +1,19 @@
+require 'java'
+
+include_class 'cytoscape.Cytoscape'
+include_class 'cytoscape.layout.CyLayouts'
+include_class 'cytoscape.layout.LayoutAlgorithm'
+include_class 'cytoscape.CytoscapeInit'
+
+include_class 
'edu.ucsd.bioeng.coreplugin.tableImport.reader.NetworkTableMappingParameters'
+include_class 
'edu.ucsd.bioeng.coreplugin.tableImport.reader.NetworkTableReader'
+include_class 'java.net.URL'
+
+props = CytoscapeInit.getProperties
+props.setProperty("layout.default", "force-directed")
+
+Dir::glob("sampleData/*.table").each {|f|
+       puts "Loading: " + f
+   Cytoscape.createNetworkFromFile f
+               Cytoscape.getCurrentNetworkView.redrawGraph(false, true)
+}

Added: csplugins/trunk/ucsd/kono/JRubyEngine/testscripts/load_networks.rb
===================================================================
--- csplugins/trunk/ucsd/kono/JRubyEngine/testscripts/load_networks.rb          
                (rev 0)
+++ csplugins/trunk/ucsd/kono/JRubyEngine/testscripts/load_networks.rb  
2009-12-04 02:23:36 UTC (rev 18653)
@@ -0,0 +1,7 @@
+require 'java'
+
+include_class 
'edu.ucsd.bioeng.coreplugin.tableImport.reader.NetworkTableMappingParameters'
+include_class 
'edu.ucsd.bioeng.coreplugin.tableImport.reader.NetworkTableReader'
+include_class 'java.net.URL'
+
+

Added: csplugins/trunk/ucsd/kono/JRubyEngine/utilscripts/biorubyshell.rb
===================================================================
--- csplugins/trunk/ucsd/kono/JRubyEngine/utilscripts/biorubyshell.rb           
                (rev 0)
+++ csplugins/trunk/ucsd/kono/JRubyEngine/utilscripts/biorubyshell.rb   
2009-12-04 02:23:36 UTC (rev 18653)
@@ -0,0 +1,30 @@
+$LOAD_PATH << ENV['JRUBY_HOME'] + '/lib/ruby/1.8'
+$LOAD_PATH << ENV['JRUBY_HOME'] + '/lib/ruby/gems/1.8/gems/bio-1.3.1/lib'
+
+#puts "LOAD_PATH: " + $:.inspect
+
+require 'bio'
+require 'bio/shell'
+
+include Java
+include Bio::Shell
+
+include_class 'cytoscape.Cytoscape'
+
+Bio::Shell::Setup.new
+Bio::Shell.load_session
+
+
+if Bio::Shell.cache[:rails]
+  Bio::Shell.cache[:rails].join
+else
+  Signal.trap("SIGINT") do
+    Bio::Shell.cache[:irb].signal_handle
+  end
+
+  catch(:IRB_EXIT) do
+    Bio::Shell.cache[:irb].eval_input
+  end
+end
+
+Bio::Shell.save_session

--

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.


Reply via email to