Skip to content

Package: AbstractNewAction

AbstractNewAction

nameinstructionbranchcomplexitylinemethod
AbstractNewAction(ConfigurationGraph)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
AbstractNewAction(String, ConfigurationGraph)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
actionPerformed(ActionEvent)
M: 1 C: 23
96%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 1 C: 7
88%
M: 0 C: 1
100%

Coverage

1: package networkconfigurator.actions;
2:
3: import java.awt.Point;
4: import java.awt.event.ActionEvent;
5:
6: import javax.swing.AbstractAction;
7:
8: import networkconfigurator.ConfigurationGraph;
9: import networkconfigurator.item.Node;
10:
11: /**
12: * Abstract Action for adding a new node.
13: *
14: * @author Max Hölscher
15: *
16: */
17: public abstract class AbstractNewAction extends AbstractAction {
18:         /**
19:          * the graph.
20:          */
21:         private final ConfigurationGraph graph;
22:
23:         /**
24:          * The Constructor.
25:          *
26:          * @param graph
27:          * the graph.
28:          */
29:         public AbstractNewAction(final ConfigurationGraph graph) {
30:                 this.graph = graph;
31:         }
32:
33:         /**
34:          * The constructor.
35:          *
36:          * @param name
37:          * the name
38:          * @param graph
39:          * the graph
40:          */
41:         public AbstractNewAction(final String name, final ConfigurationGraph graph) {
42:                 super(name);
43:                 this.graph = graph;
44:         }
45:
46:         @Override
47:         public void actionPerformed(final ActionEvent e) {
48:                 final Point point = this.graph.getMousePt().getLocation();
49:                 final Node n;
50:                 try {
51:                         n = createNode(point);
52:                         n.setSelected(true);
53:                         graph.getItems().add(n);
54:                         graph.repaint();
55:                 } catch (final CreateNodeException e1) {
56:                         // if the node could not be created.
57:                 }
58:
59:         }
60:
61:         /**
62:          * Abstract Methode for adding a Node to the graph.
63:          *
64:          * @param p
65:          * Point, where the node should be added
66:          * @return Node to be added
67:          * @throws CreateNodeException
68:          * Exception if the node could not be created.
69:          */
70:         protected abstract Node createNode(Point p) throws CreateNodeException;
71: }