Author: scooter
Date: 2009-11-21 21:34:45 -0800 (Sat, 21 Nov 2009)
New Revision: 18538

Added:
   csplugins/trunk/ucsf/scooter/commandTool/
   csplugins/trunk/ucsf/scooter/commandTool/build.xml
   csplugins/trunk/ucsf/scooter/commandTool/resources/
   csplugins/trunk/ucsf/scooter/commandTool/resources/plugin.props
   csplugins/trunk/ucsf/scooter/commandTool/src/
   csplugins/trunk/ucsf/scooter/commandTool/src/commandTool/
   csplugins/trunk/ucsf/scooter/commandTool/src/commandTool/CommandTool.java
   csplugins/trunk/ucsf/scooter/commandTool/src/commandTool/ui/
   
csplugins/trunk/ucsf/scooter/commandTool/src/commandTool/ui/CommandToolDialog.java
Log:
Revised commandTool version


Added: csplugins/trunk/ucsf/scooter/commandTool/build.xml
===================================================================
--- csplugins/trunk/ucsf/scooter/commandTool/build.xml                          
(rev 0)
+++ csplugins/trunk/ucsf/scooter/commandTool/build.xml  2009-11-22 05:34:45 UTC 
(rev 18538)
@@ -0,0 +1,69 @@
+<?xml version = "1.0"?>
+<project name = "commandTool" default = "jar" basedir = ".">
+   
+   <property name = "src" location = "src"/>
+   <property name = "build" location = "build"/>
+   <property name = "build.compiler" value = "modern"/>
+   <!-- path to Cytoscape under development (CVS) -->
+   <property name = "lib" location = "../../../../cytoscape"/>
+   <property name = "jar"  location = "jar"/>
+   <property name = "doc" location = "doc"/>
+
+   <property name="cytoscape.plugin" value="${lib}/plugins"/>
+
+   <path id = "classpath">
+       <fileset dir = "${lib}">
+          <include name = "**/*.jar"/>
+       </fileset>
+   </path>
+
+   <target name="prepare" depends="clean">
+      <mkdir dir="${build}"/>
+   </target>
+
+   <target name="compile" depends = "prepare" description="Compile with 
Cytoscape under development">
+   <!-- Compile the java code from ${src} into ${build} -->
+   <javac source = "1.5" debug="true" deprecation="true" srcdir = "${src}" 
destdir="${build}">
+      <classpath refid = "classpath"/>
+   </javac>
+   </target>
+
+   <target name="clean" description="clean up" >
+      <!-- Delete the ${build} and ${src} directory trees -->
+      <delete dir="${build}"/>
+      <delete dir="${jar}"/>
+   </target>
+
+   <target name="jar" depends="compile" description="makes a jar for Cytoscape 
under development">
+   <mkdir dir = "${jar}"/>
+   <copy todir="build/commandTool" file="resources/plugin.props"/>
+   <jar jarfile="${jar}/commandTool.jar">
+      <manifest>
+          <attribute name="Cytoscape-Plugin" value="commandTool.CommandTool" />
+      </manifest>
+      <fileset dir="${build}"/>
+   </jar>
+   </target>
+
+   <target name = "run" depends="jar" description = "Run under development">
+      <java classname = "cytoscape.CyMain" classpathref = "classpath"
+          fork = "true" maxmemory = "1g">
+         <arg line = "--JLD"/>
+         <arg line = "${jar}/commandTool.jar"/>
+         <arg line = "-vt"/>
+         <arg line = "5000"/>
+      </java>
+    </target>
+
+
+   <!-- Target to Run JavaDoc -->
+    <target name="doc" description="Runs JavaDoc.">
+        <javadoc packagenames="metaNodePlugin2.*" sourcepath="src" 
source="1.5" destdir="doc"
+                        classpathref="classpath_release" >
+        <link href = "http://java.sun.com/j2se/1.4.2/docs/api/"/>
+        <link href = "http://csbi.sourceforge.net/API/"/>
+       <link href = "http://chianti.ucsd.edu/Cyto-2_4_1/javadoc/"; />
+       </javadoc>
+    </target>
+
+</project>

Added: csplugins/trunk/ucsf/scooter/commandTool/resources/plugin.props
===================================================================
--- csplugins/trunk/ucsf/scooter/commandTool/resources/plugin.props             
                (rev 0)
+++ csplugins/trunk/ucsf/scooter/commandTool/resources/plugin.props     
2009-11-22 05:34:45 UTC (rev 18538)
@@ -0,0 +1,34 @@
+#plugin.props 
+
+# This props file should be filled out and included in the plugin jar file.  
This props file will be used 
+# to put information into the Plugin Manager about the plugin 
+
+# -- The following properties are REQUIRED -- #
+
+# The plugin name that will be displayed to users
+pluginName=commandTool
+
+# Description used to give users information about the plugin such as what it 
does.  
+# Html tags are encouraged for formatting purposes.
+pluginDescription=This plugin provides an interface to the new Cytoscape 2.7 
command feature
+
+# Plugin version number, this must be two numbers separated by a decimlal.  
Ex. 0.2, 14.03
+pluginVersion=0.9
+
+# Compatible Cytoscape version
+cytoscapeVersion=2.7
+
+# Category, use one of the categories listed on the website or create your own
+pluginCategory=Other
+
+# -- The following properties are OPTIONAL -- #
+
+# URL to a website that gives more information about your plugin, Ex. 
http://my-lab-site.org
+projectURL=http://www.rbvi.ucsf.edu/Research/cytoscape/
+
+# 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=John "Scooter" Morris:UCSF
+
+# Date this plugin/plugin version was released
+releaseDate=November 1, 2009

Added: csplugins/trunk/ucsf/scooter/commandTool/src/commandTool/CommandTool.java
===================================================================
--- csplugins/trunk/ucsf/scooter/commandTool/src/commandTool/CommandTool.java   
                        (rev 0)
+++ csplugins/trunk/ucsf/scooter/commandTool/src/commandTool/CommandTool.java   
2009-11-22 05:34:45 UTC (rev 18538)
@@ -0,0 +1,75 @@
+/* vim: set ts=2: */
+/**
+ * Copyright (c) 2007 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions, and the following disclaimer.
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions, and the following
+ *      disclaimer in the documentation and/or other materials provided
+ *      with the distribution.
+ *   3. Redistributions must acknowledge that this software was
+ *      originally developed by the UCSF Computer Graphics Laboratory
+ *      under support by the NIH National Center for Research Resources,
+ *      grant P41-RR01081.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+package commandTool;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
+
+import cytoscape.Cytoscape;
+import cytoscape.plugin.CytoscapePlugin;
+import cytoscape.CytoscapeInit;
+import cytoscape.logger.CyLogger;
+
+import commandTool.ui.CommandToolDialog;
+
+public class CommandTool extends CytoscapePlugin implements ActionListener {
+       private CyLogger logger = null;
+
+       /**
+        * We don't do much at initialization time
+        */
+       public CommandTool() {
+               logger = CyLogger.getLogger(CommandTool.class);
+
+               // Add ourselves to the menu
+               JMenuItem menu = new JMenuItem("Command Tool...");
+               menu.addActionListener(this);
+
+               JMenu pluginMenu = 
Cytoscape.getDesktop().getCyMenus().getMenuBar()
+                                           .getMenu("Plugins");
+               pluginMenu.add(menu);
+
+       }
+
+       public void actionPerformed(ActionEvent e) {
+               // Popup our dialog
+               CommandToolDialog d = new 
CommandToolDialog(Cytoscape.getDesktop(), logger);
+               d.pack();
+               d.setLocationRelativeTo(Cytoscape.getDesktop());
+               d.setVisible(true);
+       }
+
+}

Added: 
csplugins/trunk/ucsf/scooter/commandTool/src/commandTool/ui/CommandToolDialog.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/commandTool/src/commandTool/ui/CommandToolDialog.java
                          (rev 0)
