Author: kono
Date: 2009-12-04 15:10:29 -0800 (Fri, 04 Dec 2009)
New Revision: 18668

Added:
   csplugins/trunk/ucsd/kono/ScriptEngineManager/build.xml
   csplugins/trunk/ucsd/kono/ScriptEngineManager/images/
   csplugins/trunk/ucsd/kono/ScriptEngineManager/images/gnome-terminal.png
   csplugins/trunk/ucsd/kono/ScriptEngineManager/images/stock_run-macro.png
   csplugins/trunk/ucsd/kono/ScriptEngineManager/lib/
   csplugins/trunk/ucsd/kono/ScriptEngineManager/lib/bsf.jar
   csplugins/trunk/ucsd/kono/ScriptEngineManager/lib/commons-logging-1.1.jar
   csplugins/trunk/ucsd/kono/ScriptEngineManager/plugin.props
   csplugins/trunk/ucsd/kono/ScriptEngineManager/resources/
   csplugins/trunk/ucsd/kono/ScriptEngineManager/src/
   csplugins/trunk/ucsd/kono/ScriptEngineManager/src/edu/
   csplugins/trunk/ucsd/kono/ScriptEngineManager/src/edu/ucsd/
   csplugins/trunk/ucsd/kono/ScriptEngineManager/src/edu/ucsd/bioeng/
   csplugins/trunk/ucsd/kono/ScriptEngineManager/src/edu/ucsd/bioeng/idekerlab/
   
csplugins/trunk/ucsd/kono/ScriptEngineManager/src/edu/ucsd/bioeng/idekerlab/scriptenginemanager/
   
csplugins/trunk/ucsd/kono/ScriptEngineManager/src/edu/ucsd/bioeng/idekerlab/scriptenginemanager/ScriptEngineManager.java
   
csplugins/trunk/ucsd/kono/ScriptEngineManager/src/edu/ucsd/bioeng/idekerlab/scriptenginemanager/ScriptEngineManagerPlugin.java
   
csplugins/trunk/ucsd/kono/ScriptEngineManager/src/edu/ucsd/bioeng/idekerlab/scriptenginemanager/engine/
   
csplugins/trunk/ucsd/kono/ScriptEngineManager/src/edu/ucsd/bioeng/idekerlab/scriptenginemanager/engine/ScriptingEngine.java
   
csplugins/trunk/ucsd/kono/ScriptEngineManager/src/edu/ucsd/bioeng/idekerlab/scriptenginemanager/ui/
   
csplugins/trunk/ucsd/kono/ScriptEngineManager/src/edu/ucsd/bioeng/idekerlab/scriptenginemanager/ui/SelectScriptDialog.java
Log:
New Script Engine manager.

Added: csplugins/trunk/ucsd/kono/ScriptEngineManager/build.xml
===================================================================
--- csplugins/trunk/ucsd/kono/ScriptEngineManager/build.xml                     
        (rev 0)
+++ csplugins/trunk/ucsd/kono/ScriptEngineManager/build.xml     2009-12-04 
23:10:29 UTC (rev 18668)
@@ -0,0 +1,89 @@
+<?xml version="1.0"?>
+<!-- Script engine manager for Cytoscape by Kei Ono -->
+
+<project name="ScriptEngineManager" default="all" basedir=".">
+
+       <!-- The build directory -->
+       <!-- 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="ScriptEngineManager.jar" />
+
+       <!--  ============ Compilation Control Options ======================= 
-->
+       <property name="compile.debug" value="true" />
+       <property name="compile.deprecation" value="true" />
+       <property name="compile.optimize" value="true" />
+       <property name="cytoscape.dir" value="../cytoscape" />
+
+       <!-- ==================== Compilation Classpath ====================== 
-->
+       <path id="compile.classpath">
+               <fileset dir="${cytoscape.dir}">
+                       <include name="cytoscape.jar" />
+               </fileset>
+               <fileset dir="${basedir}/lib">
+                       <include name="*.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" 
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/images">
+                       <fileset dir="${basedir}/images" />
+               </copy>
+
+               <copy 
todir="${build.dir}/classes/edu/ucsd/bioeng/idekerlab/scriptenginemanager" 
file="${basedir}/plugin.props" />
+
+               <jar destfile="${project.jar}" basedir="${build.dir}/classes">
+
+                       <manifest>
+                               <attribute name="Cytoscape-Plugin" 
value="edu.ucsd.bioeng.idekerlab.scriptenginemanager.ScriptEngineManagerPlugin" 
/>
+                       </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/ScriptEngineManager/images/gnome-terminal.png
===================================================================
(Binary files differ)


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

Added: csplugins/trunk/ucsd/kono/ScriptEngineManager/images/stock_run-macro.png
===================================================================
(Binary files differ)


Property changes on: 
csplugins/trunk/ucsd/kono/ScriptEngineManager/images/stock_run-macro.png
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:mime-type
   + application/octet-stream

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


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

Added: csplugins/trunk/ucsd/kono/ScriptEngineManager/lib/commons-logging-1.1.jar
===================================================================
(Binary files differ)


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

Added: csplugins/trunk/ucsd/kono/ScriptEngineManager/plugin.props
===================================================================
--- csplugins/trunk/ucsd/kono/ScriptEngineManager/plugin.props                  
        (rev 0)
+++ csplugins/trunk/ucsd/kono/ScriptEngineManager/plugin.props  2009-12-04 
23:10:29 UTC (rev 18668)
@@ -0,0 +1,22 @@
+# -- The following properties are REQUIRED -- #
+
+# The plugin name that will be displayed to users
+pluginName=ScriptEngineManager
+
+# Description used to give users information about the plugin such as what it 
does.  
+# Html tags are encouraged for formatting purposes.
+pluginDescription=<p>Manages scripting engines following Cytoscape scripting 
engine guideline.  Supporting Ruby, JavaScript, Groovy and Python.  
</p><p><strong><font color="red">This plugin is for technology evaluation 
purpose ONLY!  Still experimental and design will be changed in the future 
versions.</font></strong>
+
+# Plugin version number, this must be two numbers separated by a decimlal.  
Ex. 0.2, 14.03
+pluginVersion=0.05
+
+# Compatible Cytoscape version
+cytoscapeVersion=2.6, 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

Added: 
csplugins/trunk/ucsd/kono/ScriptEngineManager/src/edu/ucsd/bioeng/idekerlab/scriptenginemanager/ScriptEngineManager.java
===================================================================
--- 
csplugins/trunk/ucsd/kono/ScriptEngineManager/src/edu/ucsd/bioeng/idekerlab/scriptenginemanager/ScriptEngineManager.java
                            (rev 0)
+++ 
csplugins/trunk/ucsd/kono/ScriptEngineManager/src/edu/ucsd/bioeng/idekerlab/scriptenginemanager/ScriptEngineManager.java
    2009-12-04 23:10:29 UTC (rev 18668)
