01: package com.umlet.element.custom;
02:
03: import java.awt.*;
04: import java.util.*;
05: import com.umlet.control.*;
06: import com.umlet.element.base.Entity;
07:
08: public class Database extends com.umlet.element.base.Entity {
09:
10: // Change this method if you want to edit the graphical
11: // representation of your custom element.
12: public void paint(Graphics g) {
13:
14: // Some unimportant initialization stuff; setting color, font
15: // quality, etc. You should not have to change this.
16: Graphics2D g2 = (Graphics2D) g;
17: g2.setFont(Constants.getFont());
18: g2.setColor(_activeColor);
19: Constants.getFRC(g2);
20:
21: int inset = Constants.getFontsize();
22:
23: // It's getting interesting here:
24: // First, the strings you type in the element editor are read and
25: // split into lines.
26: // Then, by default, they are printed out on the element, aligned
27: // to the left.
28: // Change this to modify this default text printing and to react
29: // to special strings
30: // (like the "--" string in the UML class elements which draw a line).
31: Vector tmp = Constants.decomposeStrings(this
32: .getPanelAttributes(), "\n");
33: int yPos = inset + Constants.getDistLineToText();
34: boolean CENTER = true;
35: for (int i = 0; i < tmp.size(); i++) {
36: String s = (String) tmp.elementAt(i);
37: if (s.equals("--")) {
38: CENTER = false;
39: g2.drawLine(0, yPos, this .getWidth(), yPos);
40: yPos += Constants.getDistLineToText();
41: } else {
42: yPos += Constants.getFontsize();
43: if (CENTER) {
44: Constants.write(g2, s, this .getWidth() / 2, yPos,
45: true);
46: } else {
47: Constants.write(g2, s, Constants.getFontsize() / 2,
48: yPos, false);
49: }
50: yPos += Constants.getDistTextToText();
51: }
52: }
53:
54: // Finally, change other graphical attributes using
55: // drawLine, getWidth, getHeight..
56: g2.drawLine(0, this .getHeight() - 1 - inset / 2, 0, inset / 2);
57: g2.drawOval(0, 0, this .getWidth(), inset);
58: g2.drawArc(0, this .getHeight() - 1 - inset, this .getWidth(),
59: Constants.getFontsize(), 180, 180);
60: g2.drawLine(this .getWidth() - 1, inset / 2,
61: this .getWidth() - 1, this .getHeight() - 1 - inset / 2);
62: }
63:
64: // Change this method if you want to set the resize-attributes of
65: // your custom element
66: public int getPossibleResizeDirections() {
67: // Remove from this list the borders you don't want to be resizeable.
68: return Constants.RESIZE_TOP | Constants.RESIZE_LEFT
69: | Constants.RESIZE_BOTTOM | Constants.RESIZE_RIGHT;
70: }
71:
72: // Advanced: change this method to modify the area where relations
73: // stick to your custom element.
74: public StickingPolygon getStickingBorder() {
75: // By default, the element returns its outer borders. Change it,
76: // if your element needs to stick to relations differently.
77: // See, for example, the source code of the UML interface element.
78: StickingPolygon p = new StickingPolygon();
79: p.addLine(new Point(0, 0), new Point(this .getWidth() - 1, 0),
80: Constants.RESIZE_TOP);
81: p.addLine(new Point(this .getWidth() - 1, 0), new Point(this
82: .getWidth() - 1, this .getHeight() - 1),
83: Constants.RESIZE_RIGHT);
84: p.addLine(new Point(this .getWidth() - 1, this .getHeight() - 1),
85: new Point(0, this .getHeight() - 1),
86: Constants.RESIZE_BOTTOM);
87: p.addLine(new Point(0, this .getHeight() - 1), new Point(0, 0),
88: Constants.RESIZE_LEFT);
89: return p;
90: }
91: }
|