vnoření mapObject zpet do map
parent
05dd0f7273
commit
57371e1f26
|
|
@ -0,0 +1 @@
|
||||||
|
*.log
|
||||||
|
|
@ -11,7 +11,6 @@ import jnet.lib.LogFile;
|
||||||
import jnet.lib.PropertiesManager;
|
import jnet.lib.PropertiesManager;
|
||||||
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.ObjectType;
|
import jnet.lib.object.ObjectType;
|
||||||
import jnet.lib.object.OnlineClients;
|
import jnet.lib.object.OnlineClients;
|
||||||
import jnet.lib.object.ServerConfig;
|
import jnet.lib.object.ServerConfig;
|
||||||
|
|
@ -26,12 +25,12 @@ public class Client {
|
||||||
public static final String APP_NAME = "jNet";
|
public static final String APP_NAME = "jNet";
|
||||||
|
|
||||||
public static List<Map> maps = new CopyOnWriteArrayList<>();
|
public static List<Map> maps = new CopyOnWriteArrayList<>();
|
||||||
public static ArrayList<MapObject> mapObject = new ArrayList<>();
|
//public static List<MapObject> mapObject = new ArrayList<>();
|
||||||
public static ArrayList<OnlineClients> onlineClients = new ArrayList<>();
|
public static List<OnlineClients> onlineClients = new ArrayList<>();
|
||||||
public static ArrayList<ObjectType> objectType = new ArrayList<>();
|
public static List<ObjectType> objectType = new ArrayList<>();
|
||||||
public static ArrayList<SnmpProfile> snmpProfile = new ArrayList<>();
|
public static List<SnmpProfile> snmpProfile = new ArrayList<>();
|
||||||
public static ArrayList<User> users = new ArrayList<>();
|
public static List<User> users = new ArrayList<>();
|
||||||
public static ArrayList<Event> events = new ArrayList<>();
|
public static List<Event> events = new ArrayList<>();
|
||||||
public static User user;
|
public static User user;
|
||||||
public static boolean connected = false;
|
public static boolean connected = false;
|
||||||
public static Window okno = new Window();
|
public static Window okno = new Window();
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,6 @@ package jnet.client;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import javax.swing.SwingUtilities;
|
|
||||||
import jnet.client.gui.MapTree;
|
|
||||||
import jnet.client.gui.Tray;
|
|
||||||
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;
|
||||||
|
|
@ -34,7 +31,6 @@ public class ClientMessageParser {
|
||||||
handlers.put(Message.USER, ClientMessageParser::handleUser);
|
handlers.put(Message.USER, ClientMessageParser::handleUser);
|
||||||
handlers.put(Message.USER_INFO, ClientMessageParser::handleUserInfo);
|
handlers.put(Message.USER_INFO, ClientMessageParser::handleUserInfo);
|
||||||
handlers.put(Message.MAP, ClientMessageParser::handleMap);
|
handlers.put(Message.MAP, ClientMessageParser::handleMap);
|
||||||
handlers.put(Message.OBJECT_LIST, ClientMessageParser::handleObjectList);
|
|
||||||
handlers.put(Message.STATUS_UPDATE, ClientMessageParser::handleStatusUpdate);
|
handlers.put(Message.STATUS_UPDATE, ClientMessageParser::handleStatusUpdate);
|
||||||
handlers.put(Message.SET_MAP_LOCK, ClientMessageParser::handleSetMapLock);
|
handlers.put(Message.SET_MAP_LOCK, ClientMessageParser::handleSetMapLock);
|
||||||
handlers.put(Message.SNMP_PROFILE, ClientMessageParser::handleSnmpProfile);
|
handlers.put(Message.SNMP_PROFILE, ClientMessageParser::handleSnmpProfile);
|
||||||
|
|
@ -102,27 +98,22 @@ public class ClientMessageParser {
|
||||||
UIUpdater.updateTray();
|
UIUpdater.updateTray();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void handleObjectList(Message msg) {
|
|
||||||
Client.mapObject = (ArrayList<MapObject>) msg.getMsg();
|
|
||||||
// aktualizace UI
|
|
||||||
UIUpdater.updateMapTree();
|
|
||||||
UIUpdater.updateTray();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void handleStatusUpdate(Message msg) {
|
private static void handleStatusUpdate(Message msg) {
|
||||||
int[] o = (int[]) msg.getMsg();
|
int[] o = (int[]) msg.getMsg();
|
||||||
int obj_id = o[0];
|
int obj_id = o[0];
|
||||||
int status = o[1];
|
int status = o[1];
|
||||||
|
for (Map map : Client.maps) {
|
||||||
for (MapObject mapObject : Client.mapObject) {
|
for (MapObject mapObject : map.getObjects()) {
|
||||||
if (mapObject.getId() == obj_id) {
|
if (mapObject.getId() == obj_id) {
|
||||||
mapObject.setStatus(status);
|
mapObject.setStatus(status);
|
||||||
// aktualizace UI
|
// aktualizace UI
|
||||||
UIUpdater.updateMapTree();
|
UIUpdater.updateMapTree();
|
||||||
UIUpdater.updateTray();
|
UIUpdater.updateTray();
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SoundManager.changeStatus(status);
|
SoundManager.changeStatus(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -159,12 +150,23 @@ public class ClientMessageParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void handleAddObject(Message msg) {
|
private static void handleAddObject(Message msg) {
|
||||||
Client.mapObject.add((MapObject) msg.getMsg());
|
MapObject mo = (MapObject) msg.getMsg();
|
||||||
|
for (Map map : Client.maps) {
|
||||||
|
if (map.getId() == mo.getMap()) {
|
||||||
|
map.getObjects().add(mo);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void handleRemoveObject(Message msg) {
|
private static void handleRemoveObject(Message msg) {
|
||||||
int objId = (int) msg.getMsg();
|
int objId = (int) msg.getMsg();
|
||||||
Client.mapObject.removeIf(mapObject -> mapObject.getId() == objId);
|
for (Map map : Client.maps) {
|
||||||
|
for (MapObject object : map.getObjects()) {
|
||||||
|
if (object.getId() == objId) {
|
||||||
|
map.getObjects().remove(object);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// aktualizace UI
|
// aktualizace UI
|
||||||
UIUpdater.updateMapTree();
|
UIUpdater.updateMapTree();
|
||||||
UIUpdater.updateTray();
|
UIUpdater.updateTray();
|
||||||
|
|
@ -172,12 +174,15 @@ public class ClientMessageParser {
|
||||||
|
|
||||||
private static void handleUpdateObject(Message msg) {
|
private static void handleUpdateObject(Message msg) {
|
||||||
MapObject mo = (MapObject) msg.getMsg();
|
MapObject mo = (MapObject) msg.getMsg();
|
||||||
for (int i = 0; i < Client.mapObject.size(); i++) {
|
for (Map map : Client.maps) {
|
||||||
if (Client.mapObject.get(i).getId() == mo.getId()) {
|
for (int i = 0; i < map.getObjects().size(); i++) {
|
||||||
Client.mapObject.set(i, mo);
|
if (map.getObjects().get(i).getId() == mo.getId()) {
|
||||||
|
map.getObjects().set(i, mo);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void handleMapRemove(Message msg) {
|
private static void handleMapRemove(Message msg) {
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import javax.sound.sampled.FloatControl;
|
||||||
import javax.sound.sampled.LineUnavailableException;
|
import javax.sound.sampled.LineUnavailableException;
|
||||||
import javax.sound.sampled.UnsupportedAudioFileException;
|
import javax.sound.sampled.UnsupportedAudioFileException;
|
||||||
import jnet.lib.Status;
|
import jnet.lib.Status;
|
||||||
|
import jnet.lib.object.Map;
|
||||||
import jnet.lib.object.MapObject;
|
import jnet.lib.object.MapObject;
|
||||||
|
|
||||||
public class SoundManager {
|
public class SoundManager {
|
||||||
|
|
@ -19,18 +20,17 @@ public class SoundManager {
|
||||||
|
|
||||||
public static void playOnline(){
|
public static void playOnline(){
|
||||||
int count = 0;
|
int count = 0;
|
||||||
ListIterator<MapObject> iteratorMapObject = Client.mapObject.listIterator();
|
for (Map map : Client.maps) {
|
||||||
while (iteratorMapObject.hasNext()) {
|
for (MapObject object : map.getObjects()) {
|
||||||
MapObject obj = iteratorMapObject.next();
|
if (object.getStatus() == Status.OFFLINE && count != 0) {
|
||||||
if (obj.getStatus() == Status.OFFLINE && count != 0) {
|
|
||||||
playNextOffline();
|
playNextOffline();
|
||||||
break;
|
break;
|
||||||
} else if (obj.getStatus() == Status.OFFLINE) {
|
} else if (object.getStatus() == Status.OFFLINE) {
|
||||||
System.err.println(obj.getName());
|
|
||||||
count++;
|
count++;
|
||||||
playFirstOffline();
|
playFirstOffline();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -81,9 +81,9 @@ public class EventsPanel extends JPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String[] getObjetInfo(int id) {
|
private String[] getObjetInfo(int id) {
|
||||||
for (MapObject mapObject : Client.mapObject) {
|
for (Map map : Client.maps) {
|
||||||
if (mapObject.getId() == id) {
|
for (MapObject mapObject : map.getObjects()) {
|
||||||
for (Map map : Client.maps) {
|
if (mapObject.getId() == id) {
|
||||||
if (map.getId() == mapObject.getMap()) {
|
if (map.getId() == mapObject.getMap()) {
|
||||||
String[] data = {map.getName(), mapObject.getName()};
|
String[] data = {map.getName(), mapObject.getName()};
|
||||||
return data;
|
return data;
|
||||||
|
|
@ -91,6 +91,7 @@ public class EventsPanel extends JPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ public class MapTreeCellRenderer extends DefaultTreeCellRenderer {
|
||||||
if (o instanceof Map) {
|
if (o instanceof Map) {
|
||||||
try {
|
try {
|
||||||
Map m = (Map) o;
|
Map m = (Map) o;
|
||||||
switch (getMapStatus(m.getId())) {
|
switch (m.getStatus()) {
|
||||||
case Status.OK: // online
|
case Status.OK: // online
|
||||||
image = ImageIO.read(new File("img/flag_green.png"));
|
image = ImageIO.read(new File("img/flag_green.png"));
|
||||||
break;
|
break;
|
||||||
|
|
@ -60,26 +60,4 @@ public class MapTreeCellRenderer extends DefaultTreeCellRenderer {
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getMapStatus(int mapId) {
|
|
||||||
int status = Status.NA;
|
|
||||||
Iterator<MapObject> iteratorMapObject = Client.mapObject.iterator();
|
|
||||||
while (iteratorMapObject.hasNext()) {
|
|
||||||
MapObject obj = iteratorMapObject.next();
|
|
||||||
if (obj.getMap() == mapId) {
|
|
||||||
switch (obj.getStatus()) {
|
|
||||||
case Status.OFFLINE:
|
|
||||||
return Status.OFFLINE;
|
|
||||||
case Status.WARNING:
|
|
||||||
status = Status.WARNING;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (status != Status.WARNING) {
|
|
||||||
status = Status.OK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -80,23 +80,15 @@ public class MapView extends JPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateMapView(int mapId) {
|
|
||||||
for (Map map : Client.maps) {
|
|
||||||
if (map.getId() == mapId) {
|
|
||||||
// obnoveni objektu
|
|
||||||
paintObjects.clear();
|
|
||||||
// nahrat objekty
|
|
||||||
loadObject(map.getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void loadObject(int mapId) {
|
private static void loadObject(int mapId) {
|
||||||
for (MapObject obj : Client.mapObject) {
|
for (Map map : Client.maps) {
|
||||||
if (obj.getMap() == mapId) {
|
for (MapObject obj : map.getObjects()) {
|
||||||
paintObjects.add(new PaintObject(obj));
|
if (obj.getMap() == mapId) {
|
||||||
|
paintObjects.add(new PaintObject(obj));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,12 +75,12 @@ public class MapViewAction implements MouseMotionListener, MouseListener {
|
||||||
// odeslani nove pozice objektu
|
// odeslani nove pozice objektu
|
||||||
// TODO doresit kontrolu souradnic aby se zbytecne neodesilala zmena kdyz k ni nedojde
|
// TODO doresit kontrolu souradnic aby se zbytecne neodesilala zmena kdyz k ni nedojde
|
||||||
// zkontrolovat zda došlo ke zmene pozice
|
// zkontrolovat zda došlo ke zmene pozice
|
||||||
int[] data = {
|
int[] data = {
|
||||||
selectedObject.getId(),
|
selectedObject.getId(),
|
||||||
(int) selectedObject.getX(),
|
(int) selectedObject.getX(),
|
||||||
(int) selectedObject.getY()
|
(int) selectedObject.getY()
|
||||||
};
|
};
|
||||||
NettyClient.send(Message.OBJECT_MOVE, data);
|
NettyClient.send(Message.OBJECT_MOVE, data);
|
||||||
}
|
}
|
||||||
// dvojklik na objekt
|
// dvojklik na objekt
|
||||||
if (e.getClickCount() == 2) {
|
if (e.getClickCount() == 2) {
|
||||||
|
|
@ -158,12 +158,12 @@ public class MapViewAction implements MouseMotionListener, MouseListener {
|
||||||
|
|
||||||
private void doubleClickOnObject(PaintObject selectedObject) {
|
private void doubleClickOnObject(PaintObject selectedObject) {
|
||||||
int id = selectedObject.getId();
|
int id = selectedObject.getId();
|
||||||
Iterator<MapObject> iteratorMapObject = Client.mapObject.iterator();
|
for (Map map : Client.maps) {
|
||||||
while (iteratorMapObject.hasNext()) {
|
for (MapObject object : map.getObjects()) {
|
||||||
MapObject obj = iteratorMapObject.next();
|
if (object.getId() == id) {
|
||||||
if (obj.getId() == id) {
|
new ObjectDialog(map.getId(), object, false);
|
||||||
new ObjectDialog(map.getId(), obj, false);
|
break;
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,12 +15,11 @@ import java.util.Iterator;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import jnet.lib.LogFile;
|
import jnet.lib.LogFile;
|
||||||
import jnet.lib.Status;
|
import jnet.lib.Status;
|
||||||
|
import jnet.lib.object.Map;
|
||||||
import jnet.lib.object.MapObject;
|
import jnet.lib.object.MapObject;
|
||||||
|
|
||||||
public class Tray {
|
public class Tray {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private SystemTray tray = SystemTray.getSystemTray();
|
private SystemTray tray = SystemTray.getSystemTray();
|
||||||
private static TrayIcon trayIcon;
|
private static TrayIcon trayIcon;
|
||||||
private static PopupMenu menu = new PopupMenu();
|
private static PopupMenu menu = new PopupMenu();
|
||||||
|
|
@ -38,25 +37,26 @@ public class Tray {
|
||||||
MenuItem exitItem = new MenuItem("Ukončit");
|
MenuItem exitItem = new MenuItem("Ukončit");
|
||||||
exitItem.addActionListener(new ActionListener() {
|
exitItem.addActionListener(new ActionListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
LogFile.printInfo("Exit appliaction from tray icon");
|
LogFile.printInfo("Exit appliaction from tray icon");
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
menu.add(exitItem);
|
menu.add(exitItem);
|
||||||
|
|
||||||
trayIcon = new TrayIcon(ImageIO.read(new File("img/flag_gray.png")), Client.APP_NAME, menu);
|
trayIcon = new TrayIcon(ImageIO.read(new File("img/flag_gray.png")), Client.APP_NAME, menu);
|
||||||
trayIcon.addActionListener(new ActionListener() {
|
trayIcon.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed( ActionEvent e ) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
//Double click - obnovit/minimalizovat
|
//Double click - obnovit/minimalizovat
|
||||||
if (Client.okno.isVisible()) {
|
if (Client.okno.isVisible()) {
|
||||||
Client.okno.setVisible(false);
|
Client.okno.setVisible(false);
|
||||||
} else {
|
} else {
|
||||||
Client.okno.setVisible(true);
|
Client.okno.setVisible(true);
|
||||||
}
|
}
|
||||||
}}
|
}
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
tray = SystemTray.getSystemTray();
|
tray = SystemTray.getSystemTray();
|
||||||
|
|
@ -71,7 +71,7 @@ public class Tray {
|
||||||
|
|
||||||
public static void setIcon(String icon) {
|
public static void setIcon(String icon) {
|
||||||
try {
|
try {
|
||||||
BufferedImage image = ImageIO.read(new File("img/"+icon));
|
BufferedImage image = ImageIO.read(new File("img/" + icon));
|
||||||
trayIcon.setImage(image);
|
trayIcon.setImage(image);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
LogFile.printErr("TrayIcon error: " + ex.getMessage());
|
LogFile.printErr("TrayIcon error: " + ex.getMessage());
|
||||||
|
|
@ -79,7 +79,6 @@ public class Tray {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void setStatusOffline() {
|
public static void setStatusOffline() {
|
||||||
setIcon("flag_red.png");
|
setIcon("flag_red.png");
|
||||||
}
|
}
|
||||||
|
|
@ -97,17 +96,17 @@ public class Tray {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void refresh() {
|
public static void refresh() {
|
||||||
Iterator<MapObject> iteratorMapObject = Client.mapObject.iterator();
|
setStatusOnline(); // Výchozí stav
|
||||||
while (iteratorMapObject.hasNext()) {
|
|
||||||
MapObject obj = iteratorMapObject.next();
|
for (Map map : Client.maps) {
|
||||||
switch (obj.getStatus()) {
|
int status = map.getStatus();
|
||||||
case Status.OFFLINE:
|
|
||||||
setStatusOffline();
|
if (status == Status.OFFLINE) {
|
||||||
case Status.WARNING:
|
setStatusOffline(); // OFFLINE má nejvyšší prioritu
|
||||||
setStatusWarning();
|
return;
|
||||||
break;
|
}
|
||||||
default:
|
if (status == Status.WARNING) {
|
||||||
setStatusOnline();
|
setStatusWarning(); // Možná varování, ale pokračujeme
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
package jnet.client.gui;
|
||||||
|
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
|
|
||||||
|
public class UIUpdater {
|
||||||
|
|
||||||
|
public static void updateMapUI() {
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
MapTree.reload();
|
||||||
|
Tray.refresh();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updateMapTree() {
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
MapTree.reload();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updateTray() {
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
Tray.refresh();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue