diff --git a/anchorgarden/pom.xml b/anchorgarden/pom.xml new file mode 100644 index 0000000..70e9027 --- /dev/null +++ b/anchorgarden/pom.xml @@ -0,0 +1,78 @@ + + + + 4.0.0 + + piccolo2d-complete + org.piccolo2d + 3.1-SNAPSHOT + + AnchorGarden + AnchorGarden + bundle + + + + + org.piccolo2d + piccolo2d-extras + ${project.version} + + + + + + + org.piccolo2d + piccolo2d-extras + compile + + + + + + + maven-assembly-plugin + + + + jaist.css.covis.AnchorGarden + + + + jar-with-dependencies + + + + + + diff --git a/anchorgarden/src/build/conf/checkstyle.xml b/anchorgarden/src/build/conf/checkstyle.xml new file mode 100644 index 0000000..de75759 --- /dev/null +++ b/anchorgarden/src/build/conf/checkstyle.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/anchorgarden/src/main/java/.DS_Store b/anchorgarden/src/main/java/.DS_Store new file mode 100644 index 0000000..ca8029f --- /dev/null +++ b/anchorgarden/src/main/java/.DS_Store Binary files differ diff --git a/anchorgarden/src/main/java/jaist/css/covis/AnchorGarden.java b/anchorgarden/src/main/java/jaist/css/covis/AnchorGarden.java new file mode 100644 index 0000000..b98b3f3 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/AnchorGarden.java @@ -0,0 +1,568 @@ +package jaist.css.covis; + +import java.awt.AWTException; +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Point; +import java.awt.Robot; +import java.awt.dnd.DropTarget; +import java.awt.event.ActionListener; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; +import java.util.ArrayList; +import java.util.Queue; +import java.util.concurrent.ConcurrentLinkedQueue; + +import edu.umd.cs.piccolo.PCamera; +import edu.umd.cs.piccolo.PInputManager; +import edu.umd.cs.piccolo.PNode; +import edu.umd.cs.piccolo.event.PBasicInputEventHandler; +import edu.umd.cs.piccolo.event.PInputEvent; +import edu.umd.cs.piccolo.event.PInputEventListener; +import edu.umd.cs.piccolo.nodes.PText; +import edu.umd.cs.piccolo.util.PBounds; +import edu.umd.cs.piccolo.util.PPaintContext; +import edu.umd.cs.piccolox.event.PZoomToEventHandler; +import jaist.css.covis.cls.Covis_Object; +import jaist.css.covis.cls.Informer; +import jaist.css.covis.fm.FlowMenu_TMRG; +import jaist.css.covis.fm.PActionListener; +import jaist.css.covis.pui.CameraFitConstraint.PositionEnum; +import jaist.css.covis.pui.FadeTimer; +import jaist.css.covis.pui.PMenuBar; +import jaist.css.covis.pui.PMenuItem_Color; +import jaist.css.covis.pui.PMenuRoot; +import jaist.css.covis.util.BUtil; +import jaist.css.covis.util.MouseWheelRotationListener; +import jaist.css.covis.util.MyPCanvas; + +/** + * 最初に起動されるクラス + * @author miuramo + * + */ +public class AnchorGarden extends RootWindow implements MouseWheelRotationListener, Runnable { + + public static final String WINDOWTITLE = "Anchor Garden 2"; + + //TODO: ここでログインとソースコード記録するかどうかを決定する trueならログ記録 + // public static final boolean LOGGINGSRC = true; + public static final boolean LOGGINGSRC = false; + + public transient static Color messageBackColor = new Color(254,200,200); + // public FadeTimer[] messageFadeTimers = new FadeTimer[20]; + public Queue messageFadeTimersQueue= new ConcurrentLinkedQueue(); + +// Category log; + + /** + * 最初に実行するmainメソッド + * @param args + */ + + public static void main(String[] args){ + new AnchorGarden(); + } + public AnchorGarden(){ + this(new CoVisBuffer()); + } + public AnchorGarden(CoVisBuffer b){ + super(b); +// BasicConfigurator.configure(); // Log4J Initialize + // オープニングの鳴き声 + Informer.playSound("Rooster.wav"); +// log = Logger.getLogger(AnchorGarden.class.getName()); + initializeMenu(); + switchBuffer(buffer); + } + + + int REPAINTINTERVAL = 5000; + Thread repaintcheckthread; + + public FlowMenu_TMRG flowmenuEventHandler; + + PPickEventHandler pickEventHandler; + + MyPPanEventHandler panEventHandler; + + // DrawEventHandler drawEventHandler; + + PZoomToEventHandler zoomeh; + + ActionListener repaintaction; + + // CameraFitConstraint selectorFitConstraint; + + CoversTransparencyControl coversTransparencyControl; + + PMenuBar pmenubar; + + PMenuRoot mroot; + + PMenuRoot mcolorroot; // 色パレットのルート + + PMenuRoot mpageroot; // ページ一括切り替えメニュー + + PBounds panregionbounds; + + boolean isFlash = false; + + boolean dirty; + boolean ready = false; + + PText modenode; + + public Point2D cursorpoint; + + public PInputEvent lastCursorPointingEvent; + + DropTarget target = null; + + PInputEventListener piel; + + ViewerKeyEventListener viewerKeyListener; + + PCamera virtualCamera; + + + public static BasicStroke REDINKSTROKE = new BasicStroke((float) 2.0, + BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 90.0f); + + public static Color SYSTEMINKCOLOR = Color.red;// StudentPanel.inkcolor; + // public static int REDINKCOLORINT=3; + + PNode tooltipNode; + + boolean showToolTip = true; + + ArrayList bunruiExplainTexts = new ArrayList(); + + public static void setRedInkStroke(float f) { + REDINKSTROKE = new BasicStroke((float) f, BasicStroke.CAP_ROUND, + BasicStroke.JOIN_ROUND, 90.0f); + } + + public static void setRedInkColor(Color c) { + SYSTEMINKCOLOR = c; + } + + public void setShowToolTip(boolean f) { + showToolTip = f; + if (!f) if (tooltipNode != null) tooltipNode.setVisible(false); + } + + public PBounds zoomBounds_focusbyCursor(PBounds pb, double rate) { + double x = pb.getX(); + double y = pb.getY(); + double w = pb.getWidth(); + double h = pb.getHeight(); + double nw = w * rate; + double nh = h * rate; + Point2D camcp = canvas.getCamera().getViewBounds().getCenter2D(); + double camcx = camcp.getX(); + double camcy = camcp.getY(); + double curx = cursorpoint.getX(); + double cury = cursorpoint.getY(); + double nx = x - (nw - w) / 2 + curx - camcx; + double ny = y - (nh - h) / 2 + cury - camcy; + PBounds ret = new PBounds(nx, ny, nw, nh); + cursorpoint = ret.getCenter2D(); + moveCursorPointCenter(); + return ret; + } + + public MyPCanvas getCanvas() { + return canvas; + } + + public void moveCursorPointCenter() { + Point canvasglobalp = getCanvas().getLocationOnScreen(); + int canvasw = getCanvas().getWidth(); + int canvash = getCanvas().getHeight(); + try { + Robot r = new Robot(); + r.mouseMove((int) (canvasglobalp.getX() + canvasw / 2), + (int) (canvasglobalp.getY() + canvash / 2)); + } catch (AWTException ex) { + } + } + + /** + * ATNRootWindow.switchBuffer から呼ばれる(重要!!) + * + */ + public void initialize() { + getCanvas().setDefaultRenderQuality(PPaintContext.HIGH_QUALITY_RENDERING); + getCanvas().setAnimatingRenderQuality(PPaintContext.HIGH_QUALITY_RENDERING); + getCanvas().setInteractingRenderQuality(PPaintContext.HIGH_QUALITY_RENDERING); + + disablemask.rejectAllEventTypes(); + // flowmenu + flowmenuEventHandler = new FlowMenu_TMRG(this); + flowmenuEventHandler.setEventFilter(b1mask); + getCanvas().addInputEventListener(flowmenuEventHandler); + + // pick + pickEventHandler = new PPickEventHandler(this); + pickEventHandler.setEventFilter(disablemask); + getCanvas().addInputEventListener(pickEventHandler); + // getCanvas().getRoot().getDefaultInputManager().setKeyboardFocus(pickEventHandler); + + // pan + panEventHandler = new MyPPanEventHandler(this); + panEventHandler.setEventFilter(disablemask); + getCanvas().addInputEventListener(panEventHandler); + + // draw + // drawEventHandler = new DrawEventHandler(this); + // drawEventHandler.setEventFilter(disablemask); + // getCanvas().addInputEventListener(drawEventHandler); + + // // Button2 - pan + // getCanvas().getPanEventHandler().setEventFilter(b2mask); + + // Button 3 - regionzoom + CoVisWindow_ZoomRegionHandler zrh = new CoVisWindow_ZoomRegionHandler(this); + getCanvas().addInputEventListener(zrh); + zrh.setEventFilter(b3mask); + getCanvas().removeInputEventListener(getCanvas().getZoomEventHandler()); + + // check current cursor position + getCanvas().addInputEventListener(new PInputManager() { + public void mouseMoved(PInputEvent e) { + cursorpoint = e.getPosition(); + lastCursorPointingEvent = e; + } + }); + + // ショートカットキーイベント + viewerKeyListener = new ViewerKeyEventListener(this); + getCanvas().getCamera().addInputEventListener(viewerKeyListener); + // frame.addKeyListener(viewerKeyListener); + getCanvas().addKeyListener(viewerKeyListener); + + // mroot = new PMenuRoot(); + // PMenuItem_String pm1 = new PMenuItem_String("menu", true, Color.orange); + // PMenuItem_String pm2 = new PMenuItem_String("pick", true, Color.orange); + // PMenuItem_String pm3 = new PMenuItem_String("pan", true, Color.orange); + // PMenuItem_String pm4 = new PMenuItem_String("draw", true, Color.orange); + // // ^^^^ true if the menu is a "radio button" + // mroot.add(pm1); + // mroot.add(pm2); + // mroot.add(pm3); + // mroot.add(pm4); + // mroot.setSelected(pm1); + // pm1.addPActionListener(new PActionListener() { + // public void actionPerformed(PInputEvent e) { + // flowmenuEventHandler.setEventFilter(b1mask); + // pickEventHandler.setEventFilter(disablemask); + // panEventHandler.setEventFilter(disablemask); + // drawEventHandler.setEventFilter(disablemask); + // } + // }); + // pm2.addPActionListener(new PActionListener() { + // public void actionPerformed(PInputEvent e) { + // flowmenuEventHandler.setEventFilter(disablemask); + // pickEventHandler.setEventFilter(b1mask); + // panEventHandler.setEventFilter(disablemask); + // drawEventHandler.setEventFilter(disablemask); + // } + // }); + // pm3.addPActionListener(new PActionListener() { + // public void actionPerformed(PInputEvent e) { + // flowmenuEventHandler.setEventFilter(disablemask); + // pickEventHandler.setEventFilter(disablemask); + // panEventHandler.setEventFilter(b1mask); + // drawEventHandler.setEventFilter(disablemask); + // } + // }); + // pm4.addPActionListener(new PActionListener() { + // public void actionPerformed(PInputEvent e) { + // flowmenuEventHandler.setEventFilter(disablemask); + // pickEventHandler.setEventFilter(disablemask); + // panEventHandler.setEventFilter(disablemask); + // drawEventHandler.setEventFilter(b1mask); + // } + // }); + // // getCanvas().getCamera().addChild(pm_root); + // mroot.setOffset(660, 0); + + pmenubar = new PMenuBar(getCanvas().getCamera(), this); + // pmenubar.addPMenuRoot(mroot, PositionEnum.TOPCENTER, new Dimension()); + + // mcolorroot = new PMenuRoot(); + // PMenuItem_Color pmc_black = new PMenuItem_Color("k", true, Color.black); + //// PMenuItem_Color pmc_white = new PMenuItem_Color("w", true, Color.white); + // PMenuItem_Color pmc_blue = new PMenuItem_Color("b", true, Color.blue); + // PMenuItem_Color pmc_green = new PMenuItem_Color("g",true, new Color(0,120,0)); + //// System.out.println("緑 "+(long)(new Color(0,120,0).getRGB())); + // PMenuItem_Color pmc_red = new PMenuItem_Color("r", true, Color.red); + //// PMenuItem_Color pmc_orange = new PMenuItem_Color("o",true,Color.orange); + // mcolorroot.add(pmc_black); + //// mcolorroot.add(pmc_white); + // mcolorroot.add(pmc_blue); + // mcolorroot.add(pmc_green); + // mcolorroot.add(pmc_red); + //// mcolorroot.add(pmc_orange); + // mcolorroot.setSelected(pmc_red); + // pmenubar.addPMenuRoot(mcolorroot, PositionEnum.TOPRIGHT, new Dimension()); + // pmc_black.addPActionListener(new PActionListener() { + // public void actionPerformed(PInputEvent e) { + // CoVisWindow.setRedInkColor(Color.black); + // } + // }); + //// pmc_white.addPActionListener(new PActionListener() { + //// public void actionPerformed(PInputEvent e) { + //// GKJWindow.setRedInkColor(Color.red); + //// } + //// }); + // pmc_red.addPActionListener(new PActionListener() { + // public void actionPerformed(PInputEvent e) { + // CoVisWindow.setRedInkColor(Color.red); + // } + // }); + // pmc_blue.addPActionListener(new PActionListener() { + // public void actionPerformed(PInputEvent e) { + // CoVisWindow.setRedInkColor(Color.blue); + // } + // }); + // pmc_green.addPActionListener(new PActionListener(){ + // public void actionPerformed(PInputEvent e){ + // CoVisWindow.setRedInkColor(new Color(0,120,0)); + // } + // }); + //// pmc_orange.addPActionListener(new PActionListener(){ + //// public void actionPerformed(PInputEvent e){ + //// GKJWindow.setRedInkColor(Color.orange); + //// } + //// }); + // viewerKeyListener.addPMenuToShortcutList(pmc_black); + //// viewerKeyListener.addPMenuToShortcutList(pmc_white); + // viewerKeyListener.addPMenuToShortcutList(pmc_red); + // viewerKeyListener.addPMenuToShortcutList(pmc_blue); + // viewerKeyListener.addPMenuToShortcutList(pmc_green); + //// viewerKeyListener.addPMenuToShortcutList(pmc_orange); + + PMenuRoot layoutPMR = new PMenuRoot(); + PMenuItem_Color pmc_reset = new PMenuItem_Color("Reset World", false, Color.orange); + PMenuItem_Color pmc_layout = new PMenuItem_Color("Zoom home (ESC-key)", false, Color.orange); + // PMenuItem_Color pmc_src = new PMenuItem_Color("source code", false, Color.orange); + // PMenuItem_Color pmc_cover = new PMenuItem_Color("cover", false, Color.orange); + // PMenuItem_Color pmc_drawinfo = new PMenuItem_Color("peninfo", false, Color.orange); + // PMenuItem_Color pmc_label = new PMenuItem_Color("label", false, Color.orange); + layoutPMR.add(pmc_reset); + layoutPMR.add(pmc_layout); + // layoutPMR.add(pmc_src); + // layoutPMR.add(pmc_cover); + // layoutPMR.add(pmc_drawinfo); + // layoutPMR.add(pmc_label); + + pmenubar.addPMenuRoot(layoutPMR, PositionEnum.TOPLEFT, new Dimension()); + pmc_reset.addPActionListener(new PActionListener() { + public void actionPerformed(PInputEvent e) { + AnchorGarden.this.resetWorld(); + } + }); + pmc_layout.addPActionListener(new PActionListener() { + public void actionPerformed(PInputEvent e) { + AnchorGarden.this.fitAndZoomHome(200); + } + }); + // pmc_src.addPActionListener(new PActionListener(){ + // public void actionPerformed(PInputEvent e){ + // showSrcWin(); + // } + // }); + // pmc_drawinfo.addPActionListener(new PActionListener(){ + // public void actionPerformed(PInputEvent e){ + // CoVisWindow.this.buffer.viewcontroller.cblist.get("drawInfo").setSelected(!CoVisWindow.this.buffer.viewcontroller.cblist.get("drawInfo").isSelected()); + // } + // }); + // pmc_label.addPActionListener(new PActionListener(){ + // public void actionPerformed(PInputEvent e){ + // CoVisWindow.this.buffer.viewcontroller.showLabelButton.doClick(); + // CoVisWindow.this.fitAndZoomHome(1); + // } + // }); + + + coversTransparencyControl = new CoversTransparencyControl(this); + + getCanvas().getCamera().addInputEventListener(new PBasicInputEventHandler() { + public void mouseMoved(PInputEvent event) { + updateToolTip(event); + } + + public void mouseDragged(PInputEvent event) { + updateToolTip(event); + } + + public void updateToolTip(PInputEvent event) { + if (showToolTip && !event.isShiftDown()) { + PNode n = event.getInputManager().getMouseOver().getPickedNode(); + if (n.getAttribute("tooltip") != null){ + Object o = n.getAttribute("tooltip"); + if (o instanceof ToolTipProvider) { + PNode newTTN = ((ToolTipProvider)o).getToolTipNode(); + if (tooltipNode != newTTN){ + if (tooltipNode != null) tooltipNode.removeFromParent(); + tooltipNode = newTTN; + if (tooltipNode != null) getCanvas().getCamera().addChild(tooltipNode); + } + Point2D p = event.getCanvasPosition(); + // if (tooltipNode != null) tooltipNode.setOffset(p.getX()+25, p.getY()+15); + if (tooltipNode != null) { + if (tooltipNode instanceof Covis_Object) tooltipNode.setOffset(p.getX()+10, p.getY()+10); + else tooltipNode.setOffset(p.getX()+25, p.getY()+15); + } + if (tooltipNode != null) tooltipNode.setVisible(true); + } + } else { + if (tooltipNode != null){ + tooltipNode.removeFromParent(); + tooltipNode = null; + } + } + checkIfCoverIsNecessary(); //カバーシートはズームしすぎたら邪魔になるので消す + } + } + }); + + // // TODO: バッファを切り替えたときに、全体画面に戻る(要カスタマイズ?) + // getCanvas().getCamera().animateViewToCenterBounds(buffer.grayBackSheet.getBounds(), true, 0); + + // fitAndZoomHome(1); //最初のレイアウト + // TODO: ウィンドウ初期化時のごたごたを隠すため、ぼやっと表示(ただし、bufferの初期化が済んでいるときは除く) + // if (buffer.layer.getTransparency() == 0.0f) { + // buffer.layer.animateToTransparency(0.0f, 100); + buffer.layer.animateToTransparency(1.0f, 1200); + // getCanvas().getLayer().addChild(buffer.virtualCamera); + getCanvas().getCamera().setViewBounds(new Rectangle2D.Float(-10,-10,20,20)); + getCanvas().getCamera().setViewScale(0.0001); + // setViewBounds(new Rectangle2D.Float(0,0,10000,10000)); + + +// なぜかものすごく重くなるので,自前のスレッドで処理することにした 2016/8/31 + // repaintaction = new ActionListener() { +// public void actionPerformed(ActionEvent e) { +// checkrepaint(); +// } +// }; + // Timer t = new Timer(REPAINTINTERVAL, repaintaction); + // t.start(); + repaintcheckthread = new Thread(this); + repaintcheckthread.start(); + ready = true; + modenode = new PText("Select mode"); + modenode.setScale(2.0); + + } + + @Override + public void run() { + while(repaintcheckthread != null){ + try { + Thread.sleep(REPAINTINTERVAL); + } catch (InterruptedException e) { + e.printStackTrace(); + } + checkrepaint(); + } + } + + + /** + * MyPCanvas の MouseWheelRotationListener に登録してあれば,ホイール回転時に情報がくる + */ + public void mouseWheelRotated(float f) { + checkIfCoverIsNecessary(); + } + /** + * カバーシートはズームしすぎたら邪魔になるので消す + */ + public void checkIfCoverIsNecessary(){ + // if (getCanvas().getCamera().getViewBounds().getHeight() > buffer.covisProperty.stsizey*4) { + // coversTransparencyControl.transparencyThread_Start(1); + // } else { + // coversTransparencyControl.transparencyThread_Start(0); + // } + } + + + public void initializeMenu(){ + super.initializeMenu(); + // JMenuItem up = new JMenuItem("更新"); + // up.addActionListener(new ActionListener(){ + // public void actionPerformed(ActionEvent e){ + // if (buffer != null) buffer.updateFromDB(); + // } + // }); + // viewMenu.add(up); + + // updateMenu = new JCheckBoxMenuItem(); //外枠だけ作成しておく(どうせSwitchBufferでActionを設定するので) + // + // viewMenu.add(updateMenu); + menuBar.revalidate(); + menuBar.repaint(); + } + + public void checkrepaint() { + if (dirty) + getCanvas().repaint(); + dirty = false; + } + + public void zoomHomePane(int animsec) { + PBounds pb = buffer.layer.getFullBounds(); + pb = BUtil.zoomBounds(pb, 1.05); + getCanvas().getCamera().animateViewToCenterBounds(pb, true, animsec); + } + public void zoomPane(int d) { + PCamera pc = getCanvas().getCamera(); + PBounds pb = pc.getViewBounds(); + float f = 1.0f - (0.08f * d); + pb = BUtil.zoomBounds(pb, f); + pc.animateViewToCenterBounds(pb, true, 0); + } + public void fitLayout(int animsec) { + } + public void fitAndZoomHome(int animsec){ + zoomHomePane(animsec); + } + public void zoomBounds(PBounds pb, float f){ + PCamera pc = getCanvas().getCamera(); + pb = BUtil.zoomBounds(pb, f); + pc.animateViewToCenterBounds(pb, true, 0); + } + public void initZoom(int i) { + } + + public void showFadingMessage(String s, Color bc, Color fc, float scale, float trans){ + PText pt = new PText(s); + pt.setScale(scale); + pt.setTransparency(trans); + pt.setPaint(bc); + pt.setTextPaint(fc); + + double yplus = getCanvas().getCamera().getBoundsReference().getHeight()*3/4; + for(FadeTimer f : messageFadeTimersQueue){ + if (yplus < (f.pn.getOffset().getY() + f.pn.getHeight() * f.pn.getScale() + 4)) + yplus = f.pn.getOffset().getY() + f.pn.getHeight() * f.pn.getScale() + 4; + } + getCanvas().getCamera().addChild(pt); + pt.setOffset((getCanvas().getCamera().getBoundsReference().getWidth()-pt.getWidth()*pt.getScale())/2,yplus); + + FadeTimer ft = new FadeTimer(pt, 5000,2000); + messageFadeTimersQueue.add(ft); + ft.setFadeTimers(messageFadeTimersQueue); + + if (yplus + pt.getHeight()* pt.getScale() + 4> getCanvas().getCamera().getBoundsReference().getHeight()){ + for(FadeTimer f : messageFadeTimersQueue){ + f.pn.offset(0, getCanvas().getCamera().getBoundsReference().getHeight()-yplus - pt.getHeight()* pt.getScale() - 4); + } + } + } + +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/CoVisBuffer.java b/anchorgarden/src/main/java/jaist/css/covis/CoVisBuffer.java new file mode 100644 index 0000000..e9e9c5a --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/CoVisBuffer.java @@ -0,0 +1,397 @@ +package jaist.css.covis; + +import java.awt.Color; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.TreeMap; + +import javax.swing.JCheckBox; +import javax.swing.Timer; + +import edu.umd.cs.piccolo.PNode; +import edu.umd.cs.piccolo.nodes.PPath; +import jaist.css.covis.cls.Anchor; +import jaist.css.covis.cls.ClassField; +import jaist.css.covis.cls.ClassFieldMenu; +import jaist.css.covis.cls.ClassStamp; +import jaist.css.covis.cls.Covis_Array; +import jaist.css.covis.cls.Covis_BTree; +import jaist.css.covis.cls.Covis_Frac; +import jaist.css.covis.cls.Covis_LinkList; +import jaist.css.covis.cls.Covis_Object; +import jaist.css.covis.cls.Covis_Oval; +import jaist.css.covis.cls.Covis_Rect; +import jaist.css.covis.cls.Covis_String; +import jaist.css.covis.cls.Covis_int; +import jaist.css.covis.cls.Covis_primitive; +import jaist.css.covis.cls.ObjectField; +import jaist.css.covis.cls.StaticField; +import jaist.css.covis.cls.VarField; +import jaist.css.covis.cls.Variable; +import jaist.css.covis.hist.CVHist_Link; +import jaist.css.covis.hist.CVHist_Method; +import jaist.css.covis.hist.CVHist_MethodNew; +import jaist.css.covis.hist.CVHist_New; +import jaist.css.covis.hist.CVHist_Unlink; +import jaist.css.covis.hist.CVHist_Value; +import jaist.css.covis.hist.CVHist_ValueArray; +import jaist.css.covis.hist.CVHist_Var; +import jaist.css.covis.hist.CVHistory; + +/** + * 生徒パネルビューの表示データ(モデル).ATNWindowがビューとなり,このATNBufferを参照して表示する. + * @author miuramo + * + */ +public class CoVisBuffer extends RootBuffer { + public static final Color stafcolor = new Color(255,255,240,200); + public static final Color objfcolor = new Color(200,255,240,200); + public static final Color varfcolor = new Color(220,220,255,200); + public static final Color typefcolor = new Color(255,222,56,200); + public static final Color linkcolor = new Color(200,255,200,200); + public static final Color ulinkcolor = new Color(255,200,200); + public static final Color varcolor = new Color(140,200,255); + public static final Color methodcolor = new Color(255,250,255); + + /** + * Log4J + */ +// Category log; + public CoVisProperty covisProperty; + JCheckBox updateContCB; + + public ObjectField objField; + public ClassField clsField; + public VarField varField; + public StaticField staField; + Timer clsFieldInitTimer; + + ArrayList[] advancedClass; + +// InfoGetter ig; + + public TreeMap history; + + public void putHistoryMethod(String type, Object obj, String methodcall, boolean isShow){ + CVHist_Method cvhist = new CVHist_Method(obj, this, methodcall, isShow); + // obj.setCVHist(cvhist); + history.put(System.currentTimeMillis(), cvhist); + updateSourceWindow(); + } + public void putHistoryMethodNew(String type, Covis_Object obj, String methodcall){ + CVHist_MethodNew cvhist = new CVHist_MethodNew(obj, this, methodcall); + obj.setCVHist(cvhist); + history.put(System.currentTimeMillis(), cvhist); + updateSourceWindow(); + } + public void putHistoryNew(String type, Covis_Object obj){ + putHistoryNew(type, obj, true); + } + public void putHistoryNew(String type, Covis_Object obj, boolean isShow){ + CVHist_New cvhist = new CVHist_New(obj, this, isShow); + obj.setCVHist(cvhist); + if (isShow) history.put(System.currentTimeMillis(), cvhist); + updateSourceWindow(); + } + public void putHistoryVar(String type, Variable var) { + putHistoryVar(type, var, false); + } + public void putHistoryVar(String type, Variable var, boolean isShow) { + CVHist_Var cvhist = new CVHist_Var(var, this, isShow); + var.setCVHist(cvhist); + if (isShow) history.put(System.currentTimeMillis(), cvhist); + if (isShow) updateSourceWindow(); + } + public void putHistoryEditValue(Variable var){ + CVHist_Value cvhist = new CVHist_Value(var, this); + // var.setCVHist(cvhist); + history.put(System.currentTimeMillis(), cvhist); + updateSourceWindow(); + } + public void putHistoryEditValueArray(Covis_primitive v, Covis_Array a) { + CVHist_ValueArray cvhist = new CVHist_ValueArray(v,a,this); + history.put(System.currentTimeMillis(), cvhist); + updateSourceWindow(); + } + + public void putHisotryLink(String type, Anchor a, Covis_Object obj){ + if (obj==null) {System.out.println("obj=null"); return;} + if (obj.cvhist==null) {System.out.println("obj.cvhist=null"); return;} + if (obj.cvhist.getCode()==null) {System.out.println("obj.cvhist.getCode()=null"); return;} + if (a.getSrcVariable()==null) {System.out.println("a.getVarIfAvailable()=null"); return;} + + if (obj.cvhist.getCode().startsWith("new ") || (obj.cvhist instanceof CVHist_MethodNew && !obj.cvhist.isConsumed()) ){ //newで始まるばあい + // もし,NEWが先なら,変数だけつけると変数定義が後になってしまうため,変数定義もつける + // if (a.getSrcVariable() != null){ + // String[] strAry1 = new String[4]; + // if (a.getSrcVariable().cvhist==null) {System.out.println("a.getVarIfAvailable().cvhist=null"); return;} + + if (obj.cvhist.tstamp < a.getSrcVariable().cvhist.tstamp){ //変数のほうを後に作成したなら + String vardefine = a.getSrcVariable().cvhist.getCode(); + vardefine = vardefine.substring(0, vardefine.length()-1); + // obj.cvhist.setCode(vardefine +" = "+obj.cvhist.getCode()); + setHistLinkCode_ConcatinateVarDefAndNew(a, vardefine, obj); + a.getSrcVariable().cvhist.setAlive(false); + } else { + // obj.cvhist.setCode(a.getVarName()+" = "+obj.cvhist.getCode()); + // System.out.println(a.getVarName()+" "+a.varName); + setHistLinkCode_ConcatinateVarDefAndNew(a, Variable.getShortestName(a.srcVariable.getVarNamesAry()), obj);//ここここ + // a.getSrcVariable().cvhist.setAlive(false); + } + obj.cvhist.setConsumed(true); + //incoming>0 のオブジェクトであれば,全部Consumedにする.過去のnewオブジェクトにリンクできなくなるが. + for(CVHistory cvh : history.values()){ + if (cvh instanceof CVHist_New){ + CVHist_New cvhnew = (CVHist_New)cvh; + if (cvhnew.getObject().anchors_incoming.size()>0){ + cvhnew.setConsumed(true); + } + } + } + // } + } else { //リンクの場合 + CVHist_Link cvhist = new CVHist_Link(a, obj, this); + if (cvhist.getCode() != null) + history.put(System.currentTimeMillis(), cvhist); + } + updateSourceWindow(); + } + private void setHistLinkCode_ConcatinateVarDefAndNew(Anchor a, String varDefOrVarName, Covis_Object obj){ + System.out.println("setHistLinkCode_ConcatinateVarDefAndNew varDefOrVarName "+varDefOrVarName); + obj.cvhist.setCode(varDefOrVarName+ + " = "+obj.cvhist.getCode(),true); + + return; + } + + public void putHistoryUnLink(String type, Anchor anchor) { + System.out.println("putHistoryUnlink"); + CVHist_Unlink cvhist = new CVHist_Unlink(anchor, this); + if (!cvhist.getCode().startsWith("null")) + history.put(System.currentTimeMillis(), cvhist); + updateSourceWindow(); + } + + public void updateSourceWindow(){ + StringBuffer sb = new StringBuffer(); + for(CVHistory s: history.values()){ + if (s.isAlive()) sb.append(s.getCode()+"\n"); + } +// addLog(10,sb.toString()); //TODO: ログ追加 + if (getWindow().srcWindow != null) + getWindow().srcWindow.jta.setText(sb.toString()); + } + + public CoVisBuffer(){ + this(null); + } + + public CoVisBuffer(CoVisProperty _sprop) { + super(); +// log = Logger.getLogger(CoVisBuffer.class.getName()); + if (_sprop == null) _sprop = CoVisBuffer.loadProperty(); + covisProperty = _sprop; + + // viewcontroller = new ViewController(this); + // updateStateAction = new DBUpdateContinuousAction("連続", "general/Refresh16", "連続更新", new Integer(KeyEvent.VK_C)); + + history = new TreeMap(); + +// if (AnchorGarden.LOGGINGSRC){ +// ig = new InfoGetter();//TODO:ここでログイン必要かどうか決める +// } + initialize(); //このinitialize は上のstudent stock initialize, StudentPanel stock initialize の後で行う必要がある +// if (AnchorGarden.LOGGINGSRC){ +// ig.addLog(1, "started"); +// } + + } +// public void addLog(int i, String src) { +// if (ig != null) ig.addLog(i, src); +// } +// public void addLogNow(int i, String src) { +// if (ig != null) ig.addLogNow(i, src); +// } + + @SuppressWarnings("unchecked") + public void initialize() { + layer.setTransparency(0.0f); //初期化時のごたごたを隠すため(ATNWindow.initialize()の最後で除除に表示) + + int width = 1100; + int height = 900; + + PNode bg = new PNode(); + for(int i=0;i<=width;i+=100){ + PPath line = PPath.createLine(i, 0, i, height); + line.setPaint(Color.LIGHT_GRAY); + line.setTransparency(0.3f); + bg.addChild(line); + } + for(int j=0;j<=height;j+=100){ + PPath line = PPath.createLine(0, j, width, j); + line.setPaint(Color.LIGHT_GRAY); + line.setTransparency(0.3f); + bg.addChild(line); + } + layer.addChild(bg); + + objField = new ObjectField("Object", objfcolor, this); + objField.setOffset(500,0); + objField.setPathToRectangle(0, 0, 600, height); + objField.addAttribute("tooltip", objField); + layer.addChild(objField); + + varField = new VarField("Variable", varfcolor, this); + varField.addAttribute("tooltip", varField); + varField.setOffset(180,0); + layer.addChild(varField); + + clsField = new ClassField("Type", typefcolor, this); + // clsField.setOffset(840,0); + clsField.setOffset(0,0); + layer.addChild(clsField); + + // staField = new StaticField("Class (Static)", stafcolor, this); + // staField.setOffset(350,-160); + // staField.setPathToRectangle(0, 0, 750, 120); + // staField.addAttribute("tooltip", staField); + // layer.addChild(staField); + + + + + advancedClass = new ArrayList[3]; + for(int i=0;i(); + } + + ClassStamp newP; + + + newP = new ClassStamp(new Covis_Frac(this,true) ,this); + advancedClass[1].add(newP); + clsField.addChild(newP); + newP = new ClassStamp(new Covis_Array(this,true,"Frac"), this); + advancedClass[1].add(newP); + clsField.addChild(newP); + + newP = new ClassStamp(new Covis_LinkList(this,true) ,this); + advancedClass[1].add(newP); + clsField.addChild(newP); + + newP = new ClassStamp(new Covis_BTree(this,true) ,this); + advancedClass[1].add(newP); + clsField.addChild(newP); + // newP = new ClassStamp(new Covis_Array(this,true,"BTree"), this); + // advancedClass[1].add(newP); + // clsField.addChild(newP); + + + newP = new ClassStamp(new Covis_int(this,true) ,this); + advancedClass[0].add(newP); + clsField.addChild(newP); + newP = new ClassStamp(new Covis_Array(this,true,"int") ,this); + advancedClass[0].add(newP); + clsField.addChild(newP); + newP = new ClassStamp(new Covis_String(this,true) ,this); + advancedClass[0].add(newP); + clsField.addChild(newP); + newP = new ClassStamp(new Covis_Array(this,true,"String") ,this); + advancedClass[0].add(newP); + clsField.addChild(newP); + + // Advanced Classes + newP = new ClassStamp(new Covis_Object(this,true) ,this); + advancedClass[2].add(newP); +// clsField.addChild(newP); + newP = new ClassStamp(new Covis_Array(this,true,"Object") ,this); + advancedClass[2].add(newP); + // clsField.addChild(newP); + newP = new ClassStamp(new Covis_Oval(this,true) ,this); + advancedClass[2].add(newP); + newP = new ClassStamp(new Covis_Array(this,true,"Oval") ,this); + advancedClass[2].add(newP); + newP = new ClassStamp(new Covis_Rect(this,true) ,this); + advancedClass[2].add(newP); + newP = new ClassStamp(new Covis_Array(this,true,"Rect") ,this); + advancedClass[2].add(newP); + + + // newP = new ClassStamp(new Covis_Random(this,true)); + // advancedClass.add(newP); + // newP = new ClassStamp(new Covis_char(this,true)); + // advancedClass.add(newP); + // newP = new ClassStamp(new Covis_Array(this,true,"char")); + // advancedClass.add(newP); + // newP = new ClassStamp(new CopyOfCovis_Array(this,true)); + // advancedClass.add(newP); + + clsField.layout(1); + // clsField.layoutByToString(0); + + clsField.addAttribute("popupMenu", new ClassFieldMenu(clsField,this)); + + } + public void createInitTimer(){ + if (clsFieldInitTimer == null){ + clsFieldInitTimer = new Timer(500, new ActionListener(){ + public void actionPerformed(ActionEvent e){ +// clsField.layout(200); + while(getWindow()==null) + try { + Thread.sleep(1000); + } catch (InterruptedException e1) { + e1.printStackTrace(); + } + getWindow().zoomHomePane(1400); + + System.out.println("clsField init"); + clsFieldInitTimer.stop(); + clsFieldInitTimer = null; + } + }); + clsFieldInitTimer.start(); + } + } + + public void updateFromDB(){ + // mysql.updateFromDB(); + } + + public static CoVisProperty loadProperty() { + return new CoVisProperty(null); + } + public void resetWorld() { + varField.removeAllVariables(); + history.clear(); + for(ClassStamp ct: clsField.getTypeNodes()){ + ct.cv_type.clear_objCount(); + } + } + + public void showAdvancedClasses(int level) { + for(int i=0;i -1) { + line = lines[i].substring(0, index); + } else { + line = lines[i]; + } + // System.out.println(line); + st2 = new StringTokenizer(line, "="); + if (st2.countTokens() == 2) { + String finame = st2.nextToken().trim(); + String val = st2.nextToken().trim(); + Object o = gen_primitive(this, finame, val); + setter(this, finame, o); + } + } + } + } + + @SuppressWarnings("rawtypes") + public static final Class getWrapperClass(Class primitiveClass) { + Class wrapper = null; + if (primitiveClass == Boolean.TYPE) + wrapper = java.lang.Boolean.class; + else if (primitiveClass == Character.TYPE) + wrapper = java.lang.Character.class; + else if (primitiveClass == Byte.TYPE) + wrapper = java.lang.Byte.class; + else if (primitiveClass == Short.TYPE) + wrapper = java.lang.Short.class; + else if (primitiveClass == Integer.TYPE) + wrapper = java.lang.Integer.class; + else if (primitiveClass == Long.TYPE) + wrapper = java.lang.Long.class; + else if (primitiveClass == Float.TYPE) + wrapper = java.lang.Float.class; + else if (primitiveClass == Double.TYPE) + wrapper = java.lang.Double.class; + else if (primitiveClass == java.lang.String.class) + wrapper = java.lang.String.class; + return wrapper; + } + +// public void test() { +// try { +// // クラスを取得 +// Class c = Class.forName("jaist.css.atn.ATNProperty"); +// // アクセス可能なフィールドをリフレクトする +// Field[] field = c.getFields(); +// System.out.println("----- アクセス可能なフィールド -------"); +// for (int i = 0; i < field.length; i++) { +// String fieldname = field[i].toString(); +// System.out.print(fieldname + " "); +// System.out.println(field[i].get(this).toString()); +// } +// System.out.println(); +// } catch (Exception ex) { +// ex.printStackTrace(System.out); +// } +// } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + public static Object gen_primitive(Object obj, String fieldname, + String value) { + try { + // (1) determine target wrapper class of primitive + Class cthis = obj.getClass(); + Field f = cthis.getField(fieldname); + // System.out.println(f.getType().toString()); + Class pclass = getWrapperClass(f.getType()); + // System.out.println(pclass.toString()); + Class[] pconstcarg = new Class[1]; + pconstcarg[0] = Class.forName("java.lang.String"); + Constructor pconst = pclass.getConstructor(pconstcarg); + Object[] parg = new Object[1]; + parg[0] = value; + return pconst.newInstance(parg); + } catch (Exception ex) { + ex.printStackTrace(System.out); + } + return null; + } + + // obj: 対象オブジェクト,fieldname 対象フィールド, o 変更後の値 + @SuppressWarnings("rawtypes") + public static void setter(Object obj, String fieldname, Object o) { + try { + Class c = obj.getClass(); + Field f = c.getField(fieldname); + StringBuffer sb = new StringBuffer(); + sb.append(" | " + fieldname + " : "); + sb.append(f.get(obj).toString() + " -> "); + f.set(obj, o); + sb.append(f.get(obj).toString()); + System.out.println(sb.toString()); + } catch (Exception ex) { + ex.printStackTrace(System.out); + } + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/CoVisWindow_SelectionRegionHandler.java b/anchorgarden/src/main/java/jaist/css/covis/CoVisWindow_SelectionRegionHandler.java new file mode 100644 index 0000000..9541ea6 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/CoVisWindow_SelectionRegionHandler.java @@ -0,0 +1,292 @@ +package jaist.css.covis; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Stroke; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Hashtable; + +import edu.umd.cs.piccolo.PNode; +import edu.umd.cs.piccolo.event.PDragSequenceEventHandler; +import edu.umd.cs.piccolo.event.PInputEvent; +import edu.umd.cs.piccolo.nodes.PPath; +import edu.umd.cs.piccolo.util.PBounds; + +/** + * Selectableを範囲選択 + * @author miuramo + * + */ +public class CoVisWindow_SelectionRegionHandler extends PDragSequenceEventHandler { + AnchorGarden viewer; + + PPath selection; + + private Stroke[] strokes = null; + + private float strokeNum = 0; + + final static int NUM_STROKES = 10; + + final static int DASH_WIDTH = 15; + + Point2D cmp; // ドラッグ開始座標 + + Point2D cp; //ドラッグ中の座標 + + public ArrayList tempSelect; + +// double dist_max_ext_cp; //そのときの距離 + PBounds initialBounds; //ドラッグ開始時の視野 + + PNode targetPN; + Point2D targetPNorigin; + Point2D targetPNtopleft; + + PNode selectTarget; + int dragCount = 0; + + public Hashtable trash; // DELキーで選択削除したものを,一旦蓄えておく.次に削除するまで,一段のみアンドゥ可能 + public boolean undoExecuted = false; + + public CoVisWindow_SelectionRegionHandler(AnchorGarden _viewer) { + this.viewer = _viewer; + + float[] dash = { DASH_WIDTH, DASH_WIDTH }; + strokes = new Stroke[NUM_STROKES]; + for (int i = 0; i < NUM_STROKES; i++) { + strokes[i] = new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1, dash, i); + } + tempSelect = new ArrayList(); + + trash = new Hashtable(); + } + + public void startDrag(PInputEvent e) { + super.startDrag(e); + + //クリック選択トグル用 + if (e.getPickedNode().getAttribute("selectable")!=null){ + selectTarget = (PNode) e.getPickedNode().getAttribute("selectable"); + } + dragCount = 0; + + // 範囲選択用 ターゲットベース (not カメラビューベース) + if (e.getPickedNode() instanceof PNode && (e.getPickedNode().getAttribute("drawTarget")!=null)){ + targetPN = (PNode) e.getPickedNode().getAttribute("drawTarget"); + System.out.println(targetPN.getClass().getName()); + targetPNorigin = (Point2D) e.getPickedNode().getAttribute("drawOffset"); + if (targetPNorigin == null) targetPNorigin = new Point2D.Double(); + + if (targetPN != null) { + Point2D p = e.getPositionRelativeTo(e.getPickedNode()); + if (targetPNorigin != null) p.setLocation(p.getX()+targetPNorigin.getX(),p.getY()+targetPNorigin.getY()); + targetPNtopleft = p; + + //しかし,選択範囲の赤枠はカメラにつける + cmp = e.getPositionRelativeTo(viewer.getCanvas().getCamera()); + selection = new PPath(); + selection.setPathToRectangle((float) cmp.getX(), (float) cmp.getY(), 0, 0); + selection.setStrokePaint(Color.red);//赤 + selection.setPaint(null); + selection.setStroke(strokes[0]); + viewer.getCanvas().getCamera().addChild(selection); + } + } else { + targetPN = null; + } +// tempSelect.clear(); + viewer.setShowToolTip(false); + + } + + public void drag(PInputEvent e) { + super.drag(e); + + if (targetPN != null){ + // 選択範囲の更新 + cp = e.getPositionRelativeTo(viewer.getCanvas().getCamera()); + Rectangle2D selectionViewRect = new Rectangle2D.Double(cmp.getX(),cmp.getY(),0,0); + selectionViewRect.add(cp); + selectionViewRect.add(cmp); +// float cp_cmp_x = (float)(cp.getX() - cmp.getX()); +// float cp_cmp_y = (float)(cp.getY() - cmp.getY()); +// selection.setPathToRectangle((float) cmp.getX(), (float) cmp.getY(), cp_cmp_x, cp_cmp_y); + selection.setPathTo(selectionViewRect); + + // 選択対象物(Selectable)を検索 + Point2D p = e.getPositionRelativeTo(e.getPickedNode()); + if (targetPNorigin != null) p.setLocation(p.getX()+targetPNorigin.getX(),p.getY()+targetPNorigin.getY()); + Rectangle2D layerb = new PBounds(); + layerb.add(targetPNtopleft); + layerb.add(p); + +// ノート上のShortStroke ノートに絞って探索 +// if (e.getPickedNode().getAttribute("info") != null){ +// String attr = (String)e.getPickedNode().getAttribute("info"); +// if (attr.startsWith("noteCams")){ +// PNode d = (PNode) e.getPickedNode().getAttribute("drawTarget"); + Collection col = targetPN.getAllNodes(); + for(Object o:col){ + PNode pn = (PNode)o; + if (pn instanceof Selectable){ +// if (layerb.contains(pn.getGlobalBounds())){ //完全に含まれるとき選択 + Rectangle2D pngb = pn.getBounds(); // Label はoffsetで動いているので,Boundsでは比較できない +// System.out.println("original BB" + pngb.toString()); +// System.out.println("original AT" + pn.getTransform().toString()); + pn.getTransform().transform(pngb, pngb); +// System.out.println("modified BB" + pngb.toString()); + if (layerb.intersects(pngb)){ //少しでも重なれば選択 + ((Selectable)pn).setSelected(true, tempSelect); +// if (!tempSelect.contains((Selectable)pn)) tempSelect.add((Selectable)pn); + pn.repaint(); + } + } + } +// } +// } +// } + +//// ドラッグ開始した,Daishi上のLabelのみに絞って探索 +// if (e.getPickedNode().getAttribute("info") != null){ +// String attr = (String)e.getPickedNode().getAttribute("info"); +// if (attr.startsWith("Daishi")){ +// Daishi d = (Daishi) e.getPickedNode(); +// for(PPath cd: d.childDaishies){ +// Collection col = cd.getAllNodes(); +// for(Object o:col){ +// PNode pn = (PNode)o; +//// if (layerb.contains(pn.getGlobalBounds())){ //完全に含まれるとき選択 +// if (layerb.intersects(pn.getBounds())){ //少しでも重なれば選択 +// if (pn instanceof Selectable){ +// ((Selectable)pn).setSelected(true, tempSelect); +//// if (!tempSelect.contains((Selectable)pn)) tempSelect.add((Selectable)pn); +// pn.repaint(); +// } +// } +// } +// } +// } +// } + ArrayList tempSelect4Check = new ArrayList(tempSelect); + for(Selectable sl : tempSelect4Check){ + PNode pn = (PNode) sl; + Rectangle2D pngb = pn.getBounds(); + pn.getTransform().transform(pngb, pngb); +// if (!layerb.contains(((PNode)sl).getGlobalBounds())){ //完全に含まれるとき選択 + if (!layerb.intersects(pngb)){ //少しでも重なれば選択 + sl.setSelected(false,tempSelect); + } + } + + // 右下にドラッグしているときの,青い点線矩形の点線パターンを変化させる + float origStrokeNum = strokeNum; + strokeNum = (strokeNum + 0.3f) % NUM_STROKES; + if ((int) strokeNum != (int) origStrokeNum) { + selection.setStroke(strokes[(int) strokeNum]); + } + } + dragCount++; + +// // 選択範囲に完全に含まれるSelectableがあれば選択する//カメラビュー中心主義 +// PAffineTransform at = viewer.getCanvas().getCamera().getViewTransform(); +// Rectangle2D globalb = selection.getGlobalBounds(); +// Rectangle2D layerb = new Rectangle2D.Double(); +// at.inverseTransform(globalb, layerb); //グローバルからカメラへ + + // 以前は全部探索 しかし,効率がわるい +// for(Student stu: viewer.buffer.id2stuHash.values()){ +// for(PPath d: stu.daishi.childDaishies){ +// Collection col = d.getAllNodes(); +// for(Object o:col){ +// PNode pn = (PNode)o; +//// if (layerb.contains(pn.getGlobalBounds())){ //完全に含まれるとき選択 +// if (layerb.intersects(pn.getGlobalBounds())){ //少しでも重なれば選択 +// if (pn instanceof Selectable){ +// ((Selectable)pn).setSelected(true); +// if (!tempSelect.contains((Selectable)pn)) tempSelect.add((Selectable)pn); +// pn.repaint(); +// } +// } +// } +// } +// } + } + + public void endDrag(PInputEvent e) { + super.endDrag(e); + cp = e.getPositionRelativeTo(viewer.getCanvas().getCamera()); + if (selection != null) selection.removeFromParent(); + selection = null; + + if (selectTarget != null && dragCount < 3){ + if (selectTarget.getBounds().contains(e.getPositionRelativeTo(selectTarget))){//離したときもラベルの上なら + ((Selectable)selectTarget).toggleSelected(tempSelect); //選択をトグルする +// System.out.println("Toggle"); + } + selectTarget = null; + } + +// tempSelect.clear(); + viewer.setShowToolTip(true); + +// if (cmp.getX() < cp.getX() && cmp.getY() < cp.getY()) { +// // カメラ座標から,グローバル(パネル)座標への変換 +// PAffineTransform at = viewer.getCanvas().getCamera().getViewTransform(); +// Rectangle2D globalb = selection.getGlobalBounds(); +// Rectangle2D layerb = new Rectangle2D.Double(); +// at.inverseTransform(globalb, layerb); +// viewer.getCanvas().getCamera().animateViewToCenterBounds(layerb, true, 1000); +// } + } + + public void removeSelected() { + trash.clear(); + for(Selectable sel: tempSelect){ + if (sel.isSelected()) sel.removeLabel(trash); + } + tempSelect.clear(); + undoExecuted = false; + viewer.canvas.cam.repaint(); + } +// public void undoRemoveSelected(){ +// if (trash.size() == 0){ +// System.out.println("No Undoable Items."); +// return; +// } +// if (!undoExecuted){ +// for(PNode pn: trash.keySet()){ +// PNode parent = trash.get(pn); +// ((Historical)pn).addWithHist(parent); +// tempSelect.add((Selectable)pn); +// } +// undoExecuted = true; +// } else { +// for(PNode pn: trash.keySet()){ +// ((Historical)pn).removeWithHist(); +// } +// undoExecuted = false; +// tempSelect.clear(); +// } +// viewer.canvas.cam.repaint(); +// } + + public void toFrontSelected() { + for(Selectable sel : tempSelect){ + PNode pn = (PNode) sel; + PNode parentnode = pn.getParent(); + parentnode.addChild(pn); + } + } + + //選択解除 + public void DeSelect() { + for(Selectable sel : tempSelect){ + sel.setSelected(false, null); + } + tempSelect.clear(); + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/CoVisWindow_ZoomRegionHandler.java b/anchorgarden/src/main/java/jaist/css/covis/CoVisWindow_ZoomRegionHandler.java new file mode 100644 index 0000000..eb03f93 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/CoVisWindow_ZoomRegionHandler.java @@ -0,0 +1,122 @@ +package jaist.css.covis; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Stroke; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; + +import edu.umd.cs.piccolo.PCamera; +import edu.umd.cs.piccolo.PNode; +import edu.umd.cs.piccolo.event.PDragSequenceEventHandler; +import edu.umd.cs.piccolo.event.PInputEvent; +import edu.umd.cs.piccolo.nodes.PPath; +import edu.umd.cs.piccolo.util.PAffineTransform; +import edu.umd.cs.piccolo.util.PBounds; +import jaist.css.covis.util.BUtil; +import jaist.css.covis.util.FramePopup; + +/** + * ATNWindowで右ドラッグしながら青色のズーム範囲矩形を表示し,ズームする機能を実現するクラス + * @author miuramo + * + */ +public class CoVisWindow_ZoomRegionHandler extends PDragSequenceEventHandler { + AnchorGarden viewer; + + PPath selection; + + PNode target; + + private Stroke[] strokes = null; + + private float strokeNum = 0; + + private int dragCount = 0; + + final static int NUM_STROKES = 10; + + final static int DASH_WIDTH = 15; + + Point2D cmp; // ドラッグ開始座標 + + Point2D cp; //ドラッグ中の座標 + + Point2D max_ext_cp; // 左上方向(通常とは逆方向)一番遠くにドラッグしたときの座標 +// double dist_max_ext_cp; //そのときの距離 + PBounds initialBounds; //ドラッグ開始時の視野 + + public CoVisWindow_ZoomRegionHandler(AnchorGarden _viewer) { + this.viewer = _viewer; + + float[] dash = { DASH_WIDTH, DASH_WIDTH }; + strokes = new Stroke[NUM_STROKES]; + for (int i = 0; i < NUM_STROKES; i++) { + strokes[i] = new BasicStroke(2, BasicStroke.CAP_BUTT, + BasicStroke.JOIN_MITER, 1, dash, i); + } + } + + public void startDrag(PInputEvent e) { + super.startDrag(e); + target = e.getPickedNode(); + cmp = e.getPositionRelativeTo(viewer.getCanvas().getCamera()); + max_ext_cp = cmp; // 初期化 + selection = new PPath(); + selection.setPathToRectangle((float) cmp.getX(), (float) cmp.getY(), 0, + 0); + selection.setStrokePaint(Color.blue);//青色 + selection.setPaint(null); + selection.setStroke(strokes[0]); + viewer.getCanvas().getCamera().addChild(selection); + initialBounds = viewer.getCanvas().getCamera().getViewBounds(); + dragCount = 0; + } + + public void drag(PInputEvent e) { + super.drag(e); + dragCount++; + cp = e.getPositionRelativeTo(viewer.getCanvas().getCamera()); + float cp_cmp_x = (float)(cp.getX() - cmp.getX()); + float cp_cmp_y = (float)(cp.getY() - cmp.getY()); + + selection.setPathToRectangle((float) cmp.getX(), (float) cmp.getY(), + cp_cmp_x, cp_cmp_y); + + // 右下にドラッグしているときの,青い点線矩形の点線パターンを変化させる + float origStrokeNum = strokeNum; + strokeNum = (strokeNum + 0.3f) % NUM_STROKES; + if ((int) strokeNum != (int) origStrokeNum) { + selection.setStroke(strokes[(int) strokeNum]); + } + +// 左上方向(通常とは逆方向)一番遠くにドラッグしたときの処理 + if (cp_cmp_x < 0 || cp_cmp_y < 0){ + PCamera pc = viewer.getCanvas().getCamera(); + float f; + if (cp_cmp_x < 0) f = Math.abs((float)(viewer.getCanvas().getWidth()/(viewer.getCanvas().getWidth() - cp.distance(cmp)))); + else f = Math.abs((float)((viewer.getCanvas().getWidth() - cp.distance(cmp))/viewer.getCanvas().getWidth())); +// System.out.println("f "+f); + PBounds pb = BUtil.zoomBounds(initialBounds, f); + pc.animateViewToCenterBounds(pb, true, 0); + } + } + + public void endDrag(PInputEvent e) { + super.endDrag(e); + cp = e.getPositionRelativeTo(viewer.getCanvas().getCamera()); + if (dragCount < 6 && target.getAttribute("popupMenu") != null){ + FramePopup popup = (FramePopup) target.getAttribute("popupMenu"); + popup.showWithFrame(viewer.getCanvas(), (int) cp.getX(), (int) cp.getY(), viewer.frame); + } + selection.removeFromParent(); + if (cmp.getX() < cp.getX() && cmp.getY() < cp.getY()) { + // カメラ座標から,グローバル(パネル)座標への変換 + PAffineTransform at = viewer.getCanvas().getCamera().getViewTransform(); + Rectangle2D globalb = selection.getGlobalBounds(); + Rectangle2D layerb = new Rectangle2D.Double(); + at.inverseTransform(globalb, layerb); + viewer.getCanvas().getCamera().animateViewToCenterBounds(layerb, true, 1000); + } + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/CoversTransparencyControl.java b/anchorgarden/src/main/java/jaist/css/covis/CoversTransparencyControl.java new file mode 100644 index 0000000..0d8bc06 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/CoversTransparencyControl.java @@ -0,0 +1,58 @@ +package jaist.css.covis; + +import java.util.ArrayList; + +import edu.umd.cs.piccolo.PNode; + +public class CoversTransparencyControl implements Runnable { + Thread transparencyThread = null; + ArrayList effectAry; //ダイナミックに作成する?(計算コストを考え,ここではしない) + AnchorGarden window; + float target_transparency[] = new float[]{0.0f, 1.0f}; + float tick_transparency[] = new float[]{-0.035f, 0.05f}; + int direction = 0; + int msec; + float animcount = 20; + float currentValue = 1f; + boolean quitTransparencyThread = true; + public CoversTransparencyControl(AnchorGarden _win){ + window = _win; + + effectAry = new ArrayList(); + // ここに,影響をあたえるPNodeを追加する + + } + + void transparencyThread_Start(int direct){ + if (direct == direction) return; + direction = direct; +// System.out.println("direction changes to "+direction); + + if (transparencyThread == null){ + quitTransparencyThread = false; + transparencyThread = new Thread(this); + transparencyThread.start(); + } + } + public void run() { + while(!quitTransparencyThread){ + currentValue += tick_transparency[direction]; + if ((direction == 0 && currentValue < target_transparency[direction]) || + (direction == 1 && target_transparency[direction] < currentValue )) { + currentValue = target_transparency[direction]; + quitTransparencyThread = true; + } + for(PNode pn: effectAry){ + pn.setTransparency(currentValue); + } + window.canvas.repaint(); + try { + Thread.sleep(50); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + transparencyThread = null; +// System.out.println("Thread exit"); + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/JLabelW.java b/anchorgarden/src/main/java/jaist/css/covis/JLabelW.java new file mode 100644 index 0000000..c985226 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/JLabelW.java @@ -0,0 +1,21 @@ +package jaist.css.covis; + +import java.awt.Font; + +import javax.swing.JLabel; + +public class JLabelW extends JLabel { + /** + * + */ + private static final long serialVersionUID = -4720296888345083391L; + public static Font sans14 = new Font("sansserif", Font.BOLD, 14); + public static Font sans22 = new Font("sansserif", Font.BOLD, 22); + public static Font sans30 = new Font("sansserif", Font.BOLD, 30); + + public JLabelW(String s){ + super(s,JLabel.CENTER); + setFont(sans22); + } + +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/JLabelWL.java b/anchorgarden/src/main/java/jaist/css/covis/JLabelWL.java new file mode 100644 index 0000000..530bce1 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/JLabelWL.java @@ -0,0 +1,21 @@ +package jaist.css.covis; + +import java.awt.Font; + +import javax.swing.JLabel; + +public class JLabelWL extends JLabel { + /** + * + */ + private static final long serialVersionUID = -4720296888345083391L; + public static Font sans14 = new Font("sansserif", Font.BOLD, 14); + public static Font sans22 = new Font("sansserif", Font.BOLD, 22); + public static Font sans30 = new Font("sansserif", Font.BOLD, 30); + + public JLabelWL(String s){ + super(s,JLabel.LEFT); + setFont(sans22); + } + +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/JTableStripeRenderer.java b/anchorgarden/src/main/java/jaist/css/covis/JTableStripeRenderer.java new file mode 100644 index 0000000..1b42221 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/JTableStripeRenderer.java @@ -0,0 +1,36 @@ +package jaist.css.covis; + +import java.awt.Color; +import java.awt.Component; + +import javax.swing.BorderFactory; +import javax.swing.JTable; +import javax.swing.table.DefaultTableCellRenderer; + +//http://terai.xrea.jp/Swing/StripeTable.html +public class JTableStripeRenderer extends DefaultTableCellRenderer { + + private static final long serialVersionUID = 5385937199280359421L; + private static final Color ec = new Color(240, 240, 255); + public JTableStripeRenderer() { + super(); + setOpaque(true); + setBorder(BorderFactory.createEmptyBorder(0,5,0,5)); + } + public Component getTableCellRendererComponent( + JTable table, Object value, + boolean isSelected, boolean hasFocus, + int row, int column) { + super.getTableCellRendererComponent(table, value, + isSelected, hasFocus, row, column); + if(isSelected) { + setForeground(table.getSelectionForeground()); + setBackground(table.getSelectionBackground()); + }else{ + setForeground(table.getForeground()); + setBackground((row%2==0)?ec:table.getBackground()); + } + setHorizontalAlignment((value instanceof Number)?RIGHT:LEFT); + return this; + } +} \ No newline at end of file diff --git a/anchorgarden/src/main/java/jaist/css/covis/JTextAreaToggleAntiAlias.java b/anchorgarden/src/main/java/jaist/css/covis/JTextAreaToggleAntiAlias.java new file mode 100644 index 0000000..6c03f11 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/JTextAreaToggleAntiAlias.java @@ -0,0 +1,94 @@ +package jaist.css.covis; + +import java.awt.Font; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; + +import javax.swing.JTextArea; + +public class JTextAreaToggleAntiAlias extends JTextArea implements MouseListener{ + + private static final long serialVersionUID = -8299619738797635210L; + private boolean aaOn; + Font font; + +// private HighlightedDocument document = new HighlightedDocument(); + public JTextAreaToggleAntiAlias(){ +// setDocument(document); + setAntiAlias(true); +// document.setHighlightStyle(HighlightedDocument.JAVA_STYLE); + + addMouseListener(this); + } + public JTextAreaToggleAntiAlias(int w, int h){ + this(); + } + public JTextAreaToggleAntiAlias(String s){ + this(); + setText(s); + } + public void setFont(Font f){ + font = f; + super.setFont(f); + repaint(); + } + public void setFontSize(int s){ + Font f = new Font(font.getName(), font.getStyle(), s); + setFont(f); + } + public void setFontSizePlus(int s){ + Font f = new Font(font.getName(), font.getStyle(), font.getSize()+s); + setFont(f); + } + public void setAntiAlias(boolean aaOn) + { + this.aaOn = aaOn; + } + + public void paintComponent(Graphics g) + { + if (aaOn) + { + ((Graphics2D) g).addRenderingHints(new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON)); + } + else + { + ((Graphics2D) g).addRenderingHints(new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF)); + } + super.paintComponent(g); + } + @Override + public void mouseClicked(MouseEvent e) { + // TODO Auto-generated method stub + + } + @Override + public void mousePressed(MouseEvent e) { + if (e.isControlDown()){ + if (e.getButton()==MouseEvent.BUTTON1){ + setFontSizePlus(-2); + } else { + setFontSizePlus(2); + } + } + + } + @Override + public void mouseReleased(MouseEvent e) { + // TODO Auto-generated method stub + + } + @Override + public void mouseEntered(MouseEvent e) { + // TODO Auto-generated method stub + + } + @Override + public void mouseExited(MouseEvent e) { + // TODO Auto-generated method stub + + } +}; diff --git a/anchorgarden/src/main/java/jaist/css/covis/MyPPanEventHandler.java b/anchorgarden/src/main/java/jaist/css/covis/MyPPanEventHandler.java new file mode 100644 index 0000000..b0977a1 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/MyPPanEventHandler.java @@ -0,0 +1,22 @@ +package jaist.css.covis; + +import edu.umd.cs.piccolo.event.PDragSequenceEventHandler; +import edu.umd.cs.piccolo.event.PInputEvent; +import edu.umd.cs.piccolo.util.PDimension; + +/** + * ATNWindow右上メニューの[pan] + * @author miuramo + * + */ +public class MyPPanEventHandler extends PDragSequenceEventHandler { + AnchorGarden window; + + public MyPPanEventHandler(AnchorGarden _window){ + window = _window; + } + public void drag(PInputEvent e) { + PDimension d = e.getDelta(); + window.canvas.getCamera().translateView(d.getWidth(), d.getHeight()); + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/PPickEventHandler.java b/anchorgarden/src/main/java/jaist/css/covis/PPickEventHandler.java new file mode 100644 index 0000000..79e9756 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/PPickEventHandler.java @@ -0,0 +1,86 @@ +package jaist.css.covis; + +import java.util.ArrayList; + +import edu.umd.cs.piccolo.PNode; +import edu.umd.cs.piccolo.event.PDragSequenceEventHandler; +import edu.umd.cs.piccolo.event.PInputEvent; +import edu.umd.cs.piccolo.util.PDimension; + +/** + * ATNWindow右上メニューの[pick] + * @author miuramo + * + */ +public class PPickEventHandler extends PDragSequenceEventHandler { + AnchorGarden window; + + long lastRelease; //ダブルクリック判定用 + + public PPickEventHandler(AnchorGarden _window){ + window = _window; + } + + PNode targetPN; // ターゲット + +// public void mousePressed(PInputEvent e){ +// super.mousePressed(e); +// if (e.getPickedNode().getAttribute("info")!=null){ +// System.out.println(e.getPickedNode().getAttribute("info")); +// } +// } + public void startDrag(PInputEvent e){ + super.startDrag(e); + if (e.getPickedNode() instanceof PNode && (e.getPickedNode().getAttribute("moveTarget")!=null)){ + targetPN = (PNode) e.getPickedNode().getAttribute("moveTarget"); + } else { + targetPN = null; + } + } + + public void drag(PInputEvent e){ + super.drag(e); + if (targetPN != null){ + PDimension d = e.getDeltaRelativeTo(window.canvas.getLayer()); + targetPN.translate(d.getWidth(), d.getHeight()); + targetPN.moveToFront(); + + if (targetPN instanceof Selectable){ + Selectable sel = (Selectable)targetPN; + if (sel.isSelected()){ + //選択されたほかのSelectableも一緒に動かしてあげたい.ただし,子ラベルは既に動かしているので除く + ArrayList synchroMoveNodes = new ArrayList(); + synchroMoveNodes.addAll(window.flowmenuEventHandler.selectionHandler.tempSelect); + synchroMoveNodes.remove(sel); + for(Selectable s: sel.getAllChildren()){ + synchroMoveNodes.remove(s); + } +// for(Selectable s: synchroMoveNodes){ +// ((Historical)s).moveWithHist(d.getWidth(), d.getHeight()); +// } + } + } + } else { + PDimension d = e.getDelta(); + window.canvas.getCamera().translateView(d.getWidth(), d.getHeight()); + } + } + + public void endDrag(PInputEvent e){ + super.endDrag(e); + +// if (System.currentTimeMillis() - lastRelease < 350){ //ダブルクリック判定 dbl +// if (targetPN != null){ +// PBounds pb = targetPN.getGlobalFullBounds(); +// pb = BUtil.zoomBounds(pb, 1.05); +// window.canvas.getCamera().animateViewToCenterBounds(pb, true, 500); +// +//// if (targetPN instanceof Student){ +//// ((Student)targetPN).createNewLabel(); +//// } +// } +// } + targetPN = null; + lastRelease = System.currentTimeMillis(); + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/PopupListener.java b/anchorgarden/src/main/java/jaist/css/covis/PopupListener.java new file mode 100644 index 0000000..a23ab5b --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/PopupListener.java @@ -0,0 +1,43 @@ +package jaist.css.covis; + +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +import javax.swing.JPopupMenu; + +/** + * ポップアップメニュー起動用のイベントリスナ + * + * ControlPanelの出番が減ったため,未使用 + * @author miuramo + * + */ +@Deprecated +public class PopupListener extends MouseAdapter { + JPopupMenu popup_withshift; + + JPopupMenu popup_normal; + + public PopupListener(JPopupMenu p_shift, JPopupMenu p_normal) { + popup_withshift = p_shift; + popup_normal = p_normal; + } + + public void mousePressed(MouseEvent e) { + maybeShowPopup(e); + } + + public void mouseReleased(MouseEvent e) { + maybeShowPopup(e); + } + + private void maybeShowPopup(MouseEvent e) { + if (e.isPopupTrigger()) { + if (e.isShiftDown()) { + popup_withshift.show(e.getComponent(), e.getX(), e.getY()); + } else { + popup_normal.show(e.getComponent(), e.getX(), e.getY()); + } + } + } +} \ No newline at end of file diff --git a/anchorgarden/src/main/java/jaist/css/covis/ProgressBar.java b/anchorgarden/src/main/java/jaist/css/covis/ProgressBar.java new file mode 100644 index 0000000..480cb1b --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/ProgressBar.java @@ -0,0 +1,139 @@ +package jaist.css.covis; + +import java.awt.BorderLayout; +import java.awt.Cursor; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.lang.reflect.Method; + +import javax.swing.BorderFactory; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JProgressBar; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.Timer; + +/** + * 時間がかかるタスクのためのプログレスバー + * @see DBReadTask + * @see FileReadTask + * + */ +@SuppressWarnings("serial") +public class ProgressBar extends JPanel { + public final static int ONE_SECOND = 1300; + + private JProgressBar progressBar; + + private Timer timer; + + // private JButton startButton; + private ProgressibleTask task; + + private JTextArea taskOutput; + + private String newline = "\n"; + + private Object targetobj; + + private Method aftercall; + + private JFrame parent; + + public ProgressBar(ProgressibleTask thetask, Object obj, Method ac, JFrame p) { + super(new BorderLayout()); + targetobj = obj; + aftercall = ac; + parent = p; + task = thetask; + + progressBar = new JProgressBar(0, task.getLengthOfTask()); + progressBar.setValue(0); + progressBar.setStringPainted(true); + + taskOutput = new JTextArea(5, 20); + taskOutput.setMargin(new Insets(5, 5, 5, 5)); + taskOutput.setEditable(false); + taskOutput.setCursor(null); + // inherit the panel's cursor + // see bug 4851758 + + // add(panel, BorderLayout.PAGE_START); + add(progressBar, BorderLayout.NORTH); + add(new JScrollPane(taskOutput), BorderLayout.SOUTH); + setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); + + // Create a timer. + timer = new Timer(ONE_SECOND, new ActionListener() { + public void actionPerformed(ActionEvent evt) { + progressBar.setValue(task.getCurrent()); + String s = task.getMessage(); + if (s != null) { + taskOutput.append(s + newline); + taskOutput.setCaretPosition(taskOutput.getDocument() + .getLength()); + } + if (task.isDone()) { + // Toolkit.getDefaultToolkit().beep(); + timer.stop(); + // startButton.setEnabled(true); + setCursor(null); // turn off the wait cursor + // progressBar.setValue(progressBar.getMinimum()); + /* + * snaillogloader.frame.dispose(); + * snaillogloader.startSnailViewer(); snaillogloader.frame = + * null; + */ + parent.dispose(); + parent = null; + + // 登録された後処理メソッドがあれば実行. + if (aftercall == null) + return; + try { + @SuppressWarnings("rawtypes") + Class[] params = {}; + @SuppressWarnings("unused") + Object ret = aftercall.invoke(targetobj, + (Object[]) params); + } catch (Exception ex) { + } + } + } + }); + } + + /** + * Called when the user presses the playB button. + */ + public void actionPerformed(ActionEvent evt) { + // startButton.setEnabled(false); + setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + task.go(); + timer.start(); + } + + /** + * Create the GUI and show it. For thread safety, this method should be + * invoked from the event-dispatching thread. private static void + * createAndShowGUI() { //Make sure we have nice window decorations. + * JFrame.setDefaultLookAndFeelDecorated(true); + * + * //Create and set up the window. JFrame frame = new + * JFrame("ProgressBarDemo"); + * frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + * + * //Create and set up the content pane. JComponent newContentPane = new + * ProgressBar(null); newContentPane.setOpaque(true); //content panes must + * be opaque frame.setContentPane(newContentPane); + * + * //Display the window. frame.pack(); frame.setVisible(true); } + * + * public static void main(String[] args) { //Schedule a job for the + * event-dispatching thread: //creating and showing this application's GUI. + * javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { + * createAndShowGUI(); } }); } + */ +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/ProgressibleTask.java b/anchorgarden/src/main/java/jaist/css/covis/ProgressibleTask.java new file mode 100644 index 0000000..262a945 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/ProgressibleTask.java @@ -0,0 +1,39 @@ +package jaist.css.covis; + +/** + * 時間がかかるタスクのためのインタフェース + * @see DBReadTask + * @see FileReadTask + * + */ +public interface ProgressibleTask { + + /** + * Called from ProgressBarDemo to playB the task. + */ + public abstract void go(); + + /** + * Called from ProgressBarDemo to find out how much work needs to be done. + */ + public abstract int getLengthOfTask(); + + /** + * Called from ProgressBarDemo to find out how much has been done. + */ + public abstract int getCurrent(); + + public abstract void stop(); + + /** + * Called from ProgressBarDemo to find out if the task has completed. + */ + public abstract boolean isDone(); + + /** + * Returns the most recent status message, or null if there is no current + * status message. + */ + public abstract String getMessage(); + +} \ No newline at end of file diff --git a/anchorgarden/src/main/java/jaist/css/covis/RootBuffer.java b/anchorgarden/src/main/java/jaist/css/covis/RootBuffer.java new file mode 100644 index 0000000..6e5d1fb --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/RootBuffer.java @@ -0,0 +1,86 @@ +package jaist.css.covis; + +import java.util.ArrayList; +import java.util.HashSet; + +import edu.umd.cs.piccolo.PCamera; +import edu.umd.cs.piccolo.PLayer; +import edu.umd.cs.piccolo.PRoot; + +/** + * ATNBuffer(バッファ)のスーパークラス.画面表示モデルのルート(root), および表示レイヤ(layer)を持つ. + * + * + */ +public class RootBuffer { + public static ArrayList buffers = new ArrayList(); + + /** + * このBufferを表示中のウィンドウリスト + */ + public HashSet showingWindows; + public PRoot root; + public PLayer layer; + public String name; + public static String bufferName = "World"; + static int bufferid; + boolean hasModifiedUnsaved; + public RootBuffer(){ + root = new PRoot(); + layer = new PLayer(); + root.addChild(layer); + + name = bufferName+" "+String.valueOf(RootBuffer.bufferid); + RootBuffer.bufferid++; + buffers.add((CoVisBuffer)this); +// PText test = new PText(name); +// layer.addChild(test); +// test.offset(-200, -200); + RootBuffer.updateAllBufferMenu(); + } + public void addCamera(PCamera cam){ + root.addChild(cam); + cam.addLayer(layer); + } + public void delete(){ + buffers.remove(this); + RootBuffer.updateAllBufferMenu(); + } + public static void updateAllBufferMenu(){ + for(RootWindow pw: RootWindow.windows){ + pw.updateBufferMenu(); + } + } + public static CoVisBuffer find(String s){ + for(CoVisBuffer b: buffers){ + if (b.name.equals(s)) return b; + } + return null; + } + + public void addShowingWindow(AnchorGarden w){ + if (showingWindows == null) showingWindows = new HashSet(); + showingWindows.add(w); + } + public void removeShowingWindow(AnchorGarden w){ + if (showingWindows == null) showingWindows = new HashSet(); + showingWindows.remove(w); +// if(showingWindows.size()==0){ // もし、参照するウィンドウが0になったら +// ((ATNBuffer)this).updateContAction.setSelected(false); //DB連続更新を切る +// } +// ここでupdateContActionのプロパティを変更するのではなく、実際の更新箇所でウィンドウ数をチェックする。 + //    ほうが便利(頻繁に繰り返し切り替えることがあるかもしれないので)DBUpdateContinuousThread.runでチェック。 + } + public void repaint(){ + for(AnchorGarden w:showingWindows){ + w.canvas.repaint(); + } + } + public AnchorGarden getWindow(){ + if (showingWindows == null) return null; + for(AnchorGarden w:showingWindows){ + return w; // どれでもいいから返す + } + return null; + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/RootWindow.java b/anchorgarden/src/main/java/jaist/css/covis/RootWindow.java new file mode 100644 index 0000000..8f9f4b9 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/RootWindow.java @@ -0,0 +1,626 @@ +package jaist.css.covis; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.Toolkit; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ComponentEvent; +import java.awt.event.ComponentListener; +import java.awt.event.InputEvent; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.WindowEvent; +import java.awt.event.WindowListener; +import java.awt.event.WindowStateListener; +import java.util.ArrayList; + +import javax.swing.JCheckBoxMenuItem; +import javax.swing.JFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; + +import edu.umd.cs.piccolo.PCamera; +import edu.umd.cs.piccolo.event.PInputEventFilter; +import edu.umd.cs.piccolo.util.PBounds; +import jaist.css.covis.cls.ClassFieldMenu; +import jaist.css.covis.util.MyPCanvas; +import jaist.css.covis.util.MyPFrame; + +/** + * ATNWindow のスーパークラス.フレーム(MyPFrame),キャンバス(MyPCanvas)を持つ. + * ちなみに,カメラはキャンバスがデフォルトで1つ備えている. + * + * ATNBufferを関連付けて表示するには,ATNRootBufferのaddCamera(PCamera)を呼び出す. + * この処理は switchBuffer() で行っている. + * + * @author miuramo + * + */ +public class RootWindow implements ActionListener, WindowStateListener { + public static ArrayList windows = new ArrayList(); + + public PInputEventFilter b1mask = new PInputEventFilter(InputEvent.BUTTON1_DOWN_MASK); + + public PInputEventFilter b2mask = new PInputEventFilter(InputEvent.BUTTON2_DOWN_MASK); + + public PInputEventFilter b3mask = new PInputEventFilter(InputEvent.BUTTON3_DOWN_MASK); + + public PInputEventFilter disablemask = new PInputEventFilter(0); + + public MyPFrame frame; + public MyPCanvas canvas; + + public CoVisBuffer buffer; + public JMenuBar menuBar; + public JMenu fileMenu; + public JMenu extraMenu; + public JMenu windowMenu; + public JMenu bufferMenu; + + + public SrcWindow srcWindow; + + // あまり聞いてこないモード + public JCheckBoxMenuItem isAutoMode; + // あまり聞いてこないモード + public JCheckBoxMenuItem isAutoMode_obj; + //継承のクラスを表示するモード + public JCheckBoxMenuItem isAdvancedMode; + + + // public JCheckBoxMenuItem updateMenu; + + public static int windowid; + + public RootWindow(){ + CoVisBuffer b = new CoVisBuffer(); + constructFrame(); + switchBuffer(b); + frame.setVisible(true); + } + public RootWindow(CoVisBuffer b){ + buffer = b; + constructFrame(); + switchBuffer(b); + frame.setSize(b.covisProperty.viewsizex,b.covisProperty.viewsizey); + frame.setLocation(b.covisProperty.viewlocx, b.covisProperty.viewlocy); + frame.validate(); + frame.addWindowStateListener(this); + frame.setVisible(true); + + RootWindow.this.showSrcWin(true); // TODO:段階がすすんだら,起動時に見せるようにする + } + public void constructFrame(){ + frame = new MyPFrame(AnchorGarden.WINDOWTITLE+" "+String.valueOf(windowid), false, null); + RootWindow.windowid++; + windows.add(this); + + frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + frame.addWindowListener(new WindowListener(){ + public void windowOpened(WindowEvent arg0) { + // System.out.println("open"); + // RootWindow.this.showSrcWin(true); // TODO:段階がすすんだら,起動時に見せるようにする + } + public void windowClosing(WindowEvent arg0) { + tobeclosed(); + } + public void windowClosed(WindowEvent arg0) {} + public void windowIconified(WindowEvent arg0) { + if (srcWindow != null){ + srcWindow.setState(JFrame.ICONIFIED); + } + } + public void windowDeiconified(WindowEvent arg0) { + if (srcWindow != null){ + // srcWindow.setVisible(true); + srcWindow.setState(JFrame.NORMAL); + srcWindow.follow(); + } + } + public void windowActivated(WindowEvent arg0) { + if (srcWindow != null && srcWindow.getState()!=JFrame.ICONIFIED){ + // srcWindow.setVisible(true); + srcWindow.setState(JFrame.NORMAL); + srcWindow.follow(); + } + } + public void windowDeactivated(WindowEvent arg0) { + } + }); + frame.addComponentListener(new ComponentListener(){ + @Override + public void componentHidden(ComponentEvent arg0) { } + @Override + public void componentMoved(ComponentEvent arg0) { + if (srcWindow != null && srcWindow.getState()!=JFrame.ICONIFIED){ + srcWindow.follow(); + } + } + @Override + public void componentResized(ComponentEvent arg0) { + if (srcWindow != null && srcWindow.getState()!=JFrame.ICONIFIED){ + srcWindow.follow(); + } + } + @Override + public void componentShown(ComponentEvent arg0) { } + }); + + initializeMenu(); + } + protected void initializeMenu(){ + menuBar = new JMenuBar(); + fileMenu = new JMenu("File"); + menuBar.add(fileMenu); + + JMenuItem resetWorld = new JMenuItem("Reset World"); + resetWorld.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent arg0) { + resetWorld(); + } + }); + fileMenu.add(resetWorld); + + + JMenuItem newBuffer = new JMenuItem("new "+RootBuffer.bufferName); + newBuffer.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent arg0) { + newBuffer(); + } + }); + fileMenu.add(newBuffer); + + JMenuItem newFrame = new JMenuItem("new Window"); + newFrame.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent arg0) { + newFrame(); + } + }); + fileMenu.add(newFrame); + + fileMenu.addSeparator(); + + // JMenuItem printpreview = new JMenuItem("Print Preview (Portlait)"); + // printpreview.addActionListener(new ActionListener(){ + // public void actionPerformed(ActionEvent arg0) { + //// canvas.setPreferredSize(new Dimension(584,816)); + // frame.setSize(592,876); + // frame.validate(); + // } + // }); + // fileMenu.add(printpreview); + + JMenuItem printpreview2 = new JMenuItem("Print Preview (Landscape)"); + printpreview2.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent arg0) { + // canvas.setPreferredSize(new Dimension(584,816)); + frame.setSize(876,592); + frame.validate(); + } + }); + fileMenu.add(printpreview2); + + // JMenuItem printpreview3 = new JMenuItem("set preview frame (A0 Landscape)"); + // printpreview3.addActionListener(new ActionListener(){ + // public void actionPerformed(ActionEvent arg0) { + //// canvas.setPreferredSize(new Dimension(584,816)); + // frame.setSize(3370+10,2384+60); + // frame.validate(); + // } + // }); + // fileMenu.add(printpreview3); + +// JMenuItem print = new JMenuItem("Print"); +// print.addActionListener(new ActionListener(){ +// public void actionPerformed(ActionEvent arg0) { +//// PrintPrintable.print(canvas.cam); +// } +// }); +// fileMenu.add(print); + +// JMenuItem printPDF = new JMenuItem("PDF Print"); +// printPDF.addActionListener(new ActionListener(){ +// public void actionPerformed(ActionEvent e){ +// // lastGraphView.display.setHighQuality(true); +// ((AnchorGarden)RootWindow.this).pmenubar.mybar.setVisible(false); +// printPDF(canvas, "A4L", "ag2.pdf"); +// openPDF("ag2.pdf"); +// ((AnchorGarden)RootWindow.this).pmenubar.mybar.setVisible(true); +// } +// +// }); +// fileMenu.add(printPDF); + + + JMenuItem exit = new JMenuItem("Exit"); + exit.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent arg0) { + if (JOptionPane.showConfirmDialog(RootWindow.this.frame, "本当に全部終了してよろしいですか?", "確認", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION){ + System.exit(0); + } + } + }); + fileMenu.add(exit); + + windowMenu = new JMenu("Window"); + + JMenuItem fit = new JMenuItem("Fit"); + fit.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent arg0) { + canvas.cam.animateViewToCenterBounds( + buffer.layer.getUnionOfChildrenBounds(new PBounds()), + true, 1000); + } + }); + windowMenu.add(fit); + + final JCheckBoxMenuItem full = new JCheckBoxMenuItem("Full Screen"); + full.addItemListener(new ItemListener(){ + public void itemStateChanged(ItemEvent arg0) { + frame.setFullScreenMode(full.isSelected()); + } + }); + windowMenu.add(full); + + extraMenu = new JMenu("Extra"); + menuBar.add(extraMenu); + + + isAutoMode = new JCheckBoxMenuItem("Automatic Variable Name"); + isAutoMode.addItemListener(new ItemListener(){ + public void itemStateChanged(ItemEvent arg0){ + } + }); + isAutoMode.setSelected(true); + // isAutoMode.setSelected(false); + extraMenu.add(isAutoMode); + + + isAutoMode_obj = new JCheckBoxMenuItem("Automatic Constructor"); + isAutoMode_obj.addItemListener(new ItemListener(){ + public void itemStateChanged(ItemEvent arg0){ + } + }); + isAutoMode_obj.setSelected(true); + // isAutoMode.setSelected(false); + extraMenu.add(isAutoMode_obj); + + final JMenuItem srcWin = new JMenuItem("Source Code"); + srcWin.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent arg0) { + showSrcWin(true); + } + }); + extraMenu.add(srcWin); + + extraMenu.addSeparator(); + + JMenuItem[] modeMI = new JMenuItem[ClassFieldMenu.modes.length]; + for(int i=0;i paperSizeHash = new Hashtable(); +// paperSizeHash.put("A0L", PageSize.A0.rotate()); +// paperSizeHash.put("A1L", PageSize.A1.rotate()); +// paperSizeHash.put("A2L", PageSize.A2.rotate()); +// paperSizeHash.put("A3L", PageSize.A3.rotate()); +// paperSizeHash.put("A4L", PageSize.A4.rotate()); +// paperSizeHash.put("A0P", PageSize.A0); +// paperSizeHash.put("A1P", PageSize.A1); +// paperSizeHash.put("A2P", PageSize.A2); +// paperSizeHash.put("A3P", PageSize.A3); +// paperSizeHash.put("A4P", PageSize.A4); +// paperSizeHash.put("A0", PageSize.A0); +// paperSizeHash.put("A1", PageSize.A1); +// paperSizeHash.put("A2", PageSize.A2); +// paperSizeHash.put("A3", PageSize.A3); +// paperSizeHash.put("A4", PageSize.A4); +// +// Document document = new Document(new Rectangle(0,0,canvas.getWidth(),canvas.getHeight()), 0, 0, 0, 0); +// System.out.println("f "+frame.getWidth()+" "+frame.getHeight()); +// System.out.println("c "+canvas.getWidth()+" "+canvas.getHeight()); +// // Document document = new Document(new Rectangle(0,0,frame.getWidth()-16,frame.getHeight()-60), 0, 0, 0, 0); +// // step 2: creation of the writer +// PdfWriter writer = null; +// try { +// writer = PdfWriter.getInstance(document, new FileOutputStream(outfilename)); +// // writer.setPdfVersion(PdfWriter.VERSION_1_7); +// } catch (FileNotFoundException e) { +// e.printStackTrace(); +// } catch (DocumentException e) { +// e.printStackTrace(); +// } +// +// // step 3: we open the document +// document.open(); +// +// // step 4: we grab the ContentByte and do some stuff with it +// +// // we create a fontMapper and read all the fonts in the font directory +// DefaultFontMapper mapper = new DefaultFontMapper(); +// FontFactory.registerDirectories(); +// mapper.insertDirectory("c:\\windows\\fonts"); +// // we create a template and a Graphics2D object that corresponds with it +// PdfContentByte cb = writer.getDirectContent(); +// +// Graphics2D g2 = cb.createGraphicsShapes(canvas.getWidth(), canvas.getHeight()); +// +// // System.out.println(pagesizeString+" "+paperSizeHash.get(pagesizeString).getWidth()+" "+paperSizeHash.get(pagesizeString).getHeight()); +// // canvas.paintDisplay(g2, new Dimension(3000,2000)); +// canvas.paint(g2); +// +// g2.dispose(); +// +// // step 5: we close the document +// document.close(); +// } + +} + + diff --git a/anchorgarden/src/main/java/jaist/css/covis/Selectable.java b/anchorgarden/src/main/java/jaist/css/covis/Selectable.java new file mode 100644 index 0000000..80853c8 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/Selectable.java @@ -0,0 +1,16 @@ +package jaist.css.covis; + +import java.util.ArrayList; +import java.util.Hashtable; + +import edu.umd.cs.piccolo.PNode; + +public interface Selectable { + boolean isSelected(); + void setSelected(boolean f, ArrayList list); + void toggleSelected(ArrayList list); + void removeLabel(Hashtable trash); + void toFront(); + public ArrayList getAllChildren(); + public PNode theNode(); +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/SrcWindow.java b/anchorgarden/src/main/java/jaist/css/covis/SrcWindow.java new file mode 100644 index 0000000..a7b4589 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/SrcWindow.java @@ -0,0 +1,156 @@ +package jaist.css.covis; + +import jaist.css.covis.cls.Covis_BTree; +import jaist.css.covis.cls.Covis_Frac; + +import java.awt.BorderLayout; +import java.awt.Font; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import javax.swing.JCheckBoxMenuItem; +import javax.swing.JFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JScrollPane; +import javax.swing.JTabbedPane; +import javax.swing.JViewport; + +public class SrcWindow extends JFrame implements ActionListener { + // public static boolean doFollowMainWindow = true; + + private static final long serialVersionUID = 1526947556907544070L; + JTextAreaToggleAntiAlias jta; + JScrollPane scroll; + JButton process; + JButton loadNow; + CoVisBuffer buffer; + AnchorGarden window; + + public JCheckBoxMenuItem doFollowSrcWin;//ソースコードウィンドウを追従させる? + public JCheckBoxMenuItem doFollowSrcWinLeft;//ソースコードウィンドウを追従させる? + + JTabbedPane tab; + public static Font sans14 = new Font("sansserif", Font.BOLD, 14); + public static Font sans18 = new Font("sansserif", Font.BOLD, 18); + public static Font sans22 = new Font("sansserif", Font.BOLD, 22); + public static Font sans26 = new Font("sansserif", Font.BOLD, 26); + public static Font sans30 = new Font("sansserif", Font.BOLD, 30); + public static Font sans34 = new Font("sansserif", Font.BOLD, 34); + public static Font sans38 = new Font("sansserif", Font.BOLD, 38); + public static Font sans42 = new Font("sansserif", Font.BOLD, 42); + public static Font sans46 = new Font("sansserif", Font.BOLD, 46); + + public static Font code14 = new Font("sansserif", Font.PLAIN, 14); + // public static Font code14 = new Font("DialogInput", Font.BOLD, 14); + + public SrcWindow(CoVisBuffer buf, AnchorGarden win){ + super("Source Code Window"); + buffer = buf; + window = win; + + + setLayout(new BorderLayout()); + jta = new JTextAreaToggleAntiAlias(""); +// jta.setLineWrap(true); + scroll = new JScrollPane(jta); + + jta.setFont(sans22); + + + JMenuBar menuBar = new JMenuBar(); + JMenu fontM = new JMenu("FontSize"); + JMenuItem jmi = new JMenuItem("14"); + fontM.add(jmi); + jmi.addActionListener(this); + jmi = new JMenuItem("18"); + fontM.add(jmi); + jmi.addActionListener(this); + jmi = new JMenuItem("22"); + fontM.add(jmi); + jmi.addActionListener(this); + jmi = new JMenuItem("26"); + fontM.add(jmi); + jmi.addActionListener(this); + jmi = new JMenuItem("30"); + fontM.add(jmi); + jmi.addActionListener(this); + jmi = new JMenuItem("34"); + fontM.add(jmi); + jmi.addActionListener(this); + jmi = new JMenuItem("38"); + fontM.add(jmi); + jmi.addActionListener(this); + jmi = new JMenuItem("42"); + fontM.add(jmi); + jmi.addActionListener(this); + jmi = new JMenuItem("46"); + fontM.add(jmi); + jmi.addActionListener(this); + menuBar.add(fontM); + + JMenu windowMenu = new JMenu("Window"); + doFollowSrcWin = new JCheckBoxMenuItem("Snap to MainWindow"); + doFollowSrcWin.setSelected(true); + windowMenu.add(doFollowSrcWin); + menuBar.add(windowMenu); + + doFollowSrcWinLeft = new JCheckBoxMenuItem("Align to Left of MainWindow"); + doFollowSrcWinLeft.setSelected(true); + doFollowSrcWinLeft.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e){ + follow(); + } + }); + windowMenu.add(doFollowSrcWinLeft); + + + setJMenuBar(menuBar); + + tab = new JTabbedPane(); + tab.addTab("(operation code)", scroll); + JTextAreaToggleAntiAlias fracclass = new JTextAreaToggleAntiAlias(Covis_Frac.classdef); + fracclass.setEditable(false); + fracclass.setFont(code14); + tab.addTab("class Frac", new JScrollPane(fracclass)); + JTextAreaToggleAntiAlias btreeclass = new JTextAreaToggleAntiAlias(Covis_BTree.classdef); + btreeclass.setEditable(false); + btreeclass.setFont(code14); + tab.addTab("class BTree", new JScrollPane(btreeclass)); + // tab.addTab("String", new JTextArea()); + + getContentPane().add(tab, BorderLayout.CENTER); + // pack(); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setSize((int)(400),(int)(window.frame.getHeight())); + follow(); + } + public void actionPerformed(ActionEvent e){ + int fsize = Integer.parseInt(e.getActionCommand()); + JScrollPane jsp = (JScrollPane)tab.getComponentAt(tab.getSelectedIndex()); + System.out.println(jsp.getComponent(0).getClass().toString()); + JViewport v = (JViewport) jsp.getViewport(); + JTextAreaToggleAntiAlias target = (JTextAreaToggleAntiAlias) v.getView(); + target.setFontSize(fsize); + validate(); + repaint(); + } + + public String lastLine(){ + String[] lines = jta.getText().split("\n"); + return lines[lines.length-1]; + } + public void follow() { + if (doFollowSrcWin.isSelected()){ + if (doFollowSrcWinLeft.isSelected()){ + setLocation((int)(window.frame.getLocation().getX()-this.getWidth()),(int)(window.frame.getLocation().getY())); + setSize((int)(this.getWidth()),(int)(window.frame.getHeight())); + } else { + setLocation((int)(window.frame.getLocation().getX()+window.frame.getWidth()),(int)(window.frame.getLocation().getY())); + setSize((int)(this.getWidth()),(int)(window.frame.getHeight())); + } + } + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/SwingWorker.java b/anchorgarden/src/main/java/jaist/css/covis/SwingWorker.java new file mode 100644 index 0000000..6207aa6 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/SwingWorker.java @@ -0,0 +1,139 @@ +package jaist.css.covis; + +import javax.swing.SwingUtilities; + +/** + * (from Java Tutorial) + * + * This is the 3rd version of SwingWorker (also known as SwingWorker 3), an + * abstract class that you subclass to perform GUI-related work in a dedicated + * thread. For instructions on and examples of using this class, see: + * + * http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html + * + * Note that the API changed slightly in the 3rd version: You must now invoke + * playB() on the SwingWorker after creating it. + */ +public abstract class SwingWorker { + private Object value; // see getValue(), setValue() + + /** + * Class to maintain reference to current worker thread under separate + * synchronization control. + */ + private static class ThreadVar { + private Thread thread; + + ThreadVar(Thread t) { + thread = t; + } + + synchronized Thread get() { + return thread; + } + + synchronized void clear() { + thread = null; + } + } + + private ThreadVar threadVar; + + /** + * Get the value produced by the worker thread, or null if it hasn't been + * constructed yet. + */ + protected synchronized Object getValue() { + return value; + } + + /** + * Set the value produced by worker thread + */ + private synchronized void setValue(Object x) { + value = x; + } + + /** + * Compute the value to be returned by the get method. + */ + public abstract Object construct(); + + /** + * Called on the event dispatching thread (not on the worker thread) after + * the construct method has returned. + */ + public void finished() { + } + + /** + * A new method that interrupts the worker thread. Call this method to force + * the worker to stop what it's doing. + */ + public void interrupt() { + Thread t = threadVar.get(); + if (t != null) { + t.interrupt(); + } + threadVar.clear(); + } + + /** + * Return the value created by the construct method. Returns + * null if either the constructing thread or the current thread was + * interrupted before a value was produced. + * + * @return the value created by the construct method + */ + public Object get() { + while (true) { + Thread t = threadVar.get(); + if (t == null) { + return getValue(); + } + try { + t.join(); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); // propagate + return null; + } + } + } + + /** + * Start a thread that will call the construct method and + * then exit. + */ + public SwingWorker() { + final Runnable doFinished = new Runnable() { + public void run() { + finished(); + } + }; + + Runnable doConstruct = new Runnable() { + public void run() { + try { + setValue(construct()); + } finally { + threadVar.clear(); + } + + SwingUtilities.invokeLater(doFinished); + } + }; + + Thread t = new Thread(doConstruct); + threadVar = new ThreadVar(t); + } + + /** + * Start the worker thread. + */ + public void start() { + Thread t = threadVar.get(); + if (t != null) { + t.start(); + } + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/ToolTipProvider.java b/anchorgarden/src/main/java/jaist/css/covis/ToolTipProvider.java new file mode 100644 index 0000000..a4569c5 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/ToolTipProvider.java @@ -0,0 +1,7 @@ +package jaist.css.covis; + +import edu.umd.cs.piccolo.PNode; + +public interface ToolTipProvider { + PNode getToolTipNode(); +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/ViewController_SizeConstraintPanel.java b/anchorgarden/src/main/java/jaist/css/covis/ViewController_SizeConstraintPanel.java new file mode 100644 index 0000000..116c8da --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/ViewController_SizeConstraintPanel.java @@ -0,0 +1,25 @@ +package jaist.css.covis; + +import java.awt.Dimension; + +import javax.swing.JComponent; +import javax.swing.JPanel; +/** + * サイズを別のコンポーネントにあわせて変更するパネル + * + * ViewController内で,PageManagerに表示設定用パネルの大きさをあわせるために使用している. + * + */ +public class ViewController_SizeConstraintPanel extends JPanel{ + + private static final long serialVersionUID = -8408407486972598471L; + JComponent comp; + public ViewController_SizeConstraintPanel(JComponent c){ + comp = c; + } + public Dimension getPreferredSize(){ + return comp.getPreferredSize(); + } + + +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/ViewerKeyEventListener.java b/anchorgarden/src/main/java/jaist/css/covis/ViewerKeyEventListener.java new file mode 100644 index 0000000..9fe7c35 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/ViewerKeyEventListener.java @@ -0,0 +1,129 @@ +package jaist.css.covis; + +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.util.Hashtable; + +import edu.umd.cs.piccolo.PCamera; +import edu.umd.cs.piccolo.event.PBasicInputEventHandler; +import edu.umd.cs.piccolo.event.PInputEvent; +import edu.umd.cs.piccolo.util.PBounds; +import jaist.css.covis.pui.PMenuItem_Abstract; +import jaist.css.covis.util.BUtil; + +/** + * キーボードからのキー入力イベントを処理するクラス + * @author miuramo + * + */ +public class ViewerKeyEventListener extends PBasicInputEventHandler implements KeyListener { + AnchorGarden viewer; + + Hashtable shortCutKeyMap; +// Category log; + + public ViewerKeyEventListener(AnchorGarden _viewer) { + viewer = _viewer; + shortCutKeyMap = new Hashtable(); +// log = Logger.getLogger(ViewerKeyEventListener.class.getName()); + } + + public void addPMenuToShortcutList(PMenuItem_Abstract pm) { + shortCutKeyMap.put(pm.text.charAt(0), pm); + } + + public void keyPressed(PInputEvent e) { +// log.debug("keyCode=" + e.getKeyCode() + " keyChar [" +// + e.getKeyChar() + "]"); + if (e.getKeyCode() == 27) {// ESC + viewer.zoomHomePane(500); + } + if (e.getKeyCode() == 36) {// HOME + viewer.getCanvas().getCamera().animateViewToCenterBounds( + viewer.buffer.layer.getFullBounds(), true, 1000); + // layoutHome(); + } + if (e.getKeyCode() == 34) {// PageDown + 59 + PCamera pc = viewer.getCanvas().getCamera(); + PBounds pb = pc.getViewBounds(); + pb = BUtil.zoomBounds(pb, 0.9); + pc.animateViewToCenterBounds(pb, true, 0); + } + if (e.getKeyCode() == 33) {// PageUp - + PCamera pc = viewer.getCanvas().getCamera(); + PBounds pb = pc.getViewBounds(); + pb = BUtil.zoomBounds(pb, 1.1); + pc.animateViewToCenterBounds(pb, true, 0); + } + if (e.getKeyCode() == 32) { +// log.debug("scale: " +// + viewer.getCanvas().getCamera().getViewScale()); + } + if (e.getKeyCode() == 112){ // Function 1 (F1) で生徒番号のトグル +// viewer.buffer.viewcontroller.manageLayer("cover", !viewer.buffer.viewcontroller.getLayerState("cover")); + } + if (e.getKeyCode() == 113){ // Function 2 (F2) で調査 +// viewer.buffer.viewcontroller.manageLayer("drawInfo", !viewer.buffer.viewcontroller.getLayerState("drawInfo")); + } + if (e.getKeyCode() == 116){ // Function 5 (F5) + viewer.buffer.updateFromDB(); + } + + if (e.getKeyCode() == 127){ // Del +// viewer.buffer.updateFromDB(); + viewer.flowmenuEventHandler.selectionHandler.removeSelected(); + } +// if (e.getKeyCode() == 90 && e.isControlDown()){ // Ctrl-Z = Undo Del +// viewer.flowmenuEventHandler.selectionHandler.undoRemoveSelected(); +// } + + PMenuItem_Abstract pmenu = shortCutKeyMap.get(e.getKeyChar()); + if (pmenu != null) + pmenu.doClick(e); + else { + pmenu = shortCutKeyMap.get(Character.toLowerCase(e.getKeyChar())); + if (pmenu != null) + pmenu.doCapicalShortcutKeySelected(e); + } + } + + public void mousePressed(PInputEvent event) { + event.getInputManager().setKeyboardFocus(this); + } + + @Override + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == 27) {// ESC + viewer.zoomHomePane(500); + } + if (e.getKeyCode() == 36) {// HOME + viewer.getCanvas().getCamera().animateViewToCenterBounds( + viewer.buffer.layer.getFullBounds(), true, 1000); + // layoutHome(); + } + if (e.getKeyCode() == 34) {// PageDown + 59 + PCamera pc = viewer.getCanvas().getCamera(); + PBounds pb = pc.getViewBounds(); + pb = BUtil.zoomBounds(pb, 0.9); + pc.animateViewToCenterBounds(pb, true, 0); + } + if (e.getKeyCode() == 33) {// PageUp - + PCamera pc = viewer.getCanvas().getCamera(); + PBounds pb = pc.getViewBounds(); + pb = BUtil.zoomBounds(pb, 1.1); + pc.animateViewToCenterBounds(pb, true, 0); + } + } + + @Override + public void keyReleased(KeyEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void keyTyped(KeyEvent e) { + // TODO Auto-generated method stub + + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/ZipUtil.java b/anchorgarden/src/main/java/jaist/css/covis/ZipUtil.java new file mode 100644 index 0000000..2a7eaac --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/ZipUtil.java @@ -0,0 +1,32 @@ +package jaist.css.covis; + +import java.io.BufferedInputStream; +import java.io.ByteArrayOutputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + + +public class ZipUtil { + + public static byte[] read(ZipFile zfile, ZipEntry zent){ + BufferedInputStream in; + ByteArrayOutputStream varyBuf = new ByteArrayOutputStream(); + final int LS = 1024; + int b; + try { + in = new BufferedInputStream(zfile.getInputStream(zent)); + byte buf[] = new byte[LS]; + while((b = in.read(buf, 0, buf.length)) != -1 ) { + varyBuf.write(buf,0,b) ; + } + varyBuf.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return varyBuf.toByteArray(); + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/Anchor.java b/anchorgarden/src/main/java/jaist/css/covis/cls/Anchor.java new file mode 100644 index 0000000..43c01f6 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/Anchor.java @@ -0,0 +1,295 @@ +package jaist.css.covis.cls; + +import jaist.css.covis.CoVisBuffer; +import jaist.css.covis.ToolTipProvider; + +import java.awt.BasicStroke; +import java.awt.Color; + +import edu.umd.cs.piccolo.PNode; +import edu.umd.cs.piccolo.event.PInputEvent; +import edu.umd.cs.piccolo.nodes.PPath; +import edu.umd.cs.piccolo.nodes.PText; +import edu.umd.cs.piccolo.util.PBounds; +import edu.umd.cs.piccolo.util.PDimension; + +class AnchorTab extends PPath implements Move, ToolTipProvider { + private static final long serialVersionUID = 3651392444867276102L; + Anchor anchor; + PNode tooltip; + public AnchorTab(Anchor a){ + anchor = a; + setPathToEllipse(-20, -20, 20, 20); + setPaint(Color.orange); + setStrokePaint(Color.orange.darker()); + setStroke(new BasicStroke(1)); + setAnchorEnabled(false); + } + public void move(PDimension d){ + translate(d.getWidth(), d.getHeight()); //履歴に関係ない動作 + } + // public String referenceVarNames(){ + // return anchor.srcVariable.getVarName(); + // } + public PNode getToolTipNode(){ + tooltip = null; + if (tooltip == null) { + PText pt = new PText(anchor.srcVariable.getVarName()); + pt.setPaint(Color.orange); + tooltip = pt; + } + return tooltip; + } + public void setAnchorEnabled(boolean active){ + if (active){ + addAttribute("moveTarget", this); + addAttribute("tooltip", this); + } else { + if (anchor.srcVariable.object != null){ + addAttribute("moveTarget", anchor.srcVariable.object); + addAttribute("tooltip", anchor.srcVariable.object); + } else { + addAttribute("moveTarget", anchor.srcVariable); + addAttribute("tooltip", anchor.srcVariable); + } + } + } +} + +public class Anchor extends PPath implements Runnable, DragNotice { + private static final long serialVersionUID = -8491055463977967303L; + // Variable var; + public Covis_Object destObject; + public Covis_Object lastDestObject; + AnchorTab anchortab; + + RefLink link; + Thread rewindThread; + public boolean isOperating = false; + + public Class type; + public String varName; + + long toFront_ts; + int aryIndex = -1; + // public PNode src; // Variable or Covis_Array + public Variable srcVariable; // Variable or Covis_Array + public boolean lastDetach = false; //最後にアタッチされていたオブジェクト(はずして,すぐに同じおぶじぇくとにつけるのは禁止) + public Anchor(Class t, Variable _src, int aI){ + this(t,_src); + aryIndex = aI; + } + public Anchor(Class t, Variable _src){ + type = t; + srcVariable = _src; + aryIndex = -1; + setPathToEllipse(-20, -20, 20, 20); + // setPaint(Color.orange); + // setStrokePaint(Color.orange.darker()); + // setStroke(new BasicStroke(1)); + setPaint(null); + setStrokePaint(null); + + // co.setScale(0.3f); + // addChild(cv_class); + // layout(0); + + // addAttribute("moveTargetY", this); + addAttribute("info", "Anchor "+this.toString()); + // addAttribute("selectable", this); + // addAttribute("moveTarget", this); + // addAttribute("dragLayout", this); + + anchortab = new AnchorTab(this); + + link = new RefLink(this,anchortab,this); + addChild(link); + anchortab.addAttribute("moveLink", link); + addAttribute("moveLink", link); + + addChild(anchortab); + anchortab.addAttribute("dragNotice", this); + anchortab.addAttribute("toFront", this); + + rewindThread = new Thread(this); + rewindThread.start(); + } + public void start_RewindThread(){ + if (rewindThread == null){ + rewindThread = new Thread(this); + rewindThread.start(); + // System.out.println("Start thread"); + } + } + // インカミングリンクが入ったら,trueになる>アンカータブが動くようになる. + public void setAnchorEnabled(boolean active){ + if (active){ + anchortab.addAttribute("moveTarget", this.anchortab); + anchortab.addAttribute("tooltip", this.anchortab); + } else { + anchortab.addAttribute("moveTarget", srcVariable.object); + anchortab.addAttribute("tooltip", srcVariable.object); + } + } + + + public void run() { + int count = 0; + while(count < 10){ + if (!isOperating) { + PDimension d = link.diff(); + anchortab.translate(d.getWidth(), d.getHeight()); + link.update(); + repaint(); + double size = d.getHeight()*d.getWidth(); + if (size < 0.00000001) count++; + // preSize = size; + // count++; + } + // System.out.print("."); + try { + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + rewindThread = null; + } + + public void setDragNotice(boolean f) { + isOperating = f; + } + + public void drag(PInputEvent e, CoVisBuffer buffer) { + if (!srcVariable.isEnabled()) { + anchortab.setPaint(Color.gray); + return; + } + boolean isAnyOverlap = false; + boolean isTypeMatch = true; + toFront(System.currentTimeMillis()); + PBounds pb = anchortab.getGlobalBounds(); + for(PNode co: buffer.objField.getAllNodes()){ + if (!(co instanceof Covis_Object)) continue; + PBounds cob = co.getGlobalBounds(); + if (cob.contains(pb) || pb.intersects(cob)){ + Covis_Object candidate = (Covis_Object) co; + // type が candidate のスーパークラス(type hoge = candidateができる)ならtrue + // System.out.println("type "+type.toString()); + // System.out.println("can "+candidate.type.toString()); + // if (candidate instanceof type) + if (type.isAssignableFrom(candidate.type)){ + // if (candidate.getClsName().equals(var.cv_class.getClsName())){ //TODO:本当はサブクラスチェック + destObject = candidate; + anchortab.setPaint(Color.red); + isAnyOverlap = true; + } else { + isTypeMatch = false; + } + } + } + if (!isAnyOverlap) { + if (isTypeMatch && srcVariable.isEnabled()) anchortab.setPaint(Color.orange); else { + anchortab.setPaint(Color.gray); + } + if (destObject != null){ + destObject.detach(this); + lastDetach = true; + destObject = null; + } + } + } + + public void endDrag(PInputEvent e, CoVisBuffer buffer) { + if (anchortab.getPaint() == Color.gray) Informer.playSound("RecEnd.wav"); + + anchortab.setPaint(Color.orange); + start_RewindThread(); + if (!srcVariable.isEnabled()) { + return; + } + if (destObject != null){ + destObject.attach(this); + } else { + if (lastDetach) { + if (lastDestObject != null){ + buffer.putHistoryUnLink("unlink", this); + lastDestObject = null; + } + lastDetach = false; + } + } + } + public void setVarName(String s){ + varName = getVarName(); + anchortab.tooltip = null; + if (destObject != null) { + destObject.tooltip = null; + if (destObject instanceof Covis_Array){ + Covis_Array ca = ((Covis_Array)destObject); + for(Anchor a: ca.anchors_member){ + a.anchortab.tooltip = null; + if (a.destObject != null) a.destObject.tooltip = null; + } + } + } + } + //TODO: + + public Class getVarClass(){ + return srcVariable.type; + // if (src instanceof Variable) return ((Variable)src).type; + // else if (src instanceof Covis_Array) return ((Covis_Array)src).type.getComponentType(); + // else return null; + } + //TODO: + + public String getVarName(){ + return srcVariable.getBaseVarName(); + // if (src instanceof Variable) return ((Variable)src).varname; + // else if (src instanceof Covis_Array) { + // // System.out.println("yes, covis_array"); + // Covis_Array ca = ((Covis_Array)src); + // if (ca.referenceVarNames() != null){ + // String[] o = ca.referenceVarNames().split("\n"); + // StringBuffer sb = new StringBuffer(); + // for(String s:o){ + // sb.append(s+"["+aryIndex+"]\n"); + // } + // return sb.toString().substring(0, sb.length()-1); + // } + // } + // System.out.println("Anchor.getVarNameがnullを返しました"); + // return null; + } + public Variable getSrcVariable(){ + return srcVariable; + } + + public void toFront(long ts) { + + if (toFront_ts == ts) return; + toFront_ts = ts; + PNode parent = getParent(); + if (parent != null){ + // removeFromParent(); + parent.addChild(this); + if (parent instanceof ToFront) ((ToFront)parent).toFront(ts); + if (parent.getAttribute("toFront")!=null){ + ((ToFront)parent.getAttribute("toFront")).toFront(ts); + } + } + } + //TODO: + public String getClsName(){ + return srcVariable.getTypeName(); + // if (src instanceof Covis_Array){ + // return ((Covis_Array)src).elementObj.getClsName(); + // } else if (src instanceof Covis_Object){ + // return ((Covis_Object)src).getClsName(); + // } else if (src instanceof Variable){ + // return ((Variable)src).getTypeName(); + // } + // return "error_in_Anchor_getClsName()"; + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/ArrayInitializeWindow.java b/anchorgarden/src/main/java/jaist/css/covis/cls/ArrayInitializeWindow.java new file mode 100644 index 0000000..d61b6f0 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/ArrayInitializeWindow.java @@ -0,0 +1,89 @@ +package jaist.css.covis.cls; + +import java.awt.BorderLayout; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Random; + +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; + +public class ArrayInitializeWindow extends JDialog { + + private static final long serialVersionUID = -7025036939612024059L; + public JTextField[] jtfary; + public String valtype; + public ArrayInitializeWindow(JFrame parent, int size, String type){ + super(parent, "Initialize Array", true); + valtype = type; + JPanel jp = new JPanel(new GridLayout(2,size)); + jtfary = new JTextField[size]; + for(int i=0;i getTypeNodes(){ + List col = new ArrayList(getChildrenReference()); + ArrayList ret = new ArrayList(); + for(PNode p: col) { + if (p instanceof ClassStamp){ + ClassStamp v = (ClassStamp)p; + ret.add(v); + } + } + return ret; + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/ClassFieldMenu.java b/anchorgarden/src/main/java/jaist/css/covis/cls/ClassFieldMenu.java new file mode 100644 index 0000000..b957036 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/ClassFieldMenu.java @@ -0,0 +1,68 @@ +package jaist.css.covis.cls; + +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JFrame; +import javax.swing.JMenuItem; +import javax.swing.JPopupMenu; + +import jaist.css.covis.CoVisBuffer; +import jaist.css.covis.util.FramePopup; + + +public class ClassFieldMenu extends JPopupMenu implements FramePopup, ActionListener { + ClassField f; + JFrame frame; + private static final long serialVersionUID = -3662668322301800275L; + public static String[] modes = {"Novice mode", "Class/Instance mode", "Inheritance mode"}; + + CoVisBuffer buffer; + public ClassFieldMenu(ClassField _f, CoVisBuffer buf) { + this.f = _f; + buffer = buf; + + JMenuItem menuItem; + + setLightWeightPopupEnabled(false); + + menuItem = new JMenuItem("cancel"); + add(menuItem); + + addSeparator(); + + for(int i=0;i targetClass; + public ClassInspector(Class target){ + targetClass = target; + } + + public void inspect_print() { + inspect_print_recursive(targetClass,0); + } + public void Systemoutprintln(String s, int n){ + for(int i=0;i c, int n) { + Systemoutprintln("Name: "+c.getName(),n); + Systemoutprintln("CanonicalName :"+c.getCanonicalName(),n); + Systemoutprintln("============Fields",n); + Field[] fs = c.getDeclaredFields(); + for(Field f: fs){ +// Systemoutprintln("Modifier: "+Modifier.toString(f.getModifiers()),n); +// Systemoutprintln("Name: "+f.getName(),n); +// Systemoutprintln("Type: "+f.getType().toString(),n); + Systemoutprintln(""+f.toString(), n); + } + Method[] ms = c.getDeclaredMethods(); + Systemoutprintln("============Methods",n); + for(Method m: ms){ +// Systemoutprintln("Modifier: "+Modifier.toString(m.getModifiers()),n); +// Systemoutprintln("Name: "+m.getName(),n); +// Systemoutprintln("Return Type: "+m.getReturnType().toString(),n); + Systemoutprintln(""+m.toString(),n); + } + Constructor[] conss = c.getDeclaredConstructors(); + Systemoutprintln("============Constructors",n); + for(Constructor cons : conss){ +// Systemoutprintln("Modifier: "+Modifier.toString(cons.getModifiers()),n); +// Systemoutprintln("Name: "+cons.getName(),n); + Systemoutprintln(""+cons.toString(),n); + } + Systemoutprintln("",n); + Class superclazz = c.getSuperclass(); + if (superclazz==null) return; + else inspect_print_recursive(superclazz,n+2); + } + + + +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/ClassStamp.java b/anchorgarden/src/main/java/jaist/css/covis/cls/ClassStamp.java new file mode 100644 index 0000000..2258b79 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/ClassStamp.java @@ -0,0 +1,177 @@ +package jaist.css.covis.cls; + +import jaist.css.covis.CoVisBuffer; +import jaist.css.covis.Selectable; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; +import java.util.TreeMap; + +import edu.umd.cs.piccolo.PNode; +import edu.umd.cs.piccolo.nodes.PPath; +import edu.umd.cs.piccolo.nodes.PText; +import edu.umd.cs.piccolo.util.PDimension; + +public class ClassStamp extends PPath implements Layoutable, Selectable, Move { + public static BasicStroke roundrectStroke = new BasicStroke(4f,BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 90.0f); + + private static final long serialVersionUID = -2274392520995258292L; + public static Object[] possibilities = {"Object", "Oval", "Rect", "String", "int", "char"}; + public Covis_Type cv_type; + PNode cv_class_for_tooltip; + PText tooltip_classname; + public static ClassStamp selectedType; + public static ArrayList stamps; + static{ + stamps = new ArrayList(); + } + private boolean isSelected; + + PPath handle; + PText caption; + public static float top = 27; + public CoVisBuffer buffer; + public ClassStamp(Covis_Type co, CoVisBuffer buf){ + cv_type = co; + buffer = buf; + + setPathToRectangle(0,top,200,100); + setPaint(new Color(230,230,200)); + setStrokePaint(Color.gray); + setStroke(new BasicStroke(1)); + + addChild(cv_type); + layout(0); + + // addAttribute("moveTargetY", this); + addAttribute("info", "ClassStamp "+this.toString()); + addAttribute("selectable", this); + addAttribute("moveTargetY", this); + addAttribute("dragLayout", this); + + + handle = new PPath(this.getPathReference()); + handle.addAttribute("moveTargetY", this); + handle.addAttribute("dragLayout", this); + handle.setTransparency(0.0f); + handle.setPaint(Color.pink); + handle.setStrokePaint(Color.red); + handle.setStroke(roundrectStroke); + handle.setPickable(true); + handle.moveToFront(); + handle.addAttribute("info", "ClassStamp handle"); + handle.addAttribute("selectable", this); + handle.addAttribute("exclusiveSelectable", stamps); + addChild(handle); + + caption = new PText(cv_type.getClsName()); + caption.scale(2); + caption.setOffset(10,-2); + caption.addAttribute("moveTargetY", this); + caption.addAttribute("dragLayout", this); + addChild(caption); + + stamps.add(this); + + addAttribute("popupMenu", new ClassStampMenu(this, buffer)); + cv_type.addAttribute("popupMenu", new ClassStampMenu(this, buffer)); + handle.addAttribute("popupMenu", new ClassStampMenu(this, buffer)); + caption.addAttribute("popupMenu", new ClassStampMenu(this, buffer)); + } + public String toString(){ + return cv_type.getClsName(); + } + + public void layout(int dur){ + layoutExceptOne(null, dur); + } + + public void layoutExceptOne(PNode operationNode, int dur) { + List col = getChildrenReference(); + TreeMap map = new TreeMap(); + for(PNode p: col) map.put(p.getYOffset(), p); + + double offsetx = 10; + double endx = 10; + double offsety = 10; + double endy = 10; + double maxx = 0, maxy = 0; + for(PNode p : map.values()){ + // p.setOffset(offsetx, offsety); + double px = p.getFullBounds().width; + double py = p.getFullBounds().height; + if (maxx < offsetx + endx + px) maxx = offsetx + endx + px; + if (maxy < offsety + endy + py) maxy = offsety + endy + py; + if (operationNode != p) p.animateToPositionScaleRotation(offsetx, offsety+top, 1, 0, dur); + offsety += py; + offsety += 10; + } + animateToBounds(0, top, maxx, maxy, dur); + } + + public ArrayList getAllChildren() { + return null; + } + + public boolean isSelected() { + return isSelected; + } + + public void setSelected(boolean f, ArrayList list) { + isSelected = f; + + + if (f) { + handle.setTransparency(0.8f); + // Informer.playSound("Default.wav"); + Informer.playSound("Pop.wav"); + } else { + handle.setTransparency(0.0f); + } + if (f && list != null && !list.contains(this)) list.add(this); + if (!f && list != null && list.contains(this)) list.remove(this); + if (f) selectedType = this; else { + if (selectedType == this) { + selectedType = null; + } + } + } + + public PNode theNode() { + return this; + } + + public void toFront() { + getParent().addChild(this); + } + + public void toggleSelected(ArrayList list) { + setSelected(!isSelected, list); + } + + public void removeLabel(Hashtable trash) { + if (trash != null) trash.put(this, getParent()); + removeFromParent(); + } + public PNode getToolTipNode(){ + if (cv_class_for_tooltip == null) { + cv_class_for_tooltip = cv_type.createToolTip(); + cv_class_for_tooltip.setScale(0.5f); + } + return cv_class_for_tooltip; + } + + public PNode getToolTipNode_forVariable() { + if (tooltip_classname == null) { + tooltip_classname = new PText("Click to add variable\nof '"+cv_type.getClsName()+"'"); + tooltip_classname.setScale(1.5f); + } + return tooltip_classname; + } + public void move(PDimension d){ + translate(d.getWidth(), d.getHeight()); //履歴に関係ない動作 + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/ClassStampMenu.java b/anchorgarden/src/main/java/jaist/css/covis/cls/ClassStampMenu.java new file mode 100644 index 0000000..dcd77c3 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/ClassStampMenu.java @@ -0,0 +1,145 @@ +package jaist.css.covis.cls; + +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; + +import javax.swing.JFrame; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; +import javax.swing.JPopupMenu; + +import jaist.css.covis.CoVisBuffer; +import jaist.css.covis.Selectable; +import jaist.css.covis.util.FramePopup; + + +public class ClassStampMenu extends JPopupMenu implements FramePopup, ActionListener{ + ClassStamp cstamp; + JFrame frame; + private static final long serialVersionUID = -3662668322301800275L; + + CoVisBuffer buffer; + public ClassStampMenu(ClassStamp _f, CoVisBuffer buf) { + this.cstamp = _f; + + buffer = buf; + if (buffer==null) JOptionPane.showMessageDialog(null, "buffer is null"); + + JMenuItem menuItem; + + setLightWeightPopupEnabled(false); + + menuItem = new JMenuItem("cancel"); + add(menuItem); + + addSeparator(); + if (!cstamp.isSelected()){ + menuItem = new JMenuItem("select"); + add(menuItem); + menuItem.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e){ + ArrayList sel = new ArrayList(); + if (ClassStamp.selectedType != null){ + ClassStamp.selectedType.setSelected(false, sel); + } + cstamp.toggleSelected(sel); + } + }); + + addSeparator(); + } + menuItem = new JMenuItem("inspect"); + add(menuItem); + menuItem.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e){ + Class clazz = cstamp.cv_type.getClass(); + ClassInspector ci = new ClassInspector(clazz); + ci.inspect_print(); + } + }); + + addSeparator(); + + if (cstamp.cv_type instanceof Covis_primitive){ + menuItem = new JMenuItem("create variable (automatic)"); + add(menuItem); + menuItem.addActionListener(this); + + menuItem = new JMenuItem("create variable (manual)"); + add(menuItem); + menuItem.addActionListener(this); + } else if (cstamp.cv_type instanceof Covis_Array){ + menuItem = new JMenuItem("create variable (automatic)"); + add(menuItem); + menuItem.addActionListener(this); + + menuItem = new JMenuItem("create variable (manual)"); + add(menuItem); + menuItem.addActionListener(this); + + menuItem = new JMenuItem("create array (automatic): new "+cstamp.cv_type.getClsName().substring(0,cstamp.cv_type.getClsName().length()-2)+"[ 4 ]"); + add(menuItem); + menuItem.addActionListener(this); + + menuItem = new JMenuItem("create array (manual): new "+cstamp.cv_type.getClsName().substring(0,cstamp.cv_type.getClsName().length()-2)+"[ N ]"); + add(menuItem); + menuItem.addActionListener(this); + + } else if (cstamp.cv_type instanceof Covis_Object){ + menuItem = new JMenuItem("create variable (automatic)"); + add(menuItem); + menuItem.addActionListener(this); + + menuItem = new JMenuItem("create variable (manual)"); + add(menuItem); + menuItem.addActionListener(this); + + menuItem = new JMenuItem("create object (automatic): new "+cstamp.cv_type.getClsName()+"()"); + add(menuItem); + menuItem.addActionListener(this); + + menuItem = new JMenuItem("create object (manual): new "+cstamp.cv_type.getClsName()+"("+cstamp.cv_type.getConstructorArgs()+")"); + add(menuItem); + menuItem.addActionListener(this); + } + // addSeparator(); + // + // menuItem = new JMenuItem("レイアウト"); + // add(menuItem); + // menuItem.addActionListener(new ActionListener() { + // public void actionPerformed(ActionEvent e) { + // f.layout(500); + // } + // }); + + } + public void showWithFrame(Component c, int x, int y, JFrame _f) { + frame = _f; + show(c, x, y); + } + /** + * 右メニューから生成 + */ + @Override + public void actionPerformed(ActionEvent arg0) { + if (buffer==null) JOptionPane.showMessageDialog(null, "buffer is null"); + if (arg0.getActionCommand().indexOf("variable")>-1){ + if (arg0.getActionCommand().indexOf("manual")>-1){ + buffer.varField.addVariable(cstamp,false); + } else { + buffer.varField.addVariable(cstamp,true); + } + } + if (arg0.getActionCommand().indexOf("new")>-1){ + if (arg0.getActionCommand().indexOf("manual")>-1){ + buffer.objField.addObject(cstamp,false); + } else { + buffer.objField.addObject(cstamp,true); + } + } + + } + +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/ClickHandler.java b/anchorgarden/src/main/java/jaist/css/covis/cls/ClickHandler.java new file mode 100644 index 0000000..8f62f5e --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/ClickHandler.java @@ -0,0 +1,8 @@ +package jaist.css.covis.cls; + +import jaist.css.covis.fm.FlowMenu_TMRG; +import edu.umd.cs.piccolo.event.PInputEvent; + +public interface ClickHandler { + public void clicked(PInputEvent e, FlowMenu_TMRG fmenu); +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/CovisObj_TransparencyControl.java b/anchorgarden/src/main/java/jaist/css/covis/cls/CovisObj_TransparencyControl.java new file mode 100644 index 0000000..f1d5ff4 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/CovisObj_TransparencyControl.java @@ -0,0 +1,67 @@ +package jaist.css.covis.cls; + +import edu.umd.cs.piccolo.PNode; + +public class CovisObj_TransparencyControl implements Runnable { + Thread transparencyThread = null; +// ArrayList effectAry; //ダイナミックに作成する?(計算コストを考え,ここではしない) + float target_transparency[] = new float[]{0.0f, 1.0f}; + public float tick_transparency[] = new float[]{-0.008f, 0.5f}; + int direction = 1; + int msec; + int slow_percentrate = 100; + float animcount = 1000; + float currentValue = 1f; + boolean quitTransparencyThread = true; + Covis_Object obj; + PNode window; + public CovisObj_TransparencyControl(Covis_Object o){ + obj = o; + + // ここに,影響をあたえるPNodeを追加する + } + + public void transparencyThread_Start(int direct, PNode w, int _slow_percentrate){ + window = w; + slow_percentrate = _slow_percentrate; + if (direct == 0 && direction == 0) return; + direction = direct; +// System.out.println("direction changes to "+direction); + + if (transparencyThread == null){ + quitTransparencyThread = false; + transparencyThread = new Thread(this); + transparencyThread.start(); + } + } + public void run() { + while(!quitTransparencyThread){ + currentValue += tick_transparency[direction]; + if ((direction == 0 && currentValue < target_transparency[direction]) || + (direction == 1 && target_transparency[direction] < currentValue )) { + currentValue = target_transparency[direction]; + quitTransparencyThread = true; + } + + obj.setTransparency(currentValue); + if (window != null) window.repaint(); + + try { + Thread.sleep(100 * slow_percentrate / 100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + if (direction == 0) { +// System.out.println("dead."); + + obj.detachAll(); + obj.removeFromParent(); + obj.dispose(); + + + } + transparencyThread = null; +// + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_Array.java b/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_Array.java new file mode 100644 index 0000000..a238bbf --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_Array.java @@ -0,0 +1,441 @@ +package jaist.css.covis.cls; + +import jaist.css.covis.CoVisBuffer; + +import java.awt.Color; +import java.lang.reflect.Array; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.HashSet; + +import javax.swing.JFrame; +import javax.swing.JOptionPane; + +import edu.umd.cs.piccolo.nodes.PPath; +import edu.umd.cs.piccolo.nodes.PText; +import edu.umd.cs.piccolo.util.PDimension; + +public class Covis_Array extends Covis_Object { + private static final long serialVersionUID = 8131819427660903628L; + public static Color defaultColor = new Color(222,122,10); + public static String lastSelectedClass = "Object"; + public Covis_Type elementObj; + public String elementClassStr; // あらかじめ,定義してもよい("int", "String"など) + public static int lastAryaNum = 4; + + // ArrayList anchors_member; + ArrayList data4primitive; + ArrayList primitives; + int sizeofArray; + + public Covis_Array(CoVisBuffer buf, boolean isAuto){ + super(buf, isAuto); + color = defaultColor; + setPaint(color); + setStroke(basicStroke); + elementObj = this; + init_length(4,isAuto); + } + public Covis_Array(CoVisBuffer buf, boolean isAuto, String presetElementClass){ + super(buf, isAuto); + elementClassStr = presetElementClass; + Class c; + try { + c = Class.forName("jaist.css.covis.cls.Covis_"+elementClassStr); + color = (Color) c.getField("defaultColor").get(null); + Constructor con = c.getConstructor(CoVisBuffer.class, boolean.class); + elementObj = (Covis_Type) con.newInstance(buf, true); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (SecurityException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + setPaint(color); + setStroke(basicStroke); + init_length(4,isAuto); + } + public Covis_Array(Color c, CoVisBuffer buf, boolean isAuto){ + super(c, buf, isAuto); + } + public Covis_Array(Covis_Type obj, Class t, CoVisBuffer buf, int arySize, boolean isAuto){ + super(buf, isAuto); + type = t; + color = obj.getClassColor(); + elementObj = obj; + setPaint(color); + setStroke(basicStroke); + init_length(arySize, isAuto); + } + public String getClsName(){ + if (elementClassStr == null){ + int p = getClass().getName().lastIndexOf("_"); + return getClass().getName().substring(p+1)+"[]"; + } else { + return elementClassStr+"[]"; + } + } + public void setValues(String s, int size){ + data4primitive = new ArrayList(); + primitives = new ArrayList(); + String[] sary = s.split(","); + for(int i=0;i 0)) { + // System.out.println(s+" Selected."); + lastSelectedClass = s; + elementClassStr = s; + } else { + return null; + } + } + + int aryLength = 4; + + if (!isAuto){ + String val = JOptionPane.showInputDialog(buffer.getWindow().frame, "Input array size. [1-10]", "4"); + if (val != null) { + aryLength = Integer.parseInt(val); + if (aryLength < 1) aryLength = 1; + if (aryLength > 10) aryLength = 10; + } else { + return null; + } + } + try { + Class c = Class.forName("jaist.css.covis.cls.Covis_"+elementClassStr); + Constructor constructor = c.getConstructor(CoVisBuffer.class, boolean.class); + Covis_Type cv_class = (Covis_Type) constructor.newInstance(buffer,true); + type = Array.newInstance(c, aryLength).getClass(); + + return new Covis_Array(cv_class, type, buffer, aryLength, isAuto); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (SecurityException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return null; + } + public Covis_Object Covis_clone(boolean isAuto){ + return new Covis_Array(buffer, isAuto); + } + public Color getClassColor(){ + return defaultColor; + } + + public static int objCount = 0; + public static int objAryCount = 0; + public String getNextVarName(boolean isAry){ + StringBuffer sb = new StringBuffer(getClsName().toLowerCase().substring(0,3)); + if (isAry) { + objAryCount++; + sb.append("Ary"); + sb.append(objAryCount); + } else { + objCount++; + sb.append(objCount); + } + return sb.toString(); + } + /** + * オーバーライド + */ + public void detach(Anchor anchor){ + super.detach(anchor); + checkAtRefDetached(); + } + /** + * オーバーライド + */ + public void attach(Anchor anchor){ + super.attach(anchor); + checkAtRefDetached(); + // for(Anchor a: aryAnchors){ + // a.anchortab.tooltip = null; + // if (a.dest != null) a.dest.tooltip = null; + // a.setAnchorEnabled(true); + // } + for(Anchor a: anchors_member){ //基本的にはcheckAtRefDetachedを利用し,アンカー有効化だけ,別に処理 + a.setAnchorEnabled(true); //本当は,はずしたときには無効化をしないといけないのでは(だけど,全部外れたかどうかチェックする必要があるので大変) + } + } + /** + * リファレンスが切れたときに,チェックする + */ + public void checkAtRefDetached(){ + HashSet temp = new HashSet(); + for(Anchor a: anchors_incoming){ + if (a.srcVariable.object != this) temp.add(a); + a.anchortab.tooltip = null; + } + if (temp.size()==0){ +// tc.tick_transparency[0] = -0.05f; //一旦離したら早く消える + tc.transparencyThread_Start(0, this, 50); + addAttribute("moveLink", null); + } + for(Anchor a: anchors_member){ + a.anchortab.tooltip = null; + if (a.destObject != null) a.destObject.tooltip = null; + } + if (primitives != null){ + for(Covis_primitive prim : primitives){ + prim.tooltip = null; + } + } + tooltip = null; + } + + public void dispose(){ + for(Anchor a: anchors_member){ + if (a.destObject != null) a.destObject.detach(a); + } + super.dispose(); + } + public void move(PDimension d){ + super.move(d); + for(Anchor a: anchors_member){ + a.start_RewindThread(); + } + } + // overwrite + public String getConstructorInfo() { + StringBuffer sb = new StringBuffer(); + if (elementObj instanceof Covis_primitive){ + if (buffer.getWindow().isAutoMode.isSelected()){ // isAuto + sb.append("new "+elementObj.getClsName()+"["+sizeofArray+"]"); + } else { + String defaultVar = "0"; + boolean hasUndefaultValue = false; + if (elementObj instanceof Covis_int) defaultVar = "0"; + + sb.append("new "+elementObj.getClsName()+"[]"); + sb.append("{"); + for(String s: data4primitive){ + if (elementObj instanceof Covis_char){ + sb.append("'"+s+"',"); + } else { + sb.append(s+","); + } + if (!s.equals(defaultVar)) hasUndefaultValue = true; + } + sb = new StringBuffer(sb.substring(0, sb.length()-1)); + sb.append("}"); + + if (!hasUndefaultValue){ + sb = new StringBuffer(); + sb.append("new "+elementObj.getClsName()+"["+sizeofArray+"]"); + } + } + } else { + sb.append("new "+elementObj.getClsName()+"["+sizeofArray+"]"); + } + return sb.append(";").toString(); + } + /** + * 配列の要素変更用(プリミティブ) + * @param v + * @return + */ + public String getEditValueInfo(Covis_primitive v) { + //参照名の1つ+[x] = val + return referenceVarNames().split("\n")[0]+ + "["+(String)v.getAttribute("index")+"] = "+v.getValue()+";"; + } + public Covis_Object newInstance(boolean isAuto){ + Constructor constructor; + Covis_Object cv_class = null; + try { + if (elementClassStr == null){ + constructor = getClass().getConstructor(CoVisBuffer.class, boolean.class); + cv_class = (Covis_Object) constructor.newInstance(buffer,isAuto); + } else { + constructor = getClass().getConstructor(CoVisBuffer.class, boolean.class,String.class); + cv_class = (Covis_Object) constructor.newInstance(buffer,isAuto,elementClassStr); + } + + } catch (SecurityException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + return cv_class; + } + + @Override + public void clear_objCount() { + try { + Field f = getClass().getField("objCount"); + f.setInt(getClass(), 0); + Field fg = getClass().getField("objAryCount"); + fg.setInt(getClass(), 0); + } catch (SecurityException e) { + e.printStackTrace(); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + public String toString(){ + StringBuffer sb = new StringBuffer(); + sb.append("{"); + if (elementObj instanceof Covis_Object){ + for(Anchor a: anchors_member){ + if (a.destObject == null){ + sb.append("null,"); + } else { + sb.append(a.destObject.toString()+","); + } + } + } else { + for(String s: data4primitive){ + sb.append(s+","); + } + } + return sb.toString().substring(0, sb.toString().length()-1)+"}"; + } + +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_BTree.java b/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_BTree.java new file mode 100644 index 0000000..4612bb6 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_BTree.java @@ -0,0 +1,465 @@ +package jaist.css.covis.cls; + +import jaist.css.covis.CoVisBuffer; +import jaist.css.covis.JLabelW; +import jaist.css.covis.SrcWindow; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; + +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JTextField; + +import edu.umd.cs.piccolo.nodes.PText; + +public class Covis_BTree extends Covis_Object { + + private static final long serialVersionUID = 8906063645409838445L; + public static Color defaultColor = new Color(100,255,150); + public Covis_BTree(CoVisBuffer buf, boolean isAuto){ + super(buf, isAuto); + color = defaultColor; + setPaint(color); + setStroke(basicStroke); + } + public Covis_BTree(Color c, CoVisBuffer buf, boolean isAuto){ + super(c, buf, isAuto); + } + Covis_int val; + VariableM left, right; + // overwrite + public String getConstructorInfo() { + // return "new "+getClsName()+"("+valueText.getText()+"); // or, just "+valueText.getText(); + return "new "+getClsName()+"("+val.value+");"; + } + + // public String getConstructorArguments() { + // return a.value+", "+b.value; + // } + + public void init(boolean isAuto){ + setPathToRectangle(0, 0, 100,60); + + val = new Covis_int(buffer, isAuto); + val.valueText.addAttribute("moveTarget", this); + val.valueText.addAttribute("tooltip", this); + + val.setValue("5"); + if (isAuto){ + } else { + BTreeConstructorDialog dialog = BTreeConstructorDialog.showDialog(buffer.getWindow().frame, this, "Constructor of BTree", "new BTree( a );"); + if (dialog.isCanceled()) { + this.setVisible(false); + return; + } + } + + val.setScale(0.9f); + val.addAttribute("moveTarget", this); + val.addAttribute("tooltip", this); + val.offset(30, 5); + addChild(val); + + // インデックス値を右肩にはりつける + PText ptidx0 = new PText("var"); + ptidx0.setScale(0.6); + ptidx0.setOffset(42,5); + ptidx0.setTextPaint(Color.blue); + addChild(ptidx0); + ptidx0.addAttribute("moveTarget", this); + ptidx0.addAttribute("tooltip", this); + + + PText ptidx = new PText("left"); + ptidx.setScale(0.6); + ptidx.setOffset(10,25); + ptidx.setTextPaint(Color.blue); + addChild(ptidx); + ptidx.addAttribute("moveTarget", this); + ptidx.addAttribute("tooltip", this); + + PText ptidx2 = new PText("right"); + ptidx2.setScale(0.6); + ptidx2.setOffset(77,25); + ptidx2.setTextPaint(Color.blue); + addChild(ptidx2); + ptidx2.addAttribute("moveTarget", this); + ptidx2.addAttribute("tooltip", this); + + left = new VariableM(this,null,buffer,"left",this); + right = new VariableM(this, null, buffer,"right",this);//new Anchor(this.getClass(), this); + + addChild(left); + left.setOffset(5,35); + addChild(right); + right.setOffset(73,35); + anchors_member.add(left.anchor); + anchors_member.add(right.anchor); + left.addAttribute("moveTarget", this); + left.addAttribute("tooltip", this); + right.addAttribute("moveTarget", this); + right.addAttribute("tooltip", this); + + buffer.putHistoryVar("var", right, false); + buffer.putHistoryVar("var", left, false); + + + } + public Covis_Object Covis_clone(boolean isAuto){ + return new Covis_BTree(buffer, isAuto); + } + public Color getClassColor(){ + return defaultColor; + } + + public static int objCount = 0; + public static int objAryCount = 0; + public String getNextVarName(boolean isAry){ + StringBuffer sb = new StringBuffer(getClsName().toLowerCase().substring(0,4)); + if (isAry) { + objAryCount++; + sb.append("Ary"); + sb.append(objAryCount); + } else { + objCount++; + sb.append(objCount); + } + return sb.toString(); + } + @Override + public void clear_objCount() { + objCount = 0; + objAryCount = 0; + System.out.println("clear count "+getClsName()); + } + //デフォルトコンストラクタの引数(プリミティブなので,必要としないはずだが) + @Override + public String getConstructorArgs() { + return " a "; + } + + // /** + // * オーバーライド + // */ + // public void detach(Anchor anchor){ + // super.detach(anchor); + // checkAtRefDetached(); + // } + // /** + // * オーバーライド + // */ + // public void attach(Anchor anchor){ + // super.attach(anchor); + // checkAtRefDetached(); + //// for(Anchor a: aryAnchors){ + //// a.anchortab.tooltip = null; + //// if (a.dest != null) a.dest.tooltip = null; + //// a.setAnchorEnabled(true); + //// } + // for(Anchor a: anchors_member){ //基本的にはcheckAtRefDetachedを利用し,アンカー有効化だけ,別に処理 + // a.setAnchorEnabled(true); //本当は,はずしたときには無効化をしないといけないのでは(だけど,全部外れたかどうかチェックする必要があるので大変) + // } + // } + // /** + // * リファレンスが切れたときに,チェックする + // */ + // public void checkAtRefDetached(){ + // HashSet temp = new HashSet(); + // for(Anchor a: anchors_incoming){ + // if (a.src.object != this) temp.add(a); + // a.anchortab.tooltip = null; + // } + // if (temp.size()==0){ + // tc.tick_transparency[0] = -0.05f; //一旦離したら早く消える + // tc.transparencyThread_Start(0, this); + // addAttribute("moveLink", null); + // } + // for(Anchor a: anchors_member){ + // a.anchortab.tooltip = null; + // if (a.dest != null) a.dest.tooltip = null; + // } + // tooltip = null; + // } + public void covis_addNode(int n){ + if (n < Integer.parseInt(this.val.getValue())){ + if (left.anchor.link.dest==null){ + + Covis_BTree cb = new Covis_BTree(buffer,true); + cb.val.setValue(String.valueOf(n));//本当は,コンストラクタで一緒にすべし + + buffer.putHistoryNew("method", cb, false); + buffer.objField.addObject(cb); + cb.attach(left.anchor); + cb.setOffsetAlignment(this, -60, 80); + } else { + ((Covis_BTree)left.anchor.link.dest).covis_addNode(n); + } + } else { + if (right.anchor.link.dest==null){ + Covis_BTree cb = new Covis_BTree(buffer,true); + cb.val.setValue(String.valueOf(n));//本当は,コンストラクタで一緒にすべし + + buffer.putHistoryNew("method", cb, false); + buffer.objField.addObject(cb); + cb.attach(right.anchor); + cb.setOffsetAlignment(this, 120, 80); + } else { + ((Covis_BTree)right.anchor.link.dest).covis_addNode(n); + } + } + } + public Covis_BTree covis_addNodeWithRet(int n){ + if (n < Integer.parseInt(this.val.getValue())){ + if (left.anchor.link.dest==null){ + + Covis_BTree cb = new Covis_BTree(buffer,true); + cb.val.setValue(String.valueOf(n));//本当は,コンストラクタで一緒にすべし + +// buffer.putHistoryMethodNew("method", cb, false); + buffer.objField.addObject(cb); + cb.attach(left.anchor); + cb.setOffsetAlignment(this, -60, 80); + return cb; + } else { + return ((Covis_BTree)left.anchor.link.dest).covis_addNodeWithRet(n); + } + } else { + if (right.anchor.link.dest==null){ + Covis_BTree cb = new Covis_BTree(buffer,true); + cb.val.setValue(String.valueOf(n));//本当は,コンストラクタで一緒にすべし + +// buffer.putHistoryMethodNew("method", cb, false); + buffer.objField.addObject(cb); + cb.attach(right.anchor); + cb.setOffsetAlignment(this, 120, 80); + return cb; + } else { + return ((Covis_BTree)right.anchor.link.dest).covis_addNodeWithRet(n); + } + } + } + public boolean covis_findNode(int n){ + int myval = Integer.parseInt(this.val.getValue()); + if (n == myval) return true; + if (n < myval){ + if (left.anchor.link.dest==null){ + return false; + } + else { + return ((Covis_BTree)left.anchor.link.dest).covis_findNode(n); + } + } else { + if (right.anchor.link.dest==null){ + return false; + } else { + return ((Covis_BTree)right.anchor.link.dest).covis_findNode(n); + } + } + } + public Covis_BTree covis_findNodeObj(int n){ + int myval = Integer.parseInt(this.val.getValue()); + if (n == myval) return this; + if (n < myval){ + if (left.anchor.link.dest==null){ + return null; + } + else { + return ((Covis_BTree)left.anchor.link.dest).covis_findNodeObj(n); + } + } else { + if (right.anchor.link.dest==null){ + return null; + } else { + return ((Covis_BTree)right.anchor.link.dest).covis_findNodeObj(n); + } + } + } + public String toString(){ + return "["+val.getValue()+"]"; + } + +// public Covis_BTree covis_add_and_return(int n){ +// if (n < Integer.parseInt(this.val.getValue())){ +// if (left.anchor.link.dest==null){ +// Covis_BTree cb = new Covis_BTree(buffer,true); +// cb.val.setValue(String.valueOf(n)); +//// buffer.objField.addObject(cb); +// cb.attach(left.anchor); +// cb.setOffsetAlignment(this, -60, 80); +// return cb; +// } else { +// ((Covis_BTree)left.anchor.link.dest).covis_add(n); +// } +// } else { +// if (right.anchor.link.dest==null){ +// Covis_BTree cb = new Covis_BTree(buffer,true); +// cb.val.setValue(String.valueOf(n)); +//// buffer.objField.addObject(cb); +// cb.attach(right.anchor); +// cb.setOffsetAlignment(this, 120, 80); +// return cb; +// } else { +// ((Covis_BTree)right.anchor.link.dest).covis_add(n); +// } +// } +// return null; +// } + + + public static String classdef = "" + +"public class BTree {\n"+ +" int val; \n"+ +" BTree left; \n"+ +" BTree right; \n"+ +" \n"+ +" public BTree() {\n"+ +" val = 5;\n"+ +" }\n"+ +" public BTree(int ival) {\n"+ +" val = ival;\n"+ +" }\n"+ +" public void addNode(int n){\n"+ +" if (n < val){\n"+ +" if (left == null) \n"+ +" left = new BTree(n);\n"+ +" else left.addNode(n);\n"+ +" } else {\n"+ +" if (right == null)\n"+ +" right = new BTree(n);\n"+ +" else right.addNode(n);\n"+ +" }\n"+ +" }\n"+ +" public BTree addNodeWithRet(int n){\n"+ +" if (n < val){\n"+ +" if (left == null){\n"+ +" left = new BTree(n);\n"+ +" return left;\n"+ +" } else left.addNodeWithRet(n);\n"+ +" } else {\n"+ +" if (right == null){\n"+ +" right = new BTree(n);\n"+ +" return right;\n"+ +" } else right.addNodeWithRet(n);\n"+ +" }\n"+ +" return null;"+ +" }\n"+ +" public boolean findNode(int n){\n"+ +" if (n == val) return true;\n"+ +" if (n < val){\n"+ +" if (left == null) \n"+ +" return false;\n"+ +" else return left.findNode(n);\n"+ +" } else {\n"+ +" if (right == null)\n"+ +" return false;\n"+ +" else return right.findNode(n);\n"+ +" }\n"+ +" }\n"+ +" public BTree findNodeObj(int n){\n"+ +" if (n == val) return this;\n"+ +" if (n < val){\n"+ +" if (left == null) \n"+ +" return null;\n"+ +" else return left.findNodeObj(n);\n"+ +" } else {\n"+ +" if (right == null)\n"+ +" return null;\n"+ +" else return right.findNodeObj(n);\n"+ +" }\n"+ +" }\n"+ +"}"; + + +} + +class BTreeConstructorDialog extends JDialog implements KeyListener { + private static final long serialVersionUID = 1852035735398130391L; + + JFrame parent; + + JTextField jtfa; + + JButton ok; + + boolean canceled = true; + + public BTreeConstructorDialog(JFrame p, Covis_BTree frac, String title, String mes1) { + super(p, title, true); + parent = p; + jtfa = new JTextField(frac.val.getValue()); + jtfa.setFont(SrcWindow.sans30); + jtfa.setBackground(Covis_int.defaultColor); + jtfa.addKeyListener(this);//Enterおしたら確定 + getContentPane().setLayout(new BorderLayout()); + getContentPane().add(new JLabelW(mes1), BorderLayout.NORTH); + JPanel inner = new JPanel(); + inner.setLayout(new GridLayout(1,2)); + inner.add(new JLabelW("a")); + inner.add(jtfa); + getContentPane().add(inner, BorderLayout.CENTER); + ok = new JButton("ok"); + getContentPane().add(ok, BorderLayout.SOUTH); + // pack(); + setSize(200,120); + setLocation(p.getLocation().x + (p.getWidth() - this.getWidth())/2, p.getLocation().y +(p.getHeight()-this.getHeight())/2); + + jtfa.setCaretPosition(jtfa.getText().length()); + + ok.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + canceled = false; + setVisible(false); + } + }); + // cancel.addActionListener(new ActionListener() { + // public void actionPerformed(ActionEvent e) { + // tarea = null; + // dispose(); + // } + // }); + + jtfa.addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { + jtfa = null; + dispose(); + } + } + }); + } + public boolean isCanceled(){ + return canceled; + } + + public static BTreeConstructorDialog showDialog(JFrame parent, Covis_BTree btre, String title, String mes1) { + BTreeConstructorDialog d = new BTreeConstructorDialog(parent, + btre, title, mes1); + d.setVisible(true); + if (d.jtfa != null){ + int v = Integer.parseInt(d.jtfa.getText()); + btre.val.setValue(String.valueOf(v)); + } + return d; + } + + @Override + public void keyPressed(KeyEvent arg0) { + if (arg0.getKeyCode() == KeyEvent.VK_ENTER){ + ok.doClick(); + } + } + @Override + public void keyReleased(KeyEvent arg0) { } + @Override + public void keyTyped(KeyEvent arg0) { } +} + diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_Frac.java b/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_Frac.java new file mode 100644 index 0000000..d2e1b43 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_Frac.java @@ -0,0 +1,427 @@ +package jaist.css.covis.cls; + +import jaist.css.covis.CoVisBuffer; +import jaist.css.covis.JLabelW; +import jaist.css.covis.SrcWindow; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; + +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JTextField; + +import edu.umd.cs.piccolo.nodes.PPath; +import edu.umd.cs.piccolo.nodes.PText; + +public class Covis_Frac extends Covis_Object { + + private static final long serialVersionUID = 8906063645409838445L; + public static Color defaultColor = new Color(200,170,255); + public Covis_Frac(CoVisBuffer buf, boolean isAuto){ + super(buf, isAuto); + color = defaultColor; + setPaint(color); + setStroke(basicStroke); + } + public Covis_Frac(Color c, CoVisBuffer buf, boolean isAuto){ + super(c, buf, isAuto); + } + Covis_int a,b; + // overwrite + public String getConstructorInfo() { +// return "new "+getClsName()+"("+valueText.getText()+"); // or, just "+valueText.getText(); + return "new "+getClsName()+"("+a.value+","+b.value+");"; + } + +// public String getConstructorArguments() { +// return a.value+", "+b.value; +// } + + public void init(boolean isAuto){ + setPathToRectangle(0, 0, 100,60); + PPath sep = PPath.createLine(60,7,40,55); + sep.setStroke(Covis_Object.basicStroke); + sep.addAttribute("moveTarget", this); + sep.addAttribute("tooltip", this); + addChild(sep); + + a = new Covis_int(buffer, isAuto); + a.addAttribute("moveTarget", this); + a.addAttribute("tooltip", this); + a.valueText.addAttribute("moveTarget", this); + a.valueText.addAttribute("tooltip", this); + a.setValue("2"); + b = new Covis_int(buffer, isAuto); + b.addAttribute("moveTarget", this); + b.addAttribute("tooltip", this); + b.valueText.addAttribute("moveTarget", this); + b.valueText.addAttribute("tooltip", this); + b.setValue("3"); + if (isAuto){ + } else { + FracConstructorDialog dialog = FracConstructorDialog.showDialog(buffer.getWindow().frame, this, "Constructor of Frac", "new Frac( a , b );"); + if (dialog.isCanceled()) { + this.setVisible(false); + return; + } + } + + a.setScale(0.8f); + b.setScale(0.8f); + a.offset(5, 5); + b.offset(63, 15); + addChild(a); + addChild(b); + + // インデックス値を右肩にはりつける + PText ptidx = new PText("a"); + ptidx.setScale(0.6); + ptidx.setOffset(18,5); + ptidx.setTextPaint(Color.blue); + addChild(ptidx); + ptidx.addAttribute("moveTarget", this); + ptidx.addAttribute("tooltip", this); + + PText ptidx2 = new PText("b"); + ptidx2.setScale(0.6); + ptidx2.setOffset(77,15); + ptidx2.setTextPaint(Color.blue); + addChild(ptidx2); + ptidx2.addAttribute("moveTarget", this); + ptidx2.addAttribute("tooltip", this); + } + public Covis_Object Covis_clone(boolean isAuto){ + return new Covis_Frac(buffer, isAuto); + } + public Color getClassColor(){ + return defaultColor; + } + + public static int objCount = 0; + public static int objAryCount = 0; + public String getNextVarName(boolean isAry){ + StringBuffer sb = new StringBuffer(getClsName().toLowerCase().substring(0,4)); + if (isAry) { + objAryCount++; + sb.append("Ary"); + sb.append(objAryCount); + } else { + objCount++; + sb.append(objCount); + } + return sb.toString(); + } + @Override + public void clear_objCount() { + objCount = 0; + objAryCount = 0; + System.out.println("clear count "+getClsName()); + } + //デフォルトコンストラクタの引数(プリミティブなので,必要としないはずだが) + @Override + public String getConstructorArgs() { + return " a, b "; + } + + public void covis_reduce(){ + int ia = Integer.valueOf(a.value); + int ib = Integer.valueOf(b.value); + if (ib == 0) return; + int g = gcd(ia,ib); + ia = ia/g; + ib = ib/g; + a.setValue(String.valueOf(ia)); + b.setValue(String.valueOf(ib)); + } + public int gcd(int m, int n){ + while (m != n) { + if (m < n) { + n -= m; + } else { + m -= n; + } + } + return n; + } + ///////////////////////////////////////////////////////////////////////////////////// +/* public float covis_getFloatValue(){ + int ia = Integer.valueOf(a.value); + int ib = Integer.valueOf(b.value); + System.out.println("in method "+(float)ia/ib); + return ((float)ia/(float)ib); + } + public int covis_getBunsi(){ + int ia = Integer.valueOf(a.value); + System.out.println("in method "+ia); + return ia; + } + public int covis_getBumbo(){ + int ib= Integer.valueOf(b.value); + System.out.println("in method "+ib); + return ib; + }*/ + public void covis_setBunsiBumbo(int fa, int fb){ + a.setValue(String.valueOf(fa)); + b.setValue(String.valueOf(fb)); + } + public String covis_print(){ + return toString(); + } + public Covis_Frac covis_plus_new(Covis_Frac other){ + int ia = Integer.valueOf(a.value); + int ib = Integer.valueOf(b.value); + int oa = Integer.valueOf(other.a.value); + int ob = Integer.valueOf(other.b.value); + if (ib == 0 || ob == 0) return null; + ia = (ia*ob)+(oa*ib); + ib = ib * ob; + Covis_Frac cf = new Covis_Frac(buffer,true); + cf.a.setValue(String.valueOf(ia)); + cf.b.setValue(String.valueOf(ib)); + return cf; + } + public void covis_plus(Covis_Frac other){ + int ia = Integer.valueOf(a.value); + int ib = Integer.valueOf(b.value); + int oa = Integer.valueOf(other.a.value); + int ob = Integer.valueOf(other.b.value); + if (ib == 0 || ob == 0) return; + ia = (ia*ob)+(oa*ib); + ib = ib * ob; + a.setValue(String.valueOf(ia)); + b.setValue(String.valueOf(ib)); + } + public void covis_minus(Covis_Frac other){ + int ia = Integer.valueOf(a.value); + int ib = Integer.valueOf(b.value); + int oa = Integer.valueOf(other.a.value); + int ob = Integer.valueOf(other.b.value); + if (ib == 0 || ob == 0) return; + ia = (ia*ob)-(oa*ib); + ib = ib * ob; + a.setValue(String.valueOf(ia)); + b.setValue(String.valueOf(ib)); + } + public Covis_Frac covis_minus_new(Covis_Frac other){ + int ia = Integer.valueOf(a.value); + int ib = Integer.valueOf(b.value); + int oa = Integer.valueOf(other.a.value); + int ob = Integer.valueOf(other.b.value); + if (ib == 0 || ob == 0) return null; + ia = (ia*ob)-(oa*ib); + ib = ib * ob; + Covis_Frac cf = new Covis_Frac(buffer,true); + cf.a.setValue(String.valueOf(ia)); + cf.b.setValue(String.valueOf(ib)); + return cf; + } + + public void covis_mul(Covis_Frac other){ + int ia = Integer.valueOf(a.value); + int ib = Integer.valueOf(b.value); + int oa = Integer.valueOf(other.a.value); + int ob = Integer.valueOf(other.b.value); + if (ib == 0 || ob == 0) return; + ia = ia * oa; + ib = ib * ob; + a.setValue(String.valueOf(ia)); + b.setValue(String.valueOf(ib)); + } + public Covis_Frac covis_mul_new(Covis_Frac other){ + int ia = Integer.valueOf(a.value); + int ib = Integer.valueOf(b.value); + int oa = Integer.valueOf(other.a.value); + int ob = Integer.valueOf(other.b.value); + if (ib == 0 || ob == 0) return null; + ia = ia * oa; + ib = ib * ob; + Covis_Frac cf = new Covis_Frac(buffer,true); + cf.a.setValue(String.valueOf(ia)); + cf.b.setValue(String.valueOf(ib)); + return cf; + } + public void covis_div(Covis_Frac other){ + int ia = Integer.valueOf(a.value); + int ib = Integer.valueOf(b.value); + int oa = Integer.valueOf(other.a.value); + int ob = Integer.valueOf(other.b.value); + if (ib == 0 || ob == 0) return; + ia = ia * ob; + ib = ib * oa; + a.setValue(String.valueOf(ia)); + b.setValue(String.valueOf(ib)); + } + public Covis_Frac covis_div_new(Covis_Frac other){ + int ia = Integer.valueOf(a.value); + int ib = Integer.valueOf(b.value); + int oa = Integer.valueOf(other.a.value); + int ob = Integer.valueOf(other.b.value); + if (ib == 0 || ob == 0) return null; + ia = ia * ob; + ib = ib * oa; + Covis_Frac cf = new Covis_Frac(buffer,true); + cf.a.setValue(String.valueOf(ia)); + cf.b.setValue(String.valueOf(ib)); + return cf; + } + public String toString(){ + return a.value+"/"+b.value; + } + + public static String classdef = "public class Frac {\n"+ +" int a; //bunsi\n"+ +" int b; //bumbo\n"+ +"\n"+ +" public Frac() {\n"+ +" a = 2; b = 3;\n"+ +" }\n"+ +" public Frac(int ia, int ib) {\n"+ +" a = ia; b = ib;\n"+ +" }\n"+ +//" public float getFloatValue(){\n"+ +//" return ((float)a/(float)b);\n"+ +//" }\n"+ +" public void setBunsiBumbo(int fa, int fb){\n"+ +" a = fa; b = fb;\n"+ +" }\n"+ +" public void print(){\n"+ +" System.out.println(a+\"/\"+b);\n"+ +" }\n"+ +" public void plus(Frac f){\n"+ +" int na = a * f.b + b * f.a;\n"+ +" int nb = b * f.b;\n"+ +" a = na; b = nb;\n"+ +" }\n"+ +" public Frac plus_new(Frac f){\n"+ +" int na = a * f.b + b * f.a;\n"+ +" int nb = b * f.b;\n"+ +" return new Frac(na,nb);\n"+ +" }\n"+ +" public void minus(Frac f){ } //omit\n"+ +" public Frac minus_new(Frac f){ } //omit\n"+ +" public void mul(Frac f){ } //omit\n"+ +" public Frac mul_new(Frac f){ } //omit\n"+ +" public void div(Frac f){ } //omit\n"+ +" public Frac div_new(Frac f){ } //omit\n"+ +" public void reduce(){ //yakubun \n"+ +" int g = gcd(a,b);\n"+ +" a = a/g; b = b/g;\n"+ +" }\n"+ +" public int gcd(int m, int n){\n"+ +" while (m != n) {\n"+ +" if (m < n) { n -= m; }\n"+ +" else { m -= n; }\n"+ +" }\n"+ +" return n;\n"+ +" }\n"+ +"}\n"; + +} + +class FracConstructorDialog extends JDialog implements KeyListener { + private static final long serialVersionUID = 1852035735398130391L; + + JFrame parent; + + JTextField jtfa, jtfb; + + JButton ok; + boolean canceled = true; + + public FracConstructorDialog(JFrame p, Covis_Frac frac, String title, String mes1) { + super(p, title, true); + parent = p; + jtfa = new JTextField(frac.a.getValue()); + jtfa.setFont(SrcWindow.sans30); + jtfa.setBackground(Covis_int.defaultColor); + jtfa.addKeyListener(this); + jtfb = new JTextField(frac.b.getValue()); + jtfb.setFont(SrcWindow.sans30); + jtfb.setBackground(Covis_int.defaultColor); + jtfb.addKeyListener(this); + getContentPane().setLayout(new BorderLayout()); + getContentPane().add(new JLabelW(mes1), BorderLayout.NORTH); + JPanel inner = new JPanel(); + inner.setLayout(new GridLayout(2,2)); + inner.add(new JLabelW("a")); + inner.add(jtfa); + inner.add(new JLabelW("b")); + inner.add(jtfb); + getContentPane().add(inner, BorderLayout.CENTER); + ok = new JButton("ok"); + getContentPane().add(ok, BorderLayout.SOUTH); +// pack(); + setSize(200,180); + setLocation(p.getLocation().x + (p.getWidth() - this.getWidth())/2, p.getLocation().y +(p.getHeight()-this.getHeight())/2); + + jtfa.setCaretPosition(jtfa.getText().length()); + jtfb.setCaretPosition(jtfb.getText().length()); + + ok.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + canceled = false; + setVisible(false); + } + }); +// cancel.addActionListener(new ActionListener() { +// public void actionPerformed(ActionEvent e) { +// tarea = null; +// dispose(); +// } +// }); + + jtfa.addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { + jtfa = null; + jtfb = null; + dispose(); + } + } + }); + jtfb.addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { + jtfa = null; + jtfb = null; + dispose(); + } + } + }); + } + @Override + public void keyPressed(KeyEvent arg0) { + if (arg0.getKeyCode() == KeyEvent.VK_ENTER){ + ok.doClick(); + } + } + @Override + public void keyReleased(KeyEvent arg0) { } + @Override + public void keyTyped(KeyEvent arg0) { } + + public boolean isCanceled(){ + return canceled; + } + + public static FracConstructorDialog showDialog(JFrame parent, Covis_Frac frac, String title, String mes1) { + FracConstructorDialog d = new FracConstructorDialog(parent, + frac, title, mes1); + d.setVisible(true); + if (d.jtfa != null && d.jtfb != null){ + frac.a.setValue(String.valueOf(Integer.parseInt(d.jtfa.getText()))); + frac.b.setValue(String.valueOf(Integer.parseInt(d.jtfb.getText()))); + } + return d; + } +} + diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_LinkList.java b/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_LinkList.java new file mode 100644 index 0000000..38da98c --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_LinkList.java @@ -0,0 +1,429 @@ +package jaist.css.covis.cls; + +import jaist.css.covis.CoVisBuffer; +import jaist.css.covis.JLabelW; +import jaist.css.covis.SrcWindow; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; + +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JTextField; + +import edu.umd.cs.piccolo.nodes.PText; + +public class Covis_LinkList extends Covis_Object { + + private static final long serialVersionUID = 8906063645409838445L; + public static Color defaultColor = new Color(255,153,204); + public Covis_LinkList(CoVisBuffer buf, boolean isAuto){ + super(buf, isAuto); + color = defaultColor; + setPaint(color); + setStroke(basicStroke); + } + public Covis_LinkList(Color c, CoVisBuffer buf, boolean isAuto){ + super(c, buf, isAuto); + } + Covis_int val; + VariableM next; + // overwrite + public String getConstructorInfo() { + // return "new "+getClsName()+"("+valueText.getText()+"); // or, just "+valueText.getText(); + return "new "+getClsName()+"("+val.value+");"; + } + + // public String getConstructorArguments() { + // return a.value+", "+b.value; + // } + + public void init(boolean isAuto){ + setPathToRectangle(0, 0, 100,60); + + val = new Covis_int(buffer, isAuto); + val.valueText.addAttribute("moveTarget", this); + val.valueText.addAttribute("tooltip", this); + + val.setValue("3"); + if (isAuto){ + } else { + LinkListConstructorDialog dialog = LinkListConstructorDialog.showDialog(buffer.getWindow().frame, this, "Constructor of LinkList", "new LinkList( a );"); + if (dialog.isCanceled()) { + this.setVisible(false); + return; + } + } + + val.setScale(0.9f); + val.addAttribute("moveTarget", this); + val.addAttribute("tooltip", this); + val.offset(13, 9); + addChild(val); + + // インデックス値を右肩にはりつける + PText ptidx0 = new PText("var"); + ptidx0.setScale(0.6); + ptidx0.setOffset(24,1); + ptidx0.setTextPaint(Color.blue); + addChild(ptidx0); + ptidx0.addAttribute("moveTarget", this); + ptidx0.addAttribute("tooltip", this); + + + PText ptidx = new PText("next"); + ptidx.setScale(0.6); + ptidx.setOffset(68,13); + ptidx.setTextPaint(Color.blue); + addChild(ptidx); + ptidx.addAttribute("moveTarget", this); + ptidx.addAttribute("tooltip", this); + + // PText ptidx2 = new PText("right"); + // ptidx2.setScale(0.6); + // ptidx2.setOffset(77,25); + // ptidx2.setTextPaint(Color.blue); + // addChild(ptidx2); + // ptidx2.addAttribute("moveTarget", this); + // ptidx2.addAttribute("tooltip", this); + + // left = new VariableM(this,null,buffer,"left",this); + next = new VariableM(this, null, buffer,"next",this);//new Anchor(this.getClass(), this); + + // addChild(left); + // left.setOffset(5,35); + addChild(next); + next.setOffset(65,23); + // anchors_member.add(left.anchor); + anchors_member.add(next.anchor); + // left.addAttribute("moveTarget", this); + // left.addAttribute("tooltip", this); + next.addAttribute("moveTarget", this); + next.addAttribute("tooltip", this); + + buffer.putHistoryVar("var", next, false); + // buffer.putHistoryVar("var", left, false); + + + } + public Covis_Object Covis_clone(boolean isAuto){ + return new Covis_LinkList(buffer, isAuto); + } + public Color getClassColor(){ + return defaultColor; + } + + public static int objCount = 0; + public static int objAryCount = 0; + public String getNextVarName(boolean isAry){ + StringBuffer sb = new StringBuffer(getClsName().toLowerCase().substring(0,4)); + if (isAry) { + objAryCount++; + sb.append("Ary"); + sb.append(objAryCount); + } else { + objCount++; + sb.append(objCount); + } + return sb.toString(); + } + @Override + public void clear_objCount() { + objCount = 0; + objAryCount = 0; + System.out.println("clear count "+getClsName()); + } + //デフォルトコンストラクタの引数(プリミティブなので,必要としないはずだが) + @Override + public String getConstructorArgs() { + return " a "; + } + + // /** + // * オーバーライド + // */ + // public void detach(Anchor anchor){ + // super.detach(anchor); + // checkAtRefDetached(); + // } + // /** + // * オーバーライド + // */ + // public void attach(Anchor anchor){ + // super.attach(anchor); + // checkAtRefDetached(); + //// for(Anchor a: aryAnchors){ + //// a.anchortab.tooltip = null; + //// if (a.dest != null) a.dest.tooltip = null; + //// a.setAnchorEnabled(true); + //// } + // for(Anchor a: anchors_member){ //基本的にはcheckAtRefDetachedを利用し,アンカー有効化だけ,別に処理 + // a.setAnchorEnabled(true); //本当は,はずしたときには無効化をしないといけないのでは(だけど,全部外れたかどうかチェックする必要があるので大変) + // } + // } + // /** + // * リファレンスが切れたときに,チェックする + // */ + // public void checkAtRefDetached(){ + // HashSet temp = new HashSet(); + // for(Anchor a: anchors_incoming){ + // if (a.src.object != this) temp.add(a); + // a.anchortab.tooltip = null; + // } + // if (temp.size()==0){ + // tc.tick_transparency[0] = -0.05f; //一旦離したら早く消える + // tc.transparencyThread_Start(0, this); + // addAttribute("moveLink", null); + // } + // for(Anchor a: anchors_member){ + // a.anchortab.tooltip = null; + // if (a.dest != null) a.dest.tooltip = null; + // } + // tooltip = null; + // } + public void covis_addNode(int n){ + if (next.anchor.link.dest==null){ + Covis_LinkList cb = new Covis_LinkList(buffer,true); + cb.val.setValue(String.valueOf(n));//本当は,コンストラクタで一緒にすべし + + buffer.putHistoryNew("method", cb, false); + buffer.objField.addObject(cb); + cb.attach(next.anchor); + cb.setOffsetAlignment(this, 120, 80); + } else { + ((Covis_LinkList)next.anchor.link.dest).covis_addNode(n); + } + + } + public Covis_LinkList covis_addNodeWithRet(int n){ + if (next.anchor.link.dest==null){ + Covis_LinkList cb = new Covis_LinkList(buffer,true); + cb.val.setValue(String.valueOf(n));//本当は,コンストラクタで一緒にすべし + + // buffer.putHistoryMethodNew("method", cb, false); + buffer.objField.addObject(cb); + cb.attach(next.anchor); + cb.setOffsetAlignment(this, 120, 80); + return cb; + } else { + return ((Covis_LinkList)next.anchor.link.dest).covis_addNodeWithRet(n); + } + + } + public boolean covis_findNode(int n){ + int myval = Integer.parseInt(this.val.getValue()); + if (n == myval) return true; + if (next.anchor.link.dest==null){ + return false; + } else { + return ((Covis_LinkList)next.anchor.link.dest).covis_findNode(n); + } + } + public Covis_LinkList covis_findNodeObj(int n){ + int myval = Integer.parseInt(this.val.getValue()); + if (n == myval) return this; + if (n < myval){ + // if (left.anchor.link.dest==null){ + // return null; + // } + // else { + // return ((Covis_LinkList)left.anchor.link.dest).covis_findNodeObj(n); + // } + return null; + + } else { + if (next.anchor.link.dest==null){ + return null; + } else { + return ((Covis_LinkList)next.anchor.link.dest).covis_findNodeObj(n); + } + } + } + public String toString(){ + return "["+val.getValue()+"]"; + } + + // public Covis_BTree covis_add_and_return(int n){ + // if (n < Integer.parseInt(this.val.getValue())){ + // if (left.anchor.link.dest==null){ + // Covis_BTree cb = new Covis_BTree(buffer,true); + // cb.val.setValue(String.valueOf(n)); + //// buffer.objField.addObject(cb); + // cb.attach(left.anchor); + // cb.setOffsetAlignment(this, -60, 80); + // return cb; + // } else { + // ((Covis_BTree)left.anchor.link.dest).covis_add(n); + // } + // } else { + // if (right.anchor.link.dest==null){ + // Covis_BTree cb = new Covis_BTree(buffer,true); + // cb.val.setValue(String.valueOf(n)); + //// buffer.objField.addObject(cb); + // cb.attach(right.anchor); + // cb.setOffsetAlignment(this, 120, 80); + // return cb; + // } else { + // ((Covis_BTree)right.anchor.link.dest).covis_add(n); + // } + // } + // return null; + // } + + + public static String classdef = "" + + "public class BTree {\n"+ + " int val; //数値\n"+ + " BTree left; //左リンク\n"+ + " BTree right; //右リンク\n"+ + " \n"+ + " public BTree() {\n"+ + " val = 5;\n"+ + " }\n"+ + " public BTree(int ival) {\n"+ + " val = ival;\n"+ + " }\n"+ + " public void addNode(int n){\n"+ + " if (n < val){\n"+ + " if (left == null) \n"+ + " left = new BTree(n);\n"+ + " else left.addNode(n);\n"+ + " } else {\n"+ + " if (right == null)\n"+ + " right = new BTree(n);\n"+ + " else right.addNode(n);\n"+ + " }\n"+ + " }\n"+ + " public BTree addNodeWithRet(int n){\n"+ + " if (n < val){\n"+ + " if (left == null){\n"+ + " left = new BTree(n);\n"+ + " return left;\n"+ + " } else left.addNodeWithRet(n);\n"+ + " } else {\n"+ + " if (right == null){\n"+ + " right = new BTree(n);\n"+ + " return right;\n"+ + " } else right.addNodeWithRet(n);\n"+ + " }\n"+ + " return null;"+ + " }\n"+ + " public boolean findNode(int n){\n"+ + " if (n == val) return true;\n"+ + " if (n < val){\n"+ + " if (left == null) \n"+ + " return false;\n"+ + " else return left.findNode(n);\n"+ + " } else {\n"+ + " if (right == null)\n"+ + " return false;\n"+ + " else return right.findNode(n);\n"+ + " }\n"+ + " }\n"+ + " public BTree findNodeObj(int n){\n"+ + " if (n == val) return this;\n"+ + " if (n < val){\n"+ + " if (left == null) \n"+ + " return null;\n"+ + " else return left.findNodeObj(n);\n"+ + " } else {\n"+ + " if (right == null)\n"+ + " return null;\n"+ + " else return right.findNodeObj(n);\n"+ + " }\n"+ + " }\n"+ + "}"; + + +} + +class LinkListConstructorDialog extends JDialog implements KeyListener { + private static final long serialVersionUID = 1852035735398130391L; + + JFrame parent; + + JTextField jtfa; + + JButton ok; + + boolean canceled = true; + + public LinkListConstructorDialog(JFrame p, Covis_LinkList frac, String title, String mes1) { + super(p, title, true); + parent = p; + jtfa = new JTextField(frac.val.getValue()); + jtfa.setFont(SrcWindow.sans30); + jtfa.setBackground(Covis_int.defaultColor); + jtfa.addKeyListener(this);//Enterおしたら確定 + getContentPane().setLayout(new BorderLayout()); + getContentPane().add(new JLabelW(mes1), BorderLayout.NORTH); + JPanel inner = new JPanel(); + inner.setLayout(new GridLayout(1,2)); + inner.add(new JLabelW("a")); + inner.add(jtfa); + getContentPane().add(inner, BorderLayout.CENTER); + ok = new JButton("ok"); + getContentPane().add(ok, BorderLayout.SOUTH); + // pack(); + setSize(200,120); + setLocation(p.getLocation().x + (p.getWidth() - this.getWidth())/2, p.getLocation().y +(p.getHeight()-this.getHeight())/2); + + jtfa.setCaretPosition(jtfa.getText().length()); + + ok.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + canceled = false; + setVisible(false); + } + }); + // cancel.addActionListener(new ActionListener() { + // public void actionPerformed(ActionEvent e) { + // tarea = null; + // dispose(); + // } + // }); + + jtfa.addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { + jtfa = null; + dispose(); + } + } + }); + } + public boolean isCanceled(){ + return canceled; + } + + public static LinkListConstructorDialog showDialog(JFrame parent, Covis_LinkList btre, String title, String mes1) { + LinkListConstructorDialog d = new LinkListConstructorDialog(parent, + btre, title, mes1); + d.setVisible(true); + if (d.jtfa != null){ + int v = Integer.parseInt(d.jtfa.getText()); + btre.val.setValue(String.valueOf(v)); + } + return d; + } + + @Override + public void keyPressed(KeyEvent arg0) { + if (arg0.getKeyCode() == KeyEvent.VK_ENTER){ + ok.doClick(); + } + } + @Override + public void keyReleased(KeyEvent arg0) { } + @Override + public void keyTyped(KeyEvent arg0) { } +} + diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_Object.java b/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_Object.java new file mode 100644 index 0000000..99e0be7 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_Object.java @@ -0,0 +1,405 @@ +package jaist.css.covis.cls; + +import jaist.css.covis.CoVisBuffer; +import jaist.css.covis.ToolTipProvider; +import jaist.css.covis.hist.CVHist_New; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.geom.Point2D; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Hashtable; +import java.util.TreeMap; + +import javax.swing.JFrame; + +import edu.umd.cs.piccolo.PNode; +import edu.umd.cs.piccolo.activities.PActivity; +import edu.umd.cs.piccolo.nodes.PText; +import edu.umd.cs.piccolo.util.PDimension; + +public class Covis_Object extends Covis_Type implements ToolTipProvider, ToFront, Move { + public static BasicStroke basicStroke = new BasicStroke(3f,BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 90.0f); + public static BasicStroke dottedStroke = new BasicStroke(3f,BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 90.0f, new float[]{5,10},0); + public static BasicStroke thinStroke = new BasicStroke(1.5f,BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 90.0f); + + // float[] dash = { DASH_WIDTH, DASH_WIDTH }; + // strokes = new Stroke[NUM_STROKES]; + // for (int i = 0; i < NUM_STROKES; i++) { + // strokes[i] = new BasicStroke(2, BasicStroke.CAP_BUTT, + // BasicStroke.JOIN_MITER, 1, dash, i); + // } + + private static final long serialVersionUID = 1676721160662045517L; + public static int objCount = 0; + public static int objAryCount = 0; + public String getNextVarName(boolean isAry){ + StringBuffer sb = new StringBuffer(getClsName().toLowerCase().substring(0,3)); + if (isAry) { + objAryCount++; + sb.append("Ary"); + sb.append(objAryCount); + } else { + objCount++; + sb.append(objCount); + } + return sb.toString(); + } + + public CovisObj_TransparencyControl tc; + + public static Color defaultColor = new Color(255,255,222); + public Color color; + + // 複数リンクからの参照がありうるので,HashSet + public HashSet anchors_incoming; + public ArrayList anchors_member; + + // public Hashtable myrefs; + + public PText tooltip; + + long toFront_ts; + public Class type; + + public CVHist_New cvhist; + public CoVisBuffer buffer; + public boolean isAuto; + + public Covis_Object(CoVisBuffer buf, boolean isAuto) throws NullPointerException{ + buffer = buf; + anchors_member = new ArrayList(); + // myrefs = new Hashtable(); + init(isAuto); + color = defaultColor; + setPaint(color); + tc = new CovisObj_TransparencyControl(this); + anchors_incoming = new HashSet(); + addAttribute("tooltip", this); + setStroke(dottedStroke); + type = getClass(); + } + public Covis_Object(Color c, CoVisBuffer buf, boolean isAuto){ + this(buf, isAuto); + color = c; + setPaint(color); + } + public void init(boolean isAuto){ + setPathToRectangle(0, 0, 80 ,50); + } + public String getClsName(){ + int p = getClass().getName().lastIndexOf("_"); + return getClass().getName().substring(p+1); + } + private boolean isSelected; + private boolean isHighlighted; + public Covis_Object defaultObject; + + public Covis_Object Covis_clone(){ + return new Covis_Object(buffer,true); + } + public Covis_Object createNew(JFrame f, boolean isAuto) throws InvocationTargetException{ + return newInstance(isAuto); + } + public Covis_Object newInstance(boolean isAuto) throws InvocationTargetException { + Constructor constructor; + Covis_Object cv_class = null; + try { + constructor = getClass().getConstructor(CoVisBuffer.class, boolean.class); + cv_class = (Covis_Object) constructor.newInstance(buffer,isAuto); + } catch (SecurityException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + return cv_class; + } + public void setHighlight(boolean f){ + isHighlighted = f; + } + public boolean isHighlighted(){ + return isHighlighted; + } + public void setSelected(boolean s){ + isSelected = s; + } + public boolean isSelected(){ + return isSelected; + } + public Color getClassColor(){ + return defaultColor; + } + public void attach(Anchor anchor){ + if (getTransparency()<0.1f) return; //あまり薄かったらアタッチさせません + // System.out.println("at "+toString()); + Informer.playSound("Laser2.wav"); + + if (anchor.link.dest != null && anchor.link.dest != this) return; //anchor.link.dest.detach(anchor); + anchors_incoming.add(anchor); + anchor.link.dest = this; + anchor.destObject = this;//これがないと,BTreeアンリンクのときに消えない + addAttribute("moveLink", anchor.link); + tc.transparencyThread_Start(1, this, 100); + // setTransparency(1.0f); + // anchor.anchortab.tooltip = null; + tooltip = null; + // move(new PDimension()); + anchor.toFront(System.currentTimeMillis()); + for(Anchor a: anchors_incoming){ + a.start_RewindThread(); + // a.anchortab.tooltip = null; + } + // anchor.lastAttach = null; + //ここで,有効な変数からリンクされているかチェックし,setAnchorEnabledを再設定する.アタッチもデタッチも共通 + setMemberVariableEnabled(checkValidVariable(new Hashtable())); + buffer.objField.clearObjVarName(); + buffer.varField.updateVarNameChain(); + + buffer.putHisotryLink("lnk", anchor, this); + anchor.lastDestObject = this; + } + public void setMemberVariableEnabled(boolean checkValidVariable) { + // if (anchors_member == null) return; + for(Anchor a: anchors_member){ + a.srcVariable.setEnabled(checkValidVariable); + // a.setAnchorEnabled(checkValidVariable); + } + } + public boolean checkValidVariable(Hashtable checked) { + if (checked.containsKey(this.hashCode())) return false; + checked.put(this.hashCode(), this); + boolean b = false; + for(Anchor a: anchors_incoming){ + if (a.srcVariable.object == null) return true; //Variableだから + if (a.srcVariable instanceof VariableM){ + VariableM vm = (VariableM) a.srcVariable; + if (vm.object instanceof Covis_Object){ + if (((Covis_Object)vm.object).checkValidVariable(checked)) b = true; + } + } + } + return b; + } + public void appendVarNameRecursive(Variable v, Hashtable checked) { + if (checked.containsKey(this.hashCode())) return; + checked.put(this.hashCode(), this); + // myrefs.put(v.getVarName(), v.cv_class); + for(Anchor a: anchors_member){ + for(String s: v.getVarNamesAry()){ +// System.out.println(" addVarNames "+s+ " to "+a.srcVariable.getBaseVarName()); + a.srcVariable.addVarNames(s); + } + a.srcVariable.appendVarNameRecursive(checked); + } + } + + public void detach(Anchor anchor){ +// System.out.println("detach "+toString()); + // Informer.playSound("Default.wav"); + anchors_incoming.remove(anchor); + anchor.destObject = null;//ここはまだ切らない.その都合上,ここに変数再編成を書くことができない,はウソでした. + anchor.link.dest = null; //ここは切らないと,リンク線が残る + + setMemberVariableEnabled(checkValidVariable(new Hashtable())); + buffer.objField.clearObjVarName(); + buffer.varField.updateVarNameChain(); + + + if (anchors_incoming.size()==0 || !checkValidVariable(new Hashtable()) ){ + // System.out.println("hogehoge"); + tc.tick_transparency[0] = -0.05f; //一旦離したら早く消える + tc.transparencyThread_Start(0, this, 100); + addAttribute("moveLink", null); + } + tooltip = null; + // move(new PDimension()); + for(Anchor a: anchors_incoming){ + a.start_RewindThread(); + // a.anchortab.tooltip = null; + } +// anchor.lastDestObject = null; + + } + public void detachAll() { + HashSet set = new HashSet(anchors_incoming); + for(Anchor a:set){ + detach(a); + a.destObject = null; + } + // if (anchors_member == null) return; + HashSet set2 = new HashSet(anchors_member); + for(Anchor a:set2){ + if (a.destObject == null) continue; + a.destObject.detach(a); + } + } + public int attachPointOffset(Anchor mya) { + if (anchors_incoming.size()==1) return 0; + TreeMap map = new TreeMap(); + for(Anchor p: anchors_incoming) { + double y = p.getGlobalTranslation().getY(); + while(map.get(y)!=null) y+=0.01; + map.put(y, p); + } + int yy = 0; + for(Anchor a: map.values()){ + if (a == mya) return yy; + yy += 10; + } + return 0; + } + public String referenceVarNames(){ + if (anchors_incoming.size()==0) return null; + StringBuffer sb = new StringBuffer(); + for(Anchor a: anchors_incoming){ + sb.append(a.srcVariable.getVarName()+"\n"); + } + +// TreeMap map = new TreeMap(); +// for(Anchor p: anchors_incoming) { +// double yy = p.getGlobalTranslation().getY(); +// while (map.get(yy)!= null) yy+=0.01; +// map.put(yy, p); +// } +// for(Anchor a: map.values()){ +// sb.append(a.getVarName()+"\n"); +// } + return sb.toString().substring(0, sb.length()-1); + } + public ArrayList referenceVarNamesAry(){ + ArrayList temp = new ArrayList(); + for(Anchor a: anchors_incoming){ + temp.addAll(a.srcVariable.getVarNamesAry()); + } + return temp; + } + // anchors_incoming をハッシュにして返す + public TreeMap referenceAnchors(){ + TreeMap map = new TreeMap(); + for(Anchor p: anchors_incoming){ + map.put(p.getVarName(), p); + } + return map; + } + //TODO:ツールチップ + public PNode getToolTipNode(){ + tooltip = null; + if (tooltip == null) { + PText pt = new PText(referenceVarNames()+"\n(hash "+ String.valueOf(hashCode())+")"); + pt.setPaint(Color.white); + tooltip = pt; + } + return tooltip; + } + + /** + * ToFrontインタフェースの実装 + */ + public void toFront(long ts) { + if (toFront_ts == ts) return; + toFront_ts = ts; + + PNode parent = getParent(); + if (parent != null){ + // removeFromParent(); + parent.addChild(this); + if (parent instanceof ToFront) ((ToFront)parent).toFront(ts); + if (parent.getAttribute("toFront")!=null){ + ((ToFront)parent.getAttribute("toFront")).toFront(ts); + } + for(Anchor p: anchors_incoming){ + p.toFront(ts); + } + } + } + public void checkAtRefDetached(){ + } + public void dispose(){ + // System.out.println("disposed"); + buffer.updateSourceWindow(); + } + public void move(PDimension d){ + translate(d.getWidth(), d.getHeight()); //履歴に関係ない動作 + for(Anchor a: anchors_incoming){ + a.start_RewindThread(); + } + for(Anchor a: anchors_member){ + a.start_RewindThread(); + } + } + @Override + public PNode createToolTip() { + try { + return newInstance(true); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + return null; + } + public String getConstructorInfo() { + return "new "+getClsName()+"();"; + } + // public String getConstructorArguments() { + // return ""; + // } + public void setCVHist(CVHist_New _cvhist) { + cvhist = _cvhist; + } + public static String getClsNameStatic(Class elementType) { + // System.out.println(elementType.getSimpleName()); + int p = elementType.getSimpleName().lastIndexOf("_"); + return elementType.getSimpleName().substring(p+1); + } + @Override + public void clear_objCount() { + try { + Field f = getClass().getField("objCount"); + f.setInt(getClass(), 0); + Field fg = getClass().getField("objAryCount"); + fg.setInt(getClass(), 0); + } catch (SecurityException e) { + e.printStackTrace(); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + //デフォルトコンストラクタの引数 + @Override + public String getConstructorArgs() { + return ""; + } + public void setOffsetAlignment(Covis_Object o, int dx, int dy){ + Point2D pos = o.getOffset(); + Point2D newpos = new Point2D.Double(pos.getX()+dx, pos.getY()+dy); + setOffset(newpos); + } + public Covis_String covis_toString(){ + Covis_String cs = new Covis_String(buffer,true); + cs.setValues(toString()); + buffer.putHistoryNew("new", cs, false); + return cs; + } + public String toString(){ + return String.valueOf(hashCode()); + } + public PActivity animateToZoom(float f, long l) { + PActivity p = animateToPositionScaleRotation(getOffset().getX(), getOffset().getY(), f, 0, l); + return p; + } + + +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_Oval.java b/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_Oval.java new file mode 100644 index 0000000..9ac2f0a --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_Oval.java @@ -0,0 +1,50 @@ +package jaist.css.covis.cls; + +import jaist.css.covis.CoVisBuffer; + +import java.awt.Color; + +public class Covis_Oval extends Covis_Object { + + private static final long serialVersionUID = 8906063645409838445L; + public static Color defaultColor = new Color(244,190,236); + public Covis_Oval(CoVisBuffer buf, boolean isAuto){ + super(buf, isAuto); + color = defaultColor; + setPaint(color); + setStroke(basicStroke); + } + public Covis_Oval(Color c, CoVisBuffer buf, boolean isAuto){ + super(c, buf, isAuto); + } + public void init(boolean isAuto){ + setPathToEllipse(0, 0, 80,50); + } + public Covis_Object Covis_clone(boolean isAuto){ + return new Covis_Oval(buffer, isAuto); + } + public Color getClassColor(){ + return defaultColor; + } + + public static int objCount = 0; + public static int objAryCount = 0; + public String getNextVarName(boolean isAry){ + StringBuffer sb = new StringBuffer(getClsName().toLowerCase().substring(0,4)); + if (isAry) { + objAryCount++; + sb.append("Ary"); + sb.append(objAryCount); + } else { + objCount++; + sb.append(objCount); + } + return sb.toString(); + } + @Override + public void clear_objCount() { + objCount = 0; + objAryCount = 0; + System.out.println("clear count "+getClsName()); + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_Random.java b/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_Random.java new file mode 100644 index 0000000..7f64f34 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_Random.java @@ -0,0 +1,43 @@ +package jaist.css.covis.cls; + +import jaist.css.covis.CoVisBuffer; + +import java.awt.Color; + +public class Covis_Random extends Covis_Object { + private static final long serialVersionUID = 8131819427660903628L; + public static Color defaultColor = new Color(242,178,188); + public Covis_Random(CoVisBuffer buf, boolean isAuto){ + super(buf, isAuto); + color = defaultColor; + setPaint(color); + setStroke(basicStroke); + } + public Covis_Random(Color c, CoVisBuffer buf, boolean isAuto){ + super(c, buf, isAuto); + } + public void init(boolean isAuto){ + setPathToEllipse(0, 0, 75, 50); + } + public Covis_Object Covis_clone(boolean isAuto){ + return new Covis_Random(buffer, isAuto); + } + public Color getClassColor(){ + return defaultColor; + } + + public static int objCount = 0; + public static int objAryCount = 0; + public String getNextVarName(boolean isAry){ + StringBuffer sb = new StringBuffer(getClsName().toLowerCase().substring(0,4)); + if (isAry) { + objAryCount++; + sb.append("Ary"); + sb.append(objAryCount); + } else { + objCount++; + sb.append(objCount); + } + return sb.toString(); + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_Rect.java b/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_Rect.java new file mode 100644 index 0000000..1c5e06e --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_Rect.java @@ -0,0 +1,49 @@ +package jaist.css.covis.cls; + +import jaist.css.covis.CoVisBuffer; + +import java.awt.Color; + +public class Covis_Rect extends Covis_Object { + private static final long serialVersionUID = 8131819427660903628L; + public static Color defaultColor = new Color(178,242,188); + public Covis_Rect(CoVisBuffer buf, boolean isAuto){ + super(buf, isAuto); + color = defaultColor; + setPaint(color); + setStroke(basicStroke); + } + public Covis_Rect(Color c, CoVisBuffer buf, boolean isAuto){ + super(c, buf, isAuto); + } + public void init(boolean isAuto){ + setPathToRectangle(0, 0, 80, 50); + } + public Covis_Object Covis_clone(boolean isAuto){ + return new Covis_Rect(buffer, isAuto); + } + public Color getClassColor(){ + return defaultColor; + } + + public static int objCount = 0; + public static int objAryCount = 0; + public String getNextVarName(boolean isAry){ + StringBuffer sb = new StringBuffer(getClsName().toLowerCase().substring(0,4)); + if (isAry) { + objAryCount++; + sb.append("Ary"); + sb.append(objAryCount); + } else { + objCount++; + sb.append(objCount); + } + return sb.toString(); + } + @Override + public void clear_objCount() { + objCount = 0; + objAryCount = 0; + System.out.println("clear count "+getClsName()); + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_String.java b/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_String.java new file mode 100644 index 0000000..cabbee2 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_String.java @@ -0,0 +1,112 @@ +package jaist.css.covis.cls; + +import jaist.css.covis.CoVisBuffer; + +import java.awt.Color; + +import javax.swing.JOptionPane; + +import edu.umd.cs.piccolo.nodes.PText; + +public class Covis_String extends Covis_Object { + private static final long serialVersionUID = 8131819427660903628L; + public static Color defaultColor = new Color(255,232,96); + Covis_primitive elementObj; + + PText valueText; + public Covis_String(CoVisBuffer buf, boolean isAuto){ + super(buf, isAuto); + color = defaultColor; + setPaint(color); + setStroke(basicStroke); + } + public Covis_String(Color c, CoVisBuffer buf, boolean isAuto){ + super(c, buf, isAuto); + } + public void init(boolean isAuto) throws NullPointerException { + setPathToRectangle(0, 0, 100, 50); + if (isAuto){ + setValues("Moji"); + } else { + String val = JOptionPane.showInputDialog(buffer.getWindow().frame, "Input String.", "Input String", JOptionPane.QUESTION_MESSAGE); + if (val == null) { + val = "Moji"; + throw new NullPointerException(); + } + setValues(val); + } + } + public void setValues(String s){ + if (valueText == null) valueText = new PText(); + valueText.setText('"'+s+'"'); + valueText.setScale(2.2); + valueText.addAttribute("moveTarget", this); + valueText.setOffset(4,10); + addChild(valueText); + setPathToRectangle(0, 0, (float)(8+valueText.getWidth()*valueText.getScale()), (float)(20+valueText.getHeight()*valueText.getScale())); + + } + public Covis_Object Covis_clone(boolean isAuto){ + return new Covis_String(buffer, isAuto); + } + public Color getClassColor(){ + return defaultColor; + } + + + public static int objCount = 0; + public static int objAryCount = 0; + public String getNextVarName(boolean isAry){ + StringBuffer sb = new StringBuffer(getClsName().toLowerCase().substring(0,3)); + if (isAry) { + objAryCount++; + sb.append("Ary"); + sb.append(objAryCount); + } else { + objCount++; + sb.append(objCount); + } + return sb.toString(); + } + // overwrite + public String getConstructorInfo() { +// return "new "+getClsName()+"("+valueText.getText()+"); // or, just "+valueText.getText(); + return "new "+getClsName()+"("+valueText.getText()+");"; + } + +// public Covis_String covis_toString(){ +// Covis_String cs = new Covis_String(buffer,true); +// cs.setValues(toString()); +// buffer.putHistoryNew("new", cs, false); +// return cs; +// } + public Covis_String covis_toString(){ +// Covis_String cs = new Covis_String(buffer,true); +// cs.setValues(toString()); +// buffer.putHistoryNew("new", cs, false); +// return cs; + return this; + } + public String toString(){ + return valueText.getText().substring(1,valueText.getText().length()-1); + } +// return ; + public boolean covis_equals(Covis_String arg){ + return this.covis_toString().equals(arg.covis_toString()); + } + public boolean covis_eqeq_isSame(Covis_String arg){ + return (this==arg); + } + public void covis_setText(String s){ + setValues(s); + } + public void covis_append(String s){ + setValues(toString()+s); + } +// @Override +// public void clear_objCount() { +// objCount = 0; +// objAryCount = 0; +// System.out.println("clear count "+getClsName()); +// } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_Type.java b/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_Type.java new file mode 100644 index 0000000..d7fb105 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_Type.java @@ -0,0 +1,25 @@ +package jaist.css.covis.cls; + +import jaist.css.covis.CoVisBuffer; + +import java.awt.Color; +import java.lang.reflect.InvocationTargetException; + +import javax.swing.JFrame; + +import edu.umd.cs.piccolo.PNode; +import edu.umd.cs.piccolo.nodes.PPath; + +@SuppressWarnings("serial") +public abstract class Covis_Type extends PPath { + public CoVisBuffer buffer; + + public abstract String getClsName(); + public abstract Covis_Type createNew(JFrame f, boolean isAuto) throws InvocationTargetException; + public abstract PNode createToolTip(); + public abstract Color getClassColor(); + public abstract String getNextVarName(boolean isArray); + public abstract Covis_Type newInstance(boolean isAuto) throws InvocationTargetException; + public abstract void clear_objCount(); + public abstract String getConstructorArgs(); +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_char.java b/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_char.java new file mode 100644 index 0000000..c8c7b18 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_char.java @@ -0,0 +1,87 @@ +package jaist.css.covis.cls; + +import jaist.css.covis.CoVisBuffer; + +import java.awt.Color; + +import edu.umd.cs.piccolo.nodes.PText; + +public class Covis_char extends Covis_primitive { + private static final long serialVersionUID = 8131819427660903628L; + public static Color defaultColor = new Color(248,184,120); + + public Covis_char(CoVisBuffer buf, boolean isAuto){ + super(buf, isAuto); + color = defaultColor; + setPaint(color); + setStroke(basicStroke); + } + public Covis_char(Color c, CoVisBuffer buf, boolean isAuto){ + super(c, buf, isAuto); + } + public void init(boolean isAuto){ + setPathToRectangle(0, 0, 40, 50); + setValue("a"); +// value = "'a'"; +// valueText = new PText(value); +// valueText.setScale(2); +// addChild(valueText); +// valueText.setGreekThreshold(1.0d); +// valueTextOffset = -6f; +// justify(); + } + public boolean setValue(String s){ + if (s == null){ + return false; + } + if (s.equals("")){ + s = "\\0"; + } else { + s = s.trim().substring(0,1); + } + value = "'"+s+"'"; + if (valueText == null){ + valueText = new PText(value); + valueText.setScale(2); + addChild(valueText); + valueText.setGreekThreshold(1.0d); + } + valueText.setText(value); + valueTextOffset = -6f; + justify(); + return true; + } + public String getValue(){ + return value.substring(1,value.length()-1); + } +// public void edit(JFrame f, Variable v){ +// super.edit(f,v); +// } + + public Color getClassColor(){ + return defaultColor; + } + + public static int objCount = 0; + public static int objAryCount = 0; + public String getNextVarName(boolean isAry){ + StringBuffer sb = new StringBuffer(getClsName().substring(0,2)); + if (isAry) { + objAryCount++; + sb.append("Ary"); +// sb.append("_"); + sb.append(objAryCount); + } else { + objCount++; + sb.append(objCount); + } + return sb.toString(); + } + +// @Override +// public void clear_objCount() { +// objCount = 0; +// objAryCount = 0; +// System.out.println("clear count "+getClsName()); +// } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_int.java b/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_int.java new file mode 100644 index 0000000..13cceaf --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_int.java @@ -0,0 +1,78 @@ +package jaist.css.covis.cls; + +import jaist.css.covis.CoVisBuffer; + +import java.awt.Color; + +import edu.umd.cs.piccolo.PNode; +import edu.umd.cs.piccolo.nodes.PText; + +public class Covis_int extends Covis_primitive { + private static final long serialVersionUID = 8131819427660903628L; + public static Color defaultColor = new Color(140,200,255); + + public Covis_int(CoVisBuffer buf, boolean isAuto){ + super(buf, isAuto); + color = defaultColor; + setPaint(color); + setStroke(basicStroke); + } + public Covis_int(Color c, CoVisBuffer buf, boolean isAuto){ + super(c, buf, isAuto); + } + public void init(boolean isAuto){ + setPathToRectangle(0, 0, 40, 50); + setValue("0"); + } + public boolean setValue(String s){ + try{ + Integer.parseInt(s); + }catch(NumberFormatException ex){ + return false; + } + value = s.trim(); + + if (valueText == null){ + valueText = new PText(); + valueText.setScale(2); + addChild(valueText); + valueText.setGreekThreshold(1.0d); + } + valueText.setText(value); + valueTextOffset = -6f; + justify(); + return true; + } + + public Color getClassColor(){ + return defaultColor; + } + + public static int objCount = 0; + public static int objAryCount = 0; + public String getNextVarName(boolean isAry){ + StringBuffer sb = new StringBuffer(getClsName()); + if (isAry) { + objAryCount++; + sb.append("Ary"); + sb.append(objAryCount); + } else { + objCount++; + sb.append(objCount); + } + return sb.toString(); + } + + public PNode getToolTipNode(){ + PNode temp = super.getToolTipNode(); + if (temp != null) temp.setPaint(defaultColor); + return temp; + } + +// @Override +// public void clear_objCount() { +// objCount = 0; +// objAryCount = 0; +// System.out.println("clear count "+getClsName()); +// } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_primitive.java b/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_primitive.java new file mode 100644 index 0000000..447bb51 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/Covis_primitive.java @@ -0,0 +1,288 @@ +package jaist.css.covis.cls; + +import jaist.css.covis.CoVisBuffer; +import jaist.css.covis.ToolTipProvider; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.util.HashSet; +import java.util.TreeMap; + +import javax.swing.JFrame; +import javax.swing.JOptionPane; + +import edu.umd.cs.piccolo.PNode; +import edu.umd.cs.piccolo.nodes.PText; +import edu.umd.cs.piccolo.util.PDimension; + +public class Covis_primitive extends Covis_Type implements ToolTipProvider, ToFront, Move { + public static BasicStroke basicStroke = new BasicStroke(3f,BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 90.0f); + public static BasicStroke dottedStroke = new BasicStroke(3f,BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 90.0f, new float[]{5,10},0); + public static BasicStroke thinStroke = new BasicStroke(1.5f,BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 90.0f); + +// float[] dash = { DASH_WIDTH, DASH_WIDTH }; +// strokes = new Stroke[NUM_STROKES]; +// for (int i = 0; i < NUM_STROKES; i++) { +// strokes[i] = new BasicStroke(2, BasicStroke.CAP_BUTT, +// BasicStroke.JOIN_MITER, 1, dash, i); +// } + public static PNode nullNode = new PNode(); + private static final long serialVersionUID = 1676721160662045517L; + public static int objCount = 0; + public static int objAryCount = 0; + + public String getNextVarName(boolean isAry){ + StringBuffer sb = new StringBuffer(getClsName().toLowerCase().substring(0,3)); + if (isAry) { + objAryCount++; + sb.append("Ary"); + sb.append(objAryCount); + } else { + objCount++; + sb.append(objCount); + } + return sb.toString(); + } + +// public CovisObj_TransparencyControl tc; + + public static Color defaultColor = new Color(255,255,222); + public Color color; + + public PText valueText; + public float valueTextOffset = -9.5f; + public void justify(){ + double vw = valueText.getWidth(); + double vh = valueText.getHeight(); + double scalex, scaley; + scalex = getWidth()/vw; + scaley = getHeight()/vh; + if (scalex > 2d) scalex = 2d; + if (scaley > 2d) scaley = 2d; + if (scalex < scaley) scaley = scalex; + valueText.setScale(scaley*0.95); + vw = valueText.getWidth(); + vh = valueText.getHeight(); + double x = (getWidth()-vw)/2; + double y = (getHeight()-vh)/2; + valueText.setOffset(x+valueTextOffset,y); + } + public String value; + public boolean setValue(String s){ + return false; + } + public String getValue(){ + return value; + } + public void edit(JFrame f, Variable v){ + edit(f,v,false); + } + + public void edit(JFrame f, Variable v, boolean isnew){ + String input; + input = JOptionPane.showInputDialog(f, "Input Value for "+v.getBaseVarName(), getValue()); + if (input == null) return; + if (!setValue(input)){ + JOptionPane.showMessageDialog(f,"Value is not accepted.","Error",JOptionPane.WARNING_MESSAGE); + } + if (!isnew) { + buffer.putHistoryEditValue(v); //変更したらソースコードに追加 + Informer.playSound("Pop.wav"); + } + + } + + // 複数リンクからの参照がありうるので,HashSet + HashSet anchors_incoming; + + public PText tooltip; + + long toFront_ts; + Class type; + + public Covis_primitive(CoVisBuffer buf, boolean isAuto){ + buffer = buf; + init(isAuto); + color = defaultColor; + setPaint(color); +// tc = new CovisObj_TransparencyControl(this); + anchors_incoming = new HashSet(); + addAttribute("tooltip", this); + setStroke(dottedStroke); + type = getClass(); + } + public Covis_primitive(Color c, CoVisBuffer buf, boolean isAuto){ + this(buf,isAuto); + color = c; + setPaint(color); + } + public void init(boolean isAuto){ + setPathToRectangle(0, 0, 80 ,50); + } + public String getClsName(){ + int p = getClass().getName().lastIndexOf("_"); + return getClass().getName().substring(p+1); + } + private boolean isSelected; + private boolean isHighlighted; + public Covis_primitive defaultObject; + + public Covis_primitive Covis_clone(boolean isAuto){ + return new Covis_primitive(buffer,true); + } + public Covis_primitive createNew(JFrame f, boolean isAuto){ + return null; + } + public Covis_primitive newInstance(boolean isAuto){ + Constructor constructor; + Covis_primitive cv_prim = null; + try { + constructor = getClass().getConstructor(CoVisBuffer.class, boolean.class); + cv_prim = (Covis_primitive) constructor.newInstance(buffer, isAuto); + } catch (SecurityException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + return cv_prim; + } + public void setHighlight(boolean f){ + isHighlighted = f; + } + public boolean isHighlighted(){ + return isHighlighted; + } + public void setSelected(boolean s){ + isSelected = s; + } + public boolean isSelected(){ + return isSelected; + } + public Color getClassColor(){ + return defaultColor; + } + public void attach(Anchor anchor){ + + } + public void detach(Anchor anchor){ + + } + public void detachAll() { + + } + public int attachPointOffset(Anchor mya) { + if (anchors_incoming.size()==1) return 0; + TreeMap map = new TreeMap(); + for(Anchor p: anchors_incoming) { + double y = p.getGlobalTranslation().getY(); + while(map.get(y)!=null) y+=0.01; + map.put(y, p); + } + int yy = 0; + for(Anchor a: map.values()){ + if (a == mya) return yy; + yy += 10; + } + return 0; + } +// public String referenceVarNames(){ +// if (anchors_incoming.size()==0) return null; +// StringBuffer sb = new StringBuffer(); +// TreeMap map = new TreeMap(); +// for(Anchor p: anchors_incoming) { +// map.put(p.getGlobalTranslation().getY(), p); +// } +// for(Anchor a: map.values()){ +// sb.append(a.getVarName()+"\n"); +// } +// return sb.toString().substring(0, sb.length()-1); +// } + public String referenceVarNames(){ + if (getAttribute("parentAry")!=null){ + String refsrc = ((Covis_Array)getAttribute("parentAry")).referenceVarNames()+"\n"; + String indexStr = "["+(String)getAttribute("index")+"]"; + String refsrc2 = refsrc.replaceAll("\n",indexStr+" \n"); + return refsrc2; + } + return null; + } + + public PNode getToolTipNode(){ + if (tooltip == null) { + String refVarNames = referenceVarNames(); + if (refVarNames == null) return null; + tooltip = new PText(refVarNames); + tooltip.setPaint(defaultColor); + } + return tooltip; + } + + /** + * ToFrontインタフェースの実装 + */ + public void toFront(long ts) { + if (toFront_ts == ts) return; + toFront_ts = ts; + + PNode parent = getParent(); + if (parent != null){ +// removeFromParent(); + parent.addChild(this); + if (parent instanceof ToFront) ((ToFront)parent).toFront(ts); + if (parent.getAttribute("toFront")!=null){ + ((ToFront)parent.getAttribute("toFront")).toFront(ts); + } + for(Anchor p: anchors_incoming){ + p.toFront(ts); + } + } + } + public void checkAtRefDetached(){ + } + public void dispose(){ + } + public void move(PDimension d){ + translate(d.getWidth(), d.getHeight()); //履歴に関係ない動作 + for(Anchor a: anchors_incoming){ + a.start_RewindThread(); + } + } + @Override + public PNode createToolTip() { + return nullNode; + } + @Override + public void clear_objCount() { + try { + Field f = getClass().getField("objCount"); + f.setInt(getClass(), 0); + Field fg = getClass().getField("objAryCount"); + fg.setInt(getClass(), 0); + } catch (SecurityException e) { + e.printStackTrace(); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + //デフォルトコンストラクタの引数(プリミティブなので,必要としないはずだが) + @Override + public String getConstructorArgs() { + return ""; + } + +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/DragNotice.java b/anchorgarden/src/main/java/jaist/css/covis/cls/DragNotice.java new file mode 100644 index 0000000..274361c --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/DragNotice.java @@ -0,0 +1,10 @@ +package jaist.css.covis.cls; + +import jaist.css.covis.CoVisBuffer; +import edu.umd.cs.piccolo.event.PInputEvent; + +public interface DragNotice { + public void setDragNotice(boolean f); + public void drag(PInputEvent e, CoVisBuffer buffer); + public void endDrag(PInputEvent e, CoVisBuffer buffer); +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/Field.java b/anchorgarden/src/main/java/jaist/css/covis/cls/Field.java new file mode 100644 index 0000000..764a80f --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/Field.java @@ -0,0 +1,103 @@ +package jaist.css.covis.cls; + +import java.awt.Color; +import java.awt.Font; +import java.util.List; +import java.util.TreeMap; + +import edu.umd.cs.piccolo.PNode; +import edu.umd.cs.piccolo.nodes.PPath; +import edu.umd.cs.piccolo.nodes.PText; +import edu.umd.cs.piccolo.util.PDimension; + +public class Field extends PPath implements Layoutable , Move{ + private static final long serialVersionUID = 3524513728998576206L; + + public String typeName; // Variable, Object, Class + public Color color; + PText caption; + public static Font bold = new Font("sansserif", Font.BOLD, 12); + public static float top = 40; + public Field(String _typeName, Color c){ + color = c; + typeName = _typeName; + setPathToRectangle(0, 0, 200, 100); + setPaint(color); + setStrokePaint(null); +// setStroke(new BasicStroke(1)); + scale(1); +// setTransparency(0.4f); + + this.addAttribute("moveTarget", this); + this.addAttribute("info", "Field "+toString()); + this.addAttribute("selectable", this); + + caption = new PText(typeName); + caption.scale(3); + caption.setFont(bold); + caption.setOffset(10,0); + caption.addAttribute("moveTarget", this); + caption.addAttribute("dragLayout", this); + addChild(caption); + } + + public void layout(int dur){ + layoutExceptOne(null, dur); + } + + public void layoutExceptOne(PNode operationNode, int dur) { + List col = getChildrenReference(); + TreeMap map = new TreeMap(); + for(PNode p: col) { + double y = p.getYOffset(); + while(map.get(y)!=null) y+=0.001; + if (p != caption) map.put(y, p); + } + + double offsetx = 10; + double endx = 10; + double offsety = 10; + double endy = 10; + double maxx = 0, maxy = 0; + for(PNode p : map.values()){ +// p.setOffset(offsetx, offsety); + double px = p.getFullBounds().width; + double py = p.getFullBounds().height; + if (maxx < offsetx + endx + px) maxx = offsetx + endx + px; + if (maxy < offsety + endy + py) maxy = offsety + endy + py; + if (operationNode != p) p.animateToPositionScaleRotation(offsetx, offsety+top, 1, 0, dur); + offsety += py; + offsety += 1; + } + animateToBounds(0, 0, maxx, maxy+top, dur); + } + + public void layoutByToString(int dur){ + List col = getChildrenReference(); + TreeMap map = new TreeMap(); + for(PNode p: col) { + if (p != caption) map.put(p.toString(), p); + } + + double offsetx = 10; + double endx = 10; + double offsety = 10; + double endy = 10; + double maxx = 0, maxy = 0; + for(PNode p : map.values()){ +// System.out.println(p.toString()); + p.setOffset(offsetx, offsety+top); + double px = p.getFullBounds().width; + double py = p.getFullBounds().height; + if (maxx < offsetx + endx + px) maxx = offsetx + endx + px; + if (maxy < offsety + endy + py) maxy = offsety + endy + py; + offsety += py; + offsety += 1; + } + animateToBounds(0, 0, maxx, maxy+top, dur); + } + + public void move(PDimension d){ + translate(d.getWidth(), d.getHeight()); //履歴に関係ない動作 + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/Informer.java b/anchorgarden/src/main/java/jaist/css/covis/cls/Informer.java new file mode 100644 index 0000000..0193ecf --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/Informer.java @@ -0,0 +1,205 @@ +package jaist.css.covis.cls; + +import java.applet.Applet; +import java.applet.AudioClip; +import java.io.BufferedInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Hashtable; + +import javax.sound.sampled.AudioFormat; +import javax.sound.sampled.AudioInputStream; +import javax.sound.sampled.AudioSystem; +import javax.sound.sampled.DataLine; +import javax.sound.sampled.LineUnavailableException; +import javax.sound.sampled.SourceDataLine; +import javax.sound.sampled.UnsupportedAudioFileException; + +public class Informer implements Runnable { + // public static void send(String to, String subject, String mes){ + // try { + // Properties props = System.getProperties(); + // // SMTPサーバーのアドレスを指定 + // props.put("mail.smtp.host","moto.qee.jp"); + // Session session=Session.getDefaultInstance(props,null); + // MimeMessage mimeMessage=new MimeMessage(session); + // // 送信元メールアドレスと送信者名を指定 + // mimeMessage.setFrom(new InternetAddress("icluster@moto.qee.jp","知的クラスタ","iso-2022-jp")); + // // 送信先メールアドレスを指定 + // mimeMessage.setRecipients(Message.RecipientType.TO, to); + // // メールのタイトルを指定 + // mimeMessage.setSubject(subject,"iso-2022-jp"); + // // メールの内容を指定 + // mimeMessage.setText(mes,"iso-2022-jp"); + // // メールの形式を指定 + // mimeMessage.setHeader("Content-Type","text/plain; charset=iso-2022-jp"); + // // 送信日付を指定 + // mimeMessage.setSentDate(new Date()); + // mimeMessage.setHeader("Content-Transfer-Encoding", "7bit"); + // // 送信します + // Transport.send(mimeMessage); + // } catch (Exception e) { + // e.printStackTrace(); + // } + // } + String file; + static Hashtable hash = new Hashtable(); + public static boolean canPlaySound = true; +// public static boolean isSignedJAR = false; + + public Informer(String s){ + file = s; + try { + preload(); + } catch (Exception e) { + canPlaySound = false; + e.printStackTrace(); + } + } + public void play(){ + Thread t = new Thread(this); + t.start(); + } + + public static Hashtable soundCache = new Hashtable(); + public static void playSound2(String file){ + if (!canPlaySound) return; + AudioClip pong = soundCache.get(file); + if (pong == null){ + // サウンドをロード + pong = Applet.newAudioClip(Informer.class.getResource(file)); + soundCache.put(file, pong); + } + pong.play(); + } + public static Informer informer; + + public static void playSound(String file){ + if (!canPlaySound) return; + if (hash.containsKey(file)){ + Informer inf = hash.get(file); + inf.play(); + } else { + Informer inf = new Informer(file); + hash.put(file, inf); + inf.play(); + } + // informer.playSoundJARFile(file); + } + + + public byte[] path2byte(String path) { + File f = new File(path); + long fsize = f.length(); + + ByteArrayOutputStream varyBuf = new ByteArrayOutputStream((int) fsize); + InputStream in = null; + int b; + try { + in = new BufferedInputStream(audioInputStream); + final int LS = 1024; + byte buf[] = new byte[LS]; + + while ((b = in.read(buf, 0, buf.length)) != -1) { + varyBuf.write(buf, 0, b); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + } + return varyBuf.toByteArray(); + } + + InputStream is; + AudioInputStream audioInputStream; + AudioFormat audioFormat; + DataLine.Info info; + SourceDataLine line; + byte[] wav; + private void preload() throws Exception { + try{ + is = getClass().getResourceAsStream("/"+file); + try { + audioInputStream = AudioSystem.getAudioInputStream(new BufferedInputStream(is)); + } catch (UnsupportedAudioFileException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + audioFormat = audioInputStream.getFormat(); + } catch(NullPointerException np){ + try { + System.out.println("Second try"); + audioInputStream = AudioSystem.getAudioInputStream(new File("res/"+file)); + } catch (UnsupportedAudioFileException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + // オーディオ形式を取得します + audioFormat = audioInputStream.getFormat(); + } + // データラインの情報オブジェクトを生成します + info = new DataLine.Info(SourceDataLine.class, audioFormat); + // 指定されたデータライン情報に一致するラインを取得します + try { + line = (SourceDataLine) AudioSystem.getLine(info); + } catch (LineUnavailableException e) { + e.printStackTrace(); + } + wav = path2byte(file); + + } + + public void run() { + try { + // 指定されたオーディオ形式でラインを開きます + if (!canPlaySound) return; + if (line == null) return; + line.open(audioFormat); + // ラインでのデータ入出力を可能にします + line.start(); + + line.write(wav, 0, wav.length); + + // ラインからキューに入っているデータを排出します + line.drain(); + // ラインを閉じます + line.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + // public void run2() { + // final int EXTERNAL_BUFFER_SIZE = 128000; + // try { + // // 指定されたオーディオ形式でラインを開きます + // line.open(audioFormat); + // // ラインでのデータ入出力を可能にします + // line.start(); + // + // int nBytesRead = 0; + // byte[] abData = new byte[EXTERNAL_BUFFER_SIZE]; + // while (nBytesRead != -1) { + // // オーディオストリームからデータを読み込みます + // nBytesRead = audioInputStream.read(abData, 0, abData.length); + // if (nBytesRead >= 0) { + // // オーディオデータをミキサーに書き込みます + // int nBytesWritten = line.write(abData, 0, nBytesRead); + // } + // } + // // ラインからキューに入っているデータを排出します + // line.drain(); + // // ラインを閉じます + // line.close(); + // } catch (Exception e) { + // e.printStackTrace(); + // } + // } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/Layoutable.java b/anchorgarden/src/main/java/jaist/css/covis/cls/Layoutable.java new file mode 100644 index 0000000..d5e7bd1 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/Layoutable.java @@ -0,0 +1,8 @@ +package jaist.css.covis.cls; + +import edu.umd.cs.piccolo.PNode; + +public interface Layoutable { + public void layout(int dur); + public void layoutExceptOne(PNode pn, int dur); +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/LinkMovable.java b/anchorgarden/src/main/java/jaist/css/covis/cls/LinkMovable.java new file mode 100644 index 0000000..c698ead --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/LinkMovable.java @@ -0,0 +1,5 @@ +package jaist.css.covis.cls; + +public interface LinkMovable { + public void update(); +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/Move.java b/anchorgarden/src/main/java/jaist/css/covis/cls/Move.java new file mode 100644 index 0000000..e04ed21 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/Move.java @@ -0,0 +1,7 @@ +package jaist.css.covis.cls; + +import edu.umd.cs.piccolo.util.PDimension; + +public interface Move { + public void move(PDimension d); +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/ObjectField.java b/anchorgarden/src/main/java/jaist/css/covis/cls/ObjectField.java new file mode 100644 index 0000000..45004cf --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/ObjectField.java @@ -0,0 +1,220 @@ +package jaist.css.covis.cls; + +import jaist.css.covis.CoVisBuffer; +import jaist.css.covis.ToolTipProvider; +import jaist.css.covis.fm.FlowMenu_TMRG; + +import java.awt.Color; +import java.awt.Font; +import java.awt.geom.Point2D; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; +import java.util.TreeMap; + +import edu.umd.cs.piccolo.PNode; +import edu.umd.cs.piccolo.event.PInputEvent; +import edu.umd.cs.piccolo.nodes.PPath; +import edu.umd.cs.piccolo.nodes.PText; +import edu.umd.cs.piccolo.util.PBounds; +import edu.umd.cs.piccolo.util.PDimension; + +public class ObjectField extends PPath implements Layoutable , ToolTipProvider, ClickHandler, Move { + private static final long serialVersionUID = 3524513728998576206L; + public static PNode nullToolTip = new PNode(); + public String typeName; // Variable, Object, Class + public Color color; + PText caption; + public static Font bold = new Font("sansserif", Font.BOLD, 12); + public static float top = 40; + public CoVisBuffer buffer; + public ObjectField(String _typeName, Color c, CoVisBuffer buf){ + color = c; + typeName = _typeName; + buffer = buf; + setPathToRectangle(0, 0, 200, 100); + setPaint(color); + setStrokePaint(null); + // setStroke(new BasicStroke(1)); + scale(1); + // setTransparency(0.4f); + + this.addAttribute("moveTarget", this); + this.addAttribute("info", "Field "+toString()); + this.addAttribute("selectable", this); + + caption = new PText(typeName); + caption.scale(3); + caption.setFont(bold); + caption.setOffset(10,0); + caption.addAttribute("moveTarget", this); + caption.addAttribute("dragLayout", this); + addChild(caption); + + this.addAttribute("clickHandler", this); + } + + public void layout(int dur){ + layoutExceptOne(null, dur); + } + + public void layoutExceptOne(PNode operationNode, int dur) { + List col = getChildrenReference(); + TreeMap map = new TreeMap(); + for(PNode p: col) { + if (p != caption) map.put(p.getYOffset(), p); + } + + double offsetx = 10; + double endx = 10; + double offsety = 10; + double endy = 10; + double maxx = 0, maxy = 0; + for(PNode p : map.values()){ + // p.setOffset(offsetx, offsety); + double px = p.getFullBounds().width; + double py = p.getFullBounds().height; + if (maxx < offsetx + endx + px) maxx = offsetx + endx + px; + if (maxy < offsety + endy + py) maxy = offsety + endy + py; + if (operationNode != p) p.animateToPositionScaleRotation(offsetx, offsety+top, 1, 0, dur); + offsety += py; + offsety += 10; + } + animateToBounds(0, 0, maxx, maxy+top, dur); + } + public PNode getToolTipNode() { + if (ClassStamp.selectedType == null) return nullToolTip; + PNode p = ClassStamp.selectedType.getToolTipNode(); + p.setTransparency(0.6f); + return p; + } + + public void clicked(PInputEvent e, FlowMenu_TMRG fmenu) { +// if (e.isShiftDown()){ +// SrcExecutor s = new SrcExecutor(buffer); +// String f = JOptionPane.showInputDialog(null); +// s.execute(f); +// return; +// } + if (ClassStamp.selectedType == null) { + Informer.playSound("RecEnd.wav"); + return; + } + else { + boolean isAuto = buffer.getWindow().isAutoMode_obj.isSelected(); + //SHIFT押していたら,マニュアル/オートをトグル + if (e.isShiftDown()) isAuto = !isAuto; + Covis_Object o = null; + try { + o = (Covis_Object) ClassStamp.selectedType.cv_type.createNew(fmenu.window.frame, isAuto); + } catch (InvocationTargetException e1) { + // e1.printStackTrace(); + } + if (o == null) { + Informer.playSound("RecEnd.wav"); + return; + } + if (o.getVisible()==false) return;//TODO:ここは,コンストラクタダイアログがキャンセルされたときに使う + addChild(o); + buffer.putHistoryNew("new", o); + // Informer.playSound("hwandsw.wav"); + o.addAttribute("moveTarget", o); + o.addAttribute("selectable", o); + o.setOffset(e.getPositionRelativeTo(this)); + if (o instanceof Covis_Object) + ((Covis_Object)o).tc.transparencyThread_Start(0, this, 100); + Informer.playSound("Fairydust.wav"); + } + } + + public void move(PDimension d){ + translate(d.getWidth(), d.getHeight()); //履歴に関係ない動作 + + for(PNode p: getChildrenReference()) { + if (p instanceof Move) ((Move)p).move(new PDimension()); + } + } + + public void addObject(ClassStamp f) { + boolean isAuto = buffer.getWindow().isAutoMode_obj.isSelected(); + addObject(f, isAuto); + } + public Point2D getNextNewObjectPosition(){ + //まず,下方向の余裕をさがす + double ycandidate = 0; + List col = new ArrayList(getChildrenReference()); + for(PNode p: col) { + double tempy = p.getYOffset()+p.getHeight(); + if (ycandidate < tempy) ycandidate = tempy; + } + if (ycandidate < this.getHeight()- 60){ + return new Point2D.Double(20,ycandidate+20); + } + //次に,右方向でさがす + // PPath checkPath = PPath.createRectangle(0, 0, 110, 55); + for(int y = 1; y< (this.getHeight()/20)-4; y++){ + for(int x = 1; x< (this.getWidth()/20)-1; x++){ + // checkPath.setOffset(x*120,y*60); + PNodeBoundsIntersectsFilter rpf = new PNodeBoundsIntersectsFilter( + new PBounds(x*20+getX()+getOffset().getX()-10,y*20+getY()+getOffset().getY()+10,120,80)); + ArrayList pnbuf = new ArrayList(); + this.getAllNodes(rpf, pnbuf); + for(PNode pn: pnbuf){ + System.out.println("x="+x+" y="+y+" "+pn.toString()); + } + if (pnbuf.size()==0) { + System.out.println("found x="+x+" y="+y); + return new Point2D.Double(x*20,y*20+30); + } + } + } + return new Point2D.Double(getWidth()/3, getHeight()/3); + } + public void addObject(ClassStamp f, boolean isAuto) { + Covis_Object o = null; + try { + o = (Covis_Object) f.cv_type.createNew(buffer.getWindow().frame, isAuto); + } catch (InvocationTargetException e1) { + // e1.printStackTrace(); + } + if (o == null) { + Informer.playSound("RecEnd.wav"); + return; + } + addChild(o); + buffer.putHistoryNew("new", o); + // Informer.playSound("hwandsw.wav"); + o.addAttribute("moveTarget", o); + o.addAttribute("selectable", o); + o.setOffset(getNextNewObjectPosition()); + if (o instanceof Covis_Object) + ((Covis_Object)o).tc.transparencyThread_Start(0, this, 100); + Informer.playSound("Fairydust.wav"); + } + //メソッド内でよばれたとき,200%の時間をかけて,ゆっくりとフェードアウト + public void addObject(Covis_Object o){ + addChild(o); + // buffer.putHistoryNew("new", o); + // Informer.playSound("hwandsw.wav"); + o.addAttribute("moveTarget", o); + o.addAttribute("selectable", o); + if (o.anchors_incoming.size()<1){ + o.setOffset(getNextNewObjectPosition()); + ((Covis_Object)o).tc.transparencyThread_Start(0, this, 200); + Informer.playSound("Fairydust.wav"); + } + } + + public void clearObjVarName(){ + List col = new ArrayList(getChildrenReference()); + for(PNode p: col) { + if (p instanceof Covis_Object){ + Covis_Object co= (Covis_Object)p; + // v.myrefs.clear(); + for(Anchor a: co.anchors_member){ + a.srcVariable.clearVarNamesAry(); + } + } + } + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/PNodeBoundsIntersectsFilter.java b/anchorgarden/src/main/java/jaist/css/covis/cls/PNodeBoundsIntersectsFilter.java new file mode 100644 index 0000000..9c04417 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/PNodeBoundsIntersectsFilter.java @@ -0,0 +1,33 @@ +package jaist.css.covis.cls; + +import edu.umd.cs.piccolo.PNode; +import edu.umd.cs.piccolo.util.PBounds; +import edu.umd.cs.piccolo.util.PNodeFilter; + +/** + * 引数に与えたノードの領域が,boundsの領域に完全に入っているかどうかを調べるフィルタ + * + * @author miuramo + * + */ +public class PNodeBoundsIntersectsFilter implements PNodeFilter { + PBounds bounds; // 判定する領域 + + public PNodeBoundsIntersectsFilter(PBounds r) { + bounds = r; + } + + public boolean accept(PNode aNode) { + if (aNode instanceof Covis_Object){ + System.out.println(aNode.getGlobalFullBounds().toString()); + if (bounds.intersects(aNode.getGlobalFullBounds()) || bounds.contains(aNode.getGlobalFullBounds())) { // 基準boundsが,arpと重なる場合のみ + return true; + } + } + return false; + } + + public boolean acceptChildrenOf(PNode aNode) { + return true; + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/RefLink.java b/anchorgarden/src/main/java/jaist/css/covis/cls/RefLink.java new file mode 100644 index 0000000..afb1ee7 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/RefLink.java @@ -0,0 +1,64 @@ +package jaist.css.covis.cls; + +import jaist.css.covis.fm.FlowMenu_TMRG; + +import java.awt.Color; +import java.awt.geom.Line2D; +import java.awt.geom.Point2D; + +import edu.umd.cs.piccolo.PNode; +import edu.umd.cs.piccolo.event.PInputEvent; +import edu.umd.cs.piccolo.nodes.PPath; +import edu.umd.cs.piccolo.util.PDimension; + +/** + * アンカータブと変数などとをつなぐ「線」 + * @author miuramo + */ +public class RefLink extends PPath implements LinkMovable, ClickHandler { + private static final long serialVersionUID = 6035096413162581382L; + + PNode src; + PNode knob; + Covis_Object dest = null; + Anchor anchor; + public RefLink(PNode t1, PNode t2, Anchor a){ + src = t1; + knob = t2; + anchor = a; + setStroke(ClassStamp.roundrectStroke); + setStrokePaint(Color.gray); + + addAttribute("clickHandler", this); + } + + public void update(){ + Point2D srcP = src.getGlobalTranslation(); + Point2D knobP = knob.getGlobalTranslation(); + float dx = (float)(knobP.getX() - srcP.getX() - 10); + float dy = (float)(knobP.getY() - srcP.getY() - 10); + setPathTo(new Line2D.Float(-10,-10, dx, dy)); + } + + public PDimension diff(){ + PNode target; + Point2D targetP; + if (dest != null) target = dest; else target = src; + targetP = target.getGlobalTranslation(); + Point2D destP = knob.getGlobalTranslation(); + double dx = destP.getX() - targetP.getX(); + double dy = destP.getY() - targetP.getY(); + if (dest != null) { + dx-=10; dy-=10 + dest.attachPointOffset(anchor); + return new PDimension(-dx,-dy); + } else { + return new PDimension(-dx*3/5,-dy*3/5); + } + } + + public void clicked(PInputEvent e, FlowMenu_TMRG fmenu) { +// System.out.println("reflink click"); + anchor.toFront(System.currentTimeMillis()); + } + +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/StaticField.java b/anchorgarden/src/main/java/jaist/css/covis/cls/StaticField.java new file mode 100644 index 0000000..b1db9e0 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/StaticField.java @@ -0,0 +1,191 @@ +package jaist.css.covis.cls; + +import jaist.css.covis.CoVisBuffer; +import jaist.css.covis.ToolTipProvider; +import jaist.css.covis.fm.FlowMenu_TMRG; + +import java.awt.Color; +import java.awt.Font; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; +import java.util.TreeMap; + +import edu.umd.cs.piccolo.PNode; +import edu.umd.cs.piccolo.event.PInputEvent; +import edu.umd.cs.piccolo.nodes.PPath; +import edu.umd.cs.piccolo.nodes.PText; +import edu.umd.cs.piccolo.util.PDimension; + +public class StaticField extends PPath implements Layoutable , ToolTipProvider, ClickHandler, Move { + private static final long serialVersionUID = -6949546345615986003L; + public static PNode nullToolTip = new PNode(); + public String typeName; // Variable, Object, Class + public Color color; + PText caption; + public static Font bold = new Font("sansserif", Font.BOLD, 12); + public static float top = 40; + public CoVisBuffer buffer; + public StaticField(String _typeName, Color c, CoVisBuffer buf){ + color = c; + typeName = _typeName; + buffer = buf; + setPathToRectangle(0, 0, 200, 100); + setPaint(color); + setStrokePaint(null); +// setStroke(new BasicStroke(1)); + scale(1); +// setTransparency(0.4f); + + this.addAttribute("moveTarget", this); + this.addAttribute("info", "Field "+toString()); + this.addAttribute("selectable", this); + + caption = new PText(typeName); + caption.scale(3); + caption.setFont(bold); + caption.setOffset(10,0); + caption.addAttribute("moveTarget", this); + caption.addAttribute("dragLayout", this); + addChild(caption); + + this.addAttribute("clickHandler", this); + } + + public void layout(int dur){ + layoutExceptOne(null, dur); + } + + public void layoutExceptOne(PNode operationNode, int dur) { + List col = getChildrenReference(); + TreeMap map = new TreeMap(); + for(PNode p: col) { + double y = p.getYOffset(); + while(map.get(y)!=null) y+=0.001; + if (p != caption) map.put(y, p); + } + + double offsetx = 10; + double endx = 10; + double offsety = 10; + double endy = 10; + double maxx = 0, maxy = 0; + for(PNode p : map.values()){ +// p.setOffset(offsetx, offsety); + double px = p.getFullBounds().width; + double py = p.getFullBounds().height; + if (maxx < offsetx + endx + px) maxx = offsetx + endx + px; + if (maxy < offsety + endy + py) maxy = offsety + endy + py; + if (operationNode != p) p.animateToPositionScaleRotation(offsetx, offsety+top, 1, 0, dur); + offsety += py; + offsety += 1; + } + animateToBounds(0, 0, maxx, maxy+top, dur); + } + +// +// public PNode getToolTipNode() { +// if (ClassStamp.selectedType == null) return nullToolTip; +// PNode p = ClassStamp.selectedType.getToolTipNode(); +// p.setTransparency(0.6f); +// return p; +// } + @Override + public PNode getToolTipNode() { + return null; + } + + @Override + public void clicked(PInputEvent e, FlowMenu_TMRG fmenu) { + } + +// public void clicked(PInputEvent e, FlowMenu_TMRG fmenu) { +// if (ClassStamp.selectedType == null) { +// Informer.playSound("RecEnd.wav"); +// return; +// } +// else { +// boolean isAuto = buffer.getWindow().isAutoMode_obj.isSelected(); +// //SHIFT押していたら,マニュアル/オートをトグル +// if (e.isShiftDown()) isAuto = !isAuto; +// Covis_Object o = null; +// try { +// o = (Covis_Object) ClassStamp.selectedType.cv_type.createNew(fmenu.window.frame, isAuto); +// } catch (InvocationTargetException e1) { +//// e1.printStackTrace(); +// } +// if (o == null) { +// Informer.playSound("RecEnd.wav"); +// return; +// } +// addChild(o); +// buffer.putHistoryNew("new", o); +//// Informer.playSound("hwandsw.wav"); +// o.addAttribute("moveTarget", o); +// o.addAttribute("selectable", o); +// o.setOffset(e.getPositionRelativeTo(this)); +// if (o instanceof Covis_Object) +// ((Covis_Object)o).tc.transparencyThread_Start(0, this); +// Informer.playSound("Fairydust.wav"); +// } +// } + + public void move(PDimension d){ + translate(d.getWidth(), d.getHeight()); //履歴に関係ない動作 + + for(PNode p: getChildrenReference()) { + if (p instanceof Move) ((Move)p).move(new PDimension()); + } + } + + public void addObject(ClassStamp f) { + boolean isAuto = buffer.getWindow().isAutoMode_obj.isSelected(); + addObject(f, isAuto); + } + public void addObject(ClassStamp f, boolean isAuto) { + Covis_Object o = null; + try { + o = (Covis_Object) f.cv_type.createNew(buffer.getWindow().frame, isAuto); + } catch (InvocationTargetException e1) { +// e1.printStackTrace(); + } + if (o == null) { + Informer.playSound("RecEnd.wav"); + return; + } + addChild(o); + buffer.putHistoryNew("new", o); +// Informer.playSound("hwandsw.wav"); + o.addAttribute("moveTarget", o); + o.addAttribute("selectable", o); + o.setOffset(getWidth()/2, getHeight()/2); + if (o instanceof Covis_Object) + ((Covis_Object)o).tc.transparencyThread_Start(0, this, 100); + Informer.playSound("Fairydust.wav"); + } + public void addObject(Covis_Object o){ + addChild(o); +// buffer.putHistoryNew("new", o); +// Informer.playSound("hwandsw.wav"); + o.addAttribute("moveTarget", o); + o.addAttribute("selectable", o); + o.setOffset(getWidth()/2, getHeight()/2); + if (o instanceof Covis_Object) + ((Covis_Object)o).tc.transparencyThread_Start(0, this, 200); + Informer.playSound("Fairydust.wav"); + } + + public void clearObjVarName(){ + List col = new ArrayList(getChildrenReference()); + for(PNode p: col) { + if (p instanceof Covis_Object){ + Covis_Object co= (Covis_Object)p; +// v.myrefs.clear(); + for(Anchor a: co.anchors_member){ + a.srcVariable.clearVarNamesAry(); + } + } + } + } + +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/ToFront.java b/anchorgarden/src/main/java/jaist/css/covis/cls/ToFront.java new file mode 100644 index 0000000..d9f52bf --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/ToFront.java @@ -0,0 +1,5 @@ +package jaist.css.covis.cls; + +public interface ToFront { + public void toFront(long ts); +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/VarField.java b/anchorgarden/src/main/java/jaist/css/covis/cls/VarField.java new file mode 100644 index 0000000..55ff8eb --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/VarField.java @@ -0,0 +1,241 @@ +package jaist.css.covis.cls; + +import jaist.css.covis.CoVisBuffer; +import jaist.css.covis.ToolTipProvider; +import jaist.css.covis.fm.FlowMenu_TMRG; + +import java.awt.Color; +import java.awt.Font; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; +import java.util.TreeMap; + +import javax.swing.Timer; + +import edu.umd.cs.piccolo.PNode; +import edu.umd.cs.piccolo.event.PInputEvent; +import edu.umd.cs.piccolo.nodes.PPath; +import edu.umd.cs.piccolo.nodes.PText; +import edu.umd.cs.piccolo.util.PDimension; + +public class VarField extends PPath implements Layoutable , ToolTipProvider, ClickHandler, Move { + private static final long serialVersionUID = 3524513728998576206L; + public static PNode nullToolTip = new PNode(); + public String typeName; // Variable, Object, Class + public Color color; + PText caption; + public static Font bold = new Font("sansserif", Font.BOLD, 12); + public static float top = 40; + public Timer rewindTimer; + public CoVisBuffer buffer; + public static ArrayList vflist; + static { + vflist = new ArrayList(); + } + /** + * VarField複数化計画 + * Buffer.setHistLinkCode_ConcatinateVarDefAndNew がうまく探せるように再設計する + * @param _typeName + * @param c + * @param buf + */ + + public VarField(String _typeName, Color c, CoVisBuffer buf){ + color = c; + typeName = _typeName; + buffer = buf; + setPathToRectangle(0, 0, 255, 100); + setPaint(color); + setStrokePaint(null); +// setStroke(new BasicStroke(1)); + scale(1); +// setTransparency(0.4f); + + this.addAttribute("moveTarget", this); + this.addAttribute("info", "Field "+toString()); + this.addAttribute("selectable", this); + + caption = new PText(typeName); + caption.scale(3); + caption.setFont(bold); + caption.setOffset(10,0); + caption.addAttribute("moveTarget", this); + caption.addAttribute("dragLayout", this); + addChild(caption); + + this.addAttribute("clickHandler", this); + + rewindTimer = new Timer(100, new ActionListener(){ + public void actionPerformed(ActionEvent e){ + move(new PDimension()); + rewindTimer.stop(); + } + }); + } + + public void layout(int dur){ + layoutExceptOne(null, dur); + } + + public void layoutExceptOne(PNode operationNode, int dur) { + List col = getChildrenReference(); + TreeMap map = new TreeMap(); + for(PNode p: col) { + if (p != caption) map.put(p.getYOffset(), p); + } + + double offsetx = 10; + double endx = 10; + double offsety = 10; + double endy = 30; //少し余白をつくり,変数追加しやすく + double maxx = 0, maxy = 0; + for(PNode p : map.values()){ +// p.setOffset(offsetx, offsety); + double px = p.getBounds().width; + double py = p.getBounds().height; + if (maxx < offsetx + endx + px) maxx = offsetx + endx + px; + if (maxy < offsety + endy + py) maxy = offsety + endy + py; + if (operationNode != p) { + p.animateToPositionScaleRotation(offsetx, offsety+top, 1, 0, dur); + if (p instanceof Move) ((Move)p).move(new PDimension()); + } + offsety += py; + offsety += 10; + } + if (maxx < 200) maxx = 200; + if (maxy+top < 100) maxy = 100-top; + animateToBounds(0, 0, maxx, maxy+top, dur); + +// System.out.println("Layout"); + + rewindTimer.start(); + } + public PNode getToolTipNode() { + if (ClassStamp.selectedType == null) { + PText p = new PText("First, select one ' Type '\non the left column"); + p.setScale(1.4f); + p.setTextPaint(Color.red); + return p; +// return nullToolTip; + } + PNode p = ClassStamp.selectedType.getToolTipNode_forVariable(); + return p; + } + + public void clicked(PInputEvent e, FlowMenu_TMRG fmenu) { + if (ClassStamp.selectedType == null) return; + else { + + Variable var = null; + try { + var = new Variable(ClassStamp.selectedType.cv_type.newInstance(true), fmenu.window.frame, buffer,false); + } catch (InvocationTargetException e1) { + e1.printStackTrace(); + } + if (var.type == null) return; + var.setTransparency(0.0f); + addChild(var); + var.addAttribute("moveTargetY", var); +// var.addAttribute("selectable", var); + var.setOffset(e.getPositionRelativeTo(this)); + layout(200); + boolean isAuto = buffer.getWindow().isAutoMode.isSelected(); + //SHIFT押していたら,マニュアル/オートをトグル + if (e.isShiftDown()) isAuto = !isAuto; + + if (!isAuto) if (var.rename(buffer.getWindow().frame) == null) { + var.dispose(); + return; + } + if (!isAuto && var.cv_class instanceof Covis_primitive && !var.isArray) ((Covis_primitive)var.cv_class).edit(buffer.getWindow().frame,var,true); + var.setTransparency(1.0f); +// Informer.playSound("Default.wav"); + Informer.playSound("Pop.wav"); + buffer.putHistoryVar("var", var, true); + } + } + + public void addVariable(ClassStamp cs){ + boolean isAuto = buffer.getWindow().isAutoMode.isSelected(); + addVariable(cs,isAuto); + } + public void addVariable(ClassStamp cs, boolean isAuto){ + Variable var = null; + try { + var = new Variable(cs.cv_type.newInstance(true), buffer.getWindow().frame, buffer,false); + } catch (InvocationTargetException e1) { + e1.printStackTrace(); + } + if (var.type == null) return; + var.setTransparency(0.0f); + addChild(var); + var.addAttribute("moveTargetY", var); +// var.addAttribute("selectable", var); + var.setOffset(0,this.getHeight()); + layout(200); + if (!isAuto) if (var.rename(buffer.getWindow().frame) == null) { + var.dispose(); + return; + } + if (!isAuto && var.cv_class instanceof Covis_primitive && !var.isArray) ((Covis_primitive)var.cv_class).edit(buffer.getWindow().frame,var,true); + var.setTransparency(1.0f); +// Informer.playSound("Default.wav"); + Informer.playSound("Pop.wav"); + buffer.putHistoryVar("var", var, true); + } + + public boolean checkExistName(String input, Variable variable) { + List col = getChildrenReference(); + for(PNode p: col) { + if (p instanceof Variable){ + Variable v = (Variable)p; + if (v.getBaseVarName().equals(input) && v != variable) return true; + } + } + return false; + } + + public void move(PDimension d){ + translate(d.getWidth(), d.getHeight()); //履歴に関係ない動作 + for(PNode p: getChildrenReference()) { + if (p instanceof Move) ((Move)p).move(new PDimension()); + } + } + + public void removeAllVariables() { + List col = new ArrayList(getChildrenReference()); + for(PNode p: col) { + if (p instanceof Variable){ + Variable v = (Variable)p; + v.dispose(); + } + } + layout(500); + } + public Variable findVar(String head){ + List col = new ArrayList(getChildrenReference()); + for(PNode p: col) { + if (p instanceof Variable){ + Variable v = (Variable)p; + if (head.startsWith(v.getBaseVarName())) return v; + } + } + return null; + } + + public void updateVarNameChain(){ + List col = new ArrayList(getChildrenReference()); + for(PNode p: col) { + if (p instanceof Variable){ + Variable v = (Variable)p; +// System.out.println("start OrigVariable "+v.getVarName()); + v.appendVarNameRecursive(new Hashtable());//具体的には,リンク先に名前を設定(追加).その先にVarMがあれば,さらに追加していく. + } + } + layout(500); + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/Variable.java b/anchorgarden/src/main/java/jaist/css/covis/cls/Variable.java new file mode 100644 index 0000000..63ae87d --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/Variable.java @@ -0,0 +1,390 @@ +package jaist.css.covis.cls; + +import jaist.css.covis.CoVisBuffer; +import jaist.css.covis.Selectable; +import jaist.css.covis.hist.CVHist_Var; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.lang.reflect.Array; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Hashtable; +import java.util.List; +import java.util.TreeMap; + +import javax.swing.JFrame; +import javax.swing.JOptionPane; + +import edu.umd.cs.piccolo.PNode; +import edu.umd.cs.piccolo.nodes.PPath; +import edu.umd.cs.piccolo.nodes.PText; +import edu.umd.cs.piccolo.util.PDimension; + +public class Variable extends PPath implements Layoutable, Selectable, ToFront , Move{ + public static BasicStroke roundrectStroke = new BasicStroke(6f,BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 90.0f); + + private static final long serialVersionUID = -2274392520995258292L; + + public Covis_Type cv_class; + public Class type; + public Class elementType; + boolean isArray = false; + // public Covis_Object cv_class_for_tooptip; + // public static Variable selected_stamp; + // public static ArrayList stamps; + // static{ + // stamps = new ArrayList(); + // } + private boolean isSelected; + + public boolean isEnabled = true; + public Covis_Type object = null;//これがあるとMember + + PPath handle; + PText caption; + + public Anchor anchor; + private String varname_base; + private HashSet varnames; + + public CVHist_Var cvhist; + + long toFront_ts = 0; + public CoVisBuffer buffer; + + public static float top = 0; + + public void setVarName_Base(String s){ + varname_base = s; +// varnames.add(s); + } + public boolean isEnabled(){ + return isEnabled; + } + public void setEnabled(boolean b){ + isEnabled = b; + anchor.setAnchorEnabled(b); + } + public Variable(Covis_Type co, JFrame frame, CoVisBuffer buf, boolean isMember){ + cv_class = co; + buffer = buf; + varnames = new HashSet(); + if (cv_class instanceof Covis_Array){ + // 型(クラス・プリミティブ)選択 + String s; + if (((Covis_Array)cv_class).elementClassStr == null){ + s = (String)JOptionPane.showInputDialog( + frame, + "Choose Type of the Array", + "Choose Type", + JOptionPane.QUESTION_MESSAGE, + null, + ClassStamp.possibilities, + Covis_Array.lastSelectedClass); + if ((s != null) && (s.length() > 0)) { + // System.out.println(s+" Selected."); + Covis_Array.lastSelectedClass = s; + } else { + type = null; + } + } else { + s = ((Covis_Array)cv_class).elementClassStr; + } + try { + Class c = Class.forName("jaist.css.covis.cls.Covis_"+s); + Constructor constructor = c.getConstructor(CoVisBuffer.class, boolean.class); + cv_class = (Covis_Type) constructor.newInstance(buffer,true); + + type = Array.newInstance(c, 4).getClass(); + elementType = cv_class.getClass(); + + System.out.println("array "+type.toString()); + System.out.println("ele "+elementType.toString()); + isArray = true; + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (SecurityException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + } else { + type = cv_class.getClass(); + elementType = type; + } + setPathToRectangle(0,0,250,40); + setPaint(cv_class.getClassColor()); + setStrokePaint(Color.gray); + setStroke(new BasicStroke(1)); + + // co.setScale(0.3f); + // addChild(cv_class); + // layout(0); + + addAttribute("info", "ClassStamp "+this.toString()); + // addAttribute("selectable", this); + addAttribute("moveTargetY", this); + addAttribute("dragLayout", this); + + handle = new PPath(this.getPathReference()); + handle.addAttribute("moveTargetY", this); + handle.addAttribute("dragLayout", this); + handle.setTransparency(0.0f); + handle.setPaint(Color.pink); + handle.setStrokePaint(Color.red); + handle.setStroke(roundrectStroke); + handle.setPickable(true); + handle.moveToFront(); + handle.addAttribute("info", "ClassStamp handle"); + // handle.addAttribute("selectable", this); + // handle.addAttribute("exclusiveSelectable", stamps); + addChild(handle); + + if (!isMember){ + varname_base = cv_class.getNextVarName(isArray); + caption = new PText(getTypeName()+" "+varname_base); + caption.scale(2.2f); + caption.setOffset(10,3); + caption.addAttribute("moveTargetY", this); + caption.addAttribute("dragLayout", this); + addChild(caption); + caption.addAttribute("popupMenu", new VariableMenu(this)); + } + + if (cv_class instanceof Covis_Object || isArray){ + anchor = new Anchor(type, this); + anchor.setVarName(varname_base); + addChild(anchor); + anchor.setOffset(245,30); + if (!isMember){ + anchor.setAnchorEnabled(true); + } + } else { + // プリミティブなので,1つだけ追加 + Covis_primitive prim = (Covis_primitive) cv_class; + addChild(prim); + prim.setPathToRectangle(0,0,30,(float)getHeight()); + prim.setStroke(new BasicStroke(2)); + prim.justify(); + prim.setOffset(getWidth()-prim.getWidth(), (getHeight()-prim.getHeight())/2); + prim.addAttribute("moveTargetY", this); + prim.addAttribute("dragLayout", this); + prim.valueText.addAttribute("moveTargetY", this); + prim.valueText.addAttribute("dragLayout", this); + prim.valueText.addAttribute("popupMenu", new VariableMenu(this)); + } + + addAttribute("popupMenu", new VariableMenu(this)); + handle.addAttribute("popupMenu", new VariableMenu(this)); + // stamps.add(this); + } + public String getTypeName(){ + if (!isArray){ + // if (type.isAssignableFrom(Covis_Object.class)){ + return cv_class.getClsName(); + } else { + return cv_class.getClsName()+"[]"; + } + } + + public void layout(int dur){ + layoutExceptOne(null, dur); + } + + public void layoutExceptOne(PNode operationNode, int dur) { + List col = getChildrenReference(); + TreeMap map = new TreeMap(); + for(PNode p: col) map.put(p.getYOffset(), p); + + double offsetx = 10; + double endx = 10; + double offsety = 10; + double endy = 10; + double maxx = 0, maxy = 0; + for(PNode p : map.values()){ + // p.setOffset(offsetx, offsety); + double px = p.getFullBounds().width; + double py = p.getFullBounds().height; + if (maxx < offsetx + endx + px) maxx = offsetx + endx + px; + if (maxy < offsety + endy + py) maxy = offsety + endy + py; + if (operationNode != p) p.animateToPositionScaleRotation(offsetx, offsety+top, 1, 0, dur); + offsety += py; + offsety += 10; + } + animateToBounds(0, top, maxx, maxy, dur); + } + + public ArrayList getAllChildren() { + return null; + } + + public boolean isSelected() { + return isSelected; + } + + public void setSelected(boolean f, ArrayList list) { + isSelected = f; + if (f) handle.setTransparency(0.8f); else handle.setTransparency(0.0f); + if (f && list != null && !list.contains(this)) list.add(this); + if (!f && list != null && list.contains(this)) list.remove(this); + } + + public PNode theNode() { + return this; + } + + public void toggleSelected(ArrayList list) { + setSelected(!isSelected, list); + } + + public void removeLabel(Hashtable trash) { + if (trash != null) trash.put(this, getParent()); + removeFromParent(); + } + // public PNode getToolTipNode(){ + // if (cv_class_for_tooptip == null) { + // cv_class_for_tooptip = cv_class.Covis_clone(); + // cv_class_for_tooptip.setScale(0.5f); + // } + // return cv_class_for_tooptip; + // } + + public String getBaseVarName() { + return varname_base; + } + public void addVarNames(String prefix){ +// System.out.println("Variable.addVarNames"+prefix); + varnames.add(prefix); + } + public String getVarName(){ + StringBuffer sb = new StringBuffer(); + for(String s: getVarNamesAry()){ + sb.append(s+"\n"); + } + if (sb.length()==0) return sb.toString(); + return sb.toString().substring(0, sb.toString().length()-1); + } + public ArrayList getVarNamesAry(){ + ArrayList news = new ArrayList(); + if (this instanceof VariableM){ + String sepdot = "."; + if (object instanceof Covis_Array) sepdot = ""; + + for(String s: varnames){ + news.add(s+sepdot+varname_base); + } + } else { + news.add(varname_base); + } + return news; + } + public void clearVarNamesAry(){ + varnames.clear(); + } + + // この変数を削除する + public void dispose() { + if (anchor != null && anchor.destObject != null){ + anchor.destObject.detach(anchor); + } + Layoutable layout = (Layoutable) getParent(); + removeFromParent(); + layout.layout(200); + } + + // 変数名変更 + public String rename(JFrame f) { + String input; + while (true){ + if (isArray) { + input = JOptionPane.showInputDialog(f, "Input new name for "+cv_class.getClsName()+"[] variable.", varname_base); + } else { + input = JOptionPane.showInputDialog(f, "Input new name for "+cv_class.getClsName()+" variable.", varname_base); + } + if (input == null) return null; + if (input.equals("")) return null; + // 変数名重複チェック + // 親に聞くのが一番 + VarField parent = (VarField) getParent(); + + if (parent.checkExistName(input, this)) { + JOptionPane.showMessageDialog(null, "Same name is already used.\n\nPlease input other name.", "Rename Error", JOptionPane.WARNING_MESSAGE); + continue; + } + if (!input.matches("^[a-zA-Z_][a-zA-Z0-9]*")){ + JOptionPane.showMessageDialog(null, "Name should start with alphabet or _.\n\nPlease input other name.", "Rename Error", JOptionPane.WARNING_MESSAGE); + continue; + } + break; + } + + varname_base = input; + if (anchor != null) { + anchor.setVarName(varname_base); + } + caption.setText(getTypeName()+" "+varname_base); + if (anchor != null && anchor.destObject != null){ + anchor.destObject.tooltip = null; //変数名ツールチップを再構築 + } + return varname_base; + } + public void toFront(){ + toFront(System.currentTimeMillis()); + } + public void toFront(long ts) { + if (toFront_ts == ts) return; + toFront_ts = ts; + PNode parent = getParent(); + if (parent != null){ + // removeFromParent(); + parent.addChild(this); + if (parent instanceof ToFront) ((ToFront)parent).toFront(ts); + } + } + public void move(PDimension d){ + translate(d.getWidth(), d.getHeight()); //履歴に関係ない動作 + if (anchor != null) anchor.start_RewindThread(); + } + public String getConstructorInfo() { + if (cv_class instanceof Covis_Object || isArray) return getTypeName()+" "+varname_base+";"; + else return getTypeName()+" "+varname_base+" = "+((Covis_primitive)cv_class).value+";"; //getValue()にすると,''がとれてしまうので + } + public void setCVHist(CVHist_Var _cvhist) { + cvhist = _cvhist; + } + public String getEditValueInfo() { + if (cv_class instanceof Covis_Object || isArray) return getTypeName()+" "+varname_base+";"; + else return varname_base+" = "+((Covis_primitive)cv_class).value+";"; //getValue()にすると,''がとれてしまうので + } + public void appendVarNameRecursive(Hashtable checked) { +// System.out.println(varname_base); + if (anchor == null) return; + if (anchor.destObject != null){ +// if (checked.containsKey(this.hashCode())) return; +// checked.put(this.hashCode(), this); +// System.out.println("V append "+getVarName()); + anchor.destObject.appendVarNameRecursive(this, checked); + } + } + + public static String getShortestName(ArrayList src){ + if (src.size()==0) return null; + if (src.size()==1) return src.get(0); + String temp = src.get(0); + for(String s: src){ + if (s.length() < temp.length()) temp = s; + } + return temp; + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/VariableM.java b/anchorgarden/src/main/java/jaist/css/covis/cls/VariableM.java new file mode 100644 index 0000000..74eeb23 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/VariableM.java @@ -0,0 +1,200 @@ +package jaist.css.covis.cls; + +import jaist.css.covis.CoVisBuffer; +import jaist.css.covis.Selectable; +import jaist.css.covis.hist.CVHist_Var; + +import java.util.ArrayList; +import java.util.List; +import java.util.TreeMap; + +import javax.swing.JFrame; +import javax.swing.JOptionPane; + +import edu.umd.cs.piccolo.PNode; +import edu.umd.cs.piccolo.util.PDimension; + +public class VariableM extends Variable{ + private static final long serialVersionUID = 1922932400458120787L; + + + + public VariableM(Covis_Type co, JFrame frame, CoVisBuffer buf, String _varname, Covis_Type obj){ + super(co,frame,buf,true); + setPathToRectangle(0,0,20,20); + removeChild(handle); + handle = null; + + isEnabled = false; + object = obj; + + setVarName_Base(_varname); +// setPaint(cv_class.getClassColor()); + setStrokePaint(null); +// setStroke(new BasicStroke(1)); + +// co.setScale(0.3f); +// addChild(cv_class); +// layout(0); + +// addAttribute("info", "ClassStamp "+this.toString()); +//// addAttribute("selectable", this); +// addAttribute("moveTargetY", this); +// addAttribute("dragLayout", this); + + + addAttribute("info", null); + addAttribute("moveTargetY", null); + addAttribute("dragLayout", null); + + addAttribute("moveTarget", co); + addAttribute("tooltip", co); + + if (cv_class instanceof Covis_Object || isArray){ +// removeChild(anchor); +// anchor = new Anchor(type, this); +// anchor.setVarName(varname); +// addChild(anchor); + anchor.setOffset(20,20); + anchor.setAnchorEnabled(false); //まだ触れない.変数からリンクされたら,触れるようにする. + anchor.anchortab.addAttribute("moveTarget", co); + anchor.anchortab.addAttribute("tooltip", co); + } else { +// // プリミティブなので,1つだけ追加 +// Covis_primitive prim = (Covis_primitive) cv_class; +// addChild(prim); +// prim.setPathToRectangle(0,0,30,(float)getHeight()); +// prim.setStroke(new BasicStroke(2)); +// prim.justify(); +// prim.setOffset(getWidth()-prim.getWidth(), (getHeight()-prim.getHeight())/2); +// prim.addAttribute("moveTargetY", this); +// prim.addAttribute("dragLayout", this); +// prim.valueText.addAttribute("moveTargetY", this); +// prim.valueText.addAttribute("dragLayout", this); +// prim.valueText.addAttribute("popupMenu", new VariableMenu(this)); + } + +// addAttribute("popupMenu", new VariableMenu(this)); +// handle.addAttribute("popupMenu", new VariableMenu(this)); +// caption.addAttribute("popupMenu", new VariableMenu(this)); +// stamps.add(this); + } + public String getTypeName(){ + if (!isArray){ +// if (type.isAssignableFrom(Covis_Object.class)){ + return cv_class.getClsName(); + } else { + return cv_class.getClsName()+"[]"; + } + } + + public void layout(int dur){ + layoutExceptOne(null, dur); + } + + public void layoutExceptOne(PNode operationNode, int dur) { + List col = getChildrenReference(); + TreeMap map = new TreeMap(); + for(PNode p: col) map.put(p.getYOffset(), p); + + double offsetx = 10; + double endx = 10; + double offsety = 10; + double endy = 10; + double maxx = 0, maxy = 0; + for(PNode p : map.values()){ +// p.setOffset(offsetx, offsety); + double px = p.getFullBounds().width; + double py = p.getFullBounds().height; + if (maxx < offsetx + endx + px) maxx = offsetx + endx + px; + if (maxy < offsety + endy + py) maxy = offsety + endy + py; + if (operationNode != p) p.animateToPositionScaleRotation(offsetx, offsety+top, 1, 0, dur); + offsety += py; + offsety += 10; + } + animateToBounds(0, top, maxx, maxy, dur); + } + + public ArrayList getAllChildren() { + return null; + } + +// public String getBaseVarName() { +// return varname_base; +// } + +// この変数を削除する + public void dispose() { + if (anchor != null && anchor.destObject != null){ + anchor.destObject.detach(anchor); + } + Layoutable layout = (Layoutable) getParent(); + removeFromParent(); + layout.layout(200); + } + +// 変数名変更 + public String rename(JFrame f) { + String input; + while (true){ + if (isArray) { + input = JOptionPane.showInputDialog(f, "Input new name for "+cv_class.getClsName()+"[] variable.", getBaseVarName()); + } else { + input = JOptionPane.showInputDialog(f, "Input new name for "+cv_class.getClsName()+" variable.", getBaseVarName()); + } + if (input == null) return null; + if (input.equals("")) return null; + // 変数名重複チェック + // 親に聞くのが一番 + VarField parent = (VarField) getParent(); + + if (parent.checkExistName(input, this)) { + JOptionPane.showMessageDialog(null, "Same name is already used.\n\nPlease input other name.", "Rename Error", JOptionPane.WARNING_MESSAGE); + continue; + } + if (!input.matches("^[a-zA-Z_][a-zA-Z0-9]*")){ + JOptionPane.showMessageDialog(null, "Name should start with alphabet or _.\n\nPlease input other name.", "Rename Error", JOptionPane.WARNING_MESSAGE); + continue; + } + break; + } + + setVarName_Base(input); + if (anchor != null) { + anchor.setVarName(getBaseVarName()); + } + caption.setText(getTypeName()+" "+getBaseVarName()); + if (anchor != null && anchor.destObject != null){ + anchor.destObject.tooltip = null; //変数名ツールチップを再構築 + } + return getBaseVarName(); + } + public void toFront(){ + toFront(System.currentTimeMillis()); + } + public void toFront(long ts) { + if (toFront_ts == ts) return; + toFront_ts = ts; + PNode parent = getParent(); + if (parent != null){ +// removeFromParent(); + parent.addChild(this); + if (parent instanceof ToFront) ((ToFront)parent).toFront(ts); + } + } + public void move(PDimension d){ + translate(d.getWidth(), d.getHeight()); //履歴に関係ない動作 + if (anchor != null) anchor.start_RewindThread(); + } + public String getConstructorInfo() { + if (cv_class instanceof Covis_Object || isArray) return getTypeName()+" "+getBaseVarName()+";"; + else return getTypeName()+" "+getBaseVarName()+" = "+((Covis_primitive)cv_class).value+";"; //getValue()にすると,''がとれてしまうので + } + public void setCVHist(CVHist_Var _cvhist) { + cvhist = _cvhist; + } + public String getEditValueInfo() { + if (cv_class instanceof Covis_Object || isArray) return getTypeName()+" "+getBaseVarName()+";"; + else return getBaseVarName()+" = "+((Covis_primitive)cv_class).value+";"; //getValue()にすると,''がとれてしまうので + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/cls/VariableMenu.java b/anchorgarden/src/main/java/jaist/css/covis/cls/VariableMenu.java new file mode 100644 index 0000000..feaeb6b --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/cls/VariableMenu.java @@ -0,0 +1,141 @@ +package jaist.css.covis.cls; + +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.lang.reflect.Method; + +import javax.swing.JFrame; +import javax.swing.JMenu; +import javax.swing.JMenuItem; +import javax.swing.JPopupMenu; + +import jaist.css.covis.mi.WrapMethod; +import jaist.css.covis.util.FramePopup; + + +public class VariableMenu extends JPopupMenu implements FramePopup { + Variable v; + JFrame frame; + private static final long serialVersionUID = -3662668322301800275L; + + JMenu methodMenu; + JMenuItem deleteMenuItem; + + public VariableMenu(Variable _v) { + this.v = _v; + + JMenuItem menuItem; + + setLightWeightPopupEnabled(false); + + menuItem = new JMenuItem("cancel"); + add(menuItem); + + + addSeparator(); + // + // menuItem = new JMenuItem("method"); + // add(menuItem); + // + // menuItem.addActionListener(new ActionListener() { + // public void actionPerformed(ActionEvent e) { + // String mes = JOptionPane.showInputDialog(null,"input method name"); + // Method meth = null; + // try { + // meth = v.anchor.dest.getClass().getMethod(mes, new Class[]{}); + // } catch (SecurityException e1) { + // e1.printStackTrace(); + // } catch (NoSuchMethodException e1) { + // e1.printStackTrace(); + // } + // if (meth != null){ + // try { + //// meth.invoke(v.anchor.dest, new Object[]{null}); + // meth.invoke(v.anchor.dest); + // } catch (IllegalArgumentException e1) { + // e1.printStackTrace(); + // } catch (IllegalAccessException e1) { + // // TODO Auto-generated catch block + // e1.printStackTrace(); + // } catch (InvocationTargetException e1) { + // // TODO Auto-generated catch block + // e1.printStackTrace(); + // } + // } + // + // } + // }); + + /* if (false){ + addSeparator(); + menuItem = new JMenuItem("rename"); + add(menuItem); + menuItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + // System.out.println(e.getSource().getClass().getName()); + v.rename(frame); + } + }); + } + */ + if (v.cv_class instanceof Covis_primitive && !v.isArray){ + addSeparator(); + menuItem = new JMenuItem("edit value"); + add(menuItem); + menuItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + // System.out.println(e.getSource().getClass().getName()); + ((Covis_primitive)v.cv_class).edit(frame,v); + } + }); + } + + + } + + public void showWithFrame(Component c, int x, int y, JFrame _f) { + frame = _f; + + if (deleteMenuItem != null) remove(deleteMenuItem); + + if (v.anchor != null) + if (v.anchor.destObject != null){ + if (methodMenu != null) remove(methodMenu); + //メソッド探索開始 + methodMenu = new JMenu("Method"); + add(methodMenu); + // Method[] methods = v.anchor.destObject.getClass().getDeclaredMethods(); + Method[] methods = v.anchor.destObject.getClass().getMethods(); + for(Method m: methods){ + if (m.getName().startsWith("covis_")){ + String mname = m.toString().replaceAll("java\\.lang\\.", ""); + // System.out.println("mname "+mname); + String mname2 = mname.replaceAll("jaist\\.css\\.covis\\.cls\\.Covis\\_", ""); + // System.out.println("mname2 " +mname2); + String mname3 = mname2.replaceAll("covis\\_", ""); + // System.out.println("mname3 "+mname3); + + //2つめのスペースから,.までを削除 + int lastspcPos = mname3.lastIndexOf(" "); + int lastdotPos = mname3.lastIndexOf("."); + String mname4 = mname3.substring(0,lastspcPos)+" "+mname3.substring(lastdotPos+1); + // System.out.println("mname4 "+mname4); + JMenuItem mi = new JMenuItem(new WrapMethod(m, v.anchor.destObject, mname4, v)); + methodMenu.add(mi); + } + } + + } + deleteMenuItem = new JMenuItem("delete"); + add(deleteMenuItem); + deleteMenuItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + v.dispose(); + } + }); + + show(c, x, y); + } +} + diff --git a/anchorgarden/src/main/java/jaist/css/covis/filefilter/BookFileFilter.java b/anchorgarden/src/main/java/jaist/css/covis/filefilter/BookFileFilter.java new file mode 100644 index 0000000..7b0bf30 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/filefilter/BookFileFilter.java @@ -0,0 +1,48 @@ +package jaist.css.covis.filefilter; + +import java.io.File; + +/** + * ブックファイル用フィルタ + * + * 以前は,複数のページデータを集めて,Bookファイルを1つ読み込むだけですむようにしていた. + * 現在は,ページデータは単体でファイルに保存しておき,組み合わせて並び替えたりしながら読み込める + * ようにした. + * @author miuramo + * + */ + +@Deprecated +public class BookFileFilter extends javax.swing.filechooser.FileFilter implements + java.io.FilenameFilter { + String suffix; + + public BookFileFilter(String s) { + suffix = s; + } + + public boolean accept(File dir) { + // if (dir.isDirectory()) return true; + String name = dir.getName(); + if (name.endsWith(suffix) || name.endsWith(".book") + || dir.isDirectory()) { + return true; + } else { + return false; + } + } + + public boolean accept(File dir, String name) { + // if (dir.isDirectory()) return true; + if (name.endsWith(suffix) || name.endsWith(".book") + || dir.isDirectory()) { + return true; + } else { + return false; + } + } + + public String getDescription() { + return "book file (*.book)"; + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/filefilter/ImageFileFilter.java b/anchorgarden/src/main/java/jaist/css/covis/filefilter/ImageFileFilter.java new file mode 100644 index 0000000..6333485 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/filefilter/ImageFileFilter.java @@ -0,0 +1,51 @@ +package jaist.css.covis.filefilter; + +import java.io.File; + +/** + * 以前は,BookEditorと呼ばれるページ編集用の特別のプログラムを起動しないと + * ページのマークを編集できなかった. + * BookEditorで画像ファイルを読み込んで背景画像とするときに使用されていた. + * + * 現在は,直接PageBrowserに画像ファイルをドラッグ&ドロップするだけでページ画像の設定 + * ができるので,不要. + * + * @author miuramo + * + */ +@Deprecated +public class ImageFileFilter extends javax.swing.filechooser.FileFilter implements + java.io.FilenameFilter { + String suffix; + + public ImageFileFilter(String s) { + suffix = s; + } + + public boolean accept(File dir) { + // if (dir.isDirectory()) return true; + String name = dir.getName(); + if (name.endsWith(suffix) || name.endsWith(".png") + || name.endsWith(".jpg") || name.endsWith(".gif") + || dir.isDirectory()) { + return true; + } else { + return false; + } + } + + public boolean accept(File dir, String name) { + // if (dir.isDirectory()) return true; + if (name.endsWith(suffix) || name.endsWith(".png") + || name.endsWith(".jpg") || name.endsWith(".gif") + || dir.isDirectory()) { + return true; + } else { + return false; + } + } + + public String getDescription() { + return "image file (*.png, *.jpg, *.gif)"; + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/filefilter/NullFileFilter.java b/anchorgarden/src/main/java/jaist/css/covis/filefilter/NullFileFilter.java new file mode 100644 index 0000000..d4ced7c --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/filefilter/NullFileFilter.java @@ -0,0 +1,46 @@ +package jaist.css.covis.filefilter; + +import java.io.File; + +/** + * Javaのファイルダイアログ(JFileChooser)で,特定の拡張子のファイルのみを + * 選んで表示したいときに,用いる. + * + * 拡張子部分をコンストラクタで指定できるため,現在も使用中. + * + * @author miuramo + * + */ +public class NullFileFilter extends javax.swing.filechooser.FileFilter implements + java.io.FilenameFilter { + String suffix; + + /** + * コンストラクタ + * @param s 拡張子の文字列(例,txt) + */ + public NullFileFilter(String s) { + suffix = s; + } + + public boolean accept(File dir) { + String name = dir.getName(); + if (name.endsWith(suffix) || dir.isDirectory()) { + return true; + } else { + return false; + } + } + + public boolean accept(File dir, String name) { + if (name.endsWith(suffix)) { + return true; + } else { + return false; + } + } + + public String getDescription() { + return suffix; + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/filefilter/SSFileFilter.java b/anchorgarden/src/main/java/jaist/css/covis/filefilter/SSFileFilter.java new file mode 100644 index 0000000..37137fb --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/filefilter/SSFileFilter.java @@ -0,0 +1,43 @@ +package jaist.css.covis.filefilter; + +import java.io.File; + +/** + * 以前DB化するまえは,それぞれのPDAから読み込んだ筆記データをShortStroke Log (sslog, *.ss) + * またはそれをGZIPで圧縮した*.ssgファイルとして保存したり,呼び出したりしていた. + * + * そのときの名残り. + * + * @author miuramo + * + */ +@Deprecated +public class SSFileFilter extends javax.swing.filechooser.FileFilter implements + java.io.FilenameFilter { + String suffix; + + public SSFileFilter(String s) { + suffix = s; + } + + public boolean accept(File dir) { + String name = dir.getName(); + if (name.endsWith(suffix) || name.endsWith(".ssg") || dir.isDirectory()) { + return true; + } else { + return false; + } + } + + public boolean accept(File dir, String name) { + if (name.endsWith(suffix) || name.endsWith(".ssg")) { + return true; + } else { + return false; + } + } + + public String getDescription() { + return "ss log (*.ss, *.ssg)"; + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/filefilter/package-info.java b/anchorgarden/src/main/java/jaist/css/covis/filefilter/package-info.java new file mode 100644 index 0000000..db2c136 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/filefilter/package-info.java @@ -0,0 +1,6 @@ +/** + * ファイルの選択ダイアログに表示されるファイルを制限するためのフィルタクラスです. + * + */ + +package jaist.css.covis.filefilter; \ No newline at end of file diff --git a/anchorgarden/src/main/java/jaist/css/covis/fm/AbstractFlowMenu.java b/anchorgarden/src/main/java/jaist/css/covis/fm/AbstractFlowMenu.java new file mode 100644 index 0000000..b30c738 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/fm/AbstractFlowMenu.java @@ -0,0 +1,169 @@ +package jaist.css.covis.fm; + +import java.awt.Cursor; +import java.awt.geom.Point2D; + +import javax.swing.JFrame; + +import edu.umd.cs.piccolo.PCamera; +import edu.umd.cs.piccolo.PCanvas; +import edu.umd.cs.piccolo.PNode; +import edu.umd.cs.piccolo.event.PDragSequenceEventHandler; +import edu.umd.cs.piccolo.event.PInputEvent; + +/** + * フローメニューの共通部分 + * @author miuramo + * + */ +public class AbstractFlowMenu extends PDragSequenceEventHandler { + + public static Cursor handcursor = new Cursor(Cursor.HAND_CURSOR); + + public static Cursor defaultcursor = new Cursor(Cursor.DEFAULT_CURSOR); + + // public V geopanel; + // public PPath squiggle; + public int strokecount; + + public long stime; + + public PNode target; + + public JFrame frame; + + // public StudentPanel sptarget; + public Point2D tp; + + public State fmenu, fmenu_orig; + + public PCanvas canvas; + + public PCamera camera; + + public Point2D basep; + + public Point2D camerap; + + // public PBounds sptargetbb; + // private State now_state; + public java.util.Timer daemon; + + public boolean outofbounds = false; + +// Category log; + + // public Vector redpenv; + // double[2] 配列のベクトルを入れるだけ。作ったら各spanelにまかせる。StringBufferはここでは不要。あとで外す。 + + public PNode getTarget() { + return target; + } + + // public StudentPanel getSpTarget(){ + // return sptarget; + // } + public int getX() { + return (int) camerap.getX(); + } + + public int getY() { + return (int) camerap.getY(); + } + + // メニューを表示,または非表示にする + public void showMenu(boolean f) { + if (f) { + fmenu = fmenu_orig; + fmenu.paint(); + if (fmenu != null) + camera.addChild(fmenu); + if (frame != null) + frame.setCursor(handcursor); + } else { + if (daemon != null) { + daemon.cancel(); + daemon = null; + } + if (fmenu != null) { + camera.addChild(fmenu); + camera.removeChild(fmenu); + } + fmenu = null; + target = null; + strokecount = 0; + } + } + + // メニューが表示中かどうか(直接,カメラの子ノードとして存在するかどうかを調べる) + public boolean isMenuShown() { + if (fmenu == null) + return false; + return fmenu.isDescendentOf(camera); + } + + public void changeState(State newstate) { + if (fmenu != null) { + camera.addChild(fmenu); + camera.removeChild(fmenu); + } + fmenu = newstate; + fmenu.paint(); + camera.addChild(fmenu); + } + + public AbstractFlowMenu(JFrame f, PCanvas can, PCamera cam) { + frame = f; + canvas = can; + camera = cam; + +// log = Logger.getLogger(AbstractFlowMenu.class.getName()); + } + + public void startDrag_pre(PInputEvent e) { + target = e.getPickedNode(); + tp = target.getOffset(); + basep = e.getPosition(); +// log.debug(basep); + camerap = e.getPositionRelativeTo(camera); + } + + public void startDrag_post(PInputEvent e) { + // サブクラスで,必要なMyTimerTask_forYourClass を起動し,スケジュールする + } + + public void startDrag(PInputEvent e) { + super.startDrag(e); + // canvas.setCursor(handcursor); + } + + public void drag(PInputEvent e) { + super.drag(e); + } + + public void endDrag(PInputEvent e) { + super.endDrag(e); + endDrag_first(e); + endDrag_mid(e); + endDrag_end(e); + } + + public void endDrag_first(PInputEvent e) { + if (fmenu != null) + fmenu.endDrag(e); + if (daemon != null) { + daemon.cancel(); + daemon = null; + } + } + + public void endDrag_mid(PInputEvent e) { + } + + public void endDrag_end(PInputEvent e) { + showMenu(false); + outofbounds = false; + if (frame != null) + frame.setCursor(defaultcursor); + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/fm/DefaultState.java b/anchorgarden/src/main/java/jaist/css/covis/fm/DefaultState.java new file mode 100644 index 0000000..fbc9bbc --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/fm/DefaultState.java @@ -0,0 +1,146 @@ +package jaist.css.covis.fm; + +import java.awt.Font; +import java.awt.geom.AffineTransform; +import java.awt.geom.Arc2D; +import java.awt.geom.Area; +import java.awt.geom.Ellipse2D; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; + +import edu.umd.cs.piccolo.event.PInputEvent; +import edu.umd.cs.piccolo.nodes.PPath; +import edu.umd.cs.piccolo.nodes.PText; + +/** + * 一般的な「状態」 + * + * @author miuramo + * + */ +@SuppressWarnings("serial") +public class DefaultState extends State { + public DefaultState(AbstractFlowMenu f, String n) { + super(f, n); + } + + public void drag(PInputEvent e) { + super.drag(e); + Point2D cp = e.getPositionRelativeTo(owner.camera); + index = getPlace((int) cp.getX(), (int) cp.getY()); + updateMenu(index); + // System.out.println("x: "+cp.getX()+" y: "+cp.getY() +" st "+index); + } + + public void paint() { + removeAllChildren(); + Ellipse2D.Double ed2 = new Ellipse2D.Double(-SIZE / 2.0 - SIZE / 16.0, + -SIZE / 2.0 - SIZE / 16.0, SIZE + SIZE / 8.0, SIZE + SIZE / 8.0); + // Arc2D.Double ac = new + // Arc2D.Double(-SIZE,-SIZE,SIZE*2.0,SIZE*2.0,0,-44, Arc2D.PIE); + Arc2D.Double ac = new Arc2D.Double(-SIZE / 4.0 * 5.0, + -SIZE / 4.0 * 5.0, SIZE / 2.0 * 5.0, SIZE / 2.0 * 5.0, 0, + -43.5, Arc2D.PIE); + @SuppressWarnings("unused") + Rectangle2D.Double rd = new Rectangle2D.Double(0, 0, SIZE, SIZE); + + Area a = new Area(); + a.add(new Area(ac)); + a.subtract(new Area(ed2)); + AffineTransform at = new AffineTransform(); + + int mx = owner.getX(); + int my = owner.getY(); + int sx = 0, sy = 0; + + Font f = (new PText()).getFont(); + Font nf = new Font(f.getFontName(), Font.BOLD, (int) (14 * SIZE / 80.0)); + // g2.setFont(nf); + + for (int i = 0; i < 8; i++) { + + at.setToTranslation(mx, my); + at.rotate(Math.toRadians(-112 - i * 45)); + Area b = a.createTransformedArea(at); + + itempath[i + 2] = new PPath(b); + itempath[i + 2].setStroke(null); + if (nextstates[i + 2] == null) { + itempath[i + 2].setPaint(no); + } else { + if (nextstates[i + 2].isEnabled()) { + itempath[i + 2].setPaint(fill); + } else { + itempath[i + 2].setPaint(no); + } + } + // p.setStroke(new + // BasicStroke(2,BasicStroke.CAP_ROUND,BasicStroke.CAP_ROUND)); + // p.setStrokePaint(Color.gray); + + // if(!isEnable(i+2)){ + // p.setPaint(no);//continue; + // // p.setStrokePaint(no); + // } + // if(state == i+2){ + // p.setPaint(choose); + // // p.setStrokePaint(choose); + // } + // else{ + // p.setPaint(fill); + // // p.setStrokePaint(fill); + // } + addChild(itempath[i + 2]); + } + for (int i = 0; i < 8; i++) { + switch (i) { + case 0: + sx = (int) (Math.cos(105.0 * RD) * (double) SIZE + mx); + sy = (int) (-1.3 * Math.sin(135.0 * RD) * (double) SIZE + my); + break; + case 1: + sx = (int) (Math.cos(150.0 * RD) * (double) SIZE + mx); + sy = (int) (-1.2 * Math.sin(150.0 * RD) * (double) SIZE + my); + break; + // case 2: sx = (int)(Math.cos(180.0*RD)*(double)SIZE+mx); + case 2: + sx = (int) (1.1 * Math.cos(180.0 * RD) * (double) SIZE + mx); + sy = (int) (-Math.sin(180.0 * RD) * (double) SIZE + my); + break; + case 3: + sx = (int) (Math.cos(210.0 * RD) * (double) SIZE + mx); + sy = (int) (-Math.sin(220.0 * RD) * (double) SIZE + my); + break; + case 4: + sx = (int) (Math.cos(255.0 * RD) * (double) SIZE + mx); + sy = (int) (-Math.sin(235.0 * RD) * (double) SIZE + my); + break; + case 5: + sx = (int) (1.4 * Math.cos(290.0 * RD) * (double) SIZE + mx); + sy = (int) (-Math.sin(320.0 * RD) * (double) SIZE + my); + break; + case 6: + sx = (int) (1.1 * Math.cos(55.0 * RD) * (double) SIZE + mx); + sy = (int) (-Math.sin(0.0 * RD) * (double) SIZE + my); + break; + case 7: + sx = (int) (1.5 * Math.cos(75 * RD) * (double) SIZE + mx); + sy = (int) (-1.3 * Math.sin(30.0 * RD) * (double) SIZE + my); + break; + } + // g2.setColor(strColor); + String sst = getString(i + 2); + if (sst != null) { + PText pt = new PText(sst); + pt.offset(sx, sy); + pt.setFont(nf); + // System.out.println(i + " "+getString(i+2)+" "+sx+" "+sy); + addChild(pt); + } + } + PText pt2 = new PText(getName()); + pt2.offset((mx - SIZE / 2.0 + 20), my); + pt2.setFont(nf); + addChild(pt2); + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/fm/FlowMenu_TMRG.java b/anchorgarden/src/main/java/jaist/css/covis/fm/FlowMenu_TMRG.java new file mode 100644 index 0000000..c333558 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/fm/FlowMenu_TMRG.java @@ -0,0 +1,272 @@ +package jaist.css.covis.fm; + +import jaist.css.covis.AnchorGarden; +import jaist.css.covis.CoVisWindow_SelectionRegionHandler; +import jaist.css.covis.Selectable; +import jaist.css.covis.cls.ClickHandler; +import jaist.css.covis.cls.DragNotice; +import jaist.css.covis.cls.Layoutable; +import jaist.css.covis.cls.LinkMovable; +import jaist.css.covis.cls.Move; + +import java.awt.geom.Point2D; +import java.util.ArrayList; + +import edu.umd.cs.piccolo.PNode; +import edu.umd.cs.piccolo.event.PInputEvent; +import edu.umd.cs.piccolo.util.PBounds; +import edu.umd.cs.piccolo.util.PDimension; + +/** + * フローメニュー + * + * @author miuramo + * + */ +public class FlowMenu_TMRG extends AbstractFlowMenu { + +// Category log; + + public AnchorGarden window; + + public Point2D inkbasep; + + public PBounds sptargetbb; + + public String info; // PNode.getAttribute("info"); + + public PNode moveTarget; // PNode.getAttribute("moveTarget"); + + public PNode moveTargetY; // PNode.getAttribute("moveTargetY"); + + public Selectable selectTarget; // PNode.getAttribute("selectable"); + + public ArrayList exclusiveSelectionBag = new ArrayList(); + + public ClickHandler clickHandler; // PNode.getAttribute("clickHandler"); + + public DragNotice dragNotice; + + public long lastRelease; + + public ArrayList drags; + + public CoVisWindow_SelectionRegionHandler selectionHandler; + + public boolean isShiftDown; + + public boolean enabled = true; + + public ArrayList childGroupingBag = new ArrayList(); + + public PNode getTarget() { + return target; + } + + public int getX() { + return (int) camerap.getX(); + } + + public int getY() { + return (int) camerap.getY(); + } + + public void changeState(State newstate) { + if (fmenu != null) { + camera.addChild(fmenu); + camera.removeChild(fmenu); + } + fmenu = newstate; + fmenu.paint(); + camera.addChild(fmenu); + } + + public FlowMenu_TMRG(AnchorGarden _window) { + super(_window.frame, _window.getCanvas(), _window.getCanvas().getCamera()); +// log = Logger.getLogger(FlowMenu_TMRG.class.getName()); + + window = _window; + + selectionHandler = new CoVisWindow_SelectionRegionHandler(window); + + drags = new ArrayList(); + + // fmenu setup + fmenu_orig = new DefaultState(this, ""); + } + + + + + + public void startDrag_pre(PInputEvent e) { + super.startDrag_pre(e); + } + + public void startDrag_post(PInputEvent e) { + Object o = target.getAttribute("NoFlowMenu"); + if (o != null && o.toString().equals("true")) { + } else { + // TODO:メニューの起動 + /* + daemon = new java.util.Timer(); + daemon.schedule(new MyTimerTask_GKJFlowMenuOpen((float) camerap.getX(), + (float) camerap.getY(), this), 3000); + */ + } + } + + @SuppressWarnings("unchecked") + public void startDrag(PInputEvent e) { + super.startDrag(e); + startDrag_pre(e); + + if (target.getAttribute("info")!=null){ + info = (String) target.getAttribute("info"); +// log.debug(info); +// log.debug(target.getBounds().toString()); + } + if (target.getAttribute("moveTarget")!=null){ + moveTarget = (PNode) target.getAttribute("moveTarget"); + } + if (target.getAttribute("moveTargetY")!=null){ + moveTargetY = (PNode) target.getAttribute("moveTargetY"); + } + if (target.getAttribute("dragNotice")!=null){ + dragNotice = (DragNotice) target.getAttribute("dragNotice"); + dragNotice.setDragNotice(true); + } + if (target.getAttribute("exclusiveSelectable")!=null){ + selectTarget = (Selectable) target.getAttribute("selectable"); + exclusiveSelectionBag = (ArrayList) target.getAttribute("exclusiveSelectable"); + } + if (target.getAttribute("clickHandler")!=null){ + clickHandler = (ClickHandler) target.getAttribute("clickHandler"); + } + if (e.isShiftDown()) { + isShiftDown = true; + enabled = false; + selectionHandler.startDrag(e); + startDrag_post(e); + return; + } + startDrag_post(e); + + window.setShowToolTip(false); + + } + + public void drag(PInputEvent e) { + super.drag(e); + + if (fmenu != null) + fmenu.drag(e); + else { + if (isShiftDown && e.isShiftDown()) { + selectionHandler.drag(e); + return; + } + drags.add(e); + if (moveTarget != null){ + PDimension d = e.getDeltaRelativeTo(window.canvas.getLayer()); + if (moveTarget instanceof Move) ((Move)moveTarget).move(d); + // System.out.println("XY: "+moveTarget.getTransform().getTranslateX()+" "+moveTarget.getTransform().getTranslateY()); + if (moveTarget.getAttribute("moveLink") != null){ + LinkMovable lm = (LinkMovable) moveTarget.getAttribute("moveLink"); + lm.update(); + } + if (dragNotice != null){ + dragNotice.drag(e, window.buffer); + } + } else if (moveTargetY != null){ + PDimension d = e.getDeltaRelativeTo(window.canvas.getLayer()); + if (moveTargetY instanceof Move) ((Move)moveTargetY).move(new PDimension(0,d.getHeight())); + + if (moveTargetY.getAttribute("dragLayout")!=null){ + Object o = ((PNode)moveTargetY.getAttribute("dragLayout")).getParent(); + if (o instanceof Layoutable){ + Layoutable layout = (Layoutable) (((PNode)moveTargetY.getAttribute("dragLayout")).getParent()); + layout.layoutExceptOne(moveTargetY, 0); + } + } + if (moveTargetY.getAttribute("moveLink")!=null){ + LinkMovable lm = (LinkMovable) moveTargetY.getAttribute("moveLink"); + lm.update(); + } + } else { + PDimension d = e.getDelta(); + window.canvas.getCamera().translateView(d.getWidth(), d.getHeight()); + } + } + + } + + public void endDrag(PInputEvent e) { + super.endDrag(e); + + if (fmenu != null) + fmenu.endDrag(e); + // if (isShiftDown) { + // selectionHandler.endDrag(e); + // } + if (drags.size() < 3){ + if (selectTarget != null){ + ArrayList copyBag = new ArrayList(exclusiveSelectionBag); + copyBag.remove(selectTarget); + for(Selectable sel : copyBag){ + sel.setSelected(false, null); + } + selectTarget.toggleSelected(null); + } + if (clickHandler != null){ + clickHandler.clicked(e, this); + } + } + clickHandler = null; + + for(Selectable sel: new ArrayList(childGroupingBag)) sel.setSelected(false, childGroupingBag); + + if (daemon != null) { + daemon.cancel(); + daemon = null; + } + // long ctime = (new Date().getTime() - stime); + // if (System.currentTimeMillis() - lastRelease < 350){ //ダブルクリック判定 dbl + // if (moveTarget != null){ + // PBounds pb = moveTarget.getGlobalFullBounds(); + // pb = BUtil.zoomBounds(pb, 1.05); + // window.canvas.getCamera().animateViewToCenterBounds(pb, true, 500); + // } + // } + + + moveTarget = null; + + if (moveTargetY != null && moveTargetY.getAttribute("dragLayout")!=null){ + Object o = ((PNode)moveTargetY.getAttribute("dragLayout")).getParent(); + if (o instanceof Layoutable){ + Layoutable layout = (Layoutable) (((PNode)moveTargetY.getAttribute("dragLayout")).getParent()); + layout.layout(200); + } + } + moveTargetY = null; + selectTarget = null; + lastRelease = System.currentTimeMillis(); + + + if (dragNotice != null){ + dragNotice.endDrag(e,window.buffer); + dragNotice.setDragNotice(false); + dragNotice = null; + } + + window.setShowToolTip(true); + drags.clear(); + enabled = true; + isShiftDown = false; + } + + public void endDrag_mid(PInputEvent e) { + super.endDrag_mid(e); + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/fm/JogState.java b/anchorgarden/src/main/java/jaist/css/covis/fm/JogState.java new file mode 100644 index 0000000..94039c9 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/fm/JogState.java @@ -0,0 +1,167 @@ +package jaist.css.covis.fm; + +import jaist.css.covis.AnchorGarden; + +import java.awt.Font; +import java.awt.geom.AffineTransform; +import java.awt.geom.Arc2D; +import java.awt.geom.Area; +import java.awt.geom.Ellipse2D; +import java.awt.geom.Point2D; + +import edu.umd.cs.piccolo.event.PInputEvent; +import edu.umd.cs.piccolo.nodes.PPath; +import edu.umd.cs.piccolo.nodes.PText; + +/** + * ジョグダイアル状態 + * + * @author miuramo + * + */ +public @SuppressWarnings("serial") +class JogState extends State { + protected int width = 10; + + protected int value = 0; + + protected static double[] limit = { SIZE / 4.0, SIZE / 2.0, + SIZE / 4.0 * 5.0, SIZE / 4.0 * 5.0 }; + + // 無保証のフィールド + AnchorGarden sview; + + public JogState(AbstractFlowMenu f, String n) { + super(f, n); + + // 無保証のフィールドをセット + sview = ((FlowMenu_TMRG) f).window; + } + + public String getValue() { + return String.valueOf(value); + } + + public void updateMenu(int index) { + @SuppressWarnings("unused") + int temp = old_index; + int diff; + if (index != old_index) { + if (index != 1) + itempath[index].setPaint(choose); + if (old_index != 1) + itempath[old_index].setPaint(fill); + if (index != 1 && old_index != 1) { + diff = old_index - index; + if (Math.abs(diff) > 14) { // 2->17 or 17->2 + diff = -diff / 15; + } + sview.zoomPane(diff); + } + } + old_index = index; + } + + public int getPlace(int x, int y) { + int xx, yy, id; + int rr; + int mx = owner.getX(); + int my = owner.getY(); + xx = x - mx; + yy = my - y; + distance = rr = (int) (Math.sqrt(xx * xx + yy * yy)); + if (rr < limit[1]) { // メニューの中心 + id = 1; + } else { // メニューの外側 + double r = Math.atan((double) yy / (double) xx) / RD; + if (xx < 0) { + r += 180.0; + } + if (r < 67.5) { + r += 360.0; + } + id = (int) ((r - 67.5) / 22.5) + 2; + } + return id; + } + + public void drag(PInputEvent e) { + super.drag(e); + Point2D cp = e.getPositionRelativeTo(owner.camera); + index = getPlace((int) cp.getX(), (int) cp.getY()); + updateMenu(index); + // System.out.println("x: "+cp.getX()+" y: "+cp.getY() +" st "+index); + } + + public void paint() { + removeAllChildren(); + int mx = owner.getX(); + int my = owner.getY(); + // int sx = 0, sy = 0; + + // for(int k=0; k<3; k++){ + for (int k = 1; k < 2; k++) { + Ellipse2D.Double ed2 = new Ellipse2D.Double(-limit[k] - 1, + -limit[k] - 1, limit[k] * 2 + 2, limit[k] * 2 + 2); + Arc2D.Double ac = new Arc2D.Double(-limit[k + 1], -limit[k + 1], + limit[k + 1] * 2, limit[k + 1] * 2, 0, -21, Arc2D.PIE); + // ^^^ + Area a = new Area(); + a.add(new Area(ac)); + a.subtract(new Area(ed2)); + AffineTransform at = new AffineTransform(); + + for (int i = 0; i < 16; i++) { + // g2.setStroke(new + // BasicStroke(2,BasicStroke.CAP_ROUND,BasicStroke.CAP_ROUND)); + + at.setToTranslation(mx, my); + at.rotate(Math.toRadians(-89.5 - i * 22.5)); + Area b = a.createTransformedArea(at); + + PPath bpath = new PPath(b); + // if(state == i+2 && limit[k] < distance && (distance < + // limit[k+1] || k ==2)){ + // bpath.setPaint(choose); + // } + // else{ + bpath.setPaint(fill); + bpath.setStroke(null); + addChild(bpath); + itempath[i + 2] = bpath; + } + } + Font f = (new PText()).getFont(); + Font nf = new Font(f.getFontName(), Font.BOLD, (int) (16 * SIZE / 80.0)); + // FontMetrics fm = g2.getFontMetrics(nf); + String s = "<<++ -->>"; + char[] c = new char[s.length()]; + s.getChars(0, s.length(), c, 0); + PText pt = new PText(s); + pt.setFont(nf); + // topleftnumText.offset(mx - fm.charsWidth(c, 0, c.length)/2, + // (int)(my+limit[1]+10)); + pt.offset(mx - 45, (int) (my + limit[1] + 10)); + + s = getValue(); + c = new char[s.length()]; + s.getChars(0, s.length(), c, 0); + PText pt2 = new PText(s); + pt2.setFont(nf); + pt2.offset(mx, my); + // pt2.offset(mx-fm.charsWidth(c, 0, c.length)/2, my); + addChild(pt); + addChild(pt2); + } + + public void setWidth(int rr) { + if (rr < limit[1]) { + width = 1; + } else if (rr < limit[2]) { + width = 10; + } else { + // width=50; + width = 10; + } + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/fm/MyTimerTask_Abstract.java b/anchorgarden/src/main/java/jaist/css/covis/fm/MyTimerTask_Abstract.java new file mode 100644 index 0000000..0ed9eb3 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/fm/MyTimerTask_Abstract.java @@ -0,0 +1,37 @@ +package jaist.css.covis.fm; + +import java.awt.Cursor; +import java.util.TimerTask; + +/** + * 一般的なタイマータスク + * + * + * @author miuramo + * + */ +public class MyTimerTask_Abstract extends TimerTask { + public static Cursor handcursor = new Cursor(Cursor.HAND_CURSOR); + + public static Cursor defaultcursor = new Cursor(Cursor.DEFAULT_CURSOR); + + float x, y; + + AbstractFlowMenu fm_super; + + public MyTimerTask_Abstract(float _x, float _y, AbstractFlowMenu f) { + x = _x; + y = _y; + fm_super = f; + } + + public void run() { + } + + public void preopen() { + } + + public void openMenu() { + fm_super.showMenu(true); + } +} \ No newline at end of file diff --git a/anchorgarden/src/main/java/jaist/css/covis/fm/MyTimerTask_GKJFlowMenuOpen.java b/anchorgarden/src/main/java/jaist/css/covis/fm/MyTimerTask_GKJFlowMenuOpen.java new file mode 100644 index 0000000..3b27245 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/fm/MyTimerTask_GKJFlowMenuOpen.java @@ -0,0 +1,35 @@ +package jaist.css.covis.fm; + +/** + * フローメニューが開くときのタイマータスク + * + * @author miuramo + * + */ +public class MyTimerTask_GKJFlowMenuOpen extends MyTimerTask_Abstract { + FlowMenu_TMRG fm; + + public MyTimerTask_GKJFlowMenuOpen(float _x, float _y, AbstractFlowMenu f) { + super(_x, _y, f); + fm = (FlowMenu_TMRG) f; + + } + + public void run() { + if (fm.enabled && fm.target != null && fm.drags.size() < 3 && fm.window.flowmenuEventHandler.getEventFilter() == fm.window.b1mask) {// target != null means + // "drugging", + // strokecount < 5 means + // "no squiggle" + preopen(); + openMenu(); + } + } + + public void preopen() { + } + + public void openMenu() { + super.openMenu(); + fm.window.setShowToolTip(false); + } +} \ No newline at end of file diff --git a/anchorgarden/src/main/java/jaist/css/covis/fm/PActionListener.java b/anchorgarden/src/main/java/jaist/css/covis/fm/PActionListener.java new file mode 100644 index 0000000..f3104f2 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/fm/PActionListener.java @@ -0,0 +1,13 @@ +package jaist.css.covis.fm; + +import edu.umd.cs.piccolo.event.PInputEvent; + +/** + * FlowMenuでメニューアイテムが選択されたときに,実行される標準的なアクションのためのインタフェース + * + * @author miuramo + * + */ +public interface PActionListener { + public void actionPerformed(PInputEvent e); +} \ No newline at end of file diff --git a/anchorgarden/src/main/java/jaist/css/covis/fm/ScrollStateAction.java b/anchorgarden/src/main/java/jaist/css/covis/fm/ScrollStateAction.java new file mode 100644 index 0000000..c35c254 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/fm/ScrollStateAction.java @@ -0,0 +1,31 @@ +package jaist.css.covis.fm; + +import java.awt.geom.Point2D; + +import edu.umd.cs.piccolo.event.PInputEvent; +import edu.umd.cs.piccolo.util.PDimension; + +/** + * 画面のパニング + * + * @author miuramo + * + */ +@SuppressWarnings("serial") +public class ScrollStateAction extends StateAction { + public ScrollStateAction(FlowMenu_TMRG f, String n) { + super(f, n); + } + + public void drag(PInputEvent e) { + super.drag(e); + Point2D cp = e.getPosition(); + if (owner.camera.getViewBounds().contains(cp)) { + PDimension d = e.getDelta(); + owner.camera.translateView(d.getWidth(), d.getHeight()); + // owner.camera.setViewOffset(cp.getX()-owner.camerap.getX(),cp.getY()-owner.camerap.getY()); + // System.out.println("dx: "+(cp.getX())+" dy: + // "+(cp.getY()-owner.camerap.getY())); + } + } +} \ No newline at end of file diff --git a/anchorgarden/src/main/java/jaist/css/covis/fm/State.java b/anchorgarden/src/main/java/jaist/css/covis/fm/State.java new file mode 100644 index 0000000..84d70b0 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/fm/State.java @@ -0,0 +1,205 @@ +package jaist.css.covis.fm; + +import java.awt.Color; + +import edu.umd.cs.piccolo.event.PInputEvent; +import edu.umd.cs.piccolo.nodes.PPath; + +/** + * 状態 + * + * @author miuramo + * + */ +@SuppressWarnings("serial") +public class State extends PPath { + protected final double RD = 3.141592 / 180.0; + + protected final int CENTER = 1; + + protected AbstractFlowMenu owner; + + public static int SIZE = 80; + + public State[] nextstates = new State[10]; + + public PPath[] itempath = new PPath[18]; + + int orig_index = 1, old_index = 1, index = 1, distance; + + String name; + + State prevstate; + + boolean isenable = true; + + //色の設定 + static Color no = new Color(0, 0, 0, 120); + + static Color fill = new Color(153, 153, 255, 220); + static Color strColor = new Color(0, 0, 0, 255); + + static Color choose = new Color(255, 0, 0, 180); + + PInputEvent currentevent; + +// Category log; // Log4J + + public State(AbstractFlowMenu f, String n) { + owner = f; + name = n; + isenable = true; +// log = Logger.getLogger(State.class.getName()); + } + + public void setMenuSize(int size) { + SIZE = size; + } + + public void addNextState(State s, int index) { + nextstates[index] = s; + } + + public int getSIZE() { + return SIZE; + } + + public String getName() { + return name; + }; + + public boolean isEnabled() { + return isenable; + } + + public void setEnable(boolean b) { + isenable = b; + } + + public boolean isEnable(int n) { + return nextstates[n].isEnabled(); + } + + public void setPrevState(State s) { + prevstate = s; + } + + public void setOrigIndex(int i) { + orig_index = i; + old_index = i; + } + + public AbstractFlowMenu getOwner() { + return owner; + } + + public void setOwner(FlowMenu_TMRG _owner) { + owner = _owner; + } + + public void paint() { + }; + + public String getString(int i) { + if (nextstates[i] != null) { + return nextstates[i].getName(); + } + return null; + } + + public void drag(PInputEvent e) { + currentevent = e; + // Point2D cp = e.getPositionRelativeTo(owner.camera); + // System.out.println("x: "+cp.getX()+" y: "+cp.getY() +" st "+index); + } + + public void endDrag(PInputEvent e) { + currentevent = e; + // owner.reset(); + // owner.repaint(); + } + + public void updateMenu(int index) { + // int temp = old_index; + if (index != 1 && nextstates[index] != null + && nextstates[index].isEnabled() && itempath[index] != null) + itempath[index].setPaint(choose); + if (index != old_index) { + // state has changed + // System.out.println("state changed from "+old_index+" to "+index + + // " (orig: "+orig_index+")"); + // if (index != 1 && nextstates[index] != null && + // nextstates[index].isEnabled()) itempath[index].setPaint(choose); + if (old_index != 1 && nextstates[old_index] != null + && nextstates[old_index].isEnabled()) + itempath[old_index].setPaint(fill); + if (orig_index == 1) { // 1 to 2-9 + if (nextstates[index] != null && nextstates[index].isEnabled()) { +// log.debug("[" + nextstates[index].getName() +// + "] selected, i: " + index + " oldi: " +// + old_index + " "); + nextstates[index].setPrevState(this); + nextstates[index].setOrigIndex(index); + owner.changeState(nextstates[index]); + } else { + if (prevstate != null) { + // System.out.println("["+getName()+"] deselected, i: + // "+index+" oldi: "+old_index+" "); + prevstate.updateMenu(index); + owner.changeState(prevstate); + } + } + } else { // 2-9 to 1 + if (index == 1) { + if (nextstates[old_index] != null + && nextstates[old_index].isEnabled()) { +// log.debug("[" +// + nextstates[old_index].getName() +// + "] selected, i: " + index + " oldi: " +// + old_index + " "); + nextstates[old_index].setPrevState(this); + nextstates[old_index].setOrigIndex(index); + owner.changeState(nextstates[old_index]); + if (nextstates[old_index] instanceof StateAction) { + StateAction sa = (StateAction) nextstates[old_index]; + sa.action(currentevent); + } + } else { + if (prevstate != null) { + // System.out.println("["+getName()+"] deselected, + // i: "+index+" oldi: "+old_index+" "); + prevstate.updateMenu(index); + owner.changeState(prevstate); + } + } + } + } + old_index = index; + } + } + + public int getPlace(int x, int y) { + int xx, yy, index; + int rr; + int mx = owner.getX(); + int my = owner.getY(); + xx = x - mx; + yy = my - y; + distance = rr = (int) (Math.sqrt(xx * xx + yy * yy)); + if (rr < SIZE / 2.0 + SIZE / 16.0) { // メニューの中心 + index = 1; + } else { // メニューの外側 + double r = Math.atan((double) yy / (double) xx) / RD; + if (xx < 0) { + r += 180.0; + } + if (r < 67.5) { + r += 360.0; + } + index = (int) ((r - 67.5) / 45) + 2; + // itempath[index].setPaint(choose); + } + return index; + } + +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/fm/StateAction.java b/anchorgarden/src/main/java/jaist/css/covis/fm/StateAction.java new file mode 100644 index 0000000..fc12389 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/fm/StateAction.java @@ -0,0 +1,27 @@ +package jaist.css.covis.fm; + +import edu.umd.cs.piccolo.event.PInputEvent; + +/** + * 状態を選択したときのアクション + * + * @author miuramo + * + */ +public @SuppressWarnings("serial") +class StateAction extends State { + PActionListener pal; + + public StateAction(AbstractFlowMenu f, String n) { + super(f, n); + } + + public void addPActionListener(PActionListener p) { + pal = p; + } + + public void action(PInputEvent e) { + if (pal != null) + pal.actionPerformed(e); + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/fm/WalkScrollStateAction.java b/anchorgarden/src/main/java/jaist/css/covis/fm/WalkScrollStateAction.java new file mode 100644 index 0000000..e090dbf --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/fm/WalkScrollStateAction.java @@ -0,0 +1,67 @@ +package jaist.css.covis.fm; + +import java.awt.Color; +import java.awt.geom.Point2D; +import java.util.TimerTask; + +import edu.umd.cs.piccolo.event.PInputEvent; +import edu.umd.cs.piccolo.nodes.PPath; + +/** + * ウォーク・スクロールのときのアクション + * + * @author miuramo + * + */ + +public @SuppressWarnings("serial") +class WalkScrollStateAction extends StateAction { + PPath arrow; + + double sumx, sumy; + + Point2D cp; + + java.util.Timer walktask = null; + +// Category log; // Log4J + + public WalkScrollStateAction(FlowMenu_TMRG f, String n) { + super(f, n); +// log = Logger.getLogger(WalkScrollStateAction.class.getName()); + } + + class WalkTimerTask extends TimerTask { + public void run() { +// log.debug("dx: " + sumx + " dy: " + sumy); +// owner.camera.translateView(-sumx, -sumy); + } + } + + public void drag(PInputEvent e) { + super.drag(e); + cp = e.getPositionRelativeTo(owner.camera); + sumx = cp.getX() - owner.camerap.getX(); + sumy = cp.getY() - owner.camerap.getY(); + if (walktask == null) { + walktask = new java.util.Timer(); + walktask.schedule(new WalkTimerTask(), 100, 100); + } + } + + public void endDrag(PInputEvent e) { + walktask.cancel(); + walktask = null; + super.endDrag(e); + removeAllChildren(); + } + + public void paint() { + Point2D cmp = owner.camerap; + arrow = PPath.createEllipse((float) cmp.getX(), (float) cmp.getY(), + 10f, 10f); + arrow.setPaint(Color.blue); + arrow.setStrokePaint(null); + addChild(arrow); + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/fm/ZoomRegionStateAction.java b/anchorgarden/src/main/java/jaist/css/covis/fm/ZoomRegionStateAction.java new file mode 100644 index 0000000..80172b9 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/fm/ZoomRegionStateAction.java @@ -0,0 +1,87 @@ +package jaist.css.covis.fm; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Stroke; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; + +import edu.umd.cs.piccolo.event.PInputEvent; +import edu.umd.cs.piccolo.nodes.PPath; +import edu.umd.cs.piccolo.util.PAffineTransform; + +/** + * 範囲指定ズームのためのアクション + * + * @author miuramo + * + */ +@SuppressWarnings("serial") +public class ZoomRegionStateAction extends StateAction { + PPath selection; + + Point2D cp; + + private Stroke[] strokes = null; + + private float strokeNum = 0; + + final static int NUM_STROKES = 10; + + final static int DASH_WIDTH = 15; + + FlowMenu_TMRG ownersv; + + public ZoomRegionStateAction(FlowMenu_TMRG f, String n) { + super(f, n); + float[] dash = { DASH_WIDTH, DASH_WIDTH }; + strokes = new Stroke[NUM_STROKES]; + for (int i = 0; i < NUM_STROKES; i++) { + strokes[i] = new BasicStroke(3, BasicStroke.CAP_BUTT, + BasicStroke.JOIN_MITER, 1, dash, i); + } + ownersv = (FlowMenu_TMRG) f; + } + + public void drag(PInputEvent e) { + super.drag(e); + Point2D cmp = owner.camerap; + cp = e.getPositionRelativeTo(owner.camera); + selection.setPathToRectangle((float) cmp.getX(), (float) cmp.getY(), + (float) (cp.getX() - cmp.getX()), (float) (cp.getY() - cmp + .getY())); + + float origStrokeNum = strokeNum; + strokeNum = (strokeNum + 0.5f) % NUM_STROKES; // Increment by partial + // steps to slow down + // animation + if ((int) strokeNum != (int) origStrokeNum) { + selection.setStroke(strokes[(int) strokeNum]); + } + } + + public void endDrag(PInputEvent e) { + Point2D cmp = owner.camerap; + cp = e.getPositionRelativeTo(owner.camera); + removeAllChildren(); + if (cmp.getX() < cp.getX() && cmp.getY() < cp.getY()) { + // カメラ座標から,グローバル(パネル)座標への変換 + PAffineTransform at = owner.camera.getViewTransform(); + Rectangle2D globalb = selection.getGlobalBounds(); + Rectangle2D layerb = new Rectangle2D.Double(); + at.inverseTransform(globalb, layerb); + owner.camera.animateViewToCenterBounds(layerb, true, 1000); + } + } + + public void paint() { + Point2D cmp = owner.camerap; + selection = new PPath(); + selection.setPathToRectangle((float) cmp.getX(), (float) cmp.getY(), 0, + 0); + selection.setStrokePaint(Color.blue); + selection.setPaint(null); + selection.setStroke(strokes[0]); + addChild(selection); + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/fm/package-info.java b/anchorgarden/src/main/java/jaist/css/covis/fm/package-info.java new file mode 100644 index 0000000..7ec14da --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/fm/package-info.java @@ -0,0 +1,6 @@ +/** + * フローメニュー(円形・階層ポップアップメニュー)用のクラスです. + * + */ + +package jaist.css.covis.fm; \ No newline at end of file diff --git a/anchorgarden/src/main/java/jaist/css/covis/hist/CVHist_Link.java b/anchorgarden/src/main/java/jaist/css/covis/hist/CVHist_Link.java new file mode 100644 index 0000000..3e244dc --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/hist/CVHist_Link.java @@ -0,0 +1,122 @@ +package jaist.css.covis.hist; + +import jaist.css.covis.CoVisBuffer; +import jaist.css.covis.cls.Anchor; +import jaist.css.covis.cls.Covis_Object; +import jaist.css.covis.cls.Variable; + +import java.util.ArrayList; + +public class CVHist_Link extends CVHistory { + Anchor anchor; + Covis_Object obj; + public CVHist_Link(Anchor a, Covis_Object o, CoVisBuffer buf){ + super(buf); + anchor = a; // = の左側 + obj = o; // = の右側 + + ArrayList srcReferredNames = new ArrayList(); + for(String s: a.srcVariable.getVarNamesAry()){ + srcReferredNames.add(s); + } + //ひきざん + ArrayList destReferredNames = new ArrayList(); + for(String s: a.destObject.referenceVarNames().split("\n")){ + if (!srcReferredNames.contains(s)) destReferredNames.add(s); + } + + code = Variable.getShortestName(srcReferredNames) +" = "+ + Variable.getShortestName(destReferredNames) +";"; + setCode(code,true); + +/* + TreeMap objRefMap = obj.referenceAnchors(); + ArrayList rightCandidates = new ArrayList(); + ArrayList rightCandidatesNeedCast = new ArrayList(); + for(Anchor ank: objRefMap.values()){ + String[] varNames = ank.getVarName().split("\n"); + for(String vN: varNames){ +// System.out.println(vN); + if (vN.equals(a.getVarName())){ + continue; + } + //右側について,なるべく,オブジェクトをきちんと表現する型での既存参照を探す + if (a.type == buf.varField.findVar(vN).elementType){ + rightCandidates.add(vN); + } else { + rightCandidatesNeedCast.add(vN); + } + } + } + ArrayList leftCandidates = new ArrayList(); + ArrayList leftCandidatesNeedCast = new ArrayList(); + String[] varNames = a.getVarName().split("\n"); + for(String vN: varNames){ + if (buffer.varField.findVar(vN)==null) continue;//TODO:原因究明 + if (buffer.varField.findVar(vN).elementType == obj.type){ + leftCandidates.add(vN); + } else { + leftCandidatesNeedCast.add(vN); + } + } + System.out.println("左の候補"); + for(String s: leftCandidates) System.out.println(s); + System.out.println("左の候補(キャスト)"); + for(String s: leftCandidatesNeedCast) System.out.println(s); + System.out.println("右の候補"); + for(String s: rightCandidates) System.out.println(s); + System.out.println("右の候補(キャスト)"); + for(String s: rightCandidatesNeedCast) System.out.println(s); + + //右側を選ばせるならここで. + // キャストなし + String left; + if (leftCandidates.size()>0) left = leftCandidates.get(0); + else if (leftCandidatesNeedCast.size()>0) left = leftCandidatesNeedCast.get(0); + else left = "NOLEFT"; + + String right = null; + if (rightCandidates.size()>0) { + for(String r: rightCandidates){ + if (r.equals(left)) continue; + right = r; + } + } + else if (rightCandidatesNeedCast.size()>0){ + for(String r: rightCandidatesNeedCast){ + if (r.equals(left)) continue; + right = r; + } + } + else right = null; + + System.out.println("left "+left+" "+right); + if (right == null){ + setAlive(false); + return; + } + Class leftVarType; + Class rightVarType; + if (obj instanceof Covis_Array){ + leftVarType = buffer.varField.findVar(left).type; + rightVarType = buffer.varField.findVar(right).type; + } else { + if (buffer.varField.findVar(left)==null) return;//TODO:ループ時にNULL:要原因究明 + if (buffer.varField.findVar(right)==null) return; + leftVarType = buffer.varField.findVar(left).elementType; + rightVarType = buffer.varField.findVar(right).elementType; + } + if (leftVarType == rightVarType){ + code = left +" = "+right+";"; + setCode(code,true); + } else { + code = left +" = ("+Covis_Object.getClsNameStatic(leftVarType)+") "+right+";"; + setCode(code,true); + } + } + //キャストが必要な場合もある. + // 自分で選ばせる? + * + */ + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/hist/CVHist_Method.java b/anchorgarden/src/main/java/jaist/css/covis/hist/CVHist_Method.java new file mode 100644 index 0000000..23a8ad5 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/hist/CVHist_Method.java @@ -0,0 +1,15 @@ +package jaist.css.covis.hist; + +import jaist.css.covis.CoVisBuffer; + +public class CVHist_Method extends CVHistory { + boolean isShow; + Object retobj; + public CVHist_Method(Object v, CoVisBuffer buf, String code, boolean iS){ + super(buf); + retobj = v; + isShow = iS; + setCode(code, iS); +// System.out.println("setCode: "+var.getConstructorInfo()); + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/hist/CVHist_MethodNew.java b/anchorgarden/src/main/java/jaist/css/covis/hist/CVHist_MethodNew.java new file mode 100644 index 0000000..136e14b --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/hist/CVHist_MethodNew.java @@ -0,0 +1,19 @@ +package jaist.css.covis.hist; + +import jaist.css.covis.CoVisBuffer; +import jaist.css.covis.cls.Covis_Object; +import edu.umd.cs.piccolo.PNode; + +public class CVHist_MethodNew extends CVHist_New { +// Covis_Object obj; + + public CVHist_MethodNew(Covis_Object o, CoVisBuffer buf, String src){ + super(o,buf,true); + obj = o; + setCode(src,true); + } + public boolean isAlive(){ + if (((PNode)obj).getTransparency() < 0.2) return false; + else return true; + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/hist/CVHist_New.java b/anchorgarden/src/main/java/jaist/css/covis/hist/CVHist_New.java new file mode 100644 index 0000000..8863921 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/hist/CVHist_New.java @@ -0,0 +1,30 @@ +package jaist.css.covis.hist; + +import jaist.css.covis.CoVisBuffer; +import jaist.css.covis.cls.Covis_Object; +import edu.umd.cs.piccolo.PNode; + +public class CVHist_New extends CVHistory { + Covis_Object obj; + boolean isShow; + boolean consumed = false; + + public CVHist_New(Covis_Object o, CoVisBuffer buf, boolean iS){ + super(buf); + obj = o; isShow = iS; + setCode(obj.getConstructorInfo(),iS); + } + public boolean isAlive(){ + if (((PNode)obj).getTransparency() < 0.2 && code.startsWith("new")) return false; + else return true; + } + public boolean isConsumed(){ + return consumed; + } + public void setConsumed(boolean b){ + consumed = b; + } + public Covis_Object getObject(){ + return obj; + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/hist/CVHist_Unlink.java b/anchorgarden/src/main/java/jaist/css/covis/hist/CVHist_Unlink.java new file mode 100644 index 0000000..54898a4 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/hist/CVHist_Unlink.java @@ -0,0 +1,19 @@ +package jaist.css.covis.hist; + +import jaist.css.covis.CoVisBuffer; +import jaist.css.covis.cls.Anchor; +import jaist.css.covis.cls.Variable; + +public class CVHist_Unlink extends CVHistory { + Anchor anchor; +// Covis_Object obj; + public CVHist_Unlink(Anchor a, CoVisBuffer buf){ + super(buf); + anchor = a; +// obj = o; +// String[] refs = anchor.srcVariable.getVarName().split("\n"); +// setCode(refs[refs.length-1] +" = null;",true); + setCode(Variable.getShortestName(anchor.srcVariable.getVarNamesAry()) +" = null;",true); + //普通に0でもよいが,最後に追加したものをなるべく使ったほうがよいかと思って. + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/hist/CVHist_Value.java b/anchorgarden/src/main/java/jaist/css/covis/hist/CVHist_Value.java new file mode 100644 index 0000000..0041e67 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/hist/CVHist_Value.java @@ -0,0 +1,13 @@ +package jaist.css.covis.hist; + +import jaist.css.covis.CoVisBuffer; +import jaist.css.covis.cls.Variable; + +public class CVHist_Value extends CVHistory { + Variable var; + public CVHist_Value(Variable v, CoVisBuffer buf){ + super(buf); + var = v; + setCode(var.getEditValueInfo(),true); + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/hist/CVHist_ValueArray.java b/anchorgarden/src/main/java/jaist/css/covis/hist/CVHist_ValueArray.java new file mode 100644 index 0000000..3422234 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/hist/CVHist_ValueArray.java @@ -0,0 +1,16 @@ +package jaist.css.covis.hist; + +import jaist.css.covis.CoVisBuffer; +import jaist.css.covis.cls.Covis_Array; +import jaist.css.covis.cls.Covis_primitive; + +public class CVHist_ValueArray extends CVHistory { + Covis_primitive v; + Covis_Array a; + public CVHist_ValueArray(Covis_primitive _v, Covis_Array _a, CoVisBuffer buf){ + super(buf); + v = _v; + a = _a; + setCode(a.getEditValueInfo(v),true); + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/hist/CVHist_Var.java b/anchorgarden/src/main/java/jaist/css/covis/hist/CVHist_Var.java new file mode 100644 index 0000000..84f9bbf --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/hist/CVHist_Var.java @@ -0,0 +1,16 @@ +package jaist.css.covis.hist; + +import jaist.css.covis.CoVisBuffer; +import jaist.css.covis.cls.Variable; + +public class CVHist_Var extends CVHistory { + Variable var; + boolean isShow; + public CVHist_Var(Variable v, CoVisBuffer buf, boolean iS){ + super(buf); + var = v; + isShow = iS; + setCode(var.getConstructorInfo(), iS); +// System.out.println("setCode: "+var.getConstructorInfo()); + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/hist/CVHistory.java b/anchorgarden/src/main/java/jaist/css/covis/hist/CVHistory.java new file mode 100644 index 0000000..47651d0 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/hist/CVHistory.java @@ -0,0 +1,71 @@ +package jaist.css.covis.hist; + +import jaist.css.covis.CoVisBuffer; + +import java.awt.Color; + +public class CVHistory { + public long tstamp; + String type; + String code; + CoVisBuffer buffer; + boolean isAlive = true; + + public CVHistory(CoVisBuffer b){ + tstamp = System.currentTimeMillis(); + buffer = b; + } + public String getCode(){ + return code; + } +// public void setCode(String s){ +// setCode(s, true); +// } + public void setCode(String s, boolean isShow){ + code = s; + if (!isShow) return; + //操作の種類を判定 + String operation_type = ""; + Color bgcolor = null; + String classname = this.getClass().getName(); + if (classname.endsWith("New")){ + if (code.indexOf("=")>1){ + operation_type = "Link to New Object"; + bgcolor = CoVisBuffer.linkcolor; + } else { + operation_type = "New Object"; + bgcolor = CoVisBuffer.typefcolor; + } + } else if (classname.endsWith("Link")){ + operation_type = "Link"; + bgcolor = CoVisBuffer.linkcolor; + } else if (classname.endsWith("Unlink")){ + operation_type = "Unlink"; + bgcolor = CoVisBuffer.ulinkcolor; + } else if (classname.endsWith("ValueArray")){ + operation_type = "Assign Value"; + bgcolor = CoVisBuffer.varcolor; + } else if (classname.endsWith("Value")){ + operation_type = "Assign Value"; + bgcolor = CoVisBuffer.varcolor; + } else if (classname.endsWith("Var")){ + operation_type = "Declare Variable"; + bgcolor = CoVisBuffer.varfcolor; + } else if (classname.endsWith("Method")){ + operation_type = "Method Call"; + bgcolor = CoVisBuffer.methodcolor; + } + + if (buffer.getWindow()!=null) + buffer.getWindow().showFadingMessage(s+" ("+operation_type+")", bgcolor, Color.black, 1.7f, 0.9f); +// System.out.println(this.getClass().getName()); +// System.out.println("new code: "+s); + } + public void setAlive(boolean b) { + isAlive = b; + } + public boolean isAlive(){ + return isAlive; + } + +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/mi/InputField.java b/anchorgarden/src/main/java/jaist/css/covis/mi/InputField.java new file mode 100644 index 0000000..57924eb --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/mi/InputField.java @@ -0,0 +1,10 @@ +package jaist.css.covis.mi; + + +public interface InputField { + public String getType(); + public String getSelectedItemString(); + public Object getSelectedItemObject(); + public void setType(String s); + +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/mi/InputField_Reference.java b/anchorgarden/src/main/java/jaist/css/covis/mi/InputField_Reference.java new file mode 100644 index 0000000..6ecc069 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/mi/InputField_Reference.java @@ -0,0 +1,50 @@ +package jaist.css.covis.mi; + +import jaist.css.covis.SrcWindow; + +import java.util.HashMap; + +import javax.swing.DefaultComboBoxModel; +import javax.swing.JComboBox; + +public class InputField_Reference extends JComboBox implements InputField { + + /** + * + */ + private static final long serialVersionUID = -5269150644561511322L; + HashMap hashsrc; + + public InputField_Reference(HashMap hash){ + super(); +// String[] ary = new String[hash.size()]; + DefaultComboBoxModel dcbm = new DefaultComboBoxModel(); + for(Object o: hash.keySet().toArray()){ + String s = (String)o; + dcbm.addElement(s); + } + setModel(dcbm); + hashsrc = hash; + setFont(SrcWindow.sans22); + setAlignmentX(3.0f); + } + String type; + @Override + public Object getSelectedItemObject() { + return hashsrc.get(getSelectedItem()); + } + public String getSelectedItemString() { + return getSelectedItem().toString(); + } + + @Override + public String getType() { + return type; + } + + @Override + public void setType(String s) { + type = s; + } + +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/mi/InputField_String.java b/anchorgarden/src/main/java/jaist/css/covis/mi/InputField_String.java new file mode 100644 index 0000000..4042739 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/mi/InputField_String.java @@ -0,0 +1,43 @@ +package jaist.css.covis.mi; + +import jaist.css.covis.SrcWindow; +import jaist.css.covis.cls.Covis_String; + +import javax.swing.JTextField; + +public class InputField_String extends JTextField implements InputField { + + /** + * + */ + private static final long serialVersionUID = -2251681272731799372L; + + public InputField_String(String orig){ + super(orig, 5); + setBackground(Covis_String.defaultColor); + setFont(SrcWindow.sans22); + setAlignmentX(3.0f); + setToolTipText("String"); + + } + String type; + @Override + public Object getSelectedItemObject() { + return new String(this.getText()); + } + + public String getSelectedItemString() { + return new String("\""+this.getText()+"\""); + } + + @Override + public String getType() { + return type; + } + + @Override + public void setType(String s) { + type = s; + } + +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/mi/InputField_int.java b/anchorgarden/src/main/java/jaist/css/covis/mi/InputField_int.java new file mode 100644 index 0000000..9b4aedc --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/mi/InputField_int.java @@ -0,0 +1,45 @@ +package jaist.css.covis.mi; + +import jaist.css.covis.SrcWindow; +import jaist.css.covis.cls.Covis_int; + +import javax.swing.JTextField; + +public class InputField_int extends JTextField implements InputField { + + /** + * + */ + private static final long serialVersionUID = -2251681272731799372L; + + public InputField_int(int n){ + super(String.valueOf(n),5); + setBackground(Covis_int.defaultColor); + setFont(SrcWindow.sans22); + setAlignmentX(3.0f); + setToolTipText("int"); + + } + String type; + @Override + public Object getSelectedItemObject() { + return Integer.getInteger(this.getText()); + // return new Integer(Integer.parseInt()); + } + + public String getSelectedItemString() { + int val = Integer.parseInt(this.getText()); + return String.valueOf(val); + } + + @Override + public String getType() { + return type; + } + + @Override + public void setType(String s) { + type = s; + } + +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/mi/MethodInvocationDialog.java b/anchorgarden/src/main/java/jaist/css/covis/mi/MethodInvocationDialog.java new file mode 100644 index 0000000..8a1aa8b --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/mi/MethodInvocationDialog.java @@ -0,0 +1,190 @@ +package jaist.css.covis.mi; + +import jaist.css.covis.JLabelW; +import jaist.css.covis.JLabelWL; +import jaist.css.covis.cls.Covis_Object; +import jaist.css.covis.cls.Covis_String; +import jaist.css.covis.cls.Variable; + +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.lang.reflect.InvocationTargetException; + +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JTextField; + +import edu.umd.cs.piccolo.activities.PActivity; + +public class MethodInvocationDialog extends JDialog implements KeyListener { + private static final long serialVersionUID = 1852035735398130391L; + + JFrame parent; + JTextField jtfa, jtfb; + JButton ok; + + WrapMethod wm; + Variable var; + + public MethodInvocationDialog(JFrame p, String title, WrapMethod _wm, String mes1, Variable v) { + super(p, title, true); + parent = p; + wm = _wm; + var = v; + + // final JComboBox[] jcb = new JComboBox[wm.paramClses.length]; + final InputField[] jcb = new InputField[wm.paramClses.length]; + for(int i=0;i "+coob.toString()); + } else { + wm.obj.buffer.putHistoryMethodNew("new", coob, methodcall); + }/* + } else { + if (coob instanceof Covis_BTree){ + wm.obj.buffer.putHistoryMethodNew("new", coob, methodcall); + } else { + wm.obj.buffer.putHistoryMethod("method", coob, methodcall+"//> "+coob.toString(),true); + } + }*/ + highlightReturnObject(coob); + } else { + if (retValObject != null){ + wm.obj.buffer.putHistoryMethod("method", retValObject, methodcall+"//> "+retValObject.toString(), true); + } else { + // System.out.println(wm.method.getReturnType().toString()); + if (wm.method.getReturnType().toString().equals("void"))//元々voidだから期待してない + wm.obj.buffer.putHistoryMethod("method", retValObject, methodcall, true); + else + wm.obj.buffer.putHistoryMethod("method", retValObject, methodcall+"//> null", true); + } + } + } + + private void highlightReturnObject(Covis_Object coob) { + // PActivity z1 = coob.animateToZoom(2.0f,300); + coob.setScale(2.0f); + PActivity z2 = coob.animateToZoom(1.0f,300); + PActivity p1 = coob.animateToTransparency(0f, 300); + PActivity p2 = coob.animateToTransparency(1f, 300); + PActivity p11 = coob.animateToTransparency(0f, 300); + PActivity p12 = coob.animateToTransparency(1f, 300); + PActivity p21 = coob.animateToTransparency(0f, 300); + PActivity p22 = coob.animateToTransparency(1f, 300); + PActivity p31 = coob.animateToTransparency(0f, 300); + PActivity p32 = coob.animateToTransparency(1f, 300); + p1.setStartTime(System.currentTimeMillis()); + p2.startAfter(p1); + p11.startAfter(p2); + p12.startAfter(p11); + p21.startAfter(p12); + p22.startAfter(p21); + p31.startAfter(p22); + p32.startAfter(p31); + z2.startAfter(p32); + } + @Override + public void keyPressed(KeyEvent arg0) { + if (arg0.getKeyCode() == KeyEvent.VK_ENTER){ + ok.doClick(); + } + } + @Override + public void keyReleased(KeyEvent arg0) { } + @Override + public void keyTyped(KeyEvent arg0) { } + + public static void showDialog(JFrame parent, String title, WrapMethod _wm, String mes1, Variable v) { + MethodInvocationDialog d = new MethodInvocationDialog(parent, + title, _wm, mes1, v); + d.setVisible(true); + if (d.jtfa != null && d.jtfb != null){ + // frac.a.setValue(d.jtfa.getText()); + // frac.b.setValue(d.jtfb.getText()); + } else + return; + } +} \ No newline at end of file diff --git a/anchorgarden/src/main/java/jaist/css/covis/mi/WrapMethod.java b/anchorgarden/src/main/java/jaist/css/covis/mi/WrapMethod.java new file mode 100644 index 0000000..b041350 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/mi/WrapMethod.java @@ -0,0 +1,72 @@ +package jaist.css.covis.mi; + +import jaist.css.covis.cls.Anchor; +import jaist.css.covis.cls.Covis_Object; +import jaist.css.covis.cls.Variable; + +import java.awt.event.ActionEvent; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.TreeMap; +import java.util.Map.Entry; + +import javax.swing.AbstractAction; + +import edu.umd.cs.piccolo.PNode; + +public class WrapMethod extends AbstractAction { + private static final long serialVersionUID = -3933799327221553449L; + Method method; + Covis_Object obj; + Variable variable; + public WrapMethod(Method m, Covis_Object o, String mname, Variable var){ + super(mname); + obj = o; method = m; variable = var; + } + Class[] paramClses; + HashMap,HashMap> candidates; + @Override + public void actionPerformed(ActionEvent arg0) { + System.out.println(method.toString()); + paramClses = method.getParameterTypes(); + if (paramClses.length==0){ //引数なければ,そのまま実行! + Object[] arg = null; + MethodInvocationDialog mid = new MethodInvocationDialog(obj.buffer.getWindow().frame, "invoke method", this, "select arguments", variable); + //メソッドコールを文字列に + StringBuffer sb = new StringBuffer(); + sb.append(Variable.getShortestName(variable.getVarNamesAry())+"."+method.getName().replace("covis_", "")+"();"); + + mid.invokeMethod(arg, sb.toString()); + return; + } + candidates = new HashMap, HashMap>(); + for(Class c: paramClses){ + if (candidates.containsKey(c)) continue; + +// System.out.println(c.toString()+"を探索"); + //格納容器 + HashMap temp = new HashMap(); + for(PNode pn: obj.buffer.objField.getAllNodes()){ + if (c.isInstance(pn)){ + Covis_Object o = (Covis_Object)pn; + + TreeMap map = o.referenceAnchors(); + for(Entry set: map.entrySet()){ + String s = set.getKey(); + Anchor a = set.getValue(); + // System.out.println("a "+a.getVarClass()); + // System.out.println("c "+c.getName()); + if (c.isAssignableFrom(a.getVarClass())){ + temp.put(Variable.getShortestName(a.srcVariable.getVarNamesAry()), a.destObject); + System.out.println(s); + } + } + } + } + candidates.put(c,temp); + } + //オブジェクトの候補(参照のための変数)はあつまった. + MethodInvocationDialog.showDialog(obj.buffer.getWindow().frame, "invoke method", this, "select arguments", variable); + } +} + diff --git a/anchorgarden/src/main/java/jaist/css/covis/package-info.java b/anchorgarden/src/main/java/jaist/css/covis/package-info.java new file mode 100644 index 0000000..38c710e --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/package-info.java @@ -0,0 +1,9 @@ +/** + * AirTransNoteの中核を構成するパッケージです. + * + * AirTransNoteを起動する外観(ビュー)クラスATNWindowや, + * 表示モデル管理クラスATNBuffer を含みます. + * + */ + +package jaist.css.covis; \ No newline at end of file diff --git a/anchorgarden/src/main/java/jaist/css/covis/play/SrcExecutor.java b/anchorgarden/src/main/java/jaist/css/covis/play/SrcExecutor.java new file mode 100644 index 0000000..869d29e --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/play/SrcExecutor.java @@ -0,0 +1,23 @@ +package jaist.css.covis.play; + +import java.util.ArrayList; + +import jaist.css.covis.CoVisBuffer; + +public class SrcExecutor { + CoVisBuffer buf; + public SrcExecutor(CoVisBuffer b){ + buf = b; + } + + public ArrayList execute(String src){ + ArrayList errors = new ArrayList(); + System.out.println("ORIG:"+ src); + String[] tokens = src.split("\""); + for(String t: tokens){ + System.out.println(t); + } + + return errors; + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/pui/CameraFitConstraint.java b/anchorgarden/src/main/java/jaist/css/covis/pui/CameraFitConstraint.java new file mode 100644 index 0000000..ec78ff8 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/pui/CameraFitConstraint.java @@ -0,0 +1,92 @@ +package jaist.css.covis.pui; + +import java.awt.Dimension; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +import edu.umd.cs.piccolo.PCamera; +import edu.umd.cs.piccolo.util.PBounds; + +/** + * 表示領域(キャンバス)のサイズ変更に合わせて,ぴったりレイアウトするためのPropertyChangeListener + * + * おもにPMenu (Piccolo Menu:勝手に作成した簡易ボタン)の位置を調整するために使用 + * + * @author miuramo + * + */ +public class CameraFitConstraint implements PropertyChangeListener { + public static enum PositionEnum { + TOPLEFT, TOPRIGHT, TOPFILL, TOPCENTER, BOTTOMLEFT, BOTTOMRIGHT, BOTTOMFILL; // Cascading Style Sheet のマージン定義における並びと同じ + } + + CameraFittable target; + + PCamera camera; + + PositionEnum constraint; + + Dimension defaultGap; + + public CameraFitConstraint(CameraFittable t, PCamera cam, PositionEnum con, + Dimension _defaultGap) { + target = t; + camera = cam; + constraint = con; +// defaultOffset = _defaultOffset; + defaultGap = _defaultGap; + } + + public void propertyChange(PropertyChangeEvent evt) { + if (evt.getSource() == camera) { + if (evt.getPropertyName().equals("bounds")) { + fitTo(camera.getBoundsReference()); + } + } + } + public void fitTo(PBounds b){ + if (constraint == PositionEnum.TOPRIGHT) + fitToTopRight(camera.getBoundsReference()); + else if (constraint == PositionEnum.TOPLEFT) + fitToTopLeft(camera.getBoundsReference()); + else if (constraint == PositionEnum.TOPCENTER) + fitToTopCenter(camera.getBoundsReference()); + + } + + public void fitToTopRight(PBounds b) { + // Boundsが変化したら!!! + // resize((float)b.width); + target.setOffset(b.width - target.getFullBounds().width, 0); + + // preBounds = b; + } + public void fitToTopLeft(PBounds b) { + // Boundsが変化したら!!! + // resize((float)b.width); + target.setOffset(0, 0); + // preBounds = b; + } + public void fitToTopCenter(PBounds b) { + // Boundsが変化したら!!! + // resize((float)b.width); + target.setOffset(b.getWidth()/2 - target.getFullBounds().width/2, 0); + // preBounds = b; + } + + + public void fitToBottomFill(PBounds b) { + // Boundsが変化したら!!! + resize((float) b.width); + target.setOffset(defaultGap.getWidth(), b.height + - target.getFullBounds().height - 2); + + // preBounds = b; + } + + public void resize(float width) { + target.setPathToRectangle((float) 0, (float) 0, + (float) (width - (defaultGap.getWidth() * 2)), + (float) defaultGap.getHeight()); + } +} \ No newline at end of file diff --git a/anchorgarden/src/main/java/jaist/css/covis/pui/CameraFittable.java b/anchorgarden/src/main/java/jaist/css/covis/pui/CameraFittable.java new file mode 100644 index 0000000..2c35526 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/pui/CameraFittable.java @@ -0,0 +1,18 @@ +package jaist.css.covis.pui; + +import edu.umd.cs.piccolo.util.PBounds; + +/** + * 画面表示領域にぴったり揃えて配置されるオブジェクトが実装すべきインタフェース. + * + * pui.PMenuRoot が実装している. + * @author miuramo + * + */ +public interface CameraFittable { + public void setOffset(double x, double y); + + public void setPathToRectangle(float x, float y, float w, float h); + + public PBounds getFullBounds(); +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/pui/FadeTimer.java b/anchorgarden/src/main/java/jaist/css/covis/pui/FadeTimer.java new file mode 100644 index 0000000..f64038e --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/pui/FadeTimer.java @@ -0,0 +1,65 @@ +package jaist.css.covis.pui; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Queue; + +import javax.swing.Timer; + +import edu.umd.cs.piccolo.PNode; + +public class FadeTimer implements ActionListener, Runnable{ + int keepMsec; + int fadeMsec; + public PNode pn; + Thread thread; + Timer timer = null; + public Queue fadeTimers; + //親がFadeTimerのリストを管理しており、消したらリストから自分自身を削除する場合 + public void setFadeTimers(Queue ft){ + fadeTimers = ft; + } + public FadeTimer(PNode p, int kM, int fM) { + keepMsec = kM; + pn = p; + fadeMsec = fM; + thread = new Thread(this); + thread.start(); + } + public void run() { + try { + Thread.sleep(keepMsec); + } catch (InterruptedException e) { + e.printStackTrace(); + } + timer = new Timer(fadeMsec, this); + timer.setRepeats(false); + pn.animateToTransparency(0f, fadeMsec); + timer.start(); + } + public void fadeNow(){ + if (timer == null){ + timer = new Timer(fadeMsec, this); + timer.setRepeats(false); + pn.animateToTransparency(0f, fadeMsec); + timer.start(); + } + } + public void invisibleNow(){ + if (timer == null){ + timer = new Timer(fadeMsec, this); + timer.setRepeats(false); + pn.setTransparency(0f); + timer.start(); + } + } + + public void actionPerformed(ActionEvent e) { + pn.removeFromParent(); + if (fadeTimers != null){ + fadeTimers.remove(this); + } + } + + +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/pui/PMenuBar.java b/anchorgarden/src/main/java/jaist/css/covis/pui/PMenuBar.java new file mode 100644 index 0000000..078a5ea --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/pui/PMenuBar.java @@ -0,0 +1,96 @@ +package jaist.css.covis.pui; + +import jaist.css.covis.AnchorGarden; + +import java.awt.Dimension; +import java.util.ArrayList; + +import edu.umd.cs.piccolo.PCamera; +import edu.umd.cs.piccolo.event.PBasicInputEventHandler; +import edu.umd.cs.piccolo.event.PInputEvent; +import edu.umd.cs.piccolo.nodes.PPath; +import edu.umd.cs.piccolo.util.PBounds; + +public class PMenuBar extends PBasicInputEventHandler implements CameraFittable, Runnable { + // private static final long serialVersionUID = 1776018940471391776L; + + public PPath mybar; + PCamera camera; + AnchorGarden window; +// float transparency = 0.8f; + float base_transparency = 0.9f; + Thread transparencyThread = null; + boolean quitTransparencyThread = true; + ArrayList cfcList; + public PMenuBar(PCamera _cam, AnchorGarden _win){ + camera = _cam; + window = _win; + mybar = new PPath(); + mybar.setTransparency(base_transparency); + camera.addChild(mybar); + camera.addInputEventListener(this); + cfcList = new ArrayList(); + } + public void addPMenuRoot(PMenuRoot root, CameraFitConstraint.PositionEnum pos, Dimension _defaultGap){ + mybar.addChild(root); +// Point2D initP = new Point2D.Double(window.buffer.gkjProperty.viewsizey - root.getFullBoundsReference().getWidth(),0); +// if (pos == CameraFitConstraint.PositionEnum.TOPLEFT) initP.setLocation(0,0); +// root.setOffset(initP); + CameraFitConstraint cfc = new CameraFitConstraint(root, camera, pos, _defaultGap); + cfc.fitTo(camera.getBoundsReference()); + camera.addPropertyChangeListener(cfc); + } + public PBounds getFullBounds() { + return mybar.getFullBounds(); + } + public void setOffset(double x, double y) { + mybar.setOffset(x,y); + } + public void setPathToRectangle(float x, float y, float w, float h) { + mybar.setPathToRectangle(x,y,w,h); + } + + public void mouseMoved(PInputEvent event) { + double y = event.getPositionRelativeTo(camera).getY(); + if (y < getFullBounds().getHeight()*2){ + if (transparencyThread != null) quitTransparencyThread = true; + mybar.setTransparency(base_transparency); + mybar.repaint(); + } else { + if (mybar.getTransparency() == base_transparency) transparencyThread_Start(); + } + } + void transparencyThread_Start(){ + if (transparencyThread == null){ + quitTransparencyThread = false; + transparencyThread = new Thread(this); + transparencyThread.start(); + } + } + public void run() { + for(float f = base_transparency; f>=0.0f; f-=0.05){ + mybar.setTransparency(f); + mybar.repaint(); + try { + Thread.sleep(50); + } catch (InterruptedException e) { + e.printStackTrace(); + } + if (quitTransparencyThread) { + mybar.setTransparency(base_transparency); + mybar.repaint(); + transparencyThread = null; + break; + } + } + mybar.setTransparency(0.0f); + mybar.repaint(); + transparencyThread = null; + } + public void manualFit(PBounds pb) { + for(CameraFitConstraint cfc: cfcList){ + cfc.fitTo(pb); + } + } + +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/pui/PMenuItem_Abstract.java b/anchorgarden/src/main/java/jaist/css/covis/pui/PMenuItem_Abstract.java new file mode 100644 index 0000000..86fbea0 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/pui/PMenuItem_Abstract.java @@ -0,0 +1,130 @@ +package jaist.css.covis.pui; + +import jaist.css.covis.fm.PActionListener; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; + +import edu.umd.cs.piccolo.event.PBasicInputEventHandler; +import edu.umd.cs.piccolo.event.PInputEvent; +import edu.umd.cs.piccolo.nodes.PPath; +import edu.umd.cs.piccolo.nodes.PText; + +/** + * PMenuItem実装の共通部分 + * + * @author miuramo + * + */ +public class PMenuItem_Abstract extends PPath { + private static final long serialVersionUID = 427251829572460625L; + + public PText ptext; + + public String text; + + PActionListener al = null; + + boolean isToggle; + + public Color defaultcolor; + + public PMenuRoot parent; + + boolean isSelected = false; + + Point2D pressP; + + PActionListener capitalShortcutKeyListener; + + public PMenuItem_Abstract(String arg, boolean m, Color c) { + super(new Rectangle2D.Float(0, 0, 3, 10)); + text = arg; + isToggle = m; + + ptext = new PText(arg); + ptext.offset(5, 3); + setPathToRectangle(0, 0, (float) ptext.getWidth() + 10, (float) ptext + .getHeight() + 5); + addChild(ptext); + setPaint(c); + setStroke(new BasicStroke(2)); + setStrokePaint(c.darker()); + setTransparency(0.8f); + defaultcolor = c; + + addInputEventListener(new PBasicInputEventHandler() { + public void mouseEntered(PInputEvent e) { + setPaint(defaultcolor); + } + + public void mouseExited(PInputEvent e) { + setSelected(isSelected); + } + + public void mousePressed(PInputEvent e) { + setPaint(Color.red); + pressP = e.getPositionRelativeTo(PMenuItem_Abstract.this); + } + + public void mouseReleased(PInputEvent e) { + setSelected(isSelected); + if (pressP != null && getBoundsReference().contains(pressP) + && getBoundsReference().contains(e.getPositionRelativeTo(PMenuItem_Abstract.this))) doClick(e); + pressP = null; + } + +// public void mouseClicked(PInputEvent e) { +// doClick(e); +// } + }); + } + + public String getText() { + return text; + } + + public void addPActionListener(PActionListener a) { + al = a; + } + + public void doClick(PInputEvent e) { + System.out.println(text + " is clicked."); + if (al != null) + al.actionPerformed(e); + if (isToggle) { + isSelected = !isSelected; + parent.setSelected(PMenuItem_Abstract.this); + } + } + + public void setSelected(boolean f) { + isSelected = f; + if (f) { + setStrokePaint(defaultcolor); + setPaint(defaultcolor); + } else { + setStrokePaint(defaultcolor.darker()); + setPaint(defaultcolor.darker()); + } + } + public boolean isSelected(){ + return isSelected; + } + + /** + * ショートカットキーで,大文字キーを押したときの反応 注意:イベントソースはあてにならない + * + * @param a + */ + public void addCapitalShortcutKeyListener(PActionListener a) { + capitalShortcutKeyListener = a; + } + + public void doCapicalShortcutKeySelected(PInputEvent e) { + if (capitalShortcutKeyListener != null) + capitalShortcutKeyListener.actionPerformed(e); + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/pui/PMenuItem_Color.java b/anchorgarden/src/main/java/jaist/css/covis/pui/PMenuItem_Color.java new file mode 100644 index 0000000..af65d8b --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/pui/PMenuItem_Color.java @@ -0,0 +1,16 @@ +package jaist.css.covis.pui; + +import java.awt.Color; + +/** + * (教師が書き込みするときの)色を選択するPMenuItem + * @author miuramo + * + */ +public class PMenuItem_Color extends PMenuItem_Abstract { + private static final long serialVersionUID = -3055144215383523849L; + + public PMenuItem_Color(String arg, boolean m, Color color) { + super(arg, m, color); + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/pui/PMenuItem_String.java b/anchorgarden/src/main/java/jaist/css/covis/pui/PMenuItem_String.java new file mode 100644 index 0000000..9a25128 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/pui/PMenuItem_String.java @@ -0,0 +1,16 @@ +package jaist.css.covis.pui; + +import java.awt.Color; + +/** + * 一般的な文字列ラベルを持つPMenuItem + * @author miuramo + * + */ +public class PMenuItem_String extends PMenuItem_Abstract { + private static final long serialVersionUID = 1789811891741678164L; + + public PMenuItem_String(String arg, boolean m, Color c) { + super(arg, m, c); + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/pui/PMenuRoot.java b/anchorgarden/src/main/java/jaist/css/covis/pui/PMenuRoot.java new file mode 100644 index 0000000..b844d7b --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/pui/PMenuRoot.java @@ -0,0 +1,55 @@ +package jaist.css.covis.pui; + + +import java.util.ArrayList; +import java.util.Iterator; + +import edu.umd.cs.piccolo.PNode; +import edu.umd.cs.piccolo.nodes.PPath; + +/** + * PMenuItemを並べて表示するための受け皿(メニュールート) + * @author miuramo + * + */ +@SuppressWarnings("serial") +public class PMenuRoot extends PPath implements CameraFittable { + PMenuItem_Abstract selected = null; // 選択中のメニュー + + ArrayList pmenulist; + + public PMenuRoot() { + pmenulist = new ArrayList(); + } + + public void layoutChildren() { + double xOffset = 0; + double yOffset = 0; + + Iterator i = getChildrenIterator(); + while (i.hasNext()) { + PNode each = (PNode) i.next(); + each.setOffset(xOffset - each.getX(), yOffset); + xOffset += each.getWidth();// + 2; //(gap) + } + } + + public void add(PMenuItem_Abstract childMenu) { + childMenu.parent = this; + addChild(childMenu); + pmenulist.add(childMenu); + } + + public void setSelected(PMenuItem_Abstract childMenu) { + for (PMenuItem_Abstract pm : pmenulist) { + if (pm.isToggle) { + if (pm == childMenu) { + pm.setSelected(true); + } else { + pm.setSelected(false); + } + } + } + selected = childMenu; + } +} \ No newline at end of file diff --git a/anchorgarden/src/main/java/jaist/css/covis/pui/package-info.java b/anchorgarden/src/main/java/jaist/css/covis/pui/package-info.java new file mode 100644 index 0000000..d07ed11 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/pui/package-info.java @@ -0,0 +1,6 @@ +/** + * 手書き文字認識DLLを呼び出すクラス群です. + * + */ + +package jaist.css.covis.pui; \ No newline at end of file diff --git a/anchorgarden/src/main/java/jaist/css/covis/util/BUtil.java b/anchorgarden/src/main/java/jaist/css/covis/util/BUtil.java new file mode 100644 index 0000000..6dd2b8e --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/util/BUtil.java @@ -0,0 +1,176 @@ +package jaist.css.covis.util; + +import edu.umd.cs.piccolo.util.PBounds; + +/** + * Bounds Utility Class + * + * @author miuramo + * + */ +public class BUtil { + /** + * 面積を返す + * @param pagemanager 領域 + * @return 面積 + */ + public static int getArea(PBounds pb) { + double w = pb.getWidth(); + double h = pb.getHeight(); + return (int) (w * h); + } + + /** + * 引数pbで与えた領域を,引数rateだけ拡大した新しい領域を返す + * @param pagemanager 領域 + * @param rate ズーム率 + * @return 新しい領域 + */ + public static PBounds zoomBounds(PBounds pb, double rate) { + double x = pb.getX(); + double y = pb.getY(); + double w = pb.getWidth(); + double h = pb.getHeight(); + double nw = w * rate; + double nh = h * rate; + double nx = x - (nw - w) / 2; + double ny = y - (nh - h) / 2; + return new PBounds(nx, ny, nw, nh); + } + + /** + * 引数pbで与えた領域を,引数rateだけ拡大した新しい領域を返す(ただしX方向のみ) + * @param pagemanager 領域 + * @param rate ズーム率 + * @return 新しい領域 + */ + public static PBounds zoomBoundsX(PBounds pb, double rate) { + double x = pb.getX(); + double y = pb.getY(); + double w = pb.getWidth(); + double h = pb.getHeight(); + double nw = w * rate; + double nh = h; + double nx = x - (nw - w) / 2; + double ny = y - (nh - h) / 2; + return new PBounds(nx, ny, nw, nh); + } + + /** + * 引数pbで与えた領域に,指定した幅と高さを加えた新しい領域を返す + * @param pagemanager 領域 + * @param plusx 横方向追加分 + * @param plusy 縦方向追加分 + * @return 新しい領域 + */ + public static PBounds plusBounds(PBounds pb, int plusx, int plusy) { + double x = pb.getX(); + double y = pb.getY(); + double w = pb.getWidth(); + double h = pb.getHeight(); + double nw = w + plusx; + double nh = h + plusy; + double nx = x - (nw - w) / 2; + double ny = y - (nh - h) / 2; + return new PBounds(nx, ny, nw, nh); + } + + /** + * pos が 1から3のときは,指定した領域を縦の長さを半分にした領域を計算し,それが元の領域の上か,中心か,下に移動する. + * pos が0のときは,領域をそのまま返す + * @param pagemanager 領域 + * @param pos 場所 + * @return 新しい領域 + */ + // pos = {0, 1, 2, 3 } = {full, top, middle, bottom}; + public static PBounds halfBounds(PBounds pb, int pos) { + double x = pb.getX(); + double y = pb.getY(); + double w = pb.getWidth(); + double h = pb.getHeight(); + if (pos == 0) { + return new PBounds(pb); + } + if (pos == 1) { + double nx = x; + double ny = y; + double nw = w; + double nh = h / 2; + return new PBounds(nx, ny, nw, nh); + } + if (pos == 2) { + double nx = x; + double ny = y + h / 4; + double nw = w; + double nh = h / 2; + return new PBounds(nx, ny, nw, nh); + } + if (pos == 3) { + double nx = x; + double ny = y + h / 2; + double nw = w; + double nh = h / 2; + return new PBounds(nx, ny, nw, nh); + } + return null; + } + + /** + * ズーム説明用の領域を計算する(現在は未使用) + * @param firstpb 最初の領域 + * @param panelpb パネルの領域 + * @param cameraview カメラの表示領域 + * @param width 幅 + * @return 新しい領域 + */ + public static PBounds explainBounds(PBounds firstpb, PBounds panelpb, + PBounds cameraview, double width) { + double fpbw = firstpb.width; + double zoom = width / fpbw; + PBounds tempb = zoomBoundsX(firstpb, zoom); + + double preferredheight = width * cameraview.height / cameraview.width; + + double tx = tempb.x; + double ty = tempb.y; + double tw = tempb.width; + double th = tempb.height; + double px = panelpb.x; + double py = panelpb.y; + double pw = panelpb.width; + double ph = panelpb.height; + if (tx < px) { + tx = px; + } + if (px + pw < tx + tw) { + tx = (px + pw) - tw; + } + double tcy = ty + th / 2; + ty = tcy - preferredheight / 2; + th = preferredheight; + if (ty < py) { + ty = py; + } + if (py + ph < ty + th) { + ty = (py + ph) - th; + } + return new PBounds(tx, ty, tw, th); + } + + /** + * Check whether piece is completely included in large. True if not + * included. + * + * @param large + * @param piece + * @return True if piece is not included in large + */ + public static boolean isHamidashi(PBounds large, PBounds piece) { + // if (piece.x < large.x) return true; + // if (piece.y < large.y) return true; + // if (large.x+large.width < piece.x+piece.width) return true; + // if (large.y+large.height < piece.y + piece.height) return true; + // return false; + return !large.contains(piece); + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/util/DateUtil.java b/anchorgarden/src/main/java/jaist/css/covis/util/DateUtil.java new file mode 100644 index 0000000..d75ea4c --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/util/DateUtil.java @@ -0,0 +1,23 @@ +package jaist.css.covis.util; + +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * Date Utility Class + * + * @author miuramo + * + */ +public class DateUtil { + /** + * Longで示された時刻を,フォーマットした文字列を返す + * @param time Longで示された時刻 + * @return フォーマットした文字列 + */ + public static String convert(long time) { + Date d = new Date(time); + SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); + return df.format(d); + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/util/FileReadWriter.java b/anchorgarden/src/main/java/jaist/css/covis/util/FileReadWriter.java new file mode 100644 index 0000000..90ec048 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/util/FileReadWriter.java @@ -0,0 +1,99 @@ +package jaist.css.covis.util; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; + +/** + * ファイル読み書きクラス + * + * @author miuramo + * + */ +public class FileReadWriter { + + /** ファイルを読み込み,各行を配列に入れて返す + * @param fn ファイル名 + * @return 文字列の配列(各行が要素) + */ + public static String[] getLines(String fn) { + if (fn == null) return new String[]{""}; + ArrayList list = new ArrayList(); + try { + BufferedReader br = new BufferedReader(new InputStreamReader( + new FileInputStream(fn))); + String line = null; + /* ファイル読み込み */ + while ((line = br.readLine()) != null) { + list.add(line); + } + /* ファイルを閉じます */ + br.close(); + } catch (IOException err) { + System.out.println("ReadError:" + fn); + } + return (String[]) list.toArray(new String[list.size()]); + } + + /** 配列をファイルに書き込む + * + * @param fn ファイル名 + * @param data 文字列の配列(各行が要素) + */ + public static void putLines(String fn, String data[]) { + try { + FileWriter filewriter = new FileWriter(fn, false); + for (int i = 0; i < data.length; i++) { + /* 改行文字追加 */ + data[i] = data[i] + "\n"; + /* 文字列を書き込みます */ + filewriter.write(data[i]); + } + /* ファイルを閉じます */ + filewriter.close(); + } catch (IOException e) { + System.out.println("WriteError:" + fn); + } + } + + /** ArrayListをファイルに書き込む + * + * @param fn ファイル名 + * @param list 文字列のArrayList(各要素が行となる) + */ + public static void putLines(String fn, ArrayList list) { + try { + FileWriter filewriter = new FileWriter(fn, false); + for (String s : list) { + /* 文字列を書き込みます */ + filewriter.write(s + "\n"); + } + /* ファイルを閉じます */ + filewriter.close(); + } catch (IOException e) { + System.out.println("WriteError:" + fn); + } + } + + /** + * 文字列を分割して配列で返します + + * @param delim 区切り文字 + * @param text 分割したいテキスト + * @return 分割した文字列の配列 + */ + public static String[] split(String delim, String text) { + int index = -1; + ArrayList list = new ArrayList(); + while ((index = text.indexOf(delim)) != -1) { + list.add(text.substring(0, index)); + text = text.substring(index + delim.length()); + } + list.add(text); + String[] ret = (String[]) list.toArray(new String[list.size()]); + return ret; + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/util/FileUtil.java b/anchorgarden/src/main/java/jaist/css/covis/util/FileUtil.java new file mode 100644 index 0000000..4e088a5 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/util/FileUtil.java @@ -0,0 +1,79 @@ +package jaist.css.covis.util; + +import java.io.BufferedInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; + +/** + * File Utility Class + * + * @author miuramo + * + */ +@Deprecated +public class FileUtil { + + /** + * バイナリファイルをバイト列として読み込む + * @param path ファイルのパス + * @return バイナリ配列データ + */ + public byte[] path2byte(String path) { + File f = new File(path); + long fsize = f.length(); + + ByteArrayOutputStream varyBuf = new ByteArrayOutputStream((int) fsize); + InputStream in = null; + int b; + try { + in = new BufferedInputStream(new FileInputStream(path)); + final int LS = 1024; + byte buf[] = new byte[LS]; + + while ((b = in.read(buf, 0, buf.length)) != -1) { + varyBuf.write(buf, 0, b); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + } + return varyBuf.toByteArray(); + } + + public void byte2file(String path, byte[] b) { + } + + public byte[] byte2gzip(byte[] source) { + return null; + } + + public byte[] byte2zip(byte[] source) { + return null; + } + +} + +// 以下本体部の読み込み +// 45: String line; +// 46: // ByteArrayOutputStreamに読み込んだ内容を出力しておく +// 47: ByteArrayOutputStream receivedBuffer = new ByteArrayOutputStream(); +// 48: while((size=in.readLine(buffer,0,buffer.length)) != -1){ +// 49: line = new String(buffer,0, size); +// 50: if (line.indexOf(boundary)!=-1) break; +// 51: receivedBuffer.write(buffer,0,size); +// 52: } +// 53: in.close(); +// 54: +// 55: // 受信したデータをファイルに出力 +// 56: FileOutputStream fout = new FileOutputStream(fileName); +// 57: byte buf[] = receivedBuffer.toByteArray(); +// 58: // boundaryの前に出力される空行(CR+LF)を削ってファイルに出力 +// 59: fout.write(buf, 0, buf.length-2); +// 60: fout.close(); + diff --git a/anchorgarden/src/main/java/jaist/css/covis/util/FramePopup.java b/anchorgarden/src/main/java/jaist/css/covis/util/FramePopup.java new file mode 100644 index 0000000..66d4f57 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/util/FramePopup.java @@ -0,0 +1,9 @@ +package jaist.css.covis.util; + +import java.awt.Component; + +import javax.swing.JFrame; + +public interface FramePopup { + public void showWithFrame(Component c, int x, int y, JFrame f); +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/util/InputTokenizer.java b/anchorgarden/src/main/java/jaist/css/covis/util/InputTokenizer.java new file mode 100644 index 0000000..4d590cd --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/util/InputTokenizer.java @@ -0,0 +1,105 @@ +package jaist.css.covis.util; + +import java.util.ArrayList; + +/** + * InputTokenizer + * + * 日本語,英語の文章を区切って Card(ラベル)に配置しやすくするための クラス + * + * MeCab(日本語構文解析器)がインストールされていて,日本語文章なら mecabTokenize() そうでなければ tokenize()を使うように + * するとよい.(33-37行目) + * + * @author miuramo + * + */ +public class InputTokenizer { + String orig; + + ArrayList tokens; + + // static Vector distinguish; + // static { + // distinguish.add(Character.UnicodeBlock) + // } + + public InputTokenizer(String src) { + orig = src.trim(); // 前後の空白は取り除かれる + tokens = new ArrayList(); + + tokenize(); + /* + * if (orig.indexOf(" ")>0) tokenize(); // 空白があるのはおそらく英語だろう>tokenize() + * else mecabTokenize(); + */ + } + + public void tokenize() { + char[] charary; + + charary = orig.toCharArray(); + Character.UnicodeBlock currentB = null, prevB = null; + StringBuffer sb = new StringBuffer(); + + for (int i = 0; i < charary.length; i++) { + currentB = Character.UnicodeBlock.of(charary[i]); + if (charary[i] == ' ') { + // 一旦区切る + if (sb.length() > 0) + tokens.add(sb.toString()); + sb = new StringBuffer(); + // そして,同じものを集める + sb.append(charary[i]); + i++; + while (charary[i] == ' ') { + sb.append(charary[i]); + i++; + } + currentB = Character.UnicodeBlock.of(charary[i]); + // 集まったら,次へ + if (sb.length() > 0) + tokens.add(sb.toString()); + sb = new StringBuffer(); + sb.append(charary[i]); + } else if (currentB == prevB + && currentB != Character.UnicodeBlock.HIRAGANA) { + sb.append(charary[i]); + } else { + if (sb.length() > 0) + tokens.add(sb.toString()); + sb = new StringBuffer(); + sb.append(charary[i]); + } + prevB = currentB; + } + tokens.add(sb.toString()); + } + + public void print() { + for (String s : tokens) { + System.out.println("[" + s + "]"); + } + } + +// public Vector getTokens() { +// Vector tok = new Vector(); +// for (String s : tokens) { +// tok.add(new Token(s)); +// } +// return tok; +// } + +// public static void main(String[] args) { +// BufferedReader stdin = new BufferedReader(new InputStreamReader( +// System.in)); +// String strnum; +// try { +// while ((strnum = stdin.readLine()) != null) { +// InputTokenizer it = new InputTokenizer(strnum); +// it.print(); +// } +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/util/MemoryMonitor.java b/anchorgarden/src/main/java/jaist/css/covis/util/MemoryMonitor.java new file mode 100644 index 0000000..09b2f1a --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/util/MemoryMonitor.java @@ -0,0 +1,391 @@ +/* + * @(#)MemoryMonitor.java 1.37 06/08/29 + * + * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * -Redistribution of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * -Redistribution in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING + * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE + * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN") + * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE + * AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS + * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST + * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, + * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY + * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, + * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed, licensed or intended + * for use in the design, construction, operation or maintenance of any + * nuclear facility. + */ + +/** + * + * @(#)MemoryMonitor.java 1.37 06/08/29 + */ + +package jaist.css.covis.util; + +import static java.awt.Color.BLACK; +import static java.awt.Color.GREEN; +import static java.awt.Color.YELLOW; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Rectangle; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.awt.event.WindowListener; +import java.awt.geom.Line2D; +import java.awt.geom.Rectangle2D; +import java.awt.image.BufferedImage; +import java.util.Date; + +import javax.swing.JCheckBox; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.border.EtchedBorder; +import javax.swing.border.TitledBorder; + +/** + * Tracks Memory allocated & used, displayed in graph form. + */ +public class MemoryMonitor extends JPanel { + + /** + * + */ + private static final long serialVersionUID = -1130602506109710526L; + + static JCheckBox dateStampCB = new JCheckBox("Output Date Stamp"); + + public Surface surf; + + JPanel controls; + + boolean doControls; + + JTextField tf; + + public MemoryMonitor() { + setLayout(new BorderLayout()); + setBorder(new TitledBorder(new EtchedBorder(), "Memory Monitor")); + add(surf = new Surface()); + controls = new JPanel(); + controls.setPreferredSize(new Dimension(135, 80)); + Font font = new Font("serif", Font.PLAIN, 10); + JLabel label = new JLabel("Sample Rate"); + label.setFont(font); + label.setForeground(BLACK); + controls.add(label); + tf = new JTextField("1000"); + tf.setPreferredSize(new Dimension(45, 20)); + controls.add(tf); + controls.add(label = new JLabel("ms")); + label.setFont(font); + label.setForeground(BLACK); + controls.add(dateStampCB); + dateStampCB.setFont(font); + addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + removeAll(); + if ((doControls = !doControls)) { + surf.stop(); + add(controls); + } else { + try { + surf.sleepAmount = Long.parseLong(tf.getText().trim()); + } catch (Exception ex) { + } + surf.start(); + add(surf); + } + revalidate(); + repaint(); + } + }); + } + + public class Surface extends JPanel implements Runnable { + + /** + * + */ + private static final long serialVersionUID = 7400160221241153518L; + + public Thread thread; + + public long sleepAmount = 1000; + + private int w, h; + + private BufferedImage bimg; + + private Graphics2D big; + + private Font font = new Font("Times New Roman", Font.PLAIN, 11); + + private Runtime r = Runtime.getRuntime(); + + private int columnInc; + + private int pts[]; + + private int ptNum; + + private int ascent, descent; + + private Rectangle graphOutlineRect = new Rectangle(); + + private Rectangle2D mfRect = new Rectangle2D.Float(); + + private Rectangle2D muRect = new Rectangle2D.Float(); + + private Line2D graphLine = new Line2D.Float(); + + private Color graphColor = new Color(46, 139, 87); + + private Color mfColor = new Color(0, 100, 0); + + private String usedStr; + + public Surface() { + setBackground(BLACK); + addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + if (thread == null) + start(); + else + stop(); + } + }); + } + + public Dimension getMinimumSize() { + return getPreferredSize(); + } + + public Dimension getMaximumSize() { + return getPreferredSize(); + } + + public Dimension getPreferredSize() { + return new Dimension(135, 80); + } + + public void paint(Graphics g) { + + if (big == null) { + return; + } + + big.setBackground(getBackground()); + big.clearRect(0, 0, w, h); + + float freeMemory = (float) r.freeMemory(); + float totalMemory = (float) r.totalMemory(); + + // .. Draw allocated and used strings .. + big.setColor(GREEN); + big.drawString(String.valueOf((int) totalMemory / 1024) + + "K allocated", 4.0f, (float) ascent + 0.5f); + usedStr = String.valueOf(((int) (totalMemory - freeMemory)) / 1024) + + "K used"; + big.drawString(usedStr, 4, h - descent); + + // Calculate remaining size + float ssH = ascent + descent; + float remainingHeight = (float) (h - (ssH * 2) - 0.5f); + float blockHeight = remainingHeight / 10; + float blockWidth = 20.0f; + // .. Memory Free .. + big.setColor(mfColor); + int MemUsage = (int) ((freeMemory / totalMemory) * 10); + int i = 0; + for (; i < MemUsage; i++) { + mfRect.setRect(5, (float) ssH + i * blockHeight, blockWidth, + (float) blockHeight - 1); + big.fill(mfRect); + } + + // .. Memory Used .. + big.setColor(GREEN); + for (; i < 10; i++) { + muRect.setRect(5, (float) ssH + i * blockHeight, blockWidth, + (float) blockHeight - 1); + big.fill(muRect); + } + + // .. Draw History Graph .. + big.setColor(graphColor); + int graphX = 30; + int graphY = (int) ssH; + int graphW = w - graphX - 5; + int graphH = (int) remainingHeight; + graphOutlineRect.setRect(graphX, graphY, graphW, graphH); + big.draw(graphOutlineRect); + + int graphRow = graphH / 10; + + // .. Draw row .. + for (int j = graphY; j <= graphH + graphY; j += graphRow) { + graphLine.setLine(graphX, j, graphX + graphW, j); + big.draw(graphLine); + } + + // .. Draw animated column movement .. + int graphColumn = graphW / 15; + + if (columnInc == 0) { + columnInc = graphColumn; + } + + for (int j = graphX + columnInc; j < graphW + graphX; j += graphColumn) { + graphLine.setLine(j, graphY, j, graphY + graphH); + big.draw(graphLine); + } + + --columnInc; + + if (pts == null) { + pts = new int[graphW]; + ptNum = 0; + } else if (pts.length != graphW) { + int tmp[] = null; + if (ptNum < graphW) { + tmp = new int[ptNum]; + System.arraycopy(pts, 0, tmp, 0, tmp.length); + } else { + tmp = new int[graphW]; + System.arraycopy(pts, pts.length - tmp.length, tmp, 0, + tmp.length); + ptNum = tmp.length - 2; + } + pts = new int[graphW]; + System.arraycopy(tmp, 0, pts, 0, tmp.length); + } else { + big.setColor(YELLOW); + pts[ptNum] = (int) (graphY + graphH + * (freeMemory / totalMemory)); + for (int j = graphX + graphW - ptNum, k = 0; k < ptNum; k++, j++) { + if (k != 0) { + if (pts[k] != pts[k - 1]) { + big.drawLine(j - 1, pts[k - 1], j, pts[k]); + } else { + big.fillRect(j, pts[k], 1, 1); + } + } + } + if (ptNum + 2 == pts.length) { + // throw out oldest point + for (int j = 1; j < ptNum; j++) { + pts[j - 1] = pts[j]; + } + --ptNum; + } else { + ptNum++; + } + } + g.drawImage(bimg, 0, 0, this); + } + + public void start() { + thread = new Thread(this); + thread.setPriority(Thread.MIN_PRIORITY); + thread.setName("MemoryMonitor"); + thread.start(); + } + + public synchronized void stop() { + thread = null; + notify(); + } + + public void run() { + + Thread me = Thread.currentThread(); + + while (thread == me && !isShowing() || getSize().width == 0) { + try { + Thread.sleep(500); + } catch (InterruptedException e) { + return; + } + } + + while (thread == me && isShowing()) { + Dimension d = getSize(); + if (d.width != w || d.height != h) { + w = d.width; + h = d.height; + bimg = (BufferedImage) createImage(w, h); + big = bimg.createGraphics(); + big.setFont(font); + FontMetrics fm = big.getFontMetrics(font); + ascent = (int) fm.getAscent(); + descent = (int) fm.getDescent(); + } + repaint(); + try { + Thread.sleep(sleepAmount); + } catch (InterruptedException e) { + break; + } + if (MemoryMonitor.dateStampCB.isSelected()) { + System.out.println(new Date().toString() + " " + usedStr); + } + } + thread = null; + } + } + + public static void openMemoryMonitor() { + final MemoryMonitor demo = new MemoryMonitor(); + final JFrame f = new JFrame("MemoryMonitor"); + WindowListener l = new WindowAdapter() { + public void windowClosing(WindowEvent e) { + demo.surf.stop(); + f.dispose(); + } + public void windowDeiconified(WindowEvent e) { + demo.surf.start(); + } + + public void windowIconified(WindowEvent e) { + demo.surf.stop(); + } + }; + + f.addWindowListener(l); + f.getContentPane().add(demo, BorderLayout.CENTER); + f.pack(); + f.setSize(new Dimension(200, 200)); + f.setVisible(true); + f.setLocation(965, 1); + demo.surf.start(); + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/util/MouseWheelRotationListener.java b/anchorgarden/src/main/java/jaist/css/covis/util/MouseWheelRotationListener.java new file mode 100644 index 0000000..f202f53 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/util/MouseWheelRotationListener.java @@ -0,0 +1,5 @@ +package jaist.css.covis.util; + +public interface MouseWheelRotationListener { + public void mouseWheelRotated(float f); +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/util/MyBox.java b/anchorgarden/src/main/java/jaist/css/covis/util/MyBox.java new file mode 100644 index 0000000..5985c0a --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/util/MyBox.java @@ -0,0 +1,7 @@ +package jaist.css.covis.util; + +public interface MyBox { + public double getWidth(); + public double getHeight(); + public String toString(); +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/util/MyBoxMatrixHolder.java b/anchorgarden/src/main/java/jaist/css/covis/util/MyBoxMatrixHolder.java new file mode 100644 index 0000000..d283cd1 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/util/MyBoxMatrixHolder.java @@ -0,0 +1,129 @@ +package jaist.css.covis.util; + +import java.awt.geom.Point2D; +import java.util.ArrayList; +import java.util.TreeMap; + +/** + * マス目に文字列などのデータを結びつけるクラス + * + * ここでは,特に(int,int) -> String を意識して,putメソッドを作成している + * 複数行のテキストトークンを扱えるようにカスタマイズ + */ +public class MyBoxMatrixHolder { + ArrayList> datahash; + ArrayList lastList; + + public MyBoxMatrixHolder() { + datahash = new ArrayList>(); + lastList = new ArrayList(); + datahash.add(lastList); + } + public MyBoxMatrixHolder(ArrayList boxes, double trialWidth){ + this(); + double t = 0; + for(MyBox b: boxes){ + if (trialWidth < (t + b.getWidth())){ + addNewLine(); + t = 0; + } + lastList.add(b); + t += b.getWidth(); + } + } + public void addNewLine(){ + lastList = new ArrayList(); + datahash.add(lastList); + } + public void add(int y, MyBox val) { + datahash.get(y).add(val); + } + public double getLineLength(int y){ + Point2D p = getAllLength(datahash.get(y)); + return p.getX(); + } + public Point2D getDimension(){ + double w = 0; + double h = 0; + for(int i=0;i get(int y) { + return datahash.get(y); + } + + public void removeAll() { + datahash.clear(); + } + public String toString(){ + StringBuffer sb = new StringBuffer(); + for(int i=0;i tokenlist){ + double length = 0; + double height = 0; + for(MyBox szht:tokenlist) { + length += szht.getWidth(); + if (height < szht.getHeight()) height = szht.getHeight(); + } + return new Point2D.Double(length,height); + } + public static String getPreferredStringLineBreak(String s, double parentrate){ + String src = s.replaceAll("\n", ""); +// InputTokenizer it = new InputTokenizer(src); + ArrayList tokens = new InputTokenizer(src).tokens; + ArrayList blist = new ArrayList(); + for(String k:tokens){ + SimpleZenHanToken szht = new SimpleZenHanToken(k); + blist.add(szht); + } + MyBoxMatrixHolder best = getPreferredHolder(blist, parentrate); + return best.toString(); + } + + public static MyBoxMatrixHolder getPreferredHolder(ArrayList blist, double parentrate){ + TreeMap resultRates = new TreeMap(); + double trialLen = getAllLength(blist).getX(); +// double ratediff = Double.MAX_VALUE; + for(int i=0;i<9;i++){ + MyBoxMatrixHolder mbmh = new MyBoxMatrixHolder(blist, trialLen); + double fitrate = mbmh.getFitRate(); + resultRates.put(Math.abs(parentrate - fitrate), mbmh); +// System.out.println(i+" "+fitrate); +// if (ratediff < Math.abs(parentrate - fitrate)) break; + if (parentrate < fitrate){ + trialLen *= 0.75; + } else { + trialLen *= 1.3; + } +// if (Math.abs(trialLen-lastTrialLen)<2.0d) break; + } + for(double d: resultRates.keySet()){ + System.out.println(d+" "+resultRates.get(d).toString()); + } + ArrayList intres = new ArrayList(resultRates.values()); + return intres.get(0); + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/util/MyPCanvas.java b/anchorgarden/src/main/java/jaist/css/covis/util/MyPCanvas.java new file mode 100644 index 0000000..1d24f15 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/util/MyPCanvas.java @@ -0,0 +1,208 @@ +package jaist.css.covis.util; + +import java.awt.AWTException; +import java.awt.Point; +import java.awt.Robot; +import java.awt.event.InputEvent; +import java.awt.event.MouseEvent; +import java.awt.geom.NoninvertibleTransformException; +import java.awt.geom.Point2D; + +import edu.umd.cs.piccolo.PCamera; +import edu.umd.cs.piccolo.PCanvas; +import edu.umd.cs.piccolo.PInputManager; +import edu.umd.cs.piccolo.event.PBasicInputEventHandler; +import edu.umd.cs.piccolo.event.PInputEvent; +import edu.umd.cs.piccolo.event.PInputEventFilter; +import edu.umd.cs.piccolo.event.PPanEventHandler; +import edu.umd.cs.piccolo.util.PBounds; +import edu.umd.cs.piccolox.event.PSelectionEventHandler; +import edu.umd.cs.piccolox.event.PZoomToEventHandler; + +@SuppressWarnings("serial") + + + +public class MyPCanvas extends PCanvas { + + static PInputEventFilter b1mask = new PInputEventFilter( + InputEvent.BUTTON1_DOWN_MASK); + + static PInputEventFilter b2mask = new PInputEventFilter( + InputEvent.BUTTON2_DOWN_MASK); + + static PInputEventFilter b3mask = new PInputEventFilter( + InputEvent.BUTTON3_DOWN_MASK); + + static PInputEventFilter disablemask = new PInputEventFilter(0); + + PBasicInputEventHandler flowmenuEventHandler; + + PSelectionEventHandler selectionEventHandler; + + PPanEventHandler panEventHandler; + + PZoomToEventHandler zoomeh; + + Point2D cursorpoint; + + public PCamera cam; + + WheelZoomEventHandler wheelzoom; + + public MouseWheelRotationListener wheelListener; + + /** + * ホイール回転時のズーム方向.1または-1.デフォルトは1 = 手前(下)回転でズームイン + */ +// public int wheelrotationdirection = -1; + + /** + * カーソルを中央にもってくるかどうか + */ + public boolean moveMouseCursorOnZoomIn = true; + Robot robot; + + /** + * ズーム時の幅 + */ + public float wheelZoomRatio = 1.0f; + + public MyPCanvas() { + super(); + initialize(); + try { + robot = new Robot(); + } catch (AWTException e) { + } + } + /** + * 擬似的なクリック + * @param x + * @param y + */ + public void pseudoClick(int x, int y){ + getRoot().getDefaultInputManager().processEventFromCamera(new MouseEvent(this,0,0,MouseEvent.BUTTON1,x,y,1,true), MouseEvent.MOUSE_PRESSED, getCamera()); + getRoot().getDefaultInputManager().processEventFromCamera(new MouseEvent(this,0,0,MouseEvent.BUTTON1,x,y,1,false), MouseEvent.MOUSE_RELEASED, getCamera()); + } + + public void setWheelRotationDirection(int d){ + if (wheelzoom != null) wheelzoom.setDirection(d); + } + public void setMouseWheelRotationListener(MouseWheelRotationListener l){ + wheelListener = l; + } + public void setWheelZoomRatio(float f){ + wheelZoomRatio = f; + } + + public PBasicInputEventHandler getWheelListener() { + return wheelzoom; + } + + class WheelZoomEventHandler extends PBasicInputEventHandler { + public int direction = -1; + public void setDirection(int d){ + direction = d; + } + public void mouseWheelRotated(PInputEvent e) { + if (!e.isControlDown() && !e.isShiftDown() && !e.isAltDown()) { + PCamera pc = getCamera(); + +// System.out.println("wheel rotation: " + pc.getAttribute("hoge")); + PBounds pb = pc.getViewBounds(); +// System.out.println(pb.toString()); + float f = 1.0f + (0.2f * direction * e.getWheelRotation()); + if (e.getWheelRotation() //下に回すと正になるので + * direction < 0) { + pb = zoomBounds_focusbyCursor(pb, f); + } else { + pb = BUtil.zoomBounds(pb, f); + } + if (pb.x == 0 && pb.y == 0) { + System.out.println("ズームイン位置がまだ準備前"); + return; + } + pc.animateViewToCenterBounds(pb, true, 0); + if (MyPCanvas.this.wheelListener != null) MyPCanvas.this.wheelListener.mouseWheelRotated(f); + } + } + } + + public void initialize() { + cam = getCamera(); + + disablemask.rejectAllEventTypes(); + + wheelzoom = new WheelZoomEventHandler(); + wheelzoom.setEventFilter(b2mask); + cam.addInputEventListener(wheelzoom); + + // panEventHandler = new PPanEventHandler(); + // getPanEventHandler().setEventFilter(disablemask); + // panEventHandler.setEventFilter(b2mask); + // addInputEventListener(panEventHandler); + getPanEventHandler().setEventFilter(b2mask); + // check current cursor position + addInputEventListener(new PInputManager() { + public void mouseMoved(PInputEvent e) { + cursorpoint = e.getCanvasPosition(); + try { + e.getPath().getPathTransformTo(getLayer()).inverseTransform(cursorpoint, cursorpoint); + } catch (RuntimeException ex) { + cursorpoint = e.getPosition(); // Camera付きのメニューボタンや,背景部分(PCamera)のとき + } + // TODO: 本来であればRuntimeExceptionを出さずに処理したいのだが.. +// e.getPickedNode().localToParent(cursorpoint); +// System.out.println(e.getPickedNode().getRoot().getClass().getName()); +// if (e.getPickedNode() instanceof PCamera) +// else cursorpoint = e.getPositionRelativeTo(getLayer()); + catch (NoninvertibleTransformException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + }); + } + + public PBounds zoomBounds_focusbyCursor(PBounds pb, double rate) { + double x = pb.getX(); + double y = pb.getY(); + double w = pb.getWidth(); + double h = pb.getHeight(); + double nw = w * rate; + double nh = h * rate; + Point2D camcp = cam.getViewBounds().getCenter2D(); + double camcx = camcp.getX(); + double camcy = camcp.getY(); +// System.out.println("camcp "+camcx+" "+camcy); + double curx = cursorpoint.getX(); + double cury = cursorpoint.getY(); +// System.out.println("cursor "+curx+" "+cury); + double nx = x - (nw - w) / 2 + curx - camcx; + double ny = y - (nh - h) / 2 + cury - camcy; + PBounds ret = new PBounds(nx, ny, nw, nh); + cursorpoint = ret.getCenter2D(); + if (moveMouseCursorOnZoomIn) { + moveCursorPointCenter(); + } else { + } + return ret; + } + + public void moveCursorPointCenter() { + Point canvasglobalp = getLocationOnScreen(); + int canvasw = getWidth(); + int canvash = getHeight(); + if (robot != null) + robot.mouseMove((int) (canvasglobalp.getX() + canvasw / 2), + (int) (canvasglobalp.getY() + canvash / 2)); + } +} + +//@SuppressWarnings("serial") +//class MyPCanvas_noPointerZoom extends MyPCanvas { +//public PBounds zoomBounds_focusbyCursor(PBounds pb, double rate) { +//return BUtil.zoomBounds(pb, rate); +//} +//} diff --git a/anchorgarden/src/main/java/jaist/css/covis/util/MyPFrame.java b/anchorgarden/src/main/java/jaist/css/covis/util/MyPFrame.java new file mode 100644 index 0000000..5d4f73e --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/util/MyPFrame.java @@ -0,0 +1,275 @@ +package jaist.css.covis.util; + +/* + * Copyright (c) 2002-@year@, University of Maryland + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this list of conditions + * and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the University of Maryland nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean + * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo. + */ +//package edu.umd.cs.piccolox; + +import java.awt.DisplayMode; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; +import java.awt.Rectangle; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.util.ArrayList; +import java.util.Collection; +import java.util.EventListener; +import java.util.Iterator; + +import javax.swing.JFrame; + +//import org.apache.commons.lang.SystemUtils; + +/** + * PFrame is meant to be subclassed by applications that just need a PCanvas in a JFrame. + * It also includes full screen mode functionality when run in JDK 1.4. These + * subclasses should override the initialize method and start adding their own + * code there. Look in the examples package to see lots of uses of PFrame. + * + * @version 1.0 + * @author Jesse Grosjean + */ +public class MyPFrame extends JFrame { + private static final long serialVersionUID = -999101227638438097L; + public MyPCanvas canvas; + public GraphicsDevice graphicsDevice; + public DisplayMode originalDisplayMode; + public EventListener escapeFullScreenModeListener; + + public MyPFrame() { + this("", false, null); + } + + public MyPFrame(String title, boolean fullScreenMode, MyPCanvas aCanvas) { + this(title, GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(), fullScreenMode, aCanvas); + } + + public MyPFrame(String title, GraphicsDevice aDevice, final boolean fullScreenMode, final MyPCanvas aCanvas) { + super(title, aDevice.getDefaultConfiguration()); + + graphicsDevice = aDevice; + + try { + originalDisplayMode = graphicsDevice.getDisplayMode(); + } catch (InternalError e) { + e.printStackTrace(); + } + + setBounds(getDefaultFrameBounds()); + setBackground(null); + + try { + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + } catch (SecurityException e) {} // expected from applets + + if (aCanvas == null) { + canvas = new MyPCanvas(); + } else { + canvas = aCanvas; + } + + getContentPane().add(canvas); + validate(); +// if (SystemUtils.IS_OS_MAC) setFullScreenMode(fullScreenMode); + canvas.requestFocus(); + beforeInitialize(); + + // Manipulation of Piccolo's scene graph should be done from Swings + // event dispatch thread since Piccolo is not thread safe. This code calls + // initialize() from that thread once the PFrame is initialized, so you are + // safe to start working with Piccolo in the initialize() method. + + MyPFrame.this.initialize(); + +// SwingUtilities.invokeLater(new Runnable() { +// public void run() { +// MyPFrame.this.initialize(); +// repaint(); +//// canvas.grabFocus(); +//// System.out.println("invokelater"); +// } +// }); + } + + public MyPCanvas getCanvas() { + return canvas; + } +// public void setCanvas(PCanvas c){ +// canvas = c; +// getContentPane().add(canvas); +// validate(); +// canvas.requestFocus(); +// setFullScreenMode(isFullScreenMode()); +// } + + public Rectangle getDefaultFrameBounds() { + return new Rectangle(100, 100, 400, 400); + } + + //**************************************************************** + // Full Screen Display Mode + //**************************************************************** + + public boolean isFullScreenMode() { + return graphicsDevice.getFullScreenWindow() != null; + } + + public void setFullScreenMode(boolean fullScreenMode){ + setFullScreenMode(fullScreenMode,graphicsDevice); + } + public void setFullScreenMode(boolean fullScreenMode, GraphicsDevice graphicsDevice2) { + graphicsDevice = graphicsDevice2; + + if (fullScreenMode) { + addEscapeFullScreenModeListener(); + + if (isDisplayable()) { + dispose(); + } + + setUndecorated(true); + setResizable(false); + graphicsDevice2.setFullScreenWindow(this); + + if (graphicsDevice2.isDisplayChangeSupported()) { + chooseBestDisplayMode(graphicsDevice2); + } + validate(); + } else { + removeEscapeFullScreenModeListener(); + + if (isDisplayable()) { + dispose(); + } + + setUndecorated(false); + setResizable(true); + graphicsDevice2.setFullScreenWindow(null); + validate(); + setVisible(true); + } + } + + protected void chooseBestDisplayMode(GraphicsDevice device) { + DisplayMode best = getBestDisplayMode(device); + if (best != null) { + device.setDisplayMode(best); + } + } + + protected DisplayMode getBestDisplayMode(GraphicsDevice device) { + Iterator itr = getPreferredDisplayModes(device).iterator(); + while (itr.hasNext()) { + DisplayMode each = (DisplayMode) itr.next(); + DisplayMode[] modes = device.getDisplayModes(); + for (int i = 0; i < modes.length; i++) { + if (modes[i].getWidth() == each.getWidth() && + modes[i].getHeight() == each.getHeight() && + modes[i].getBitDepth() == each.getBitDepth()) { + return each; + } + } + } + + return null; + } + + /** + * By default return the current display mode. Subclasses may override this method + * to return other modes in the collection. + */ + @SuppressWarnings({ "unchecked", "rawtypes" }) + protected Collection getPreferredDisplayModes(GraphicsDevice device) { + ArrayList result = new ArrayList(); + + result.add(device.getDisplayMode()); + /*result.add(new DisplayMode(640, 480, 32, 0)); + result.add(new DisplayMode(640, 480, 16, 0)); + result.add(new DisplayMode(640, 480, 8, 0));*/ + + return result; + } + + /** + * This method adds a key listener that will take this PFrame out of full + * screen mode when the escape key is pressed. This is called for you + * automatically when the frame enters full screen mode. + */ + public void addEscapeFullScreenModeListener() { + removeEscapeFullScreenModeListener(); + escapeFullScreenModeListener = new KeyAdapter() { + public void keyPressed(KeyEvent aEvent) { + if (aEvent.getKeyCode() == KeyEvent.VK_ESCAPE) { + setFullScreenMode(false); + } + } + }; + canvas.addKeyListener((KeyListener)escapeFullScreenModeListener); + } + + /** + * This method removes the escape full screen mode key listener. It will be + * called for you automatically when full screen mode exits, but the method + * has been made public for applications that wish to use other methods for + * exiting full screen mode. + */ + public void removeEscapeFullScreenModeListener() { + if (escapeFullScreenModeListener != null) { + canvas.removeKeyListener((KeyListener)escapeFullScreenModeListener); + escapeFullScreenModeListener = null; + } + } + + //**************************************************************** + // Initialize + //**************************************************************** + + /** + * This method will be called before the initialize() method and will be + * called on the thread that is constructing this object. + */ + public void beforeInitialize() { + } + + /** + * Subclasses should override this method and add their + * Piccolo initialization code there. This method will be called on the + * swing event dispatch thread. Note that the constructors of PFrame + * subclasses may not be complete when this method is called. If you need to + * initailize some things in your class before this method is called place + * that code in beforeInitialize(); + */ + public void initialize() { + } + + public static void main(String[] argv) { + new MyPFrame(); + } +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/util/SimpleZenHanToken.java b/anchorgarden/src/main/java/jaist/css/covis/util/SimpleZenHanToken.java new file mode 100644 index 0000000..1862981 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/util/SimpleZenHanToken.java @@ -0,0 +1,43 @@ +package jaist.css.covis.util; + + +/** + * 全角なら2,半角なら1と長さをカウントする単純なトークン + * @author miuramo + * + */ +public class SimpleZenHanToken implements MyBox { + int length; + String orig; + public SimpleZenHanToken(String s){ + orig = s; + char[] charary; + charary = s.toCharArray(); + for(int i=0;i': + sb.append(">"); + break; + case '"': + sb.append("""); + break; + case '&': + sb.append("&"); + break; + default: + sb.append((char) ch); + break; + } + } + return sb.toString(); + } + + /** + * とりあえず判定 別箇所にあるべき機能であるが。 + */ + public static boolean isEmail(java.lang.String email) { + boolean ret = false; + int at; + if ((at = email.indexOf('@')) >= 0) { + if (email.indexOf('.', at) >= at) { + ret = true; + } + } + return ret; + } + + /** + * 半角カタカナを全角カタカナに変換する日本語正規化 1文字単位。 + */ + public static char toKanaFull(char kana) { + int index; + + if ((index = kana1.indexOf(kana)) >= 0) { + kana = kana2.charAt(index); + } + + return kana; + } + + /** + * 半角カタカナを全角カタカナにし、濁点も統合する。 日本語正規化 使用例 郵便番号辞書 JPRS RACEドメイン + */ + public static java.lang.String toKanaFull(java.lang.String str) { + StringBuffer str2; + char kkv; + str2 = new StringBuffer(); + for (int i = 0; i < str.length(); i++) { + kkv = toKanaFull(str.charAt(i)); + // if (kkv == '゛') { + // kkv = str2.charAt(str2.length() - 1); + // kkv++; + // str2.deleteCharAt(str2.length() - 1); + // } else if (kkv == '゜') { + // kkv = str2.charAt(str2.length() - 1); + // kkv += 2; + // str2.deleteCharAt(str2.length() - 1); + // } + str2.append(kkv); + + } + + return str2.toString(); + } + + /** + * 日本語正規化 全角/半角カタカナをひらがなにする + */ + public static java.lang.String kanaUpper(java.lang.String str) { + StringBuffer str2; + str2 = new StringBuffer(); + char ch; + str = toKanaFull(str); + for (int i = 0; i < str.length(); i++) { + ch = str.charAt(i); + // idx = kana2.indexOf(ch); + if (ch >= 0x30A0 && ch <= 0x30FA) { + ch -= 0x60; + } + str2.append(ch); + } + return str2.toString(); + } + + /** + * ひらがなを全角カタカナにする + */ + public static java.lang.String kanaLower(java.lang.String str) { + StringBuffer str2; + // char[] str2; + str2 = new StringBuffer(); + char ch; + // str = kanaconv(str); + for (int i = 0; i < str.length(); i++) { + ch = str.charAt(i); + // idx = kana2.indexOf(ch); + if (ch >= 0x3040 && ch <= 0x309A) { + ch += 0x60; + } + str2.append(ch); + } + return str2.toString(); + } + + static final java.lang.String 全角記号 = "+−*/=|!?”#@$%&’`()[],.;:_<>^"; + + static final java.lang.String 半角記号 = "+-*/=|!?\"#@$%&'`()[],.;:_<>^"; + + /** + * 英数字列を半角文字に正規化する。 未完全版。 郵便番号、電話番号、日本語ドメイン等 + */ + public static java.lang.String toHalf(java.lang.String str) { + StringBuffer str2; + str2 = new StringBuffer(); + char ch; + int idx; + for (int i = 0; i < str.length(); i++) { + ch = str.charAt(i); + // if (ch >= 'a' && ch <= 'z') { + // ch += 'a' - 'a'; + // } else if (ch >= 'A' && ch <= 'Z') { + // ch += 'A' - 'A'; + // } else if (ch >= '0' && ch <= '9') { + // ch += '0' - '0'; + // } else if (ch == ' ') { + // ch = ' '; + // } else if ((idx = 全角記号.indexOf(ch)) >= 0) { + // ch = 半角記号.charAt(idx); + // } else if (ch == '¥') { // 判断は微妙 + // ch = '\\'; + // } + str2.append(ch); + } + return str2.toString(); + } + + public static String toZenkaku(String str) { + StringBuffer str2; + str2 = new StringBuffer(); + char ch; + int idx; + for (int i = 0; i < str.length(); i++) { + ch = str.charAt(i); + // if (ch >= 'a' && ch <= 'z') { + // ch += 'a' - 'a'; + // } else if (ch >= 'A' && ch <= 'Z') { + // ch += 'A' - 'A'; + // } else if (ch >= '0' && ch <= '9') { + // ch += '0' - '0'; + // } else if (ch == ' ') { + // ch = ' '; + // } else if ((idx = 半角記号.indexOf(ch)) >= 0) { + // ch = 全角記号.charAt(idx); + // } else if (ch == '¥') { // 判断は微妙 + // ch = '\\'; + // } + str2.append(ch); + } + return str2.toString(); + } + +} diff --git a/anchorgarden/src/main/java/jaist/css/covis/util/package-info.java b/anchorgarden/src/main/java/jaist/css/covis/util/package-info.java new file mode 100644 index 0000000..ec744f7 --- /dev/null +++ b/anchorgarden/src/main/java/jaist/css/covis/util/package-info.java @@ -0,0 +1,6 @@ +/** + * 日付,ファイル,2次元の領域計算,そのほかを扱うライブラリクラス群です. + * + */ + +package jaist.css.covis.util; \ No newline at end of file diff --git a/anchorgarden/src/main/java/mbs/security/Encrypter.java b/anchorgarden/src/main/java/mbs/security/Encrypter.java new file mode 100644 index 0000000..d40a3a5 --- /dev/null +++ b/anchorgarden/src/main/java/mbs/security/Encrypter.java @@ -0,0 +1,78 @@ +package mbs.security; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +/** + * ハッシュ値生成機能を提供 + * @auther Mahny + */ +public class Encrypter{ + + /** + * メッセージダイジェスト:MD5 + */ + public static final String ALG_MD5= "MD5"; + + /** + * メッセージダイジェスト:SHA-1 + */ + public static final String ALG_SHA1= "SHA-1"; + + /** + * メッセージダイジェスト:SHA-256 + */ + public static final String ALG_SHA256= "SHA-256"; + + /** + * メッセージダイジェスト:SHA-384 + */ + public static final String ALG_SHA384= "SHA-384"; + + /** + * メッセージダイジェスト:SHA-512 + */ + public static final String ALG_SHA512= "SHA-512"; + + /** + * ハッシュ値を返す + * @param org 計算元文字列 + * @param algorithm ハッシュアルゴリズム名(Encrypter.ALG_xxxで取得できる) + * @return ハッシュ値 + */ + public static String getHash(String org, String algorithm){ + // 引数・アルゴリズム指定が無い場合は計算しない + if ((org== null)||(algorithm== null)){ + return null; + } + + // 初期化 + MessageDigest md= null; + try{ + md= MessageDigest.getInstance(algorithm); + } + catch(NoSuchAlgorithmException e){ + return null; + } + + md.reset(); + md.update(org.getBytes()); + byte[] hash= md.digest(); + + // ハッシュを16進数文字列に変換 + StringBuffer sb= new StringBuffer(); + int cnt= hash.length; + for(int i= 0; i< cnt; i++){ + sb.append(Integer.toHexString( (hash[i]>> 4) & 0x0F ) ); + sb.append(Integer.toHexString( hash[i] & 0x0F ) ); + } + return sb.toString(); + } + public static void main(String[] args){ + + String value= "aaa"; + String hash= Encrypter.getHash(value, Encrypter.ALG_SHA1); + + System.out.println("出力結果:" + hash); + } +} diff --git a/anchorgarden/src/main/java/overview.html b/anchorgarden/src/main/java/overview.html new file mode 100644 index 0000000..1f579df --- /dev/null +++ b/anchorgarden/src/main/java/overview.html @@ -0,0 +1,3 @@ +Examples overview. +TODO: write a bit of an intro + diff --git a/anchorgarden/src/main/resources/org/piccolo2d/examples/texture.png b/anchorgarden/src/main/resources/org/piccolo2d/examples/texture.png new file mode 100755 index 0000000..611033f --- /dev/null +++ b/anchorgarden/src/main/resources/org/piccolo2d/examples/texture.png Binary files differ diff --git a/extras/.project b/extras/.project index a316e06..33e139f 100644 --- a/extras/.project +++ b/extras/.project @@ -26,4 +26,15 @@ org.eclipse.jdt.core.javanature org.maven.ide.eclipse.maven2Nature + + + 1649943579253 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/pom.xml b/pom.xml index df9ae49..fdf4e16 100644 --- a/pom.xml +++ b/pom.xml @@ -315,6 +315,7 @@ extras examples + anchorgarden