Skip to contentMethod: host(Host)
      1: package networkconfigurator.actions;
2: 
3: import java.awt.Point;
4: 
5: import model.assignment.VariableAssignment;
6: import networkconfigurator.ConfigurationGraph;
7: import networkconfigurator.item.ConfigRouter;
8: import networkconfigurator.item.Device;
9: import networkconfigurator.item.HardwareEdge;
10: import networkconfigurator.item.Host;
11: import networkconfigurator.item.Internet;
12: import networkconfigurator.item.ItemVisitor;
13: import networkconfigurator.item.NetworkAdapter;
14: import networkconfigurator.item.NetworkCable;
15: import networkconfigurator.item.Node;
16: import networkconfigurator.item.Router;
17: import networkconfigurator.item.Slot;
18: import networkconfigurator.item.Switch;
19: 
20: /**
21:  * Action for adding a new Node.
22:  * 
23:  * @author Erik Arand
24:  *
25:  */
26: public class NewSlotAction extends AbstractNewAction {
27:         /**
28:          * the configurationgraph.
29:          */
30:         private final ConfigurationGraph graph;
31: 
32:         /**
33:          * Action for a new NetworkAdapter.
34:          * 
35:          * @param name
36:          *            the name of the node.
37:          * @param graph
38:          *            the graph.
39:          */
40:         public NewSlotAction(final String name, final ConfigurationGraph graph) {
41:                 super(name, graph);
42:                 this.graph = graph;
43:         }
44: 
45:         @Override
46:         protected Node createNode(final Point p) {
47:                 final Device owner = (Device) graph.getSelected().get(0);
48:                 final Node newSlot = new Slot(p, owner, new VariableAssignment(null, null, "Slot", null));
49: 
50:                 graph.getSelected().get(0).accept(new VisitorForHardwareEdge(newSlot));
51:                 return newSlot;
52:         }
53: 
54:         /**
55:          * Visitor for adding HardwareEdges between the new slot and the Switch or Internet.
56:          * 
57:          * @author Erik Arand.
58:          *
59:          */
60:         private final class VisitorForHardwareEdge implements ItemVisitor {
61:                 /**
62:                  * the new slot.
63:                  */
64:                 private final Node newSlot;
65: 
66:                 /**
67:                  * The constructor.
68:                  * 
69:                  * @param newSlot
70:                  *            the new slot.
71:                  */
72:                 private VisitorForHardwareEdge(final Node newSlot) {
73:                         this.newSlot = newSlot;
74:                 }
75: 
76:                 @Override
77:                 public void sWitch(final Switch sWitch) {
78:                         graph.getItems().add(new HardwareEdge(sWitch, newSlot));
79:                 }
80: 
81:                 @Override
82:                 public void router(final Router router) {
83:                 }
84: 
85:                 @Override
86:                 public void networkCable(final NetworkCable edge) {
87:                 }
88: 
89:                 @Override
90:                 public void internet(final Internet internet) {
91:                         graph.getItems().add(new HardwareEdge(internet, newSlot));
92:                 }
93: 
94:                 @Override
95:                 public void host(final Host host) {
96:                 }
97: 
98:                 @Override
99:                 public void hardwareEdge(final HardwareEdge edge) {
100:                 }
101: 
102:                 @Override
103:                 public void configRouter(final ConfigRouter router) {
104:                 }
105: 
106:                 @Override
107:                 public void adapter(final NetworkAdapter adapter) {
108:                 }
109: 
110:                 @Override
111:                 public void slot(final Slot slot) {
112:                 }
113:         }
114: 
115: }