// File: FigConstVert.java // Classes: FigConstVert // Original Author:Kedar Patankar - Alberto Medina // $Id: FigConstVert.java,v 1.1.1.1 1997/02/27 20:52:40 chandra Exp $ package uci.graphedit; import java.awt.Color; import java.awt.Graphics; import java.awt.FontMetrics; import java.awt.Rectangle; import java.awt.Point; import java.util.Hashtable; /** Primitive Fig to draw rectangles on a LayerDiagram */ public class FigConstVert extends Fig { /* Label associated with the Construction Class */ private String _label; /* number of handles on the boundary rectangle */ public static final int numHandles = 8; /** Construct a new ConstVert w/ the given position, size, and line color */ public FigConstVert(Integer x, Integer y, Integer r_width, Integer r_height, Color r_color, Color f_color, String label){ super(x.intValue(), y.intValue(), r_width.intValue(), r_height.intValue(), r_color, f_color, numHandles); _label = label; } /** Construct a new ConstVert w/ the given position, size, and attributes */ public FigConstVert(int x, int y, int r_width, int r_height, Hashtable gAttrs){ super(x, y, r_width, r_height, Color.black, null, numHandles); setGraphicAttributes(gAttrs); } /** Construct a new FigRect w/ the given position, size, line color, * and fill color*/ public FigConstVert(int x, int y, int r_width, int r_height, Color r_color, Color f_color) { super(x, y, r_width, r_height, r_color, f_color, numHandles); } /** Reply the vertex name */ public String get_label() { return _label; } /** Set the vertex name */ public void set_label(String name,Document d) { int width,height; width=d.vertexSize().x; height=d.vertexSize().y; Graphics g = d.getGraphics(); g.setFont(d.getFont()); FontMetrics fm =g.getFontMetrics(); int maxnooflines, nooflines, letterHeight,stringWidth; 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; } _label=name; objectWidth=width; objectHeight=height; } /** Draw this ConstVert */ public void draw(Graphics g) { int x = position().x; int y = position().y; int width=objectWidth-2; int height=objectHeight-2; if (objectFillColor != null) { g.setColor(objectFillColor); g.fillRect(x,y,width,height); } g.setColor(objectLineColor); g.drawRect(x,y,width,height); FontMetrics fm =g.getFontMetrics(g.getFont()); int stringx = x + 2; int stringy = y + 2; int letterheight = fm.getHeight(); int label_length=_label.length(); for (int i=0,k=0;i