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.object.Event;
|
||||
import jnet.lib.object.Map;
|
||||
import jnet.lib.object.MapObject;
|
||||
import jnet.lib.object.ObjectType;
|
||||
import jnet.lib.object.OnlineClients;
|
||||
import jnet.lib.object.ServerConfig;
|
||||
|
|
@ -26,12 +25,12 @@ public class Client {
|
|||
public static final String APP_NAME = "jNet";
|
||||
|
||||
public static List<Map> maps = new CopyOnWriteArrayList<>();
|
||||
public static ArrayList<MapObject> mapObject = new ArrayList<>();
|
||||
public static ArrayList<OnlineClients> onlineClients = new ArrayList<>();
|
||||
public static ArrayList<ObjectType> objectType = new ArrayList<>();
|
||||
public static ArrayList<SnmpProfile> snmpProfile = new ArrayList<>();
|
||||
public static ArrayList<User> users = new ArrayList<>();
|
||||
public static ArrayList<Event> events = new ArrayList<>();
|
||||
//public static List<MapObject> mapObject = new ArrayList<>();
|
||||
public static List<OnlineClients> onlineClients = new ArrayList<>();
|
||||
public static List<ObjectType> objectType = new ArrayList<>();
|
||||
public static List<SnmpProfile> snmpProfile = new ArrayList<>();
|
||||
public static List<User> users = new ArrayList<>();
|
||||
public static List<Event> events = new ArrayList<>();
|
||||
public static User user;
|
||||
public static boolean connected = false;
|
||||
public static Window okno = new Window();
|
||||
|
|
|
|||
|
|
@ -3,9 +3,6 @@ package jnet.client;
|
|||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
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.network.NettyClient;
|
||||
import jnet.lib.LogFile;
|
||||
|
|
@ -34,7 +31,6 @@ public class ClientMessageParser {
|
|||
handlers.put(Message.USER, ClientMessageParser::handleUser);
|
||||
handlers.put(Message.USER_INFO, ClientMessageParser::handleUserInfo);
|
||||
handlers.put(Message.MAP, ClientMessageParser::handleMap);
|
||||
handlers.put(Message.OBJECT_LIST, ClientMessageParser::handleObjectList);
|
||||
handlers.put(Message.STATUS_UPDATE, ClientMessageParser::handleStatusUpdate);
|
||||
handlers.put(Message.SET_MAP_LOCK, ClientMessageParser::handleSetMapLock);
|
||||
handlers.put(Message.SNMP_PROFILE, ClientMessageParser::handleSnmpProfile);
|
||||
|
|
@ -102,19 +98,12 @@ public class ClientMessageParser {
|
|||
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) {
|
||||
int[] o = (int[]) msg.getMsg();
|
||||
int obj_id = o[0];
|
||||
int status = o[1];
|
||||
|
||||
for (MapObject mapObject : Client.mapObject) {
|
||||
for (Map map : Client.maps) {
|
||||
for (MapObject mapObject : map.getObjects()) {
|
||||
if (mapObject.getId() == obj_id) {
|
||||
mapObject.setStatus(status);
|
||||
// aktualizace UI
|
||||
|
|
@ -123,6 +112,8 @@ public class ClientMessageParser {
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SoundManager.changeStatus(status);
|
||||
}
|
||||
|
||||
|
|
@ -159,12 +150,23 @@ public class ClientMessageParser {
|
|||
}
|
||||
|
||||
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) {
|
||||
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
|
||||
UIUpdater.updateMapTree();
|
||||
UIUpdater.updateTray();
|
||||
|
|
@ -172,14 +174,17 @@ public class ClientMessageParser {
|
|||
|
||||
private static void handleUpdateObject(Message msg) {
|
||||
MapObject mo = (MapObject) msg.getMsg();
|
||||
for (int i = 0; i < Client.mapObject.size(); i++) {
|
||||
if (Client.mapObject.get(i).getId() == mo.getId()) {
|
||||
Client.mapObject.set(i, mo);
|
||||
for (Map map : Client.maps) {
|
||||
for (int i = 0; i < map.getObjects().size(); i++) {
|
||||
if (map.getObjects().get(i).getId() == mo.getId()) {
|
||||
map.getObjects().set(i, mo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void handleMapRemove(Message msg) {
|
||||
int mapId = (int) msg.getMsg();
|
||||
Client.maps.removeIf(map -> map.getId() == mapId);
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import javax.sound.sampled.FloatControl;
|
|||
import javax.sound.sampled.LineUnavailableException;
|
||||
import javax.sound.sampled.UnsupportedAudioFileException;
|
||||
import jnet.lib.Status;
|
||||
import jnet.lib.object.Map;
|
||||
import jnet.lib.object.MapObject;
|
||||
|
||||
public class SoundManager {
|
||||
|
|
@ -19,20 +20,19 @@ public class SoundManager {
|
|||
|
||||
public static void playOnline(){
|
||||
int count = 0;
|
||||
ListIterator<MapObject> iteratorMapObject = Client.mapObject.listIterator();
|
||||
while (iteratorMapObject.hasNext()) {
|
||||
MapObject obj = iteratorMapObject.next();
|
||||
if (obj.getStatus() == Status.OFFLINE && count != 0) {
|
||||
for (Map map : Client.maps) {
|
||||
for (MapObject object : map.getObjects()) {
|
||||
if (object.getStatus() == Status.OFFLINE && count != 0) {
|
||||
playNextOffline();
|
||||
break;
|
||||
} else if (obj.getStatus() == Status.OFFLINE) {
|
||||
System.err.println(obj.getName());
|
||||
} else if (object.getStatus() == Status.OFFLINE) {
|
||||
count++;
|
||||
playFirstOffline();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void changeStatus(int state){
|
||||
if (Client.config.getBoolean("sound")) {
|
||||
|
|
|
|||
|
|
@ -81,9 +81,9 @@ public class EventsPanel extends JPanel {
|
|||
}
|
||||
|
||||
private String[] getObjetInfo(int id) {
|
||||
for (MapObject mapObject : Client.mapObject) {
|
||||
if (mapObject.getId() == id) {
|
||||
for (Map map : Client.maps) {
|
||||
for (MapObject mapObject : map.getObjects()) {
|
||||
if (mapObject.getId() == id) {
|
||||
if (map.getId() == mapObject.getMap()) {
|
||||
String[] data = {map.getName(), mapObject.getName()};
|
||||
return data;
|
||||
|
|
@ -91,6 +91,7 @@ public class EventsPanel extends JPanel {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public class MapTreeCellRenderer extends DefaultTreeCellRenderer {
|
|||
if (o instanceof Map) {
|
||||
try {
|
||||
Map m = (Map) o;
|
||||
switch (getMapStatus(m.getId())) {
|
||||
switch (m.getStatus()) {
|
||||
case Status.OK: // online
|
||||
image = ImageIO.read(new File("img/flag_green.png"));
|
||||
break;
|
||||
|
|
@ -60,26 +60,4 @@ public class MapTreeCellRenderer extends DefaultTreeCellRenderer {
|
|||
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) {
|
||||
for (MapObject obj : Client.mapObject) {
|
||||
for (Map map : Client.maps) {
|
||||
for (MapObject obj : map.getObjects()) {
|
||||
if (obj.getMap() == mapId) {
|
||||
paintObjects.add(new PaintObject(obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -158,15 +158,15 @@ public class MapViewAction implements MouseMotionListener, MouseListener {
|
|||
|
||||
private void doubleClickOnObject(PaintObject selectedObject) {
|
||||
int id = selectedObject.getId();
|
||||
Iterator<MapObject> iteratorMapObject = Client.mapObject.iterator();
|
||||
while (iteratorMapObject.hasNext()) {
|
||||
MapObject obj = iteratorMapObject.next();
|
||||
if (obj.getId() == id) {
|
||||
new ObjectDialog(map.getId(), obj, false);
|
||||
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();
|
||||
|
|
|
|||
|
|
@ -15,12 +15,11 @@ import java.util.Iterator;
|
|||
import javax.imageio.ImageIO;
|
||||
import jnet.lib.LogFile;
|
||||
import jnet.lib.Status;
|
||||
import jnet.lib.object.Map;
|
||||
import jnet.lib.object.MapObject;
|
||||
|
||||
public class Tray {
|
||||
|
||||
|
||||
|
||||
private SystemTray tray = SystemTray.getSystemTray();
|
||||
private static TrayIcon trayIcon;
|
||||
private static PopupMenu menu = new PopupMenu();
|
||||
|
|
@ -49,14 +48,15 @@ public class Tray {
|
|||
trayIcon = new TrayIcon(ImageIO.read(new File("img/flag_gray.png")), Client.APP_NAME, menu);
|
||||
trayIcon.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed( ActionEvent e ) {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
//Double click - obnovit/minimalizovat
|
||||
if (Client.okno.isVisible()) {
|
||||
Client.okno.setVisible(false);
|
||||
} else {
|
||||
Client.okno.setVisible(true);
|
||||
}
|
||||
}}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
tray = SystemTray.getSystemTray();
|
||||
|
|
@ -71,7 +71,7 @@ public class Tray {
|
|||
|
||||
public static void setIcon(String icon) {
|
||||
try {
|
||||
BufferedImage image = ImageIO.read(new File("img/"+icon));
|
||||
BufferedImage image = ImageIO.read(new File("img/" + icon));
|
||||
trayIcon.setImage(image);
|
||||
} catch (IOException ex) {
|
||||
LogFile.printErr("TrayIcon error: " + ex.getMessage());
|
||||
|
|
@ -79,7 +79,6 @@ public class Tray {
|
|||
|
||||
}
|
||||
|
||||
|
||||
public static void setStatusOffline() {
|
||||
setIcon("flag_red.png");
|
||||
}
|
||||
|
|
@ -97,17 +96,17 @@ public class Tray {
|
|||
}
|
||||
|
||||
public static void refresh() {
|
||||
Iterator<MapObject> iteratorMapObject = Client.mapObject.iterator();
|
||||
while (iteratorMapObject.hasNext()) {
|
||||
MapObject obj = iteratorMapObject.next();
|
||||
switch (obj.getStatus()) {
|
||||
case Status.OFFLINE:
|
||||
setStatusOffline();
|
||||
case Status.WARNING:
|
||||
setStatusWarning();
|
||||
break;
|
||||
default:
|
||||
setStatusOnline();
|
||||
setStatusOnline(); // Výchozí stav
|
||||
|
||||
for (Map map : Client.maps) {
|
||||
int status = map.getStatus();
|
||||
|
||||
if (status == Status.OFFLINE) {
|
||||
setStatusOffline(); // OFFLINE má nejvyšší prioritu
|
||||
return;
|
||||
}
|
||||
if (status == Status.WARNING) {
|
||||
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