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.geom.Area;
006: import java.util.*;
007: import com.umlet.control.*;
008:
009: /**
010: * <p>Title: </p>
011: * <p>Description: </p>
012: * <p>Copyright: Copyright (c) 2001</p>
013: * <p>Company: </p>
014: * @author unascribed
015: * @version 1.0
016: */
017:
018: public class Package extends Entity {
019:
020: Area lastKnown = new Area();
021:
022: public Entity CloneFromMe() {
023: Package c = new Package();
024: c.setState(this .getPanelAttributes());
025: //c.setVisible(true);
026: c.setBounds(this .getBounds());
027: return c;
028: }
029:
030: public Package(String s) {
031: super (s);
032: }
033:
034: public Package() {
035: super ();
036: }
037:
038: private Vector<String> getStringVector() {
039: Vector<String> ret = Constants.decomposeStrings(this
040: .getPanelAttributes(), "\n");
041: return ret;
042: }
043:
044: public void paint(Graphics g) {
045: Graphics2D g2 = (Graphics2D) g;
046: g2.setFont(Constants.getFont());
047: Composite[] composites = colorize(g2); //enable colors
048: g2.setColor(_activeColor);
049: Constants.getFRC(g2);
050:
051: Vector<String> tmp = new Vector<String>(getStringVector()); // in order to make the addition of "--" possible
052: if (tmp.size() == 0)
053: tmp.add(" ");
054: if (!tmp.contains("--"))
055: tmp.add("--");
056:
057: int yPos = Constants.getDistLineToText();
058: boolean borders = false;
059: // G. Mueller start
060: boolean normal = false;
061: // int maxUpperBox=5*Constants.getFontsize();
062: int maxUpperBox = (int) (this .getWidth() * 0.4); // I think this looks better
063: int lines = 0;
064:
065: int yPosBorder = yPos;
066:
067: //LME: coloring (some code doubled)
068: for (int i = 0; i < tmp.size(); i++) {
069: String s = tmp.elementAt(i);
070: if (tmp.elementAt(0).equals("--") && borders == false)
071: yPosBorder = Constants.getDistLineToText()
072: + Constants.getDistTextToText()
073: + Constants.getFontsize(); // if there is no Packagename
074: if (s.equals("--") && borders == false) {
075: g2.setComposite(composites[1]);
076: g2.setColor(_fillColor);
077: g2.fillRect(0, 0, maxUpperBox, yPosBorder);
078: g2.fillRect(0, yPosBorder, this .getWidth() - 1, this
079: .getHeight()
080: - yPosBorder - 1);
081: g2.setComposite(composites[0]);
082: if (_selected)
083: g2.setColor(_activeColor);
084: else
085: g2.setColor(_deselectedColor);
086:
087: g2.drawRect(0, 0, maxUpperBox, yPosBorder);
088: g2.drawRect(0, yPosBorder, this .getWidth() - 1, this
089: .getHeight()
090: - yPosBorder - 1);
091: // yPos to write the String centered
092: yPosBorder = Constants.getFontsize()
093: / 2
094: + yPosBorder
095: / 2
096: + this .getHeight()
097: / 2
098: - (tmp.size() - lines)
099: * (Constants.getFontsize() + Constants
100: .getDistTextToText()) / 2;
101: } else if (!normal
102: && i > 1
103: && (tmp.elementAt(i - 1).equals("--") && tmp
104: .elementAt(i).startsWith("left:"))) {
105: yPosBorder = (lines + 1)
106: * (Constants.getFontsize() + Constants
107: .getDistTextToText()) / 2
108: + Constants.getDistTextToText()
109: + Constants.getFontsize()
110: + Constants.getDistTextToText();
111: } else if (!borders) {
112: maxUpperBox = Math.max(maxUpperBox, Constants
113: .getPixelWidth(g2, s)
114: + Constants.getFontsize());
115: yPosBorder += Constants.getFontsize()
116: + Constants.getDistTextToText();
117: } else if (normal) {
118: yPosBorder += Constants.getFontsize()
119: + Constants.getDistTextToText();
120: } else if (!normal) {
121: yPosBorder += Constants.getFontsize()
122: + Constants.getDistTextToText();
123: }
124: }
125:
126: for (int i = 0; i < tmp.size(); i++) {
127: String s = tmp.elementAt(i);
128:
129: if (tmp.elementAt(0).equals("--") && borders == false)
130: yPos = Constants.getDistLineToText()
131: + Constants.getDistTextToText()
132: + Constants.getFontsize(); // if there is no Packagename
133:
134: if (s.equals("--") && borders == false) {
135: borders = true;
136: // g2.drawRect(0,0,maxUpperBox,yPos);
137: // g2.drawRect(0,yPos,this.getWidth()-1,this.getHeight()-yPos-1);
138: // yPos to write the String centered
139: yPos = Constants.getFontsize()
140: / 2
141: + yPos
142: / 2
143: + this .getHeight()
144: / 2
145: - (tmp.size() - lines)
146: * (Constants.getFontsize() + Constants
147: .getDistTextToText()) / 2;
148: } else if (!normal
149: && i > 1
150: && (tmp.elementAt(i - 1).equals("--") && tmp
151: .elementAt(i).startsWith("left:"))) {
152: // writes the string normal
153: yPos = (lines + 1)
154: * (Constants.getFontsize() + Constants
155: .getDistTextToText()) / 2;
156: yPos += Constants.getDistTextToText();
157: yPos += Constants.getFontsize();
158: Constants.write(g2, s.substring(5), Constants
159: .getFontsize() / 2, yPos, false);
160: yPos += Constants.getDistTextToText();
161: normal = true;
162: } else if (!borders) {
163:
164: lines++;
165: maxUpperBox = Math.max(maxUpperBox, Constants
166: .getPixelWidth(g2, s)
167: + Constants.getFontsize());
168: yPos += Constants.getFontsize();
169: Constants.write(g2, s, Constants.getFontsize() / 2,
170: yPos, false);
171: yPos += Constants.getDistTextToText();
172:
173: } else if (normal) {
174:
175: yPos += Constants.getFontsize();
176: Constants.write(g2, s, Constants.getFontsize() / 2,
177: yPos, false);
178: yPos += Constants.getDistTextToText();
179:
180: } else if (!normal) {
181:
182: yPos += Constants.getFontsize();
183: Constants.write(g2, s, (int) this .getWidth() / 2, yPos,
184: true);
185: yPos += Constants.getDistTextToText();
186:
187: }
188: // G. Mueller End
189: }
190:
191: /*Rectangle r=this.getBounds();
192: g.drawRect(0,0,(int)r.getWidth()-1,(int)r.getHeight()-1);
193: if (_selected) {
194: g.drawRect(1,1,(int)r.getWidth()-3,(int)r.getHeight()-3);
195: }*/
196: }
197:
198: public StickingPolygon getStickingBorder() { //LME
199: StickingPolygon p = new StickingPolygon();
200: Vector<String> tmp = new Vector<String>(getStringVector());
201: if (tmp.size() == 0)
202: tmp.add(" ");
203: int yPos = Constants.getDistLineToText();
204: boolean borders = false;
205: //int maxUpperBox=5*Constants.getFontsize();
206: int maxUpperBox = (int) (this .getWidth() * 0.4);
207: for (int i = 0; i < tmp.size(); i++) {
208: String s = tmp.elementAt(i);
209: // G. Mueller start
210: if (tmp.elementAt(0).equals("--") && borders == false)
211: yPos = Constants.getDistLineToText()
212: + Constants.getDistTextToText()
213: + Constants.getFontsize(); // if there is no Packagename
214: // G.Mueller End
215: if (s.equals("--") && borders == false)
216: borders = true;
217: else if (!borders) {
218: maxUpperBox = Math.max(maxUpperBox, Constants
219: .getPixelWidth((Graphics2D) this .getGraphics(),
220: s)
221: + Constants.getFontsize());
222: yPos += Constants.getFontsize()
223: + Constants.getDistTextToText();
224: }
225: }
226: p.addLine(new Point(0, 0), new Point(maxUpperBox, 0),
227: Constants.RESIZE_TOP);
228: p.addLine(new Point(maxUpperBox, yPos), new Point(
229: getWidth() - 1, yPos), Constants.RESIZE_TOP);
230: p.addLine(new Point(maxUpperBox, 0), new Point(maxUpperBox,
231: yPos), Constants.RESIZE_TOP | Constants.RESIZE_LEFT);
232: p.addLine(new Point(getWidth() - 1, yPos), new Point(
233: getWidth() - 1, getHeight() - 1),
234: Constants.RESIZE_RIGHT);
235: p.addLine(new Point(getWidth() - 1, getHeight() - 1),
236: new Point(0, getHeight() - 1), Constants.RESIZE_BOTTOM);
237: p.addLine(new Point(0, getHeight() - 1), new Point(0, 0),
238: Constants.RESIZE_LEFT);
239: return p;
240: }
241: }
|