Compare commits
No commits in common. "da11df8f295af43092e59f1b683b4f1e3fa42c60" and "a3681616bdc907ff18996bc5a1488b1cfe1d3a49" have entirely different histories.
da11df8f29
...
a3681616bd
|
|
@ -1,14 +0,0 @@
|
||||||
autoconnect = true
|
|
||||||
debug = true
|
|
||||||
port = 1225
|
|
||||||
server = localhost
|
|
||||||
user = michal
|
|
||||||
volume = 75
|
|
||||||
start_minimalized = false
|
|
||||||
password = Michal2407
|
|
||||||
sound = true
|
|
||||||
debuger = true
|
|
||||||
sound_one_online=sound/schema1/one_online.wav
|
|
||||||
sound_next_offline=sound/schema1/next_offline.wav
|
|
||||||
sound_all_online = sound/schema1/all_online.wav
|
|
||||||
sound_first_offline=sound/schema1/first_offline.wav
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 3.2 KiB |
|
|
@ -71,6 +71,9 @@ public class Client {
|
||||||
LogFile.printDebug("Debug mode on");
|
LogFile.printDebug("Debug mode on");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// okno
|
||||||
|
///
|
||||||
///
|
///
|
||||||
/// tray icon
|
/// tray icon
|
||||||
///
|
///
|
||||||
|
|
@ -90,8 +93,6 @@ public class Client {
|
||||||
clientThread = new Thread(client);
|
clientThread = new Thread(client);
|
||||||
clientThread.start();
|
clientThread.start();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,12 @@ package jnet.client;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import jnet.client.gui.UIUpdater;
|
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;
|
||||||
|
|
@ -18,8 +16,6 @@ import jnet.lib.object.OnlineClients;
|
||||||
import jnet.lib.object.ServerConfig;
|
import jnet.lib.object.ServerConfig;
|
||||||
import jnet.lib.object.SnmpProfile;
|
import jnet.lib.object.SnmpProfile;
|
||||||
import jnet.lib.object.User;
|
import jnet.lib.object.User;
|
||||||
import jnet.lib.snmp.DeviceInfo;
|
|
||||||
import jnet.lib.snmp.Interface;
|
|
||||||
|
|
||||||
public class ClientMessageParser {
|
public class ClientMessageParser {
|
||||||
|
|
||||||
|
|
@ -49,14 +45,6 @@ public class ClientMessageParser {
|
||||||
handlers.put(Message.USER_EDIT, ClientMessageParser::handleUserEdit);
|
handlers.put(Message.USER_EDIT, ClientMessageParser::handleUserEdit);
|
||||||
handlers.put(Message.DELETE_LOG, ClientMessageParser::handleDeleteLog);
|
handlers.put(Message.DELETE_LOG, ClientMessageParser::handleDeleteLog);
|
||||||
handlers.put(Message.SERVER_CONFIG, ClientMessageParser::handleServerConfig);
|
handlers.put(Message.SERVER_CONFIG, ClientMessageParser::handleServerConfig);
|
||||||
handlers.put(Message.SNMP_OBJECT_INFO, ClientMessageParser::handleSnmpObjectInfo);
|
|
||||||
handlers.put(Message.SNMP_OBJECT_INTERFACE, ClientMessageParser::handleSnmpObjectInterface);
|
|
||||||
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);
|
|
||||||
handlers.put(Message.CONNECTION_UPDATE, ClientMessageParser::handlerConnectionUpdate);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void parse(Message msg) {
|
public static void parse(Message msg) {
|
||||||
|
|
@ -106,8 +94,7 @@ public class ClientMessageParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void handleMap(Message msg) {
|
private static void handleMap(Message msg) {
|
||||||
Map map = (Map) (Map) msg.getMsg();
|
Client.maps.add((Map) (Map) msg.getMsg());
|
||||||
Client.maps.add(map);
|
|
||||||
// aktualizace UI
|
// aktualizace UI
|
||||||
UIUpdater.updateMapTree();
|
UIUpdater.updateMapTree();
|
||||||
UIUpdater.updateTray();
|
UIUpdater.updateTray();
|
||||||
|
|
@ -223,70 +210,4 @@ public class ClientMessageParser {
|
||||||
Client.serverConfig = (ServerConfig) msg.getMsg();
|
Client.serverConfig = (ServerConfig) msg.getMsg();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void handleSnmpObjectInfo(Message msg) {
|
|
||||||
Object[] msg_obj = (Object[]) msg.getMsg();
|
|
||||||
String frame = (String) msg_obj[0];
|
|
||||||
DeviceInfo di = (DeviceInfo) msg_obj[1];
|
|
||||||
UIUpdater.updateObjectInfo(frame, di);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void handleSnmpObjectInterface(Message msg) {
|
|
||||||
Object[] msg_obj = (Object[]) msg.getMsg();
|
|
||||||
String frame = (String) msg_obj[0];
|
|
||||||
List<Interface> iface = (List<Interface>) msg_obj[1];
|
|
||||||
UIUpdater.updateObjectInterface(frame, iface);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void handleSnmpTest(Message msg) {
|
|
||||||
Object[] msg_obj = (Object[]) msg.getMsg();
|
|
||||||
String frame = (String) msg_obj[0];
|
|
||||||
boolean result = (boolean) msg_obj[1];
|
|
||||||
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);
|
|
||||||
System.out.println("jnet.client.ClientMessageParser.handleConnectionNew()");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void handlerConnectionUpdate(Message msg) {
|
|
||||||
Connection c = (Connection) msg.getMsg();
|
|
||||||
// upravi v seznamu
|
|
||||||
for (Map map : Client.maps) {
|
|
||||||
List<Connection> connections = map.getConnection();
|
|
||||||
for (int i = 0; i < connections.size(); i++) {
|
|
||||||
if (connections.get(i).getId() == c.getId()) {
|
|
||||||
connections.set(i, c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// update map view
|
|
||||||
UIUpdater.updateMapView();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,7 @@ import java.awt.event.ActionListener;
|
||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.event.MouseListener;
|
import java.awt.event.MouseListener;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
import javax.swing.JMenuItem;
|
import javax.swing.JMenuItem;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
|
|
@ -82,8 +80,7 @@ public class MapTree extends JTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void getContextMenuMap(MouseEvent e, Map m) {
|
private static void getContextMenuMap(MouseEvent e, Map m) {
|
||||||
try {
|
JMenuItem mapAdd = new JMenuItem("Přidat mapu", new ImageIcon("img/add.png"));
|
||||||
JMenuItem mapAdd = new JMenuItem("Přidat mapu", new ImageIcon(ImageIO.read(MapTree.class.getResourceAsStream("/img/add.png"))));
|
|
||||||
mapAdd.addActionListener(new ActionListener() {
|
mapAdd.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
|
@ -91,7 +88,7 @@ public class MapTree extends JTree {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
JMenuItem mapDelete = new JMenuItem("Smazat mapu", new ImageIcon(ImageIO.read(MapTree.class.getResourceAsStream("/img/trash.png"))));
|
JMenuItem mapDelete = new JMenuItem("Smazat mapu", new ImageIcon("img/trash.png"));
|
||||||
mapDelete.addActionListener(new ActionListener() {
|
mapDelete.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
|
@ -116,9 +113,6 @@ public class MapTree extends JTree {
|
||||||
menu.add(mapDelete);
|
menu.add(mapDelete);
|
||||||
}
|
}
|
||||||
menu.show(e.getComponent(), e.getX(), e.getY());
|
menu.show(e.getComponent(), e.getX(), e.getY());
|
||||||
} catch (IOException ex) {
|
|
||||||
LogFile.printErr("MapTree error: " + ex.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void expandAllNodes(JTree tree, int startingIndex, int rowCount) {
|
private static void expandAllNodes(JTree tree, int startingIndex, int rowCount) {
|
||||||
|
|
@ -132,13 +126,13 @@ public class MapTree extends JTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reload() {
|
public static void reload() {
|
||||||
try {
|
|
||||||
root.removeAllChildren();
|
root.removeAllChildren();
|
||||||
Collections.sort(Client.maps, new MapComparator());
|
Collections.sort(Client.maps, new MapComparator());
|
||||||
for (Map map : Client.maps) {
|
for (Map map : Client.maps) {
|
||||||
DefaultMutableTreeNode node = new DefaultMutableTreeNode(map);
|
DefaultMutableTreeNode node = new DefaultMutableTreeNode(map);
|
||||||
root.add(node);
|
root.add(node);
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
model.reload();
|
model.reload();
|
||||||
expandAllNodes(tree, 0, tree.getRowCount());
|
expandAllNodes(tree, 0, tree.getRowCount());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package jnet.client.gui.mapview;
|
package jnet.client.gui;
|
||||||
|
|
||||||
import jnet.client.Client;
|
import jnet.client.Client;
|
||||||
import jnet.client.network.NettyClient;
|
import jnet.client.network.NettyClient;
|
||||||
|
|
@ -7,6 +7,7 @@ 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;
|
||||||
|
|
@ -14,14 +15,13 @@ 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,21 +33,18 @@ 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(new File("img/lock.png"));
|
||||||
unlockImage = ImageIO.read(getClass().getResourceAsStream("/img/unlock.png"));
|
unlockImage = ImageIO.read(new File("img/unlock.png"));
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
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));
|
||||||
this.addMouseListener(new MapViewAction(map));
|
this.addMouseListener(new MapViewAction(map));
|
||||||
this.addMouseListener(new ConnectionListener());
|
|
||||||
|
|
||||||
// periodicke prekreslovani
|
// periodicke prekreslovani
|
||||||
Timer timer = new Timer(100, (ActionEvent ae) -> {
|
Timer timer = new Timer(100, (ActionEvent ae) -> {
|
||||||
|
|
@ -69,20 +66,6 @@ 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);
|
||||||
|
|
@ -92,20 +75,15 @@ public class MapView extends JPanel {
|
||||||
|
|
||||||
public static void updateMapView(Map map) {
|
public static void updateMapView(Map map) {
|
||||||
if (map.equals(MapView.map)) {
|
if (map.equals(MapView.map)) {
|
||||||
// obnoveni propojeni
|
|
||||||
paintConnection.clear();
|
|
||||||
loadConnection(map.getId());
|
|
||||||
// obnoveni objektu
|
// obnoveni objektu
|
||||||
paintObjects.clear();
|
paintObjects.clear();
|
||||||
|
// nahrat objekty
|
||||||
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 propojeni
|
|
||||||
paintConnection.clear();
|
|
||||||
loadConnection(map.getId());
|
|
||||||
// obnoveni objektu
|
// obnoveni objektu
|
||||||
paintObjects.clear();
|
paintObjects.clear();
|
||||||
// nahrat objekty
|
// nahrat objekty
|
||||||
|
|
@ -121,16 +99,7 @@ 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,299 @@
|
||||||
|
package jnet.client.gui;
|
||||||
|
|
||||||
|
import jnet.client.gui.dialog.ObjectDialog;
|
||||||
|
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.util.Iterator;
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
|
import javax.swing.JMenuItem;
|
||||||
|
import javax.swing.JPopupMenu;
|
||||||
|
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);
|
||||||
|
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());
|
||||||
|
new ObjectDialog(map.getId(), 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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package jnet.client.gui;
|
package jnet.client.gui;
|
||||||
|
|
||||||
import jnet.client.gui.serversettings.ServerSettingsPanel;
|
|
||||||
import jnet.client.gui.dialog.LoginDialog;
|
import jnet.client.gui.dialog.LoginDialog;
|
||||||
import jnet.client.network.NettyClient;
|
import jnet.client.network.NettyClient;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
|
|
@ -8,6 +7,7 @@ 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.*;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package jnet.client.gui.mapview;
|
package jnet.client.gui;
|
||||||
|
|
||||||
import jnet.client.Client;
|
import jnet.client.Client;
|
||||||
import java.awt.BasicStroke;
|
import java.awt.BasicStroke;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package jnet.client.gui.serversettings;
|
package jnet.client.gui;
|
||||||
|
|
||||||
import jnet.client.Client;
|
import jnet.client.Client;
|
||||||
import jnet.client.gui.dialog.AddDeviceTypeDialog;
|
import jnet.client.gui.dialog.AddDeviceTypeDialog;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package jnet.client.gui.serversettings;
|
package jnet.client.gui;
|
||||||
|
|
||||||
import jnet.client.Client;
|
import jnet.client.Client;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package jnet.client.gui.serversettings;
|
package jnet.client.gui;
|
||||||
|
|
||||||
import jnet.client.gui.serversettings.TableDeviceType;
|
|
||||||
import jnet.client.Client;
|
import jnet.client.Client;
|
||||||
import jnet.client.gui.dialog.UserDialog;
|
import jnet.client.gui.dialog.UserDialog;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
|
|
@ -84,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(getClass().getResourceAsStream("/img/yes.png")));
|
ImageIcon ii_yes = new ImageIcon(ImageIO.read(new File("img/yes.png")));
|
||||||
ImageIcon ii_no = new ImageIcon(ImageIO.read(getClass().getResourceAsStream("/img/no.png")));
|
ImageIcon ii_no = new ImageIcon(ImageIO.read(new File("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,13 +1,7 @@
|
||||||
package jnet.client.gui;
|
package jnet.client.gui;
|
||||||
|
|
||||||
import jnet.client.gui.mapview.MapView;
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.*;
|
|
||||||
import java.awt.Window;
|
|
||||||
import java.util.List;
|
|
||||||
import jnet.client.gui.dialog.ConnectionDialog;
|
|
||||||
import jnet.client.gui.dialog.object.ObjectDialog;
|
|
||||||
import jnet.lib.snmp.DeviceInfo;
|
|
||||||
import jnet.lib.snmp.Interface;
|
|
||||||
|
|
||||||
public class UIUpdater {
|
public class UIUpdater {
|
||||||
|
|
||||||
|
|
@ -36,48 +30,4 @@ public class UIUpdater {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateObjectInfo(String frameName, DeviceInfo di) {
|
|
||||||
for (Window w : JFrame.getWindows()) {
|
|
||||||
if (w instanceof JFrame && frameName.equals(w.getName())) {
|
|
||||||
SwingUtilities.invokeLater(() -> {
|
|
||||||
((ObjectDialog) w).setDeviceInfo(di);
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void updateObjectInterface(String frameName, List<Interface> iface) {
|
|
||||||
for (Window w : JFrame.getWindows()) {
|
|
||||||
if (w instanceof JFrame && frameName.equals(w.getName())) {
|
|
||||||
SwingUtilities.invokeLater(() -> {
|
|
||||||
((ObjectDialog) w).setDeviceInterface(iface);
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void showResultSnmpTest(String frameName, boolean result) {
|
|
||||||
for (Window w : JFrame.getWindows()) {
|
|
||||||
if (w instanceof JFrame && frameName.equals(w.getName())) {
|
|
||||||
SwingUtilities.invokeLater(() -> {
|
|
||||||
((ObjectDialog) w).showResultSnmpTest(result);
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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,7 +1,5 @@
|
||||||
package jnet.client.gui;
|
package jnet.client.gui;
|
||||||
|
|
||||||
import jnet.client.gui.serversettings.ServerSettingsPanel;
|
|
||||||
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;
|
||||||
|
|
@ -32,16 +30,13 @@ public class Window extends JFrame {
|
||||||
public Window() {
|
public Window() {
|
||||||
super(Client.APP_NAME); //titulek okna
|
super(Client.APP_NAME); //titulek okna
|
||||||
|
|
||||||
//identifikator okna
|
|
||||||
this.setName("mainWindow");
|
|
||||||
|
|
||||||
Dimension d = new Dimension(1024, 800);
|
Dimension d = new Dimension(1024, 800);
|
||||||
this.setPreferredSize(d);
|
this.setPreferredSize(d);
|
||||||
this.setSize(d);
|
this.setSize(d);
|
||||||
this.setLocationRelativeTo(null);
|
this.setLocationRelativeTo(null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.setIconImage(ImageIO.read(getClass().getResourceAsStream("/img/app.png")));
|
this.setIconImage(ImageIO.read(new File("img/app.png")));
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
LogFile.printErr("APP icon exception");
|
LogFile.printErr("APP icon exception");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package jnet.client.gui.dialog;
|
package jnet.client.gui.dialog;
|
||||||
|
|
||||||
import jnet.client.gui.serversettings.ServerSettingsPanel;
|
import jnet.client.gui.ServerSettingsPanel;
|
||||||
import jnet.client.gui.Window;
|
import jnet.client.gui.Window;
|
||||||
import jnet.client.network.NettyClient;
|
import jnet.client.network.NettyClient;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
|
|
||||||
|
|
@ -1,252 +0,0 @@
|
||||||
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.Client;
|
|
||||||
import jnet.client.network.NettyClient;
|
|
||||||
import jnet.lib.Message;
|
|
||||||
import jnet.lib.object.Connection;
|
|
||||||
import jnet.lib.object.Map;
|
|
||||||
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 Connection connection = new Connection();
|
|
||||||
|
|
||||||
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 = true;
|
|
||||||
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConnectionDialog(Connection connection) throws HeadlessException {
|
|
||||||
this.connection = connection;
|
|
||||||
this.newObject = false;
|
|
||||||
|
|
||||||
// nastaveni pocatecniho a koncoveho objektu podle id
|
|
||||||
for (Map map : Client.maps) {
|
|
||||||
for (MapObject object : map.getObjects()) {
|
|
||||||
if (object.getId() == connection.getSourceObj()) {
|
|
||||||
this.startObj = object;
|
|
||||||
}
|
|
||||||
if (object.getId() == connection.getDestinationObj()) {
|
|
||||||
this.endObj = object;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void init() {
|
|
||||||
|
|
||||||
// identifikator okna
|
|
||||||
this.setName("connection_detail_" + Math.random());
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
if (!newObject) {
|
|
||||||
|
|
||||||
// nastaveni hodnot upravovaného spojení
|
|
||||||
typComboBox.setSelectedIndex(connection.getType());
|
|
||||||
readTraffic.setSelected(connection.isReadTraffic());
|
|
||||||
sourceDeviceComboBox.setSelectedIndex((connection.getTrafficObject() == startObj.getId() ? 0 : 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
Item item = new Item(ifs.getId(), ifs.getDescription());
|
|
||||||
sourceInterfaceComboBox.addItem(item);
|
|
||||||
// pokud se nejedna o nový objekt a souhlasi index rozhrani nastavit polozku v seznamu
|
|
||||||
if (!newObject && ifs.getId() == connection.getTrafficIface()) {
|
|
||||||
// po nacteni rozhrani nastav vybrane
|
|
||||||
sourceInterfaceComboBox.setSelectedItem(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void save() {
|
|
||||||
Item sellectedIface = (Item) sourceInterfaceComboBox.getSelectedItem();
|
|
||||||
|
|
||||||
connection.setType(typComboBox.getSelectedIndex());
|
|
||||||
connection.setReadTraffic(readTraffic.isSelected());
|
|
||||||
if (readTraffic.isSelected()) {
|
|
||||||
// pokud je zapnute cteni nastavi zdrojovy objekt a interface
|
|
||||||
connection.setTrafficObject(sourceDeviceComboBox.getSelectedIndex() == 0 ? startObj.getId() : endObj.getId());
|
|
||||||
connection.setTrafficIface(sellectedIface.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newObject) {
|
|
||||||
connection.setSourceObj(startObj.getId());
|
|
||||||
connection.setDestinationObj(endObj.getId());
|
|
||||||
connection.setMap(startObj.getMap());
|
|
||||||
NettyClient.send(Message.CONNECTION_NEW, connection);
|
|
||||||
} else {
|
|
||||||
NettyClient.send(Message.CONNECTION_UPDATE, connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,607 @@
|
||||||
|
package jnet.client.gui.dialog;
|
||||||
|
|
||||||
|
import jnet.client.Client;
|
||||||
|
import jnet.client.network.NettyClient;
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import javax.swing.BorderFactory;
|
||||||
|
import javax.swing.DefaultComboBoxModel;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JCheckBox;
|
||||||
|
import javax.swing.JComboBox;
|
||||||
|
import javax.swing.JDialog;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JPasswordField;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.swing.JTabbedPane;
|
||||||
|
import javax.swing.JTable;
|
||||||
|
import javax.swing.JTextArea;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
import javax.swing.table.DefaultTableModel;
|
||||||
|
import jnet.lib.EventComparator;
|
||||||
|
import jnet.lib.LogFile;
|
||||||
|
import jnet.lib.Message;
|
||||||
|
import jnet.lib.Status;
|
||||||
|
import jnet.lib.object.Event;
|
||||||
|
import jnet.lib.object.MapObject;
|
||||||
|
import jnet.lib.object.ObjectType;
|
||||||
|
import jnet.lib.object.SnmpProfile;
|
||||||
|
|
||||||
|
public class ObjectDialog extends JDialog {
|
||||||
|
|
||||||
|
private MapObject obj;
|
||||||
|
private int mapId;
|
||||||
|
private Boolean newObject;
|
||||||
|
|
||||||
|
private JTextField nazevText = new JTextField();
|
||||||
|
private JLabel nazevWarning = new JLabel("Název musi mit min. 3 znaky");
|
||||||
|
private JTextField ipText = new JTextField();
|
||||||
|
private JLabel ipWarning = new JLabel("Neplatná IP adresa");
|
||||||
|
private JComboBox<String> typeComboBox = new JComboBox<String>();
|
||||||
|
private JTextField userText = new JTextField();
|
||||||
|
private JPasswordField hesloText = new JPasswordField();
|
||||||
|
private DefaultComboBoxModel<String> snmpmodel = new DefaultComboBoxModel<String>();
|
||||||
|
private JCheckBox disableCheBox = new JCheckBox();
|
||||||
|
private JTextField locationText = new JTextField();
|
||||||
|
private JTextArea descriptionText = new JTextArea();
|
||||||
|
|
||||||
|
private JCheckBox winboxBox = new JCheckBox("Winbox");
|
||||||
|
private JTextField portWinbox = new JTextField("8291");
|
||||||
|
private JCheckBox sshBox = new JCheckBox("SSH");
|
||||||
|
private JTextField portSsh = new JTextField("22");
|
||||||
|
private JCheckBox wwwBox = new JCheckBox("Web");
|
||||||
|
private JTextField portWww = new JTextField("80");
|
||||||
|
private JComboBox<String> wwwVerzeComboBox = new JComboBox<String>();
|
||||||
|
private JCheckBox telnetBox = new JCheckBox("Telnet");
|
||||||
|
private JTextField portTelnet = new JTextField("23");
|
||||||
|
private JCheckBox smstBox = new JCheckBox("Summit SMS");
|
||||||
|
private JTextField portSms = new JTextField("5020");
|
||||||
|
private JComboBox<String> smsVerzeComboBox = new JComboBox<String>();
|
||||||
|
private JComboBox<String> snmpProfileComboBox = new JComboBox<String>();
|
||||||
|
|
||||||
|
public ObjectDialog(int mapId, MapObject obj, boolean newObject) {
|
||||||
|
|
||||||
|
this.obj = obj;
|
||||||
|
this.mapId = mapId;
|
||||||
|
this.newObject = newObject;
|
||||||
|
|
||||||
|
if (newObject) {
|
||||||
|
setTitle("Nový objekt");
|
||||||
|
} else {
|
||||||
|
setTitle("Vlastnosti objektu");
|
||||||
|
}
|
||||||
|
|
||||||
|
setSize(600, 520);
|
||||||
|
setLocationRelativeTo(null);
|
||||||
|
setVisible(true);
|
||||||
|
setAlwaysOnTop(false);
|
||||||
|
setResizable(false);
|
||||||
|
|
||||||
|
setLayout(new BorderLayout());
|
||||||
|
|
||||||
|
JTabbedPane tabbedPane = new JTabbedPane();
|
||||||
|
|
||||||
|
JScrollPane tabNastaveni = new JScrollPane(tabNastaveni(),
|
||||||
|
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
||||||
|
|
||||||
|
tabbedPane.addTab("Informace", tabInfo());
|
||||||
|
tabbedPane.addTab("Nastaveni", tabNastaveni);
|
||||||
|
tabbedPane.addTab("Služby", tabSluzby());
|
||||||
|
tabbedPane.addTab("Události", tabUdalosti());
|
||||||
|
//tabbedPane.addTab("Sondy", tabSondy());
|
||||||
|
|
||||||
|
// pokud se jedna o novy objekt
|
||||||
|
if (newObject) {
|
||||||
|
tabbedPane.setSelectedIndex(1); // prepne na kartu nastaveni
|
||||||
|
tabbedPane.setEnabledAt(0, false); // vypne kartu informace
|
||||||
|
tabbedPane.setEnabledAt(3, false); // vypne kartu udalosti
|
||||||
|
}
|
||||||
|
|
||||||
|
add(tabbedPane, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
JPanel pane = new JPanel();
|
||||||
|
JButton save = new JButton("Ulozit");
|
||||||
|
save.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
// kontrola chyb
|
||||||
|
if (nazevText.getText().length() < 3) {
|
||||||
|
nazevWarning.setVisible(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
nazevWarning.setVisible(false);
|
||||||
|
if (!validateIp(ipText.getText())) {
|
||||||
|
ipWarning.setVisible(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ipWarning.setVisible(false);
|
||||||
|
// ulozeni do objektu
|
||||||
|
obj.setMap(mapId);
|
||||||
|
obj.setName(nazevText.getText());
|
||||||
|
obj.setIp(ipText.getText());
|
||||||
|
obj.setUser(userText.getText());
|
||||||
|
obj.setPassword(new String(hesloText.getPassword()));
|
||||||
|
for (int i = 0; i < Client.objectType.size(); i++) {
|
||||||
|
if (typeComboBox.getSelectedIndex() == i) {
|
||||||
|
obj.setObjectType(Client.objectType.get(i).getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
obj.setSnmpProfile(Client.snmpProfile.get(snmpProfileComboBox.getSelectedIndex()).getId());
|
||||||
|
obj.setActive(disableCheBox.isSelected());
|
||||||
|
obj.setDescription(descriptionText.getText());
|
||||||
|
obj.setLocation(locationText.getText());
|
||||||
|
|
||||||
|
obj.setWinbox(winboxBox.isSelected());
|
||||||
|
obj.setWinboxPort(portWinbox.getText());
|
||||||
|
obj.setSsh(sshBox.isSelected());
|
||||||
|
obj.setSshPort(portSsh.getText());
|
||||||
|
obj.setWeb(wwwBox.isSelected());
|
||||||
|
obj.setWebPort(portWww.getText());
|
||||||
|
obj.setWebVerze(wwwVerzeComboBox.getSelectedIndex());
|
||||||
|
obj.setTelnet(telnetBox.isSelected());
|
||||||
|
obj.setTelnetPort(portTelnet.getText());
|
||||||
|
obj.setSms(smstBox.isSelected());
|
||||||
|
obj.setSmsPort(portSms.getText());
|
||||||
|
obj.setSmsVerze(smsVerzeComboBox.getSelectedIndex());
|
||||||
|
if (!obj.isActive() || newObject) {
|
||||||
|
obj.setStatus(Status.NA);
|
||||||
|
}
|
||||||
|
// ArrayList<SnmpProbe> probe = new ArrayList<>();
|
||||||
|
// if (!newObject) {
|
||||||
|
// probe.addAll(obj.getSnmpProbe());
|
||||||
|
// }
|
||||||
|
// obj.setSnmpProbe(probe);
|
||||||
|
|
||||||
|
if (newObject) {
|
||||||
|
NettyClient.send(Message.ADD_OBJECT, obj);
|
||||||
|
} else {
|
||||||
|
NettyClient.send(Message.UPDATE_OBJECT, obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
// zavreni dialogu
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
pane.add(save);
|
||||||
|
|
||||||
|
JButton cancel = new JButton("Zrusit");
|
||||||
|
cancel.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
pane.add(cancel);
|
||||||
|
|
||||||
|
add(pane, BorderLayout.PAGE_END);
|
||||||
|
|
||||||
|
// nacteni snmp profilu
|
||||||
|
for (SnmpProfile sp : Client.snmpProfile) {
|
||||||
|
snmpmodel.addElement(sp.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
// doplneni poli dialogu podle vybraneho objektu
|
||||||
|
if (!newObject) {
|
||||||
|
nazevText.setText(obj.getName());
|
||||||
|
ipText.setText(obj.getIp());
|
||||||
|
userText.setText(obj.getUser());
|
||||||
|
hesloText.setText(obj.getPassword());
|
||||||
|
for (int i = 0; i < Client.objectType.size() - 1; i++) {
|
||||||
|
if (obj.getObjectType() == Client.objectType.get(i).getId()) {
|
||||||
|
typeComboBox.setSelectedIndex(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < Client.snmpProfile.size(); i++) {
|
||||||
|
if (Client.snmpProfile.get(i).getId() == obj.getSnmpProfile()) {
|
||||||
|
snmpProfileComboBox.setSelectedIndex(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
disableCheBox.setSelected(obj.isActive());
|
||||||
|
descriptionText.setText(obj.getDescription());
|
||||||
|
locationText.setText(obj.getLocation());
|
||||||
|
winboxBox.setSelected(obj.isWinbox());
|
||||||
|
portWinbox.setText(obj.getWinboxPort());
|
||||||
|
sshBox.setSelected(obj.isSsh());
|
||||||
|
portSsh.setText(obj.getSshPort());
|
||||||
|
wwwBox.setSelected(obj.isWeb());
|
||||||
|
portWww.setText(obj.getWebPort());
|
||||||
|
wwwVerzeComboBox.setSelectedIndex(obj.getWebVerze());
|
||||||
|
telnetBox.setSelected(obj.isTelnet());
|
||||||
|
portTelnet.setText(obj.getTelnetPort());
|
||||||
|
smstBox.setSelected(obj.isSms());
|
||||||
|
portSms.setText(obj.getSmsPort());
|
||||||
|
smsVerzeComboBox.setSelectedIndex(obj.getSmsVerze());
|
||||||
|
} else {
|
||||||
|
disableCheBox.setSelected(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
show();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private JPanel tabInfo() {
|
||||||
|
JPanel p = new JPanel(null);
|
||||||
|
/*
|
||||||
|
Map<String, String> label = new HashMap<String, String>();
|
||||||
|
label.put("Popis", "1.3.6.1.2.1.1.1.0");
|
||||||
|
label.put("Uptime", "1.3.6.1.2.1.1.3.0");
|
||||||
|
label.put("Contact", "1.3.6.1.2.1.1.4.0");
|
||||||
|
label.put("Name", "1.3.6.1.2.1.1.5.0");
|
||||||
|
|
||||||
|
if(!newObject){ /// TODO u objektu u kterych neni snmp protokol povolen vraci system err null
|
||||||
|
Thread ti = new Thread() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
super.run();
|
||||||
|
// nacteni snmp profilu
|
||||||
|
String port = "161";
|
||||||
|
String community = "public";
|
||||||
|
int version = SNMPManager.version1;
|
||||||
|
for (SnmpProfile sp : Client.serverSettings.getSnmp()) {
|
||||||
|
if (obj.getSnmpProfile() == sp.getId()) {
|
||||||
|
port = sp.getPort();
|
||||||
|
community = sp.getCommunity();
|
||||||
|
version = sp.getVersion();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SNMPManager mngr = new SNMPManager(obj.getIp(), port, community, version);
|
||||||
|
try {
|
||||||
|
mngr.start();
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
int y = 30;
|
||||||
|
for (Entry<String, String> entry : label.entrySet()) {
|
||||||
|
try {
|
||||||
|
JLabel label = new JLabel(entry.getKey());
|
||||||
|
label.setBounds(20, y, 90, 25);
|
||||||
|
JLabel value = new JLabel(mngr.getAsString(new OID(entry.getValue())));
|
||||||
|
value.setBounds(100, y, 200, 25);
|
||||||
|
p.add(label);
|
||||||
|
p.add(value);
|
||||||
|
y += 30;
|
||||||
|
p.revalidate();
|
||||||
|
p.repaint();
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogFile.printErr("Object dialog - SNMP error: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ti.start();
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
private JPanel tabNastaveni() {
|
||||||
|
JPanel p = new JPanel();
|
||||||
|
|
||||||
|
p.setLayout(null);
|
||||||
|
|
||||||
|
JLabel nazevLabel = new JLabel("Název");
|
||||||
|
nazevLabel.setBounds(20, 30, 80, 25);
|
||||||
|
p.add(nazevLabel);
|
||||||
|
|
||||||
|
nazevText.setBounds(110, 30, 160, 25);
|
||||||
|
p.add(nazevText);
|
||||||
|
nazevWarning.setForeground(Color.red);
|
||||||
|
nazevWarning.setBounds(110, 55, 160, 25);
|
||||||
|
nazevWarning.setVisible(false);
|
||||||
|
p.add(nazevWarning);
|
||||||
|
|
||||||
|
JLabel ipLabel = new JLabel("IP adresa");
|
||||||
|
ipLabel.setBounds(300, 30, 80, 25);
|
||||||
|
p.add(ipLabel);
|
||||||
|
|
||||||
|
ipText.setBounds(390, 30, 160, 25);
|
||||||
|
p.add(ipText);
|
||||||
|
ipWarning.setForeground(Color.red);
|
||||||
|
ipWarning.setBounds(390, 55, 160, 25);
|
||||||
|
ipWarning.setVisible(false);
|
||||||
|
p.add(ipWarning);
|
||||||
|
|
||||||
|
JLabel typLabel = new JLabel("Typ");
|
||||||
|
typLabel.setBounds(20, 130, 80, 25);
|
||||||
|
p.add(typLabel);
|
||||||
|
|
||||||
|
DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>();
|
||||||
|
for (ObjectType obj : Client.objectType) {
|
||||||
|
model.addElement(obj.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
typeComboBox.setModel(model);
|
||||||
|
typeComboBox.setBounds(110, 130, 160, 25);
|
||||||
|
p.add(typeComboBox);
|
||||||
|
|
||||||
|
JLabel userLabel = new JLabel("Uživatel");
|
||||||
|
userLabel.setBounds(20, 80, 80, 25);
|
||||||
|
p.add(userLabel);
|
||||||
|
|
||||||
|
userText.setBounds(110, 80, 160, 25);
|
||||||
|
p.add(userText);
|
||||||
|
|
||||||
|
JLabel hesloLabel = new JLabel("Heslo");
|
||||||
|
hesloLabel.setBounds(300, 80, 80, 25);
|
||||||
|
p.add(hesloLabel);
|
||||||
|
|
||||||
|
hesloText.setBounds(390, 80, 160, 25);
|
||||||
|
p.add(hesloText);
|
||||||
|
|
||||||
|
JLabel snmpLabel = new JLabel("SNMP profil");
|
||||||
|
snmpLabel.setBounds(300, 130, 80, 25);
|
||||||
|
p.add(snmpLabel);
|
||||||
|
|
||||||
|
snmpProfileComboBox.setModel(snmpmodel);
|
||||||
|
snmpProfileComboBox.setBounds(390, 130, 160, 25);
|
||||||
|
p.add(snmpProfileComboBox);
|
||||||
|
|
||||||
|
JLabel disableLabel = new JLabel("Aktivní");
|
||||||
|
disableLabel.setBounds(20, 180, 80, 25);
|
||||||
|
p.add(disableLabel);
|
||||||
|
|
||||||
|
disableCheBox.setBounds(110, 180, 160, 25);
|
||||||
|
p.add(disableCheBox);
|
||||||
|
|
||||||
|
JButton snmpTest = new JButton("Test SNMP");
|
||||||
|
snmpTest.setBounds(390, 180, 160, 25);
|
||||||
|
snmpTest.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
/* TODO idealne at test provede server (ten bude osesilat informace o snmp pozadavky!!!!
|
||||||
|
|
||||||
|
Thread testSnmp = new Thread() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
// nacteni snmp profilu
|
||||||
|
String port = "161";
|
||||||
|
String community = "public";
|
||||||
|
int version = SNMPManager.version1;
|
||||||
|
for (int i = 0; i < Client.serverSettings.getSnmp().size(); i++) {
|
||||||
|
if (snmpProfileComboBox.getSelectedIndex() == i) {
|
||||||
|
port = Client.serverSettings.getSnmp().get(i).getPort();
|
||||||
|
community = Client.serverSettings.getSnmp().get(i).getCommunity();
|
||||||
|
version = Client.serverSettings.getSnmp().get(i).getVersion();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SNMPManager mngr = new SNMPManager(ipText.getText(), port, community, version);
|
||||||
|
mngr.start();
|
||||||
|
String desc = mngr.getSysDescr();
|
||||||
|
JOptionPane.showMessageDialog(ObjectDialog.this, "Odpoved: " + desc, "SNMP test", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
JOptionPane.showMessageDialog(ObjectDialog.this, "SNMP se nepodařilo načíst", "SNMP test", JOptionPane.ERROR_MESSAGE);
|
||||||
|
System.err.println("SNMP test error: " + ex.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
testSnmp.start();
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
});
|
||||||
|
p.add(snmpTest);
|
||||||
|
|
||||||
|
JLabel locLabel = new JLabel("Umístění");
|
||||||
|
locLabel.setBounds(20, 230, 80, 25);
|
||||||
|
p.add(locLabel);
|
||||||
|
|
||||||
|
locationText.setBounds(110, 230, 440, 25);
|
||||||
|
p.add(locationText);
|
||||||
|
|
||||||
|
JLabel descLabel = new JLabel("Poznámka");
|
||||||
|
descLabel.setBounds(20, 280, 80, 25);
|
||||||
|
p.add(descLabel);
|
||||||
|
|
||||||
|
descriptionText.setBounds(110, 280, 440, 100);
|
||||||
|
descriptionText.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.BLACK), BorderFactory.createEmptyBorder(10, 10, 10, 10)));
|
||||||
|
p.add(descriptionText);
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
private JPanel tabSluzby() {
|
||||||
|
JPanel p = new JPanel();
|
||||||
|
|
||||||
|
p.setLayout(null);
|
||||||
|
|
||||||
|
winboxBox.setBounds(20, 30, 80, 25);
|
||||||
|
p.add(winboxBox);
|
||||||
|
|
||||||
|
JLabel winbox_port = new JLabel("port:");
|
||||||
|
winbox_port.setBounds(130, 30, 60, 25);
|
||||||
|
p.add(winbox_port);
|
||||||
|
|
||||||
|
portWinbox.setBounds(180, 30, 60, 25);
|
||||||
|
p.add(portWinbox);
|
||||||
|
|
||||||
|
sshBox.setBounds(20, 60, 80, 25);
|
||||||
|
p.add(sshBox);
|
||||||
|
|
||||||
|
JLabel ssh_port = new JLabel("port:");
|
||||||
|
ssh_port.setBounds(130, 60, 60, 25);
|
||||||
|
p.add(ssh_port);
|
||||||
|
|
||||||
|
portSsh.setBounds(180, 60, 60, 25);
|
||||||
|
p.add(portSsh);
|
||||||
|
|
||||||
|
wwwBox.setBounds(20, 90, 80, 25);
|
||||||
|
p.add(wwwBox);
|
||||||
|
|
||||||
|
JLabel www_port = new JLabel("port:");
|
||||||
|
www_port.setBounds(130, 90, 60, 25);
|
||||||
|
p.add(www_port);
|
||||||
|
|
||||||
|
portWww.setBounds(180, 90, 60, 25);
|
||||||
|
p.add(portWww);
|
||||||
|
|
||||||
|
JLabel www_verze = new JLabel("verze:");
|
||||||
|
www_verze.setBounds(260, 90, 60, 25);
|
||||||
|
p.add(www_verze);
|
||||||
|
|
||||||
|
wwwVerzeComboBox.setModel(new DefaultComboBoxModel(new String[]{"HTTP", "HTTPS"}));
|
||||||
|
wwwVerzeComboBox.setBounds(320, 90, 80, 25);
|
||||||
|
p.add(wwwVerzeComboBox);
|
||||||
|
|
||||||
|
telnetBox.setBounds(20, 120, 80, 25);
|
||||||
|
p.add(telnetBox);
|
||||||
|
|
||||||
|
JLabel telnet_port = new JLabel("port:");
|
||||||
|
telnet_port.setBounds(130, 120, 60, 25);
|
||||||
|
p.add(telnet_port);
|
||||||
|
|
||||||
|
portTelnet.setBounds(180, 120, 60, 25);
|
||||||
|
p.add(portTelnet);
|
||||||
|
|
||||||
|
smstBox.setBounds(20, 150, 80, 25);
|
||||||
|
p.add(smstBox);
|
||||||
|
|
||||||
|
JLabel sms_port = new JLabel("port:");
|
||||||
|
sms_port.setBounds(130, 150, 60, 25);
|
||||||
|
p.add(sms_port);
|
||||||
|
|
||||||
|
portSms.setBounds(180, 150, 60, 25);
|
||||||
|
p.add(portSms);
|
||||||
|
|
||||||
|
JLabel sms_verze = new JLabel("verze:");
|
||||||
|
sms_verze.setBounds(260, 150, 60, 25);
|
||||||
|
p.add(sms_verze);
|
||||||
|
|
||||||
|
smsVerzeComboBox.setModel(new DefaultComboBoxModel(new String[]{"SDV", "BT"}));
|
||||||
|
smsVerzeComboBox.setBounds(320, 150, 80, 25);
|
||||||
|
p.add(smsVerzeComboBox);
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
private JPanel tabUdalosti() {
|
||||||
|
|
||||||
|
String column[] = {"Začátek", "Konec", "Stav"};
|
||||||
|
DefaultTableModel tableModel = new DefaultTableModel(column, 0) {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCellEditable(int row, int column) {
|
||||||
|
//all cells false
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
// TODO pri vytvareni noveho objektu to vyhodi chybu
|
||||||
|
Collections.sort(Client.events, new EventComparator());
|
||||||
|
Collections.reverse(Client.events);
|
||||||
|
if (!newObject) {
|
||||||
|
for (Event e : Client.events) {
|
||||||
|
if (e.getObject() == obj.getId()) {
|
||||||
|
Object[] d = {
|
||||||
|
getDate(e.getStart()),
|
||||||
|
getDate(e.getEnd()),
|
||||||
|
e.getDescription()};
|
||||||
|
tableModel.addRow(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogFile.printErr("Object log error: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
JTable table = new JTable(tableModel);
|
||||||
|
table.setPreferredScrollableViewportSize(new Dimension(500, 350)); // Šířka 500, výška 300
|
||||||
|
|
||||||
|
JButton btn = new JButton("Smazat události");
|
||||||
|
btn.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
tableModel.setRowCount(0);
|
||||||
|
NettyClient.send(Message.DELETE_LOG, obj.getId());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
JPanel panel = new JPanel();
|
||||||
|
panel.add(new JScrollPane(table));
|
||||||
|
panel.add(btn);
|
||||||
|
|
||||||
|
return panel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private JPanel tabSondy() {
|
||||||
|
JPanel panel = new JPanel();
|
||||||
|
|
||||||
|
panel.setLayout(new BorderLayout());
|
||||||
|
|
||||||
|
String column[] = {"Popis", "OID", "Aktivni", "Zobrazit"};
|
||||||
|
DefaultTableModel tableModel = new DefaultTableModel(column, 0);
|
||||||
|
if (!newObject) {
|
||||||
|
// try {
|
||||||
|
// for (SnmpProbe p : obj.getSnmpProbe()) {
|
||||||
|
// Object[] d = {p.getName(), p.getOid(), "", ""};
|
||||||
|
// tableModel.addRow(d);
|
||||||
|
// }
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// LogFile.printErr("Probe list " + e.getMessage());
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
JScrollPane table = new JScrollPane();
|
||||||
|
table.add(new JTable(tableModel));
|
||||||
|
panel.add(new JTable(tableModel), BorderLayout.CENTER);
|
||||||
|
|
||||||
|
JPanel jp = new JPanel();
|
||||||
|
jp.add(new JLabel("Přidat: "));
|
||||||
|
panel.add(jp, BorderLayout.PAGE_END);
|
||||||
|
|
||||||
|
return panel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean validateIp(String ip) {
|
||||||
|
Pattern pattern = Pattern.compile("^(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])$");
|
||||||
|
Matcher matcher = pattern.matcher(ip);
|
||||||
|
return matcher.matches();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean validatePort(String port) {
|
||||||
|
try {
|
||||||
|
int pNum = Integer.parseInt(port);
|
||||||
|
if ((pNum > 0) && (pNum < 65536)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getDate(long date) {
|
||||||
|
if (date != 0) {
|
||||||
|
SimpleDateFormat ft = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
|
||||||
|
return ft.format(new Date(date));
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getStatus(int status) {
|
||||||
|
switch (status) {
|
||||||
|
case Status.OK: // online
|
||||||
|
return "online";
|
||||||
|
case Status.WARNING: // warning
|
||||||
|
return "varování";
|
||||||
|
case Status.OFFLINE: // offline
|
||||||
|
return "offline";
|
||||||
|
default: // other
|
||||||
|
return "n/a";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -35,10 +35,10 @@ public class OnlineClientsDialog extends JDialog {
|
||||||
JLabel line = new JLabel(" " + oc.getUsername() + " (" + oc.getIp() + ")");
|
JLabel line = new JLabel(" " + oc.getUsername() + " (" + oc.getIp() + ")");
|
||||||
switch (oc.getPlatform()) {
|
switch (oc.getPlatform()) {
|
||||||
case OnlineClients.PLATFORM_MOBILE:
|
case OnlineClients.PLATFORM_MOBILE:
|
||||||
line.setIcon(new ImageIcon(ImageIO.read(getClass().getResourceAsStream("/img/platform_android.png"))));
|
line.setIcon(new ImageIcon(ImageIO.read(new File("img/platform_android.png"))));
|
||||||
break;
|
break;
|
||||||
case OnlineClients.PLATFORM_PC:
|
case OnlineClients.PLATFORM_PC:
|
||||||
line.setIcon(new ImageIcon(ImageIO.read(getClass().getResourceAsStream("/img/platform_pc.png"))));
|
line.setIcon(new ImageIcon(ImageIO.read(new File("img/platform_pc.png"))));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
panel.add(line);
|
panel.add(line);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package jnet.client.gui.dialog;
|
package jnet.client.gui.dialog;
|
||||||
|
|
||||||
import jnet.client.gui.serversettings.ServerSettingsPanel;
|
import jnet.client.gui.ServerSettingsPanel;
|
||||||
import jnet.client.gui.Window;
|
import jnet.client.gui.Window;
|
||||||
import jnet.client.network.NettyClient;
|
import jnet.client.network.NettyClient;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
|
|
|
||||||
|
|
@ -1,291 +0,0 @@
|
||||||
package jnet.client.gui.dialog.object;
|
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
|
||||||
import java.awt.Frame;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.util.List;
|
|
||||||
import javax.swing.JButton;
|
|
||||||
import javax.swing.JDialog;
|
|
||||||
import javax.swing.JFrame;
|
|
||||||
import javax.swing.JLabel;
|
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JProgressBar;
|
|
||||||
import javax.swing.JTabbedPane;
|
|
||||||
import javax.swing.SwingConstants;
|
|
||||||
import javax.swing.SwingUtilities;
|
|
||||||
import javax.swing.event.ChangeEvent;
|
|
||||||
import javax.swing.event.ChangeListener;
|
|
||||||
import jnet.client.Client;
|
|
||||||
import jnet.client.network.NettyClient;
|
|
||||||
import jnet.lib.Message;
|
|
||||||
import jnet.lib.Status;
|
|
||||||
import jnet.lib.object.MapObject;
|
|
||||||
import jnet.lib.snmp.DeviceInfo;
|
|
||||||
import jnet.lib.snmp.Interface;
|
|
||||||
|
|
||||||
public class ObjectDialog extends JFrame {
|
|
||||||
|
|
||||||
private MapObject obj;
|
|
||||||
private int mapId;
|
|
||||||
private Boolean newObject;
|
|
||||||
|
|
||||||
private TabInfo tabInfo;
|
|
||||||
private TabSettings tabSettings;
|
|
||||||
private TabServices tabServices;
|
|
||||||
private TabEvents tabEvents;
|
|
||||||
|
|
||||||
private JButton snmpTest = new JButton("Test SNMP");
|
|
||||||
private JButton btnRefresh = new JButton("Obnovit");
|
|
||||||
private JDialog progress;
|
|
||||||
|
|
||||||
public ObjectDialog(MapObject obj) {
|
|
||||||
this.obj = obj;
|
|
||||||
this.mapId = obj.getMap();
|
|
||||||
this.newObject = false;
|
|
||||||
|
|
||||||
// identifikator okna
|
|
||||||
this.setName("object_detail_" + obj.getId());
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObjectDialog(MapObject obj, boolean newObject) {
|
|
||||||
this.obj = obj;
|
|
||||||
this.mapId = obj.getMap();
|
|
||||||
this.newObject = newObject;
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void init() {
|
|
||||||
|
|
||||||
if (newObject) {
|
|
||||||
setTitle("Nový objekt");
|
|
||||||
} else {
|
|
||||||
setTitle(obj.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
setSize(600, 520);
|
|
||||||
setLocationRelativeTo(null);
|
|
||||||
setVisible(true);
|
|
||||||
setAlwaysOnTop(false);
|
|
||||||
setResizable(false);
|
|
||||||
|
|
||||||
setLayout(new BorderLayout());
|
|
||||||
|
|
||||||
JTabbedPane tabbedPane = new JTabbedPane();
|
|
||||||
|
|
||||||
// JScrollPane tabNastaveni = new JScrollPane(tabNastaveni(),
|
|
||||||
// JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
|
||||||
tabInfo = new TabInfo(this.getName(), obj);
|
|
||||||
tabSettings = new TabSettings(obj, newObject);
|
|
||||||
tabServices = new TabServices(obj, newObject);
|
|
||||||
tabEvents = new TabEvents(obj);
|
|
||||||
|
|
||||||
tabbedPane.addTab("Informace", tabInfo);
|
|
||||||
tabbedPane.addTab("Nastaveni", tabSettings);
|
|
||||||
tabbedPane.addTab("Služby", tabServices);
|
|
||||||
tabbedPane.addTab("Události", tabEvents);
|
|
||||||
//tabbedPane.addTab("Sondy", tabSondy());
|
|
||||||
|
|
||||||
// Přidání listeneru na změnu tabu
|
|
||||||
tabbedPane.addChangeListener(new ChangeListener() {
|
|
||||||
@Override
|
|
||||||
public void stateChanged(ChangeEvent e) {
|
|
||||||
int selectedIndex = tabbedPane.getSelectedIndex();
|
|
||||||
if (selectedIndex == 1) { // pokud je zobrazena zalozka nastaveni zobrazit tlačítko test snmp
|
|
||||||
snmpTest.setVisible(true);
|
|
||||||
} else {
|
|
||||||
snmpTest.setVisible(false);
|
|
||||||
}
|
|
||||||
if (selectedIndex == 0) { // pokud je zobrazena karta info zobrazit tlačítko refresh
|
|
||||||
btnRefresh.setVisible(true);
|
|
||||||
} else {
|
|
||||||
btnRefresh.setVisible(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// pokud se jedna o novy objekt
|
|
||||||
if (newObject) {
|
|
||||||
tabbedPane.setSelectedIndex(1); // prepne na kartu nastaveni
|
|
||||||
tabbedPane.setEnabledAt(0, false); // vypne kartu informace
|
|
||||||
tabbedPane.setEnabledAt(3, false); // vypne kartu udalosti
|
|
||||||
} else {
|
|
||||||
// pokud se nejsedna o novy objekt odeslat snmp pozadavek na ziskani informaci o zarizeni
|
|
||||||
snmpRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
add(tabbedPane, BorderLayout.CENTER);
|
|
||||||
|
|
||||||
JPanel pane = new JPanel();
|
|
||||||
JButton save = new JButton("Ulozit");
|
|
||||||
save.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
// kontrola chyb
|
|
||||||
String nazev = tabSettings.getName();
|
|
||||||
if (nazev == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String ip = tabSettings.getIp();
|
|
||||||
if (ip == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// ulozeni do objektu
|
|
||||||
obj.setMap(mapId);
|
|
||||||
obj.setName(nazev);
|
|
||||||
obj.setIp(ip);
|
|
||||||
obj.setUser(tabSettings.getUser());
|
|
||||||
obj.setPassword(new String(tabSettings.getPassword()));
|
|
||||||
obj.setObjectType(Client.objectType.get(tabSettings.getObjType()).getId());
|
|
||||||
obj.setSnmpProfile(Client.snmpProfile.get(tabSettings.getSnmpProfile()).getId());
|
|
||||||
obj.setActive(tabSettings.isActive());
|
|
||||||
obj.setDescription(tabSettings.getDesc());
|
|
||||||
obj.setLocation(tabSettings.getLoc());
|
|
||||||
|
|
||||||
obj.setWinbox(tabServices.isWinbox());
|
|
||||||
String winboxPort = tabServices.getWinboxPort();
|
|
||||||
if (winboxPort == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
obj.setWinboxPort(winboxPort);
|
|
||||||
obj.setSsh(tabServices.isSsh());
|
|
||||||
String sshPort = tabServices.getSshPort();
|
|
||||||
if (sshPort == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
obj.setSshPort(sshPort);
|
|
||||||
obj.setWeb(tabServices.isWeb());
|
|
||||||
String webPort = tabServices.getWebPort();
|
|
||||||
if (webPort == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
obj.setWebPort(webPort);
|
|
||||||
obj.setWebVerze(tabServices.getWebVersion());
|
|
||||||
obj.setTelnet(tabServices.isTelnet());
|
|
||||||
String telnetPort = tabServices.getTelnetPort();
|
|
||||||
if (telnetPort == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
obj.setTelnetPort(telnetPort);
|
|
||||||
obj.setSms(tabServices.isSms());
|
|
||||||
String smsPort = tabServices.getSmsPort();
|
|
||||||
if (smsPort == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
obj.setSmsPort(smsPort);
|
|
||||||
obj.setSmsVerze(tabServices.getSmsVersion());
|
|
||||||
|
|
||||||
if (!obj.isActive() || newObject) {
|
|
||||||
obj.setStatus(Status.NA);
|
|
||||||
}
|
|
||||||
// ArrayList<SnmpProbe> probe = new ArrayList<>();
|
|
||||||
// if (!newObject) {
|
|
||||||
// probe.addAll(obj.getSnmpProbe());
|
|
||||||
// }
|
|
||||||
// obj.setSnmpProbe(probe);
|
|
||||||
|
|
||||||
if (newObject) {
|
|
||||||
NettyClient.send(Message.ADD_OBJECT, obj);
|
|
||||||
} else {
|
|
||||||
NettyClient.send(Message.UPDATE_OBJECT, obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
pane.add(save);
|
|
||||||
|
|
||||||
JButton cancel = new JButton("Zavřít");
|
|
||||||
cancel.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
dispose();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
pane.add(cancel);
|
|
||||||
|
|
||||||
// tlačítko snmp test na zalozce nastaveni
|
|
||||||
snmpTest.setVisible(false);
|
|
||||||
snmpTest.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
Object[] o = {getName(), obj};
|
|
||||||
NettyClient.send(Message.SNMP_TEST, o);
|
|
||||||
progress = showProgress();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
pane.add(snmpTest);
|
|
||||||
|
|
||||||
// tlačítko obnovit na info zalozce
|
|
||||||
btnRefresh.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
snmpRequest();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
pane.add(btnRefresh);
|
|
||||||
|
|
||||||
add(pane, BorderLayout.PAGE_END);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getStatus(int status) {
|
|
||||||
switch (status) {
|
|
||||||
case Status.OK: // online
|
|
||||||
return "online";
|
|
||||||
case Status.WARNING: // warning
|
|
||||||
return "varování";
|
|
||||||
case Status.OFFLINE: // offline
|
|
||||||
return "offline";
|
|
||||||
default: // other
|
|
||||||
return "n/a";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeviceInfo(DeviceInfo di) {
|
|
||||||
this.tabInfo.setName(di.getSysName());
|
|
||||||
this.tabInfo.setDesc(di.getSysDescr());
|
|
||||||
this.tabInfo.setUptime(di.getSysUptime());
|
|
||||||
this.tabInfo.setVendor(di.getSysObjectID());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeviceInterface(List<Interface> iface) {
|
|
||||||
this.tabInfo.setInterface(iface);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void showResultSnmpTest(boolean result) {
|
|
||||||
progress.dispose();
|
|
||||||
if (result) {
|
|
||||||
JOptionPane.showMessageDialog(null, "SNMP funkční", "SNMP test", JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
} else {
|
|
||||||
JOptionPane.showMessageDialog(null, "SNMP nefunkční", "SNMP test", JOptionPane.ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private JDialog showProgress(){
|
|
||||||
JDialog dialog = new JDialog((Frame) null, "Testování", true);
|
|
||||||
SwingUtilities.invokeLater(() -> {
|
|
||||||
dialog.setSize(200, 100);
|
|
||||||
dialog.setLayout(new BorderLayout());
|
|
||||||
|
|
||||||
JLabel label = new JLabel("Prosím, čekejte...", SwingConstants.CENTER);
|
|
||||||
JProgressBar progressBar = new JProgressBar();
|
|
||||||
progressBar.setIndeterminate(true); // Animace nekonečného načítání
|
|
||||||
|
|
||||||
dialog.add(label, BorderLayout.NORTH);
|
|
||||||
dialog.add(progressBar, BorderLayout.CENTER);
|
|
||||||
|
|
||||||
dialog.setLocationRelativeTo(null);
|
|
||||||
dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
|
|
||||||
dialog.setVisible(true);
|
|
||||||
});
|
|
||||||
return dialog;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void snmpRequest() {
|
|
||||||
Object[] data = {getName(), this.obj};
|
|
||||||
NettyClient.send(Message.SNMP_OBJECT_INFO, data);
|
|
||||||
NettyClient.send(Message.SNMP_OBJECT_INTERFACE, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,82 +0,0 @@
|
||||||
package jnet.client.gui.dialog.object;
|
|
||||||
|
|
||||||
import java.awt.Dimension;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
|
||||||
import javax.swing.JButton;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JScrollPane;
|
|
||||||
import javax.swing.JTable;
|
|
||||||
import javax.swing.table.DefaultTableModel;
|
|
||||||
import jnet.client.Client;
|
|
||||||
import jnet.client.network.NettyClient;
|
|
||||||
import jnet.lib.EventComparator;
|
|
||||||
import jnet.lib.LogFile;
|
|
||||||
import jnet.lib.Message;
|
|
||||||
import jnet.lib.object.Event;
|
|
||||||
import jnet.lib.object.MapObject;
|
|
||||||
|
|
||||||
public class TabEvents extends JPanel {
|
|
||||||
|
|
||||||
private MapObject obj;
|
|
||||||
|
|
||||||
public TabEvents(MapObject obj) {
|
|
||||||
this.obj = obj;
|
|
||||||
|
|
||||||
String column[] = {"Začátek", "Konec", "Stav"};
|
|
||||||
DefaultTableModel tableModel = new DefaultTableModel(column, 0) {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCellEditable(int row, int column) {
|
|
||||||
//all cells false
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
// TODO pri vytvareni noveho objektu to vyhodi chybu
|
|
||||||
Collections.sort(Client.events, new EventComparator());
|
|
||||||
Collections.reverse(Client.events);
|
|
||||||
for (Event e : Client.events) {
|
|
||||||
if (e.getObject() == obj.getId()) {
|
|
||||||
Object[] d = {
|
|
||||||
getDate(e.getStart()),
|
|
||||||
getDate(e.getEnd()),
|
|
||||||
e.getDescription()};
|
|
||||||
tableModel.addRow(d);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
LogFile.printErr("Object log error: " + e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
JTable table = new JTable(tableModel);
|
|
||||||
table.setPreferredScrollableViewportSize(new Dimension(500, 350)); // Šířka 500, výška 300
|
|
||||||
|
|
||||||
JButton btn = new JButton("Smazat události");
|
|
||||||
btn.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
tableModel.setRowCount(0);
|
|
||||||
NettyClient.send(Message.DELETE_LOG, obj.getId());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.add(new JScrollPane(table));
|
|
||||||
this.add(btn);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getDate(long date) {
|
|
||||||
if (date != 0) {
|
|
||||||
SimpleDateFormat ft = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
|
|
||||||
return ft.format(new Date(date));
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,126 +0,0 @@
|
||||||
package jnet.client.gui.dialog.object;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import javax.swing.JLabel;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JScrollPane;
|
|
||||||
import javax.swing.JTable;
|
|
||||||
import javax.swing.table.DefaultTableModel;
|
|
||||||
import jnet.client.network.NettyClient;
|
|
||||||
import jnet.lib.Message;
|
|
||||||
import jnet.lib.object.MapObject;
|
|
||||||
import jnet.lib.snmp.Interface;
|
|
||||||
|
|
||||||
public class TabInfo extends JPanel {
|
|
||||||
|
|
||||||
private String frameName;
|
|
||||||
private MapObject obj;
|
|
||||||
private JLabel uptime = new JLabel();
|
|
||||||
private JLabel name = new JLabel();
|
|
||||||
private JLabel description = new JLabel();
|
|
||||||
private JLabel vendor = new JLabel();
|
|
||||||
private DefaultTableModel tableModel;
|
|
||||||
private JTable ifaceTable;
|
|
||||||
|
|
||||||
public TabInfo(String frameName, MapObject obj) {
|
|
||||||
this.obj = obj;
|
|
||||||
this.frameName = frameName;
|
|
||||||
init();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void init() {
|
|
||||||
|
|
||||||
this.setLayout(null);
|
|
||||||
this.setBounds(0, 0, 600, 520);
|
|
||||||
|
|
||||||
int x1 = 20;
|
|
||||||
int x2 = 100;
|
|
||||||
int y = 30;
|
|
||||||
|
|
||||||
JLabel labelName = new JLabel("Název:");
|
|
||||||
labelName.setBounds(x1, y, 90, 30);
|
|
||||||
this.add(labelName);
|
|
||||||
name.setBounds(x2, y, 300, 30);
|
|
||||||
this.add(name);
|
|
||||||
y = y + 30;
|
|
||||||
|
|
||||||
JLabel labelDesc = new JLabel("Popis:");
|
|
||||||
labelDesc.setBounds(x1, y, 90, 30);
|
|
||||||
this.add(labelDesc);
|
|
||||||
description.setBounds(x2, y, 300, 30);
|
|
||||||
this.add(description);
|
|
||||||
y = y + 30;
|
|
||||||
|
|
||||||
JLabel labelVendor = new JLabel("Výrobce:");
|
|
||||||
labelVendor.setBounds(x1, y, 90, 30);
|
|
||||||
this.add(labelVendor);
|
|
||||||
vendor.setBounds(x2, y, 300, 30);
|
|
||||||
this.add(vendor);
|
|
||||||
y = y + 30;
|
|
||||||
|
|
||||||
JLabel labelUptime = new JLabel("Uptime:");
|
|
||||||
labelUptime.setBounds(x1, y, 90, 30);
|
|
||||||
this.add(labelUptime);
|
|
||||||
uptime.setBounds(x2, y, 300, 30);
|
|
||||||
this.add(uptime);
|
|
||||||
y = y + 30;
|
|
||||||
|
|
||||||
String column[] = {"Název", "Stav", "Admin", "Rychlost", "Typ", "Poslední změna"};
|
|
||||||
tableModel = new DefaultTableModel(column, 0) {
|
|
||||||
@Override
|
|
||||||
public boolean isCellEditable(int row, int column) {
|
|
||||||
//all cells false
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
ifaceTable = new JTable(tableModel);
|
|
||||||
ifaceTable.getTableHeader().setReorderingAllowed(false); // Zakáže přeskupování sloupců
|
|
||||||
ifaceTable.getTableHeader().setResizingAllowed(false); // Zakáže změnu velikosti sloupců
|
|
||||||
ifaceTable.getColumnModel().getColumn(0).setPreferredWidth(150); // Sloupec 0 bude mít šířku 100 px
|
|
||||||
ifaceTable.getColumnModel().getColumn(1).setPreferredWidth(40); // Sloupec 1 bude mít šířku 100 px
|
|
||||||
ifaceTable.getColumnModel().getColumn(2).setPreferredWidth(40); // Sloupec 2 bude mít šířku 100 px
|
|
||||||
ifaceTable.getColumnModel().getColumn(3).setPreferredWidth(50); // Sloupec 3 bude mít šířku 100 px
|
|
||||||
ifaceTable.getColumnModel().getColumn(4).setPreferredWidth(60); // Sloupec 4 bude mít šířku 100 px
|
|
||||||
//ifaceTable.getColumnModel().getColumn(5).setPreferredWidth(100); // Sloupec 5 bude mít šířku 100 px
|
|
||||||
|
|
||||||
JScrollPane tableScroll = new JScrollPane(ifaceTable);
|
|
||||||
tableScroll.setBounds(x1, y, (this.getWidth() - x1 * 3), 200);
|
|
||||||
this.add(tableScroll);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name.setText(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDesc(String desc) {
|
|
||||||
this.description.setText(desc);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUptime(String uptime) {
|
|
||||||
this.uptime.setText(uptime);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVendor(String vendor) {
|
|
||||||
this.vendor.setText(vendor);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setInterface(List<Interface> iface) {
|
|
||||||
tableModel.setRowCount(0);
|
|
||||||
for (Interface i : iface) {
|
|
||||||
Object[] d = {
|
|
||||||
i.getDescription(),
|
|
||||||
i.getOperStatus(),
|
|
||||||
i.getAdminStatus(),
|
|
||||||
i.getSpeed(),
|
|
||||||
i.getType(),
|
|
||||||
i.getLastChangeTime()};
|
|
||||||
tableModel.addRow(d);
|
|
||||||
}
|
|
||||||
ifaceTable.revalidate();
|
|
||||||
ifaceTable.repaint();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,191 +0,0 @@
|
||||||
package jnet.client.gui.dialog.object;
|
|
||||||
|
|
||||||
import javax.swing.DefaultComboBoxModel;
|
|
||||||
import javax.swing.JCheckBox;
|
|
||||||
import javax.swing.JComboBox;
|
|
||||||
import javax.swing.JLabel;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JTextField;
|
|
||||||
import jnet.lib.object.MapObject;
|
|
||||||
|
|
||||||
class TabServices extends JPanel {
|
|
||||||
|
|
||||||
private MapObject obj;
|
|
||||||
private boolean newObject;
|
|
||||||
|
|
||||||
private JCheckBox winboxBox = new JCheckBox("Winbox");
|
|
||||||
private JTextField portWinbox = new JTextField("8291");
|
|
||||||
private JCheckBox sshBox = new JCheckBox("SSH");
|
|
||||||
private JTextField portSsh = new JTextField("22");
|
|
||||||
private JCheckBox wwwBox = new JCheckBox("Web");
|
|
||||||
private JTextField portWww = new JTextField("80");
|
|
||||||
private JComboBox<String> wwwVerzeComboBox = new JComboBox<String>();
|
|
||||||
private JCheckBox telnetBox = new JCheckBox("Telnet");
|
|
||||||
private JTextField portTelnet = new JTextField("21");
|
|
||||||
private JCheckBox smstBox = new JCheckBox("Summit SMS");
|
|
||||||
private JTextField portSms = new JTextField("5020");
|
|
||||||
private JComboBox<String> smsVerzeComboBox = new JComboBox<String>();
|
|
||||||
|
|
||||||
public TabServices(MapObject obj, boolean newObject) {
|
|
||||||
this.obj = obj;
|
|
||||||
this.newObject = newObject;
|
|
||||||
|
|
||||||
this.setLayout(null);
|
|
||||||
|
|
||||||
winboxBox.setBounds(20, 30, 80, 25);
|
|
||||||
this.add(winboxBox);
|
|
||||||
|
|
||||||
JLabel winbox_port = new JLabel("port:");
|
|
||||||
winbox_port.setBounds(130, 30, 60, 25);
|
|
||||||
this.add(winbox_port);
|
|
||||||
|
|
||||||
portWinbox.setBounds(180, 30, 60, 25);
|
|
||||||
this.add(portWinbox);
|
|
||||||
|
|
||||||
sshBox.setBounds(20, 60, 80, 25);
|
|
||||||
this.add(sshBox);
|
|
||||||
|
|
||||||
JLabel ssh_port = new JLabel("port:");
|
|
||||||
ssh_port.setBounds(130, 60, 60, 25);
|
|
||||||
this.add(ssh_port);
|
|
||||||
|
|
||||||
portSsh.setBounds(180, 60, 60, 25);
|
|
||||||
this.add(portSsh);
|
|
||||||
|
|
||||||
wwwBox.setBounds(20, 90, 80, 25);
|
|
||||||
this.add(wwwBox);
|
|
||||||
|
|
||||||
JLabel www_port = new JLabel("port:");
|
|
||||||
www_port.setBounds(130, 90, 60, 25);
|
|
||||||
this.add(www_port);
|
|
||||||
|
|
||||||
portWww.setBounds(180, 90, 60, 25);
|
|
||||||
this.add(portWww);
|
|
||||||
|
|
||||||
JLabel www_verze = new JLabel("verze:");
|
|
||||||
www_verze.setBounds(260, 90, 60, 25);
|
|
||||||
this.add(www_verze);
|
|
||||||
|
|
||||||
wwwVerzeComboBox.setModel(new DefaultComboBoxModel(new String[]{"HTTP", "HTTPS"}));
|
|
||||||
wwwVerzeComboBox.setBounds(320, 90, 80, 25);
|
|
||||||
this.add(wwwVerzeComboBox);
|
|
||||||
|
|
||||||
telnetBox.setBounds(20, 120, 80, 25);
|
|
||||||
this.add(telnetBox);
|
|
||||||
|
|
||||||
JLabel telnet_port = new JLabel("port:");
|
|
||||||
telnet_port.setBounds(130, 120, 60, 25);
|
|
||||||
this.add(telnet_port);
|
|
||||||
|
|
||||||
portTelnet.setBounds(180, 120, 60, 25);
|
|
||||||
this.add(portTelnet);
|
|
||||||
|
|
||||||
smstBox.setBounds(20, 150, 80, 25);
|
|
||||||
this.add(smstBox);
|
|
||||||
|
|
||||||
JLabel sms_port = new JLabel("port:");
|
|
||||||
sms_port.setBounds(130, 150, 60, 25);
|
|
||||||
this.add(sms_port);
|
|
||||||
|
|
||||||
portSms.setBounds(180, 150, 60, 25);
|
|
||||||
this.add(portSms);
|
|
||||||
|
|
||||||
JLabel sms_verze = new JLabel("verze:");
|
|
||||||
sms_verze.setBounds(260, 150, 60, 25);
|
|
||||||
this.add(sms_verze);
|
|
||||||
|
|
||||||
smsVerzeComboBox.setModel(new DefaultComboBoxModel(new String[]{"SDV", "BT"}));
|
|
||||||
smsVerzeComboBox.setBounds(320, 150, 80, 25);
|
|
||||||
this.add(smsVerzeComboBox);
|
|
||||||
|
|
||||||
// predvyplneni poli
|
|
||||||
if (!newObject) {
|
|
||||||
winboxBox.setSelected(obj.isWinbox());
|
|
||||||
portWinbox.setText(obj.getWinboxPort());
|
|
||||||
sshBox.setSelected(obj.isSsh());
|
|
||||||
portSsh.setText(obj.getSshPort());
|
|
||||||
wwwBox.setSelected(obj.isWeb());
|
|
||||||
portWww.setText(obj.getWebPort());
|
|
||||||
wwwVerzeComboBox.setSelectedIndex(obj.getWebVerze());
|
|
||||||
telnetBox.setSelected(obj.isTelnet());
|
|
||||||
portTelnet.setText(obj.getTelnetPort());
|
|
||||||
smstBox.setSelected(obj.isSms());
|
|
||||||
portSms.setText(obj.getSmsPort());
|
|
||||||
smsVerzeComboBox.setSelectedIndex(obj.getSmsVerze());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isWinbox() {
|
|
||||||
return winboxBox.isSelected();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getWinboxPort() {
|
|
||||||
if (validatePort(portWinbox.getText())) {
|
|
||||||
return portWinbox.getText();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSsh() {
|
|
||||||
return sshBox.isSelected();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSshPort() {
|
|
||||||
if (validatePort(portSsh.getText())) {
|
|
||||||
return portSsh.getText();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isWeb() {
|
|
||||||
return wwwBox.isSelected();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getWebPort() {
|
|
||||||
if (validatePort(portWww.getText())) {
|
|
||||||
return portWww.getText();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getWebVersion() {
|
|
||||||
return wwwVerzeComboBox.getSelectedIndex();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isTelnet() {
|
|
||||||
return telnetBox.isSelected();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTelnetPort() {
|
|
||||||
if (validatePort(portTelnet.getText())) {
|
|
||||||
return portTelnet.getText();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSms() {
|
|
||||||
return smstBox.isSelected();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSmsPort() {
|
|
||||||
if (validatePort(portSms.getText())) {
|
|
||||||
return portSms.getText();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSmsVersion() {
|
|
||||||
return smsVerzeComboBox.getSelectedIndex();
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean validatePort(String port) {
|
|
||||||
try {
|
|
||||||
int pNum = Integer.parseInt(port);
|
|
||||||
if ((pNum > 0) && (pNum < 65536)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,210 +0,0 @@
|
||||||
package jnet.client.gui.dialog.object;
|
|
||||||
|
|
||||||
import java.awt.Color;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
import javax.swing.BorderFactory;
|
|
||||||
import javax.swing.DefaultComboBoxModel;
|
|
||||||
import javax.swing.JButton;
|
|
||||||
import javax.swing.JCheckBox;
|
|
||||||
import javax.swing.JComboBox;
|
|
||||||
import javax.swing.JLabel;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JPasswordField;
|
|
||||||
import javax.swing.JTextArea;
|
|
||||||
import javax.swing.JTextField;
|
|
||||||
import jnet.client.Client;
|
|
||||||
import jnet.client.network.NettyClient;
|
|
||||||
import jnet.lib.Message;
|
|
||||||
import jnet.lib.object.MapObject;
|
|
||||||
import jnet.lib.object.ObjectType;
|
|
||||||
import jnet.lib.object.SnmpProfile;
|
|
||||||
|
|
||||||
public class TabSettings extends JPanel {
|
|
||||||
|
|
||||||
private MapObject obj;
|
|
||||||
private boolean newObject;
|
|
||||||
|
|
||||||
private JTextField nazevText = new JTextField();
|
|
||||||
private JLabel nazevWarning = new JLabel("Název musi mit min. 3 znaky");
|
|
||||||
private JTextField ipText = new JTextField();
|
|
||||||
private JLabel ipWarning = new JLabel("Neplatná IP adresa");
|
|
||||||
private JComboBox<String> typeComboBox = new JComboBox<String>();
|
|
||||||
private JTextField userText = new JTextField();
|
|
||||||
private JPasswordField hesloText = new JPasswordField();
|
|
||||||
private DefaultComboBoxModel<String> snmpmodel = new DefaultComboBoxModel<String>();
|
|
||||||
private JCheckBox disableCheBox = new JCheckBox();
|
|
||||||
private JTextField locationText = new JTextField();
|
|
||||||
private JTextArea descriptionText = new JTextArea();
|
|
||||||
private JComboBox<String> snmpProfileComboBox = new JComboBox<String>();
|
|
||||||
|
|
||||||
public TabSettings(MapObject obj, boolean newObject) {
|
|
||||||
this.obj = obj;
|
|
||||||
this.newObject = newObject;
|
|
||||||
|
|
||||||
this.setLayout(null);
|
|
||||||
|
|
||||||
JLabel nazevLabel = new JLabel("Název");
|
|
||||||
nazevLabel.setBounds(20, 30, 80, 25);
|
|
||||||
this.add(nazevLabel);
|
|
||||||
|
|
||||||
nazevText.setBounds(110, 30, 160, 25);
|
|
||||||
this.add(nazevText);
|
|
||||||
|
|
||||||
nazevWarning.setForeground(Color.red);
|
|
||||||
nazevWarning.setBounds(110, 55, 160, 25);
|
|
||||||
nazevWarning.setVisible(false);
|
|
||||||
this.add(nazevWarning);
|
|
||||||
|
|
||||||
JLabel ipLabel = new JLabel("IP adresa");
|
|
||||||
ipLabel.setBounds(300, 30, 80, 25);
|
|
||||||
this.add(ipLabel);
|
|
||||||
|
|
||||||
ipText.setBounds(390, 30, 160, 25);
|
|
||||||
this.add(ipText);
|
|
||||||
ipWarning.setForeground(Color.red);
|
|
||||||
ipWarning.setBounds(390, 55, 160, 25);
|
|
||||||
ipWarning.setVisible(false);
|
|
||||||
this.add(ipWarning);
|
|
||||||
|
|
||||||
JLabel typLabel = new JLabel("Typ");
|
|
||||||
typLabel.setBounds(20, 130, 80, 25);
|
|
||||||
this.add(typLabel);
|
|
||||||
|
|
||||||
DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>();
|
|
||||||
for (ObjectType ot : Client.objectType) {
|
|
||||||
model.addElement(ot.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
typeComboBox.setModel(model);
|
|
||||||
typeComboBox.setBounds(110, 130, 160, 25);
|
|
||||||
this.add(typeComboBox);
|
|
||||||
|
|
||||||
JLabel userLabel = new JLabel("Uživatel");
|
|
||||||
userLabel.setBounds(20, 80, 80, 25);
|
|
||||||
this.add(userLabel);
|
|
||||||
|
|
||||||
userText.setBounds(110, 80, 160, 25);
|
|
||||||
this.add(userText);
|
|
||||||
|
|
||||||
JLabel hesloLabel = new JLabel("Heslo");
|
|
||||||
hesloLabel.setBounds(300, 80, 80, 25);
|
|
||||||
this.add(hesloLabel);
|
|
||||||
|
|
||||||
hesloText.setBounds(390, 80, 160, 25);
|
|
||||||
this.add(hesloText);
|
|
||||||
|
|
||||||
JLabel snmpLabel = new JLabel("SNMP profil");
|
|
||||||
snmpLabel.setBounds(300, 130, 80, 25);
|
|
||||||
this.add(snmpLabel);
|
|
||||||
|
|
||||||
// nacteni snmp profilu
|
|
||||||
for (SnmpProfile sp : Client.snmpProfile) {
|
|
||||||
snmpmodel.addElement(sp.getName());
|
|
||||||
}
|
|
||||||
snmpProfileComboBox.setModel(snmpmodel);
|
|
||||||
snmpProfileComboBox.setBounds(390, 130, 160, 25);
|
|
||||||
this.add(snmpProfileComboBox);
|
|
||||||
|
|
||||||
JLabel disableLabel = new JLabel("Aktivní");
|
|
||||||
disableLabel.setBounds(20, 180, 80, 25);
|
|
||||||
this.add(disableLabel);
|
|
||||||
|
|
||||||
disableCheBox.setBounds(110, 180, 160, 25);
|
|
||||||
this.add(disableCheBox);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
JLabel locLabel = new JLabel("Umístění");
|
|
||||||
locLabel.setBounds(20, 230, 80, 25);
|
|
||||||
this.add(locLabel);
|
|
||||||
|
|
||||||
locationText.setBounds(110, 230, 440, 25);
|
|
||||||
this.add(locationText);
|
|
||||||
|
|
||||||
JLabel descLabel = new JLabel("Poznámka");
|
|
||||||
descLabel.setBounds(20, 280, 80, 25);
|
|
||||||
this.add(descLabel);
|
|
||||||
|
|
||||||
descriptionText.setBounds(110, 280, 440, 100);
|
|
||||||
descriptionText.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.BLACK), BorderFactory.createEmptyBorder(10, 10, 10, 10)));
|
|
||||||
this.add(descriptionText);
|
|
||||||
|
|
||||||
// predvyplneni poli
|
|
||||||
if (!newObject) {
|
|
||||||
nazevText.setText(obj.getName());
|
|
||||||
ipText.setText(obj.getIp());
|
|
||||||
userText.setText(obj.getUser());
|
|
||||||
hesloText.setText(obj.getPassword());
|
|
||||||
for (int i = 0; i < Client.objectType.size() - 1; i++) {
|
|
||||||
if (obj.getObjectType() == Client.objectType.get(i).getId()) {
|
|
||||||
typeComboBox.setSelectedIndex(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < Client.snmpProfile.size(); i++) {
|
|
||||||
if (Client.snmpProfile.get(i).getId() == obj.getSnmpProfile()) {
|
|
||||||
snmpProfileComboBox.setSelectedIndex(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
disableCheBox.setSelected(obj.isActive());
|
|
||||||
descriptionText.setText(obj.getDescription());
|
|
||||||
locationText.setText(obj.getLocation());
|
|
||||||
} else {
|
|
||||||
disableCheBox.setSelected(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean validateIp(String ip) {
|
|
||||||
Pattern pattern = Pattern.compile("^(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])$");
|
|
||||||
Matcher matcher = pattern.matcher(ip);
|
|
||||||
return matcher.matches();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
if (nazevText.getText().length() < 3) {
|
|
||||||
nazevWarning.setVisible(true);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return nazevText.getText();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getIp() {
|
|
||||||
if (!validateIp(ipText.getText())) {
|
|
||||||
ipWarning.setVisible(true);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return ipText.getText();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUser() {
|
|
||||||
return userText.getText();
|
|
||||||
}
|
|
||||||
|
|
||||||
public char[] getPassword(){
|
|
||||||
return hesloText.getPassword();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getObjType(){
|
|
||||||
return typeComboBox.getSelectedIndex();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSnmpProfile(){
|
|
||||||
return snmpProfileComboBox.getSelectedIndex();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDesc(){
|
|
||||||
return descriptionText.getText();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLoc() {
|
|
||||||
return locationText.getText();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isActive(){
|
|
||||||
return disableCheBox.isSelected();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,64 +0,0 @@
|
||||||
package jnet.client.gui.mapview;
|
|
||||||
|
|
||||||
import java.awt.Point;
|
|
||||||
import java.awt.event.MouseEvent;
|
|
||||||
import java.awt.event.MouseListener;
|
|
||||||
import java.awt.geom.Line2D;
|
|
||||||
import jnet.client.gui.dialog.ConnectionDialog;
|
|
||||||
|
|
||||||
public class ConnectionListener implements MouseListener {
|
|
||||||
|
|
||||||
private final double TOLERANCE = 10;
|
|
||||||
|
|
||||||
private PaintConnection selectedConnection;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseClicked(MouseEvent e) {
|
|
||||||
if (e.getClickCount() == 2) {
|
|
||||||
// dvojité kliknutí
|
|
||||||
|
|
||||||
if (MapView.paintConnection == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
selectedConnection = findObjectAt(e.getPoint());
|
|
||||||
|
|
||||||
if (selectedConnection != null) {
|
|
||||||
new ConnectionDialog(selectedConnection.getConnection());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mousePressed(MouseEvent e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseReleased(MouseEvent e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseEntered(MouseEvent e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseExited(MouseEvent e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isPointNearLine(Point p, Line2D line, double tolerance) {
|
|
||||||
return line.ptSegDist(p) <= tolerance; // Zkontroluje vzdálenost bodu od čáry
|
|
||||||
}
|
|
||||||
|
|
||||||
private PaintConnection findObjectAt(Point p) {
|
|
||||||
for (PaintConnection node : MapView.paintConnection) {
|
|
||||||
Line2D.Double line = new Line2D.Double(node.getFrom().getX(), node.getFrom().getY(), node.getTo().getX(), node.getTo().getY());
|
|
||||||
//node.setSelected(false);
|
|
||||||
if (isPointNearLine(p, line, TOLERANCE)) {
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,300 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,195 +0,0 @@
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Point getFrom() {
|
|
||||||
return this.from;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Point getTo() {
|
|
||||||
return this.to;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Connection getConnection() {
|
|
||||||
return this.con;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue