diff --git a/src/main/java/cit/PureATN/App.java b/src/main/java/cit/PureATN/App.java index 84caa12..2ad0122 100644 --- a/src/main/java/cit/PureATN/App.java +++ b/src/main/java/cit/PureATN/App.java @@ -1,9 +1,13 @@ package cit.PureATN; +import cit.PureATN.MultiNote.MultiNote; + public class App { public static void main( String[] args ) { - new Note(); + // TODO: ここで、シンプルなNoteをつかうか、MultiNoteを立ち上げるかを、切り替える + // new Note(); + new MultiNote(); } } diff --git a/src/main/java/cit/PureATN/DPenReceiver.java b/src/main/java/cit/PureATN/DPenReceiver.java index 68fed4e..e0cd6f6 100644 --- a/src/main/java/cit/PureATN/DPenReceiver.java +++ b/src/main/java/cit/PureATN/DPenReceiver.java @@ -49,20 +49,20 @@ data = datagramPacket.getData(); int length = datagramPacket.getLength(); String message = new String(data,0,length); - System.out.println(message); + // System.out.println(message); receive(message); // この下に定義があります } } public void receive(String mes){ - String dtime = sdf.format(new Date()); - System.out.println(dtime+" "+mes); + // String dtime = sdf.format(new Date()); + // System.out.println(dtime+" "+mes); String[] ints = mes.split(" "); if (ints[0].equals("press")){ String pen = ints[2]; String penid = convertPenSerial2PenID.get(pen); if (penid != null) pen = penid; - PenUser.press(pen, Integer.parseInt(ints[1])); // 1 press, 0 up + PenUser.press(penid, Integer.parseInt(ints[1])); // 1 press, 0 up } else { int x1 = Integer.parseInt(ints[2]); int y1 = Integer.parseInt(ints[3]); @@ -73,7 +73,7 @@ String penid = convertPenSerial2PenID.get(pen); if (penid != null) pen = penid; // send(x1,y1,x2,y2,pen,1); - PenUser.add(pen, x1, y1); + PenUser.add(penid, x1, y1); } } Hashtable convertPenSerial2PenID; diff --git a/src/main/java/cit/PureATN/KeyEvent_on_Note.java b/src/main/java/cit/PureATN/KeyEvent_on_Note.java index 643fad0..5863493 100644 --- a/src/main/java/cit/PureATN/KeyEvent_on_Note.java +++ b/src/main/java/cit/PureATN/KeyEvent_on_Note.java @@ -24,7 +24,7 @@ } public void keyPressed(KeyEvent e) { - System.out.println("keyCode=" + e.getKeyCode() + " keyChar [" + e.getKeyChar() + "]"); + // System.out.println("keyCode=" + e.getKeyCode() + " keyChar [" + e.getKeyChar() + "]"); if (e.getKeyCode() == 27) {// ESC PTransformActivity ta = canvas.getCamera().animateViewToCenterBounds(canvas.getLayer().getFullBounds(), true, 1000); diff --git a/src/main/java/cit/PureATN/MultiNote/KeyEvent_on_MultiNote.java b/src/main/java/cit/PureATN/MultiNote/KeyEvent_on_MultiNote.java new file mode 100644 index 0000000..6fe14b2 --- /dev/null +++ b/src/main/java/cit/PureATN/MultiNote/KeyEvent_on_MultiNote.java @@ -0,0 +1,92 @@ +package cit.PureATN.MultiNote; + +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; + +import org.piccolo2d.PCanvas; + +public class KeyEvent_on_MultiNote implements KeyListener { + + PCanvas canvas; + + public KeyEvent_on_MultiNote(PCanvas _canvas) { + canvas = _canvas; + canvas.requestFocus(); + } + + public void keyTyped(KeyEvent e) { + } + + public void keyReleased(KeyEvent e) { + } + + public void keyPressed(KeyEvent e) { + // System.out.println("keyCode=" + e.getKeyCode() + " keyChar [" + e.getKeyChar() + "]"); + if (e.getKeyCode() == KeyEvent.VK_ENTER || e.getKeyCode() == KeyEvent.VK_F || e.getKeyCode() == KeyEvent.VK_R + || e.getKeyCode() == KeyEvent.VK_M) { + // if (zrh.selection != null){ + // if (zrh.pressN != null && zrh.pressN instanceof Sheet){ + // Sheet s = (Sheet)zrh.pressN; + // s.collect(zrh.selection, e.getKeyCode()); + // } + // if (zrh.pressN != null && zrh.pressN instanceof SSGroup){ //SSGRoup + // だったら,シートに変換 + // SSGroup ssg = (SSGroup)zrh.pressN; + // ssg.sheet.collect(zrh.selection, e.getKeyCode()); + // } + // } + // zrh.dismissRegionLater(); + } + if (e.getKeyCode() == KeyEvent.VK_Z) { + // System.out.println("SimpleATN zoomLevel = "+getZoomLevel()); + } + if (KeyEvent.VK_0 <= e.getKeyCode() && e.getKeyCode() <= KeyEvent.VK_5 ) { + System.out.println("VK_"+(e.getKeyCode()- KeyEvent.VK_0)); + } + if (e.getKeyCode() == KeyEvent.VK_F11) { + // menutoolbar.getButton("Full Screen").doClick(); + } + + // 範囲選択中なら... + // if (zrh.isDragging() && zrh.selection != null){ + // if (KeyEvent.VK_1 <= e.getKeyCode() && e.getKeyCode() <= KeyEvent.VK_5){ + // //領域フィルタに追加 + // if (zrh.pressN != null && zrh.pressN instanceof Sheet){ + // Sheet s = (Sheet)zrh.pressN; + // ConfigWindow.configWin.filter.addRegionFilter(s, zrh.selection, + // e.getKeyCode()); + // } + // if (zrh.pressN != null && zrh.pressN instanceof SSGroup){ //SSGRoup + // だったら,シートに変換 + // SSGroup ssg = (SSGroup)zrh.pressN; + // // ssg.sheet.collect(zrh.selection, e.getKeyCode()); + // ConfigWindow.configWin.filter.addRegionFilter(ssg.sheet, zrh.selection, + // e.getKeyCode()); + // } + // zrh.dismissRegionLater(); + // } + // } else { + // if (KeyEvent.VK_1 <= e.getKeyCode() && e.getKeyCode() <= KeyEvent.VK_6){ + // } + // } + // PBounds pb = getCanvas().getCamera().getViewBounds(); + // int keyCode = e.getKeyCode(); + // if (keyCode == 38) {// 上 + // pb.moveBy(0, -pb.getHeight()); + // zoomToBounds(pb,1000,"KeyPan"); + // } + // if (keyCode == 37) {// 左 + // pb.moveBy(-pb.getWidth(),0); + // zoomToBounds(pb,1000,"KeyPan"); + // } + // if (keyCode == 39) {// 右 + // pb.moveBy(pb.getWidth(),0); + // zoomToBounds(pb,1000,"KeyPan"); + // } + // if (keyCode == 40) {// 下 + // pb.moveBy(0,pb.getHeight()); + // zoomToBounds(pb,1000,"KeyPan"); + // } + // } + } +} diff --git a/src/main/java/cit/PureATN/MultiNote/MouseEvent_onMN.java b/src/main/java/cit/PureATN/MultiNote/MouseEvent_onMN.java new file mode 100644 index 0000000..9fc1075 --- /dev/null +++ b/src/main/java/cit/PureATN/MultiNote/MouseEvent_onMN.java @@ -0,0 +1,50 @@ +package cit.PureATN.MultiNote; + +import java.awt.event.MouseEvent; +import java.awt.geom.Point2D; + +import org.piccolo2d.PCamera; +import org.piccolo2d.PNode; +import org.piccolo2d.event.PBasicInputEventHandler; +import org.piccolo2d.event.PInputEvent; +import org.piccolo2d.nodes.PText; + +import cit.PureATN.Note; + + +public class MouseEvent_onMN extends PBasicInputEventHandler { + Note frame; + + PInputEvent pressEv = null; + PNode pressPN; + Point2D pressP = null; + int dragCount = 0; + + public MouseEvent_onMN(Note _ff) { + frame = _ff; + } + + public void mousePressed(final PInputEvent aEvent) { + pressEv = aEvent; + pressPN = aEvent.getPickedNode(); + dragCount = 0; + } + public void mouseDragged(final PInputEvent aEvent) { + dragCount++; + } + public void mouseReleased(final PInputEvent aEvent) { + if (pressEv == null) return; + if (pressPN.getAttribute("nozoom") != null) return;//nozoomタグがついていたら,ズームインしない(色付けボタン:FRPaletteのPPathなので) + if (dragCount < 3){ + if (pressEv.getButton()==MouseEvent.BUTTON3){ + //ポップアップメニュー + if (pressPN instanceof PCamera || pressPN instanceof PText) //Sheetのときは表示しない. + new PopupMenu_forMN(frame, pressEv, frame.getCanvas()); + } else if (pressEv.getButton()==MouseEvent.BUTTON1){ +// if (SimpleATN.theapp.zrh.selection == null){ +// frame.focus(); +// } + } + } + } +} \ No newline at end of file diff --git a/src/main/java/cit/PureATN/MultiNote/MultiNote.java b/src/main/java/cit/PureATN/MultiNote/MultiNote.java new file mode 100644 index 0000000..29b644b --- /dev/null +++ b/src/main/java/cit/PureATN/MultiNote/MultiNote.java @@ -0,0 +1,68 @@ +package cit.PureATN.MultiNote; + +import java.awt.Color; +import java.util.ArrayList; +import java.util.Enumeration; + +import javax.swing.WindowConstants; + +import org.piccolo2d.PCanvas; + +import cit.PureATN.Note; +import cit.PureATN.PenUser; +import cit.PureATN.ShortStroke; + +public class MultiNote extends Note { + + public MultiNote() { + this(null); + setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + theapp = this; // どこからでもNote.theapp で参照できるように + } + + public MultiNote(final PCanvas aCanvas) { + super(aCanvas); + setTitle("MultiNote (Esc key to zoom whole strokes)"); + int width = 1000; + int height = (int) (width * 1.414); + setSize(width, height); + setLocation(100, 200); + + // dPenReceiver = new DPenReceiver(this); + } + + public void initialize() { + super.initialize(); + + // 追加機能:キーイベント + getCanvas().addKeyListener(new KeyEvent_on_MultiNote(getCanvas())); + + // 追加機能:右クリックでメニューをだす + getCanvas().getCamera().addInputEventListener(new MouseEvent_onMN(this)); + + } + + public static void main(final String[] args) { + new MultiNote(); + } + + // 色付け + public void iroduke() { + Enumeration ite = PenUser.penusers.keys(); + while (ite.hasMoreElements()) { + String penidStr =ite.nextElement(); + String penid0x = penidStr.substring(3); + int penid = Integer.parseInt(penid0x); + // System.out.println(penid+" "+penid*penid); //pen06 + + Color c = Color.getHSBColor((float)(penid/10.0f), 0.8f, 0.8f); + ArrayList sss = PenUser.find(penidStr).strokes; + for(ShortStroke s: sss){ + s.setStrokePaint(c); + System.out.println(s.time); + } + } + repaint(); + } + +} diff --git a/src/main/java/cit/PureATN/MultiNote/PopupMenu_forMN.java b/src/main/java/cit/PureATN/MultiNote/PopupMenu_forMN.java new file mode 100644 index 0000000..245282e --- /dev/null +++ b/src/main/java/cit/PureATN/MultiNote/PopupMenu_forMN.java @@ -0,0 +1,72 @@ +package cit.PureATN.MultiNote; + +import java.awt.event.KeyEvent; +import java.awt.geom.Point2D; + +import javax.swing.JMenuItem; +import javax.swing.JPopupMenu; +import javax.swing.KeyStroke; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import org.piccolo2d.PCanvas; +import org.piccolo2d.event.PInputEvent; + +import cit.PureATN.Note; + +public class PopupMenu_forMN extends JPopupMenu { + private static final long serialVersionUID = 7741402910818721975L; + + MultiNote fframe; + PInputEvent ie; + PCanvas canvas; + + public PopupMenu_forMN(Note aFR, PInputEvent _ie, PCanvas _canvas) { + fframe = (MultiNote)aFR; //むりやりキャストする (forMN=MultiMenu用なので、大丈夫かと) + ie = _ie; + canvas = _canvas; + + setLightWeightPopupEnabled(false); + + JMenuItem menuItem; + + menuItem = new JMenuItem("cancel"); + menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0));// メニュー表示時のショートカットキー + add(menuItem); // add cancel menu + + addSeparator(); + + // あたらしいメニューアイテムの設定を開始する。 + menuItem = new JMenuItem("exit"); + menuItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + System.exit(0); + } + }); + add(menuItem);// add exit menu + + + // あたらしいメニューアイテムの設定を開始する。 + menuItem = new JMenuItem("色付け"); + menuItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + + fframe.iroduke(); + } + }); + add(menuItem);// add 色付け menu + + + // 追加のメニューは,プラグインが直接オンデマンドで追加する + // fframe.addPluginMenuTo(this); + + showPopup(); + } + + public void showPopup() { + Point2D cp = ie.getPositionRelativeTo(canvas.getCamera()); + + show(canvas, (int) cp.getX(), (int) cp.getY()); + } +} diff --git a/src/main/java/cit/PureATN/Note.java b/src/main/java/cit/PureATN/Note.java index 1ff26d7..af8b558 100644 --- a/src/main/java/cit/PureATN/Note.java +++ b/src/main/java/cit/PureATN/Note.java @@ -16,11 +16,12 @@ import org.piccolo2d.util.PPaintContext; public class Note extends PFrame { - /** - * - */ + public static void main(final String[] args) { + new Note(); + } + private static final long serialVersionUID = 1L; - private PLayer layer; + public PLayer layer; public static PInputEventFilter disablemask = new PInputEventFilter(0); public static Note theapp; // The Application @@ -33,7 +34,7 @@ } public Note(final PCanvas aCanvas) { - super("Note", false, aCanvas); + super("Note (Esc key to zoom whole strokes)", false, aCanvas); setSize(650, 800); setLocation(10, 10); @@ -157,8 +158,5 @@ }; } - public static void main(final String[] args) { - new Note(); - } } diff --git a/src/main/java/cit/PureATN/PenUser.java b/src/main/java/cit/PureATN/PenUser.java index 17535ec..4e740e6 100644 --- a/src/main/java/cit/PureATN/PenUser.java +++ b/src/main/java/cit/PureATN/PenUser.java @@ -13,6 +13,19 @@ public class PenUser { public static Hashtable penusers = new Hashtable(); + public enum GraphicsMode { + Piccolo2D, + AWT; + } + + // Piccoloをつかうか、AWTをつかうか選択する + public static GraphicsMode graphicsMode = GraphicsMode.Piccolo2D; + + /** + * DPenReceiverから呼ばれる。penIDに対応した、PenUserのインスタンスを返す(なければ用意する) + * + * @param penid + */ public static PenUser find(String penid) { penid = penid.trim(); PenUser pu = penusers.get(penid); @@ -23,6 +36,13 @@ return pu; } + /** + * DPenReceiverから呼ばれる。penIDごとに、PenUserのインスタンスを用意している + * + * @param penid + * @param x + * @param y + */ public static void add(String penid, int x, int y) { PenUser pu = PenUser.find(penid); pu.add(x, y); @@ -39,8 +59,10 @@ } } + // オブジェクトごとのフィールド String penid; - ArrayList strokes; + transient ArrayList stockstrks; // Java AWT/Swing Graphics用 + public ArrayList strokes; // Piccolo2D用 Stroke lastStroke = null; ShortStroke squiggle = null; // for Note View transient Note parent; @@ -49,52 +71,61 @@ public PenUser(String pid, Note _parent) { parent = _parent; penid = pid; - strokes = new ArrayList(); + if (graphicsMode == GraphicsMode.AWT) { + stockstrks = new ArrayList(); + } else { + strokes = new ArrayList(); + } // num = penusers.size(); num = Integer.parseInt(pid.replace("pen", "")); // System.out.println("num = "+num+" "+pid); } public void add(int x, int y) { - System.out.println(penid + " " + x + " " + y); - if (lastStroke == null) { - lastStroke = new Stroke(this); - strokes.add(lastStroke); - } - if (squiggle == null) { - squiggle = new ShortStroke(); - PNode layer = Note.theapp.getCanvas().getLayer(); - layer.addChild(squiggle); - squiggle.startDrag_on_draw(x, y); + System.out.println("add (" + penid + ") " + x + " " + y); + if (graphicsMode == GraphicsMode.AWT) { + if (lastStroke == null) { + lastStroke = new Stroke(this); + stockstrks.add(lastStroke); + } + lastStroke.add(x, y); } else { - squiggle.drag_on_draw(x, y); - PNode layer = Note.theapp.getCanvas().getLayer(); - layer.repaint(); + if (squiggle == null) { + squiggle = new ShortStroke(); + strokes.add(squiggle); + PNode layer = Note.theapp.getCanvas().getLayer(); + layer.addChild(squiggle); + squiggle.startDrag_on_draw(x, y); + } else { + squiggle.drag_on_draw(x, y); + PNode layer = Note.theapp.getCanvas().getLayer(); + layer.repaint(); + } } - lastStroke.add(x, y); Note.theapp.repaint(); + } public void press(int ph) { + System.out.println("press " + ph); if (ph == 0) { - if (lastStroke != null) { - lastStroke.finish(); - // bundlesend(lastStroke); - lastStroke = null; - + if (graphicsMode == GraphicsMode.AWT) { + if (lastStroke != null) { + lastStroke.finish(); + // bundlesend(lastStroke); + lastStroke = null; + } + } else { squiggle = null; } - } else { - // 最初のPress - } } public void draw(Graphics g) { g.setColor(Color.getHSBColor((float) (num / 10.0f), 0.8f, 0.8f)); - int count = strokes.size(); - for (int i = 0; i < count; i++/* Stroke st: strokes */) { - Stroke st = strokes.get(i); + int count = stockstrks.size(); + for (int i = 0; i < count; i++) { + Stroke st = stockstrks.get(i); st.draw(g); } } @@ -121,18 +152,19 @@ // arg2.put("penid", penid); // arg2.put("stroke", st); // arg2.put("rgb", getColorStringRGB()); - // parent.ddp.call("/strokes/insert", new Object[]{arg2}); + // parent.ddp.call("/stockstrks + // insert", new Object[]{arg2}); // arg2.remove("stroke"); // parent.ddp.call("pointsclear", new Object[]{arg2}); } - public String getColorStringRGB(){ - Color c = Color.getHSBColor((float)(num/11.0f), 0.8f, 0.8f); + public String getColorStringRGB() { + Color c = Color.getHSBColor((float) (num / 11.0f), 0.8f, 0.8f); int r = c.getRed(); int g = c.getGreen(); int b = c.getBlue(); - return "rgb("+r+","+g+","+b+")"; + return "rgb(" + r + "," + g + "," + b + ")"; } } \ No newline at end of file diff --git a/src/main/java/cit/PureATN/ShortStroke.java b/src/main/java/cit/PureATN/ShortStroke.java index a5d40c4..417ac69 100644 --- a/src/main/java/cit/PureATN/ShortStroke.java +++ b/src/main/java/cit/PureATN/ShortStroke.java @@ -133,7 +133,7 @@ this.lineTo(px,py); } public void endDrag_on_draw(){ - applyTempPtsToAry(); + // applyTempPtsToAry(); } public void applyTempPtsToAry(){ sx = new float[tempPts.size()];