package simple_uml.view.canvas; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.Rectangle; import java.awt.geom.Rectangle2D; import java.util.Vector; /** * Displays a list of strings, line by line. Line wrapping is not currently * supported. * * @author Eric Liebowitz * @version 02jul11 */ public class TextList extends SumlShape { /** * List of strings to be drawn */ private Vector atts; /** * Creates an object to display a given list of strings. The list will be * rendered at the default origin SumlShape.BASE_ORIGIN. * * @param atts List of strings to be displayed. */ public TextList (Vector atts) { this.atts = atts; } /** * Draws our list of text, rendered relative to the SumlShape.BASE_ORIGIN * point. * * @param g2d The Graphics2D object used to draw everything. */ public void draw (Graphics2D g2d)/*==>*/ { FontMetrics fm = g2d.getFontMetrics(); int width = 0; int height = (int)fm.getHeight(); int textX = (int)origin.getX(); int textY = (int)origin.getY(); for (String att: atts) { Text t = new Text(att, textX, textY); t.paint(g2d); /* * Have to remember our maximum width */ int temp = (int)t.getWidth(); width = (temp > width) ? temp : width; textY += height; } this.bounds = new Rectangle(width, height * atts.size()); }/*<==*/ }