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 Interface extends Entity {
021: public Entity CloneFromMe() {
022: Interface ret = new Interface();
023: ret.setState(this .getPanelAttributes());
024:
025: ret.setBounds(this .getBounds());
026:
027: int i = ret.getWidth() + Umlet.getInstance().getMainUnit() - 1;
028: i = i / Umlet.getInstance().getMainUnit();
029: ret.setBounds(new Rectangle(i, ret.getHeight()));
030:
031: return ret;
032: }
033:
034: public Interface(String s) {
035: super (s);
036: }
037:
038: public Interface() {
039: super ();
040: }
041:
042: private Vector getStringVector() {
043: Vector ret = Constants.decomposeStrings(this
044: .getPanelAttributes(), "\n");
045: return ret;
046: }
047:
048: public void paint(Graphics g) {
049: Graphics2D g2 = (Graphics2D) g;
050: g2.setFont(Constants.getFont());
051: Composite[] composites = colorize(g2); //enable colors
052: g2.setColor(_activeColor);
053:
054: Constants.getFRC(g2);
055:
056: /*FontRenderContext rendering;
057: if (Constants.getFontsize()>12) {
058: rendering=new FontRenderContext(null, true, true);
059: g2.setRenderingHints(Constants.UxRenderingQualityHigh());
060: }
061: else {
062: rendering=new FontRenderContext(null, false, false);
063: g2.setRenderingHints(Constants.UxRenderingQualityLow());
064: }*/
065:
066: boolean ADAPT_SIZE = false;
067:
068: Vector tmp = getStringVector();
069: int yPos = 0;
070: yPos += 2 * Umlet.getInstance().getMainUnit();
071: yPos += Constants.getDistLineToText();
072:
073: for (int i = 0; i < tmp.size(); i++) {
074: String s = (String) tmp.elementAt(i);
075: if (s.equals("--")) {
076: yPos += Constants.getDistTextToLine();
077: g2.drawLine(this .getWidth() / 2
078: - Constants.getFontsize() * 4, yPos, this
079: .getWidth()
080: / 2 + Constants.getFontsize() * 4, yPos);
081: yPos += Constants.getDistLineToText();
082: } else {
083: yPos += Constants.getFontsize();
084: TextLayout l = new TextLayout(s, Constants.getFont(),
085: Constants.getFRC(g2));
086: Rectangle2D r2d = l.getBounds();
087: int width = (int) r2d.getWidth();
088: int xPos = this .getWidth() / 2 - width / 2;
089: if (xPos < 0) {
090: ADAPT_SIZE = true;
091: break;
092: }
093: Constants.write(g2, s, this .getWidth() / 2, yPos, true);
094: yPos += Constants.getDistTextToText();
095: }
096: }
097:
098: if (ADAPT_SIZE) {
099: Controller.getInstance().executeCommandWithoutUndo(
100: new Resize(this , 8, -Umlet.getInstance()
101: .getMainUnit(), 0));
102: Controller.getInstance().executeCommandWithoutUndo(
103: new Resize(this , 2, Umlet.getInstance()
104: .getMainUnit(), 0));
105: return;
106: }
107: if (yPos > this .getHeight()) {
108: Controller.getInstance().executeCommandWithoutUndo(
109: new Resize(this , 4, 0, 20));
110: return;
111: }
112:
113: g2.setComposite(composites[1]);
114: g2.setColor(_fillColor);
115: g.fillOval(this .getWidth() / 2
116: - Umlet.getInstance().getMainUnit(), 0, 2 * Umlet
117: .getInstance().getMainUnit(), 2 * Umlet.getInstance()
118: .getMainUnit());
119: g2.setComposite(composites[0]);
120: if (_selected)
121: g2.setColor(_activeColor);
122: else
123: g2.setColor(_deselectedColor);
124:
125: g.drawOval(this .getWidth() / 2
126: - Umlet.getInstance().getMainUnit(), 0, 2 * Umlet
127: .getInstance().getMainUnit(), 2 * Umlet.getInstance()
128: .getMainUnit());
129: /*if (_selected) {
130: g.drawOval(this.getWidth()/2-Constants.getFontsize()+1, 1, 2*Constants.getFontsize()-2, 2*Constants.getFontsize()-2);
131: }*/
132: }
133:
134: /* public int doesCoordinateAppearToBeConnectedToMe(Point p) {
135: int tmpX=p.x-this.getX();
136: int tmpY=p.y-this.getY();
137:
138: int links=this.getWidth()/2-Umlet.getInstance().getMainUnit();
139: int rechts=this.getWidth()/2+Umlet.getInstance().getMainUnit();
140:
141: int oben=0;
142: int unten=2*Umlet.getInstance().getMainUnit();
143:
144: if (tmpX>links-4 && tmpX<rechts+4) {
145: if ((tmpY>oben-4 && tmpY<oben+4) || (tmpY>unten-4 && tmpY<unten+4)) return 15;
146: }
147: if (tmpY>oben-4 && tmpY<unten+4) {
148: if ((tmpX>links-4 && tmpX<links+4) || (tmpX>rechts-4 && tmpX<rechts+4)) return 15;
149: }
150:
151: return 0;
152: }*/
153:
154: public StickingPolygon getStickingBorder() { //LME
155: int links = this .getWidth() / 2
156: - Umlet.getInstance().getMainUnit();
157: int rechts = this .getWidth() / 2
158: + Umlet.getInstance().getMainUnit();
159: int oben = 0;
160: int unten = 2 * Umlet.getInstance().getMainUnit();
161: StickingPolygon p = new StickingPolygon();
162: p.addLine(new Point(links, oben), new Point(rechts, oben),
163: Constants.RESIZE_TOP);
164: p.addLine(new Point(rechts, oben), new Point(rechts, unten),
165: Constants.RESIZE_TOP);
166: p.addLine(new Point(rechts, unten), new Point(links, unten),
167: Constants.RESIZE_TOP);
168: p.addLine(new Point(links, unten), new Point(links, oben),
169: Constants.RESIZE_TOP);
170: return p;
171: }
172:
173: public int getPossibleResizeDirections() {
174: return 0;
175: } //deny size changes
176: }
|