přidany propojení mezi objekty včetně zobrazovaní trafficu
parent
c407cec1e5
commit
ed24bddcc7
Binary file not shown.
|
After Width: | Height: | Size: 3.2 KiB |
|
|
@ -9,6 +9,7 @@ import jnet.client.gui.UIUpdater;
|
||||||
import jnet.client.network.NettyClient;
|
import jnet.client.network.NettyClient;
|
||||||
import jnet.lib.LogFile;
|
import jnet.lib.LogFile;
|
||||||
import jnet.lib.Message;
|
import jnet.lib.Message;
|
||||||
|
import jnet.lib.object.Connection;
|
||||||
import jnet.lib.object.Event;
|
import jnet.lib.object.Event;
|
||||||
import jnet.lib.object.Map;
|
import jnet.lib.object.Map;
|
||||||
import jnet.lib.object.MapObject;
|
import jnet.lib.object.MapObject;
|
||||||
|
|
@ -19,7 +20,6 @@ import jnet.lib.object.SnmpProfile;
|
||||||
import jnet.lib.object.User;
|
import jnet.lib.object.User;
|
||||||
import jnet.lib.snmp.DeviceInfo;
|
import jnet.lib.snmp.DeviceInfo;
|
||||||
import jnet.lib.snmp.Interface;
|
import jnet.lib.snmp.Interface;
|
||||||
import jnet.lib.snmp.SNMPTester;
|
|
||||||
|
|
||||||
public class ClientMessageParser {
|
public class ClientMessageParser {
|
||||||
|
|
||||||
|
|
@ -52,6 +52,10 @@ public class ClientMessageParser {
|
||||||
handlers.put(Message.SNMP_OBJECT_INFO, ClientMessageParser::handleSnmpObjectInfo);
|
handlers.put(Message.SNMP_OBJECT_INFO, ClientMessageParser::handleSnmpObjectInfo);
|
||||||
handlers.put(Message.SNMP_OBJECT_INTERFACE, ClientMessageParser::handleSnmpObjectInterface);
|
handlers.put(Message.SNMP_OBJECT_INTERFACE, ClientMessageParser::handleSnmpObjectInterface);
|
||||||
handlers.put(Message.SNMP_TEST, ClientMessageParser::handleSnmpTest);
|
handlers.put(Message.SNMP_TEST, ClientMessageParser::handleSnmpTest);
|
||||||
|
handlers.put(Message.SNMP_CONNECTION_INTERFACE, ClientMessageParser::handleSnmpConnectionInterface);
|
||||||
|
handlers.put(Message.CONNECTION_NEW, ClientMessageParser::handleConnectionNew);
|
||||||
|
handlers.put(Message.TRAFFIC, ClientMessageParser::handlerTraffic);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void parse(Message msg) {
|
public static void parse(Message msg) {
|
||||||
|
|
@ -101,7 +105,8 @@ public class ClientMessageParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void handleMap(Message msg) {
|
private static void handleMap(Message msg) {
|
||||||
Client.maps.add((Map) (Map) msg.getMsg());
|
Map map = (Map) (Map) msg.getMsg();
|
||||||
|
Client.maps.add(map);
|
||||||
// aktualizace UI
|
// aktualizace UI
|
||||||
UIUpdater.updateMapTree();
|
UIUpdater.updateMapTree();
|
||||||
UIUpdater.updateTray();
|
UIUpdater.updateTray();
|
||||||
|
|
@ -237,4 +242,34 @@ public class ClientMessageParser {
|
||||||
boolean result = (boolean) msg_obj[1];
|
boolean result = (boolean) msg_obj[1];
|
||||||
UIUpdater.showResultSnmpTest(frame, result);
|
UIUpdater.showResultSnmpTest(frame, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void handleSnmpConnectionInterface(Message msg) {
|
||||||
|
Object[] msg_obj = (Object[]) msg.getMsg();
|
||||||
|
String frame = (String) msg_obj[0];
|
||||||
|
List<Interface> iface = (List<Interface>) msg_obj[1];
|
||||||
|
UIUpdater.updateConnectionInterface(frame, iface);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void handleConnectionNew(Message msg) {
|
||||||
|
Connection c = (Connection) msg.getMsg();
|
||||||
|
for (Map map : Client.maps) {
|
||||||
|
if (map.getId() == c.getMap()) {
|
||||||
|
map.getConnection().add(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UIUpdater.updateMapView();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void handlerTraffic(Message msg) {
|
||||||
|
Object[] o = (Object[]) msg.getMsg();
|
||||||
|
for (Map map : Client.maps) {
|
||||||
|
for (Connection connection : map.getConnection()) {
|
||||||
|
if (connection.getId() == (int) o[0]) {
|
||||||
|
connection.setRx((long) o[1]);
|
||||||
|
connection.setTx((long) o[2]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,300 +0,0 @@
|
||||||
package jnet.client.gui;
|
|
||||||
|
|
||||||
import jnet.client.Client;
|
|
||||||
import jnet.client.ExtAppManager;
|
|
||||||
import jnet.client.gui.dialog.DialogLocalPing;
|
|
||||||
import jnet.client.network.NettyClient;
|
|
||||||
import java.awt.Point;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.awt.event.MouseEvent;
|
|
||||||
import java.awt.event.MouseListener;
|
|
||||||
import java.awt.event.MouseMotionListener;
|
|
||||||
import javax.swing.ImageIcon;
|
|
||||||
import javax.swing.JMenuItem;
|
|
||||||
import javax.swing.JPopupMenu;
|
|
||||||
import jnet.client.gui.dialog.object.ObjectDialog;
|
|
||||||
import jnet.lib.Message;
|
|
||||||
import jnet.lib.object.Map;
|
|
||||||
import jnet.lib.object.MapObject;
|
|
||||||
|
|
||||||
public class MapViewAction implements MouseMotionListener, MouseListener {
|
|
||||||
|
|
||||||
private Map map;
|
|
||||||
|
|
||||||
public MapViewAction(Map map) {
|
|
||||||
this.map = map;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static PaintObject selectedObject;
|
|
||||||
private static Point offset;
|
|
||||||
public static boolean createConnection = false;
|
|
||||||
public static PaintObject startConMapObject;
|
|
||||||
public static PaintObject endConMapObject;
|
|
||||||
public static Point endConnPoint;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseClicked(MouseEvent e) {
|
|
||||||
// vola se pri kliknuti v mape
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mousePressed(MouseEvent e) { // vola se pri stisknuti tlacitka
|
|
||||||
// vyhledani jestli se kliklo na nejaky objekt
|
|
||||||
if (MapView.paintObjects == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (PaintObject node : MapView.paintObjects) {
|
|
||||||
// zruseni vybrani na vsech objektech
|
|
||||||
node.setSelected(false);
|
|
||||||
if (node.contains(e.getPoint())) {
|
|
||||||
if (createConnection) { // vytvareni propojeni - startovni body
|
|
||||||
startConMapObject = node;
|
|
||||||
endConnPoint = e.getPoint();
|
|
||||||
} else {
|
|
||||||
selectedObject = node;
|
|
||||||
// nastaveni vybraneho objektu
|
|
||||||
offset = new Point(
|
|
||||||
(int) selectedObject.getBoxX() - e.getX(),
|
|
||||||
(int) selectedObject.getBoxY() - e.getY()
|
|
||||||
);
|
|
||||||
// zvyrazneni vybraneho objektu
|
|
||||||
selectedObject.setSelected(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseReleased(MouseEvent e) { // vola se pri uvolneni tlacitka
|
|
||||||
if (selectedObject != null) {
|
|
||||||
// presouvani objektu
|
|
||||||
if (!map.isLock()) {// povoli upravy jen kdyz neni mapa zamcena
|
|
||||||
// odeslani nove pozice objektu
|
|
||||||
// TODO doresit kontrolu souradnic aby se zbytecne neodesilala zmena kdyz k ni nedojde
|
|
||||||
// zkontrolovat zda došlo ke zmene pozice
|
|
||||||
int[] data = {
|
|
||||||
selectedObject.getId(),
|
|
||||||
(int) selectedObject.getX(),
|
|
||||||
(int) selectedObject.getY()
|
|
||||||
};
|
|
||||||
NettyClient.send(Message.OBJECT_MOVE, data);
|
|
||||||
}
|
|
||||||
// dvojklik na objekt
|
|
||||||
if (e.getClickCount() == 2) {
|
|
||||||
doubleClickOnObject(selectedObject);
|
|
||||||
}
|
|
||||||
// prave kliknuti na objekt
|
|
||||||
if (e.getButton() == MouseEvent.BUTTON3) {
|
|
||||||
rightClickOnObject(e, selectedObject);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// prave kliknuti do volneho mista v mape
|
|
||||||
if (e.getButton() == MouseEvent.BUTTON3) {
|
|
||||||
rigthClick(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
selectedObject = null;
|
|
||||||
offset = null;
|
|
||||||
|
|
||||||
if (createConnection) {
|
|
||||||
for (PaintObject node : MapView.paintObjects) {
|
|
||||||
if (node.contains(e.getPoint())) {
|
|
||||||
endConMapObject = node;
|
|
||||||
if (startConMapObject.getId() != endConMapObject.getId()) {
|
|
||||||
//new ObjectConnectionDialog(startConMapObject.getId(), endConMapObject.getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// zrusi vytvareni propojeni
|
|
||||||
createConnection = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseEntered(MouseEvent e) {
|
|
||||||
// vola se pri vstupu kurzoru
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseExited(MouseEvent e) {
|
|
||||||
// vola se pri opusteni kurzoru
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseDragged(MouseEvent e) {
|
|
||||||
//jen pokud neni mapa zamcena
|
|
||||||
if (!map.isLock() && Client.user.isEditMap()) {
|
|
||||||
// vytvareni propojeni
|
|
||||||
if (createConnection) {
|
|
||||||
for (PaintObject node : MapView.paintObjects) {
|
|
||||||
if (node.contains(e.getPoint())) {
|
|
||||||
endConnPoint = node.getPoint();
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
endConnPoint = e.getPoint();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// presunovani objektu
|
|
||||||
if (this.selectedObject != null && this.offset != null) {
|
|
||||||
// ziskani novych souradnic
|
|
||||||
Point to = e.getPoint();
|
|
||||||
to.x += offset.x;
|
|
||||||
to.y += offset.y;
|
|
||||||
//nastaveni nove pozice
|
|
||||||
selectedObject.setPosition(to);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseMoved(MouseEvent e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void doubleClickOnObject(PaintObject selectedObject) {
|
|
||||||
int id = selectedObject.getId();
|
|
||||||
for (Map map : Client.maps) {
|
|
||||||
for (MapObject object : map.getObjects()) {
|
|
||||||
if (object.getId() == id) {
|
|
||||||
//new ObjectDialog(map.getId(), object, false);
|
|
||||||
new ObjectDialog(object);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void rigthClick(MouseEvent me) {
|
|
||||||
JPopupMenu menu = new JPopupMenu();
|
|
||||||
// zamek mapy
|
|
||||||
JMenuItem itemLock;
|
|
||||||
if (map.isLock()) {
|
|
||||||
itemLock = new JMenuItem("Odemknout mapu", new ImageIcon("img/unlock.png"));
|
|
||||||
} else {
|
|
||||||
itemLock = new JMenuItem("Zamknout mapu", new ImageIcon("img/lock.png"));
|
|
||||||
}
|
|
||||||
itemLock.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
if (map.isLock()) {
|
|
||||||
int[] d = {map.getId(), 0};
|
|
||||||
NettyClient.send(Message.SET_MAP_LOCK, d);
|
|
||||||
} else {
|
|
||||||
int[] d = {map.getId(), 1};
|
|
||||||
NettyClient.send(Message.SET_MAP_LOCK, d);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
menu.add(itemLock);
|
|
||||||
|
|
||||||
// polozka pridat objekt
|
|
||||||
if (Client.user.isAddObject()) {
|
|
||||||
JMenuItem itemAdd = new JMenuItem("Přidat objekt", new ImageIcon("img/add.png"));
|
|
||||||
itemAdd.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
MapObject mo = new MapObject();
|
|
||||||
mo.setX(me.getX());
|
|
||||||
mo.setY(me.getY());
|
|
||||||
mo.setMap(map.getId());
|
|
||||||
new ObjectDialog(mo, true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
itemAdd.setEnabled(!map.isLock());
|
|
||||||
menu.add(itemAdd);
|
|
||||||
}
|
|
||||||
// polozka pridani propojeni
|
|
||||||
/*
|
|
||||||
JMenuItem itemPropoj = new JMenuItem("Přidat propojení", new ImageIcon("img/arrow.png"));
|
|
||||||
itemPropoj.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
startConMapObject = null;
|
|
||||||
endConnPoint = null;
|
|
||||||
createConnection = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
menu.add(itemPropoj);
|
|
||||||
*/
|
|
||||||
|
|
||||||
menu.show(me.getComponent(), me.getX(), me.getY());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void rightClickOnObject(MouseEvent e, PaintObject obj) {
|
|
||||||
JPopupMenu menu = new JPopupMenu();
|
|
||||||
if (obj.getObject().isWinbox()) {
|
|
||||||
JMenuItem itemWinbox = new JMenuItem("Winbox", new ImageIcon("img/winbox.png"));
|
|
||||||
itemWinbox.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
//AppLauncher.winbox(obj.getObject().getIp(), obj.getObject().getService().getPortWinbox(), obj.getObject().getUser(), obj.getObject().getPassword());
|
|
||||||
new ExtAppManager().runWinbox(obj.getObject().getIp(), obj.getObject().getUser(), obj.getObject().getPassword(), Integer.valueOf(obj.getObject().getWinboxPort()));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
menu.add(itemWinbox);
|
|
||||||
}
|
|
||||||
if (obj.getObject().isWeb()) {
|
|
||||||
JMenuItem itemWeb = new JMenuItem("Otevřít v prohlížeči", new ImageIcon("img/browser.png"));
|
|
||||||
itemWeb.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
new ExtAppManager().runWeb(obj.getObject().getWebVerze(), obj.getObject().getIp(), obj.getObject().getWebPort());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
menu.add(itemWeb);
|
|
||||||
}
|
|
||||||
if (obj.getObject().isSsh()) {
|
|
||||||
JMenuItem itemSsh = new JMenuItem("SSH", new ImageIcon("img/ssh.png"));
|
|
||||||
itemSsh.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
new ExtAppManager().runSshPutty(obj.getObject().getIp(), obj.getObject().getUser(), obj.getObject().getPassword(), Integer.parseInt(obj.getObject().getSshPort()));
|
|
||||||
//AppLauncher.ssh(obj.getObject().getIp(), obj.getObject().getUser(), obj.getObject().getPassword(), Integer.parseInt(obj.getObject().getService().getPortSsh()));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
menu.add(itemSsh);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ping na objekt
|
|
||||||
JMenuItem itemPingRemote = new JMenuItem("Ping", new ImageIcon("img/ping.png"));
|
|
||||||
itemPingRemote.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
menu.add(itemPingRemote);
|
|
||||||
|
|
||||||
// ping na objekt
|
|
||||||
JMenuItem itemPingLocal = new JMenuItem("Ping (lokální)", new ImageIcon("img/ping.png"));
|
|
||||||
itemPingLocal.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
DialogLocalPing dp = new DialogLocalPing(obj.getObject().getIp());
|
|
||||||
Thread pingThread = new Thread(dp);
|
|
||||||
pingThread.start();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
menu.add(itemPingLocal);
|
|
||||||
|
|
||||||
// odebrani objektu
|
|
||||||
if (Client.user.isRemoveObject()) {
|
|
||||||
JMenuItem itemRemove = new JMenuItem("Odebrat", new ImageIcon("img/trash.png"));
|
|
||||||
itemRemove.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
NettyClient.send(Message.REMOVE_OBJECT, obj.getId());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
itemRemove.setEnabled(!map.isLock());
|
|
||||||
menu.add(itemRemove);
|
|
||||||
}
|
|
||||||
|
|
||||||
// zobrazeni menu
|
|
||||||
menu.show(e.getComponent(), e.getX(), e.getY());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -7,7 +7,6 @@ import java.awt.FlowLayout;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
@ -30,7 +29,7 @@ class MenuPanel extends JPanel {
|
||||||
bLogin.addActionListener(new ActionListener() {
|
bLogin.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
if (NettyClient.isConnected()) {
|
if (NettyClient.isConnected()) {
|
||||||
NettyClient.disconnect();
|
NettyClient.disconnect();
|
||||||
} else {
|
} else {
|
||||||
new LoginDialog().setVisible(true);
|
new LoginDialog().setVisible(true);
|
||||||
|
|
|
||||||
|
|
@ -83,8 +83,8 @@ public class TableUsers extends JTable {
|
||||||
for (User u : Client.users) {
|
for (User u : Client.users) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
ImageIcon ii_yes = new ImageIcon(ImageIO.read(new File("img/yes.png")));
|
ImageIcon ii_yes = new ImageIcon(ImageIO.read(getClass().getResourceAsStream("img/yes.png")));
|
||||||
ImageIcon ii_no = new ImageIcon(ImageIO.read(new File("img/no.png")));
|
ImageIcon ii_no = new ImageIcon(ImageIO.read(getClass().getResourceAsStream("img/no.png")));
|
||||||
|
|
||||||
this.setValueAt(u.getId(), row, 0);
|
this.setValueAt(u.getId(), row, 0);
|
||||||
this.setValueAt(u.getUsername(), row, 1);
|
this.setValueAt(u.getUsername(), row, 1);
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
package jnet.client.gui;
|
package jnet.client.gui;
|
||||||
|
|
||||||
|
import jnet.client.gui.mapview.MapView;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.Window;
|
import java.awt.Window;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import jnet.client.gui.dialog.ConnectionDialog;
|
||||||
import jnet.client.gui.dialog.object.ObjectDialog;
|
import jnet.client.gui.dialog.object.ObjectDialog;
|
||||||
import jnet.lib.snmp.DeviceInfo;
|
import jnet.lib.snmp.DeviceInfo;
|
||||||
import jnet.lib.snmp.Interface;
|
import jnet.lib.snmp.Interface;
|
||||||
|
|
@ -67,4 +69,15 @@ public class UIUpdater {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void updateConnectionInterface(String frameName, List<Interface> iface) {
|
||||||
|
for (Window w : JFrame.getWindows()) {
|
||||||
|
if (w instanceof JFrame && frameName.equals(w.getName())) {
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
((ConnectionDialog) w).updateInterface(iface);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package jnet.client.gui;
|
package jnet.client.gui;
|
||||||
|
|
||||||
|
import jnet.client.gui.mapview.MapView;
|
||||||
import jnet.client.Client;
|
import jnet.client.Client;
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,207 @@
|
||||||
|
package jnet.client.gui.dialog;
|
||||||
|
|
||||||
|
import java.awt.HeadlessException;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.ItemEvent;
|
||||||
|
import java.awt.event.ItemListener;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import javax.swing.DefaultComboBoxModel;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JCheckBox;
|
||||||
|
import javax.swing.JComboBox;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import jnet.client.network.NettyClient;
|
||||||
|
import jnet.lib.Message;
|
||||||
|
import jnet.lib.object.Connection;
|
||||||
|
import jnet.lib.object.MapObject;
|
||||||
|
import jnet.lib.snmp.Interface;
|
||||||
|
|
||||||
|
public class ConnectionDialog extends JFrame {
|
||||||
|
|
||||||
|
private MapObject startObj;
|
||||||
|
private MapObject endObj;
|
||||||
|
private Boolean newObject;
|
||||||
|
private List<Interface> iface = new ArrayList<>();
|
||||||
|
|
||||||
|
private JComboBox<String> typComboBox = new JComboBox<String>(new DefaultComboBoxModel(new String[]{
|
||||||
|
"Neznámé",
|
||||||
|
"Gigabit Ethernet",
|
||||||
|
"Fast Ethernet",
|
||||||
|
"Ethernet",
|
||||||
|
"10G Ethernet",
|
||||||
|
"100M Fiber",
|
||||||
|
"1G Fiber",
|
||||||
|
"10G Fiber",
|
||||||
|
"Bezdrát",
|
||||||
|
"Tunel",
|
||||||
|
"VLAN"
|
||||||
|
}));
|
||||||
|
|
||||||
|
private JCheckBox readTraffic = new JCheckBox("Číst traffic");
|
||||||
|
private JComboBox<String> sourceDeviceComboBox = new JComboBox<>();
|
||||||
|
private JComboBox<Item> sourceInterfaceComboBox = new JComboBox<>();
|
||||||
|
|
||||||
|
public ConnectionDialog(MapObject startObj, MapObject endObj) throws HeadlessException {
|
||||||
|
this.startObj = startObj;
|
||||||
|
this.endObj = endObj;
|
||||||
|
this.newObject = false;
|
||||||
|
|
||||||
|
// identifikator okna
|
||||||
|
this.setName("connection_detail_" + Math.random());
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init() {
|
||||||
|
|
||||||
|
if (newObject) {
|
||||||
|
setTitle("Nové spojení");
|
||||||
|
} else {
|
||||||
|
setTitle("Vlastnosti spojení");
|
||||||
|
}
|
||||||
|
|
||||||
|
setSize(500, 500);
|
||||||
|
setLocationRelativeTo(null);
|
||||||
|
setAlwaysOnTop(false);
|
||||||
|
setResizable(false);
|
||||||
|
setVisible(true);
|
||||||
|
|
||||||
|
setLayout(null);
|
||||||
|
|
||||||
|
int x = 20;
|
||||||
|
|
||||||
|
JLabel firstLabel = new JLabel("1: " + startObj.getName());
|
||||||
|
firstLabel.setBounds(x, 10, 500, 25);
|
||||||
|
add(firstLabel);
|
||||||
|
|
||||||
|
JLabel secondLabel = new JLabel("2: " + endObj.getName());
|
||||||
|
secondLabel.setBounds(x, 40, 500, 25);
|
||||||
|
add(secondLabel);
|
||||||
|
|
||||||
|
JLabel typLabel = new JLabel("Typ spojení");
|
||||||
|
typLabel.setBounds(x, 100, 140, 25);
|
||||||
|
add(typLabel);
|
||||||
|
|
||||||
|
typComboBox.setBounds(200, 100, 200, 25);
|
||||||
|
add(typComboBox);
|
||||||
|
|
||||||
|
readTraffic.setBounds(x, 200, 200, 25);
|
||||||
|
readTraffic.addItemListener(new ItemListener() {
|
||||||
|
@Override
|
||||||
|
public void itemStateChanged(ItemEvent e) {
|
||||||
|
if (readTraffic.isSelected()) {
|
||||||
|
sourceDeviceComboBox.setEnabled(true);
|
||||||
|
sourceInterfaceComboBox.setEnabled(true);
|
||||||
|
loadIface();
|
||||||
|
} else {
|
||||||
|
sourceDeviceComboBox.setEnabled(false);
|
||||||
|
sourceInterfaceComboBox.setEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
add(readTraffic);
|
||||||
|
|
||||||
|
JLabel sourceDeviceLabel = new JLabel("Zdrojové zařízení:");
|
||||||
|
sourceDeviceLabel.setBounds(x, 250, 140, 25);
|
||||||
|
add(sourceDeviceLabel);
|
||||||
|
|
||||||
|
sourceDeviceComboBox.addItem(startObj.getName());
|
||||||
|
sourceDeviceComboBox.addItem(endObj.getName());
|
||||||
|
sourceDeviceComboBox.setEnabled(false);
|
||||||
|
sourceDeviceComboBox.setBounds(200, 250, 200, 25);
|
||||||
|
sourceDeviceComboBox.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
loadIface();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
add(sourceDeviceComboBox);
|
||||||
|
|
||||||
|
JLabel sourceInterfaceLabel = new JLabel("Zdrojové rozhraní:");
|
||||||
|
sourceInterfaceLabel.setBounds(x, 300, 140, 25);
|
||||||
|
add(sourceInterfaceLabel);
|
||||||
|
|
||||||
|
sourceInterfaceComboBox.setEnabled(false);
|
||||||
|
sourceInterfaceComboBox.setBounds(200, 300, 200, 25);
|
||||||
|
add(sourceInterfaceComboBox);
|
||||||
|
|
||||||
|
JButton saveButton = new JButton("Uložit");
|
||||||
|
saveButton.setBounds((getWidth() / 2) - 120, 400, 90, 25);
|
||||||
|
saveButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
save();
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
add(saveButton);
|
||||||
|
|
||||||
|
JButton closeButton = new JButton("Storno");
|
||||||
|
closeButton.setBounds((getWidth() / 2) + 30, 400, 90, 25);
|
||||||
|
closeButton.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
add(closeButton);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadIface() {
|
||||||
|
MapObject obj;
|
||||||
|
if (sourceDeviceComboBox.getSelectedIndex() == 0) {
|
||||||
|
obj = startObj;
|
||||||
|
} else {
|
||||||
|
obj = endObj;
|
||||||
|
}
|
||||||
|
Object[] o = {this.getName(), obj};
|
||||||
|
NettyClient.send(Message.SNMP_CONNECTION_INTERFACE, o);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateInterface(List<Interface> iface) {
|
||||||
|
this.iface = iface;
|
||||||
|
|
||||||
|
sourceInterfaceComboBox.removeAllItems();
|
||||||
|
|
||||||
|
for (Interface ifs : iface) {
|
||||||
|
sourceInterfaceComboBox.addItem(new Item(ifs.getId(), ifs.getDescription()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void save(){
|
||||||
|
Item sellectedIface = (Item) sourceInterfaceComboBox.getSelectedItem();
|
||||||
|
Connection c = new Connection(
|
||||||
|
startObj.getId(),
|
||||||
|
endObj.getId(),
|
||||||
|
typComboBox.getSelectedIndex(),
|
||||||
|
startObj.getMap(),
|
||||||
|
readTraffic.isSelected(),
|
||||||
|
sourceDeviceComboBox.getSelectedIndex() == 0 ? startObj.getId() : endObj.getId(),
|
||||||
|
sellectedIface.getId()
|
||||||
|
);
|
||||||
|
NettyClient.send(Message.CONNECTION_NEW, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
class Item {
|
||||||
|
|
||||||
|
private int id;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public Item(int id, String name) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return name; // Zobrazí se pouze název
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package jnet.client.gui.dialog.object;
|
package jnet.client.gui.dialog.object;
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Dialog;
|
|
||||||
import java.awt.Frame;
|
import java.awt.Frame;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
|
@ -52,7 +51,7 @@ public class ObjectDialog extends JFrame {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObjectDialog(MapObject obj, boolean newObject) {
|
public ObjectDialog(MapObject obj, boolean newObject) {
|
||||||
this.obj = new MapObject();
|
this.obj = obj;
|
||||||
this.mapId = obj.getMap();
|
this.mapId = obj.getMap();
|
||||||
this.newObject = newObject;
|
this.newObject = newObject;
|
||||||
init();
|
init();
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package jnet.client.gui;
|
package jnet.client.gui.mapview;
|
||||||
|
|
||||||
import jnet.client.Client;
|
import jnet.client.Client;
|
||||||
import jnet.client.network.NettyClient;
|
import jnet.client.network.NettyClient;
|
||||||
|
|
@ -7,7 +7,6 @@ import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -15,14 +14,15 @@ import javax.imageio.ImageIO;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.Timer;
|
import javax.swing.Timer;
|
||||||
import jnet.lib.LogFile;
|
import jnet.lib.LogFile;
|
||||||
|
import jnet.lib.object.Connection;
|
||||||
import jnet.lib.object.Map;
|
import jnet.lib.object.Map;
|
||||||
import jnet.lib.object.MapObject;
|
import jnet.lib.object.MapObject;
|
||||||
|
|
||||||
public class MapView extends JPanel {
|
public class MapView extends JPanel {
|
||||||
|
|
||||||
public static List<PaintObject> paintObjects = new ArrayList<>();
|
public static List<PaintObject> paintObjects = new ArrayList<>();
|
||||||
|
public static List<PaintConnection> paintConnection = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
private BufferedImage lockImage;
|
private BufferedImage lockImage;
|
||||||
private BufferedImage unlockImage;
|
private BufferedImage unlockImage;
|
||||||
|
|
||||||
|
|
@ -33,6 +33,7 @@ public class MapView extends JPanel {
|
||||||
|
|
||||||
LogFile.printDebug("View map: " + map.getName());
|
LogFile.printDebug("View map: " + map.getName());
|
||||||
paintObjects.clear();
|
paintObjects.clear();
|
||||||
|
paintConnection.clear();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
lockImage = ImageIO.read(getClass().getResourceAsStream("/img/lock.png"));
|
lockImage = ImageIO.read(getClass().getResourceAsStream("/img/lock.png"));
|
||||||
|
|
@ -41,6 +42,7 @@ public class MapView extends JPanel {
|
||||||
LogFile.printErr("File not found: " + ex);
|
LogFile.printErr("File not found: " + ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loadConnection(map.getId());
|
||||||
loadObject(map.getId());
|
loadObject(map.getId());
|
||||||
|
|
||||||
this.addMouseMotionListener(new MapViewAction(map));
|
this.addMouseMotionListener(new MapViewAction(map));
|
||||||
|
|
@ -66,6 +68,20 @@ public class MapView extends JPanel {
|
||||||
// vykresleni lock/unlock mapy
|
// vykresleni lock/unlock mapy
|
||||||
g.drawImage(map.isLock() ? lockImage : unlockImage, 0, 0, this);
|
g.drawImage(map.isLock() ? lockImage : unlockImage, 0, 0, this);
|
||||||
|
|
||||||
|
// vykresleni stavajicich propojeni
|
||||||
|
for (PaintConnection c : paintConnection) {
|
||||||
|
c.paint(g2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Kreslení nového propojení
|
||||||
|
if (MapViewAction.createConnection && MapViewAction.startConMapObject != null && MapViewAction.endConnPoint != null) {
|
||||||
|
g.setColor(Color.RED); // Barva propojení
|
||||||
|
g.drawLine(
|
||||||
|
MapViewAction.startConMapObject.getPoint().x, MapViewAction.startConMapObject.getPoint().y,
|
||||||
|
MapViewAction.endConnPoint.x, MapViewAction.endConnPoint.y
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// vykresleni objektu
|
// vykresleni objektu
|
||||||
for (PaintObject paintObject : paintObjects) {
|
for (PaintObject paintObject : paintObjects) {
|
||||||
paintObject.paint(g2);
|
paintObject.paint(g2);
|
||||||
|
|
@ -81,7 +97,7 @@ public class MapView extends JPanel {
|
||||||
loadObject(map.getId());
|
loadObject(map.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateMapView() {
|
public static void updateMapView() {
|
||||||
if (map.equals(MapView.map)) {
|
if (map.equals(MapView.map)) {
|
||||||
// obnoveni objektu
|
// obnoveni objektu
|
||||||
|
|
@ -99,7 +115,16 @@ public class MapView extends JPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void loadConnection(int mapId) {
|
||||||
|
for (Map map : Client.maps) {
|
||||||
|
for (Connection con : map.getConnection()) {
|
||||||
|
if (con.getMap() == mapId) {
|
||||||
|
paintConnection.add(new PaintConnection(con));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,300 @@
|
||||||
|
package jnet.client.gui.mapview;
|
||||||
|
|
||||||
|
import jnet.client.Client;
|
||||||
|
import jnet.client.ExtAppManager;
|
||||||
|
import jnet.client.gui.dialog.DialogLocalPing;
|
||||||
|
import jnet.client.network.NettyClient;
|
||||||
|
import java.awt.Point;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.event.MouseListener;
|
||||||
|
import java.awt.event.MouseMotionListener;
|
||||||
|
import java.io.IOException;
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
|
import javax.swing.JMenuItem;
|
||||||
|
import javax.swing.JPopupMenu;
|
||||||
|
import jnet.client.gui.dialog.ConnectionDialog;
|
||||||
|
import jnet.client.gui.dialog.object.ObjectDialog;
|
||||||
|
import jnet.lib.LogFile;
|
||||||
|
import jnet.lib.Message;
|
||||||
|
import jnet.lib.object.Map;
|
||||||
|
import jnet.lib.object.MapObject;
|
||||||
|
|
||||||
|
public class MapViewAction implements MouseMotionListener, MouseListener {
|
||||||
|
|
||||||
|
private Map map;
|
||||||
|
|
||||||
|
public MapViewAction(Map map) {
|
||||||
|
this.map = map;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PaintObject selectedObject;
|
||||||
|
private static Point offset;
|
||||||
|
public static boolean createConnection = false;
|
||||||
|
public static PaintObject startConMapObject;
|
||||||
|
public static PaintObject endConMapObject;
|
||||||
|
public static Point endConnPoint;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
// vola se pri kliknuti v mape
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent e) { // vola se pri stisknuti tlacitka
|
||||||
|
// vyhledani jestli se kliklo na nejaky objekt
|
||||||
|
if (MapView.paintObjects == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
selectedObject = findObjectAt(e.getPoint());
|
||||||
|
|
||||||
|
if (selectedObject != null) {
|
||||||
|
handleObjectSelection(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseReleased(MouseEvent e) { // vola se pri uvolneni tlacitka
|
||||||
|
if (selectedObject != null) {
|
||||||
|
handleObjectRelease(e);
|
||||||
|
} else if (e.getButton() == MouseEvent.BUTTON3) {
|
||||||
|
rigthClick(e);
|
||||||
|
}
|
||||||
|
selectedObject = null;
|
||||||
|
offset = null;
|
||||||
|
|
||||||
|
if (createConnection && startConMapObject != null) {
|
||||||
|
endConMapObject = findObjectAt(e.getPoint());
|
||||||
|
if (endConMapObject != null && endConMapObject != startConMapObject) {
|
||||||
|
// Uložení propojení mezi objekty
|
||||||
|
new ConnectionDialog(startConMapObject.getObject(), endConMapObject.getObject());
|
||||||
|
}
|
||||||
|
createConnection = false;
|
||||||
|
startConMapObject = null;
|
||||||
|
endConMapObject = null;
|
||||||
|
endConnPoint = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseEntered(MouseEvent e) {
|
||||||
|
// vola se pri vstupu kurzoru
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseExited(MouseEvent e) {
|
||||||
|
// vola se pri opusteni kurzoru
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseDragged(MouseEvent e) {
|
||||||
|
if (map.isLock() || !Client.user.isEditMap()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (createConnection) {
|
||||||
|
endConnPoint = findNearestObject(e.getPoint());
|
||||||
|
} else if (selectedObject != null && offset != null) {
|
||||||
|
moveObject(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseMoved(MouseEvent e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private PaintObject findObjectAt(Point p) {
|
||||||
|
for (PaintObject node : MapView.paintObjects) {
|
||||||
|
node.setSelected(false);
|
||||||
|
if (node.contains(p)) {
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Point findNearestObject(Point p) {
|
||||||
|
for (PaintObject node : MapView.paintObjects) {
|
||||||
|
if (node.contains(p)) {
|
||||||
|
return node.getPoint();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleObjectSelection(MouseEvent e) {
|
||||||
|
selectedObject.setSelected(true);
|
||||||
|
|
||||||
|
if (createConnection) {
|
||||||
|
startConMapObject = selectedObject;
|
||||||
|
endConnPoint = e.getPoint();
|
||||||
|
} else {
|
||||||
|
offset = new Point(
|
||||||
|
selectedObject.getBoxX() - e.getX(),
|
||||||
|
selectedObject.getBoxY() - e.getY()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleObjectRelease(MouseEvent e) {
|
||||||
|
if (!map.isLock() && positionChanged()) {
|
||||||
|
NettyClient.send(Message.OBJECT_MOVE, new int[]{
|
||||||
|
selectedObject.getId(),
|
||||||
|
(int) selectedObject.getX(),
|
||||||
|
(int) selectedObject.getY()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (e.getClickCount() == 2) {
|
||||||
|
doubleClickOnObject(selectedObject);
|
||||||
|
}
|
||||||
|
if (e.getButton() == MouseEvent.BUTTON3) {
|
||||||
|
rightClickOnObject(e, selectedObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean positionChanged() {
|
||||||
|
return offset != null && (offset.x != 0 || offset.y != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void moveObject(MouseEvent e) {
|
||||||
|
Point to = new Point(e.getX() + offset.x, e.getY() + offset.y);
|
||||||
|
selectedObject.setPosition(to);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doubleClickOnObject(PaintObject selectedObject) {
|
||||||
|
int id = selectedObject.getId();
|
||||||
|
for (Map map : Client.maps) {
|
||||||
|
for (MapObject object : map.getObjects()) {
|
||||||
|
if (object.getId() == id) {
|
||||||
|
//new ObjectDialog(map.getId(), object, false);
|
||||||
|
new ObjectDialog(object);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void rigthClick(MouseEvent me) {
|
||||||
|
JPopupMenu menu = new JPopupMenu();
|
||||||
|
// zamek mapy
|
||||||
|
JMenuItem itemLock;
|
||||||
|
if (map.isLock()) {
|
||||||
|
itemLock = new JMenuItem("Odemknout mapu", loadImageIcon("/img/unlock.png"));
|
||||||
|
} else {
|
||||||
|
itemLock = new JMenuItem("Zamknout mapu", loadImageIcon("/img/lock.png"));
|
||||||
|
}
|
||||||
|
itemLock.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (map.isLock()) {
|
||||||
|
int[] d = {map.getId(), 0};
|
||||||
|
NettyClient.send(Message.SET_MAP_LOCK, d);
|
||||||
|
} else {
|
||||||
|
int[] d = {map.getId(), 1};
|
||||||
|
NettyClient.send(Message.SET_MAP_LOCK, d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
menu.add(itemLock);
|
||||||
|
|
||||||
|
// polozka pridat objekt
|
||||||
|
if (Client.user.isAddObject()) {
|
||||||
|
JMenuItem itemAdd = createMenuAction("Přidat objekt", "/img/add.png", new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
MapObject mo = new MapObject();
|
||||||
|
mo.setX(me.getX());
|
||||||
|
mo.setY(me.getY());
|
||||||
|
mo.setMap(map.getId());
|
||||||
|
new ObjectDialog(mo, true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
itemAdd.setEnabled(!map.isLock());
|
||||||
|
menu.add(itemAdd);
|
||||||
|
}
|
||||||
|
// polozka pridani propojeni
|
||||||
|
JMenuItem itemPropoj = createMenuAction("Přidat propojení", "/img/arrow.png", new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
startConMapObject = null;
|
||||||
|
endConnPoint = null;
|
||||||
|
createConnection = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
menu.add(itemPropoj);
|
||||||
|
|
||||||
|
menu.show(me.getComponent(), me.getX(), me.getY());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void rightClickOnObject(MouseEvent e, PaintObject obj) {
|
||||||
|
JPopupMenu menu = new JPopupMenu();
|
||||||
|
if (obj.getObject().isWinbox()) {
|
||||||
|
JMenuItem itemWinbox = createMenuAction("Winbox", "/img/winbox.png", ()
|
||||||
|
-> new ExtAppManager().runWinbox(obj.getObject().getIp(), obj.getObject().getUser(), obj.getObject().getPassword(), Integer.valueOf(obj.getObject().getWinboxPort()))
|
||||||
|
);
|
||||||
|
menu.add(itemWinbox);
|
||||||
|
}
|
||||||
|
if (obj.getObject().isWeb()) {
|
||||||
|
JMenuItem itemWeb = createMenuAction("Otevřít v prohlížeči", "/img/browser.png", ()
|
||||||
|
-> new ExtAppManager().runWeb(obj.getObject().getWebVerze(), obj.getObject().getIp(), obj.getObject().getWebPort())
|
||||||
|
);
|
||||||
|
menu.add(itemWeb);
|
||||||
|
}
|
||||||
|
if (obj.getObject().isSsh()) {
|
||||||
|
JMenuItem itemSsh = createMenuAction("SSH", "/img/ssh.png", ()
|
||||||
|
-> new ExtAppManager().runSshPutty(obj.getObject().getIp(), obj.getObject().getUser(), obj.getObject().getPassword(), Integer.parseInt(obj.getObject().getSshPort()))
|
||||||
|
);
|
||||||
|
menu.add(itemSsh);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ping na objekt
|
||||||
|
JMenuItem itemPingRemote = new JMenuItem("Ping", loadImageIcon("/img/ping.png"));
|
||||||
|
itemPingRemote.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
menu.add(itemPingRemote);
|
||||||
|
|
||||||
|
// ping na objekt
|
||||||
|
JMenuItem itemPingLocal = createMenuAction("Ping (lokální)", "/img/ping.png", new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
DialogLocalPing dp = new DialogLocalPing(obj.getObject().getIp());
|
||||||
|
Thread pingThread = new Thread(dp);
|
||||||
|
pingThread.start();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
menu.add(itemPingLocal);
|
||||||
|
|
||||||
|
// odebrani objektu
|
||||||
|
if (Client.user.isRemoveObject()) {
|
||||||
|
JMenuItem itemRemove = createMenuAction("Odebrat", "/img/trash.png", () -> NettyClient.send(Message.REMOVE_OBJECT, obj.getId()));
|
||||||
|
itemRemove.setEnabled(!map.isLock());
|
||||||
|
menu.add(itemRemove);
|
||||||
|
}
|
||||||
|
|
||||||
|
// zobrazeni menu
|
||||||
|
menu.show(e.getComponent(), e.getX(), e.getY());
|
||||||
|
}
|
||||||
|
|
||||||
|
private ImageIcon loadImageIcon(String path) {
|
||||||
|
try {
|
||||||
|
return new ImageIcon(ImageIO.read(MapViewAction.class.getResourceAsStream(path)));
|
||||||
|
} catch (IOException ex) {
|
||||||
|
LogFile.printErr("MapView error: " + ex.getMessage());
|
||||||
|
return null; // nebo nějaká výchozí ikona
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private JMenuItem createMenuAction(String label, String iconPath, Runnable action) {
|
||||||
|
JMenuItem menuItem = new JMenuItem(label, loadImageIcon(iconPath));
|
||||||
|
menuItem.addActionListener(e -> action.run());
|
||||||
|
return menuItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,183 @@
|
||||||
|
package jnet.client.gui.mapview;
|
||||||
|
|
||||||
|
import java.awt.BasicStroke;
|
||||||
|
import java.awt.Canvas;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.FontMetrics;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Point;
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
import java.awt.RenderingHints;
|
||||||
|
import java.awt.geom.AffineTransform;
|
||||||
|
import java.awt.geom.Line2D;
|
||||||
|
import java.awt.geom.RoundRectangle2D;
|
||||||
|
import jnet.client.Client;
|
||||||
|
import jnet.lib.object.Connection;
|
||||||
|
import jnet.lib.object.Map;
|
||||||
|
import jnet.lib.object.MapObject;
|
||||||
|
|
||||||
|
public class PaintConnection extends Rectangle {
|
||||||
|
|
||||||
|
private Connection con;
|
||||||
|
private Graphics2D g2;
|
||||||
|
private Point from = null;
|
||||||
|
private Point to = null;
|
||||||
|
private String connection_text;
|
||||||
|
private Font font = new Font("Helvetica", Font.PLAIN, 10);
|
||||||
|
|
||||||
|
public PaintConnection(Connection con) {
|
||||||
|
this.con = con;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void paint(Graphics g) {
|
||||||
|
|
||||||
|
refreshData();
|
||||||
|
|
||||||
|
g2 = (Graphics2D) g.create();
|
||||||
|
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
|
|
||||||
|
switch (con.getType()) {
|
||||||
|
case Connection.TYPE_OTHER:
|
||||||
|
g2.setStroke(new BasicStroke(5));
|
||||||
|
connection_text = "";
|
||||||
|
break;
|
||||||
|
case Connection.TYPE_GE:
|
||||||
|
g2.setStroke(new BasicStroke(5));
|
||||||
|
connection_text = "GE";
|
||||||
|
break;
|
||||||
|
case Connection.TYPE_FE:
|
||||||
|
g2.setStroke(new BasicStroke(3));
|
||||||
|
connection_text = "FE";
|
||||||
|
break;
|
||||||
|
case Connection.TYPE_E:
|
||||||
|
g2.setStroke(new BasicStroke(1));
|
||||||
|
connection_text = "E";
|
||||||
|
break;
|
||||||
|
case Connection.TYPE_10GE:
|
||||||
|
g2.setStroke(new BasicStroke(5)); // TODO doresit tvar cary
|
||||||
|
connection_text = "10 GE";
|
||||||
|
break;
|
||||||
|
case Connection.TYPE_100M_FIBER:
|
||||||
|
g2.setStroke(new BasicStroke(5)); // TODO doresit tvar cary
|
||||||
|
connection_text = "100M Fiber";
|
||||||
|
break;
|
||||||
|
case Connection.TYPE_1G_FIBER:
|
||||||
|
g2.setStroke(new BasicStroke(5)); // TODO doresit tvar cary
|
||||||
|
connection_text = "1G Fiber";
|
||||||
|
break;
|
||||||
|
case Connection.TYPE_10G_FIBER:
|
||||||
|
g2.setStroke(new BasicStroke(5)); // TODO doresit tvar cary
|
||||||
|
connection_text = "10G Fiber";
|
||||||
|
break;
|
||||||
|
case Connection.TYPE_WIRELESS:
|
||||||
|
float[] dashingPattern = {2f, 2f};
|
||||||
|
g2.setStroke(new BasicStroke(2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1.0f, dashingPattern, 2.0f));
|
||||||
|
connection_text = "Wireless";
|
||||||
|
break;
|
||||||
|
case Connection.TYPE_TUNEL:
|
||||||
|
g2.setStroke(new BasicStroke(5)); // TODO doresit tvar cary
|
||||||
|
connection_text = "Tunel";
|
||||||
|
break;
|
||||||
|
case Connection.TYPE_VLAN:
|
||||||
|
g2.setStroke(new BasicStroke(5)); // TODO doresit tvar cary
|
||||||
|
connection_text = "VLAN";
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
g2.draw(new Line2D.Double(this.from, this.to));
|
||||||
|
|
||||||
|
// stred cary
|
||||||
|
int stredX = (from.x + to.x) / 2; // Střed čáry (x)
|
||||||
|
int stredY = (from.y + to.y) / 2; // Střed čáry (y)
|
||||||
|
|
||||||
|
if (con.isReadTraffic()) {
|
||||||
|
// vyska, sirka
|
||||||
|
int sirka = 80;
|
||||||
|
int vyska = 42;
|
||||||
|
|
||||||
|
// vypocitani pocatecnich bodu
|
||||||
|
int x = stredX - sirka / 2;
|
||||||
|
int y = stredY - vyska / 2;
|
||||||
|
|
||||||
|
// TODO az bude vyresni detekce kliku na caru tak tyto promenen uplne zrusit
|
||||||
|
int xObdelnik, x2Obdelnik, yObdelnik, y2Obdelnik;
|
||||||
|
xObdelnik = x;
|
||||||
|
x2Obdelnik = x + sirka;
|
||||||
|
yObdelnik = y;
|
||||||
|
y2Obdelnik = y + vyska;
|
||||||
|
|
||||||
|
// zmeni barvu na cernou
|
||||||
|
g2.setPaint(new Color(220, 220, 220));
|
||||||
|
|
||||||
|
// vykresli oblast pro rx, tx
|
||||||
|
RoundRectangle2D.Double box = new RoundRectangle2D.Double(x, y, sirka, vyska, 10, 10);
|
||||||
|
g2.fill(box);
|
||||||
|
|
||||||
|
// zmeni barvu na cernou
|
||||||
|
g2.setPaint(new Color(0, 0, 0));
|
||||||
|
|
||||||
|
// nastavi font
|
||||||
|
g2.setFont(font);
|
||||||
|
|
||||||
|
// vypise typ
|
||||||
|
g2.drawString(connection_text, x + (int) (box.getWidth() / 2) - (getStringWidth(connection_text) / 2), y + 12);
|
||||||
|
|
||||||
|
// vypise TX
|
||||||
|
String tx = "Tx: " + con.getTx();
|
||||||
|
g2.drawString(tx, x + (int) (box.getWidth() / 2) - (getStringWidth(tx) / 2), y + 24);
|
||||||
|
|
||||||
|
// vypise RX
|
||||||
|
String rx = "Rx: " + con.getRx();
|
||||||
|
g2.drawString(rx, x + (int) (box.getWidth() / 2) - (getStringWidth(rx) / 2), y + 36);
|
||||||
|
} else {
|
||||||
|
// Výpočet úhlu otočení
|
||||||
|
double angle = Math.atan2(to.y - from.y, to.x - from.x);
|
||||||
|
|
||||||
|
// Uložení aktuálního transformu
|
||||||
|
AffineTransform oldTransform = g2.getTransform();
|
||||||
|
|
||||||
|
// Vytvoření nového transformu pro otočení textu
|
||||||
|
AffineTransform transform = new AffineTransform();
|
||||||
|
transform.translate(stredX, stredY); // Přesun do středu čáry
|
||||||
|
transform.rotate(angle); // Otočení podle úhlu čáry
|
||||||
|
|
||||||
|
g2.setTransform(transform);
|
||||||
|
g2.setColor(Color.RED);
|
||||||
|
|
||||||
|
// Posunutí textu, aby byl lépe vidět (mírně nad čárou)
|
||||||
|
g2.drawString(connection_text, -g2.getFontMetrics().stringWidth(connection_text) / 2, -5);
|
||||||
|
|
||||||
|
// Obnovení původního transformu
|
||||||
|
g2.setTransform(oldTransform);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void refreshData() {
|
||||||
|
// ziskani souradnic
|
||||||
|
for (Map map : Client.maps) {
|
||||||
|
if (con.getMap() == map.getId()) {
|
||||||
|
for (MapObject obj : map.getObjects()) {
|
||||||
|
if (obj.getId() == con.getSourceObj()) {
|
||||||
|
from = new Point(obj.getX(), obj.getY());
|
||||||
|
}
|
||||||
|
if (obj.getId() == con.getDestinationObj()) {
|
||||||
|
to = new Point(obj.getX(), obj.getY());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getStringWidth(String text) {
|
||||||
|
//return g.getFontMetrics().stringWidth(text);
|
||||||
|
Canvas c = new Canvas();
|
||||||
|
FontMetrics fm = c.getFontMetrics(font);
|
||||||
|
return fm.stringWidth(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package jnet.client.gui;
|
package jnet.client.gui.mapview;
|
||||||
|
|
||||||
import jnet.client.Client;
|
import jnet.client.Client;
|
||||||
import java.awt.BasicStroke;
|
import java.awt.BasicStroke;
|
||||||
Loading…
Reference in New Issue