Skip to contentMethod: visit(DetailInputBox)
      1: package networkconfigurator;
2: 
3: import java.awt.Graphics;
4: import java.awt.Rectangle;
5: 
6: import model.assignment.VariableAssignment;
7: import networkconfigurator.item.ConnectingType;
8: import networkconfigurator.item.ConnectingTypeList;
9: 
10: /**
11:  * 
12:  * @author HFW416 Jannik
13:  *
14:  */
15: public class DetailDrawVisitor {
16: 
17:         /**
18:          * the current position.
19:          */
20:         private final Rectangle currentPosition;
21:         /**
22:          * the graphics reference.
23:          */
24:         private final Graphics g;
25:         /**
26:          * the detail draw property entries.
27:          */
28:         private final DetailDrawPropertyEntry detailProperty;
29: 
30:         /**
31:          * constructor for the detail draw visitor.
32:          * 
33:          * @param currentPosition
34:          *            the current position.
35:          * @param graphics
36:          *            the graphics reference.
37:          * @param detailDrawPropertyEntry
38:          *            the detail draw property entries.
39:          */
40:         public DetailDrawVisitor(final Rectangle currentPosition, final Graphics graphics,
41:                         final DetailDrawPropertyEntry detailDrawPropertyEntry) {
42:                 this.currentPosition = currentPosition;
43:                 this.g = graphics;
44:                 this.detailProperty = detailDrawPropertyEntry;
45:         }
46: 
47:         /**
48:          * 
49:          * @param variableAssignment
50:          *            the value to draw.
51:          */
52:         public void visit(final VariableAssignment variableAssignment) {
53:                 drawDetail(variableAssignment.getValue());
54:         }
55: 
56:         /**
57:          * 
58:          * @param connectingType
59:          *            the connectingType to draw.
60:          */
61:         public void visit(final ConnectingType connectingType) {
62:                 drawDetail(connectingType.name());
63:         }
64: 
65:         /**
66:          * 
67:          * @param inputBox
68:          *            the input box to draw the content.
69:          */
70:         public void visit(final DetailInputBox inputBox) {
71:                 drawDetail(inputBox.getContentValue());
72:         }
73: 
74:         /**
75:          * 
76:          * @param connectingTypes
77:          *            the connectingTypes to draw.
78:          */
79:         public void visit(final ConnectingTypeList connectingTypes) {
80:                 drawDetail(connectingTypes.getConnectingTypeList().stream().map(item -> item.name())
81:                                 .collect(java.util.stream.Collectors.joining(", ")));
82: 
83:         }
84: 
85:         /**
86:          * draw the information on the panel.
87:          * 
88:          * @param detailValue
89:          *            The value should be displayed.
90:          */
91:         private void drawDetail(final String detailValue) {
92:                 g.setColor(detailProperty.getColor());
93:                 g.drawString(this.getDetailProperty().getPrefix() + detailValue,
94:                                 currentPosition.x + this.getDetailProperty().getPositionX(),
95:                                 currentPosition.y + this.getDetailProperty().getPositionY());
96:         }
97: 
98:         /**
99:          * getter for currentPosition.
100:          * 
101:          * @return currentPosition
102:          */
103:         public final Rectangle getCurrentPosition() {
104:                 return currentPosition;
105:         }
106: 
107:         /**
108:          * getter for graphics.
109:          * 
110:          * @return graphics
111:          */
112:         public final Graphics getG() {
113:                 return g;
114:         }
115: 
116:         /**
117:          * getter for detailProperty.
118:          * 
119:          * @return detailProperty
120:          */
121:         public final DetailDrawPropertyEntry getDetailProperty() {
122:                 return detailProperty;
123:         }
124: 
125: }