package cnetmap;

import edu.uci.ics.jung.algorithms.layout.*;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.graph.UndirectedSparseGraph;
import edu.uci.ics.jung.visualization.VisualizationViewer;
import edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse;
import edu.uci.ics.jung.visualization.control.ModalGraphMouse;
import edu.uci.ics.jung.visualization.decorators.ToStringLabeller;
import edu.uci.ics.jung.visualization.renderers.Renderer.VertexLabel.Position;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Paint;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.filechooser.FileNameExtensionFilter;
import org.apache.commons.collections15.Transformer;

/**
 * Program CNetMap
 * @author Dominik Janura
 */
public class CNetMapUI extends javax.swing.JFrame {

  List<NetNode> nodeList = new ArrayList<>();
  NodeListModel nlModel = new NodeListModel();
  ListSelectionListener nlsl;

  /**
   * Vytvorí novú formu CNetMapUI
   */
  public CNetMapUI() {
    this.nlsl = new ListSelectionListener() {

      @Override
      public void valueChanged(ListSelectionEvent lse) {
        
        if (lse.getValueIsAdjusting()) {
          addIfButton.setEnabled(false);
          addMacButton.setEnabled(false);
        } else {
          if (nodeJList.isSelectionEmpty()) {
            addIfButton.setEnabled(false);
            addMacButton.setEnabled(false);
          } else {
            if (nodeList.get(nodeJList.getSelectedIndex()).getType().equals(CNetMap.TYPE_ROUTER)) {
              addIfButton.setEnabled(true);
              addMacButton.setEnabled(false);
            }
            if (nodeList.get(nodeJList.getSelectedIndex()).getType().equals(CNetMap.TYPE_SWITCH)) {
              addIfButton.setEnabled(true);
              addMacButton.setEnabled(true);
            }
          }
        }
      }
    };
    initComponents();
    nodeJList.addListSelectionListener(nlsl);
  }

  /**
   * This method is called from within the constructor to initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is always
   * regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    mainPanel = new javax.swing.JPanel();
    nodeListLabel = new javax.swing.JLabel();
    nodeScrollPane = new javax.swing.JScrollPane();
    nodeJList = new JList(nlModel);
    addRcButton = new javax.swing.JButton();
    addRcLabel = new javax.swing.JLabel();
    addIfButton = new javax.swing.JButton();
    addIfLabel = new javax.swing.JLabel();
    addMacButton = new javax.swing.JButton();
    addMacLabel = new javax.swing.JLabel();
    mapButton = new javax.swing.JButton();
    clearListButton = new javax.swing.JButton();
    scanButton = new javax.swing.JButton();
    jLabel1 = new javax.swing.JLabel();
    mainMenuBar = new javax.swing.JMenuBar();
    fileMenu = new javax.swing.JMenu();
    exitItem = new javax.swing.JMenuItem();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    nodeListLabel.setFont(new java.awt.Font("Dialog", 0, 10)); // NOI18N
    nodeListLabel.setText("Node list:");

    nodeScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

    nodeJList.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
    nodeJList.setModel(nlModel);
    nodeJList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
    nodeJList.setVisibleRowCount(-1);
    nodeScrollPane.setViewportView(nodeJList);

    addRcButton.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
    addRcButton.setText("Add RCs");
    addRcButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        addRcButtonActionPerformed(evt);
      }
    });

    addRcLabel.setFont(new java.awt.Font("Dialog", 0, 10)); // NOI18N
    addRcLabel.setText("<html>Add running config. <br>files.");

    addIfButton.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
    addIfButton.setText("Add Interfaces");
    addIfButton.setEnabled(false);
    addIfButton.setPreferredSize(new java.awt.Dimension(120, 25));
    addIfButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        addIfButtonActionPerformed(evt);
      }
    });

    addIfLabel.setFont(new java.awt.Font("Dialog", 0, 10)); // NOI18N
    addIfLabel.setText("<html>Add interfaces file for<br>selected node.");

    addMacButton.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
    addMacButton.setText("Add MAT");
    addMacButton.setEnabled(false);
    addMacButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        addMacButtonActionPerformed(evt);
      }
    });

    addMacLabel.setFont(new java.awt.Font("Dialog", 0, 10)); // NOI18N
    addMacLabel.setText("<html>Add mac-address-table<br>file for selected switch.");

    mapButton.setText("Map Network");
    mapButton.setEnabled(false);
    mapButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        mapButtonActionPerformed(evt);
      }
    });

    clearListButton.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
    clearListButton.setText("Clear List");
    clearListButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        clearListButtonActionPerformed(evt);
      }
    });

    scanButton.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
    scanButton.setText("Import folder");
    scanButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        scanButtonActionPerformed(evt);
      }
    });

    jLabel1.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
    jLabel1.setText("or");

    javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
    mainPanel.setLayout(mainPanelLayout);
    mainPanelLayout.setHorizontalGroup(
      mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(mainPanelLayout.createSequentialGroup()
        .addContainerGap()
        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(mainPanelLayout.createSequentialGroup()
            .addComponent(scanButton, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addComponent(nodeListLabel))
          .addComponent(addRcButton, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addGroup(mainPanelLayout.createSequentialGroup()
            .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(mainPanelLayout.createSequentialGroup()
                .addGap(57, 57, 57)
                .addComponent(jLabel1))
              .addComponent(addMacLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addComponent(addRcLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                .addComponent(addIfButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)
                .addComponent(addMacButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(addIfLabel, javax.swing.GroupLayout.Alignment.LEADING))
              .addComponent(mapButton, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(mainPanelLayout.createSequentialGroup()
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(nodeScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 400, javax.swing.GroupLayout.PREFERRED_SIZE))
              .addGroup(mainPanelLayout.createSequentialGroup()
                .addGap(325, 325, 325)
                .addComponent(clearListButton)))))
        .addContainerGap(32, Short.MAX_VALUE))
    );
    mainPanelLayout.setVerticalGroup(
      mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(mainPanelLayout.createSequentialGroup()
        .addContainerGap()
        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(mainPanelLayout.createSequentialGroup()
            .addComponent(scanButton)
            .addGap(10, 10, 10)
            .addComponent(jLabel1)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addComponent(addRcButton)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(addRcLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(addIfButton, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(addIfLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(addMacButton, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(addMacLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
          .addGroup(mainPanelLayout.createSequentialGroup()
            .addComponent(nodeListLabel)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(nodeScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(clearListButton)
          .addComponent(mapButton))
        .addContainerGap(22, Short.MAX_VALUE))
    );

    mainMenuBar.setToolTipText("Exit");

    fileMenu.setText("File");
    fileMenu.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N

    exitItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
    exitItem.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
    exitItem.setText("Exit");
    exitItem.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        exitItemActionPerformed(evt);
      }
    });
    fileMenu.add(exitItem);

    mainMenuBar.add(fileMenu);

    setJMenuBar(mainMenuBar);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
        .addContainerGap()
        .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        .addContainerGap())
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
        .addContainerGap()
        .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        .addContainerGap())
    );

    pack();
  }// </editor-fold>//GEN-END:initComponents

  private void exitItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitItemActionPerformed
    System.exit(0);
  }//GEN-LAST:event_exitItemActionPerformed

  private void addRcButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addRcButtonActionPerformed
    nodeJList.clearSelection();
    nlModel.clear();
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setAcceptAllFileFilterUsed(false);
    fileChooser.setFileFilter(new FileNameExtensionFilter("running-configuration text files (.rc)", "rc"));
    fileChooser.setMultiSelectionEnabled(true);
    if (JFileChooser.APPROVE_OPTION == fileChooser.showOpenDialog(this)) {
      File[] rcFiles = fileChooser.getSelectedFiles();
      String type, hostname = null;

      for (int fIndex = 0; fIndex < rcFiles.length; fIndex++) {
        try {
          if (null != (hostname = CNetMap.resolveHostname(rcFiles[fIndex]))) {
            type = CNetMap.resolveType(rcFiles[fIndex]);
            nodeList.add(new NetNode(hostname, type));
            if (type.equals("router")) {
              try {
                nodeList.get(fIndex).setInterfaceList(NetNode.parseRC(rcFiles[fIndex]));
              } catch (IOException ex) {
                Logger.getLogger(CNetMapUI.class.getName()).log(Level.SEVERE, null, ex);
              }
            }
          }
        } catch (IOException ex) {
          Logger.getLogger(CNetMapUI.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
      nlModel.add(nodeList);
      mapButton.setEnabled(true);
    }
  }//GEN-LAST:event_addRcButtonActionPerformed

  private void mapButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mapButtonActionPerformed
    for (NetNode nodes : nodeList) {
      if (nodes.getType().equals(CNetMap.TYPE_SWITCH)) {
        nodes.setConnections(nodeList);
      }
    }
    for (NetNode nodes : nodeList) {
      if (nodes.getType().equals(CNetMap.TYPE_ROUTER)) {
        nodes.setConnections(nodeList);
      }
    }
    
    Graph<NetNode, NetLink> networkGraph = new UndirectedSparseGraph<>();
    for (NetNode nodes : nodeList) {
      networkGraph.addVertex(nodes);
    }
    
    for (NetNode nodes : nodeList) {
      for (NetInterface interfaces : nodes.getInterfaceList()) {
        if ((!interfaces.getAlreadyConnected()) && (interfaces.getConnectedNode() != null)) {
          String netwAddress;
          if (null != interfaces.getIpNetwork()) {
            netwAddress = interfaces.getIpNetwork().getHostAddress();
          } else if (null != interfaces.getConnectedInterface().getIpNetwork()) {
            netwAddress = interfaces.getConnectedInterface().getIpNetwork().getHostAddress();
          } else {
            netwAddress = " ";
          }
          NetLink link = new NetLink(interfaces.getId(), interfaces.getConnectedInterface().getId(), netwAddress);
          networkGraph.addEdge(link, nodes, interfaces.getConnectedNode());
          interfaces.setAlreadyConnected(true);
          interfaces.getConnectedInterface().setAlreadyConnected(true);
        }
      }
    }
    
    Transformer<NetNode, Paint> vertexPaint = new Transformer<NetNode, Paint>() {
      @Override
      public Paint transform(NetNode node) {
        if (node.getType().equals(CNetMap.TYPE_SWITCH))
          return Color.GRAY;
        else if (node.getType().equals(CNetMap.TYPE_ROUTER))
          return Color.BLUE;
        else
          return Color.RED;
      }
    };
    
    Layout<NetNode, NetLink> networkLayout = new ISOMLayout(networkGraph);
    networkLayout.setSize(new Dimension(600, 440));

    VisualizationViewer<NetNode, NetLink> vv = new VisualizationViewer<>(networkLayout);
    vv.setPreferredSize(new Dimension(640, 480));
    vv.setBackground(Color.white);
    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
    vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller());
    vv.getRenderer().getVertexLabelRenderer().setPosition(Position.AUTO);
    
    DefaultModalGraphMouse gm = new DefaultModalGraphMouse();
    gm.setMode(ModalGraphMouse.Mode.TRANSFORMING);
    vv.setGraphMouse(gm);
    vv.addKeyListener(gm.getModeKeyListener());

    JFrame networkFrame = new JFrame("Network visualization");
    networkFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    networkFrame.getContentPane().add(vv);
    networkFrame.pack();
    networkFrame.setVisible(true);
  }//GEN-LAST:event_mapButtonActionPerformed

  private void addIfButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addIfButtonActionPerformed
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setAcceptAllFileFilterUsed(false);
    fileChooser.setFileFilter(new FileNameExtensionFilter("interfaces text files (.if)", "if"));
    fileChooser.setMultiSelectionEnabled(false);
    if (JFileChooser.APPROVE_OPTION == fileChooser.showOpenDialog(this)) {
      File ifFile = fileChooser.getSelectedFile();

      try {
        nodeList.get(nodeJList.getSelectedIndex()).parseInterfaces(ifFile);
      } catch (IOException ex) {
        Logger.getLogger(CNetMapUI.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
  }//GEN-LAST:event_addIfButtonActionPerformed

  private void clearListButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearListButtonActionPerformed
    nodeJList.clearSelection();
    nodeList.clear();
    nlModel.clear();
    addIfButton.setEnabled(false);
    addMacButton.setEnabled(false);
    mapButton.setEnabled(false);
  }//GEN-LAST:event_clearListButtonActionPerformed

  private void addMacButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addMacButtonActionPerformed
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setMultiSelectionEnabled(false);
    fileChooser.setAcceptAllFileFilterUsed(false);
    fileChooser.setFileFilter(new FileNameExtensionFilter("mac-address-table text files (.mat)", "mat"));
    fileChooser.setMultiSelectionEnabled(false);
    if (JFileChooser.APPROVE_OPTION == fileChooser.showOpenDialog(this)) {
      File macFile = fileChooser.getSelectedFile();

      try {
        nodeList.get(nodeJList.getSelectedIndex()).parseMacAddressTable(macFile);
      } catch (IOException ex) {
        Logger.getLogger(CNetMapUI.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
  }//GEN-LAST:event_addMacButtonActionPerformed

  private void listFiles(final File folder) throws IOException {
    for (final File fileEntry : folder.listFiles()) {
      if (fileEntry.isDirectory()) {
        listFiles(fileEntry);
      } else {
        String rcName = fileEntry.getName().split("\\.")[0];
        String rcExt = fileEntry.getName().split("\\.")[1];
        if (rcExt.equals("rc")) {
          String hostname, type;
          try {
            if (null != (hostname = CNetMap.resolveHostname(fileEntry))) {
              type = CNetMap.resolveType(fileEntry);
              nodeList.add(new NetNode(hostname, type));
              if (type.equals("router")) {
                try {
                  nodeList.get(nodeList.size() - 1).setInterfaceList(NetNode.parseRC(fileEntry));
                } catch (IOException ex) {
                  Logger.getLogger(CNetMapUI.class.getName()).log(Level.SEVERE, null, ex);
                }
              }
            }
          } catch (IOException ex) {
            Logger.getLogger(CNetMapUI.class.getName()).log(Level.SEVERE, null, ex);
          }

          for (final File otherEntry : folder.listFiles()) {
            if (otherEntry.isDirectory()) {
              listFiles(otherEntry);
            } else {
              String name = otherEntry.getName().split("\\.")[0];
              String ext = otherEntry.getName().split("\\.")[1];
              if (name.equals(rcName)) {
                if (ext.equals("if")) {
                  nodeList.get(nodeList.size() - 1).parseInterfaces(otherEntry);
                } else if (ext.equals("mat")) {
                  nodeList.get(nodeList.size() - 1).parseMacAddressTable(otherEntry);
                }
              }
            }
          }
        }
      }
    }
    nlModel.add(nodeList);
    mapButton.setEnabled(true);
  }

  private void scanButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_scanButtonActionPerformed
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setMultiSelectionEnabled(false);
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    if (JFileChooser.APPROVE_OPTION == fileChooser.showOpenDialog(this)) {
      try {
        listFiles(fileChooser.getSelectedFile());
      } catch (IOException ex) {
        Logger.getLogger(CNetMapUI.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
  }//GEN-LAST:event_scanButtonActionPerformed

  /**
   * Hlavná metóda programu
   * @param args argumenty z príkazového riadku
   */
  public static void main(String args[]) {
    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
     */
    try {
      for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
          javax.swing.UIManager.setLookAndFeel(info.getClassName());
          break;
        }
      }
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
      java.util.logging.Logger.getLogger(CNetMapUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
      @Override
      public void run() {
        new CNetMapUI().setVisible(true);
      }
    });
  }

  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton addIfButton;
  private javax.swing.JLabel addIfLabel;
  private javax.swing.JButton addMacButton;
  private javax.swing.JLabel addMacLabel;
  private javax.swing.JButton addRcButton;
  private javax.swing.JLabel addRcLabel;
  private javax.swing.JButton clearListButton;
  private javax.swing.JMenuItem exitItem;
  private javax.swing.JMenu fileMenu;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JMenuBar mainMenuBar;
  private javax.swing.JPanel mainPanel;
  private javax.swing.JButton mapButton;
  private javax.swing.JList nodeJList;
  private javax.swing.JLabel nodeListLabel;
  private javax.swing.JScrollPane nodeScrollPane;
  private javax.swing.JButton scanButton;
  // End of variables declaration//GEN-END:variables
}
