import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import javax.swing.*; // スプリングモデル (「マグネティック・スプリング・モデルによるグラフ描画法について 三末 和男・杉山 公造 (株)富士通研究所 情報社会科学研究所) class SpringModel { private Vector nodes = new Vector(); private Vector node_pos = new Vector(); private Vector node_fixed = new Vector(); private Vector edges = new Vector(); private Point scr = new Point(); private int length0 = 200; private int dragging_node = -1; private Point dragging_node_ofset = new Point(); private boolean dragging_node_fixed; private int popupmenu_node = -1; private boolean popupmenu_node_fixed; private Container parent; public SpringModel(int screen_w,int screen_h,Container parent){ this.parent = parent; scr.x = screen_w; scr.y = screen_h; } public SpringModel(int screen_w,int screen_h){ this(screen_w,screen_h,null); } public synchronized boolean save(String filename){ String[] strs = new String[edges.size()]; for(int cnt=0;cnt dv = new Vector(); for(int cnt=0;cntscr.x){ node_pos.get(cnt).x = scr.x-node_pos.get(cnt).width; } node_pos.get(cnt).y += dv.get(cnt).y; if(node_pos.get(cnt).y < 0){ node_pos.get(cnt).y = 0; }else if(node_pos.get(cnt).y+node_pos.get(cnt).height>scr.y){ node_pos.get(cnt).y = scr.y-node_pos.get(cnt).height; } } } } public boolean isConnected(String n1,String n2){ return isConnected(indexOf(n1),indexOf(n2)); } private int indexOf(int x,int y){ for(int cnt=node_pos.size()-1;cnt>=0;cnt--){ Rectangle rc = node_pos.get(cnt); if(rc.contains(mouseX,mouseY)){ return cnt; } } return -1; } private int indexOf(String nodeName){ for(int cnt=0;cnt= 0){ return 0; }else{ return Math.PI; } }else if(x == 0){ if(y >= 0){ return Math.PI/2; }else{ return 3*Math.PI/2; } } double rad = Math.acos(x/Math.sqrt(Math.pow(x,2)+Math.pow(y,2))); if(y<0){ rad = (2*Math.PI)-rad; } return rad; } public boolean addEdge(String fnode,String tnode){ return addEdge(fnode,tnode,true); } public boolean addEdge(String fnode,String tnode,boolean directed){ int findex = addNode(fnode); int tindex = addNode(tnode); for(int cnt=0;cnt "+dragging_node_fixed); node_fixed.set(dragging_node,dragging_node_fixed); dragging_node = -1; } } void mouseDragged() { if(dragging_node!=-1){ node_pos.get(dragging_node).setLocation(mouseX-dragging_node_ofset.x,mouseY-dragging_node_ofset.y); } } }