📄 netkitviewer.java
字号:
/* * Copyright (C) 2005, 2006 * Santiago Carot Nemesio * * This file is part of NetGUI. * * NetGUI is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * NetGUI is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with NetGUI; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * */import edu.umd.cs.piccolo.*;import edu.umd.cs.piccolo.PCanvas;import edu.umd.cs.piccolo.nodes.*;import edu.umd.cs.piccolox.*;import edu.umd.cs.piccolox.nodes.*;import edu.umd.cs.piccolo.event.*;import edu.umd.cs.piccolo.util.*;import java.io.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.border.*;import java.lang.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.KeyEvent;public class NetKitViewer extends JFrame { NetKitGUI netkitWindow; JToolBar toolBar; JMenuItem showLayer = new JMenuItem("mostrar Nodelayer"); JMenuItem hideLayer = new JMenuItem("ocultar Nodelayer"); public NetKitViewer() { setJMenuBar(createMenuBar()); toolBar = new JToolBar("NetKitBar"); addButtons(toolBar); getContentPane().add(toolBar, BorderLayout.PAGE_START); setTitle("NetGUI"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel mainPanel = new JPanel(new GridBagLayout()); //mainPanel.setPreferredSize(new Dimension(280, 100)); netkitWindow = new NetKitGUI(500, 500); getContentPane().add(netkitWindow); pack(); setVisible(true); JOptionPane.showMessageDialog (this, "Grupo de Sistemas y Comunicaciones (GSyC)\n" + "DITTE URJC\n"+ "Este programa se distribuye bajo la licencia GNU GPL v2", "NetGUI v0.4.1", JOptionPane.INFORMATION_MESSAGE, new ImageIcon(System.getProperty("NETLAB_HOME")+"/images/other/gsyc.png")); //obtenemos el directorio de trabajo initWorkSpaceForNetKit (); } private void selectActionPerformed (ActionEvent evt) { netkitWindow.enableSelectMode (); } private void editCutActionPerformed(ActionEvent evt) { netkitWindow.deleteElement (); } private void addNewTerminalActionPerformed(ActionEvent evt) { netkitWindow.addTerminal (); } private void addNewRouterActionPerformed(ActionEvent evt) { netkitWindow.addRouter (); } private void addNewHubActionPerformed(ActionEvent evt) { netkitWindow.addHub(); } private void addNewConectionActionPerformed(ActionEvent evt) { netkitWindow.addConexion (); } private void addButtons(JToolBar toolBar) { JButton addTerminal = new JButton(new ImageIcon(System.getProperty("NETLAB_HOME")+"/images/48x48/system.png")); toolBar.add(addTerminal); JButton addRouter = new JButton(new ImageIcon(System.getProperty("NETLAB_HOME")+"/images/48x48/router.png")); toolBar.add(addRouter); JButton addHub = new JButton(new ImageIcon(System.getProperty("NETLAB_HOME")+"/images/48x48/hub.png")); toolBar.add(addHub); JButton addConexion = new JButton(new ImageIcon(System.getProperty("NETLAB_HOME")+"/images/48x48/rj45_cable.png")); toolBar.add(addConexion); JButton editCutMode = new JButton(new ImageIcon(System.getProperty("NETLAB_HOME")+"/images/48x48/editcut.png")); toolBar.add(editCutMode); JButton selectMode = new JButton(new ImageIcon(System.getProperty("NETLAB_HOME")+"/images/48x48/arrow.png")); toolBar.add(selectMode); addTerminal.setToolTipText("nuevo terminal"); addRouter.setToolTipText("nuevo router"); addHub.setToolTipText("nuevo hub"); addConexion.setToolTipText("conectar..."); editCutMode.setToolTipText("cortar"); selectMode.setToolTipText("seleccionar"); selectMode.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { selectActionPerformed(evt); } }); editCutMode.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { editCutActionPerformed(evt); } }); addTerminal.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { addNewTerminalActionPerformed(evt); } }); addRouter.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { addNewRouterActionPerformed(evt); } }); addHub.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { addNewHubActionPerformed(evt); } }); addConexion.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { addNewConectionActionPerformed(evt); } }); JButton runButton = new JButton(new ImageIcon(System.getProperty("NETLAB_HOME")+"/images/32x32/run.png")); runButton.setToolTipText("Arrancar m醧uinas"); toolBar.add(runButton); runButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { startNetKitActionPerformed(evt); } }); JButton stopButton = new JButton(new ImageIcon(System.getProperty("NETLAB_HOME")+"/images/32x32/exit.png")); stopButton.setToolTipText("Parar m醧uinas"); toolBar.add(stopButton); stopButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { stopNetKitActionPerformed(evt); } }); JButton centerButton = new JButton(new ImageIcon(System.getProperty("NETLAB_HOME")+"/images/32x32/center.png")); centerButton.setToolTipText("Centrar vista"); toolBar.add(centerButton); centerButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { centerNetKitActionPerformed(evt); } }); } private void saveAsActionPerformed(ActionEvent evt) { String currentPath = UtilNetGUI.getCurrentWorkSpace().getAbsolutePath(); String newPath = WorkSpace.exploreDirectories("Guardar como..."); if (newPath == null) return; File oldDir = new File (currentPath); File newDir = new File (newPath); if (!newDir.exists()) { newDir.mkdir(); } try { Process proc; String cmd ="tar -Scf "+newPath+"/.tmpnk --directory "+currentPath + "/ ."; String cmd2="tar xf "+newPath+"/.tmpnk --directory "+newPath +"/"; proc = Runtime.getRuntime().exec(cmd,null); proc.waitFor(); proc = Runtime.getRuntime().exec(cmd2,null); proc.waitFor(); proc = Runtime.getRuntime().exec("rm " + newPath + "/.tmpnk", null); } catch (Exception ex) {System.out.println("Error " + ex);} setTitle("NetGUI: " + newDir.getName()); UtilNetGUI.setCurrentWorkSpace(newDir); netkitWindow.saveProject(new File( UtilNetGUI.getCurrentWorkSpace().getAbsolutePath() + "/" + "netgui.nkp")); UtilNetGUI.setAplicationStatusChange(false); JOptionPane.showMessageDialog(this, "Cambios guardados" , "NetGUI", JOptionPane.INFORMATION_MESSAGE); } private void saveActionPerformed(ActionEvent evt) { String currentPath = UtilNetGUI.getCurrentWorkSpace().getAbsolutePath(); String tempPath = System.getProperty("user.home") +"/.netkitgui"; if (currentPath.equals(tempPath)) { String newPath = WorkSpace.exploreDirectories("Guardar"); if (newPath == null) return; File oldDir = new File (tempPath); File newDir = new File (newPath); if (!newDir.exists()) { oldDir.renameTo(newDir); } else { String[] children = oldDir.list(); for (int i=0; i<children.length; i++) { File f=new File(children[i]); f.renameTo(newDir); } oldDir.delete(); } setTitle("NetGUI: " + newDir.getName()); UtilNetGUI.setCurrentWorkSpace(newDir); } if (UtilNetGUI.aplicationChanged()) { netkitWindow.saveProject(new File( UtilNetGUI.getCurrentWorkSpace().getAbsolutePath() + "/" + "netgui.nkp")); UtilNetGUI.setAplicationStatusChange(false); JOptionPane.showMessageDialog(this, "Cambios guardados" , "NetGUI", JOptionPane.INFORMATION_MESSAGE); } else JOptionPane.showMessageDialog(this, "No ha habido cambios desde la 鷏tima vez que se guard
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -