/// Pass user's interaction with list to appropriate handler public void valueChanged(ListSelectionEvent e) { if (e.getSource() == sourceList) { if (!e.getValueIsAdjusting()) { int indexS = sourceList.getSelectedIndex(); srcID = indexS + 1; drawTest.repaint(); } } if (e.getSource() == destList) { if (!e.getValueIsAdjusting()) { int indexD = destList.getSelectedIndex(); dstID = indexD + 17; drawTest.repaint(); } } if (e.getSource() == routerList) { if (!e.getValueIsAdjusting()) { indexR = routerList.getSelectedIndex(); Router temp = statMux.getRouter(indexR); int[] pList = temp.getPriorityList(); audioVal.setText(String.valueOf(pList[0])); videoVal.setText(String.valueOf(pList[1])); textVal.setText(String.valueOf(pList[2])); } } if (e.getSource() == packTypeList) { if (!e.getValueIsAdjusting()) { int temp = packTypeList.getSelectedIndex(); if (temp == 0) { type = PacketType.AUDIO; } else if (temp == 1) { type = PacketType.VIDEO; } else { type = PacketType.TEXT; } drawTest.repaint(); } } }
/// Check for button clicking and apply appropriate response public void actionPerformed(ActionEvent e) { /// For each input, pass it to the correct handler /// Priority of router will be updated based on input /// Upon user's changes of the priority value, repaint /// the display component if (e.getSource() == aPlus) { Router temp = statMux.getRouter(indexR); int[] pList = temp.getPriorityList(); pList[0] = dataBound(pList[0] + 1); temp.setPriorityList(pList); audioVal.setText(String.valueOf(pList[0])); videoVal.setText(String.valueOf(pList[1])); textVal.setText(String.valueOf(pList[2])); drawTest.repaint(); } if (e.getSource() == aMinus) { Router temp = statMux.getRouter(indexR); int[] pList = temp.getPriorityList(); pList[0] = dataBound(pList[0] - 1); temp.setPriorityList(pList); audioVal.setText(String.valueOf(pList[0])); videoVal.setText(String.valueOf(pList[1])); textVal.setText(String.valueOf(pList[2])); drawTest.repaint(); } if (e.getSource() == vPlus) { Router temp = statMux.getRouter(indexR); int[] pList = temp.getPriorityList(); pList[1] = dataBound(pList[1] + 1); temp.setPriorityList(pList); audioVal.setText(String.valueOf(pList[0])); videoVal.setText(String.valueOf(pList[1])); textVal.setText(String.valueOf(pList[2])); drawTest.repaint(); } if (e.getSource() == vMinus) { Router temp = statMux.getRouter(indexR); int[] pList = temp.getPriorityList(); pList[1] = dataBound(pList[1] - 1); temp.setPriorityList(pList); audioVal.setText(String.valueOf(pList[0])); videoVal.setText(String.valueOf(pList[1])); textVal.setText(String.valueOf(pList[2])); drawTest.repaint(); } if (e.getSource() == tPlus) { Router temp = statMux.getRouter(indexR); int[] pList = temp.getPriorityList(); pList[2] = dataBound(pList[2] + 1); temp.setPriorityList(pList); audioVal.setText(String.valueOf(pList[0])); videoVal.setText(String.valueOf(pList[1])); textVal.setText(String.valueOf(pList[2])); drawTest.repaint(); } if (e.getSource() == tMinus) { Router temp = statMux.getRouter(indexR); int[] pList = temp.getPriorityList(); pList[2] = dataBound(pList[2] - 1); temp.setPriorityList(pList); audioVal.setText(String.valueOf(pList[0])); videoVal.setText(String.valueOf(pList[1])); textVal.setText(String.valueOf(pList[2])); drawTest.repaint(); } }