@@ -0,0 +1,182 @@
+/*
+ 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.scriptenginemanager;
+
+import cytoscape.Cytoscape;
+
+import edu.ucsd.bioeng.idekerlab.scriptenginemanager.engine.ScriptingEngine;
+import edu.ucsd.bioeng.idekerlab.scriptenginemanager.ui.SelectScriptDialog;
+
+import org.apache.bsf.BSFException;
+import org.apache.bsf.BSFManager;
+import org.apache.bsf.util.IOUtils;
+
+import java.awt.event.ActionEvent;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+import java.io.FileReader;
+import java.io.IOException;
+
+import java.lang.reflect.Method;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.swing.AbstractAction;
+import javax.swing.ImageIcon;
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
+
+
+/**
+ *
+ */
+public class ScriptEngineManager implements PropertyChangeListener {
+       private static final BSFManager manager;
+       private static final Map<String, ScriptingEngine> registeredNames = new 
ConcurrentHashMap<String, ScriptingEngine>();
+       private static JMenu menu;
+       private static JMenu consoleMenu;
+
+       static {
+               manager = new BSFManager();
+       }
+
+       /**
+        * Creates a new ScriptEngineManager object.
+        */
+       public ScriptEngineManager() {
+               menu = new JMenu("Execute Scripts...");
+               menu.setIcon(new 
ImageIcon(ScriptEngineManager.class.getResource("/images/stock_run-macro.png")));
+               
Cytoscape.getDesktop().getCyMenus().getMenuBar().getMenu("Plugins").add(menu);
+
+               consoleMenu = new JMenu("Scripting Language Consoles");
+               consoleMenu.setIcon(new 
ImageIcon(ScriptEngineManager.class.getResource("/images/gnome-terminal.png")));
+               
Cytoscape.getDesktop().getCyMenus().getMenuBar().getMenu("Plugins").add(consoleMenu);
+       }
+
+       protected static BSFManager getManager() {
+               return manager;
+       }
+
+       /**
+        *  DOCUMENT ME!
+        *
+        * @param id DOCUMENT ME!
+        * @param engine DOCUMENT ME!
+        */
+       public static void registerEngine(final String id, final 
ScriptingEngine engine) {
+               registeredNames.put(id, engine);
+
+               menu.add(new JMenuItem(new 
AbstractAction(engine.getDisplayName()) {
+                               public void actionPerformed(ActionEvent e) {
+                                       SelectScriptDialog.showDialog(id);
+                               }
+                       }));
+       }
+
+       /**
+        *  DOCUMENT ME!
+        *
+        * @param consoleMenuItem DOCUMENT ME!
+        */
+       public static void addConsoleMenu(final JMenuItem consoleMenuItem) {
+               consoleMenu.add(consoleMenuItem);
+       }
+
+       /**
+        *  DOCUMENT ME!
+        *
+        * @param engineID DOCUMENT ME!
+        *
+        * @return  DOCUMENT ME!
+        */
+       public ScriptingEngine getEngine(String engineID) {
+               return registeredNames.get(engineID);
+       }
+
+       /**
+        *  DOCUMENT ME!
+        *
+        * @param engineName DOCUMENT ME!
+        * @param scriptFileName DOCUMENT ME!
+        * @param arguments DOCUMENT ME!
+        *
+        * @throws BSFException DOCUMENT ME!
+        * @throws IOException DOCUMENT ME!
+        */
+       public static void execute(final String engineName, final String 
scriptFileName,
+                                  final Map<String, String> arguments)
+           throws BSFException, IOException {
+               if (BSFManager.isLanguageRegistered(engineName) == false) {
+                       // Register Engine
+                       System.out.println("Error: Can't find " + engineName);
+
+                       return;
+               }
+
+               manager.terminate();
+
+               // This is a hack...  I need to decide which version of 
Scripting System is apropreate for Cytoscape 3.
+               if (engineName != "jython") {
+                       final Object returnVal = manager.eval(engineName, 
scriptFileName, 1, 1,
+                                                             
IOUtils.getStringFromReader(new FileReader(scriptFileName)));
+
+                       if (returnVal != null) {
+                               System.out.println("Return Val = [" + returnVal 
+ "]");
+                       }
+               } else {
+                       // Jython uses special console to execute script.
+                       try {
+                               final Class engineClass = 
Class.forName("edu.ucsd.bioeng.idekerlab.pythonengine.PythonEnginePlugin");
+                               Method method = 
engineClass.getMethod("executePythonScript",
+                                                                     new 
Class[] { String.class });
+                               Object ret = method.invoke(null, new Object[] { 
scriptFileName });
+                       } catch (Exception e) {
+                               e.printStackTrace();
+                       }
+               }
+       }
+
+       /**
+        *  DOCUMENT ME!
+        *
+        * @param arg0 DOCUMENT ME!
+        */
+       public void propertyChange(PropertyChangeEvent arg0) {
+               // TODO Auto-generated method stub
+       }
+}

Added: 
csplugins/trunk/ucsd/kono/ScriptEngineManager/src/edu/ucsd/bioeng/idekerlab/scriptenginemanager/ScriptEngineManagerPlugin.java
===================================================================
--- 
csplugins/trunk/ucsd/kono/ScriptEngineManager/src/edu/ucsd/bioeng/idekerlab/scriptenginemanager/ScriptEngineManagerPlugin.java
                              (rev 0)
