Skip to content

Package: ChangeConnectionType$VisitorForChangingTheConnectionType

ChangeConnectionType$VisitorForChangingTheConnectionType

nameinstructionbranchcomplexitylinemethod
ChangeConnectionType.VisitorForChangingTheConnectionType(ChangeConnectionType)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
adapter(NetworkAdapter)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
configRouter(ConfigRouter)
M: 80 C: 0
0%
M: 12 C: 0
0%
M: 7 C: 0
0%
M: 16 C: 0
0%
M: 1 C: 0
0%
hardwareEdge(HardwareEdge)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
host(Host)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
internet(Internet)
M: 26 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
networkCable(NetworkCable)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
router(Router)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
sWitch(Switch)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
slot(Slot)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: package networkconfigurator.actions;
2:
3: import java.awt.event.ActionEvent;
4: import java.util.ArrayList;
5: import java.util.List;
6:
7: import javax.swing.JLabel;
8: import javax.swing.JOptionPane;
9: import javax.swing.JPanel;
10:
11: import networkconfigurator.ConfigurationGraph;
12: import networkconfigurator.ConnectingTypeButton;
13: import networkconfigurator.item.ConfigRouter;
14: import networkconfigurator.item.ConnectingType;
15: import networkconfigurator.item.HardwareEdge;
16: import networkconfigurator.item.Host;
17: import networkconfigurator.item.Internet;
18: import networkconfigurator.item.ItemVisitor;
19: import networkconfigurator.item.NetworkAdapter;
20: import networkconfigurator.item.NetworkCable;
21: import networkconfigurator.item.Router;
22: import networkconfigurator.item.Slot;
23: import networkconfigurator.item.Switch;
24:
25: /**
26: * Action for changing the connecting type.
27: *
28: * @author Erik Ole Arand
29: *
30: */
31: public final class ChangeConnectionType extends AbstractConfigurationGraphAction {
32:
33:         /**
34:          * List of buttons that are presented on the panel.
35:          */
36:         private final List<ConnectingTypeButton> buttons = new ArrayList<ConnectingTypeButton>();
37:
38:         /**
39:          * the default selection.
40:          */
41:         private ConnectingType connectingType = ConnectingType.ISDN;
42:         /**
43:          * The panel of the multiselection of the connection types for a ConfigRouter.
44:          */
45:         private final JPanel panel = new JPanel();
46:
47:         /**
48:          * The Constructor.
49:          *
50:          * @param name
51:          * the name.
52:          * @param graph
53:          * the graph.
54:          */
55:         public ChangeConnectionType(final String name, final ConfigurationGraph graph) {
56:                 super(name, graph);
57:
58:                 panel.add(new JLabel(NcActionsConstants.CHOOSE_A_CONNECTION_TYPE));
59:                 for (ConnectingType type : ConnectingType.values()) {
60:                         final ConnectingTypeButton button = new ConnectingTypeButton(type);
61:                         panel.add(button);
62:                         buttons.add(button);
63:                 }
64:         }
65:
66:         @Override
67:         public void actionPerformed(final ActionEvent e) {
68:
69:                 getGraph().getSelected().get(0).accept(new VisitorForChangingTheConnectionType());
70:         }
71:
72:         /**
73:          * getter connectingType.
74:          *
75:          * @return the Type.
76:          */
77:         public ConnectingType getConnectingType() {
78:                 return connectingType;
79:         }
80:
81:         /**
82:          * Visitor calls for changing the connecting type of internet or configRouter.
83:          *
84:          * @author Erik Ole Arand
85:          *
86:          */
87:         private final class VisitorForChangingTheConnectionType implements ItemVisitor {
88:
89:                 /**
90:                  * Constructor.
91:                  */
92:                 private VisitorForChangingTheConnectionType() {
93:                 }
94:
95:                 @Override
96:                 public void slot(final Slot slot) {
97:                 }
98:
99:                 @Override
100:                 public void sWitch(final Switch sWitch) {
101:                 }
102:
103:                 @Override
104:                 public void router(final Router router) {
105:                 }
106:
107:                 @Override
108:                 public void networkCable(final NetworkCable edge) {
109:                 }
110:
111:                 @Override
112:                 public void internet(final Internet internet) {
113:                         System.out.println("Internet");
114:                         connectingType = (ConnectingType) JOptionPane.showInputDialog(getGraph(),
115:                                         NcActionsConstants.CONNECTION_TYPE,
116:                                         NcActionsConstants.CHOOSE_A_CONNECTION_TYPE, JOptionPane.QUESTION_MESSAGE,
117:                                         null, ConnectingType.values(), ConnectingType.values()[0]);
118:                         internet.setConnectingType(connectingType);
119:                 }
120:
121:                 @Override
122:                 public void host(final Host host) {
123:                 }
124:
125:                 @Override
126:                 public void hardwareEdge(final HardwareEdge edge) {
127:                 }
128:
129:                 @Override
130:                 public void configRouter(final ConfigRouter router) {
131:
132:•                        for (ConnectingType type : router.getConnectingTypes().getConnectingTypeList()) {
133:•                                for (ConnectingTypeButton button : buttons) {
134:•                                        if (type.equals(button.getConnectingType())) {
135:                                                 button.setSelected(true);
136:                                         } else {
137:                                                 button.setSelected(false);
138:                                         }
139:                                 }
140:                         }
141:
142:                         final int ok = JOptionPane.showConfirmDialog(getGraph(), panel,
143:                                         NcActionsConstants.CONNECTION_TYPE, JOptionPane.OK_OPTION);
144:•                        if (ok == JOptionPane.YES_OPTION) {
145:•                                for (ConnectingTypeButton button : buttons) {
146:•                                        if (button.isSelected()) {
147:                                                 router.addConnectingType(button.getConnectingType());
148:                                         } else {
149:                                                 router.addConnectingType(button.getConnectingType());
150:                                         }
151:                                 }
152:                         }
153:                         getGraph().repaint();
154:                 }
155:
156:                 @Override
157:                 public void adapter(final NetworkAdapter adapter) {
158:                 }
159:
160:         }
161:
162:         /**
163:          * Getter of buttons.
164:          *
165:          * @return the list of buttons.
166:          */
167:         public List<ConnectingTypeButton> getButtons() {
168:                 return buttons;
169:         }
170:
171: }