// File: AltClass.java // Classes: AltClass // Original Authors: Kedar Patankar // Date 21 Jan 1997 package uci.graphedit; import java.awt.Graphics; import java.awt.FontMetrics; import java.awt.Color; import java.awt.Point; public class AltClass extends NetNode { private Document _document; public void initialize(NetNode deft, String labelname,Document d,Point click) { _document = d; uid=_document.nextId(); buildPerspective(click.x,click.y,labelname); } public void initialize(VertexInfo vertexinfo,Document d,int id) { String name = vertexinfo.get_name(); int x = vertexinfo.get_position().x; int y = vertexinfo.get_position().y; _document =d; uid=id; buildPerspective(x,y,name); } public void buildPerspective(int x,int y,String name) { int width,height; width=_document.vertexSize().x; height=_document.vertexSize().y; Graphics g = _document.getGraphics(); g.setFont(_document.getFont()); FontMetrics fm =g.getFontMetrics(); if((width-4)>")) width=fm.stringWidth("<>")+4; int maxnooflines, nooflines, letterHeight,stringWidth; stringWidth = fm.stringWidth(name); letterHeight = fm.getHeight(); while(true) { maxnooflines=(height-2)/letterHeight; nooflines=(stringWidth/(width-4)) + 2; if (nooflines>maxnooflines) { width = (int)(1.05 * (double)width); height =(int)(1.1 * (double)height); } else break; } Integer x1 = new Integer(x); Integer y1 = new Integer(y); Integer x2 = new Integer(width); Integer y2 = new Integer(height); Color fill = (Color)_document.getGraphicAttribute("FillColor"); Color border = (Color)_document.getGraphicAttribute("LineColor"); Fig obj1 = new FigAltVert(x1, y1, x2, y2, border,fill, name); Perspective pers1 = new Perspective(this, obj1); pers1.position(x,y); set_Perspective(pers1); } } /* end class AltClass */