+++ 
csplugins/trunk/ucsd/kono/ScriptEngineManager/src/edu/ucsd/bioeng/idekerlab/scriptenginemanager/ScriptEngineManagerPlugin.java
      2009-12-04 23:10:29 UTC (rev 18668)
@@ -0,0 +1,60 @@
+/*
+ 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.scriptenginemanager;
+
+import cytoscape.plugin.CytoscapePlugin;
+
+
+/**
+ *
+ */
+public class ScriptEngineManagerPlugin extends CytoscapePlugin {
+       private static final ScriptEngineManager manager = new 
ScriptEngineManager();
+
+       /**
+        * Creates a new ScriptEngineManagerPlugin object.
+        */
+       public ScriptEngineManagerPlugin() {
+       }
+
+       /**
+        *  DOCUMENT ME!
+        *
+        * @return  DOCUMENT ME!
+        */
+       public static ScriptEngineManager getManager() {
+               return manager;
+       }
+}

Added: 
csplugins/trunk/ucsd/kono/ScriptEngineManager/src/edu/ucsd/bioeng/idekerlab/scriptenginemanager/engine/ScriptingEngine.java
===================================================================
--- 
csplugins/trunk/ucsd/kono/ScriptEngineManager/src/edu/ucsd/bioeng/idekerlab/scriptenginemanager/engine/ScriptingEngine.java
                         (rev 0)
+++ 
csplugins/trunk/ucsd/kono/ScriptEngineManager/src/edu/ucsd/bioeng/idekerlab/scriptenginemanager/engine/ScriptingEngine.java
 2009-12-04 23:10:29 UTC (rev 18668)
@@ -0,0 +1,13 @@
+package edu.ucsd.bioeng.idekerlab.scriptenginemanager.engine;
+
+import javax.swing.Icon;
+
+public interface ScriptingEngine {
+       
+       public String getIdentifier();
+       
+       public String getDisplayName();
+       
+       public Icon getIcon();
+
+}

Added: 
csplugins/trunk/ucsd/kono/ScriptEngineManager/src/edu/ucsd/bioeng/idekerlab/scriptenginemanager/ui/SelectScriptDialog.java
===================================================================
--- 
csplugins/trunk/ucsd/kono/ScriptEngineManager/src/edu/ucsd/bioeng/idekerlab/scriptenginemanager/ui/SelectScriptDialog.java
                          (rev 0)
+++ 
csplugins/trunk/ucsd/kono/ScriptEngineManager/src/edu/ucsd/bioeng/idekerlab/scriptenginemanager/ui/SelectScriptDialog.java
  2009-12-04 23:10:29 UTC (rev 18668)
