diff --git a/.classpath b/.classpath index cb7ca16..9c30a2b 100644 --- a/.classpath +++ b/.classpath @@ -1,6 +1,7 @@ + diff --git a/bin/.gitignore b/bin/.gitignore index 9bd6d3a..d738ccd 100644 --- a/bin/.gitignore +++ b/bin/.gitignore @@ -1 +1,2 @@ +/commons-net-3.6.jar /co/ diff --git a/bin/co/edu/watcher/gui/WatcherGUI$1.class b/bin/co/edu/watcher/gui/WatcherGUI$1.class index 16fa70f..2947ab3 100644 Binary files a/bin/co/edu/watcher/gui/WatcherGUI$1.class and b/bin/co/edu/watcher/gui/WatcherGUI$1.class differ diff --git a/bin/co/edu/watcher/gui/WatcherGUI$2.class b/bin/co/edu/watcher/gui/WatcherGUI$2.class index 988a5ec..c72d0df 100644 Binary files a/bin/co/edu/watcher/gui/WatcherGUI$2.class and b/bin/co/edu/watcher/gui/WatcherGUI$2.class differ diff --git a/bin/co/edu/watcher/gui/WatcherGUI$3.class b/bin/co/edu/watcher/gui/WatcherGUI$3.class index f95ebcb..da140bb 100644 Binary files a/bin/co/edu/watcher/gui/WatcherGUI$3.class and b/bin/co/edu/watcher/gui/WatcherGUI$3.class differ diff --git a/bin/co/edu/watcher/gui/WatcherGUI$4.class b/bin/co/edu/watcher/gui/WatcherGUI$4.class index ea7664f..5389e71 100644 Binary files a/bin/co/edu/watcher/gui/WatcherGUI$4.class and b/bin/co/edu/watcher/gui/WatcherGUI$4.class differ diff --git a/bin/co/edu/watcher/gui/WatcherGUI$5.class b/bin/co/edu/watcher/gui/WatcherGUI$5.class index 58e911b..e76b143 100644 Binary files a/bin/co/edu/watcher/gui/WatcherGUI$5.class and b/bin/co/edu/watcher/gui/WatcherGUI$5.class differ diff --git a/bin/co/edu/watcher/gui/WatcherGUI$6.class b/bin/co/edu/watcher/gui/WatcherGUI$6.class index 8b096bd..b9c3062 100644 Binary files a/bin/co/edu/watcher/gui/WatcherGUI$6.class and b/bin/co/edu/watcher/gui/WatcherGUI$6.class differ diff --git a/bin/co/edu/watcher/gui/WatcherGUI.class b/bin/co/edu/watcher/gui/WatcherGUI.class index 9783e04..c520f44 100644 Binary files a/bin/co/edu/watcher/gui/WatcherGUI.class and b/bin/co/edu/watcher/gui/WatcherGUI.class differ diff --git a/img/about.png b/img/about.png new file mode 100644 index 0000000..c947015 Binary files /dev/null and b/img/about.png differ diff --git a/img/ni.png b/img/ni.png new file mode 100644 index 0000000..cdda53d Binary files /dev/null and b/img/ni.png differ diff --git a/src/co/edu/watcher/gui/WatcherGUI.java b/src/co/edu/watcher/gui/WatcherGUI.java index d955d82..f02bca5 100644 --- a/src/co/edu/watcher/gui/WatcherGUI.java +++ b/src/co/edu/watcher/gui/WatcherGUI.java @@ -26,6 +26,7 @@ /** * Class main GUI + * * @author Sebastian A. 2017 */ public class WatcherGUI extends JFrame implements Runnable { @@ -33,7 +34,7 @@ public class WatcherGUI extends JFrame implements Runnable { /** * Global variables */ - private static final long serialVersionUID = 2301685011176900485L; + private static final long serialVersionUID = 2301685011176900485L; private WatcherUtil util = new WatcherUtil(); private Thread thread = new Thread(this); private JPanel contentPane; @@ -43,7 +44,7 @@ public class WatcherGUI extends JFrame implements Runnable { private JLabel lblip; private DefaultTableModel model; private boolean status = false; - private String[] columnNames = { "IP Address", "Device Name"}; + private String[] columnNames = { "IP Address", "Device Name" }; /** * Create the frame. @@ -82,7 +83,16 @@ public void mousePressed(MouseEvent e) { frame.setVisible(true); } }); - mnArchivo.add(mntmAcercaDe); + mnArchivo.add(mntmAcercaDe); + + JMenuItem mntmSwitchNi = new JMenuItem("Switch NI"); + mntmSwitchNi.addMouseListener(new MouseAdapter() { + @Override + public void mousePressed(MouseEvent e) { + seletionNI(1); + } + }); + mnArchivo.add(mntmSwitchNi); mnArchivo.add(mntmSalir); JMenu mnstart = new JMenu("Start"); @@ -117,7 +127,7 @@ public void mousePressed(MouseEvent arg0) { mnViewPorts.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { - if(seletion()){ + if (seletion()) { String ipHost = (String) model.getValueAt(table.getSelectedRow(), 0); PortGUI frame = new PortGUI(ipHost); frame.setVisible(true); @@ -125,17 +135,17 @@ public void mousePressed(MouseEvent e) { } }); menuBar.add(mnViewPorts); - - JMenu mnViewServices = new JMenu("View Services"); + + JMenu mnViewServices = new JMenu("View Services"); mnViewServices.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { - if(seletion()){ + if (seletion()) { String ipHost = (String) model.getValueAt(table.getSelectedRow(), 0); ServicesGUI frame = new ServicesGUI(ipHost); - frame.setVisible(true); + frame.setVisible(true); } - } + } }); menuBar.add(mnViewServices); contentPane = new JPanel(); @@ -154,28 +164,31 @@ public void mousePressed(MouseEvent e) { panel_main = new JPanel(); contentPane.add(panel_main, BorderLayout.CENTER); - createTable(); - seletionNI(); + createTable(); + seletionNI(0); thread.start(); } - - - private void seletionNI() { + /** + * Method that show all network interface + * @param call : Kind of execution , 0 is the beginning + */ + private void seletionNI(int call) { ArrayList stockList = util.networkInterfaces(); String[] stockArr = new String[stockList.size()]; - stockArr = stockList.toArray(stockArr); + stockArr = stockList.toArray(stockArr); ImageIcon icon = new ImageIcon("img/network.png"); - String resp = (String) JOptionPane.showInputDialog(null, "Please select a network interface.", "Network Interfaces", JOptionPane.DEFAULT_OPTION, icon, stockArr, stockArr[0]); - if(resp==null) - System.exit(ABORT); - String[] array=resp.split("/"); - util.setPrivateIP(array[1]); + String resp = (String) JOptionPane.showInputDialog(null, "Please select a network interface.", + "Network Interfaces", JOptionPane.CLOSED_OPTION, icon, stockArr, stockArr[0]); + if (resp == null && call == 0) + System.exit(ABORT); + if (resp != null) { + String[] array = resp.split("/"); + util.setPrivateIP(array[1]); + } } - - /** * Methos that create the table */ @@ -199,8 +212,6 @@ public boolean isCellEditable(int row, int col) { // Agregamos el scrollpanel al contenedor panel_main.add(scrollpane, BorderLayout.CENTER); } - - /** * Thread that does the scan @@ -208,11 +219,11 @@ public boolean isCellEditable(int row, int col) { public void run() { while (true) { try { - String[] list=util.getAddressList(); - for (int i =0; i < list.length && state() == true; i++) { - lblscan.setText("Scanning :"); + String[] list = util.getAddressList(); + for (int i = 0; i < list.length && state() == true; i++) { + lblscan.setText("Scanning :"); lblip.setText(list[i]); - Object[] row = util.scan(list[i],false); + Object[] row = util.scan(list[i], false); if (row != null) model.addRow(row); } @@ -224,18 +235,18 @@ public void run() { } } } - + /** - * Method that verifies the selection of a host + * Method that verifies the selection of a host + * * @return If there is a selection true, false in other case */ private boolean seletion() { int s = table.getSelectedRow(); - if (s==-1){ - JOptionPane.showMessageDialog(null, "Please select a Host"); + if (s == -1) { + JOptionPane.showMessageDialog(null, "Please select a Host", "Alert", JOptionPane.WARNING_MESSAGE); return false; - } - else + } else return true; }