public void loadProtocols() { _protocolMenu.removeAll(); for (Protocol proto : ProtocolManager.getInstance().getProtocols()) { JMenuItem protoButton = new JMenuItem(proto.getName() + " (" + proto.getPort() + ")"); protoButton.setActionCommand("p:" + proto.getName()); protoButton.addActionListener(_pel); _protocolMenu.add(protoButton); } JMenuItem newProtoButton = new JMenuItem("New Protocol..."); newProtoButton.setActionCommand("new"); newProtoButton.addActionListener(_pel); _protocolMenu.addSeparator(); _protocolMenu.add(newProtoButton); if (!ProtocolManager.getInstance().getProtocols().isEmpty()) switchToProtocol(ProtocolManager.getInstance().getProtocols().iterator().next()); else switchToProtocol(null); }
public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); System.out.println(cmd); if (cmd.startsWith("p:")) { String pName = cmd.substring(2); _pEditor.switchToProtocol(ProtocolManager.getInstance().getProtocolByName(pName)); } else if (cmd.equals("new")) { // dialog } else if (cmd.equals("properties")) { // dialog } else if (cmd.equals("save")) { Protocol currentProtocol = _pEditor.getCurrentProtocol(); if (currentProtocol != null) currentProtocol.saveProtocol(); } else if (cmd.equals("reload")) { ProtocolManager.getInstance().loadProtocols(); _pEditor.loadProtocols(); } }