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