@@ -0,0 +1,290 @@
+/*
+ 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.scriptenginemanager.ui;
+
+import cytoscape.Cytoscape;
+
+import cytoscape.task.Task;
+import cytoscape.task.TaskMonitor;
+
+import cytoscape.task.ui.JTaskConfig;
+
+import cytoscape.task.util.TaskManager;
+
+import cytoscape.util.FileUtil;
+
+import edu.ucsd.bioeng.idekerlab.scriptenginemanager.ScriptEngineManager;
+import edu.ucsd.bioeng.idekerlab.scriptenginemanager.ScriptEngineManagerPlugin;
+import edu.ucsd.bioeng.idekerlab.scriptenginemanager.engine.ScriptingEngine;
+
+import java.awt.Color;
+
+import java.io.File;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.swing.JDialog;
+
+
+/**
+ *
+ */
+public class SelectScriptDialog extends JDialog {
+       private static SelectScriptDialog dialog = new SelectScriptDialog(null, 
true);
+       private static String currentEngineID;
+       private String scriptName = null;
+       private Map<String, String> arguments = new HashMap<String, String>();
+
+       // Variables declaration - do not modify
+       private javax.swing.JButton cancelButton;
+       private javax.swing.JButton runButton;
+       private javax.swing.JLabel titleLabel;
+       private javax.swing.JButton fileButton;
+       private javax.swing.JPanel filePanel;
+       private javax.swing.JTextField fileTextField;
+
+       // End of variables declaration
+       /**
+        *  DOCUMENT ME!
+        */
+       public static void showDialog(String engineID) {
+               final ScriptingEngine engine = 
ScriptEngineManagerPlugin.getManager().getEngine(engineID);
+
+               if (engine == null)
+                       return;
+
+               currentEngineID = engineID;
+               dialog.titleLabel.setIcon(engine.getIcon());
+               dialog.setLocationRelativeTo(Cytoscape.getDesktop());
+               dialog.pack();
+               dialog.setVisible(true);
+       }
+
+       /**
+        * Creates a new SelectScriptDialog object.
+        *
+        * @param parent  DOCUMENT ME!
+        * @param modal  DOCUMENT ME!
+        */
+       public SelectScriptDialog(java.awt.Frame parent, boolean modal) {
+               super(parent, modal);
+               initComponents();
+               pack();
+               repaint();
+       }
+
+       private void initComponents() {
+               // Background color for this plugin panel.
+               this.getContentPane().setBackground(Color.white);
+               titleLabel = new javax.swing.JLabel();
+               titleLabel.setBackground(Color.white);
+               filePanel = new javax.swing.JPanel();
+               filePanel.setBackground(Color.white);
+               fileTextField = new javax.swing.JTextField();
+               fileTextField.setBackground(Color.white);
+               fileButton = new javax.swing.JButton();
+               fileButton.setBackground(Color.white);
+               cancelButton = new javax.swing.JButton();
+               cancelButton.setBackground(Color.white);
+               runButton = new javax.swing.JButton();
+               runButton.setBackground(Color.white);
+
+               
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+               setTitle("Execute Script");
+               setResizable(false);
+
+               titleLabel.setFont(new java.awt.Font("SansSerif", 1, 16));
+               titleLabel.setText("Run Script from File");
+
+               
filePanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Script 
File",
+                                                                               
 javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
+                                                                               
 javax.swing.border.TitledBorder.DEFAULT_POSITION,
+                                                                               
 new java.awt.Font("SansSerif",
+                                                                               
                   0, 12)));
+
+               fileButton.setText("Select");
+               fileButton.addActionListener(new 
java.awt.event.ActionListener() {
+                               public void 
actionPerformed(java.awt.event.ActionEvent evt) {
+                                       fileButtonActionPerformed(evt);
+                               }
+                       });
+
+               org.jdesktop.layout.GroupLayout filePanelLayout = new 
org.jdesktop.layout.GroupLayout(filePanel);
+               filePanel.setLayout(filePanelLayout);
+               
filePanelLayout.setHorizontalGroup(filePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
+                                                                 
.add(org.jdesktop.layout.GroupLayout.TRAILING,
+                                                                      
filePanelLayout.createSequentialGroup()
+                                                                               
      .addContainerGap()
+                                                                               
      .add(fileTextField,
+                                                                               
           org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
+                                                                               
           438,
+                                                                               
           Short.MAX_VALUE)
+                                                                               
      .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
+                                                                               
      .add(fileButton)
+                                                                               
      .addContainerGap()));
