// File: ConstClass.java // Classes: ConstClass // Original Author : Kedar Patankar - Alberto Medina // Date 21 Jan 1997 package uci.graphedit; import java.awt.Graphics; import java.awt.FontMetrics; import java.awt.Color; import java.awt.Point; /** An example subclass of NetNode for use in the Example application. * * @see Example */ public class ConstClass extends NetNode { private Document _document; /** Initialize a new ConstClass from the given default node and * application specific model.

* * Needs-More-Work: for now we construct the Perspective * programatically, but eventually we will store it in a class * variable and just refer to it, or copy it(?). That way the user * can edit the Perspective(s) stored in the class variable and * have those changes shown for all existing nodes, or for all * future nodes. Maybe I should think about doing virtual copies? *

*/ public void initialize(NetNode deft, String name,Document d,Point click) { _document = d; uid=_document.nextId(); buildPerspective(click.x,click.y,name); } public void initialize(VertexInfo vertexinfo,Document d,int id) { int x = vertexinfo.get_position().x; int y = vertexinfo.get_position().y; String name = vertexinfo.get_name(); _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()); int maxnooflines, nooflines, letterHeight,stringWidth; FontMetrics fm =g.getFontMetrics(); stringWidth = fm.stringWidth(name); letterHeight = fm.getHeight(); while(true) { maxnooflines=(height-2)/letterHeight; nooflines=(stringWidth/(width-4)) + 1; if (nooflines>maxnooflines) { width = (int)(1.05 * (double)width); height =(int)(1.1 * (double)height); } else break; } Integer x2 = new Integer(width); Integer y2 = new Integer(height); Color fill = (Color)_document.getGraphicAttribute("FillColor"); Color border = (Color)_document.getGraphicAttribute("LineColor"); Integer x1=new Integer(x); Integer y1=new Integer(y); Fig obj1 = new FigConstVert(x1, y1, x2, y2, border, fill, name); Perspective pers1 = new Perspective(this, obj1); pers1.position(x,y); set_Perspective(pers1); } } /* end class ConstClass */