Hi all,

As told by Egon, I have implemented a JmolEditor for editing Jmol
scripts in Bioclipse. It is still early in development but I think I
have a good start. A screenshot is available on
http://bioclipse.net/index.php?option=com_content&task=view&id=32&Itemid=5

I am by no means experienced in Jmol scripting so I would like to hear
from you how coloring ought to be set up.

I imagined to follow eclipse coloring and propose:

Registered commands:                    Purple
Strings (between ""):                   Blue
Parameters and any other text:          Black
Comments (starting with #):             Green

Maybe colors should be colored(!) so that "red" indeed is red etc. And
maybe we should color selectable objects (all, atoms, bonds etc) in a
distinct color. What do you think about that? We can also use font
styles like bold, italic etc.

Can you think of any more rules that I should think of? Like XX always
follows YY etc. I am thankful for all hints.

A second question:
After sending a JmolViewer.evalstring(myScript), how can get any
info/error messages? I would propose the method to return false or true,
and means to getLastErrorMessage(). As we have an embedded console I
would like to propagate any arror messages to it.

Cheers,

   .../Ola


On Thu, 2006-03-02 at 17:20, Egon Willighagen wrote:
> Hi all,
> 
> I could not withold this...
> 
> Bioclipse [1] has a Jmol plugin... it was one of the first... Bioclipse is a 
> chemo/bio-informatics workbench based on the RichClientPlatform used by 
> Eclipse.
> 
> Now, Ola has written a text editor for Jmol scripts... with syntax 
> highlighting *and* code completion...
> 
> Hope we get to see a screenshot soon!
> 
> If you want to give it a go: it should be fairly easy to set up for those who 
> already use Eclipse with the SVN plugin... Bioclipse uses the same 
> environment. Since there is quite some overlap between Jmol/CDK/Bioclipse, 
> developers who know about the Bioclipse SVN are often online at #cdk at 
> irc.freenode.net.
> 
> Egon
> 
> 1.http://www.bioclipse.net/
> 
> ----------  Forwarded Message  ----------
> 
> Subject: [Bioclipse-commit] SF.net SVN: bioclipse: [304] trunk/bc_jmol
> Date: Thursday 02 March 2006 16:18
> From: [EMAIL PROTECTED]
> To: [EMAIL PROTECTED]
> 
> Revision: 304
> Author:   ospjuth
> Date:     2006-03-02 07:17:55 -0800 (Thu, 02 Mar 2006)
> ViewCVS:  http://svn.sourceforge.net/bioclipse/?rev=304&view=rev
> 
> Log Message:
> -----------
> Added a script editor for Jmol with basic syntax highlighing and code
>  completion
> 
> Modified Paths:
> --------------
>     trunk/bc_jmol/META-INF/MANIFEST.MF
>     trunk/bc_jmol/plugin.xml
> 
> Added Paths:
> -----------
>     trunk/bc_jmol/src/net/bioclipse/editors/
>     trunk/bc_jmol/src/net/bioclipse/editors/jmol/
>     trunk/bc_jmol/src/net/bioclipse/editors/jmol/JmolCompletionProcessor.java
>     trunk/bc_jmol/src/net/bioclipse/editors/jmol/JmolEditor.java
>     trunk/bc_jmol/src/net/bioclipse/editors/jmol/JmolRuleScanner.java
>     trunk/bc_jmol/src/net/bioclipse/editors/jmol/JmolSourceViewerConfig.java
> Modified: trunk/bc_jmol/META-INF/MANIFEST.MF
> ===================================================================
> --- trunk/bc_jmol/META-INF/MANIFEST.MF        2006-03-02 14:59:40 UTC (rev 
> 303)
> +++ trunk/bc_jmol/META-INF/MANIFEST.MF        2006-03-02 15:17:55 UTC (rev 
> 304)
> @@ -10,7 +10,9 @@
>   net.bioclipse,
>   net.bioclipse.plugins.bc_cdk,
>   com.tools.logging,
> - org.eclipse.ui.views
> + org.eclipse.ui.views,
> + org.eclipse.jface.text,
> + org.eclipse.ui.workbench.texteditor
>  Eclipse-AutoStart: true
>  Bundle-ClassPath: bc_jmol.jar,
>   jars/,
> 
> Modified: trunk/bc_jmol/plugin.xml
> ===================================================================
> --- trunk/bc_jmol/plugin.xml  2006-03-02 14:59:40 UTC (rev 303)
> +++ trunk/bc_jmol/plugin.xml  2006-03-02 15:17:55 UTC (rev 304)
> @@ -30,7 +30,20 @@
>        </view>
>     </extension>
> 
> +<extension
> +      point="org.eclipse.ui.editors">
> +     <editor
> +               id="net.bioclipse.editors.jmol.JmolEditor"
> +               name="JmolEditor"
> +               icon="icons/sample.gif"
> +               extensions="spt,scr"
> +         
>  contributorClass="org.eclipse.ui.texteditor.BasicTextEditorActionContributor
> " +             class="net.bioclipse.editors.jmol.JmolEditor">
> +     </editor>
> +</extension>
> 
> +
> +
>     <extension
>           point="org.eclipse.ui.actionSets">
>        <actionSet
> 
> Added:
>  trunk/bc_jmol/src/net/bioclipse/editors/jmol/JmolCompletionProcessor.java
>  ===================================================================
> ---
>  trunk/bc_jmol/src/net/bioclipse/editors/jmol/JmolCompletionProcessor.java    
>   
>                       (rev 0) +++
>  trunk/bc_jmol/src/net/bioclipse/editors/jmol/JmolCompletionProcessor.java    
> 20
> 06-03-02 15:17:55 UTC (rev 304) @@ -0,0 +1,101 @@
> +package net.bioclipse.editors.jmol;
> +
> +import org.eclipse.jface.text.BadLocationException;
> +import org.eclipse.jface.text.ITextViewer;
> +import org.eclipse.jface.text.contentassist.CompletionProposal;
> +import org.eclipse.jface.text.contentassist.ICompletionProposal;
> +import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
> +import org.eclipse.jface.text.contentassist.IContextInformation;
> +import org.eclipse.jface.text.contentassist.IContextInformationValidator;
> +
> +public class JmolCompletionProcessor implements IContentAssistProcessor {
> +
> +     /* (non-Javadoc)
> +      * Method declared on IContentAssistProcessor
> +      */
> +     public ICompletionProposal[] computeCompletionProposals(
> +             ITextViewer viewer,
> +             int documentOffset) {
> +
> +             try {
> +
> +                     int myOffset;
> +                     if (documentOffset-10<0)
> +                             myOffset=0;
> +                     else
> +                             myOffset=documentOffset-10;
> +
> +                     String startStr = viewer.getDocument().get(myOffset,10);
> +//                   System.out.println("s: " + startStr);
> +
> +                     int myLastIndex;
> +                     if (startStr.lastIndexOf(" ") < 
> startStr.lastIndexOf("\n"))
> +                             myLastIndex=startStr.lastIndexOf("\n");
> +                     else
> +                             myLastIndex=startStr.lastIndexOf(" ");
> +
> +                     String searchStr=startStr.substring(myLastIndex+1);
> +
> +                     System.out.println("To validate against: " + searchStr);
> +
> +                     //Look up all that starts with this startStr
> +                     String[] lookedUp=JmolEditor.lookUpNames(searchStr);
> +
> +                     ICompletionProposal[] result =
> +                             new ICompletionProposal[lookedUp.length];
> +                     for (int i = 0; i < lookedUp.length; i++) {
> +                             result[i] = new CompletionProposal(lookedUp[i],
> +                                                             
> documentOffset-searchStr.length(), searchStr.length(),
>  lookedUp[i].length()); +                     }
> +
> +                     return result;
> +
> +
> +             } catch (BadLocationException e) {
> +                     // TODO Auto-generated catch block
> +                     e.printStackTrace();
> +             }
> +
> +             return null;
> +     }
> +
> +     /* (non-Javadoc)
> +      * Method declared on IContentAssistProcessor
> +      */
> +     public char[] getCompletionProposalAutoActivationCharacters() {
> +             return new char[] { '\n', ' ' };
> +//           return null;
> +     }
> +
> +     /* (non-Javadoc)
> +      * Method declared on IContentAssistProcessor
> +      */
> +     public char[] getContextInformationAutoActivationCharacters() {
> +             return null;
> +     }
> +
> +     // For Context information
> +     /* (non-Javadoc)
> +      * Method declared on IContentAssistProcessor
> +      */
> +     public IContextInformationValidator getContextInformationValidator() {
> +             return null;
> +     }
> +
> +     /* (non-Javadoc)
> +      * Method declared on IContentAssistProcessor
> +      */
> +     public IContextInformation[] computeContextInformation(
> +             ITextViewer viewer,
> +             int documentOffset) {
> +
> +             return null;
> +     }
> +
> +     /* (non-Javadoc)
> +      * Method declared on IContentAssistProcessor
> +      */
> +     public String getErrorMessage() {
> +             return null;
> +     }
> +}
> 
> Added: trunk/bc_jmol/src/net/bioclipse/editors/jmol/JmolEditor.java
> ===================================================================
> --- trunk/bc_jmol/src/net/bioclipse/editors/jmol/JmolEditor.java              
>     
>             (rev 0) +++
>  trunk/bc_jmol/src/net/bioclipse/editors/jmol/JmolEditor.java 2006-03-02
>  15:17:55 UTC (rev 304) @@ -0,0 +1,199 @@
> +package net.bioclipse.editors.jmol;
> +
> +import java.util.ArrayList;
> +import java.util.Collections;
> +import java.util.HashSet;
> +import java.util.Set;
> +
> +
> +
> +import net.bioclipse.editors.SimpleEditor;
> +
> +
> +/**
> + * Add jmol syntax completion and coloring
> + */
> +public class JmolEditor extends SimpleEditor {
> +
> +     protected final static String[] jmolProposals = {
> +             "select",
> +             "rotate",
> +             "all",
> +             "animation",
> +             "anim",
> +             "console",
> +             "measure",
> +             "monitor",
> +             "select",
> +             "ssbonds",
> +             "atom",
> +             "expressions",
> +             "define",
> +             "meshribbon",
> +             "set",
> +             "bond",
> +             "styles",
> +             "star",
> +             "backbone",
> +             "delay",
> +             "model",
> +             "set",
> +             "stereo",
> +             "background",
> +             "depth",
> +             "move",
> +             "set",
> +             "strands",
> +             "bondorder",
> +             "dots",
> +             "moveto",
> +             "set",
> +             "lighting",
> +             "perspective",
> +             "trace",
> +             "cartoon",
> +             "cartoons",
> +             "echo",
> +             "pmesh",
> +             "set",
> +             "translate",
> +             "center",
> +             "centre",
> +             "exit",
> +             "polyhedra",
> +             "set",
> +             "chainCaseSensitive",
> +             "vector",
> +             "vectors",
> +             "centerAt",
> +             "font",
> +             "quit",
> +             "debugScript",
> +             "vibration",
> +             "color",
> +             "colour",
> +             "frame",
> +             "refresh",
> +             "measurement",
> +             "wireframe",
> +             "hbonds",
> +             "reset",
> +             "picking",
> +             "zap",
> +             "hover",
> +             "restrict",
> +             "spin",
> +             "zoom",
> +             "isosurface",
> +             "ribbon",
> +             "ribbons",
> +             "show",
> +             "label",
> +             "labels",
> +             "rocket ",
> +             "rockets",
> +             "slab",
> +             "comment",
> +             "load",
> +             "rotate",
> +             "spacefill",
> +             "connect",
> +             "loop",
> +             "script ",
> +             "source",
> +             "spin"
> +     };
> +
> +
> +     protected static String[] subStrings;
> +
> +     protected static ArrayList startList;
> +     protected static ArrayList fullList;
> +
> +
> +     /**
> +      * Constructor
> +      *
> +      */
> +     public JmolEditor()
> +     {
> +             super();
> +             computeSubStrings();
> +             setSourceViewerConfiguration(new JmolSourceViewerConfig());
> +     }
> +
> +
> +     public static String[] getSubStrings() {
> +             return subStrings;
> +     }
> +     public static String[] getJmolProposals() {
> +             return jmolProposals;
> +     }
> +
> +     /**
> +      * Compute all substrings of the proposals
> +      */
> +     private void computeSubStrings() {
> +
> +             startList=new ArrayList();
> +             fullList=new ArrayList();
> +
> +             //All words
> +             for (int i=0;i<jmolProposals.length;i++){
> +
> +                     String name=jmolProposals[i];
> +
> +                     //This word
> +                     for (int j=1;j<name.length();j++){
> +                             String startAdd=name.substring(0,j);
> +                             String endAdd=name.substring(j,name.length());
> +                             startList.add(startAdd);
> +                             fullList.add(name);
> +
> +                     }
> +
> +             }
> +
> +             System.out.println("==============");
> +             subStrings=new String[startList.size()];
> +             for (int i=0; i< fullList.size();i++){
> +                     System.out.println(startList.get(i) + " - " + 
> fullList.get(i));
> +                     subStrings[i]=(String)startList.get(i);
> +             }
> +             System.out.println("==============");
> +
> +
> +     }
> +
> +     @SuppressWarnings("unchecked")
> +     public static String[] lookUpNames(String start){
> +
> +             //Temp list
> +             ArrayList lst=new ArrayList();
> +
> +             //Look through all in startlist and add matching names to ret
> +             for (int i=0; i< startList.size();i++){
> +                     String thisStart = (String)startList.get(i);
> +                     if (thisStart.startsWith(start)){
> +                             if (!(lst.contains(fullList.get(i))))
> +                                     lst.add(fullList.get(i));
> +                     }
> +             }
> +
> +             Collections.sort(lst);
> +
> +             //Convert list to array of strings
> +             String[] ret=new String[lst.size()];
> +             for (int i=0; i< lst.size();i++){
> +                     ret[i]=(String)lst.get(i);
> +             }
> +
> +             return ret;
> +     }
> +
> +
> +
> +
> +
> +}
> +
> 
> Added: trunk/bc_jmol/src/net/bioclipse/editors/jmol/JmolRuleScanner.java
> ===================================================================
> --- trunk/bc_jmol/src/net/bioclipse/editors/jmol/JmolRuleScanner.java        
>                  (rev 0) +++
>  trunk/bc_jmol/src/net/bioclipse/editors/jmol/JmolRuleScanner.java    
> 2006-03-02
>  15:17:55 UTC (rev 304) @@ -0,0 +1,33 @@
> +package net.bioclipse.editors.jmol;
> +
> +import org.eclipse.jface.text.TextAttribute;
> +import org.eclipse.jface.text.rules.EndOfLineRule;
> +import org.eclipse.jface.text.rules.IRule;
> +import org.eclipse.jface.text.rules.IToken;
> +import org.eclipse.jface.text.rules.MultiLineRule;
> +import org.eclipse.jface.text.rules.RuleBasedScanner;
> +import org.eclipse.jface.text.rules.SingleLineRule;
> +import org.eclipse.jface.text.rules.Token;
> +import org.eclipse.swt.graphics.Color;
> +import org.eclipse.swt.graphics.RGB;
> +import org.eclipse.swt.widgets.Display;
> +
> +public class JmolRuleScanner extends RuleBasedScanner {
> +     private static Color TAG_COLOR= new Color(Display.getCurrent(), new
>  RGB(200, 0, 0)); +   private static Color COMMENT_COLOR= new
>  Color(Display.getCurrent(), new RGB(0, 200, 0)); +
> +     public JmolRuleScanner() {
> +             IToken tagToken =
> +                     new Token(
> +                             new TextAttribute(TAG_COLOR));
> +
> +             IToken commentToken= new Token(new 
> TextAttribute(COMMENT_COLOR));
> +
> +             IRule[] rules = new IRule[2];
> +             //Add rule for processing instructions
> +
> +             rules[0] = new SingleLineRule("selec", "elect", tagToken);
> +             rules[1] = (new EndOfLineRule("#", commentToken)); //$NON-NLS-1$
> +             setRules(rules);
> +     }
> +}
> 
> Added:
>  trunk/bc_jmol/src/net/bioclipse/editors/jmol/JmolSourceViewerConfig.java
>  ===================================================================
> --- trunk/bc_jmol/src/net/bioclipse/editors/jmol/JmolSourceViewerConfig.java  
>                         (rev 0) +++
>  trunk/bc_jmol/src/net/bioclipse/editors/jmol/JmolSourceViewerConfig.java     
> 200
> 6-03-02 15:17:55 UTC (rev 304) @@ -0,0 +1,60 @@
> +package net.bioclipse.editors.jmol;
> +
> +import org.eclipse.jface.text.IDocument;
> +import org.eclipse.jface.text.TextAttribute;
> +import org.eclipse.jface.text.contentassist.ContentAssistant;
> +import org.eclipse.jface.text.contentassist.IContentAssistant;
> +import org.eclipse.jface.text.presentation.IPresentationReconciler;
> +import org.eclipse.jface.text.presentation.PresentationReconciler;
> +import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
> +import org.eclipse.jface.text.rules.Token;
> +import org.eclipse.jface.text.source.ISourceViewer;
> +import org.eclipse.jface.text.source.SourceViewerConfiguration;
> +import org.eclipse.swt.graphics.Color;
> +import org.eclipse.swt.graphics.RGB;
> +import org.eclipse.swt.widgets.Display;
> +
> +public class JmolSourceViewerConfig extends SourceViewerConfiguration {
> +     private JmolRuleScanner scanner;
> +     private static Color DEFAULT_TAG_COLOR =
> +             new Color(Display.getCurrent(), new RGB(0, 0, 200));
> +
> +     public JmolSourceViewerConfig() {
> +
> +     }
> +
> +     protected JmolRuleScanner getTagScanner() {
> +             if (scanner == null) {
> +                     scanner = new JmolRuleScanner();
> +                     scanner.setDefaultReturnToken(
> +                             new Token(new 
> TextAttribute(DEFAULT_TAG_COLOR)));
> +             }
> +             return scanner;
> +     }
> +
> +     /**
> +      * Define reconciler for MyEditor
> +      */
> +     public IPresentationReconciler getPresentationReconciler(ISourceViewer
>  sourceViewer) { +            PresentationReconciler reconciler = new
>  PresentationReconciler(); +          DefaultDamagerRepairer dr = new
>  DefaultDamagerRepairer(getTagScanner()); +           
> reconciler.setDamager(dr,
>  IDocument.DEFAULT_CONTENT_TYPE);
> +             reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
> +             return reconciler;
> +     }
> +
> +     public IContentAssistant getContentAssistant(ISourceViewer 
> sourceViewer) {
> +
> +             ContentAssistant assistant = new ContentAssistant();
> +             assistant.setContentAssistProcessor(
> +                     new JmolCompletionProcessor(),
> +                     IDocument.DEFAULT_CONTENT_TYPE);
> +
> +             assistant.enableAutoActivation(true);
> +             assistant.enableAutoInsert(true);
> +             assistant.setAutoActivationDelay(500);
> +             assistant.setProposalPopupOrientation(
> +                     IContentAssistant.PROPOSAL_OVERLAY);
> +             return assistant;
> +     }
> +}
> \ No newline at end of file
> 
> 
> 
> This was sent by the SourceForge.net collaborative development platform, the
>  world's largest Open Source development site.
> 
> 
> 
> 
> -------------------------------------------------------
> This SF.Net email is sponsored by xPML, a groundbreaking scripting language
> that extends applications into web and mobile media. Attend the live webcast
> and join the prime developer group breaking into this new coding territory!
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
> _______________________________________________
> Bioclipse-commit mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/bioclipse-commit
> 
> -------------------------------------------------------
-- 
Ola Spjuth
Dept of pharmaceutical biosciences
Uppsala University, Sweden




-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Jmol-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jmol-developers

Reply via email to