+++ 
csplugins/trunk/ucsf/scooter/commandTool/src/commandTool/ui/CommandToolDialog.java
  2009-11-22 05:34:45 UTC (rev 18538)
@@ -0,0 +1,363 @@
+/* vim: set ts=2: */
+/**
+ * Copyright (c) 2006 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions, and the following disclaimer.
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions, and the following
+ *      disclaimer in the documentation and/or other materials provided
+ *      with the distribution.
+ *   3. Redistributions must acknowledge that this software was
+ *      originally developed by the UCSF Computer Graphics Laboratory
+ *      under support by the NIH National Center for Research Resources,
+ *      grant P41-RR01081.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+package commandTool.ui;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import java.io.StreamTokenizer;
+import java.io.StringReader;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.ActionMap;
+import javax.swing.BorderFactory;
+import javax.swing.BoxLayout;
+import javax.swing.InputMap;
+import javax.swing.JDialog;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTextPane;
+import javax.swing.JTextField;
+import javax.swing.JButton;
+import javax.swing.KeyStroke;
+
+import javax.swing.border.Border;
+import javax.swing.border.EtchedBorder;
+
+import javax.swing.text.AttributeSet;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.DefaultStyledDocument;
+import javax.swing.text.SimpleAttributeSet;
+import javax.swing.text.StyleConstants;
+import javax.swing.text.StyledDocument;
+
+import cytoscape.command.CyCommandException;
+import cytoscape.command.CyCommandHandler;
+import cytoscape.command.CyCommandManager;
+import cytoscape.command.CyCommandResult;
+import cytoscape.logger.CyLogger;
+
+public class CommandToolDialog extends JDialog 
+                             implements ActionListener {
+
+       private CyLogger logger;
+       private List<String> commandList;
+       private int commandIndex = 0;
+
+       // Dialog components
+       private JResultsPane resultsText;
+       private JTextField inputField;
+
+       public CommandToolDialog (Frame parent, CyLogger logger) {
+               super(parent, false);
+               this.logger = logger;
+               commandList = new ArrayList();
+               initComponents();
+       }
+
+       public void setVisible(boolean tf) {
+               super.setVisible(tf);
+               inputField.requestFocusInWindow();
+       }
+
+       /**
+        * Initialize all of the graphical components of the dialog
+        */
+       private void initComponents() {
+               this.setTitle("Command Line Dialog");
+
+               setDefaultCloseOperation(DISPOSE_ON_CLOSE);
+
+               // Create a panel for the main content
+               JPanel dataPanel = new JPanel();
+               BoxLayout layout = new BoxLayout(dataPanel, 
BoxLayout.PAGE_AXIS);
+               dataPanel.setLayout(layout);
+
+               Border etchedBorder = 
BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
+
+               resultsText = new JResultsPane();
+               resultsText.setEditable(false);
+               resultsText.setPreferredSize(new Dimension(900, 200));
+               JScrollPane scrollPane = new JScrollPane(resultsText);
+
+               
scrollPane.setBorder(BorderFactory.createTitledBorder(etchedBorder, "Reply 
Log"));
+               dataPanel.add(scrollPane);
+
+               inputField = new JTextField(80);
+               
inputField.setBorder(BorderFactory.createTitledBorder(etchedBorder, "Command"));
+               // Set up our up-arrow/down-arrow actions
+               Action previousAction = new LineAction("previous");
+               inputField.getInputMap().put(KeyStroke.getKeyStroke("UP"), 
"previous");
+               inputField.getActionMap().put("previous", previousAction);
+
+               Action nextAction = new LineAction("next");
+               inputField.getInputMap().put(KeyStroke.getKeyStroke("DOWN"), 
"next");
+               inputField.getActionMap().put("next", nextAction);
+
+               inputField.addActionListener(this);
+               dataPanel.add(inputField);
+               inputField.setMaximumSize(new Dimension(1000,45));
+
+               // Create the button box
+               JPanel buttonBox = new JPanel();
+               JButton doneButton = new JButton("Done");
+               doneButton.setActionCommand("done");
+               doneButton.addActionListener(this);
+
+               JButton clearButton = new JButton("Clear");
+               clearButton.setActionCommand("clear");
+               clearButton.addActionListener(this);
+
+               buttonBox.add(clearButton);
+               buttonBox.add(doneButton);
+               
buttonBox.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
+               buttonBox.setMaximumSize(new Dimension(1000,45));
+               
+               dataPanel.add(buttonBox);
+               setContentPane(dataPanel);
+               setMaximumSize(new Dimension(1000,1000));
+       }
+
+       public void actionPerformed(ActionEvent e) {
+               if ("done".equals(e.getActionCommand())) {
+                       this.dispose();
+               } else if ("clear".equals(e.getActionCommand())) {
+                       resultsText.setStyledDocument(new 
DefaultStyledDocument());
+               } else {
+                       String input = inputField.getText();
+                       resultsText.appendCommand(input);
+                       commandList.add(input);
+                       commandIndex = commandList.size();
+
+                       handleCommand(input);
+
+                       inputField.setText("");
+               }
+       }
+
+       private void handleCommand(String input) {
+               CyCommandResult results = null;
+               try {
+                       String ns = null;
+                       if ((ns = isNamespace(input)) != null) {
+                               results = handleCommand(input, ns);
+                       } else {
+                               throw new RuntimeException("Unknown command: 
"+input);
+                       }
+                       // Get all of the messages from our results
+                       for (String s: results.getMessages()) {
+                               resultsText.appendMessage("  "+s+"\n");
+                       }
+               } catch (CyCommandException e) {
+                       resultsText.appendError("  "+e.getMessage()+"\n");
+               } catch (RuntimeException e) {
+                       resultsText.appendError("  "+e.getMessage()+"\n");
+               }
+               resultsText.appendMessage("\n");
+       }
+
+       private String isNamespace(String input) {
+               String namespace = null;
+               for (String ns: CyCommandManager.getNamespaceList()) {
+                       if (input.toLowerCase().startsWith(ns.toLowerCase()) && 
(namespace == null || ns.length() > namespace.length()))
+                               namespace = ns;
+               }
+               return namespace;
+       }
+
+       private CyCommandResult handleCommand(String inputLine, String ns) 
throws CyCommandException {
+               String sub = null;
+               // Parse the input, breaking up the tokens into appropriate
+               // commands, subcommands, and maps
+               Map<String,Object> settings = new HashMap();
+               String comm = 
parseInput(inputLine.substring(ns.length()).trim(), settings);
+               
+               for (String command: CyCommandManager.getCommandList(ns)) {
+                       if (command.toLowerCase().equals(comm.toLowerCase())) {
+                               sub = command;
+                               break;
+                       }
+               }
+
+               if (sub == null && (comm != null && comm.length() > 0))
+                       throw new CyCommandException("Unknown argument: "+comm);
+               
+               return CyCommandManager.execute(ns, sub, settings);
+       }
+
+       private String parseInput(String input, Map<String,Object> settings) {
+
+               // Tokenize
+               StringReader reader = new StringReader(input);
+               StreamTokenizer st = new StreamTokenizer(reader);
+
+               // We don't really want to parse numbers as numbers...
+               st.ordinaryChar('/');
+               st.ordinaryChar('-');
+               st.ordinaryChar('.');
+               st.ordinaryChars('0', '9');
+
+               st.wordChars('/', '/');
+               st.wordChars('-', '-');
+               st.wordChars('.', '.');
+               st.wordChars('0', '9');
+
+               List<String> tokenList = new ArrayList();
+               int tokenIndex = 0;
+               int i;
+               try {
+                       while ((i = st.nextToken()) != StreamTokenizer.TT_EOF) {
+                               switch(i) {
+                                       case '=':
+                                               // Get the next token
+                                               i = st.nextToken();
+                                               if (i == 
StreamTokenizer.TT_WORD || i == '"') {
+                                                       tokenIndex--;
+                                                       String key = 
tokenList.get(tokenIndex);
+                                                       settings.put(key, 
st.sval);
+                                                       
tokenList.remove(tokenIndex);
+                                               }
+                                               break;
+                                       case '"':
+                                       case StreamTokenizer.TT_WORD:
+                                               tokenList.add(st.sval);
+                                               tokenIndex++;
+                                               break;
+                                       default:
+                                               break;
+                               }
+                       } 
+               } catch (Exception e) { return ""; }
+
+               // Concatenate the commands together
+               String command = "";
+               for (String word: tokenList) command += word+" ";
+
+               // Now, the last token of the args goes with the first setting
+               return command.trim();
+       }
+
+       class JResultsPane extends JTextPane {
+               private SimpleAttributeSet commandAttributes;
+               private SimpleAttributeSet messageAttributes;
+               private SimpleAttributeSet errorAttributes;
+               public JResultsPane() {
+                       super();
+
+                       commandAttributes = new SimpleAttributeSet();
+                       
commandAttributes.addAttribute(StyleConstants.CharacterConstants.Foreground, 
Color.BLUE);
+                       
commandAttributes.addAttribute(StyleConstants.CharacterConstants.Italic, 
Boolean.TRUE);
+                       
commandAttributes.addAttribute(StyleConstants.CharacterConstants.Bold, 
Boolean.TRUE);
+
+                       messageAttributes = new SimpleAttributeSet();
+                       
messageAttributes.addAttribute(StyleConstants.CharacterConstants.Foreground, 
Color.BLUE);
+                       
messageAttributes.addAttribute(StyleConstants.CharacterConstants.Italic, 
Boolean.FALSE);
+                       
messageAttributes.addAttribute(StyleConstants.CharacterConstants.Bold, 
Boolean.FALSE);
+
+                       errorAttributes = new SimpleAttributeSet();
+                       
errorAttributes.addAttribute(StyleConstants.CharacterConstants.Foreground, 
Color.RED);
+                       
errorAttributes.addAttribute(StyleConstants.CharacterConstants.Italic, 
Boolean.FALSE);
+                       
errorAttributes.addAttribute(StyleConstants.CharacterConstants.Bold, 
Boolean.FALSE);
+               }
+
+               public void appendCommand(String s) {
+                       updateString(commandAttributes, s+"\n");
+               }
+
+               public void appendError(String s) {
+                       updateString(errorAttributes, s);
+               }
+
+               public void appendResult(String s) {
+               }
+
+               public void appendMessage(String s) {
+                       updateString(messageAttributes, s);
+               }
+
+               private void updateString(AttributeSet set, String s) {
+                       StyledDocument doc = getStyledDocument();
+                       try {
+                               doc.insertString(doc.getLength(), s, set);
+                       } catch (BadLocationException badLocationException) {
+                       }
+               }
+       }
+
+       class LineAction extends AbstractAction {
+               String action = null;
+               public LineAction(String action) {
+                       super();
+                       this.action = action;
+               }
+                       
+               public void actionPerformed(ActionEvent e) {
+                       if (commandList.size() == 0) return;
+
+                       // System.out.println("in: size = 
"+commandList.size()+", index = "+commandIndex);
+
+                       if (action.equals("next")) {
+                               commandIndex++;
+                       } else if (action.equals("previous")) {
+                               commandIndex--;
+                       } else
+                               return;
+
+
+                       String inputCommand;
+                       if (commandIndex >= commandList.size()) {
+                               inputCommand = "";
+                               commandIndex = commandList.size();
+                       } else if (commandIndex < 0) {
+                               inputCommand = "";
+                               commandIndex = -1;
+                       } else {
+                               inputCommand = commandList.get(commandIndex);
+                       }
+
+                       // System.out.println("out: size = 
"+commandList.size()+", index = "+commandIndex);
+                       inputField.setText(inputCommand);
+                       inputField.selectAll();
+               }
+       }
+}

--

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=.


Reply via email to