package cit.PureATN.MultiNote; import java.awt.BasicStroke; import java.awt.Color; import java.awt.geom.Point2D; import java.util.ArrayList; import java.util.Enumeration; import java.util.Iterator; import java.util.List; import java.util.Map; import javax.swing.WindowConstants; import org.josql.Query; import org.josql.QueryExecutionException; import org.josql.QueryParseException; import org.josql.QueryResults; import org.piccolo2d.PCanvas; import org.piccolo2d.PLayer; import org.piccolo2d.activities.PTransformActivity; import org.piccolo2d.nodes.PPath; import org.piccolo2d.util.PBounds; import cit.PureATN.Note; import cit.PureATN.PenUser; import cit.PureATN.ShortStroke; import cit.PureATN.SquiggleEventHandler; public class MultiNote extends Note { static int width = 920; static int height = (int) (width * 1.42); public MultiNote() { this(null); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); theapp = this; // どこからでもNote.theapp で参照できるように } public MultiNote(final PCanvas aCanvas) { super(aCanvas); int width = 1000; int height = (int) (width / 1.414); setSize(width, height); setLocation(100, 200); // dPenReceiver = new DPenReceiver(this); } public static float penID2HSBH(int i){ return ((i+3)%10)/10.0f; } public PPath[] shitajikiNodes = new PPath[11]; public void initialize() { super.initialize(); // 追加機能:キーイベント getCanvas().addKeyListener(new KeyEvent_on_MultiNote(getCanvas())); // 追加機能:右クリックでメニューをだす getCanvas().getCamera().addInputEventListener(new MouseEvent_onMN(this)); currentTitle = "MultiNote ([c]色付け [DEL]全削除 [Esc]ズーム)"; // setTitle(currentTitle); setMousePenID(1); // 基準となる紙の輪郭線 for (int i = 1; i < 11; i++) { PPath stjk = shitajikiNodes[i] = PPath.createRectangle(0, 0, width, height); // stjk.setPaint(Color.getHSBColor((float) (i / 11.0f), 0.1f, 1.0f)); stjk.setPaint(null); stjk.setStrokePaint(Color.getHSBColor(penID2HSBH(i), 0.5f, 1.0f)); stjk.setStroke(new BasicStroke(10)); // if (target.getAttribute("moveTarget")!=null){ // moveTarget = (PNode) target.getAttribute("moveTarget"); // } stjk.addAttribute("moveTarget", stjk); getCanvas().getLayer().addChild(stjk); } // getCanvas().getLayer().addChild(PPath.createRectangle(100, 100, 700, 990)); requestFocus(); } public SquiggleEventHandler createSquiggleEvent() { // may be overridden return new SquiggleEventHandler_MultiNote(this); } public static void main(final String[] args) { new MultiNote(); } // 色付け public void iroduke() { Enumeration<String> 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(penID2HSBH(penid), 0.7f, 0.7f); ArrayList<ShortStroke> sss = PenUser.find(penidStr).strokes; for (ShortStroke s : sss) { s.setStrokePaint(c); // System.out.println("ss.time " + s.time); if (s.getParent() instanceof PLayer) { shitajikiNodes[penid].addChild(s); // 親レイヤーから、下敷きに移動 } } } repaint(); } // stroke.addAttribute("moveTarget", stroke); public void setMoveTargetToShortStroke(boolean isenable) { Enumeration<String> 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.6f, 1.0f); ArrayList<ShortStroke> sss = PenUser.find(penidStr).strokes; for (ShortStroke s : sss) { if (isenable) { s.addAttribute("moveTarget", s); } else { s.addAttribute("moveTarget", null); } } } } /** * 筆記数の確認サンプル:PenIDごとに、筆記数を表示する */ public void showStat() { // 検索対象をあつめる ArrayList<ShortStroke> ass = new ArrayList<ShortStroke>(); var ite = getCanvas().getLayer().getAllNodes().iterator(); while (ite.hasNext()) { var n = ite.next(); if (n instanceof ShortStroke) { ShortStroke ss = (ShortStroke) n; ass.add(ss); } } // (n -> Query q5 = new Query(); try { q5.parse("select * from cit.PureATN.ShortStroke group by penid"); } catch (QueryParseException e) { e.printStackTrace(); } QueryResults qr5 = null; try { qr5 = q5.execute(ass); Map grpBys = qr5.getGroupByResults(); Iterator iter = grpBys.keySet().iterator(); while (iter.hasNext()) { List key = (List) iter.next(); List res = (List) grpBys.get(key); System.out.println(key.toString() + " " + res.size()); } // for (ShortStroke ss : (List<ShortStroke>) qr5.getResults()) { // System.out.println(ss.penid); // } } catch (QueryExecutionException e) { e.printStackTrace(); } } boolean expandMode = false; // 初期状態は「たたんでいる」 public void vlayout() { setExpandMode(!expandMode); } public void setExpandMode(boolean b) { expandMode = b; vlayout(expandMode); } public void vlayout(boolean doexpand) { PTransformActivity ta = null; if (doexpand) { for (int i = 1; i < 6; i++) { shitajikiNodes[i].animateToPositionScaleRotation((i - 1) * width, 0, 1, 0, 1000); } for (int i = 6; i < 11; i++) { ta = shitajikiNodes[i].animateToPositionScaleRotation((i - 6) * width, height, 1, 0, 1000); } PTransformActivity ta2 = getCanvas().getCamera().animateViewToCenterBounds( // getCanvas().getLayer().getFullBounds(), new PBounds(0, 0, width * 5, height * 2), true, 1000); ta2.startAfter(ta); } else { // たたむ for (int i = 1; i < 11; i++) { ta = shitajikiNodes[i].animateToPositionScaleRotation(0, 0, 1, 0, 1000); } PTransformActivity ta2 = getCanvas().getCamera().animateViewToCenterBounds( // getCanvas().getLayer().getFullBounds(), new PBounds(0, 0, width, height), true, 1000); ta2.startAfter(ta); } } // マウスドラッグのとき、どれか1つの枠内で開始された筆記であれば、その下敷きのUserIDに切り替える public void switchPenIDbyPoint(Point2D p) { int matchCount = 0; int lastMatchID = 0; double originx = (double) p.getX(); double originy = (double) p.getY(); for (int i = 1; i < 11; i++) { double localx = originx - shitajikiNodes[i].getOffset().getX(); double localy = originy - shitajikiNodes[i].getOffset().getY(); if (shitajikiNodes[i].getBounds().contains(localx, localy)) { matchCount++; lastMatchID = i; } } // if (matchCount==1 && lastMatchID > 0){ if (lastMatchID > 0) { setMousePenID(lastMatchID); System.out.println("switch to " + lastMatchID + "(count = " + matchCount + ")"); } } // すべての筆記を消す public void deleteAllStrokes() { for (int i = 1; i < 11; i++) { PPath stjk = shitajikiNodes[i]; stjk.removeAllChildren(); // var children = stjk.getChildrenReference(); // for (var child : children) { // if (child instanceof PPath) { // PPath pchild = (PPath) child; // pchild.removeFromParent(); // } // } // } } } }