Skip to content

Package: Node

Node

nameinstructionbranchcomplexitylinemethod
Node()
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
draw(Graphics)
M: 65 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 15 C: 0
0%
M: 1 C: 0
0%
getName()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getObserver()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
markAsSelected(Graphics)
M: 14 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
notifyObserver()
M: 15 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
registerObserver(Edge)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
removeObserver(Edge)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
setName(String)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%

Coverage

1: package networkconfigurator.item;
2:
3: import java.awt.Color;
4: import java.awt.Graphics;
5: import java.awt.Rectangle;
6: import java.awt.image.BufferedImage;
7: import java.io.IOException;
8: import java.util.ArrayList;
9: import java.util.Iterator;
10: import java.util.List;
11:
12: import networkconfigurator.DetailDrawPropertyEntry;
13: import networkconfigurator.DetailDrawVisitor;
14:
15: /**
16: * A Node represents a node in a graph.
17: *
18: * @author Erik Arand
19: */
20: public abstract class Node extends Item {
21:         /**
22:          * Name of the Node.
23:          */
24:         private String name;
25:         /**
26:          * The list of observer edges.
27:          */
28:         private final List<Edge> observer = new ArrayList<Edge>();
29:
30:         /**
31:          * Üblicher Getter für das Attribut observer.
32:          *
33:          * @return liefert observer.
34:          */
35:         public List<Edge> getObserver() {
36:                 return observer;
37:         }
38:
39:         /**
40:          * Üblicher Getter für das Attribut name.
41:          *
42:          * @return liefert name.
43:          */
44:         public String getName() {
45:                 return name;
46:         }
47:
48:         /**
49:          * Üblicher Setter für das Attribut name.
50:          *
51:          * @param name
52:          * Setzt den Parameter {@code name} in das Feld name.
53:          */
54:         public void setName(final String name) {
55:                 this.name = name;
56:         }
57:
58:         /**
59:          * the Image for the symbol.
60:          *
61:          * @return the image.
62:          * @throws IOException
63:          * exception if icon not found.
64:          */
65:         public abstract BufferedImage giveImage();
66:
67:         /**
68:          * register a edge in the list of observers.
69:          *
70:          * @param edge
71:          * the edge to be added.
72:          */
73:         public void registerObserver(final Edge edge) {
74:                 this.observer.add(edge);
75:         }
76:
77:         /**
78:          * remove a edge form the list of observers.
79:          *
80:          * @param edge
81:          * the edge to be removed.
82:          */
83:         public void removeObserver(final Edge edge) {
84:                 this.observer.remove(edge);
85:         }
86:
87:         /**
88:          * notifying the Observers.
89:          */
90:         public void notifyObserver() {
91:•                for (Edge currentEdge : this.observer) {
92:                         currentEdge.calculateMiddle();
93:                 }
94:         }
95:
96:         /**
97:          * Draw this node.
98:          *
99:          * @param g
100:          * to be drawn
101:          * @throws IOException
102:          * Exception if Icons has not been found
103:          */
104:         @Override
105:         public void draw(final Graphics g) {
106:                 final BufferedImage image = giveImage();
107:
108:                 g.setColor(Color.BLACK);
109:                 final Rectangle boundary = getBoundary();
110:                 g.drawImage(image, getPoint().x - (boundary.width / 2),
111:                                 getPoint().y - (boundary.height / 2), boundary.width, boundary.height, null);
112:
113:                 final Iterator<DetailDrawPropertyEntry> iterator = this.getPropertyDraw().iterator();
114:•                while (iterator.hasNext()) {
115:                         final DetailDrawPropertyEntry detailDrawPropertyEntry = iterator.next();
116:                         detailDrawPropertyEntry.getPropertyDrawEntry()
117:                                         .accept(new DetailDrawVisitor(getBoundary(), g, detailDrawPropertyEntry));
118:                 }
119:•                if (this.getSelected()) {
120:                         markAsSelected(g);
121:                 }
122:                 notifyObserver();
123:
124:         };
125:
126:         @Override
127:         public void markAsSelected(final Graphics g) {
128:                 final Rectangle boundary = getBoundary();
129:                 g.drawOval(boundary.x, boundary.y, boundary.width, boundary.height);
130:         }
131:
132: }