lib/browser/GraphBrowser/GraphView.java
changeset 11872 4f24fd4dbcf5
parent 11811 38721b2c6f57
child 14981 e73f8140af78
equal deleted inserted replaced
11871:0493188cff42 11872:4f24fd4dbcf5
    26 	TreeBrowser tb;
    26 	TreeBrowser tb;
    27 	long timestamp;
    27 	long timestamp;
    28 	Vertex highlighted = null;
    28 	Vertex highlighted = null;
    29 	Dimension size;
    29 	Dimension size;
    30 	boolean parent_needs_layout;
    30 	boolean parent_needs_layout;
       
    31 	Font font;
    31 
    32 
    32 	public void setTreeBrowser(TreeBrowser br) {
    33 	public void setTreeBrowser(TreeBrowser br) {
    33 		tb=br;
    34 		tb=br;
    34 	}
    35 	}
    35 
    36 
    37 
    38 
    38 	public Graph getGraph() { return gra; }
    39 	public Graph getGraph() { return gra; }
    39 
    40 
    40 	public Graph getOriginalGraph() { return gra2; }
    41 	public Graph getOriginalGraph() { return gra2; }
    41 
    42 
    42 	public GraphView(Graph gr,GraphBrowser br) {
    43 	public GraphView(Graph gr, GraphBrowser br, Font f) {
    43 		gra2=gr;
    44 		gra2=gr;
    44 		browser=br;
    45 		browser=br;
    45 		gra=(Graph)(gra2.clone());
    46 		gra=(Graph)(gra2.clone());
    46 		parent_needs_layout = true;
    47 		parent_needs_layout = true;
    47 		size = new Dimension(0, 0);
    48 		size = new Dimension(0, 0);
       
    49 		font = f;
    48 		addMouseListener(this);
    50 		addMouseListener(this);
    49 		addMouseMotionListener(this);
    51 		addMouseMotionListener(this);
    50 	}
    52 	}
    51 
    53 
    52 	public void PS(String fname,boolean printable) throws IOException {
    54 	public void PS(String fname,boolean printable) throws IOException {
    54 	    gra3.layout(null);
    56 	    gra3.layout(null);
    55 	    gra3.PS(fname,printable);
    57 	    gra3.PS(fname,printable);
    56 	}
    58 	}
    57 
    59 
    58 	public void paint(Graphics g) {
    60 	public void paint(Graphics g) {
       
    61 		g.setFont(font);
    59 		gra.draw(g);
    62 		gra.draw(g);
    60 		if (highlighted!=null) highlighted.drawBox(g,Color.white);
    63 		if (highlighted!=null) highlighted.drawBox(g,Color.white);
    61 		size = new Dimension(gra.max_x-gra.min_x, gra.max_y-gra.min_y);
    64 		size = new Dimension(gra.max_x-gra.min_x, gra.max_y-gra.min_y);
    62 		if (parent_needs_layout) {
    65 		if (parent_needs_layout) {
    63 			parent_needs_layout = false;
    66 			parent_needs_layout = false;
    73 		int x = evt.getX() + gra.min_x;
    76 		int x = evt.getX() + gra.min_x;
    74 		int y = evt.getY() + gra.min_y;
    77 		int y = evt.getY() + gra.min_y;
    75 
    78 
    76 		Vertex v2=gra.vertexAt(x,y);
    79 		Vertex v2=gra.vertexAt(x,y);
    77 		Graphics g=getGraphics();
    80 		Graphics g=getGraphics();
       
    81 		g.setFont(font);
    78 		g.translate(-gra.min_x,-gra.min_y);
    82 		g.translate(-gra.min_x,-gra.min_y);
    79 		if (highlighted!=null) {
    83 		if (highlighted!=null) {
    80 			highlighted.drawBox(g,Color.lightGray);
    84 			highlighted.drawBox(g,Color.lightGray);
    81 			highlighted=null;
    85 			highlighted=null;
    82 		}
    86 		}
   138 		collapseNodes();
   142 		collapseNodes();
   139 		relayout();
   143 		relayout();
   140 	}
   144 	}
   141 
   145 
   142 	public void relayout() {
   146 	public void relayout() {
       
   147 		Graphics g = getGraphics();
       
   148 		g.setFont(font);
   143 		browser.showWaitMessage();
   149 		browser.showWaitMessage();
   144 		highlighted=null;
   150 		highlighted=null;
   145 		gra.layout(getGraphics());
   151 		gra.layout(g);
   146 		v=null;
   152 		v=null;
   147 		parent_needs_layout = true;
   153 		parent_needs_layout = true;
   148 		update(getGraphics());
   154 		update(g);
   149 		browser.showReadyMessage();
   155 		browser.showReadyMessage();
   150 	}
   156 	}
   151 
   157 
   152 	public void focusToVertex(int n) {
   158 	public void focusToVertex(int n) {
   153 		Vertex vx=gra.getVertexByNum(n);
   159 		Vertex vx=gra.getVertexByNum(n);
   161 				Math.max(0,x-vpsize.width/2));
   167 				Math.max(0,x-vpsize.width/2));
   162 			int offset_y = Math.min(scrollp.getVAdjustable().getMaximum(),
   168 			int offset_y = Math.min(scrollp.getVAdjustable().getMaximum(),
   163 				Math.max(0,y-vpsize.height/2));
   169 				Math.max(0,y-vpsize.height/2));
   164 
   170 
   165 			Graphics g=getGraphics();
   171 			Graphics g=getGraphics();
       
   172 			g.setFont(font);
   166 			g.translate(-gra.min_x,-gra.min_y);
   173 			g.translate(-gra.min_x,-gra.min_y);
   167 			if (highlighted!=null) highlighted.drawBox(g,Color.lightGray);
   174 			if (highlighted!=null) highlighted.drawBox(g,Color.lightGray);
   168 			vx.drawBox(g,Color.white);
   175 			vx.drawBox(g,Color.white);
   169 			highlighted=vx;
   176 			highlighted=vx;
   170 			scrollp.setScrollPosition(offset_x, offset_y);
   177 			scrollp.setScrollPosition(offset_x, offset_y);
   251 		}
   258 		}
   252 	}
   259 	}
   253 
   260 
   254 	public void mouseExited(MouseEvent evt) {
   261 	public void mouseExited(MouseEvent evt) {
   255 		Graphics g=getGraphics();
   262 		Graphics g=getGraphics();
       
   263 		g.setFont(font);
   256 		g.translate(-gra.min_x,-gra.min_y);
   264 		g.translate(-gra.min_x,-gra.min_y);
   257 		if (highlighted!=null) {
   265 		if (highlighted!=null) {
   258 			highlighted.drawBox(g,Color.lightGray);
   266 			highlighted.drawBox(g,Color.lightGray);
   259 			highlighted=null;
   267 			highlighted=null;
   260 		}
   268 		}