Post date: Jan 10, 2015 11:07:41 AM
ProcessingではToolというものがあって,カラーピッカーとか,ベジェ曲線作成ツールみたいな簡単な機能をIDEに拡張機能として入れることができる.
それをeclipseで作れるようにする記事があったのでやってみた.
Processing 用拡張ツールの作り方:http://blog.livedoor.jp/reona396/archives/55030723.html
ここではコンソールに文字を出力したり,ソースに直接介入する方法を記述している.
でもやっぱりツールといったらGUIだろ!ということでGUIで作る方法を一つ.
あと,やっぱりJavaでGUI書かなきゃならないならProcessingで書きたいよね,ということでProcessingで書いてみた.
package template.tool;
import javax.swing.JFrame;
import processing.app.*;
import processing.app.tools.*;
import processing.core.PApplet;
public class HelloTool implements Tool {
Editor editor;
Test test;
JFrame frame;
public String getMenuTitle() {
return "text Mirroring";
}
public void init(Editor editor) {
this.editor = editor;
frame = new JFrame("Text");
frame.setSize(640, 480);
test = new Test(this);
test.init();
frame.getContentPane().add(test);
frame.setResizable(false);
}
public void run() {
this.frame.setVisible(true);
}
}
class Test extends PApplet {
HelloTool tool;
Test(HelloTool tool) {
this.tool = tool;
}
public void setup() {
size(800, 600);
textSize(20);
}
public void draw() {
background(0);
fill(255);
try {
String str = tool.editor.getText();
String str1[] = str.split("\n");
for (int i = 0; i < str1.length; i++) {
text(str1[i], 0, 22 * (i + 1));
}
} catch (Exception e) {
}
}
}
ちなみに今回はテストとして,テキストをリアルタイムでミラーリングするツールにした.使い勝手が悪い.
実際の動画
下のコードをHelloToolのinitに書き込めばリサイズも可能になると思う(テストしてない)
frame.addComponentListener(new ComponentAdapter()
{
public void componentResized(ComponentEvent paramAnonymousComponentEvent)
{
test.resize(frame.getSize());
}
});