// Copyright (c) 1996-98 The Regents of the University of California. All // Rights Reserved. Permission to use, copy, modify, and distribute this // software and its documentation for educational, research and non-profit // purposes, without fee, and without a written agreement is hereby granted, // provided that the above copyright notice and this paragraph appear in all // copies. Permission to incorporate this software into commercial products may // be obtained by contacting the University of California. David F. Redmiles // Department of Information and Computer Science (ICS) University of // California Irvine, California 92697-3425 Phone: 714-824-3823. This software // program and documentation are copyrighted by The Regents of the University // of California. The software program and documentation are supplied "as is", // without any accompanying services from The Regents. The Regents do not // warrant that the operation of the program will be uninterrupted or // error-free. The end-user understands that the program was developed for // research purposes and is advised not to rely exclusively on the program for // any reason. IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY // PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, // INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS // DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY // DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE // SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, // ENHANCEMENTS, OR MODIFICATIONS. // File: FigRRect.java // Classes: FigRRect // Original Author: ics125b spring 1996 // $Id: FigRRect.java,v 1.10 1997/06/10 23:42:45 jrobbins Exp $ package uci.graphedit; import java.applet.*; import java.awt.*; import java.io.*; import java.util.*; import uci.util.*; import uci.ui.*; /** Primitive Fig to draw rounded rectangles on a LayerDiagram. * * FEATURE: basic_shapes_rounded_rect */ public class FigRRect extends FigRect { //////////////////////////////////////////////////////////////// // instance variables protected int _radius = 16; //////////////////////////////////////////////////////////////// // constructors public FigRRect(int x, int y, int w, int h, Color line, int r) { super(x, y, w, h, line); } /** Construct a new FigRRect w/ the given position, size, and attributes */ public FigRRect(int x, int y, int w, int h, Hashtable gAttrs) { super(x, y, w, h, gAttrs); } /** Construct a new FigRRect w/ the given position, size, line color, * and fill color*/ public FigRRect(int x, int y, int w, int h, Color line, Color fill) { super(x, y, w, h, line, fill); } //////////////////////////////////////////////////////////////// // accessors public void radius(int r) { _radius = r; } public int radius() { return _radius; } public void setCornerRadius(int r) { _radius = r; } public int getCornerRadius() { return _radius; } public Object get(String key) { if (key.equals(pCORNER_RADIUS)) return new Integer(getCornerRadius()); else return super.get(key); } public boolean put(String key, Object value) { if (key.equals(pCORNER_RADIUS)) setCornerRadius(((Integer)value).intValue()); else return super.put(key, value); return true; } public static Vector _GeometryPropName = null; public Enumeration keysIn(String category) { if (_GeometryPropName == null) { _GeometryPropName = new Vector(); _GeometryPropName.addElement(pCORNER_RADIUS); } Enumeration geomEnum = _GeometryPropName.elements(); if (category.equals("Geometry")) return new EnumerationComposite(super.keysIn(category), geomEnum); else return super.keysIn(category); } public boolean canPut(String key) { return key.equals(pCORNER_RADIUS) || super.canPut(key); } //////////////////////////////////////////////////////////////// /// drawing methods /** Draw this FigRRect */ public void draw(Graphics g) { int rx = position().x; int ry = position().y; int new_x, new_y, new_w, new_h; int r = radius(); /* Compensate for negative width and height (for drag) */ if (objectWidth > 0) { new_x = rx; new_w = objectWidth; } else { new_x = rx + objectWidth; new_w = -objectWidth; } if (objectHeight > 0) { new_y = ry; new_h = objectHeight; } else { new_y = ry + objectHeight; new_h = -objectHeight; } if (filled) { g.setColor(objectFillColor); g.fillRoundRect(new_x, new_y, new_w, new_h, r, r); } if (lineWidth > 0) { g.setColor(objectLineColor); g.drawRoundRect(new_x, new_y, new_w - lineWidth, new_h - lineWidth, r, r); } } } /* end class FigRRect */