樹脂が固まる前に

Web Frontend / Android / Designが好きな人のメモ

Create original Tool for Processing 3.0.2

basically, how to create Processing 3.0.2 Tool is the same as 2.x

blog.livedoor.jp

Environment

github.com

Step

  1. Download the zip: processing-tool-template (v3.0.2) https://github.com/processing/processing-tool-template/releases (version is 3.0.2 ...maybe go well !!!)

  2. Eclipse: new Java Project ("testTools": my case) -> import archive file (zip)

  3. Copy core.jar & pde.jar -> Paste in : {your project name}>src>processing-tool-templates-3.0.2>lib

    • core.jar (Processing-3.0.2>core>library)
    • pde.jar (Processing-3.0.2>lib)

    f:id:pvcresin:20160317175202p:plain

  4. right click on core.jar & pde.jar -> Build Path>Add to Build Path (seemed to move)

    f:id:pvcresin:20160317180233p:plain

  5. Edit build.properties (src>processing-tool-templates-3.0.2>resources)
    path is my case

    • sketch book path (Default: ${user.home}\Documents\Processing)
      • sketchbook.location=${user.home}\Documents\Processing3
    • core.jar path
      • classpath.local.location=${user.home}\Downloads\PROGRAM\Processing\processing-3.0.2\core\library
    • libraies path (Default: ${sketchbook.location}/libraries)
      • classpath.libraries.location=${sketchbook.location}/libraries
    • java.target.version=1.8
    • (if you want) other property: Tool name, Author, Your URL ...
  6. Ant build (Eclipse)

    1. show Ant tab
      • Eclipse: Window>show View>other -> click Ant -> Ant tab appear (int the lower window)
    2. build.xml (src>resources) -> drag & drop in Ant tab -> close Processing (while building)
    3. push Run button in Ant tab -> watch console (build finished in about 5 sec)
    4. if (BUILD SUCCESSFUL) -> HelloTool is in Processing (PDE), else check build.properties and .jar file

Let's edit

HelloTool.java (src>processing-tool...>src>template>tool>HelloTool.java)
example : when you select the HelloTool, print all your code in PDE

package template.tool;

import processing.app.Base;
import processing.app.tools.Tool;
import processing.app.ui.Editor;

public class HelloTool implements Tool { // class name = project.name (build.properties)
  Base base;

  public void init(Base base) {
    this.base = base;              // Store a reference to the Processing application itself
  }

  public String getMenuTitle() {   // displayed with tools list
    return "##tool.name##";
  }
  
  public void run() {
    Editor editor = base.getActiveEditor();   // Get the currently active Editor to run the Tool on it

    System.out.println("Hello Tool. ##tool.name## ##tool.prettyVersion## by ##author##");    // <- build.property
    
    for (int i = 0; i < editor.getLineCount(); i++){
        String s = editor.getLineText(i);
        System.out.println(i + " : " + s);
    }
  }  
}

f:id:pvcresin:20160317191640p:plain