+               
filePanelLayout.setVerticalGroup(filePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
+                                                               
.add(filePanelLayout.createSequentialGroup()
+                                                                               
    
.add(filePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
+                                                                               
                        .add(fileButton)
+                                                                               
                        .add(fileTextField,
+                                                                               
                             org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
+                                                                               
                             org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
+                                                                               
                             org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
+                                                                               
    .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
+                                                                               
                     Short.MAX_VALUE)));
+
+               cancelButton.setText("Cancel");
+               cancelButton.addActionListener(new 
java.awt.event.ActionListener() {
+                               public void 
actionPerformed(java.awt.event.ActionEvent evt) {
+                                       cancelButtonActionPerformed(evt);
+                               }
+                       });
+
+               runButton.setText("Execute");
+               runButton.addActionListener(new java.awt.event.ActionListener() 
{
+                               public void 
actionPerformed(java.awt.event.ActionEvent evt) {
+                                       runButtonActionPerformed(evt);
+                               }
+                       });
+
+               org.jdesktop.layout.GroupLayout layout = new 
org.jdesktop.layout.GroupLayout(getContentPane());
+               getContentPane().setLayout(layout);
+               
layout.setHorizontalGroup(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
+                                               
.add(layout.createSequentialGroup().addContainerGap()
+                                                          
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
+                                                                     
.add(filePanel,
+                                                                          
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
+                                                                          
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
+                                                                          
Short.MAX_VALUE).add(titleLabel)
+                                                                     
.add(org.jdesktop.layout.GroupLayout.TRAILING,
+                                                                          
layout.createSequentialGroup()
+                                                                               
 .add(runButton)
+                                                                               
 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
+                                                                               
 .add(cancelButton)))
+                                                          .addContainerGap()));
+               
layout.setVerticalGroup(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
+                                             
.add(layout.createSequentialGroup().addContainerGap()
+                                                        .add(titleLabel)
+                                                        
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
+                                                        .add(filePanel,
+                                                             
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
+                                                             
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
+                                                             
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
+                                                        
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED,
+                                                                         
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
+                                                                         
Short.MAX_VALUE)
+                                                        
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
+                                                                   
.add(cancelButton).add(runButton))
+                                                        .addContainerGap()));
+
+               pack();
+       } // </editor-fold>
+
+       private void cancelButtonActionPerformed(java.awt.event.ActionEvent 
evt) {
+               this.dispose();
+       }
+
+       private void runButtonActionPerformed(java.awt.event.ActionEvent evt) {
+               scriptName = fileTextField.getText();
+
+               setVisible(false);
+               runScript();
+               dispose();
+       }
+
+       private void fileButtonActionPerformed(java.awt.event.ActionEvent evt) {
+               final File file = FileUtil.getFile("Select Script File", 
FileUtil.LOAD);
+
+               if (file == null)
+                       return;
+
+               fileTextField.setText(file.getAbsolutePath());
+               fileTextField.setToolTipText("Target Script File: " + 
file.getAbsolutePath());
+               runButton.setEnabled(true);
+       }
+
+       private void runScript() {
+               // Create Task
+               Task task = new URLdownloadTask();
+
+               // Configure JTask Dialog Pop-Up Box
+               JTaskConfig jTaskConfig = new JTaskConfig();
+               jTaskConfig.setOwner(Cytoscape.getDesktop());
+               jTaskConfig.displayCloseButton(true);
+               jTaskConfig.displayStatus(true);
+               jTaskConfig.setAutoDispose(false);
+               jTaskConfig.displayCancelButton(false);
+
+               // Execute Task in New Thread; pop open JTask Dialog Box.
+               TaskManager.executeTask(task, jTaskConfig);
+       }
+
+       private class URLdownloadTask implements Task {
+               private TaskMonitor taskMonitor;
+
+               public URLdownloadTask() {
+               }
+
+               public void run() {
+                       taskMonitor.setStatus("Running Script: \n\n" + 
scriptName + "\n\n");
+                       taskMonitor.setPercentCompleted(-1);
+
+                       if (scriptName != null) {
+                               try {
+                                       
ScriptEngineManager.execute(currentEngineID, scriptName, arguments);
+                               } catch (Exception e1) {
+                                       // TODO Auto-generated catch block
+                                       e1.printStackTrace();
+                                       taskMonitor.setException(e1, "Could not 
finish script.");
+                               }
+                       }
+
+                       taskMonitor.setPercentCompleted(100);
+                       taskMonitor.setStatus("Finished!");
+               }
+
+               public void halt() {
+               }
+
+               public void setTaskMonitor(TaskMonitor monitor) throws 
IllegalThreadStateException {
+                       this.taskMonitor = monitor;
+               }
+
+               public String getTitle() {
+                       return "Running Script: " + scriptName;
+               }
+       }
+}

--

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