001: // The UMLet source code is distributed under the terms of the GPL; see license.txt
002: package com.umlet.element.base;
003:
004: import java.awt.*;
005: import java.awt.font.*;
006: import java.awt.geom.*;
007: import java.util.*;
008:
009: import com.umlet.control.*;
010:
011: /**
012: * <p>Title: </p>
013: * <p>Description: </p>
014: * <p>Copyright: Copyright (c) 2001</p>
015: * <p>Company: </p>
016: * @author unascribed
017: * @version 1.0
018: */
019:
020: public class Actor extends Entity {
021:
022: public Actor(String s) {
023: super (s);
024: }
025:
026: public Actor() {
027: super ();
028: }
029:
030: private Vector<String> getStringVector() {
031: Vector<String> ret = Constants.decomposeStrings(this
032: .getPanelAttributes(), "\n");
033: return ret;
034: }
035:
036: public void paint(Graphics g) {
037: Graphics2D g2 = (Graphics2D) g;
038: g2.setFont(Constants.getFont());
039: Composite[] composites = colorize(g2);
040: g2.setColor(_activeColor);
041: Constants.getFRC(g2);
042:
043: boolean ADAPT_SIZE = false;
044:
045: Vector<String> tmp = getStringVector();
046: int yPos = 6 * Constants.getFontsize();
047:
048: for (int i = 0; i < tmp.size(); i++) {
049: String s = tmp.elementAt(i);
050: if (s.equals("--")) {
051: yPos += Constants.getDistTextToLine();
052: g2.drawLine(this .getWidth() / 2
053: - Constants.getFontsize() * 4, yPos, this
054: .getWidth()
055: / 2 + Constants.getFontsize() * 4, yPos);
056: yPos += Constants.getDistLineToText();
057: } else {
058: yPos += Constants.getFontsize();
059: TextLayout l = new TextLayout(s, Constants.getFont(),
060: Constants.getFRC(g2));
061: Rectangle2D r2d = l.getBounds();
062: int width = (int) r2d.getWidth();
063: int xPos = this .getWidth() / 2 - width / 2;
064: if (xPos < 0) {
065: ADAPT_SIZE = true;
066: break;
067: }
068: Constants.write(g2, s, this .getWidth() / 2, yPos, true);
069: yPos += Constants.getDistTextToText();
070: }
071: }
072:
073: if (ADAPT_SIZE) {
074: Controller.getInstance().executeCommandWithoutUndo(
075: new Resize(this , 8, -Umlet.getInstance()
076: .getMainUnit(), 0));
077: Controller.getInstance().executeCommandWithoutUndo(
078: new Resize(this , 2, Umlet.getInstance()
079: .getMainUnit(), 0));
080: return;
081: }
082: if (yPos > this .getHeight()) {
083: Controller.getInstance().executeCommandWithoutUndo(
084: new Resize(this , 4, 0, 20));
085: return;
086: }
087:
088: int startx = this .getWidth() / 2;
089:
090: g2.setComposite(composites[1]);
091: g2.setColor(_fillColor);
092: g2.fillOval(startx - Constants.getFontsize() / 2, 0, Constants
093: .getFontsize(), Constants.getFontsize());
094: g2.setComposite(composites[0]);
095: if (_selected)
096: g2.setColor(_activeColor);
097: else
098: g2.setColor(_deselectedColor);
099:
100: g2.drawOval(startx - Constants.getFontsize() / 2, 0, Constants
101: .getFontsize(), Constants.getFontsize());
102: g2.drawLine(startx, Constants.getFontsize(), startx,
103: (int) (Constants.getFontsize() * 2.5));
104: g2.drawLine(startx - 2 * Constants.getFontsize(),
105: (int) (Constants.getFontsize() * 1.3), startx + 2
106: * Constants.getFontsize(), (int) (Constants
107: .getFontsize() * 1.3));
108:
109: // Feet
110: g2.drawLine(startx, (int) (Constants.getFontsize() * 2.5),
111: startx - Constants.getFontsize(), Constants
112: .getFontsize() * 5);
113: g2.drawLine(startx, (int) (Constants.getFontsize() * 2.5),
114: startx + Constants.getFontsize(), Constants
115: .getFontsize() * 5);
116: }
117:
118: /*public int doesCoordinateAppearToBeConnectedToMe(Point p) {
119: int tmpX=p.x-this.getX();
120: int tmpY=p.y-this.getY();
121:
122: int links=this.getWidth()/2-Umlet.getInstance().getMainUnit();
123: int rechts=this.getWidth()/2+Umlet.getInstance().getMainUnit();
124:
125: int oben=0;
126: int unten=4*Umlet.getInstance().getMainUnit();
127:
128: if (tmpX>links-4 && tmpX<rechts+4) {
129: if (tmpY>oben-4 && tmpY<unten+4) return 15;
130: }
131: if (tmpY>oben-4 && tmpY<unten+4) {
132: if (tmpX>links-4 && tmpX<rechts+4) return 15;
133: }
134:
135: return 0;
136: }*/
137:
138: public StickingPolygon getStickingBorder() { //LME
139: int links = this .getWidth() / 2
140: - Umlet.getInstance().getMainUnit();
141: int rechts = this .getWidth() / 2
142: + Umlet.getInstance().getMainUnit();
143: int oben = 0;
144: int unten = 4 * Umlet.getInstance().getMainUnit();
145: StickingPolygon p = new StickingPolygon();
146: p.addLine(new Point(links, oben), new Point(rechts, oben),
147: Constants.RESIZE_TOP);
148: p.addLine(new Point(rechts, oben), new Point(rechts, unten),
149: Constants.RESIZE_TOP);
150: p.addLine(new Point(rechts, unten), new Point(links, unten),
151: Constants.RESIZE_TOP);
152: p.addLine(new Point(links, unten), new Point(links, oben),
153: Constants.RESIZE_TOP);
154: return p;
155: }
156:
157: public int getPossibleResizeDirections() {
158: return 0;
159: } //deny size changes
160:
161: }
|