first
commit
69317372ab
|
|
@ -0,0 +1,164 @@
|
|||
25.08.26 23:45:18 I ---------------------------------------------
|
||||
25.08.26 23:45:18 I jNet Client
|
||||
25.08.26 23:45:18 I Version: 1 (Tue Aug 25 22:22:02 CEST 2026)
|
||||
25.08.26 23:45:18 I ---------------------------------------------
|
||||
25.08.26 23:45:18 I
|
||||
25.08.26 23:45:18 I Loading config ...
|
||||
25.08.26 23:45:18 I successfully
|
||||
25.08.26 23:45:18 I Debug mode
|
||||
25.08.26 23:45:18 I Nalezen putty.exe v: C:\Users\cucky\Documents\NetBeansProjects\jNet\jNetClient\src\main\resources\app\putty.exe
|
||||
25.08.26 23:45:18 I Nalezen winbox.exe v: C:\Users\cucky\Documents\NetBeansProjects\jNet\jNetClient\src\main\resources\app\winbox.exe
|
||||
25.08.26 23:45:18 I Nalezen smsc_sdv.exe v: C:\Users\cucky\Documents\NetBeansProjects\jNet\jNetClient\src\main\resources\app\smsc_sdv.exe
|
||||
25.08.26 23:45:18 I Nalezen smsc_bth.exe v: C:\Users\cucky\Documents\NetBeansProjects\jNet\jNetClient\src\main\resources\app\smsc_bth.exe
|
||||
25.08.26 23:45:18 I Nalezen smsc_bt.exe v: C:\Users\cucky\Documents\NetBeansProjects\jNet\jNetClient\src\main\resources\app\smsc_bt.exe
|
||||
25.08.26 23:45:18 I RemoteAdminTools inicializovan, app dir: C:\Users\cucky\Documents\NetBeansProjects\jNet\jNetClient\src\main\resources\app
|
||||
25.08.26 23:45:19 I Connected to server
|
||||
25.08.26 23:45:19 D Received message ID: 102
|
||||
25.08.26 23:45:19 D Received message ID: 103
|
||||
25.08.26 23:45:19 D Received message ID: 111
|
||||
25.08.26 23:45:19 D Received message ID: 105
|
||||
25.08.26 23:45:19 D Received message ID: 109
|
||||
25.08.26 23:45:19 D Received message ID: 113
|
||||
25.08.26 23:45:19 D Received message ID: 112
|
||||
25.08.26 23:45:19 D Received message ID: 116
|
||||
25.08.26 23:45:19 D Received message ID: 106
|
||||
25.08.26 23:45:19 D Received message ID: 124
|
||||
25.08.26 23:45:19 D Received message ID: 131
|
||||
25.08.26 23:45:19 D Received message ID: 132
|
||||
25.08.26 23:45:23 D Received message ID: 134
|
||||
25.08.26 23:45:26 D Received message ID: 133
|
||||
25.08.26 23:45:27 D Received message ID: 134
|
||||
25.08.26 23:45:33 D Received message ID: 134
|
||||
25.08.26 23:45:37 D Received message ID: 134
|
||||
25.08.26 23:45:43 D Received message ID: 134
|
||||
25.08.26 23:45:47 D Received message ID: 134
|
||||
25.08.26 23:45:53 D Received message ID: 134
|
||||
25.08.26 23:45:56 D Received message ID: 133
|
||||
25.08.26 23:45:57 D Received message ID: 134
|
||||
25.08.26 23:46:03 D Received message ID: 134
|
||||
25.08.26 23:46:07 D Received message ID: 134
|
||||
25.08.26 23:46:13 D Received message ID: 134
|
||||
25.08.26 23:46:17 D Received message ID: 134
|
||||
25.08.26 23:46:23 D Received message ID: 134
|
||||
25.08.26 23:46:26 D Received message ID: 133
|
||||
25.08.26 23:46:27 D Received message ID: 134
|
||||
25.08.26 23:46:33 D Received message ID: 134
|
||||
25.08.26 23:46:37 D Received message ID: 134
|
||||
25.08.26 23:46:43 D Received message ID: 134
|
||||
25.08.26 23:46:47 D Received message ID: 134
|
||||
25.08.26 23:46:51 D Received message ID: 134
|
||||
25.08.26 23:46:53 D Received message ID: 134
|
||||
25.08.26 23:46:56 D Received message ID: 133
|
||||
25.08.26 23:46:57 D Received message ID: 134
|
||||
25.08.26 23:47:03 D Received message ID: 134
|
||||
25.08.26 23:47:07 D Received message ID: 134
|
||||
25.08.26 23:47:13 D Received message ID: 134
|
||||
25.08.26 23:47:17 D Received message ID: 134
|
||||
25.08.26 23:47:23 D Received message ID: 134
|
||||
25.08.26 23:47:26 D Received message ID: 133
|
||||
25.08.26 23:47:27 D Received message ID: 134
|
||||
25.08.26 23:47:33 D Received message ID: 134
|
||||
25.08.26 23:47:37 D Received message ID: 134
|
||||
25.08.26 23:47:43 D Received message ID: 134
|
||||
25.08.26 23:47:47 D Received message ID: 134
|
||||
25.08.26 23:47:53 D Received message ID: 134
|
||||
25.08.26 23:47:56 D Received message ID: 133
|
||||
25.08.26 23:47:57 D Received message ID: 134
|
||||
25.08.26 23:48:03 D Received message ID: 134
|
||||
25.08.26 23:48:07 D Received message ID: 134
|
||||
25.08.26 23:48:13 D Received message ID: 134
|
||||
25.08.26 23:48:17 D Received message ID: 134
|
||||
25.08.26 23:48:23 D Received message ID: 134
|
||||
25.08.26 23:48:28 D Received message ID: 130
|
||||
25.08.26 23:48:28 D Received message ID: 133
|
||||
25.08.26 23:48:28 D Received message ID: 134
|
||||
25.08.26 23:48:28 D Received message ID: 117
|
||||
25.08.26 23:48:28 D Received message ID: 108
|
||||
25.08.26 23:48:33 D Received message ID: 134
|
||||
25.08.26 23:48:36 D Received message ID: 118
|
||||
25.08.26 23:48:36 D Received message ID: 108
|
||||
25.08.26 23:48:37 D Received message ID: 134
|
||||
25.08.26 23:48:43 D Received message ID: 134
|
||||
25.08.26 23:48:47 D Received message ID: 134
|
||||
25.08.26 23:48:53 D Received message ID: 134
|
||||
25.08.26 23:48:56 D Received message ID: 133
|
||||
25.08.26 23:48:57 D Received message ID: 134
|
||||
25.08.26 23:49:03 D Received message ID: 134
|
||||
25.08.26 23:49:07 D Received message ID: 134
|
||||
25.08.26 23:49:13 D Received message ID: 134
|
||||
25.08.26 23:49:17 D Received message ID: 134
|
||||
25.08.26 23:49:23 D Received message ID: 134
|
||||
25.08.26 23:49:26 D Received message ID: 133
|
||||
25.08.26 23:49:27 D Received message ID: 134
|
||||
25.08.26 23:49:33 D Received message ID: 134
|
||||
25.08.26 23:49:37 D Received message ID: 134
|
||||
25.08.26 23:49:43 D Received message ID: 134
|
||||
25.08.26 23:49:47 D Received message ID: 134
|
||||
25.08.26 23:49:53 D Received message ID: 134
|
||||
25.08.26 23:49:56 D Received message ID: 133
|
||||
25.08.26 23:49:57 D Received message ID: 134
|
||||
25.08.26 23:50:03 D Received message ID: 134
|
||||
25.08.26 23:50:07 D Received message ID: 134
|
||||
25.08.26 23:50:13 D Received message ID: 134
|
||||
25.08.26 23:50:17 D Received message ID: 134
|
||||
25.08.26 23:50:21 D Received message ID: 134
|
||||
25.08.26 23:50:23 D Received message ID: 134
|
||||
25.08.26 23:50:26 D Received message ID: 133
|
||||
25.08.26 23:50:27 D Received message ID: 134
|
||||
25.08.26 23:50:33 D Received message ID: 134
|
||||
25.08.26 23:50:37 D Received message ID: 134
|
||||
25.08.26 23:50:43 D Received message ID: 134
|
||||
25.08.26 23:50:47 D Received message ID: 134
|
||||
25.08.26 23:50:53 D Received message ID: 134
|
||||
25.08.26 23:50:56 D Received message ID: 133
|
||||
25.08.26 23:50:57 D Received message ID: 134
|
||||
25.08.26 23:51:03 D Received message ID: 134
|
||||
25.08.26 23:51:07 D Received message ID: 134
|
||||
25.08.26 23:51:13 D Received message ID: 134
|
||||
25.08.26 23:51:17 D Received message ID: 134
|
||||
25.08.26 23:51:23 D Received message ID: 134
|
||||
25.08.26 23:51:26 D Received message ID: 133
|
||||
25.08.26 23:51:27 D Received message ID: 134
|
||||
25.08.26 23:51:33 D Received message ID: 134
|
||||
25.08.26 23:51:37 D Received message ID: 134
|
||||
25.08.26 23:51:43 D Received message ID: 134
|
||||
25.08.26 23:51:47 D Received message ID: 134
|
||||
25.08.26 23:51:53 D Received message ID: 134
|
||||
25.08.26 23:51:56 D Received message ID: 133
|
||||
25.08.26 23:51:57 D Received message ID: 134
|
||||
25.08.26 23:52:01 D Received message ID: 134
|
||||
25.08.26 23:52:03 D Received message ID: 134
|
||||
25.08.26 23:52:07 D Received message ID: 134
|
||||
25.08.26 23:52:13 D Received message ID: 134
|
||||
25.08.26 23:52:17 D Received message ID: 134
|
||||
25.08.26 23:52:23 D Received message ID: 134
|
||||
25.08.26 23:52:26 D Received message ID: 133
|
||||
25.08.26 23:52:27 D Received message ID: 134
|
||||
25.08.26 23:52:33 D Received message ID: 134
|
||||
25.08.26 23:52:37 D Received message ID: 134
|
||||
25.08.26 23:52:43 D Received message ID: 134
|
||||
25.08.26 23:52:47 D Received message ID: 134
|
||||
25.08.26 23:52:53 D Received message ID: 134
|
||||
25.08.26 23:52:56 D Received message ID: 133
|
||||
25.08.26 23:52:57 D Received message ID: 134
|
||||
25.08.26 23:53:03 D Received message ID: 134
|
||||
25.08.26 23:53:07 D Received message ID: 134
|
||||
25.08.26 23:53:13 D Received message ID: 134
|
||||
25.08.26 23:53:17 D Received message ID: 134
|
||||
25.08.26 23:53:23 D Received message ID: 134
|
||||
25.08.26 23:53:26 D Received message ID: 133
|
||||
25.08.26 23:53:27 D Received message ID: 134
|
||||
25.08.26 23:53:33 D Received message ID: 134
|
||||
25.08.26 23:53:37 D Received message ID: 134
|
||||
25.08.26 23:53:43 D Received message ID: 134
|
||||
25.08.26 23:53:47 D Received message ID: 134
|
||||
25.08.26 23:53:53 D Received message ID: 134
|
||||
25.08.26 23:53:56 D Received message ID: 133
|
||||
25.08.26 23:53:57 D Received message ID: 134
|
||||
25.08.26 23:54:03 D Received message ID: 134
|
||||
25.08.26 23:54:07 D Received message ID: 134
|
||||
25.08.26 23:54:13 D Received message ID: 134
|
||||
25.08.26 23:54:17 D Received message ID: 134
|
||||
25.08.26 23:54:23 D Received message ID: 134
|
||||
25.08.26 23:54:23 I Connection reset by server
|
||||
25.08.26 23:54:23 I Connection inactive ..... reconnect initiated
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<actions>
|
||||
<action>
|
||||
<actionName>run</actionName>
|
||||
<packagings>
|
||||
<packaging>jar</packaging>
|
||||
</packagings>
|
||||
<goals>
|
||||
<goal>process-classes</goal>
|
||||
<goal>org.codehaus.mojo:exec-maven-plugin:3.5.1:exec</goal>
|
||||
</goals>
|
||||
<properties>
|
||||
<exec.vmArgs>-Dio.netty.noUnsafe=true -Dio.netty.tryUnsafe=false</exec.vmArgs>
|
||||
<exec.args>${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs}</exec.args>
|
||||
<exec.appArgs></exec.appArgs>
|
||||
<exec.mainClass>${packageClassName}</exec.mainClass>
|
||||
<exec.executable>java</exec.executable>
|
||||
</properties>
|
||||
</action>
|
||||
<action>
|
||||
<actionName>debug</actionName>
|
||||
<packagings>
|
||||
<packaging>jar</packaging>
|
||||
</packagings>
|
||||
<goals>
|
||||
<goal>process-classes</goal>
|
||||
<goal>org.codehaus.mojo:exec-maven-plugin:3.5.1:exec</goal>
|
||||
</goals>
|
||||
<properties>
|
||||
<exec.vmArgs>-Dio.netty.noUnsafe=true -Dio.netty.tryUnsafe=false -agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address}</exec.vmArgs>
|
||||
<exec.args>${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs}</exec.args>
|
||||
<exec.appArgs></exec.appArgs>
|
||||
<exec.mainClass>${packageClassName}</exec.mainClass>
|
||||
<exec.executable>java</exec.executable>
|
||||
<jpda.listen>true</jpda.listen>
|
||||
</properties>
|
||||
</action>
|
||||
<action>
|
||||
<actionName>profile</actionName>
|
||||
<packagings>
|
||||
<packaging>jar</packaging>
|
||||
</packagings>
|
||||
<goals>
|
||||
<goal>process-classes</goal>
|
||||
<goal>org.codehaus.mojo:exec-maven-plugin:3.5.1:exec</goal>
|
||||
</goals>
|
||||
<properties>
|
||||
<exec.vmArgs>-Dio.netty.noUnsafe=true -Dio.netty.tryUnsafe=false</exec.vmArgs>
|
||||
<exec.args>${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs}</exec.args>
|
||||
<exec.mainClass>${packageClassName}</exec.mainClass>
|
||||
<exec.executable>java</exec.executable>
|
||||
<exec.appArgs></exec.appArgs>
|
||||
</properties>
|
||||
</action>
|
||||
</actions>
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>jnet</groupId>
|
||||
<artifactId>jNetClient</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.release>26</maven.compiler.release>
|
||||
<exec.mainClass>jnet.client.Client</exec.mainClass>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
<version>4.1.118.Final</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk18on</artifactId>
|
||||
<version>1.78.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcpkix-jdk18on</artifactId>
|
||||
<version>1.78.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>jNetLib</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<!-- Nastavení názvu výsledného JAR -->
|
||||
<finalName>jNetClient</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.3.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-resources</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-resources</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>false</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,128 @@
|
|||
package jnet.client;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import jnet.client.client.NettyClientManager;
|
||||
import jnet.client.gui.Tray;
|
||||
import jnet.client.gui.Window;
|
||||
import jnet.lib.ApacheConfig;
|
||||
import jnet.lib.BuilddDate;
|
||||
import jnet.lib.LogFile;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.Event;
|
||||
import jnet.lib.object.ObjectType;
|
||||
import jnet.lib.object.OnlineClients;
|
||||
import jnet.lib.object.ServerConfig;
|
||||
import jnet.lib.object.Site;
|
||||
import jnet.lib.object.SnmpProfile;
|
||||
import jnet.lib.object.SnmpTemplate;
|
||||
import jnet.lib.object.SnmpValueMap;
|
||||
import jnet.lib.object.User;
|
||||
import org.apache.commons.configuration2.Configuration;
|
||||
import org.apache.commons.configuration2.ex.ConfigurationException;
|
||||
|
||||
public class Client {
|
||||
|
||||
// verze klienta
|
||||
public static final int VERSION = 1;
|
||||
// jméno aplikace
|
||||
public static final String APP_NAME = "jNet client";
|
||||
|
||||
public static Configuration config;
|
||||
|
||||
public static ArrayList<OnlineClients> onlineClients = new ArrayList<>();
|
||||
public static ArrayList<Site> site = 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 ServerConfig serverConfig;
|
||||
public static User user = new User();
|
||||
public static List<Event> events = new ArrayList<>();
|
||||
public static List<SnmpTemplate> snmpTemplate = new ArrayList<>();
|
||||
public static List<SnmpValueMap> snmpValueMap = new ArrayList<>();
|
||||
|
||||
public static Window okno = Window.getInstance();
|
||||
|
||||
public static NettyClientManager nettyClient;
|
||||
public static Tray trayIcon;
|
||||
public static RemoteAdminTools remoteTools;
|
||||
public static SoundManager soundManager;
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
LogFile.clear();
|
||||
LogFile.setDebug(false);
|
||||
LogFile.printInfo("---------------------------------------------");
|
||||
LogFile.printInfo(" jNet Client ");
|
||||
LogFile.printInfo(" Version: " + VERSION + " (" + BuilddDate.get() + ")");
|
||||
LogFile.printInfo("---------------------------------------------");
|
||||
LogFile.printInfo("");
|
||||
|
||||
// Nahrani konfigurace
|
||||
LogFile.printInfo("Loading config ...");
|
||||
try {
|
||||
config = ApacheConfig.loadProperties();
|
||||
LogFile.printInfo(" successfully");
|
||||
} catch (ConfigurationException ex) {
|
||||
LogFile.printInfo(" fail: " + ex.getMessage());
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
if (config.getBoolean("debug")) {
|
||||
LogFile.setDebug(true);
|
||||
LogFile.printInfo("Debug mode");
|
||||
}
|
||||
|
||||
// ===== INICIALIZACE NÁSTROJŮ (VÝHRADNĚ ZE SLOŽKY app) =====
|
||||
try {
|
||||
remoteTools = new RemoteAdminTools();
|
||||
} catch (RuntimeException e) {
|
||||
LogFile.printErr("AdminTools selhal: " + e.getMessage());
|
||||
// Můžeme pokračovat bez nástrojů (metody selžou)
|
||||
}
|
||||
|
||||
///
|
||||
/// sound manager
|
||||
///
|
||||
soundManager = new SoundManager();
|
||||
|
||||
///
|
||||
/// tray icon
|
||||
///
|
||||
trayIcon = new Tray();
|
||||
trayIcon.createAndShowTray();
|
||||
|
||||
|
||||
///
|
||||
/// okno
|
||||
///
|
||||
okno.setSize(1024, 800);
|
||||
okno.setLocationRelativeTo(null);
|
||||
|
||||
///
|
||||
/// spustit minimalozovane ?
|
||||
///
|
||||
if (config.getBoolean("start_minimalized")) {
|
||||
okno.setVisible(false);
|
||||
} else {
|
||||
okno.setVisible(true);
|
||||
}
|
||||
|
||||
// Netty client vlákna
|
||||
nettyClient = new NettyClientManager(config.getString("server", "localhost"), config.getInt("port", 1225));
|
||||
nettyClient.start();
|
||||
|
||||
// ===== SHUTDOWN HOOK =====
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||
LogFile.printInfo("Shutdown signal received...");
|
||||
nettyClient.stop();
|
||||
if (remoteTools != null) {
|
||||
remoteTools.closeAll(); // ZAVŘE VŠECHNY SPUŠTĚNÉ PROCESY
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public static void sendMessage(Message msg) {
|
||||
nettyClient.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,280 @@
|
|||
package jnet.client;
|
||||
|
||||
import jnet.lib.LogFile;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class RemoteAdminTools {
|
||||
|
||||
private final List<Process> runningProcesses = new ArrayList<>();
|
||||
private final String puttyPath;
|
||||
private final String winboxPath;
|
||||
private final String browserPath;
|
||||
private final String smsSdvPath;
|
||||
private final String smsSdvIniPath;
|
||||
private final String smsBthPath;
|
||||
private final String smsBthIniPath;
|
||||
private final String smsBtPath;
|
||||
private final String smsBtIniPath;
|
||||
|
||||
/**
|
||||
* Konstruktor – vždy hledá putty.exe a winbox.exe ve složce "app". Složka
|
||||
* "app" se hledá: - vedle JAR souboru (pokud běžíme z JAR) - v aktuálním
|
||||
* pracovním adresáři (pokud běžíme z IDE)
|
||||
*/
|
||||
public RemoteAdminTools() {
|
||||
String appDir = findAppDirectory();
|
||||
this.puttyPath = validateExecutable(appDir, "putty.exe");
|
||||
this.winboxPath = validateExecutable(appDir, "winbox.exe");
|
||||
this.browserPath = null; // prohlížeč necháme automaticky detekovat
|
||||
this.smsSdvPath = validateExecutable(appDir, "smsc_sdv.exe");
|
||||
this.smsSdvIniPath = appDir + File.separator + "smsc_sdv.INI";
|
||||
this.smsBthPath = validateExecutable(appDir, "smsc_bth.exe");
|
||||
this.smsBthIniPath = appDir + File.separator + "smsc_bth.INI";
|
||||
this.smsBtPath = validateExecutable(appDir, "smsc_bt.exe");
|
||||
this.smsBtIniPath = appDir + File.separator + "smsc_bt.INI";
|
||||
LogFile.printInfo("RemoteAdminTools inicializovan, app dir: " + appDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Najde složku "app" – buď vedle JAR, nebo v aktuálním adresáři.
|
||||
*/
|
||||
private String findAppDirectory() {
|
||||
// 1. Pokusíme se zjistit cestu k JAR
|
||||
String jarDir = getJarDirectory();
|
||||
if (jarDir != null) {
|
||||
File appDir = new File(jarDir, "app");
|
||||
if (appDir.exists() && appDir.isDirectory()) {
|
||||
return appDir.getAbsolutePath();
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Fallback – aktuální pracovní adresář (funguje v NetBeans)
|
||||
File appDir = new File(System.getProperty("user.dir"), "app");
|
||||
if (appDir.exists() && appDir.isDirectory()) {
|
||||
return appDir.getAbsolutePath();
|
||||
}
|
||||
|
||||
// 3. Ještě zkusíme src/main/resources/app (pro případ spuštění z IDE)
|
||||
File srcAppDir = new File(System.getProperty("user.dir"), "src/main/resources/app");
|
||||
if (srcAppDir.exists() && srcAppDir.isDirectory()) {
|
||||
return srcAppDir.getAbsolutePath();
|
||||
}
|
||||
|
||||
LogFile.printErr("Slozka 'app' nebyla nalezena!");
|
||||
return System.getProperty("user.dir"); // vrátíme alespoň něco
|
||||
}
|
||||
|
||||
/**
|
||||
* Vrátí absolutní cestu ke složce, ve které se nachází spuštěný JAR. Pokud
|
||||
* běžíme z IDE (classpath), vrátí null.
|
||||
*/
|
||||
private String getJarDirectory() {
|
||||
try {
|
||||
String path = RemoteAdminTools.class.getProtectionDomain()
|
||||
.getCodeSource().getLocation().toURI().getPath();
|
||||
File jarFile = new File(path);
|
||||
if (jarFile.isFile()) {
|
||||
return jarFile.getParent();
|
||||
}
|
||||
} catch (URISyntaxException e) {
|
||||
LogFile.printErr("Nepodarilo se zjistit cestu k JAR: " + e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ověří, že executable existuje ve složce app. Pokud ne, vyhodí chybu.
|
||||
*/
|
||||
private String validateExecutable(String appDir, String fileName) {
|
||||
File exe = new File(appDir, fileName);
|
||||
if (!exe.exists() || !exe.isFile()) {
|
||||
LogFile.printErr("Soubor " + fileName + " nebyl nalezen v: " + exe.getAbsolutePath());
|
||||
throw new RuntimeException("Chybi " + fileName + " ve slozce app!");
|
||||
}
|
||||
LogFile.printInfo("Nalezen " + fileName + " v: " + exe.getAbsolutePath());
|
||||
return exe.getAbsolutePath();
|
||||
}
|
||||
|
||||
private Process startProcess(List<String> command) throws IOException {
|
||||
ProcessBuilder pb = new ProcessBuilder(command);
|
||||
Process p = pb.start();
|
||||
runningProcesses.add(p);
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Otevře PuTTY v režimu SSH a automaticky se připojí.
|
||||
*/
|
||||
public void openPuttySSH(String host, String port, String username, String password) {
|
||||
try {
|
||||
List<String> cmd = new ArrayList<>();
|
||||
cmd.add(puttyPath);
|
||||
cmd.add("-ssh");
|
||||
cmd.add("-P");
|
||||
cmd.add(port);
|
||||
if (username != null && !username.isEmpty()) {
|
||||
cmd.add("-l");
|
||||
cmd.add(username);
|
||||
}
|
||||
if (password != null && !password.isEmpty()) {
|
||||
cmd.add("-pw");
|
||||
cmd.add(password);
|
||||
}
|
||||
cmd.add(host);
|
||||
startProcess(cmd);
|
||||
LogFile.printInfo("PuTTY SSH spusten: " + host + ":" + port + " (uzivatel: " + username + ")");
|
||||
} catch (IOException e) {
|
||||
LogFile.printErr("Nepodarilo se spustit PuTTY SSH: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Otevře PuTTY v režimu SSH (bez hesla).
|
||||
*/
|
||||
public void openPuttySSH(String host, String port, String username) {
|
||||
openPuttySSH(host, port, username, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Otevře PuTTY v režimu Telnet.
|
||||
*/
|
||||
public void openPuttyTelnet(String host, String port) {
|
||||
try {
|
||||
List<String> cmd = new ArrayList<>();
|
||||
cmd.add(puttyPath);
|
||||
cmd.add("-telnet");
|
||||
cmd.add("-P");
|
||||
cmd.add(port);
|
||||
cmd.add(host);
|
||||
startProcess(cmd);
|
||||
LogFile.printInfo("PuTTY Telnet spusten: " + host + ":" + port);
|
||||
} catch (IOException e) {
|
||||
LogFile.printErr("Nepodarilo se spustit PuTTY Telnet: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Otevře Winbox a automaticky se připojí.
|
||||
*/
|
||||
public void openWinbox(String host, String username, String password) {
|
||||
try {
|
||||
List<String> cmd = new ArrayList<>();
|
||||
cmd.add(winboxPath);
|
||||
cmd.add(host);
|
||||
if (username != null && !username.isEmpty()) {
|
||||
//cmd.add("-u");
|
||||
cmd.add(username);
|
||||
}
|
||||
if (password != null && !password.isEmpty()) {
|
||||
//cmd.add("-p");
|
||||
cmd.add(password);
|
||||
}
|
||||
System.err.println(cmd);
|
||||
startProcess(cmd);
|
||||
LogFile.printInfo("Winbox spusten pro: " + host + " (uzivatel: " + username + ")");
|
||||
} catch (IOException e) {
|
||||
LogFile.printErr("Nepodarilo se spustit Winbox: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Otevře výchozí systémový prohlížeč s danou URL. POZOR: Tento proces nelze
|
||||
* automaticky ukončit, protože Desktop.browse() nevrací objekt Process. Při
|
||||
* ukončení hlavního programu se tedy prohlížeč nezavře – to je kompromis
|
||||
* kvůli požadavku na "výchozí prohlížeč".
|
||||
*/
|
||||
public void openBrowser(String ip, String port, int version) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
switch (version) {
|
||||
case 1: // HTTPS
|
||||
sb.append("HTTPS://");
|
||||
break;
|
||||
default: // HTTP
|
||||
sb.append("HTTP://");
|
||||
}
|
||||
sb.append(ip);
|
||||
sb.append(":").append(port);
|
||||
String url = sb.toString();
|
||||
try {
|
||||
URI uri = URI.create(url);
|
||||
java.awt.Desktop.getDesktop().browse(uri);
|
||||
LogFile.printInfo("Prohlizec otevren s URL: " + url);
|
||||
} catch (Exception e) {
|
||||
LogFile.printErr("Nepodarilo se otevrit prohlizec: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void openSMS(String host, String port, String password, int version) {
|
||||
String smsPath = null;
|
||||
String iniPath = null;
|
||||
switch (version) {
|
||||
case 0: //SDV
|
||||
smsPath = smsSdvPath;
|
||||
iniPath = smsSdvIniPath;
|
||||
break;
|
||||
case 1: // BTH
|
||||
smsPath = smsBthPath;
|
||||
iniPath = smsBthIniPath;
|
||||
break;
|
||||
case 2:
|
||||
smsPath = smsBtPath;
|
||||
iniPath = smsBtIniPath;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!createSmsIni(iniPath, host, port, password)) {
|
||||
LogFile.printErr("Nepodarilo se vytvorit konfiguracni soubor pro SMS");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
List<String> cmd = new ArrayList<>();
|
||||
cmd.add(smsPath);
|
||||
startProcess(cmd);
|
||||
LogFile.printInfo("SMS spustena pro " + host + ":" + port);
|
||||
} catch (IOException e) {
|
||||
LogFile.printErr("Nepodarilo se spustit SMS " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean createSmsIni(String iniPath, String host, String port, String password) {
|
||||
try (PrintWriter writer = new PrintWriter(new FileWriter(iniPath))) {
|
||||
writer.println("[Form]");
|
||||
writer.println("IPaddr=" + host + ":" + port);
|
||||
writer.println("IPpassw=" + password);
|
||||
writer.flush();
|
||||
LogFile.printInfo("INI soubor vytvoren " + iniPath);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
LogFile.printErr("Chyba pri vytvoreni INI souboru " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ukončí všechny dosud spuštěné procesy.
|
||||
*/
|
||||
public void closeAll() {
|
||||
for (Process p : runningProcesses) {
|
||||
if (p != null && p.isAlive()) {
|
||||
p.destroyForcibly();
|
||||
try {
|
||||
// Oprava: waitFor(long, TimeUnit) místo waitFor(long)
|
||||
p.waitFor(1, TimeUnit.SECONDS);
|
||||
} catch (InterruptedException ignored) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
LogFile.printInfo("Proces ukončen.");
|
||||
}
|
||||
}
|
||||
runningProcesses.clear();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package jnet.client;
|
||||
|
||||
import jnet.lib.object.NodeProbe;
|
||||
|
||||
public class SnmpResponseParser {
|
||||
|
||||
public static String parse(NodeProbe probe) {
|
||||
|
||||
if (probe.getValue() == null) {
|
||||
return "error";
|
||||
}
|
||||
if (probe.getValue().toString().equals("noSuchObject")) {
|
||||
return "error";
|
||||
}
|
||||
|
||||
|
||||
switch (probe.getDataType()) {
|
||||
case NodeProbe.DATA_TYPE_INTEGER:
|
||||
return parseInteger(probe).toString();
|
||||
case NodeProbe.DATA_TYPE_STRING:
|
||||
return probe.getValue().toString();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Object parseInteger(NodeProbe probe) {
|
||||
switch (probe.getConversionType()) {
|
||||
case NodeProbe.CONVERSION_TYPE_DIVIDE:
|
||||
double value = Integer.parseInt(probe.getValue().toString()) / probe.getConversionValue();
|
||||
return value;
|
||||
default:
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
|
||||
public static class parse {
|
||||
|
||||
public parse(NodeProbe probe) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,203 @@
|
|||
package jnet.client;
|
||||
|
||||
import javax.sound.sampled.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import jnet.lib.LogFile;
|
||||
import jnet.lib.Status;
|
||||
import jnet.lib.object.Node;
|
||||
import jnet.lib.object.Site;
|
||||
|
||||
public class SoundManager {
|
||||
|
||||
private static final String KEY_OFFLINE_FIRST = "sound.offline.first";
|
||||
private static final String KEY_OFFLINE_OTHER = "sound.offline.other";
|
||||
private static final String KEY_ONLINE_ONE = "sound.online.one";
|
||||
private static final String KEY_ONLINE_ALL = "sound.online.all";
|
||||
private static final String KEY_VOLUME = "sound.volume";
|
||||
|
||||
// ✅ SPRÁVNÉ názvy souborů podle vaší struktury (přímo v resources)
|
||||
private static final String DEFAULT_OFFLINE_FIRST = "first_offline.wav";
|
||||
private static final String DEFAULT_OFFLINE_OTHER = "next_offline.wav";
|
||||
private static final String DEFAULT_ONLINE_ONE = "one_online.wav";
|
||||
private static final String DEFAULT_ONLINE_ALL = "all_online.wav";
|
||||
private static final float DEFAULT_VOLUME = 0.8f;
|
||||
|
||||
private final Map<String, Clip> soundCache = new HashMap<>();
|
||||
private float volume = DEFAULT_VOLUME;
|
||||
|
||||
private static final String SOUND_OFFLINE_FIRST = "offlineFirst";
|
||||
private static final String SOUND_OFFLINE_OTHER = "offlineOther";
|
||||
private static final String SOUND_ONLINE_ONE = "onlineOne";
|
||||
private static final String SOUND_ONLINE_ALL = "onlineAll";
|
||||
|
||||
public SoundManager() {
|
||||
loadConfigAndSounds();
|
||||
}
|
||||
|
||||
public void loadConfigAndSounds() {
|
||||
String pathOfflineFirst = Client.config.getString(KEY_OFFLINE_FIRST, DEFAULT_OFFLINE_FIRST);
|
||||
String pathOfflineOther = Client.config.getString(KEY_OFFLINE_OTHER, DEFAULT_OFFLINE_OTHER);
|
||||
String pathOnlineOne = Client.config.getString(KEY_ONLINE_ONE, DEFAULT_ONLINE_ONE);
|
||||
String pathOnlineAll = Client.config.getString(KEY_ONLINE_ALL, DEFAULT_ONLINE_ALL);
|
||||
float newVolume = Client.config.getFloat(KEY_VOLUME, DEFAULT_VOLUME);
|
||||
setVolume(newVolume);
|
||||
|
||||
closeAll();
|
||||
loadSound(SOUND_OFFLINE_FIRST, pathOfflineFirst);
|
||||
loadSound(SOUND_OFFLINE_OTHER, pathOfflineOther);
|
||||
loadSound(SOUND_ONLINE_ONE, pathOnlineOne);
|
||||
loadSound(SOUND_ONLINE_ALL, pathOnlineAll);
|
||||
}
|
||||
|
||||
private void loadSound(String cacheKey, String filePath) {
|
||||
try {
|
||||
|
||||
URL url = null;
|
||||
ClassLoader classLoader = getClass().getClassLoader();
|
||||
|
||||
// 1. ClassLoader.getResource() - hledá v classpath
|
||||
url = classLoader.getResource(filePath);
|
||||
|
||||
// 2. getClass().getResource() s lomítkem
|
||||
if (url == null) {
|
||||
url = getClass().getResource("/" + filePath);
|
||||
}
|
||||
|
||||
// 3. getClass().getResource() bez lomítka
|
||||
if (url == null) {
|
||||
url = getClass().getResource(filePath);
|
||||
if (url != null) {
|
||||
}
|
||||
}
|
||||
// 4. Jako soubor
|
||||
if (url == null) {
|
||||
File soundFile = new File(filePath);
|
||||
if (soundFile.exists()) {
|
||||
url = soundFile.toURI().toURL();
|
||||
}
|
||||
}
|
||||
|
||||
// 5. src/main/resources/
|
||||
if (url == null) {
|
||||
File srcResource = new File("src/main/resources/" + filePath);
|
||||
if (srcResource.exists()) {
|
||||
url = srcResource.toURI().toURL();
|
||||
}
|
||||
}
|
||||
|
||||
// 6. target/classes/
|
||||
if (url == null) {
|
||||
File targetResource = new File("target/classes/" + filePath);
|
||||
if (targetResource.exists()) {
|
||||
url = targetResource.toURI().toURL();
|
||||
}
|
||||
}
|
||||
|
||||
// 7. Extrahovat název (pokud cesta obsahuje složky)
|
||||
if (url == null && filePath.contains("/")) {
|
||||
String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
|
||||
|
||||
url = classLoader.getResource(fileName);
|
||||
if (url == null) {
|
||||
url = getClass().getResource("/" + fileName);
|
||||
}
|
||||
if (url == null) {
|
||||
url = getClass().getResource(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
if (url == null) {
|
||||
System.err.println("❌ Zvukový soubor NENALEZEN: " + filePath);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
AudioInputStream audioIn = AudioSystem.getAudioInputStream(url);
|
||||
Clip clip = AudioSystem.getClip();
|
||||
clip.open(audioIn);
|
||||
setClipVolume(clip, volume);
|
||||
soundCache.put(cacheKey, clip);
|
||||
|
||||
} catch (Exception e) {
|
||||
LogFile.printErr("❌ Chyba při načítání zvuku " + filePath + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
public void setVolume(float newVolume) {
|
||||
this.volume = Math.max(0f, Math.min(1f, newVolume));
|
||||
for (Clip clip : soundCache.values()) {
|
||||
setClipVolume(clip, this.volume);
|
||||
}
|
||||
}
|
||||
|
||||
private void setClipVolume(Clip clip, float volume) {
|
||||
if (clip == null) return;
|
||||
if (clip.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
|
||||
FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
|
||||
float min = gainControl.getMinimum();
|
||||
float max = gainControl.getMaximum();
|
||||
float range = max - min;
|
||||
float gain = min + (range * volume);
|
||||
gainControl.setValue(gain);
|
||||
}
|
||||
}
|
||||
|
||||
private void play(String cacheKey) {
|
||||
Clip clip = soundCache.get(cacheKey);
|
||||
if (clip != null) {
|
||||
clip.setFramePosition(0);
|
||||
clip.start();
|
||||
System.out.println("🔊 Přehrávám zvuk: " + cacheKey);
|
||||
} else {
|
||||
System.err.println("❌ Zvuk '" + cacheKey + "' nebyl načten.");
|
||||
}
|
||||
}
|
||||
|
||||
public void evaluateAndPlay(List<Site> sites, boolean newOnline) {
|
||||
int offlineCount = 0;
|
||||
outer:
|
||||
for (Site site : sites) {
|
||||
for (Node node : site.getNode()) {
|
||||
if (node.getStatus() == Status.OFFLINE) {
|
||||
offlineCount++;
|
||||
if (offlineCount > 1) {
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// System.out.println("📊 Offline zařízení: " + offlineCount + ", nový stav: " + (newOnline ? "ONLINE" : "OFFLINE"));
|
||||
|
||||
if (!newOnline) {
|
||||
if (offlineCount > 1) {
|
||||
play(SOUND_OFFLINE_OTHER);
|
||||
} else {
|
||||
play(SOUND_OFFLINE_FIRST);
|
||||
}
|
||||
} else {
|
||||
if (offlineCount > 0) {
|
||||
play(SOUND_ONLINE_ONE);
|
||||
} else {
|
||||
play(SOUND_ONLINE_ALL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void closeAll() {
|
||||
for (Clip clip : soundCache.values()) {
|
||||
if (clip != null) {
|
||||
clip.close();
|
||||
}
|
||||
}
|
||||
soundCache.clear();
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
loadConfigAndSounds();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
package jnet.client.client;
|
||||
|
||||
import io.netty.channel.ChannelHandler.Sharable;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import jnet.client.Client;
|
||||
import jnet.client.gui.Window;
|
||||
import jnet.client.message.MessageRegister;
|
||||
import jnet.client.message.Register;
|
||||
import jnet.lib.LogFile;
|
||||
import jnet.lib.Message;
|
||||
|
||||
@Sharable
|
||||
public class ClientHandler extends SimpleChannelInboundHandler<Object> {
|
||||
|
||||
private NettyClientManager connectionThread;
|
||||
private final MessageRegister messageRegistr = new MessageRegister();
|
||||
|
||||
|
||||
public void setConnectionThread(NettyClientManager connectionThread) {
|
||||
this.connectionThread = connectionThread;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) {
|
||||
LogFile.printInfo("Connected to server");
|
||||
ctx.writeAndFlush(new Message(Message.CLIENT_TYPE, Client.VERSION));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, Object msg) {
|
||||
if (msg instanceof Message) {
|
||||
Message message = (Message) msg;
|
||||
LogFile.printDebug("Received message ID: "+ message.getType());
|
||||
Register register = messageRegistr.getRegister(message.getType());
|
||||
if (register != null) {
|
||||
register.processing(ctx, message);
|
||||
}
|
||||
} else {
|
||||
LogFile.printDebug("Unknown message received");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) {
|
||||
LogFile.printInfo("Connection inactive ..... reconnect initiated");
|
||||
Window.setStatusBarMessage("Odpojeno");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
||||
if (cause instanceof java.net.SocketException && cause.getMessage().contains("Connection reset")) {
|
||||
LogFile.printInfo("Connection reset by server");
|
||||
Window.setStatusBarMessage("Odpojeno");
|
||||
} else {
|
||||
cause.printStackTrace();
|
||||
}
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
public void sendMessage(Message msg) {
|
||||
if (connectionThread != null) {
|
||||
connectionThread.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package jnet.client.client;
|
||||
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.handler.codec.serialization.ClassResolvers;
|
||||
import io.netty.handler.codec.serialization.ObjectDecoder;
|
||||
import io.netty.handler.codec.serialization.ObjectEncoder;
|
||||
import io.netty.handler.ssl.SslContext;
|
||||
|
||||
public class ClientInitializer extends ChannelInitializer<SocketChannel> {
|
||||
|
||||
private final SslContext sslCtx;
|
||||
private final ClientHandler handler;
|
||||
|
||||
public ClientInitializer(SslContext sslCtx, ClientHandler handler) {
|
||||
this.sslCtx = sslCtx;
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initChannel(SocketChannel ch) {
|
||||
ch.pipeline()
|
||||
.addLast("ssl", sslCtx.newHandler(ch.alloc(), "localhost", 8443))
|
||||
//.addLast("objectDecoder", new ObjectDecoder(ClassResolvers.cacheDisabled(null)))
|
||||
//.addLast("objectEncoder", new ObjectEncoder())
|
||||
.addLast(new ObjectDecoder(ClassResolvers.cacheDisabled(null)))
|
||||
.addLast(new ObjectEncoder())
|
||||
.addLast("handler", handler);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,167 @@
|
|||
package jnet.client.client;
|
||||
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import io.netty.handler.ssl.SslContext;
|
||||
import jnet.client.Client;
|
||||
import jnet.lib.Message;
|
||||
|
||||
public class NettyClientManager extends Thread {
|
||||
|
||||
private final String host;
|
||||
private final int port;
|
||||
|
||||
private SslContext sslCtx = null;
|
||||
private final ClientHandler handler;
|
||||
private final EventLoopGroup group;
|
||||
|
||||
private static Channel channel;
|
||||
|
||||
private volatile boolean manualDisconnect = false;
|
||||
private volatile boolean running = true;
|
||||
private int reconnectAttempt = 0;
|
||||
private static final int MAX_RECONNECT_DELAY = 15; // max doma za kterou se pokusí klient znovu připojit
|
||||
|
||||
public NettyClientManager(String host, int port) {
|
||||
super("NettyClientManager"); // pojmenujeme vlákno
|
||||
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
|
||||
this.handler = new ClientHandler();
|
||||
this.group = new NioEventLoopGroup();
|
||||
// Propojíme handler s tímto vláknem (aby mohl posílat zprávy)
|
||||
handler.setConnectionThread(this);
|
||||
|
||||
try {
|
||||
this.sslCtx = SslUtil.createClientSslContext();
|
||||
} catch (Exception ex) {
|
||||
System.getLogger("Client SSL exception: " + ex.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
Bootstrap bootstrap = new Bootstrap();
|
||||
bootstrap.group(group)
|
||||
.channel(NioSocketChannel.class)
|
||||
.option(ChannelOption.SO_KEEPALIVE, true)
|
||||
.handler(new ClientInitializer(sslCtx, handler));
|
||||
|
||||
while (running) {
|
||||
try {
|
||||
System.out.println("Connecting to " + host + ":" + port + " (attempt " + (reconnectAttempt + 1) + ")");
|
||||
ChannelFuture future = bootstrap.connect(host, port).sync();
|
||||
channel = future.channel();
|
||||
System.out.println("Connected successfully");
|
||||
reconnectAttempt = 0;
|
||||
|
||||
channel.closeFuture().sync();
|
||||
System.out.println("Connection lost");
|
||||
|
||||
// Pokud bylo provedeno manuální odpojení, přerušíme smyčku
|
||||
if (manualDisconnect) {
|
||||
System.out.println("Manual disconnect – stopping reconnect loop");
|
||||
break;
|
||||
}
|
||||
|
||||
if (!running) {
|
||||
break;
|
||||
}
|
||||
|
||||
int delay = Math.min(1 << reconnectAttempt, MAX_RECONNECT_DELAY);
|
||||
reconnectAttempt++;
|
||||
System.out.println("Reconnecting in " + delay + "s...");
|
||||
Thread.sleep(delay * 1000L);
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
System.out.println("Connection thread interrupted");
|
||||
// Pokud je to manuální odpojení, ukončíme smyčku
|
||||
if (manualDisconnect) {
|
||||
break;
|
||||
}
|
||||
Thread.currentThread().interrupt();
|
||||
break;
|
||||
} catch (Exception e) {
|
||||
System.err.println("Connection error: " + e.getMessage());
|
||||
if (running && !manualDisconnect) {
|
||||
try {
|
||||
Thread.sleep(3000);
|
||||
} catch (InterruptedException ie) {
|
||||
if (manualDisconnect) {
|
||||
break;
|
||||
}
|
||||
Thread.currentThread().interrupt();
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Úklid po ukončení smyčky
|
||||
shutdown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Zastaví vlákno a uvolní zdroje
|
||||
*/
|
||||
public void stop() {
|
||||
running = false;
|
||||
if (channel != null) {
|
||||
channel.close();
|
||||
}
|
||||
group.shutdownGracefully();
|
||||
// Přerušíme vlákno, pokud čeká v sleep
|
||||
this.interrupt();
|
||||
}
|
||||
|
||||
private void shutdown() {
|
||||
if (channel != null && channel.isActive()) {
|
||||
channel.close();
|
||||
}
|
||||
group.shutdownGracefully();
|
||||
System.out.println("Connection thread shut down");
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return channel != null && channel.isActive();
|
||||
}
|
||||
|
||||
/**
|
||||
* Odešle zprávu serveru (pokud je spojení aktivní)
|
||||
*/
|
||||
public static void sendMessage(Message msg) {
|
||||
if (channel != null && channel.isActive()) {
|
||||
channel.writeAndFlush(msg);
|
||||
} else {
|
||||
System.out.println("Cannot send message – not connected");
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendMessage(int type, Object msg) {
|
||||
if (channel != null && channel.isActive()) {
|
||||
channel.writeAndFlush(new Message(type, msg));
|
||||
} else {
|
||||
System.out.println("Cannot send message – not connected");
|
||||
}
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
manualDisconnect = true;
|
||||
if (channel != null) {
|
||||
channel.close(); // zavře spojení – spustí channel.closeFuture().sync() v run()
|
||||
}
|
||||
this.interrupt(); // přeruší případné čekání
|
||||
System.out.println("Manual disconnect initiated");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
package jnet.client.client;
|
||||
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ReconnectManager {
|
||||
|
||||
private final Bootstrap bootstrap;
|
||||
private final EventLoopGroup group;
|
||||
private final String host;
|
||||
private final int port;
|
||||
private final ClientHandler handler;
|
||||
|
||||
private int attempt = 0;
|
||||
private static final int MAX_ATTEMPTS = Integer.MAX_VALUE;
|
||||
private static final int BASE_DELAY_SECONDS = 1;
|
||||
private static final int MAX_DELAY_SECONDS = 30;
|
||||
|
||||
public ReconnectManager(Bootstrap bootstrap, EventLoopGroup group,
|
||||
String host, int port, ClientHandler handler) {
|
||||
this.bootstrap = bootstrap;
|
||||
this.group = group;
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public void scheduleReconnect() {
|
||||
if (attempt >= MAX_ATTEMPTS) {
|
||||
System.out.println("Max reconnect attempts reached, giving up.");
|
||||
return;
|
||||
}
|
||||
|
||||
int delay = Math.min(BASE_DELAY_SECONDS * (int) Math.pow(2, attempt), MAX_DELAY_SECONDS);
|
||||
attempt++;
|
||||
|
||||
System.out.println("Reconnect attempt " + attempt + " in " + delay + "s");
|
||||
|
||||
group.schedule(() -> {
|
||||
if (!Thread.currentThread().isInterrupted()) {
|
||||
tryReconnect();
|
||||
}
|
||||
}, delay, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
private void tryReconnect() {
|
||||
bootstrap.connect(host, port).addListener(new ChannelFutureListener() {
|
||||
@Override
|
||||
public void operationComplete(ChannelFuture future) {
|
||||
if (future.isSuccess()) {
|
||||
System.out.println("Reconnect successful!");
|
||||
attempt = 0;
|
||||
} else {
|
||||
System.out.println("Reconnect failed – will retry");
|
||||
scheduleReconnect();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void resetAttempts() {
|
||||
attempt = 0;
|
||||
System.out.println("Reconnect attempts reset");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package jnet.client.client;
|
||||
|
||||
import io.netty.handler.ssl.SslContext;
|
||||
import io.netty.handler.ssl.SslContextBuilder;
|
||||
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import java.security.Security;
|
||||
|
||||
public class SslUtil {
|
||||
static {
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
}
|
||||
|
||||
public static SslContext createClientSslContext() throws Exception {
|
||||
return SslContextBuilder.forClient()
|
||||
.trustManager(InsecureTrustManagerFactory.INSTANCE) // DŮLEŽITÉ!
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
package jnet.client.gui;
|
||||
|
||||
import jnet.client.Client;
|
||||
import java.awt.BorderLayout;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import jnet.lib.EventComparator;
|
||||
import jnet.lib.Status;
|
||||
import jnet.lib.object.Node;
|
||||
import jnet.lib.object.Site;
|
||||
|
||||
public class EventsPanel extends JPanel {
|
||||
|
||||
private static final int DEFAULT_LIMIT = 50;
|
||||
|
||||
private DefaultTableModel tableModel;
|
||||
private JTable table;
|
||||
|
||||
public EventsPanel() {
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
String[] column = {"Začátek", "Konec", "Délka", "Stav", "Mapa", "Zařízení"};
|
||||
tableModel = new DefaultTableModel(column, 0) {
|
||||
@Override
|
||||
public boolean isCellEditable(int row, int column) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
table = new JTable(tableModel);
|
||||
table.setRowHeight(30);
|
||||
add(new JScrollPane(table), BorderLayout.CENTER);
|
||||
|
||||
refresh(); // naplní tabulku
|
||||
}
|
||||
|
||||
/**
|
||||
* Obnoví obsah tabulky podle aktuálních dat v Client.events.
|
||||
*/
|
||||
public void refresh() {
|
||||
tableModel.setRowCount(0); // smaže všechny řádky
|
||||
|
||||
int limit = DEFAULT_LIMIT;
|
||||
Collections.sort(Client.events, new EventComparator());
|
||||
Collections.reverse(Client.events);
|
||||
|
||||
if (limit > Client.events.size()) {
|
||||
limit = Client.events.size();
|
||||
}
|
||||
|
||||
for (int i = 0; i < limit; i++) {
|
||||
String[] info = getObjetInfo(Client.events.get(i).getNode());
|
||||
// pokud se objekt nenajde, info bude null – ošetříme
|
||||
if (info == null) {
|
||||
info = new String[]{"Neznámá", "Neznámé"};
|
||||
}
|
||||
Object[] row = {
|
||||
getDate(Client.events.get(i).getStart()),
|
||||
getDate(Client.events.get(i).getEnd()),
|
||||
getDuration(Client.events.get(i).getStart(), Client.events.get(i).getEnd()),
|
||||
Status.getStatusName(Client.events.get(i).getStatus()),
|
||||
info[0],
|
||||
info[1]
|
||||
};
|
||||
tableModel.addRow(row);
|
||||
}
|
||||
tableModel.fireTableDataChanged();
|
||||
}
|
||||
|
||||
// -- stávající pomocné metody (getDate, getDuration, getObjetInfo) zůstávají beze změny --
|
||||
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 getDuration(long startTime, long endTime) {
|
||||
if (endTime != 0) {
|
||||
long difference = endTime - startTime;
|
||||
long seconds = difference / 1000;
|
||||
long minutes = difference / (1000 * 60);
|
||||
long hours = difference / (1000 * 60 * 60);
|
||||
return hours + "h " + minutes + "m " + seconds + "s";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private String[] getObjetInfo(int id) {
|
||||
for (Site map : Client.site) {
|
||||
for (Node mapObject : map.getNode()) {
|
||||
if (mapObject.getId() == id) {
|
||||
return new String[]{map.getName(), mapObject.getName()};
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
package jnet.client.gui;
|
||||
|
||||
import jnet.client.Client;
|
||||
import jnet.client.gui.dialog.LoginDialog;
|
||||
import jnet.client.gui.serversettings.ServerSettingsPanel;
|
||||
import jnet.lib.LogFile;
|
||||
import jnet.lib.ResourceLoader;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Horní lišta s ovládacími tlačítky.
|
||||
*/
|
||||
public class MenuPanel extends JPanel {
|
||||
|
||||
public MenuPanel() {
|
||||
setPreferredSize(new Dimension(50, 50));
|
||||
setLayout(new FlowLayout(FlowLayout.LEFT));
|
||||
|
||||
// Tlačítko Připojit / Odpojit
|
||||
add(createIconButton("img/connect.png", "Připojit", e -> {
|
||||
if (Client.nettyClient != null && Client.nettyClient.isConnected()) {
|
||||
Client.nettyClient.disconnect();
|
||||
}
|
||||
// Otevře přihlašovací dialog
|
||||
SwingUtilities.invokeLater(() -> new LoginDialog().setVisible(true));
|
||||
}));
|
||||
|
||||
// Tlačítko Nastavení (klienta)
|
||||
add(createIconButton("img/settings.png", "Nastavení", e
|
||||
-> SwingUtilities.invokeLater(Window::showSettings)));
|
||||
|
||||
// Tlačítko Log (zatím prázdné)
|
||||
add(createIconButton("img/log.png", "Log", e
|
||||
-> SwingUtilities.invokeLater(Window::showLog)));
|
||||
|
||||
// Tlačítko Nastavení serveru
|
||||
if (Client.user.isEditServer()) {
|
||||
add(createIconButton("img/server_settings.png", "Nastavení serveru", e
|
||||
-> SwingUtilities.invokeLater(() -> Window.showServerSettings(ServerSettingsPanel.TAB_DEFAULT))));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void rebuild() {
|
||||
removeAll();
|
||||
// znovu přidáme tlačítka podle Client.user
|
||||
// ...
|
||||
revalidate();
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pomocná metoda pro vytvoření tlačítka s ikonou.
|
||||
*/
|
||||
private JButton createIconButton(String resourcePath, String tooltip, ActionListener action) {
|
||||
try {
|
||||
var image = ImageIO.read(ResourceLoader.getFile(resourcePath));
|
||||
JButton button = new JButton(new ImageIcon(image));
|
||||
button.setFocusPainted(false);
|
||||
button.setContentAreaFilled(false);
|
||||
button.setToolTipText(tooltip);
|
||||
button.addActionListener(action);
|
||||
return button;
|
||||
} catch (IOException ex) {
|
||||
LogFile.printErr("Nepodařilo se načíst obrázek: " + resourcePath);
|
||||
// Fallback – tlačítko s textem
|
||||
JButton fallback = new JButton(tooltip);
|
||||
fallback.addActionListener(action);
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,207 @@
|
|||
package jnet.client.gui;
|
||||
|
||||
import jnet.client.Client;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JSlider;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
import jnet.lib.ApacheConfig;
|
||||
import jnet.lib.LogFile;
|
||||
import org.apache.commons.configuration2.ex.ConfigurationException;
|
||||
|
||||
public class SettingsPanel extends JPanel {
|
||||
|
||||
public SettingsPanel() {
|
||||
show();
|
||||
}
|
||||
|
||||
public void show() {
|
||||
this.setLayout(null);
|
||||
this.setPreferredSize(new Dimension(300, 800));
|
||||
|
||||
// ===== NADPIS =====
|
||||
JLabel nadpisLabel = new JLabel("Obecné nastavení");
|
||||
nadpisLabel.setBounds(20, 20, 400, 25);
|
||||
nadpisLabel.setFont(nadpisLabel.getFont().deriveFont(20f));
|
||||
this.add(nadpisLabel);
|
||||
|
||||
// ===== CHECKBOX =====
|
||||
JCheckBox runMinimalized = new JCheckBox("Spouštět minimalizovaně");
|
||||
runMinimalized.setBounds(30, getNextY(nadpisLabel) + 20, 400, 25);
|
||||
runMinimalized.setSelected(Client.config.getBoolean("start_minimalized"));
|
||||
this.add(runMinimalized);
|
||||
|
||||
JCheckBox enableDebug = new JCheckBox("Debug režim");
|
||||
enableDebug.setBounds(30, getNextY(runMinimalized), 400, 25);
|
||||
enableDebug.setSelected(Client.config.getBoolean("debug"));
|
||||
this.add(enableDebug);
|
||||
|
||||
// ===== ZVUKY =====
|
||||
JLabel nadpisSoundLabel = new JLabel("Zvuky");
|
||||
nadpisSoundLabel.setBounds(20, getNextY(enableDebug) + 20, 400, 25);
|
||||
nadpisSoundLabel.setFont(nadpisLabel.getFont().deriveFont(20f));
|
||||
this.add(nadpisSoundLabel);
|
||||
|
||||
JCheckBox enableSounds = new JCheckBox("Povolit zvuky");
|
||||
enableSounds.setBounds(30, getNextY(nadpisSoundLabel), 400, 25);
|
||||
enableSounds.setSelected(Client.config.getBoolean("sound"));
|
||||
this.add(enableSounds);
|
||||
|
||||
// ===== HLASITOST =====
|
||||
JLabel hlasLabel = new JLabel("Hlasitost");
|
||||
hlasLabel.setBounds(30, getNextY(enableSounds), 80, 25);
|
||||
this.add(hlasLabel);
|
||||
|
||||
double volume = Client.config.getDouble("sound.volume", 0.75);
|
||||
int volumePercent = (int) (volume * 100);
|
||||
|
||||
JSlider volumeSlider = new JSlider(JSlider.HORIZONTAL, 0, 100, 50);
|
||||
volumeSlider.setBounds(110, getNextY(enableSounds), 200, 50);
|
||||
volumeSlider.setValue(volumePercent);
|
||||
volumeSlider.setPaintTrack(true);
|
||||
volumeSlider.setPaintTicks(true);
|
||||
volumeSlider.setPaintLabels(true);
|
||||
volumeSlider.setMajorTickSpacing(50);
|
||||
|
||||
JLabel sliderValue = new JLabel(volumeSlider.getValue() + " %");
|
||||
sliderValue.setBounds(350, getNextY(enableSounds), 50, 25);
|
||||
this.add(sliderValue);
|
||||
|
||||
volumeSlider.addChangeListener(e -> sliderValue.setText(volumeSlider.getValue() + " %"));
|
||||
this.add(volumeSlider);
|
||||
|
||||
// ===== VÝBĚR SOUBORŮ (POUŽÍVÁME SPRÁVNÉ KLÍČE) =====
|
||||
|
||||
// --- 1. Vše online ---
|
||||
JLabel fileAllOkLabel = new JLabel("Zvuk vše online:");
|
||||
fileAllOkLabel.setBounds(30, getNextY(volumeSlider), 150, 25);
|
||||
this.add(fileAllOkLabel);
|
||||
|
||||
JTextField filePathFieldAllOk = new JTextField(25);
|
||||
filePathFieldAllOk.setEditable(false);
|
||||
filePathFieldAllOk.setBounds(200, getNextY(volumeSlider), 200, 25);
|
||||
filePathFieldAllOk.setText(Client.config.getString("sound.online.all", ""));
|
||||
this.add(filePathFieldAllOk);
|
||||
|
||||
JButton selectFileButtonAllOk = new JButton("Vyber soubor");
|
||||
selectFileButtonAllOk.setBounds(420, getNextY(volumeSlider), 80, 25);
|
||||
selectFileButtonAllOk.addActionListener(e -> {
|
||||
JFileChooser fc = new JFileChooser();
|
||||
fc.setFileFilter(new FileNameExtensionFilter("Zvukové soubory WAV", "wav"));
|
||||
if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
|
||||
filePathFieldAllOk.setText(fc.getSelectedFile().getAbsolutePath());
|
||||
} else {
|
||||
// při zrušení vrátíme původní hodnotu z konfigurace
|
||||
filePathFieldAllOk.setText(Client.config.getString("sound.online.all", ""));
|
||||
}
|
||||
});
|
||||
this.add(selectFileButtonAllOk);
|
||||
|
||||
// --- 2. Jeden online ---
|
||||
JLabel fileOneOkLabel = new JLabel("Zvuk jeden online:");
|
||||
fileOneOkLabel.setBounds(30, getNextY(filePathFieldAllOk), 150, 25);
|
||||
this.add(fileOneOkLabel);
|
||||
|
||||
JTextField filePathFieldOneOk = new JTextField(25);
|
||||
filePathFieldOneOk.setEditable(false);
|
||||
filePathFieldOneOk.setBounds(200, getNextY(filePathFieldAllOk), 200, 25);
|
||||
filePathFieldOneOk.setText(Client.config.getString("sound.online.one", ""));
|
||||
this.add(filePathFieldOneOk);
|
||||
|
||||
JButton selectFileButtonOneOk = new JButton("Vyber soubor");
|
||||
selectFileButtonOneOk.setBounds(420, getNextY(filePathFieldAllOk), 80, 25);
|
||||
selectFileButtonOneOk.addActionListener(e -> {
|
||||
JFileChooser fc = new JFileChooser();
|
||||
fc.setFileFilter(new FileNameExtensionFilter("Zvukové soubory WAV", "wav"));
|
||||
if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
|
||||
filePathFieldOneOk.setText(fc.getSelectedFile().getAbsolutePath());
|
||||
} else {
|
||||
filePathFieldOneOk.setText(Client.config.getString("sound.online.one", ""));
|
||||
}
|
||||
});
|
||||
this.add(selectFileButtonOneOk);
|
||||
|
||||
// --- 3. První offline ---
|
||||
JLabel fileFirstKoLabel = new JLabel("Zvuk první offline:");
|
||||
fileFirstKoLabel.setBounds(30, getNextY(filePathFieldOneOk), 150, 25);
|
||||
this.add(fileFirstKoLabel);
|
||||
|
||||
JTextField filePathFieldFirstKo = new JTextField(25);
|
||||
filePathFieldFirstKo.setEditable(false);
|
||||
filePathFieldFirstKo.setBounds(200, getNextY(filePathFieldOneOk), 200, 25);
|
||||
filePathFieldFirstKo.setText(Client.config.getString("sound.offline.first", ""));
|
||||
this.add(filePathFieldFirstKo);
|
||||
|
||||
JButton selectFileButtonFirstKo = new JButton("Vyber soubor");
|
||||
selectFileButtonFirstKo.setBounds(420, getNextY(filePathFieldOneOk), 80, 25);
|
||||
selectFileButtonFirstKo.addActionListener(e -> {
|
||||
JFileChooser fc = new JFileChooser();
|
||||
fc.setFileFilter(new FileNameExtensionFilter("Zvukové soubory WAV", "wav"));
|
||||
if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
|
||||
filePathFieldFirstKo.setText(fc.getSelectedFile().getAbsolutePath());
|
||||
} else {
|
||||
filePathFieldFirstKo.setText(Client.config.getString("sound.offline.first", ""));
|
||||
}
|
||||
});
|
||||
this.add(selectFileButtonFirstKo);
|
||||
|
||||
// --- 4. Další offline ---
|
||||
JLabel fileNextKoLabel = new JLabel("Zvuk další offline:");
|
||||
fileNextKoLabel.setBounds(30, getNextY(filePathFieldFirstKo), 150, 25);
|
||||
this.add(fileNextKoLabel);
|
||||
|
||||
JTextField filePathFieldNextKo = new JTextField(25);
|
||||
filePathFieldNextKo.setEditable(false);
|
||||
filePathFieldNextKo.setBounds(200, getNextY(filePathFieldFirstKo), 200, 25);
|
||||
filePathFieldNextKo.setText(Client.config.getString("sound.offline.other", ""));
|
||||
this.add(filePathFieldNextKo);
|
||||
|
||||
JButton selectFileButtonNextKo = new JButton("Vyber soubor");
|
||||
selectFileButtonNextKo.setBounds(420, getNextY(filePathFieldFirstKo), 80, 25);
|
||||
selectFileButtonNextKo.addActionListener(e -> {
|
||||
JFileChooser fc = new JFileChooser();
|
||||
fc.setFileFilter(new FileNameExtensionFilter("Zvukové soubory WAV", "wav"));
|
||||
if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
|
||||
filePathFieldNextKo.setText(fc.getSelectedFile().getAbsolutePath());
|
||||
} else {
|
||||
filePathFieldNextKo.setText(Client.config.getString("sound.offline.other", ""));
|
||||
}
|
||||
});
|
||||
this.add(selectFileButtonNextKo);
|
||||
|
||||
// ===== TLAČÍTKO ULOŽIT =====
|
||||
JButton saveButton = new JButton("Uložit");
|
||||
saveButton.setBounds(20, getNextY(filePathFieldNextKo) + 50, 100, 30);
|
||||
saveButton.addActionListener(e -> {
|
||||
// Uložíme všechny hodnoty z komponent do konfigurace
|
||||
Client.config.setProperty("debug", enableDebug.isSelected());
|
||||
Client.config.setProperty("start_minimalized", runMinimalized.isSelected());
|
||||
Client.config.setProperty("sound", enableSounds.isSelected());
|
||||
Client.config.setProperty("sound.volume", volumeSlider.getValue() / 100.0);
|
||||
|
||||
// ===== PŘIDÁNO: ukládání cest =====
|
||||
Client.config.setProperty("sound.online.all", filePathFieldAllOk.getText());
|
||||
Client.config.setProperty("sound.online.one", filePathFieldOneOk.getText());
|
||||
Client.config.setProperty("sound.offline.first", filePathFieldFirstKo.getText());
|
||||
Client.config.setProperty("sound.offline.other", filePathFieldNextKo.getText());
|
||||
|
||||
try {
|
||||
ApacheConfig.saveProperties(Client.config);
|
||||
LogFile.printInfo("Nastavení uloženo.");
|
||||
} catch (ConfigurationException ex) {
|
||||
LogFile.printErr("Nastavení nebylo uloženo. " + ex.getMessage());
|
||||
}
|
||||
});
|
||||
this.add(saveButton);
|
||||
}
|
||||
private int getNextY(Component p) {
|
||||
return p.getY() + p.getHeight() + 30;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
package jnet.client.gui;
|
||||
|
||||
import jnet.client.Client;
|
||||
import jnet.lib.LogFile;
|
||||
import jnet.lib.ResourceLoader;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import jnet.client.gui.dialog.OnlineClientsDialog;
|
||||
|
||||
/**
|
||||
* Spodní stavová lišta – zprávy a počet online klientů.
|
||||
*/
|
||||
public class StatusBar extends JPanel {
|
||||
|
||||
private final JLabel messageLabel = new JLabel();
|
||||
private final JLabel onlineLabel = new JLabel();
|
||||
|
||||
public StatusBar() {
|
||||
setPreferredSize(new Dimension(100, 35));
|
||||
setBorder(BorderFactory.createEtchedBorder());
|
||||
setLayout(new FlowLayout(FlowLayout.LEFT, 10, 5));
|
||||
|
||||
messageLabel.setPreferredSize(new Dimension(200, 25));
|
||||
add(messageLabel);
|
||||
|
||||
add(Box.createHorizontalGlue());
|
||||
|
||||
// tlacitko zobrazujici klienty
|
||||
try {
|
||||
var img = ImageIO.read(ResourceLoader.getFile("img/online_clients.png"));
|
||||
JButton btnOnline = new JButton(new ImageIcon(img));
|
||||
btnOnline.setFocusPainted(false);
|
||||
btnOnline.setContentAreaFilled(false);
|
||||
btnOnline.setBorderPainted(false);
|
||||
btnOnline.setToolTipText("Online uživatelé");
|
||||
btnOnline.addActionListener(e
|
||||
-> new OnlineClientsDialog());
|
||||
add(btnOnline);
|
||||
} catch (IOException ex) {
|
||||
LogFile.printErr("Nepodařilo se načíst ikonu online_clients.png");
|
||||
}
|
||||
|
||||
onlineLabel.setPreferredSize(new Dimension(150, 25));
|
||||
add(onlineLabel);
|
||||
}
|
||||
|
||||
public void setMessage(String text) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
messageLabel.setText(text);
|
||||
});
|
||||
}
|
||||
|
||||
public void setOnlineCount() {
|
||||
SwingUtilities.invokeLater(()
|
||||
-> onlineLabel.setText("Klientů online: " + Client.onlineClients.size())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,113 @@
|
|||
package jnet.client.gui;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.JFrame;
|
||||
import jnet.client.Client;
|
||||
import jnet.lib.LogFile;
|
||||
import jnet.lib.ResourceLoader;
|
||||
import jnet.lib.Status;
|
||||
import jnet.lib.object.Site;
|
||||
|
||||
public class Tray {
|
||||
|
||||
private SystemTray tray;
|
||||
private static TrayIcon trayIcon;
|
||||
private static PopupMenu menu = new PopupMenu();
|
||||
|
||||
public void createAndShowTray() {
|
||||
try {
|
||||
// Ověření, zda je SystemTray podporován
|
||||
if (!SystemTray.isSupported()) {
|
||||
LogFile.printErr("SystemTray is not supported");
|
||||
return;
|
||||
}
|
||||
|
||||
// Menu pro tray ikonu
|
||||
MenuItem exitItem = new MenuItem("Ukončit");
|
||||
exitItem.addActionListener(e -> {
|
||||
LogFile.printInfo("Exit application from tray icon");
|
||||
System.exit(0);
|
||||
});
|
||||
menu.add(exitItem);
|
||||
|
||||
// Načtení výchozí ikony ze zdrojů
|
||||
trayIcon = new TrayIcon(loadImage("/img/flag_gray.png"), Client.APP_NAME, menu);
|
||||
trayIcon.setImageAutoSize(true);
|
||||
trayIcon.addActionListener(e -> {
|
||||
boolean visible = Client.okno.isVisible();
|
||||
Client.okno.setVisible(!visible);
|
||||
if (!visible) {
|
||||
// Okno bylo skryté – po zobrazení ho uvedeme do normálního režimu
|
||||
Client.okno.setExtendedState(JFrame.NORMAL);
|
||||
Client.okno.toFront();
|
||||
}
|
||||
});
|
||||
|
||||
tray = SystemTray.getSystemTray();
|
||||
tray.add(trayIcon);
|
||||
refresh();
|
||||
|
||||
} catch (IOException | AWTException ex) {
|
||||
LogFile.printErr("TrayIcon error: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static BufferedImage loadImage(String path) throws IOException {
|
||||
|
||||
File input = ResourceLoader.getFile(path);
|
||||
if (input == null) {
|
||||
throw new IOException("Soubor nenalezen: " + path);
|
||||
}
|
||||
return ImageIO.read(input);
|
||||
|
||||
}
|
||||
|
||||
public static void showMessage(String title, String message) {
|
||||
if (trayIcon != null) {
|
||||
trayIcon.displayMessage(title, message, TrayIcon.MessageType.INFO);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setIcon(String icon) {
|
||||
try {
|
||||
trayIcon.setImage(loadImage("/img/" + icon));
|
||||
} catch (IOException ex) {
|
||||
LogFile.printErr("TrayIcon error: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static void setStatusOffline() {
|
||||
setIcon("flag_red.png");
|
||||
}
|
||||
|
||||
public static void setStatusOnline() {
|
||||
setIcon("flag_green.png");
|
||||
}
|
||||
|
||||
public static void setStatusWarning() {
|
||||
setIcon("flag_orange.png");
|
||||
}
|
||||
|
||||
public static void setStatusDisconnected() {
|
||||
setIcon("flag_gray.png");
|
||||
}
|
||||
|
||||
public static void refresh() {
|
||||
for (Site map : Client.site) {
|
||||
int status = map.getSiteState();
|
||||
if (status == Status.OFFLINE) {
|
||||
setStatusOffline();
|
||||
return;
|
||||
}
|
||||
if (status == Status.WARNING) {
|
||||
setStatusWarning();
|
||||
return;
|
||||
}
|
||||
}
|
||||
setStatusOnline();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,342 @@
|
|||
package jnet.client.gui;
|
||||
|
||||
import jnet.client.Client;
|
||||
import jnet.client.gui.dialog.NewSiteDialog;
|
||||
import jnet.client.gui.maptree.MapTree;
|
||||
import jnet.client.gui.serversettings.ServerSettingsPanel;
|
||||
import jnet.lib.LogFile;
|
||||
import jnet.lib.ResourceLoader;
|
||||
import jnet.lib.object.Site;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.io.IOException;
|
||||
import jnet.client.gui.mapview.MapView;
|
||||
import jnet.lib.object.Node;
|
||||
|
||||
/**
|
||||
* Hlavní okno aplikace – implementováno jako singleton.
|
||||
*/
|
||||
public class Window extends JFrame {
|
||||
|
||||
private static Window instance;
|
||||
|
||||
private JSplitPane splitPane;
|
||||
private StatusBar statusBar;
|
||||
private MapTree mapTree;
|
||||
private MenuPanel menuPanel;
|
||||
private static ServerSettingsPanel currentServerSettingsPanel;
|
||||
private static EventsPanel currentEventsPanel;
|
||||
|
||||
// Nové: reference na aktuální MapView a jeho scroll panel
|
||||
private static MapView currentMapView;
|
||||
private static JScrollPane currentMapViewScrollPane;
|
||||
|
||||
private Window() {
|
||||
super(Client.APP_NAME);
|
||||
setIcon();
|
||||
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||
addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
handleClosing();
|
||||
}
|
||||
});
|
||||
|
||||
initComponents();
|
||||
|
||||
pack();
|
||||
setLocationRelativeTo(null);
|
||||
}
|
||||
|
||||
private void initComponents() {
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
menuPanel = new MenuPanel();
|
||||
add(menuPanel, BorderLayout.NORTH);
|
||||
|
||||
splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
|
||||
splitPane.setDividerSize(5);
|
||||
|
||||
JPanel leftPanel = new JPanel(new BorderLayout());
|
||||
leftPanel.setBackground(Color.WHITE);
|
||||
leftPanel.setPreferredSize(new Dimension(200, 250));
|
||||
|
||||
mapTree = new MapTree();
|
||||
leftPanel.add(mapTree, BorderLayout.CENTER);
|
||||
|
||||
if (Client.user != null && Client.user.isAddMap()) {
|
||||
JButton addSiteButton = new JButton("Přidat mapu");
|
||||
addSiteButton.addActionListener(e -> new NewSiteDialog().setVisible(true));
|
||||
leftPanel.add(addSiteButton, BorderLayout.SOUTH);
|
||||
}
|
||||
|
||||
splitPane.add(leftPanel, JSplitPane.LEFT);
|
||||
|
||||
// Pravý panel – prázdný
|
||||
splitPane.add(new JPanel(), JSplitPane.RIGHT);
|
||||
|
||||
add(splitPane, BorderLayout.CENTER);
|
||||
|
||||
if (statusBar == null) {
|
||||
statusBar = new StatusBar();
|
||||
}
|
||||
add(statusBar, BorderLayout.SOUTH);
|
||||
|
||||
currentServerSettingsPanel = null;
|
||||
currentEventsPanel = null;
|
||||
}
|
||||
|
||||
public static Window getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new Window();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void reloadWindow() {
|
||||
getContentPane().removeAll();
|
||||
initComponents();
|
||||
revalidate();
|
||||
repaint();
|
||||
currentEventsPanel = null;
|
||||
// Po znovunačtení okna zrušíme referenci na MapView, protože byl zničen
|
||||
currentMapView = null;
|
||||
currentMapViewScrollPane = null;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Soukromé pomocné metody
|
||||
// ------------------------------------------------------------------------
|
||||
private void setIcon() {
|
||||
try {
|
||||
var icon = ImageIO.read(ResourceLoader.getFile("img/app.png"));
|
||||
setIconImage(icon);
|
||||
} catch (IOException ex) {
|
||||
LogFile.printErr("APP icon exception");
|
||||
}
|
||||
}
|
||||
|
||||
private void handleClosing() {
|
||||
int n = JOptionPane.showOptionDialog(this,
|
||||
"Ukončit nebo minimalizovat do lišty?",
|
||||
"Ukončit",
|
||||
JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE,
|
||||
null,
|
||||
new Object[]{"Ukončit", "Minimalizovat"},
|
||||
"Minimalizovat");
|
||||
if (n == 0) {
|
||||
LogFile.printInfo("Ukončit");
|
||||
System.exit(0);
|
||||
} else if (n == 1) {
|
||||
// Skryjeme okno – zůstane pouze tray ikona
|
||||
setVisible(false);
|
||||
// Volitelně můžeme zobrazit bublinu s informací
|
||||
Tray.showMessage("jNet client", "Aplikace byla minimalizována do lišty.");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Statické přístupové metody pro ostatní komponenty
|
||||
// ------------------------------------------------------------------------
|
||||
public static void setStatusBarMessage(String message) {
|
||||
if (instance != null && instance.statusBar != null) {
|
||||
instance.statusBar.setMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void reloadOnlineClients() {
|
||||
if (instance != null && instance.statusBar != null) {
|
||||
instance.statusBar.setOnlineCount();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Nastaví nebo aktualizuje MapView pro daný Site. Odstraní starý pravý
|
||||
* panel a vloží nový MapView.
|
||||
*/
|
||||
public static void setMapView(Site site) {
|
||||
if (instance == null) {
|
||||
return;
|
||||
}
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
// Odstraníme starý pravý panel (pokud existuje)
|
||||
Component right = instance.splitPane.getRightComponent();
|
||||
if (right != null) {
|
||||
instance.splitPane.remove(right);
|
||||
}
|
||||
|
||||
// Vytvoříme nový MapView
|
||||
currentMapView = new MapView(site);
|
||||
currentMapViewScrollPane = new JScrollPane(currentMapView);
|
||||
instance.splitPane.add(currentMapViewScrollPane, JSplitPane.RIGHT);
|
||||
|
||||
instance.splitPane.revalidate();
|
||||
instance.splitPane.repaint();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktualizuje stav uzlu v aktuálním MapView. Volá se z handleru po příchodu
|
||||
* zprávy o změně stavu.
|
||||
*/
|
||||
public static void updateNodeStatusInMapView(int nodeId, int newStatus) {
|
||||
if (currentMapView != null) {
|
||||
currentMapView.updateNodeStatus(nodeId, newStatus);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktualizuje pozici uzlu v aktuálním MapView. Volá se z handleru po
|
||||
* příchodu zprávy o změně stavu.
|
||||
*/
|
||||
public static void updateNodePositionInMapView(int nodeId, int x, int y) {
|
||||
if (currentMapView != null) {
|
||||
currentMapView.updateNodePosition(nodeId, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktualizuje pozici uzlu v aktuálním MapView. Volá se z handleru po
|
||||
* příchodu zprávy o změně stavu.
|
||||
*/
|
||||
public static void addNodeInMapView(Node node) {
|
||||
if (currentMapView != null) {
|
||||
currentMapView.addNodeFromServer(node);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Kompletně obnoví MapView z nového Site objektu (např. po hromadné změně).
|
||||
*/
|
||||
public static void refreshMapView(Site site) {
|
||||
if (currentMapView != null) {
|
||||
currentMapView.refreshFromServer(site);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Obnoví aktuální zobrazení mapy podle dat ze serveru.
|
||||
* Pokud není žádná mapa otevřena, nic neprovede.
|
||||
*/
|
||||
public static void refreshCurrentMapView() {
|
||||
if (currentMapView == null) {
|
||||
return;
|
||||
}
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
Site currentSite = currentMapView.getModel().getSite();
|
||||
if (currentSite == null) {
|
||||
return;
|
||||
}
|
||||
// Najdeme aktuální verzi site v Client.site
|
||||
for (Site s : Client.site) {
|
||||
if (s.getId() == currentSite.getId()) {
|
||||
currentMapView.refreshFromServer(s);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* odebere node z mapview
|
||||
*/
|
||||
public static void removeNodeFromMapView(int nodeId) {
|
||||
if (currentMapView != null) {
|
||||
currentMapView.removeNodeFromServer(nodeId);
|
||||
}
|
||||
}
|
||||
|
||||
public static void showSettings() {
|
||||
if (instance == null) {
|
||||
return;
|
||||
}
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
JScrollPane panel = new JScrollPane(new SettingsPanel());
|
||||
// Rychlejší posouvání šipkami a kolečkem
|
||||
panel.getVerticalScrollBar().setUnitIncrement(20);
|
||||
// Rychlejší posouvání Page Up / Page Down
|
||||
panel.getVerticalScrollBar().setBlockIncrement(100);
|
||||
// Povolení rychlejšího kolečka (volitelné)
|
||||
panel.putClientProperty("JScrollBar.fastWheelScrolling", Boolean.TRUE);
|
||||
instance.splitPane.add(panel, JSplitPane.RIGHT);
|
||||
instance.splitPane.revalidate();
|
||||
});
|
||||
}
|
||||
|
||||
public static void showLog() {
|
||||
if (instance == null) {
|
||||
return;
|
||||
}
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
Component right = instance.splitPane.getRightComponent();
|
||||
if (right != null) {
|
||||
instance.splitPane.remove(right);
|
||||
}
|
||||
|
||||
if (currentEventsPanel == null) {
|
||||
currentEventsPanel = new EventsPanel();
|
||||
} else {
|
||||
currentEventsPanel.refresh();
|
||||
}
|
||||
|
||||
instance.splitPane.add(currentEventsPanel, JSplitPane.RIGHT);
|
||||
instance.splitPane.revalidate();
|
||||
instance.splitPane.repaint();
|
||||
});
|
||||
}
|
||||
|
||||
public static void showServerSettings(int tab) {
|
||||
if (instance == null) {
|
||||
return;
|
||||
}
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
if (currentServerSettingsPanel == null) {
|
||||
currentServerSettingsPanel = new ServerSettingsPanel();
|
||||
JScrollPane scroll = new JScrollPane(currentServerSettingsPanel);
|
||||
instance.splitPane.add(scroll, JSplitPane.RIGHT);
|
||||
instance.splitPane.revalidate();
|
||||
}
|
||||
currentServerSettingsPanel.setTable(tab);
|
||||
if (tab == ServerSettingsPanel.TAB_DEVICE_TYPE) {
|
||||
currentServerSettingsPanel.refreshDeviceTypes();
|
||||
} else if (tab == ServerSettingsPanel.TAB_USERS) {
|
||||
currentServerSettingsPanel.refreshUsers();
|
||||
} else if (tab == ServerSettingsPanel.TAB_SNMP_PROFILE) {
|
||||
// zatím neimplementováno
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void refreshDeviceTypes() {
|
||||
if (currentServerSettingsPanel != null) {
|
||||
currentServerSettingsPanel.refreshDeviceTypes();
|
||||
}
|
||||
}
|
||||
|
||||
public static void refreshUsers() {
|
||||
if (currentServerSettingsPanel != null) {
|
||||
currentServerSettingsPanel.refreshUsers();
|
||||
}
|
||||
}
|
||||
|
||||
public static void refreshMapTree() {
|
||||
if (instance != null) {
|
||||
instance.mapTree.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
public static MapTree getMapTree() {
|
||||
return instance != null ? instance.mapTree : null;
|
||||
}
|
||||
|
||||
public static void refreshEventsIfVisible() {
|
||||
if (currentEventsPanel != null && currentEventsPanel.isShowing()) {
|
||||
currentEventsPanel.refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,147 @@
|
|||
package jnet.client.gui.dialog;
|
||||
|
||||
import jnet.client.gui.Window;
|
||||
import jnet.client.gui.serversettings.ServerSettingsPanel;
|
||||
import jnet.client.client.NettyClientManager;
|
||||
import jnet.lib.LogFile;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.ObjectType;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Base64;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class AddDeviceTypeDialog extends JDialog {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(AddDeviceTypeDialog.class.getName());
|
||||
|
||||
private JLabel info = new JLabel("PNG obrázek o šířce 32px");
|
||||
private JTextField nazevText = new JTextField(15);
|
||||
private String imgStr = "";
|
||||
|
||||
public AddDeviceTypeDialog() {
|
||||
setTitle("Přidat typ zařízení");
|
||||
setModal(true);
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
initComponents();
|
||||
pack();
|
||||
setLocationRelativeTo(null);
|
||||
}
|
||||
|
||||
private void initComponents() {
|
||||
JPanel panel = new JPanel(new GridBagLayout());
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
gbc.insets = new Insets(5, 10, 5, 10);
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
|
||||
int row = 0;
|
||||
|
||||
// Název
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = row;
|
||||
panel.add(new JLabel("Název:"), gbc);
|
||||
gbc.gridx = 1;
|
||||
gbc.gridwidth = 2;
|
||||
panel.add(nazevText, gbc);
|
||||
row++;
|
||||
|
||||
// Obrázek
|
||||
gbc.gridwidth = 1;
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = row;
|
||||
panel.add(new JLabel("Obrázek"), gbc);
|
||||
|
||||
JButton browseButton = new JButton("Browse");
|
||||
browseButton.addActionListener(e -> browseImage());
|
||||
gbc.gridx = 1;
|
||||
panel.add(browseButton, gbc);
|
||||
|
||||
gbc.gridx = 2;
|
||||
panel.add(info, gbc);
|
||||
row++;
|
||||
|
||||
// Tlačítka
|
||||
JButton addButton = new JButton("Přidat");
|
||||
addButton.addActionListener(e -> addDeviceType());
|
||||
JButton cancelButton = new JButton("Storno");
|
||||
cancelButton.addActionListener(e -> dispose());
|
||||
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = row;
|
||||
gbc.gridwidth = 1;
|
||||
panel.add(addButton, gbc);
|
||||
gbc.gridx = 2;
|
||||
panel.add(cancelButton, gbc);
|
||||
|
||||
add(panel);
|
||||
}
|
||||
|
||||
private void browseImage() {
|
||||
JFileChooser fc = new JFileChooser(".");
|
||||
fc.setFileFilter(new FileNameExtensionFilter("PNG obrázky", "png"));
|
||||
if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
|
||||
File file = fc.getSelectedFile();
|
||||
try {
|
||||
String mimeType = Files.probeContentType(file.toPath());
|
||||
if (!"image/png".equals(mimeType)) {
|
||||
info.setForeground(Color.RED);
|
||||
info.setText("Chybný formát – vyberte PNG.");
|
||||
return;
|
||||
}
|
||||
BufferedImage bimg = ImageIO.read(file);
|
||||
if (bimg == null || bimg.getWidth() != 32) {
|
||||
info.setForeground(Color.RED);
|
||||
info.setText("Obrázek musí mít šířku 32px.");
|
||||
return;
|
||||
}
|
||||
imgStr = encodeFileToBase64(file);
|
||||
info.setForeground(Color.BLACK);
|
||||
info.setText("Obrázek nahrán (" + file.getName() + ")");
|
||||
} catch (IOException ex) {
|
||||
LOG.log(Level.SEVERE, "Chyba při načítání obrázku", ex);
|
||||
info.setForeground(Color.RED);
|
||||
info.setText("Chyba čtení souboru.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addDeviceType() {
|
||||
String name = nazevText.getText().trim();
|
||||
if (name.length() < 3) {
|
||||
info.setForeground(Color.RED);
|
||||
info.setText("Název musí mít alespoň 3 znaky.");
|
||||
return;
|
||||
}
|
||||
if (imgStr.isEmpty()) {
|
||||
info.setForeground(Color.RED);
|
||||
info.setText("Musíte vybrat obrázek.");
|
||||
return;
|
||||
}
|
||||
NettyClientManager.sendMessage(new Message(Message.NODE_ICON_NEW, new ObjectType(name, imgStr)));
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
Window.showServerSettings(ServerSettingsPanel.TAB_DEVICE_TYPE);
|
||||
dispose();
|
||||
});
|
||||
}
|
||||
|
||||
private static String encodeFileToBase64(File file) throws IOException {
|
||||
try (FileInputStream fis = new FileInputStream(file)) {
|
||||
byte[] bytes = new byte[(int) file.length()];
|
||||
int read = fis.read(bytes);
|
||||
if (read != bytes.length) {
|
||||
throw new IOException("Přečteno méně bajtů než očekáváno.");
|
||||
}
|
||||
return Base64.getEncoder().encodeToString(bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,283 @@
|
|||
package jnet.client.gui.dialog;
|
||||
|
||||
import java.awt.HeadlessException;
|
||||
import java.awt.Image;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.DefaultComboBoxModel;
|
||||
import javax.swing.ImageIcon;
|
||||
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.client.NettyClientManager;
|
||||
import jnet.lib.LogFile;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.ResourceLoader;
|
||||
import jnet.lib.object.Interface;
|
||||
import jnet.lib.object.Node;
|
||||
import jnet.lib.object.NodeConnection;
|
||||
import jnet.lib.object.Site;
|
||||
|
||||
public class ConnectionDialog extends JFrame {
|
||||
|
||||
private Node startObj;
|
||||
private Node endObj;
|
||||
private Boolean newObject;
|
||||
private List<Interface> iface = new ArrayList<>();
|
||||
private NodeConnection connection = new NodeConnection();
|
||||
private JLabel loadingLabel;
|
||||
|
||||
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(Node startObj, Node endObj, boolean newObject) throws HeadlessException {
|
||||
// this.startObj = startObj;
|
||||
// this.endObj = endObj;
|
||||
// this.newObject = newObject;
|
||||
//
|
||||
// init();
|
||||
// }
|
||||
public ConnectionDialog(NodeConnection connection, boolean newObject) throws HeadlessException {
|
||||
this.connection = connection;
|
||||
this.newObject = newObject;
|
||||
|
||||
// nastaveni pocatecniho a koncoveho objektu podle id
|
||||
for (Site map : Client.site) {
|
||||
for (Node object : map.getNode()) {
|
||||
if (object.getId() == connection.getNodeFrom()) {
|
||||
this.startObj = object;
|
||||
}
|
||||
if (object.getId() == connection.getNodeTo()) {
|
||||
this.endObj = object;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sourceDeviceComboBox.setEnabled(false);
|
||||
sourceInterfaceComboBox.setEnabled(false);
|
||||
|
||||
if (!newObject) {
|
||||
if (connection.isReadTraffic()) {
|
||||
readTraffic.setSelected(true);
|
||||
sourceDeviceComboBox.setEnabled(true);
|
||||
sourceDeviceComboBox.setSelectedItem(startObj.getName());
|
||||
sourceInterfaceComboBox.setEnabled(true);
|
||||
sourceInterfaceComboBox.setSelectedItem(connection.getTrafficIface());
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
try {
|
||||
loadingLabel = new JLabel();
|
||||
loadingLabel.setBounds(410, 300, 35, 35);
|
||||
Image image = ImageIO.read(ResourceLoader.getFile("/img/wait.png"));
|
||||
loadingLabel.setIcon(new ImageIcon(image));
|
||||
loadingLabel.setVisible(false);
|
||||
add(loadingLabel);
|
||||
} catch (IOException ex) {
|
||||
LogFile.printErr(ex.getMessage());
|
||||
}
|
||||
|
||||
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.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.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.getTrafficNode() == startObj.getId() ? 0 : 1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void loadIface() {
|
||||
loadingLabel.setVisible(true);
|
||||
Node obj;
|
||||
if (sourceDeviceComboBox.getSelectedIndex() == 0) {
|
||||
obj = startObj;
|
||||
} else {
|
||||
obj = endObj;
|
||||
}
|
||||
Object[] o = {this.getName(), obj};
|
||||
NettyClientManager.sendMessage(Message.NODE_CONNECTION_SNMP_INTERFACE, o);
|
||||
}
|
||||
|
||||
public void updateInterface(List<Interface> iface) {
|
||||
loadingLabel.setVisible(false);
|
||||
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.setTrafficNode(sourceDeviceComboBox.getSelectedIndex() == 0 ? startObj.getId() : endObj.getId());
|
||||
connection.setTrafficIface(sellectedIface.getId());
|
||||
}
|
||||
|
||||
if (newObject) {
|
||||
connection.setNodeFrom(startObj.getId());
|
||||
connection.setNodeTo(endObj.getId());
|
||||
connection.setSite(startObj.getSiteId());
|
||||
NettyClientManager.sendMessage(Message.NODE_CONNECTION_NEW, connection);
|
||||
} else {
|
||||
NettyClientManager.sendMessage(Message.NODE_CONNECTION_EDIT, 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,401 @@
|
|||
package jnet.client.gui.dialog;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Component;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
import jnet.client.Client;
|
||||
import jnet.client.client.NettyClientManager;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.Node;
|
||||
import jnet.lib.object.NodeProbe;
|
||||
import jnet.lib.object.SnmpTemplate;
|
||||
import jnet.lib.object.SnmpValueMap;
|
||||
|
||||
public class DialogProbe extends JFrame {
|
||||
|
||||
private Node node;
|
||||
private NodeProbe probe;
|
||||
private boolean newProbe;
|
||||
private JComboBox<TemplateItem> templateComboBox;
|
||||
private JComboBox<TypeItem> dataTypeComBox;
|
||||
private JComboBox<TypeItem> conversionTypeComBox;
|
||||
private JComboBox<ValueMapItem> mapValueComBox;
|
||||
private JTextField oidField = new JTextField();
|
||||
private JTextField conversionValueField = new JTextField();
|
||||
private JTextField conversionExpressionField = new JTextField();
|
||||
private JTextField intervalField = new JTextField();
|
||||
private JTextField unitField = new JTextField();
|
||||
private JTextField nameField = new JTextField();
|
||||
|
||||
public DialogProbe(NodeProbe probe, Node node, boolean newProbe) {
|
||||
this.node = node;
|
||||
this.probe = probe;
|
||||
this.newProbe = newProbe;
|
||||
|
||||
// identifikator okna
|
||||
this.setName("probe_detail_" + node.getId());
|
||||
init();
|
||||
|
||||
}
|
||||
|
||||
private void init() {
|
||||
|
||||
if (newProbe) {
|
||||
setTitle("Nová sonda");
|
||||
} else {
|
||||
setTitle(probe.getName());
|
||||
}
|
||||
|
||||
setSize(400, 700);
|
||||
setLocationRelativeTo(null);
|
||||
setAlwaysOnTop(false);
|
||||
setResizable(false);
|
||||
|
||||
setLayout(null);
|
||||
|
||||
///
|
||||
/// pole nazev
|
||||
///
|
||||
JLabel nameLabel = new JLabel("Název");
|
||||
nameLabel.setBounds(20, 20, 120, 25);
|
||||
this.add(nameLabel);
|
||||
|
||||
nameField.setBounds(150, 20, 200, 25);
|
||||
this.add(nameField);
|
||||
|
||||
///
|
||||
/// pole ze sablony
|
||||
///
|
||||
JCheckBox checkBoxTemplate = new JCheckBox("Ze šablony");
|
||||
checkBoxTemplate.setBounds(20, getNextY(nameLabel), 200, 25);
|
||||
checkBoxTemplate.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (checkBoxTemplate.isSelected()) {
|
||||
templateComboBox.setEnabled(true);
|
||||
} else {
|
||||
templateComboBox.setEnabled(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
this.add(checkBoxTemplate);
|
||||
|
||||
///
|
||||
/// rozeviraci pole vyberu sablony
|
||||
///
|
||||
JLabel templateLabel = new JLabel("Šablona");
|
||||
templateLabel.setBounds(20, getNextY(checkBoxTemplate), 120, 25);
|
||||
this.add(templateLabel);
|
||||
|
||||
templateComboBox = new JComboBox<>();
|
||||
templateComboBox.setEnabled(false);
|
||||
templateComboBox.setBounds(150, getNextY(checkBoxTemplate), 200, 25);
|
||||
for (SnmpTemplate template : Client.snmpTemplate) {
|
||||
System.err.println(node.getDeviceType() + " - " + template.getDeviceType());
|
||||
if (node.getDeviceType() == template.getDeviceType()) {
|
||||
TemplateItem item = new TemplateItem(template.getId(), template.getName(), template);
|
||||
templateComboBox.addItem(item);
|
||||
}
|
||||
|
||||
}
|
||||
templateComboBox.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
TemplateItem selectedItem = (TemplateItem) templateComboBox.getSelectedItem();
|
||||
SnmpTemplate template = selectedItem.getTemplate();
|
||||
// nastaveni polí podle vybrané šablony
|
||||
oidField.setText(template.getOid());
|
||||
unitField.setText(template.getUnit());
|
||||
dataTypeComBox.setSelectedIndex(getDataTypeItemIndex(template.getDataType()));
|
||||
conversionTypeComBox.setSelectedIndex(getConverssionTypeItemIndex(template.getConversionType()));
|
||||
conversionValueField.setText(String.valueOf(template.getConversionValue()));
|
||||
conversionExpressionField.setText(template.getConversionExpression());
|
||||
}
|
||||
});
|
||||
add(templateComboBox);
|
||||
|
||||
///
|
||||
/// pole oid
|
||||
///
|
||||
JLabel oidLabel = new JLabel("OID");
|
||||
oidLabel.setBounds(20, getNextY(templateComboBox), 120, 25);
|
||||
this.add(oidLabel);
|
||||
|
||||
oidField.setBounds(150, getNextY(templateComboBox), 200, 25);
|
||||
this.add(oidField);
|
||||
|
||||
///
|
||||
/// rozeviraci pole vyberu data type
|
||||
///
|
||||
JLabel dataTypeLabel = new JLabel("Typ dat");
|
||||
dataTypeLabel.setBounds(20, getNextY(oidLabel), 120, 25);
|
||||
this.add(dataTypeLabel);
|
||||
|
||||
dataTypeComBox = new JComboBox<>();
|
||||
dataTypeComBox.setBounds(150, getNextY(oidLabel), 200, 25);
|
||||
dataTypeComBox.addItem(new TypeItem(SnmpTemplate.DATA_TYPE_COUNTER));
|
||||
dataTypeComBox.addItem(new TypeItem(SnmpTemplate.DATA_TYPE_GAUGE));
|
||||
dataTypeComBox.addItem(new TypeItem(SnmpTemplate.DATA_TYPE_INTEGER));
|
||||
dataTypeComBox.addItem(new TypeItem(SnmpTemplate.DATA_TYPE_IPADDRESS));
|
||||
dataTypeComBox.addItem(new TypeItem(SnmpTemplate.DATA_TYPE_OID));
|
||||
dataTypeComBox.addItem(new TypeItem(SnmpTemplate.DATA_TYPE_STRING));
|
||||
dataTypeComBox.addItem(new TypeItem(SnmpTemplate.DATA_TYPE_TIMESTICK));
|
||||
dataTypeComBox.addItem(new TypeItem(SnmpTemplate.DATA_TYPE_NULL));
|
||||
add(dataTypeComBox);
|
||||
|
||||
///
|
||||
/// rozeviraci pole vyberu conversion type
|
||||
///
|
||||
JLabel conversionTypeLabel = new JLabel("Konverzní typ");
|
||||
conversionTypeLabel.setBounds(20, getNextY(dataTypeLabel), 120, 25);
|
||||
this.add(conversionTypeLabel);
|
||||
|
||||
conversionTypeComBox = new JComboBox<>();
|
||||
conversionTypeComBox.setBounds(150, getNextY(dataTypeLabel), 200, 25);
|
||||
conversionTypeComBox.addItem(new TypeItem(SnmpTemplate.CONVERSION_TYPE_DIVIDE, "Dělení"));
|
||||
conversionTypeComBox.addItem(new TypeItem(SnmpTemplate.CONVERSION_TYPE_EXPRESSION, "Výraz"));
|
||||
conversionTypeComBox.addItem(new TypeItem(SnmpTemplate.CONVERSION_TYPE_MULTIPLY, "Násobení"));
|
||||
conversionTypeComBox.addItem(new TypeItem(SnmpTemplate.CONVERSION_TYPE_NONE, "Žádný"));
|
||||
conversionTypeComBox.addItem(new TypeItem(SnmpTemplate.CONVERSION_TYPE_OFFSET, "Offset"));
|
||||
add(conversionTypeComBox);
|
||||
|
||||
///
|
||||
/// pole conversion value
|
||||
///
|
||||
JLabel conversionValueLabel = new JLabel("Konverzní hodnota");
|
||||
conversionValueLabel.setBounds(20, getNextY(conversionTypeLabel), 120, 25);
|
||||
this.add(conversionValueLabel);
|
||||
|
||||
conversionValueField.setBounds(150, getNextY(conversionTypeLabel), 200, 25);
|
||||
this.add(conversionValueField);
|
||||
|
||||
///
|
||||
/// pole conversion value
|
||||
///
|
||||
JLabel conversionExpressionLabel = new JLabel("Konverzní výraz");
|
||||
conversionExpressionLabel.setBounds(20, getNextY(conversionValueLabel), 120, 25);
|
||||
this.add(conversionExpressionLabel);
|
||||
|
||||
conversionExpressionField = new JTextField();
|
||||
conversionExpressionField.setBounds(150, getNextY(conversionValueLabel), 200, 75);
|
||||
this.add(conversionExpressionField);
|
||||
|
||||
///
|
||||
/// rozeviraci pole mapovani hodnot
|
||||
///
|
||||
JLabel mapValueLabel = new JLabel("Mapování hodnot");
|
||||
mapValueLabel.setBounds(20, getNextY(conversionExpressionField), 120, 25);
|
||||
this.add(mapValueLabel);
|
||||
|
||||
mapValueComBox = new JComboBox<>();
|
||||
mapValueComBox.setBounds(150, getNextY(conversionExpressionField), 200, 25);
|
||||
for (SnmpValueMap snmpValueMap : Client.snmpValueMap) {
|
||||
ValueMapItem valueMapItem = new ValueMapItem(snmpValueMap.getId(), snmpValueMap.getName());
|
||||
mapValueComBox.addItem(valueMapItem);
|
||||
}
|
||||
add(mapValueComBox);
|
||||
|
||||
///
|
||||
/// pole unit
|
||||
///
|
||||
JLabel unitLabel = new JLabel("Jednotka (V, °C, ...)");
|
||||
unitLabel.setBounds(20, getNextY(mapValueLabel), 120, 25);
|
||||
this.add(unitLabel);
|
||||
|
||||
unitField = new JTextField();
|
||||
unitField.setBounds(150, getNextY(mapValueLabel), 200, 25);
|
||||
this.add(unitField);
|
||||
|
||||
///
|
||||
/// pole interval
|
||||
///
|
||||
JLabel intervalLabel = new JLabel("Interval (sekund)");
|
||||
intervalLabel.setBounds(20, getNextY(unitLabel), 120, 25);
|
||||
this.add(intervalLabel);
|
||||
|
||||
intervalField = new JTextField();
|
||||
intervalField.setBounds(150, getNextY(unitLabel), 200, 25);
|
||||
intervalField.setText("30");
|
||||
this.add(intervalField);
|
||||
|
||||
// spodni tlacitka
|
||||
JPanel pane = new JPanel();
|
||||
pane.setBounds(0, getNextY(intervalLabel), this.getWidth(), this.getHeight());
|
||||
JButton save = new JButton("Ulozit");
|
||||
save.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// kontrola chyb
|
||||
|
||||
// sestaveni probe
|
||||
probe.setNodeId(node.getId());
|
||||
probe.setName(nameField.getText());
|
||||
probe.setOid(oidField.getText());
|
||||
probe.setUnit(unitField.getText());
|
||||
TypeItem dataType = (TypeItem) dataTypeComBox.getSelectedItem();
|
||||
probe.setDataType(dataType.id);
|
||||
TypeItem conversionType = (TypeItem) conversionTypeComBox.getSelectedItem();
|
||||
probe.setConversionType(conversionType.id);
|
||||
probe.setConversionValue(Double.parseDouble(conversionValueField.getText()));
|
||||
ValueMapItem valueMap = (ValueMapItem) mapValueComBox.getSelectedItem();
|
||||
probe.setValueMap(valueMap.id);
|
||||
probe.setInterval(Integer.parseInt(intervalField.getText()));
|
||||
// odeslani
|
||||
NettyClientManager.sendMessage(Message.NODE_PROBE_NEW, probe);
|
||||
// zavreni dialogu
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
pane.add(save);
|
||||
|
||||
JButton cancel = new JButton("Zavřít");
|
||||
cancel.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
pane.add(cancel);
|
||||
|
||||
add(pane, BorderLayout.PAGE_END);
|
||||
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
private int getNextY(Component p) {
|
||||
return p.getY() + p.getHeight() + 20;
|
||||
}
|
||||
|
||||
private int getDataTypeItemIndex(String value) {
|
||||
switch (value) {
|
||||
case SnmpTemplate.DATA_TYPE_COUNTER -> {
|
||||
return 0;
|
||||
}
|
||||
case SnmpTemplate.DATA_TYPE_GAUGE -> {
|
||||
return 1;
|
||||
}
|
||||
case SnmpTemplate.DATA_TYPE_INTEGER -> {
|
||||
return 2;
|
||||
}
|
||||
case SnmpTemplate.DATA_TYPE_IPADDRESS -> {
|
||||
return 3;
|
||||
}
|
||||
case SnmpTemplate.DATA_TYPE_OID -> {
|
||||
return 4;
|
||||
}
|
||||
case SnmpTemplate.DATA_TYPE_STRING -> {
|
||||
return 5;
|
||||
}
|
||||
case SnmpTemplate.DATA_TYPE_TIMESTICK -> {
|
||||
return 6;
|
||||
}
|
||||
case SnmpTemplate.DATA_TYPE_NULL -> {
|
||||
return 7;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int getConverssionTypeItemIndex(String value) {
|
||||
switch (value) {
|
||||
case SnmpTemplate.CONVERSION_TYPE_DIVIDE -> {
|
||||
return 0;
|
||||
}
|
||||
case SnmpTemplate.CONVERSION_TYPE_EXPRESSION -> {
|
||||
return 1;
|
||||
}
|
||||
case SnmpTemplate.CONVERSION_TYPE_MULTIPLY -> {
|
||||
return 2;
|
||||
}
|
||||
case SnmpTemplate.CONVERSION_TYPE_NONE -> {
|
||||
return 3;
|
||||
}
|
||||
case SnmpTemplate.CONVERSION_TYPE_OFFSET -> {
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
class TemplateItem {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
private SnmpTemplate template;
|
||||
|
||||
public TemplateItem(int id, String name, SnmpTemplate template) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.template = template;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public SnmpTemplate getTemplate() {
|
||||
return template;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name; // Zobrazí se pouze název
|
||||
}
|
||||
}
|
||||
|
||||
class TypeItem {
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
|
||||
public TypeItem(String id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public TypeItem(String name) {
|
||||
this.id = name;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name; // Zobrazí se pouze název
|
||||
}
|
||||
}
|
||||
|
||||
class ValueMapItem {
|
||||
|
||||
int id;
|
||||
String name;
|
||||
|
||||
public ValueMapItem(int id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name; // Zobrazí se pouze název
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,162 @@
|
|||
package jnet.client.gui.dialog;
|
||||
|
||||
import jnet.client.Client;
|
||||
import jnet.client.client.NettyClientManager;
|
||||
import jnet.lib.ApacheConfig;
|
||||
import org.apache.commons.configuration2.PropertiesConfiguration;
|
||||
import org.apache.commons.configuration2.ex.ConfigurationException;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static jnet.client.Client.nettyClient;
|
||||
import jnet.lib.LogFile;
|
||||
|
||||
public class LoginDialog extends JDialog {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(LoginDialog.class.getName());
|
||||
|
||||
private JTextField serverText;
|
||||
private JTextField portText;
|
||||
private JTextField userText;
|
||||
private JPasswordField passwordText;
|
||||
|
||||
public LoginDialog() {
|
||||
setTitle("Přihlásit");
|
||||
setSize(350, 250);
|
||||
setLocationRelativeTo(null);
|
||||
setResizable(false);
|
||||
setModal(true);
|
||||
initComponents();
|
||||
}
|
||||
|
||||
private void initComponents() {
|
||||
JPanel panel = new JPanel(new GridBagLayout());
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
gbc.insets = new Insets(5, 5, 5, 5);
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
|
||||
// Načtení uložených hodnot (plain text)
|
||||
String savedServer = Client.config.getString("server", "");
|
||||
String savedPort = Client.config.getString("port", "");
|
||||
String savedUser = Client.config.getString("user", "");
|
||||
String savedPassword = Client.config.getString("password", "");
|
||||
|
||||
// Server
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 0;
|
||||
gbc.gridwidth = 1;
|
||||
panel.add(new JLabel("Server:"), gbc);
|
||||
|
||||
serverText = new JTextField(savedServer, 15);
|
||||
gbc.gridx = 1;
|
||||
gbc.gridwidth = 2;
|
||||
panel.add(serverText, gbc);
|
||||
|
||||
// Port
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 1;
|
||||
gbc.gridwidth = 1;
|
||||
panel.add(new JLabel("Port:"), gbc);
|
||||
|
||||
portText = new JTextField(savedPort, 5);
|
||||
gbc.gridx = 1;
|
||||
gbc.gridwidth = 2;
|
||||
panel.add(portText, gbc);
|
||||
|
||||
// Uživatel
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 2;
|
||||
gbc.gridwidth = 1;
|
||||
panel.add(new JLabel("Uživatel:"), gbc);
|
||||
|
||||
userText = new JTextField(savedUser, 15);
|
||||
gbc.gridx = 1;
|
||||
gbc.gridwidth = 2;
|
||||
panel.add(userText, gbc);
|
||||
|
||||
// Heslo
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 3;
|
||||
gbc.gridwidth = 1;
|
||||
panel.add(new JLabel("Heslo:"), gbc);
|
||||
|
||||
passwordText = new JPasswordField(savedPassword, 15);
|
||||
gbc.gridx = 1;
|
||||
gbc.gridwidth = 2;
|
||||
panel.add(passwordText, gbc);
|
||||
|
||||
// Tlačítka
|
||||
JButton loginButton = new JButton("Přihlásit");
|
||||
loginButton.addActionListener(e -> performLogin());
|
||||
|
||||
JButton closeButton = new JButton("Storno");
|
||||
closeButton.addActionListener(e -> dispose());
|
||||
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 4;
|
||||
gbc.gridwidth = 1;
|
||||
gbc.anchor = GridBagConstraints.CENTER;
|
||||
panel.add(loginButton, gbc);
|
||||
|
||||
gbc.gridx = 2;
|
||||
panel.add(closeButton, gbc);
|
||||
|
||||
add(panel);
|
||||
pack();
|
||||
}
|
||||
|
||||
private void performLogin() {
|
||||
String server = serverText.getText().trim();
|
||||
String portStr = portText.getText().trim();
|
||||
String user = userText.getText().trim();
|
||||
String password = new String(passwordText.getPassword());
|
||||
|
||||
// Validace
|
||||
if (server.isEmpty() || portStr.isEmpty() || user.isEmpty() || password.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(this,
|
||||
"Všechna pole musí být vyplněna.",
|
||||
"Chyba",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
int port;
|
||||
try {
|
||||
port = Integer.parseInt(portStr);
|
||||
} catch (NumberFormatException ex) {
|
||||
JOptionPane.showMessageDialog(this,
|
||||
"Port musí být číslo.",
|
||||
"Chyba",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
// Uložení do konfigurace (bez hashování – zatím plain text)
|
||||
try {
|
||||
Client.config.setProperty("server", server);
|
||||
Client.config.setProperty("port", portStr);
|
||||
Client.config.setProperty("user", user);
|
||||
Client.config.setProperty("password", password); // plain text
|
||||
ApacheConfig.saveProperties( Client.config);
|
||||
|
||||
// Připojení klienta (mimo EDT – Netty)
|
||||
Client.nettyClient = new NettyClientManager(server, port);
|
||||
nettyClient.start();
|
||||
|
||||
// Zavření dialogu
|
||||
dispose();
|
||||
|
||||
} catch (ConfigurationException ex) {
|
||||
LogFile.printErr("Chyba při ukládání konfigurace");
|
||||
JOptionPane.showMessageDialog(this,
|
||||
"Chyba při ukládání nastavení: " + ex.getMessage(),
|
||||
"Chyba",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
package jnet.client.gui.dialog;
|
||||
|
||||
import jnet.client.client.NettyClientManager;
|
||||
import jnet.lib.Message;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class NewSiteDialog extends JDialog {
|
||||
|
||||
public NewSiteDialog() {
|
||||
setTitle("Přidat mapu");
|
||||
setModal(true);
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
initComponents();
|
||||
pack();
|
||||
setLocationRelativeTo(null);
|
||||
}
|
||||
|
||||
private void initComponents() {
|
||||
JPanel panel = new JPanel(new GridBagLayout());
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
gbc.insets = new Insets(5, 10, 5, 10);
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
|
||||
int row = 0;
|
||||
|
||||
JLabel label = new JLabel("Název");
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = row;
|
||||
panel.add(label, gbc);
|
||||
|
||||
JTextField nameField = new JTextField(15);
|
||||
gbc.gridx = 1;
|
||||
gbc.gridwidth = 2;
|
||||
panel.add(nameField, gbc);
|
||||
row++;
|
||||
|
||||
JButton addButton = new JButton("Přidat");
|
||||
JButton cancelButton = new JButton("Storno");
|
||||
|
||||
addButton.addActionListener(e -> {
|
||||
String name = nameField.getText().trim();
|
||||
if (name.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(this, "Název nesmí být prázdný.", "Chyba", JOptionPane.WARNING_MESSAGE);
|
||||
return;
|
||||
}
|
||||
if (name.length() < 3) {
|
||||
JOptionPane.showMessageDialog(this, "Název musí mít alespoň 3 znaky.", "Chyba", JOptionPane.WARNING_MESSAGE);
|
||||
return;
|
||||
}
|
||||
NettyClientManager.sendMessage(new Message(Message.SITE_ADD, name));
|
||||
dispose();
|
||||
});
|
||||
|
||||
cancelButton.addActionListener(e -> dispose());
|
||||
|
||||
gbc.gridwidth = 1;
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = row;
|
||||
panel.add(addButton, gbc);
|
||||
gbc.gridx = 2;
|
||||
panel.add(cancelButton, gbc);
|
||||
|
||||
add(panel);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,117 @@
|
|||
package jnet.client.gui.dialog;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Insets;
|
||||
import javax.swing.DefaultComboBoxModel;
|
||||
import javax.swing.DefaultListCellRenderer;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import static javax.swing.WindowConstants.DISPOSE_ON_CLOSE;
|
||||
import jnet.client.Client;
|
||||
import jnet.client.gui.mapview.MapView;
|
||||
import jnet.lib.object.Node;
|
||||
import jnet.lib.object.Site;
|
||||
|
||||
public class NodeChangeSite extends JDialog {
|
||||
|
||||
private final Node node;
|
||||
private final MapView mapView; // může být null
|
||||
|
||||
// Původní konstruktor pro zachování kompatibility
|
||||
public NodeChangeSite(Node node) {
|
||||
this(node, null);
|
||||
}
|
||||
|
||||
// Nový konstruktor s MapView
|
||||
public NodeChangeSite(Node node, MapView mapView) {
|
||||
this.node = node;
|
||||
this.mapView = mapView;
|
||||
setModal(true);
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
init();
|
||||
pack();
|
||||
setLocationRelativeTo(null);
|
||||
}
|
||||
|
||||
private void init() {
|
||||
setTitle("Přesun na jinou mapu");
|
||||
|
||||
JPanel panel = new JPanel(new GridBagLayout());
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
gbc.insets = new Insets(5, 10, 5, 10);
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
|
||||
int row = 0;
|
||||
|
||||
JLabel labelMap = new JLabel("Nová mapa");
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = row;
|
||||
panel.add(labelMap, gbc);
|
||||
|
||||
JComboBox<Site> comboBoxMap = new JComboBox<>();
|
||||
DefaultComboBoxModel<Site> model = new DefaultComboBoxModel<>();
|
||||
for (Site site : Client.site) {
|
||||
model.addElement(site);
|
||||
}
|
||||
comboBoxMap.setModel(model);
|
||||
comboBoxMap.setRenderer(new DefaultListCellRenderer() {
|
||||
@Override
|
||||
public Component getListCellRendererComponent(JList<?> list, Object value,
|
||||
int index, boolean isSelected,
|
||||
boolean cellHasFocus) {
|
||||
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||
if (value instanceof Site) {
|
||||
setText(((Site) value).getName());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
});
|
||||
// Pouze informativní výpis – neměníme node!
|
||||
comboBoxMap.addActionListener(e -> {
|
||||
Site selected = (Site) comboBoxMap.getSelectedItem();
|
||||
if (selected != null) {
|
||||
System.out.println("Vybráno: " + selected.getName() + " (ID: " + selected.getId() + ")");
|
||||
}
|
||||
});
|
||||
|
||||
gbc.gridx = 1;
|
||||
gbc.gridwidth = 2;
|
||||
panel.add(comboBoxMap, gbc);
|
||||
row++;
|
||||
|
||||
JButton addButton = new JButton("Uložit");
|
||||
JButton cancelButton = new JButton("Storno");
|
||||
|
||||
addButton.addActionListener(e -> {
|
||||
Site selected = (Site) comboBoxMap.getSelectedItem();
|
||||
if (selected != null && mapView != null) {
|
||||
// Spustíme režim umístění na cílové mapě
|
||||
mapView.startNodePlacement(node, selected.getId());
|
||||
// Přepneme na cílovou mapu
|
||||
mapView.switchToSite(selected.getId());
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(this, "Nebyla vybrána cílová mapa nebo chybí MapView.");
|
||||
}
|
||||
dispose();
|
||||
});
|
||||
|
||||
cancelButton.addActionListener(e -> dispose());
|
||||
|
||||
gbc.gridwidth = 1;
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = row;
|
||||
panel.add(addButton, gbc);
|
||||
gbc.gridx = 2;
|
||||
panel.add(cancelButton, gbc);
|
||||
|
||||
add(panel);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,127 @@
|
|||
package jnet.client.gui.dialog;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Insets;
|
||||
import javax.swing.DefaultComboBoxModel;
|
||||
import javax.swing.DefaultListCellRenderer;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JPanel;
|
||||
import static javax.swing.WindowConstants.DISPOSE_ON_CLOSE;
|
||||
import jnet.client.Client;
|
||||
import jnet.client.client.NettyClientManager;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.Node;
|
||||
import jnet.lib.object.Site;
|
||||
|
||||
|
||||
public class NodeMapLinkDialog extends JDialog {
|
||||
|
||||
private Boolean newObject;
|
||||
private Node node;
|
||||
|
||||
public NodeMapLinkDialog(Node node, Boolean newObject) {
|
||||
this.newObject = newObject;
|
||||
this.node = node;
|
||||
|
||||
setModal(true);
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
init();
|
||||
pack();
|
||||
setLocationRelativeTo(null);
|
||||
|
||||
}
|
||||
|
||||
private void init() {
|
||||
|
||||
if (newObject) {
|
||||
setTitle("Nový statický object");
|
||||
} else {
|
||||
setTitle(node.getName());
|
||||
}
|
||||
|
||||
JPanel panel = new JPanel(new GridBagLayout());
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
gbc.insets = new Insets(5, 10, 5, 10);
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
|
||||
int row = 0;
|
||||
|
||||
JLabel labelMap = new JLabel("Mapa");
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = row;
|
||||
panel.add(labelMap, gbc);
|
||||
|
||||
JComboBox<Site> comboBoxMap = new JComboBox<>();
|
||||
// Naplníme model
|
||||
DefaultComboBoxModel<Site> model = new DefaultComboBoxModel<>();
|
||||
for (Site site : Client.site) {
|
||||
model.addElement(site);
|
||||
}
|
||||
comboBoxMap.setModel(model);
|
||||
comboBoxMap.setRenderer(new DefaultListCellRenderer() {
|
||||
@Override
|
||||
public Component getListCellRendererComponent(JList<?> list, Object value,
|
||||
int index, boolean isSelected,
|
||||
boolean cellHasFocus) {
|
||||
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||
if (value instanceof Site) {
|
||||
Site s = (Site) value;
|
||||
setText(s.getName()); // zobrazí jméno
|
||||
}
|
||||
return this;
|
||||
}
|
||||
});
|
||||
comboBoxMap.addActionListener(e -> {
|
||||
Site selected = (Site) comboBoxMap.getSelectedItem();
|
||||
if (selected != null) {
|
||||
int id = selected.getId();
|
||||
String name = selected.getName();
|
||||
node.setName(selected.getName());
|
||||
node.setSiteLink(selected.getId());
|
||||
}
|
||||
});
|
||||
gbc.gridx = 1;
|
||||
gbc.gridwidth = 2;
|
||||
panel.add(comboBoxMap, gbc);
|
||||
row++;
|
||||
|
||||
JButton addButton = new JButton("Uložit");
|
||||
JButton cancelButton = new JButton("Storno");
|
||||
|
||||
addButton.addActionListener(e -> {
|
||||
|
||||
node.setPing(false);
|
||||
node.setType(Node.NODE_MAP);
|
||||
node.setIcon(1);
|
||||
|
||||
if (newObject) {
|
||||
NettyClientManager.sendMessage(new Message(Message.NODE_ADD, node));
|
||||
dispose();
|
||||
} else {
|
||||
NettyClientManager.sendMessage(new Message(Message.NODE_CHANGE, node));
|
||||
dispose();
|
||||
}
|
||||
dispose();
|
||||
});
|
||||
|
||||
cancelButton.addActionListener(e -> dispose());
|
||||
|
||||
gbc.gridwidth = 1;
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = row;
|
||||
panel.add(addButton, gbc);
|
||||
gbc.gridx = 2;
|
||||
panel.add(cancelButton, gbc);
|
||||
|
||||
add(panel);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
package jnet.client.gui.dialog;
|
||||
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Insets;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
import static javax.swing.WindowConstants.DISPOSE_ON_CLOSE;
|
||||
|
||||
import jnet.lib.object.Node;
|
||||
|
||||
import javax.swing.JDialog;
|
||||
import jnet.client.client.NettyClientManager;
|
||||
import jnet.lib.Message;
|
||||
|
||||
public class NodeStaticDialog extends JDialog {
|
||||
|
||||
private Boolean newObject;
|
||||
private Node node;
|
||||
|
||||
public NodeStaticDialog(Node node, Boolean newObject) {
|
||||
this.newObject = newObject;
|
||||
this.node = node;
|
||||
|
||||
setModal(true);
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
init();
|
||||
pack();
|
||||
setLocationRelativeTo(null);
|
||||
|
||||
}
|
||||
|
||||
private void init() {
|
||||
|
||||
if (newObject) {
|
||||
setTitle("Nový statický object");
|
||||
} else {
|
||||
setTitle(node.getName());
|
||||
}
|
||||
|
||||
JPanel panel = new JPanel(new GridBagLayout());
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
gbc.insets = new Insets(5, 10, 5, 10);
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
|
||||
int row = 0;
|
||||
|
||||
JLabel label = new JLabel("Název");
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = row;
|
||||
panel.add(label, gbc);
|
||||
|
||||
JTextField nameField = new JTextField(15);
|
||||
nameField.setText(node.getName());
|
||||
gbc.gridx = 1;
|
||||
gbc.gridwidth = 2;
|
||||
panel.add(nameField, gbc);
|
||||
row++;
|
||||
|
||||
JButton addButton = new JButton("Uložit");
|
||||
JButton cancelButton = new JButton("Storno");
|
||||
|
||||
addButton.addActionListener(e -> {
|
||||
String name = nameField.getText().trim();
|
||||
if (name.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(this, "Název nesmí být prázdný.", "Chyba", JOptionPane.WARNING_MESSAGE);
|
||||
return;
|
||||
}
|
||||
if (name.length() < 3) {
|
||||
JOptionPane.showMessageDialog(this, "Název musí mít alespoň 3 znaky.", "Chyba", JOptionPane.WARNING_MESSAGE);
|
||||
return;
|
||||
}
|
||||
node.setPing(false);
|
||||
node.setName(name);
|
||||
node.setType(Node.NODE_STATIC);
|
||||
node.setIcon(1);
|
||||
|
||||
if (newObject) {
|
||||
NettyClientManager.sendMessage(new Message(Message.NODE_ADD, node));
|
||||
dispose();
|
||||
} else {
|
||||
NettyClientManager.sendMessage(new Message(Message.NODE_CHANGE, node));
|
||||
dispose();
|
||||
}
|
||||
dispose();
|
||||
});
|
||||
|
||||
cancelButton.addActionListener(e -> dispose());
|
||||
|
||||
gbc.gridwidth = 1;
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = row;
|
||||
panel.add(addButton, gbc);
|
||||
gbc.gridx = 2;
|
||||
panel.add(cancelButton, gbc);
|
||||
|
||||
add(panel);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
package jnet.client.gui.dialog;
|
||||
|
||||
import jnet.client.Client;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
import java.io.IOException;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.Box;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import jnet.lib.LogFile;
|
||||
import jnet.lib.ResourceLoader;
|
||||
import jnet.lib.object.OnlineClients;
|
||||
|
||||
public class OnlineClientsDialog extends JDialog {
|
||||
|
||||
public OnlineClientsDialog() {
|
||||
setTitle("Online klienti");
|
||||
setLocationRelativeTo(null);
|
||||
setAlwaysOnTop(true);
|
||||
|
||||
setLayout(new FlowLayout(FlowLayout.CENTER));
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
|
||||
panel.setBorder(new EmptyBorder(10, 25, 10, 25));
|
||||
|
||||
panel.add(Box.createRigidArea(new Dimension(5, 10)));
|
||||
for (OnlineClients oc : Client.onlineClients) {
|
||||
try {
|
||||
JLabel line = new JLabel(" " + oc.getUsername() + " (" + oc.getIp() + ")");
|
||||
switch (oc.getPlatform()) {
|
||||
case OnlineClients.PLATFORM_MOBILE:
|
||||
line.setIcon(new ImageIcon(ImageIO.read(ResourceLoader.getFile("/img/platform_android.png"))));
|
||||
break;
|
||||
case OnlineClients.PLATFORM_PC:
|
||||
line.setIcon(new ImageIcon(ImageIO.read(ResourceLoader.getFile("/img/platform_pc.png"))));
|
||||
break;
|
||||
}
|
||||
panel.add(line);
|
||||
panel.add(Box.createRigidArea(new Dimension(5, 10)));
|
||||
} catch (IOException ex) {
|
||||
LogFile.printErr("Online Clients dialog exception: " + ex.getMessage());
|
||||
}
|
||||
|
||||
panel.add(Box.createRigidArea(new Dimension(5, 20)));
|
||||
}
|
||||
|
||||
add(panel);
|
||||
pack();
|
||||
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,175 @@
|
|||
package jnet.client.gui.dialog;
|
||||
|
||||
import jnet.client.gui.Window;
|
||||
import jnet.client.gui.serversettings.ServerSettingsPanel;
|
||||
import jnet.client.client.NettyClientManager;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.User;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
public class UserDialog extends JDialog {
|
||||
|
||||
private boolean newUser;
|
||||
private final User user;
|
||||
private JTextField userNameField;
|
||||
private JTextField passwordField;
|
||||
private JCheckBox setServer;
|
||||
private JCheckBox addMap;
|
||||
private JCheckBox deleteMap;
|
||||
private JCheckBox editMap;
|
||||
private JCheckBox addObject;
|
||||
private JCheckBox deleteObject;
|
||||
private JCheckBox editObject;
|
||||
|
||||
public UserDialog(User user, boolean newUser) {
|
||||
this.user = user;
|
||||
this.newUser = newUser;
|
||||
|
||||
setTitle(user == null ? "Přidat uživatele" : "Upravit uživatele");
|
||||
setModal(true);
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
initComponents();
|
||||
if (!newUser) {
|
||||
loadUserData();
|
||||
} else {
|
||||
passwordField.setText(generateRandomPassword(8));
|
||||
}
|
||||
pack();
|
||||
setLocationRelativeTo(null);
|
||||
}
|
||||
|
||||
private void initComponents() {
|
||||
JPanel panel = new JPanel(new GridBagLayout());
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
gbc.insets = new Insets(5, 10, 5, 10);
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
|
||||
int row = 0;
|
||||
|
||||
userNameField = new JTextField(15);
|
||||
addRow(panel, gbc, row++, "Uživatelské jméno", userNameField);
|
||||
|
||||
passwordField = new JTextField(15);
|
||||
addRow(panel, gbc, row++, "Heslo", passwordField);
|
||||
|
||||
setServer = new JCheckBox("Nastavit server");
|
||||
addMap = new JCheckBox("Přidat mapu");
|
||||
deleteMap = new JCheckBox("Odebrat mapu");
|
||||
editMap = new JCheckBox("Upravit mapu");
|
||||
addObject = new JCheckBox("Přidat objekt");
|
||||
deleteObject = new JCheckBox("Odebrat objekt");
|
||||
editObject = new JCheckBox("Upravit objekt");
|
||||
|
||||
gbc.gridwidth = 2;
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = row;
|
||||
panel.add(setServer, gbc);
|
||||
row++;
|
||||
gbc.gridy = row;
|
||||
panel.add(addMap, gbc);
|
||||
row++;
|
||||
gbc.gridy = row;
|
||||
panel.add(deleteMap, gbc);
|
||||
row++;
|
||||
gbc.gridy = row;
|
||||
panel.add(editMap, gbc);
|
||||
row++;
|
||||
gbc.gridy = row;
|
||||
panel.add(addObject, gbc);
|
||||
row++;
|
||||
gbc.gridy = row;
|
||||
panel.add(deleteObject, gbc);
|
||||
row++;
|
||||
gbc.gridy = row;
|
||||
panel.add(editObject, gbc);
|
||||
row++;
|
||||
|
||||
JButton actionBtn = new JButton(user == null ? "Přidat" : "Upravit");
|
||||
JButton cancelBtn = new JButton("Storno");
|
||||
|
||||
actionBtn.addActionListener(e -> performAction());
|
||||
cancelBtn.addActionListener(e -> dispose());
|
||||
|
||||
gbc.gridwidth = 1;
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = row;
|
||||
panel.add(actionBtn, gbc);
|
||||
gbc.gridx = 2;
|
||||
panel.add(cancelBtn, gbc);
|
||||
|
||||
add(panel);
|
||||
}
|
||||
|
||||
private void addRow(JPanel panel, GridBagConstraints gbc, int row, String label, JComponent comp) {
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = row;
|
||||
gbc.gridwidth = 1;
|
||||
panel.add(new JLabel(label), gbc);
|
||||
gbc.gridx = 1;
|
||||
gbc.gridwidth = 2;
|
||||
panel.add(comp, gbc);
|
||||
}
|
||||
|
||||
private void loadUserData() {
|
||||
userNameField.setText(user.getUsername());
|
||||
setServer.setSelected(user.isEditServer());
|
||||
addMap.setSelected(user.isAddMap());
|
||||
deleteMap.setSelected(user.isRemoveMap());
|
||||
editMap.setSelected(user.isEditMap());
|
||||
addObject.setSelected(user.isAddObject());
|
||||
deleteObject.setSelected(user.isRemoveObject());
|
||||
editObject.setSelected(user.isEditObject());
|
||||
}
|
||||
|
||||
private void performAction() {
|
||||
String name = userNameField.getText().trim();
|
||||
if (name.length() < 3) {
|
||||
JOptionPane.showMessageDialog(this, "Uživatelské jméno musí mít alespoň 3 znaky.", "Chyba", JOptionPane.WARNING_MESSAGE);
|
||||
return;
|
||||
}
|
||||
String pwd = passwordField.getText().trim();
|
||||
if (pwd.isEmpty() && newUser) {
|
||||
JOptionPane.showMessageDialog(this, "Heslo nesmí být prázdné.", "Chyba", JOptionPane.WARNING_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
User u = new User(
|
||||
0,
|
||||
name,
|
||||
pwd,
|
||||
addMap.isSelected(),
|
||||
deleteMap.isSelected(),
|
||||
editMap.isSelected(),
|
||||
addObject.isSelected(),
|
||||
deleteObject.isSelected(),
|
||||
editObject.isSelected(),
|
||||
setServer.isSelected()
|
||||
);
|
||||
|
||||
if (newUser) {
|
||||
NettyClientManager.sendMessage(new Message(Message.USER_ADD, u));
|
||||
} else {
|
||||
u.setId(user.getId());
|
||||
NettyClientManager.sendMessage(new Message(Message.USER_EDIT, u));
|
||||
}
|
||||
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
Window.showServerSettings(ServerSettingsPanel.TAB_USERS);
|
||||
dispose();
|
||||
});
|
||||
}
|
||||
|
||||
private String generateRandomPassword(int length) {
|
||||
String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
SecureRandom random = new SecureRandom();
|
||||
StringBuilder sb = new StringBuilder(length);
|
||||
for (int i = 0; i < length; i++) {
|
||||
sb.append(chars.charAt(random.nextInt(chars.length())));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,300 @@
|
|||
package jnet.client.gui.dialog.node;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Frame;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.ArrayList;
|
||||
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.client.NettyClientManager;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.Status;
|
||||
import jnet.lib.object.DeviceInfo;
|
||||
import jnet.lib.object.Interface;
|
||||
import jnet.lib.object.Node;
|
||||
import jnet.lib.object.SnmpProfile;
|
||||
|
||||
public class NodeDeviceDialog extends JFrame {
|
||||
|
||||
private Node obj;
|
||||
private int mapId;
|
||||
private Boolean newObject;
|
||||
|
||||
private TabInfo tabInfo;
|
||||
private TabSettings tabSettings;
|
||||
private TabServices tabServices;
|
||||
private TabEvents tabEvents;
|
||||
private TabProbes tabProbes;
|
||||
|
||||
private JButton snmpTest = new JButton("Test SNMP");
|
||||
private JButton btnRefresh = new JButton("Obnovit");
|
||||
private JDialog progress;
|
||||
|
||||
public NodeDeviceDialog(Node obj) {
|
||||
this.obj = obj;
|
||||
this.newObject = false;
|
||||
|
||||
// identifikator okna
|
||||
this.setName("object_detail_" + obj.getId());
|
||||
init();
|
||||
}
|
||||
|
||||
public NodeDeviceDialog(Node obj, boolean newObject) {
|
||||
this.obj = obj;
|
||||
this.newObject = newObject;
|
||||
if (newObject) {
|
||||
obj.setProbe(new ArrayList<>());
|
||||
}
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
|
||||
if (newObject) {
|
||||
setTitle("Nové zařízení");
|
||||
} 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);
|
||||
tabProbes = new TabProbes(obj);
|
||||
|
||||
tabbedPane.addTab("Informace", tabInfo);
|
||||
tabbedPane.addTab("Události", tabEvents);
|
||||
tabbedPane.addTab("Nastaveni", tabSettings);
|
||||
tabbedPane.addTab("Služby", tabServices);
|
||||
tabbedPane.addTab("Sondy", tabProbes);
|
||||
|
||||
// Přidání listeneru na změnu tabu
|
||||
tabbedPane.addChangeListener(new ChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
int selectedIndex = tabbedPane.getSelectedIndex();
|
||||
if (selectedIndex == 2) { // 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(2); // prepne na kartu nastaveni
|
||||
tabbedPane.setEnabledAt(0, false); // vypne kartu informace
|
||||
tabbedPane.setEnabledAt(1, false); // vypne kartu udalosti
|
||||
tabbedPane.setEnabledAt(4, 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.setType(Node.NODE_DEVICE);
|
||||
obj.setName(nazev);
|
||||
obj.setIp(ip);
|
||||
obj.setUser(tabSettings.getUser());
|
||||
obj.setPassword(new String(tabSettings.getPassword()));
|
||||
obj.setIcon(Client.objectType.get(tabSettings.getObjType()).getId());
|
||||
obj.setSnmpProfile(Client.snmpProfile.get(tabSettings.getSnmpProfile()).getId());
|
||||
obj.setPing(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.isPing() || newObject) {
|
||||
obj.setStatus(Status.NA);
|
||||
}
|
||||
// ArrayList<SnmpProbe> probe = new ArrayList<>();
|
||||
// if (!newObject) {
|
||||
// probe.addAll(obj.getSnmpProbe());
|
||||
// }
|
||||
// obj.setSnmpProbe(probe);
|
||||
if (newObject) {
|
||||
NettyClientManager.sendMessage(new Message(Message.NODE_ADD, obj));
|
||||
dispose();
|
||||
} else {
|
||||
NettyClientManager.sendMessage(new Message(Message.NODE_CHANGE, obj));
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
});
|
||||
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) {
|
||||
SnmpProfile profile = Client.snmpProfile.get(tabSettings.getSnmpProfile());
|
||||
Object[] o = {tabSettings.getIp(), profile.getPort(), profile.getVersion(), profile.getCommunityRead(), getName()};
|
||||
NettyClientManager.sendMessage(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};
|
||||
NettyClientManager.sendMessage(Message.NODE_SNMP_INFO, data);
|
||||
NettyClientManager.sendMessage(Message.NODE_SNMP_INTERFACE, data);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
package jnet.client.gui.dialog.node;
|
||||
|
||||
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.lib.EventComparator;
|
||||
import jnet.lib.LogFile;
|
||||
import jnet.lib.Status;
|
||||
import jnet.lib.object.Event;
|
||||
import jnet.lib.object.Node;
|
||||
|
||||
public class TabEvents extends JPanel {
|
||||
|
||||
private Node obj;
|
||||
|
||||
public TabEvents(Node obj) {
|
||||
this.obj = obj;
|
||||
|
||||
String column[] = {"Začátek", "Konec", "Délka", "Stav"};
|
||||
DefaultTableModel tableModel = new DefaultTableModel(column, 0) {
|
||||
|
||||
@Override
|
||||
public boolean isCellEditable(int row, int column) {
|
||||
//all cells false
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
Collections.sort(Client.events, new EventComparator());
|
||||
Collections.reverse(Client.events);
|
||||
for (Event e : Client.events) {
|
||||
if (e.getNode()== obj.getId()) {
|
||||
Object[] d = {
|
||||
getDate(e.getStart()),
|
||||
getDate(e.getEnd()),
|
||||
getDuration(e.getStart(), e.getEnd()),
|
||||
Status.getStatusName(e.getStatus())};
|
||||
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 "";
|
||||
}
|
||||
|
||||
private String getDuration(long startTime, long endTime) {
|
||||
if (endTime != 0) {
|
||||
long difference = endTime - startTime;
|
||||
long seconds = difference / 1000;
|
||||
long minutes = difference / (1000 * 60);
|
||||
long hours = difference / (1000 * 60 * 60);
|
||||
return hours + "h " + minutes + "m " + seconds + "s";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,124 @@
|
|||
package jnet.client.gui.dialog.node;
|
||||
|
||||
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.lib.object.Interface;
|
||||
import jnet.lib.object.Node;
|
||||
|
||||
public class TabInfo extends JPanel {
|
||||
|
||||
private String frameName;
|
||||
private Node 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, Node 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
package jnet.client.gui.dialog.node;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.List;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.RowSorter;
|
||||
import javax.swing.SortOrder;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import javax.swing.table.TableRowSorter;
|
||||
import jnet.client.Client;
|
||||
import jnet.client.SnmpResponseParser;
|
||||
import jnet.lib.object.Node;
|
||||
import jnet.lib.object.NodeProbe;
|
||||
import jnet.lib.object.SnmpTemplate;
|
||||
import jnet.client.gui.dialog.DialogProbe;
|
||||
|
||||
public class TabProbes extends JPanel {
|
||||
|
||||
String COLUMN_NAMES[] = {"Nazev", "Hodota"};
|
||||
DefaultTableModel model;
|
||||
Node obj;
|
||||
|
||||
TabProbes(Node obj) {
|
||||
|
||||
this.obj = obj;
|
||||
|
||||
initTable();
|
||||
|
||||
}
|
||||
|
||||
private void initTable() {
|
||||
model = new DefaultTableModel(COLUMN_NAMES, 0) {
|
||||
@Override
|
||||
public boolean isCellEditable(int row, int column) {
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
JTable table = new JTable(model);
|
||||
table.setPreferredScrollableViewportSize(new Dimension(500, 350)); // Šířka 500, výška 300
|
||||
|
||||
JButton btn = new JButton("Přidat sondu");
|
||||
btn.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
new DialogProbe(new NodeProbe(), obj, true).show();
|
||||
}
|
||||
});
|
||||
|
||||
this.add(new JScrollPane(table));
|
||||
this.add(btn);
|
||||
|
||||
loadData();
|
||||
|
||||
}
|
||||
|
||||
private void loadData() {
|
||||
model.setRowCount(0);
|
||||
|
||||
if (obj.getProbe() != null) {
|
||||
for (NodeProbe probe : obj.getProbe()) {
|
||||
model.addRow(new Object[]{
|
||||
probe.getName(),
|
||||
SnmpResponseParser.parse(probe) + " V"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,191 @@
|
|||
package jnet.client.gui.dialog.node;
|
||||
|
||||
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.Node;
|
||||
|
||||
class TabServices extends JPanel {
|
||||
|
||||
private Node 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(Node 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", "BTH", "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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,205 @@
|
|||
package jnet.client.gui.dialog.node;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.DefaultComboBoxModel;
|
||||
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.lib.object.Node;
|
||||
import jnet.lib.object.ObjectType;
|
||||
import jnet.lib.object.SnmpProfile;
|
||||
|
||||
public class TabSettings extends JPanel {
|
||||
|
||||
private Node 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(Node 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("Ikona");
|
||||
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("Ping");
|
||||
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.getIcon()== 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.isPing());
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,127 @@
|
|||
package jnet.client.gui.maptree;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import jnet.client.Client;
|
||||
import jnet.client.gui.Window;
|
||||
import jnet.lib.LogFile;
|
||||
import jnet.lib.object.Site;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import javax.swing.tree.TreeSelectionModel;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import javax.imageio.ImageIO;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.ResourceLoader;
|
||||
import jnet.lib.MapComparator;
|
||||
|
||||
public class MapTree extends JTree {
|
||||
|
||||
private final DefaultTreeModel model;
|
||||
private final DefaultMutableTreeNode root = new DefaultMutableTreeNode("Mapy");
|
||||
|
||||
public MapTree() {
|
||||
setRootVisible(false);
|
||||
getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
|
||||
model = new DefaultTreeModel(root);
|
||||
setModel(model);
|
||||
setCellRenderer(new MapTreeCellRenderer());
|
||||
|
||||
addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
handleMouseEvent(e);
|
||||
}
|
||||
});
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
||||
private void handleMouseEvent(MouseEvent e) {
|
||||
DefaultMutableTreeNode node = (DefaultMutableTreeNode) getLastSelectedPathComponent();
|
||||
if (node == null) return;
|
||||
|
||||
if (SwingUtilities.isRightMouseButton(e)) {
|
||||
Object obj = node.getUserObject();
|
||||
getContextMenuMap(e, (Site) obj);
|
||||
} else if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2) {
|
||||
Object obj = node.getUserObject();
|
||||
if (obj instanceof Site) {
|
||||
SwingUtilities.invokeLater(() -> Window.setMapView((Site) obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Obnoví strom – načte aktuální seznam site z Client.site.
|
||||
* Ošetřeno pro případ, že Client.site je null.
|
||||
*/
|
||||
public void refresh() {
|
||||
root.removeAllChildren();
|
||||
|
||||
Collections.sort(Client.site, new MapComparator());
|
||||
|
||||
// OŠETŘENÍ: Client.site může být null při prvním spuštění
|
||||
if (Client.site != null) {
|
||||
for (Site site : Client.site) {
|
||||
root.add(new DefaultMutableTreeNode(site));
|
||||
}
|
||||
} else {
|
||||
LogFile.printInfo("MapTree: Client.site je null, strom zůstává prázdný.");
|
||||
}
|
||||
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
model.reload();
|
||||
expandAll();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Statická metoda pro obnovení stromu z jiných tříd.
|
||||
*/
|
||||
public static void refreshTree() {
|
||||
Window.getInstance().refreshMapTree();
|
||||
}
|
||||
|
||||
private void expandAll() {
|
||||
for (int i = 0; i < getRowCount(); i++) {
|
||||
expandRow(i);
|
||||
}
|
||||
}
|
||||
|
||||
private static void getContextMenuMap(MouseEvent e, Site m) {
|
||||
try {
|
||||
|
||||
JMenuItem mapDelete = new JMenuItem("Smazat mapu", new ImageIcon(ImageIO.read(ResourceLoader.getFile("/img/trash.png"))));
|
||||
mapDelete.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
int option = JOptionPane.showConfirmDialog(
|
||||
null,
|
||||
"Smazat mapu " + m.getName() + " a všechny její objekty ?",
|
||||
"Potvrzení akce",
|
||||
JOptionPane.YES_NO_OPTION
|
||||
);
|
||||
|
||||
if (option == JOptionPane.YES_OPTION) {
|
||||
Client.sendMessage(new Message(Message.SITE_DELETE, m.getId()));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
JPopupMenu menu = new JPopupMenu();
|
||||
if (Client.user.isRemoveMap()) {
|
||||
menu.add(mapDelete);
|
||||
}
|
||||
menu.show(e.getComponent(), e.getX(), e.getY());
|
||||
} catch (IOException ex) {
|
||||
LogFile.printErr("MapTree error: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
package jnet.client.gui.maptree;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JTree;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.DefaultTreeCellRenderer;
|
||||
import jnet.lib.ResourceLoader;
|
||||
import jnet.lib.Status;
|
||||
import jnet.lib.object.Site;
|
||||
|
||||
public class MapTreeCellRenderer extends DefaultTreeCellRenderer {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(MapTreeCellRenderer.class.getName());
|
||||
private static final Map<Integer, ImageIcon> iconCache = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public Component getTreeCellRendererComponent(JTree tree, Object value,
|
||||
boolean selected, boolean expanded,
|
||||
boolean leaf, int row, boolean hasFocus) {
|
||||
JLabel label = (JLabel) super.getTreeCellRendererComponent(
|
||||
tree, value, selected, expanded, leaf, row, hasFocus);
|
||||
|
||||
DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
|
||||
Object o = node.getUserObject();
|
||||
|
||||
if (o instanceof Site) {
|
||||
Site site = (Site) o;
|
||||
ImageIcon icon = loadIconForState(site.getSiteState());
|
||||
label.setIcon(icon);
|
||||
label.setText(site.getName());
|
||||
} else {
|
||||
label.setText(o != null ? o.toString() : "");
|
||||
label.setIcon(null);
|
||||
}
|
||||
|
||||
label.setBorder(new EmptyBorder(7, 25, 3, 3));
|
||||
return label;
|
||||
}
|
||||
|
||||
private ImageIcon loadIconForState(int state) {
|
||||
return iconCache.computeIfAbsent(state, key -> {
|
||||
String filename;
|
||||
switch (key) {
|
||||
case Status.OK:
|
||||
filename = "img/flag_green.png";
|
||||
break;
|
||||
case Status.WARNING:
|
||||
filename = "img/flag_orange.png";
|
||||
break;
|
||||
case Status.OFFLINE:
|
||||
filename = "img/flag_red.png";
|
||||
break;
|
||||
default:
|
||||
filename = "img/flag_gray.png";
|
||||
}
|
||||
try {
|
||||
BufferedImage img = ImageIO.read(ResourceLoader.getFile(filename));
|
||||
return img != null ? new ImageIcon(img) : null;
|
||||
} catch (IOException e) {
|
||||
LOG.log(Level.SEVERE, "Failed to load icon: " + filename, e);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package jnet.client.gui.mapview;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.geom.Line2D;
|
||||
|
||||
public class Connection {
|
||||
private PaintSiteObject source;
|
||||
private PaintSiteObject target;
|
||||
private Color color = Color.BLACK;
|
||||
|
||||
public Connection(PaintSiteObject source, PaintSiteObject target) {
|
||||
this.source = source;
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public void draw(Graphics2D g2) {
|
||||
if (source == null || target == null) return;
|
||||
Point p1 = source.getCenter();
|
||||
Point p2 = target.getCenter();
|
||||
g2.setColor(color);
|
||||
g2.setStroke(new BasicStroke(2));
|
||||
g2.draw(new Line2D.Double(p1, p2));
|
||||
}
|
||||
|
||||
// Gettery a settery
|
||||
public PaintSiteObject getSource() { return source; }
|
||||
public PaintSiteObject getTarget() { return target; }
|
||||
public void setColor(Color color) { this.color = color; }
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
package jnet.client.gui.mapview;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.Stroke;
|
||||
import java.awt.geom.RoundRectangle2D;
|
||||
import jnet.lib.object.Node;
|
||||
|
||||
public class DeviceNodeRenderer implements NodeRenderer {
|
||||
|
||||
private static final int ARC = 10;
|
||||
private static final Stroke THIN_STROKE = new BasicStroke(1.0f);
|
||||
|
||||
@Override
|
||||
public void paint(Graphics2D g2, NodeView nodeView) {
|
||||
Node node = nodeView.getNode();
|
||||
int cx = nodeView.getCenterX();
|
||||
int cy = nodeView.getCenterY();
|
||||
int w = nodeView.getWidth();
|
||||
int h = nodeView.getHeight();
|
||||
|
||||
RoundRectangle2D shape = new RoundRectangle2D.Double(cx - w/2, cy - h/2, w, h, ARC, ARC);
|
||||
|
||||
// Pozadí
|
||||
g2.setColor(getStatusColor(node.getStatus()));
|
||||
g2.fill(shape);
|
||||
|
||||
// Tenké ohraničení
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.setStroke(THIN_STROKE);
|
||||
g2.draw(shape);
|
||||
|
||||
// Ikona
|
||||
Image icon = nodeView.getIcon();
|
||||
int imgY = (int) shape.getY() + 8; // větší horní odstup
|
||||
int iconHeight = 0;
|
||||
if (icon != null) {
|
||||
int imgX = (int) (shape.getX() + (w - icon.getWidth(null)) / 2);
|
||||
g2.drawImage(icon, imgX, imgY, null);
|
||||
iconHeight = icon.getHeight(null);
|
||||
imgY += iconHeight + 8; // větší mezera mezi ikonou a textem
|
||||
}
|
||||
|
||||
// ZMĚNA: text + sondy pomocí nové metody
|
||||
int textStartY = imgY + 2;
|
||||
TextUtils.drawNodeInfo(g2, node, cx, textStartY,
|
||||
nodeView.getFontMetricsBold(),
|
||||
nodeView.getFontMetricsNormal());
|
||||
}
|
||||
|
||||
private Color getStatusColor(int status) {
|
||||
switch (status) {
|
||||
case 1: return new Color(83, 241, 83);
|
||||
case 2: return new Color(255, 131, 0);
|
||||
case 3: return new Color(221, 63, 63);
|
||||
default: return new Color(172, 172, 172);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,179 @@
|
|||
package jnet.client.gui.mapview;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.RenderingHints;
|
||||
import jnet.lib.object.NodeConnection;
|
||||
|
||||
public class EdgeView {
|
||||
|
||||
private final NodeView source;
|
||||
private final NodeView target;
|
||||
private final NodeConnection connection;
|
||||
private boolean selected = false;
|
||||
|
||||
private static final Font TRAFFIC_FONT = new Font("Arial", Font.PLAIN, 10);
|
||||
|
||||
public EdgeView(NodeView source, NodeView target) {
|
||||
this(source, target, null);
|
||||
}
|
||||
|
||||
public EdgeView(NodeView source, NodeView target, NodeConnection connection) {
|
||||
this.source = source;
|
||||
this.target = target;
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
public void paint(Graphics2D g2) {
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2.setColor(selected ? Color.BLUE : Color.DARK_GRAY);
|
||||
g2.setStroke(new BasicStroke(2.0f));
|
||||
|
||||
int x1 = source.getCenterX();
|
||||
int y1 = source.getCenterY();
|
||||
int x2 = target.getCenterX();
|
||||
int y2 = target.getCenterY();
|
||||
|
||||
g2.drawLine(x1, y1, x2, y2);
|
||||
|
||||
// Zobrazení traffic informací, pokud je spojení označeno pro čtení
|
||||
if (connection != null && connection.isReadTraffic()) {
|
||||
int mx = (x1 + x2) / 2;
|
||||
int my = (y1 + y2) / 2;
|
||||
|
||||
String rxText = "RX: " + formatTrafficBytesToBits(connection.getRx());
|
||||
String txText = "TX: " + formatTrafficBytesToBits(connection.getTx());
|
||||
|
||||
g2.setFont(TRAFFIC_FONT);
|
||||
FontMetrics fm = g2.getFontMetrics();
|
||||
int rxWidth = fm.stringWidth(rxText);
|
||||
int txWidth = fm.stringWidth(txText);
|
||||
int textWidth = Math.max(rxWidth, txWidth);
|
||||
int textHeight = fm.getHeight();
|
||||
int padding = 4;
|
||||
|
||||
int rectWidth = textWidth + 2 * padding;
|
||||
int rectHeight = 2 * textHeight + padding + 4;
|
||||
int rectX = mx - rectWidth / 2;
|
||||
int rectY = my - rectHeight / 2;
|
||||
|
||||
// Plně bílé pozadí bez ohraničení
|
||||
g2.setColor(Color.WHITE);
|
||||
g2.fillRoundRect(rectX, rectY, rectWidth, rectHeight, 6, 6);
|
||||
|
||||
// Text – oba řádky horizontálně vycentrované
|
||||
g2.setColor(Color.BLACK);
|
||||
int yOffset = rectY + fm.getAscent() + padding;
|
||||
g2.drawString(rxText, rectX + (rectWidth - rxWidth) / 2, yOffset);
|
||||
g2.drawString(txText, rectX + (rectWidth - txWidth) / 2, yOffset + textHeight + 2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formátuje přenosovou rychlost v bytech za sekundu (B/s) do formátu jako
|
||||
* The Dude (bps s dekadickými jednotkami).
|
||||
*/
|
||||
private String formatTrafficBytesToBits(long bytesPerSecond) {
|
||||
long bps = bytesPerSecond * 8; // převod B/s → bps
|
||||
return formatTrafficBits(bps);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formátuje přenosovou rychlost v bitech za sekundu (bps) do čitelného
|
||||
* formátu s dekadickými jednotkami (1000) jako The Dude.
|
||||
*
|
||||
* @param bps Rychlost v bitech za sekundu (bits per second)
|
||||
* @return Formátovaný řetězec např. "436 Mbps", "28.8 Mbps", "4.2 Gbps"
|
||||
*/
|
||||
private String formatTrafficBits(long bps) {
|
||||
if (bps < 0) {
|
||||
return "0 bps";
|
||||
}
|
||||
|
||||
if (bps < 1_000) {
|
||||
return bps + " bps";
|
||||
}
|
||||
|
||||
double kbps = bps / 1_000.0;
|
||||
if (kbps < 1_000) {
|
||||
return formatDecimal(kbps) + " Kbps";
|
||||
}
|
||||
|
||||
double mbps = kbps / 1_000.0;
|
||||
if (mbps < 1_000) {
|
||||
return formatDecimal(mbps) + " Mbps";
|
||||
}
|
||||
|
||||
double gbps = mbps / 1_000.0;
|
||||
if (gbps < 1_000) {
|
||||
return formatDecimal(gbps) + " Gbps";
|
||||
}
|
||||
|
||||
double tbps = gbps / 1_000.0;
|
||||
return formatDecimal(tbps) + " Tbps";
|
||||
}
|
||||
|
||||
/**
|
||||
* Formátuje desetinné číslo s rozumným počtem desetinných míst. Pro The
|
||||
* Dude styl: 1 desetinné místo pro Mbps, celé pro Kbps.
|
||||
*/
|
||||
private String formatDecimal(double value) {
|
||||
if (value >= 100) {
|
||||
return String.format("%.0f", value);
|
||||
} else if (value >= 10) {
|
||||
return String.format("%.1f", value);
|
||||
} else {
|
||||
return String.format("%.1f", value);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSelected() {
|
||||
return selected;
|
||||
}
|
||||
|
||||
public void setSelected(boolean selected) {
|
||||
this.selected = selected;
|
||||
}
|
||||
|
||||
public NodeView getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public NodeView getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public NodeConnection getConnection() {
|
||||
return connection;
|
||||
}
|
||||
|
||||
public boolean contains(Point p, int threshold) {
|
||||
int x1 = source.getCenterX();
|
||||
int y1 = source.getCenterY();
|
||||
int x2 = target.getCenterX();
|
||||
int y2 = target.getCenterY();
|
||||
double dist = distanceToSegment(p.x, p.y, x1, y1, x2, y2);
|
||||
return dist <= threshold;
|
||||
}
|
||||
|
||||
private double distanceToSegment(int px, int py, int x1, int y1, int x2, int y2) {
|
||||
double vx = x2 - x1;
|
||||
double vy = y2 - y1;
|
||||
double dx = px - x1;
|
||||
double dy = py - y1;
|
||||
double t = (dx * vx + dy * vy) / (vx * vx + vy * vy);
|
||||
if (t < 0) {
|
||||
t = 0;
|
||||
}
|
||||
if (t > 1) {
|
||||
t = 1;
|
||||
}
|
||||
double projX = x1 + t * vx;
|
||||
double projY = y1 + t * vy;
|
||||
return Math.hypot(px - projX, py - projY);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,207 @@
|
|||
package jnet.client.gui.mapview;
|
||||
|
||||
import jnet.lib.object.Node;
|
||||
import jnet.lib.object.NodeConnection;
|
||||
import jnet.lib.object.Site;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Datový model mapy – spravuje seznamy uzlů, hran a výběr.
|
||||
*/
|
||||
public class MapModel {
|
||||
|
||||
private final List<NodeView> nodeViews = new ArrayList<>();
|
||||
private final List<EdgeView> edgeViews = new ArrayList<>();
|
||||
private final Set<NodeView> selectedNodes = new HashSet<>();
|
||||
private final Set<EdgeView> selectedEdges = new HashSet<>();
|
||||
|
||||
private Site site;
|
||||
private MapView mapView; // ← reference pro konstruktor NodeView
|
||||
private Runnable onChange;
|
||||
|
||||
public MapModel(Site site, MapView mapView) {
|
||||
this.site = site;
|
||||
this.mapView = mapView;
|
||||
}
|
||||
|
||||
public void setOnChange(Runnable onChange) {
|
||||
this.onChange = onChange;
|
||||
}
|
||||
|
||||
private void fireChange() {
|
||||
if (onChange != null) onChange.run();
|
||||
}
|
||||
|
||||
// ---------- Inicializace ----------
|
||||
public void initFromSite() {
|
||||
nodeViews.clear();
|
||||
edgeViews.clear();
|
||||
selectedNodes.clear();
|
||||
selectedEdges.clear();
|
||||
|
||||
for (Node node : site.getNode()) {
|
||||
nodeViews.add(new NodeView(node, mapView));
|
||||
}
|
||||
|
||||
for (NodeConnection nc : site.getNodeConnection()) {
|
||||
NodeView source = findNodeViewById(nc.getNodeFrom());
|
||||
NodeView target = findNodeViewById(nc.getNodeTo());
|
||||
if (source != null && target != null) {
|
||||
boolean exists = edgeViews.stream().anyMatch(e ->
|
||||
(e.getSource() == source && e.getTarget() == target) ||
|
||||
(e.getSource() == target && e.getTarget() == source)
|
||||
);
|
||||
if (!exists) {
|
||||
// NOVÉ – předáváme i NodeConnection
|
||||
edgeViews.add(new EdgeView(source, target, nc));
|
||||
}
|
||||
}
|
||||
}
|
||||
fireChange();
|
||||
}
|
||||
|
||||
// ---------- Vyhledávání ----------
|
||||
public NodeView findNodeViewById(int nodeId) {
|
||||
return nodeViews.stream()
|
||||
.filter(nv -> nv.getNode().getId() == nodeId)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public NodeView findNodeAt(Point p) {
|
||||
for (int i = nodeViews.size() - 1; i >= 0; i--) {
|
||||
NodeView nv = nodeViews.get(i);
|
||||
if (nv.contains(p)) return nv;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public EdgeView findEdgeAt(Point p, int threshold) {
|
||||
return edgeViews.stream()
|
||||
.filter(e -> e.contains(p, threshold))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
// ---------- Správa uzlů a hran ----------
|
||||
public void addNode(NodeView nodeView) {
|
||||
nodeViews.add(nodeView);
|
||||
fireChange();
|
||||
}
|
||||
|
||||
public void addEdge(EdgeView edgeView) {
|
||||
edgeViews.add(edgeView);
|
||||
fireChange();
|
||||
}
|
||||
|
||||
public void removeNode(NodeView nodeView) {
|
||||
edgeViews.removeIf(e -> e.getSource() == nodeView || e.getTarget() == nodeView);
|
||||
nodeViews.remove(nodeView);
|
||||
selectedNodes.remove(nodeView);
|
||||
fireChange();
|
||||
}
|
||||
|
||||
public void removeEdge(EdgeView edgeView) {
|
||||
edgeViews.remove(edgeView);
|
||||
selectedEdges.remove(edgeView);
|
||||
fireChange();
|
||||
}
|
||||
|
||||
public void deleteSelected() {
|
||||
for (NodeView n : new ArrayList<>(selectedNodes)) {
|
||||
removeNode(n);
|
||||
}
|
||||
for (EdgeView e : new ArrayList<>(selectedEdges)) {
|
||||
removeEdge(e);
|
||||
}
|
||||
fireChange();
|
||||
}
|
||||
|
||||
// ---------- Správa výběru ----------
|
||||
public void selectNode(NodeView nv) {
|
||||
if (nv != null && !selectedNodes.contains(nv)) {
|
||||
selectedNodes.add(nv);
|
||||
nv.setSelected(true);
|
||||
fireChange();
|
||||
}
|
||||
}
|
||||
|
||||
public void deselectNode(NodeView nv) {
|
||||
if (nv != null && selectedNodes.contains(nv)) {
|
||||
selectedNodes.remove(nv);
|
||||
nv.setSelected(false);
|
||||
fireChange();
|
||||
}
|
||||
}
|
||||
|
||||
public void toggleNode(NodeView nv) {
|
||||
if (selectedNodes.contains(nv)) deselectNode(nv);
|
||||
else selectNode(nv);
|
||||
}
|
||||
|
||||
public void selectEdge(EdgeView ev) {
|
||||
if (ev != null && !selectedEdges.contains(ev)) {
|
||||
selectedEdges.add(ev);
|
||||
ev.setSelected(true);
|
||||
fireChange();
|
||||
}
|
||||
}
|
||||
|
||||
public void deselectEdge(EdgeView ev) {
|
||||
if (ev != null && selectedEdges.contains(ev)) {
|
||||
selectedEdges.remove(ev);
|
||||
ev.setSelected(false);
|
||||
fireChange();
|
||||
}
|
||||
}
|
||||
|
||||
public void toggleEdge(EdgeView ev) {
|
||||
if (selectedEdges.contains(ev)) deselectEdge(ev);
|
||||
else selectEdge(ev);
|
||||
}
|
||||
|
||||
public void clearSelection() {
|
||||
for (NodeView nv : new ArrayList<>(selectedNodes)) {
|
||||
nv.setSelected(false);
|
||||
}
|
||||
for (EdgeView ev : new ArrayList<>(selectedEdges)) {
|
||||
ev.setSelected(false);
|
||||
}
|
||||
selectedNodes.clear();
|
||||
selectedEdges.clear();
|
||||
fireChange();
|
||||
}
|
||||
|
||||
// ---------- Gettery ----------
|
||||
public List<NodeView> getNodeViews() {
|
||||
return Collections.unmodifiableList(nodeViews);
|
||||
}
|
||||
|
||||
public List<EdgeView> getEdgeViews() {
|
||||
return Collections.unmodifiableList(edgeViews);
|
||||
}
|
||||
|
||||
public Set<NodeView> getSelectedNodes() {
|
||||
return Collections.unmodifiableSet(selectedNodes);
|
||||
}
|
||||
|
||||
public Set<EdgeView> getSelectedEdges() {
|
||||
return Collections.unmodifiableSet(selectedEdges);
|
||||
}
|
||||
|
||||
public Site getSite() {
|
||||
return site;
|
||||
}
|
||||
|
||||
public void setSite(Site site) {
|
||||
this.site = site;
|
||||
initFromSite();
|
||||
}
|
||||
|
||||
public MapView getMapView() {
|
||||
return mapView;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,283 @@
|
|||
package jnet.client.gui.mapview;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import javax.swing.JOptionPane;
|
||||
import jnet.client.client.NettyClientManager;
|
||||
import jnet.client.gui.dialog.ConnectionDialog;
|
||||
import jnet.client.gui.dialog.node.NodeDeviceDialog;
|
||||
import jnet.client.gui.dialog.NodeStaticDialog;
|
||||
import jnet.lib.LogFile;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.Node;
|
||||
import jnet.lib.object.NodeConnection;
|
||||
|
||||
public class MapMouseHandler implements MouseListener, MouseMotionListener, MouseWheelListener {
|
||||
|
||||
private static final int EDGE_THRESHOLD = 8;
|
||||
|
||||
private final MapModel model;
|
||||
private final Runnable repainter;
|
||||
private final MapView mapView;
|
||||
|
||||
private Point dragStart = null;
|
||||
private Point lastMousePos = null;
|
||||
private Rectangle selectionRect = null;
|
||||
private boolean isDragging = false;
|
||||
private boolean isSelecting = false;
|
||||
|
||||
private Set<Integer> draggedNodeIds = new HashSet<>();
|
||||
private Map<Integer, Point> startPositions = new HashMap<>();
|
||||
|
||||
public MapMouseHandler(MapModel model, Runnable repainter, MapView mapView) {
|
||||
this.model = model;
|
||||
this.repainter = repainter;
|
||||
this.mapView = mapView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
dragStart = e.getPoint();
|
||||
lastMousePos = e.getPoint();
|
||||
|
||||
draggedNodeIds.clear();
|
||||
startPositions.clear();
|
||||
|
||||
NodeView clickedNode = model.findNodeAt(dragStart);
|
||||
EdgeView clickedEdge = (clickedNode == null) ? model.findEdgeAt(dragStart, EDGE_THRESHOLD) : null;
|
||||
|
||||
boolean isLocked = model.getSite().isLock();
|
||||
|
||||
if (clickedNode != null) {
|
||||
if (e.isControlDown() || e.isShiftDown()) {
|
||||
model.toggleNode(clickedNode);
|
||||
} else {
|
||||
if (!model.getSelectedNodes().contains(clickedNode)) {
|
||||
model.clearSelection();
|
||||
model.selectNode(clickedNode);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isLocked) {
|
||||
for (NodeView nv : model.getSelectedNodes()) {
|
||||
int nodeId = nv.getNode().getId();
|
||||
draggedNodeIds.add(nodeId);
|
||||
startPositions.put(nodeId, new Point(nv.getCenterX(), nv.getCenterY()));
|
||||
}
|
||||
isDragging = true;
|
||||
} else {
|
||||
isDragging = false;
|
||||
LogFile.printDebug("MapMouseHandler: Site je zamcena, pretahovani zakazano");
|
||||
}
|
||||
isSelecting = false;
|
||||
|
||||
} else if (clickedEdge != null) {
|
||||
if (e.isControlDown() || e.isShiftDown()) {
|
||||
model.toggleEdge(clickedEdge);
|
||||
} else {
|
||||
model.clearSelection();
|
||||
model.selectEdge(clickedEdge);
|
||||
}
|
||||
isDragging = false;
|
||||
isSelecting = false;
|
||||
|
||||
} else {
|
||||
if (!e.isControlDown() && !e.isShiftDown()) {
|
||||
model.clearSelection();
|
||||
draggedNodeIds.clear();
|
||||
startPositions.clear();
|
||||
}
|
||||
selectionRect = new Rectangle(dragStart);
|
||||
isSelecting = true;
|
||||
isDragging = false;
|
||||
}
|
||||
repainter.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
boolean isLocked = model.getSite().isLock();
|
||||
|
||||
if (isDragging && !isLocked) {
|
||||
Set<NodeView> currentSelection = model.getSelectedNodes();
|
||||
|
||||
for (NodeView nv : currentSelection) {
|
||||
int nodeId = nv.getNode().getId();
|
||||
if (draggedNodeIds.contains(nodeId)) {
|
||||
Node node = nv.getNode();
|
||||
Point startPos = startPositions.get(nodeId);
|
||||
if (startPos != null && (startPos.x != node.getX() || startPos.y != node.getY())) {
|
||||
LogFile.printDebug("Posun uzlu " + node.getName() + " (ID=" + nodeId
|
||||
+ ") na [" + node.getX() + ", " + node.getY() + "]");
|
||||
int[] data = {node.getId(), node.getX(), node.getY()};
|
||||
NettyClientManager.sendMessage(new Message(Message.NODE_POSITION_CHANGE, data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
isDragging = false;
|
||||
draggedNodeIds.clear();
|
||||
startPositions.clear();
|
||||
repainter.run();
|
||||
}
|
||||
|
||||
if (isSelecting && selectionRect != null) {
|
||||
Rectangle rect = selectionRect;
|
||||
for (NodeView nv : model.getNodeViews()) {
|
||||
if (rect.intersects(nv.getBounds())) {
|
||||
model.selectNode(nv);
|
||||
}
|
||||
}
|
||||
selectionRect = null;
|
||||
isSelecting = false;
|
||||
repainter.run();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
if (model.getSite().isLock()) {
|
||||
if (isSelecting && selectionRect != null) {
|
||||
Point current = e.getPoint();
|
||||
selectionRect = new Rectangle(
|
||||
Math.min(dragStart.x, current.x),
|
||||
Math.min(dragStart.y, current.y),
|
||||
Math.abs(current.x - dragStart.x),
|
||||
Math.abs(current.y - dragStart.y)
|
||||
);
|
||||
repainter.run();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Point current = e.getPoint();
|
||||
|
||||
if (isDragging && !draggedNodeIds.isEmpty()) {
|
||||
Set<NodeView> currentSelection = model.getSelectedNodes();
|
||||
|
||||
List<NodeView> nodesToDrag = new ArrayList<>();
|
||||
for (NodeView nv : currentSelection) {
|
||||
if (draggedNodeIds.contains(nv.getNode().getId())) {
|
||||
nodesToDrag.add(nv);
|
||||
}
|
||||
}
|
||||
|
||||
if (nodesToDrag.isEmpty()) {
|
||||
LogFile.printDebug("MapMouseHandler: Zbyly 0 uzlu k pretazeni, ukoncuji drag");
|
||||
isDragging = false;
|
||||
draggedNodeIds.clear();
|
||||
startPositions.clear();
|
||||
repainter.run();
|
||||
return;
|
||||
}
|
||||
|
||||
int dx = current.x - lastMousePos.x;
|
||||
int dy = current.y - lastMousePos.y;
|
||||
for (NodeView nv : nodesToDrag) {
|
||||
nv.translate(dx, dy);
|
||||
}
|
||||
|
||||
lastMousePos = current;
|
||||
repainter.run();
|
||||
return;
|
||||
}
|
||||
|
||||
if (isSelecting && selectionRect != null) {
|
||||
selectionRect = new Rectangle(
|
||||
Math.min(dragStart.x, current.x),
|
||||
Math.min(dragStart.y, current.y),
|
||||
Math.abs(current.x - dragStart.x),
|
||||
Math.abs(current.y - dragStart.y)
|
||||
);
|
||||
repainter.run();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
lastMousePos = e.getPoint();
|
||||
|
||||
if (model.getSite().isLock()) {
|
||||
NodeView nv = model.findNodeAt(e.getPoint());
|
||||
if (nv != null) {
|
||||
e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
} else {
|
||||
e.getComponent().setCursor(Cursor.getDefaultCursor());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
// Režim umístění uzlu
|
||||
if (mapView.isWaitingForPlacement()) {
|
||||
if (e.getButton() == MouseEvent.BUTTON1) {
|
||||
mapView.placeNodeAt(e.getPoint());
|
||||
} else if (e.getButton() == MouseEvent.BUTTON3) {
|
||||
mapView.cancelNodePlacement();
|
||||
JOptionPane.showMessageDialog(mapView, "Přesun zrušen.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.getClickCount() == 2) {
|
||||
NodeView nv = model.findNodeAt(e.getPoint());
|
||||
if (nv != null) {
|
||||
Node node = nv.getNode();
|
||||
switch (node.getType()) {
|
||||
case Node.NODE_DEVICE -> {
|
||||
LogFile.printDebug("MapMouseHandler: Dvojklik na uzel " + node.getName());
|
||||
NodeDeviceDialog dialog = new NodeDeviceDialog(nv.getNode(), false);
|
||||
dialog.show();
|
||||
}
|
||||
case Node.NODE_MAP -> {
|
||||
int targetSiteId = node.getSiteLink();
|
||||
if (targetSiteId > 0 && mapView != null) {
|
||||
mapView.switchToSite(targetSiteId);
|
||||
} else {
|
||||
LogFile.printDebug("MapMouseHandler: Node typu mapa nemá nastaveno ID cílové site.");
|
||||
}
|
||||
}
|
||||
case Node.NODE_STATIC -> {
|
||||
NodeStaticDialog snd = new NodeStaticDialog(nv.getNode(), false);
|
||||
snd.show();
|
||||
}
|
||||
default -> {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Dvojklik na spojení (hranu)
|
||||
EdgeView ev = model.findEdgeAt(e.getPoint(), EDGE_THRESHOLD);
|
||||
if (ev != null) {
|
||||
// NOVÉ – získáme celý NodeConnection
|
||||
NodeConnection conn = ev.getConnection();
|
||||
if (conn != null) {
|
||||
|
||||
// Můžete zde také otevřít dialog pro úpravu spojení, např.:
|
||||
new ConnectionDialog(conn, false).show();
|
||||
} else {
|
||||
LogFile.printDebug("MapMouseHandler: EdgeView nemá přiřazený NodeConnection");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseWheelMoved(MouseWheelEvent e) {
|
||||
}
|
||||
|
||||
public Rectangle getSelectionRect() {
|
||||
return selectionRect;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package jnet.client.gui.mapview;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Stroke;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
|
||||
public class MapNodeRenderer implements NodeRenderer {
|
||||
|
||||
private static final Stroke THIN_STROKE = new BasicStroke(1.0f);
|
||||
|
||||
@Override
|
||||
public void paint(Graphics2D g2, NodeView nodeView) {
|
||||
int cx = nodeView.getCenterX();
|
||||
int cy = nodeView.getCenterY();
|
||||
int w = nodeView.getWidth();
|
||||
int h = nodeView.getHeight();
|
||||
|
||||
Ellipse2D oval = new Ellipse2D.Double(cx - w/2, cy - h/2, w, h);
|
||||
g2.setColor(new Color(173, 216, 230));
|
||||
g2.fill(oval);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.setStroke(THIN_STROKE);
|
||||
g2.draw(oval);
|
||||
|
||||
TextUtils.drawCenteredText(g2,
|
||||
nodeView.getNode().getName(),
|
||||
nodeView.getNode().getIp(),
|
||||
cx, cy,
|
||||
nodeView.getFontMetricsBold(),
|
||||
nodeView.getFontMetricsNormal());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,205 @@
|
|||
package jnet.client.gui.mapview;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionListener;
|
||||
import jnet.client.Client;
|
||||
import jnet.client.client.NettyClientManager;
|
||||
import jnet.client.gui.dialog.ConnectionDialog;
|
||||
import jnet.client.gui.dialog.NodeChangeSite;
|
||||
import jnet.client.gui.dialog.node.NodeDeviceDialog;
|
||||
import jnet.client.gui.dialog.NodeStaticDialog;
|
||||
import jnet.client.gui.dialog.NodeMapLinkDialog;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.Site;
|
||||
import jnet.lib.object.Node;
|
||||
import jnet.lib.object.NodeConnection;
|
||||
|
||||
public class MapPopupMenu {
|
||||
|
||||
private final MapModel model;
|
||||
private final Component parent;
|
||||
private final Runnable refresher;
|
||||
|
||||
private JPopupMenu popupMenu;
|
||||
private Point lastMousePos = new Point(0, 0);
|
||||
private NodeView clickedNode = null;
|
||||
private EdgeView clickedEdge = null; // NOVÉ
|
||||
|
||||
public MapPopupMenu(MapModel model, Component parent, Runnable refresher) {
|
||||
this.model = model;
|
||||
this.parent = parent;
|
||||
this.refresher = refresher;
|
||||
this.popupMenu = new JPopupMenu();
|
||||
}
|
||||
|
||||
// UPRAVENO – přidán parametr EdgeView
|
||||
public void show(Component invoker, int x, int y, NodeView node, EdgeView edge) {
|
||||
this.lastMousePos = new Point(x, y);
|
||||
this.clickedNode = node;
|
||||
this.clickedEdge = edge;
|
||||
buildMenu(node != null, edge != null);
|
||||
popupMenu.show(invoker, x, y);
|
||||
}
|
||||
|
||||
// UPRAVENO – rozlišuje hasNode a hasEdge
|
||||
private void buildMenu(boolean hasNode, boolean hasEdge) {
|
||||
popupMenu.removeAll();
|
||||
|
||||
// 1) Kliknutí na SPOJENÍ
|
||||
if (hasEdge) {
|
||||
addItem("Smazat spojení", e -> deleteEdge(clickedEdge));
|
||||
addItem("Upravit spojení", e -> editEdge(clickedEdge));
|
||||
return; // menu pro spojení je samostatné
|
||||
}
|
||||
|
||||
// 2) Kliknutí na UZEL
|
||||
if (hasNode) {
|
||||
Node node = clickedNode.getNode();
|
||||
if (node.isWinbox()) {
|
||||
addItem("Winbox", e -> Client.remoteTools.openWinbox(node.getIp() + ":" + node.getWinboxPort(), node.getUser(), node.getPassword()));
|
||||
}
|
||||
if (node.isWeb()) {
|
||||
addItem("Prohlížeč", e -> Client.remoteTools.openBrowser(node.getIp(), node.getWebPort(), node.getWebVerze()));
|
||||
}
|
||||
if (node.isSsh()) {
|
||||
addItem("SSH", e -> Client.remoteTools.openPuttySSH(node.getIp(), node.getSshPort(), node.getUser(), node.getPassword()));
|
||||
}
|
||||
if (node.isTelnet()) {
|
||||
addItem("Telnet", e -> Client.remoteTools.openPuttyTelnet(node.getIp(), node.getTelnetPort()));
|
||||
}
|
||||
if (node.isSms()) {
|
||||
addItem("SMS (Summit)", e -> Client.remoteTools.openSMS(node.getIp(), node.getSmsPort(), node.getPassword(), node.getSmsVerze()));
|
||||
}
|
||||
if (!model.getSite().isLock()) {
|
||||
if (node.isWinbox() || node.isWeb() || node.isSsh() || node.isTelnet() || node.isSms()) {
|
||||
popupMenu.addSeparator();
|
||||
}
|
||||
addItem("Přesunout na jinou mapu", e -> {
|
||||
if (parent instanceof MapView) {
|
||||
new NodeChangeSite(node, (MapView) parent).show();
|
||||
} else {
|
||||
new NodeChangeSite(node).show();
|
||||
}
|
||||
});
|
||||
addItem("Smazat", e -> deleteNode(clickedNode));
|
||||
addItem("Zrušit výběr", e -> model.clearSelection());
|
||||
addItem("Přidat spojení", e -> startEdgeCreation());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 3) Kliknutí na PRÁZDNOU PLOCHU
|
||||
if (model.getSite().isLock()) {
|
||||
addItem("Odemknout mapu", e -> mapLock(model.getSite()));
|
||||
} else {
|
||||
addItem("Zamknout mapu", e -> mapLock(model.getSite()));
|
||||
addItem("Přidat zařízení", e -> showDeviceDialog(lastMousePos));
|
||||
addItem("Přidat statický object", e -> showStaticDialog(lastMousePos));
|
||||
addItem("Přidat odkaz na mapu", e -> showMapLinkDialog(lastMousePos));
|
||||
popupMenu.addSeparator();
|
||||
addItem("Smazat vybrané", e -> model.deleteSelected());
|
||||
addItem("Zrušit výběr", e -> model.clearSelection());
|
||||
}
|
||||
}
|
||||
|
||||
private void addItem(String text, ActionListener listener) {
|
||||
JMenuItem item = new JMenuItem(text);
|
||||
item.addActionListener(listener);
|
||||
popupMenu.add(item);
|
||||
}
|
||||
|
||||
// ---------- Akce pro prázdnou plochu ----------
|
||||
private void showDeviceDialog(Point location) {
|
||||
int siteId = model.getSite().getId();
|
||||
Node obj = new Node();
|
||||
obj.setX(location.x);
|
||||
obj.setY(location.y);
|
||||
obj.setSiteId(siteId);
|
||||
NodeDeviceDialog dialog = new NodeDeviceDialog(obj, true);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private void showStaticDialog(Point location) {
|
||||
int siteId = model.getSite().getId();
|
||||
Node obj = new Node();
|
||||
obj.setX(location.x);
|
||||
obj.setY(location.y);
|
||||
obj.setSiteId(siteId);
|
||||
NodeStaticDialog dialog = new NodeStaticDialog(obj, true);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private void showMapLinkDialog(Point location) {
|
||||
int siteId = model.getSite().getId();
|
||||
Node obj = new Node();
|
||||
obj.setX(location.x);
|
||||
obj.setY(location.y);
|
||||
obj.setSiteId(siteId);
|
||||
NodeMapLinkDialog dialog = new NodeMapLinkDialog(obj, true);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private void startEdgeCreation() {
|
||||
if (model.getSelectedNodes().size() >= 2) {
|
||||
var it = model.getSelectedNodes().iterator();
|
||||
NodeView src = it.next();
|
||||
NodeView tgt = it.next();
|
||||
EdgeView ev = new EdgeView(src, tgt);
|
||||
model.addEdge(ev);
|
||||
NodeConnection nc = new NodeConnection();
|
||||
nc.setNodeFrom(src.getNode().getId());
|
||||
nc.setNodeTo(tgt.getNode().getId());
|
||||
new ConnectionDialog(nc, true).show();
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(parent, "Vyberte alespoň dva uzly pro vytvoření spojení.");
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteNode(NodeView nodeView) {
|
||||
int confirm = JOptionPane.showConfirmDialog(parent,
|
||||
"Opravdu chcete smazat " + nodeView.getNode().getName() + "?",
|
||||
"Smazání",
|
||||
JOptionPane.YES_NO_OPTION);
|
||||
if (confirm == JOptionPane.YES_OPTION) {
|
||||
NettyClientManager.sendMessage(Message.NODE_DELETE, nodeView.getNode().getId());
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- NOVÉ AKCE PRO SPOJENÍ ----------
|
||||
private void deleteEdge(EdgeView edgeView) {
|
||||
int confirm = JOptionPane.showConfirmDialog(parent,
|
||||
"Opravdu chcete smazat spojení?",
|
||||
"Smazání spojení",
|
||||
JOptionPane.YES_NO_OPTION);
|
||||
if (confirm == JOptionPane.YES_OPTION) {
|
||||
NodeConnection conn = edgeView.getConnection();
|
||||
if (conn != null && conn.getId() > 0) {
|
||||
NettyClientManager.sendMessage(Message.NODE_CONNECTION_DELETE, conn.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void editEdge(EdgeView edgeView) {
|
||||
NodeConnection conn = edgeView.getConnection();
|
||||
// if (conn == null) {
|
||||
// // Vytvoříme nové spojení mezi stejnými uzly
|
||||
// NodeView src = edgeView.getSource();
|
||||
// NodeView tgt = edgeView.getTarget();
|
||||
// conn = new NodeConnection();
|
||||
// conn.setNodeFrom(src.getNode().getId());
|
||||
// conn.setNodeTo(tgt.getNode().getId());
|
||||
// }
|
||||
new ConnectionDialog(conn, false).show();
|
||||
}
|
||||
|
||||
// ---------- Ostatní ----------
|
||||
public JPopupMenu getPopupMenu() {
|
||||
return popupMenu;
|
||||
}
|
||||
|
||||
private void mapLock(Site site) {
|
||||
Object[] data = {site.getId(), !site.isLock()};
|
||||
NettyClientManager.sendMessage(new Message(Message.SITE_SET_LOCK, data));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,272 @@
|
|||
package jnet.client.gui.mapview;
|
||||
|
||||
import jnet.lib.LogFile;
|
||||
import jnet.lib.ResourceLoader;
|
||||
import jnet.lib.object.Node;
|
||||
import jnet.lib.object.Site;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import jnet.client.Client;
|
||||
import jnet.client.client.NettyClientManager;
|
||||
import jnet.lib.Message;
|
||||
|
||||
public class MapView extends JPanel {
|
||||
|
||||
private static final Color SELECTION_FILL = new Color(0, 0, 255, 50);
|
||||
private static final Color SELECTION_BORDER = Color.BLUE;
|
||||
private static final int EDGE_THRESHOLD = 8; // NOVÉ
|
||||
|
||||
private static BufferedImage lockImage;
|
||||
private static BufferedImage unlockImage;
|
||||
|
||||
static {
|
||||
try {
|
||||
lockImage = ImageIO.read(ResourceLoader.getFile("img/lock.png"));
|
||||
unlockImage = ImageIO.read(ResourceLoader.getFile("img/unlock.png"));
|
||||
} catch (IOException e) {
|
||||
LogFile.printErr("MapView: Failed to load lock/unlock images: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
private final MapModel model;
|
||||
private final MapMouseHandler mouseHandler;
|
||||
private final MapPopupMenu popupMenu;
|
||||
|
||||
private Node pendingNode;
|
||||
private int pendingTargetSiteId;
|
||||
private boolean isWaitingForPlacement = false;
|
||||
private final List<Node> pendingNodesToAdd = new ArrayList<>();
|
||||
|
||||
public MapView(Site site) {
|
||||
this.model = new MapModel(site, this);
|
||||
this.model.setOnChange(this::repaint);
|
||||
|
||||
this.mouseHandler = new MapMouseHandler(model, this::repaint, this);
|
||||
this.popupMenu = new MapPopupMenu(model, this, this::requestRefreshFromServer);
|
||||
|
||||
setBackground(Color.WHITE);
|
||||
setLayout(null);
|
||||
setFocusable(true);
|
||||
|
||||
addMouseListener(mouseHandler);
|
||||
addMouseMotionListener(mouseHandler);
|
||||
addMouseWheelListener(mouseHandler);
|
||||
|
||||
// UPRAVENÝ MouseAdapter pro pravý klik – zjišťuje i hranu
|
||||
addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.getButton() == MouseEvent.BUTTON3) {
|
||||
NodeView clickedNode = model.findNodeAt(e.getPoint());
|
||||
EdgeView clickedEdge = null;
|
||||
if (clickedNode == null) {
|
||||
clickedEdge = model.findEdgeAt(e.getPoint(), EDGE_THRESHOLD);
|
||||
}
|
||||
popupMenu.show(MapView.this, e.getX(), e.getY(), clickedNode, clickedEdge);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
setupKeyListener();
|
||||
model.initFromSite();
|
||||
}
|
||||
|
||||
// ...... zbytek třídy zůstává beze změny ......
|
||||
// (všechny ostatní metody: startNodePlacement, cancelNodePlacement,
|
||||
// placeNodeAt, switchToSite, paintComponent, refreshFromServer atd.)
|
||||
|
||||
// Pro úplnost uvádím i zbylé metody, ale jejich kód je totožný s původním
|
||||
|
||||
public void startNodePlacement(Node node, int targetSiteId) {
|
||||
this.pendingNode = node;
|
||||
this.pendingTargetSiteId = targetSiteId;
|
||||
this.isWaitingForPlacement = true;
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
|
||||
setToolTipText("Klikněte levým tlačítkem pro umístění uzlu, pravým tlačítkem / ESC zruší.");
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void cancelNodePlacement() {
|
||||
this.isWaitingForPlacement = false;
|
||||
this.pendingNode = null;
|
||||
setCursor(Cursor.getDefaultCursor());
|
||||
setToolTipText(null);
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void placeNodeAt(Point location) {
|
||||
if (!isWaitingForPlacement || pendingNode == null) return;
|
||||
pendingNode.setX(location.x);
|
||||
pendingNode.setY(location.y);
|
||||
pendingNodesToAdd.add(pendingNode);
|
||||
int[] data = {pendingNode.getId(), pendingTargetSiteId, location.x, location.y};
|
||||
NettyClientManager.sendMessage(new Message(Message.NODE_MOVE_TO_SITE, data));
|
||||
NodeView nv = model.findNodeViewById(pendingNode.getId());
|
||||
if (nv != null) {
|
||||
model.removeNode(nv);
|
||||
}
|
||||
cancelNodePlacement();
|
||||
JOptionPane.showMessageDialog(this, "Uzel byl odeslán k přesunu na cílovou mapu.");
|
||||
}
|
||||
|
||||
public boolean isWaitingForPlacement() {
|
||||
return isWaitingForPlacement;
|
||||
}
|
||||
|
||||
public void switchToSite(int siteId) {
|
||||
LogFile.printDebug("MapView: Switching to site ID " + siteId);
|
||||
if (isWaitingForPlacement && siteId != pendingTargetSiteId) {
|
||||
cancelNodePlacement();
|
||||
JOptionPane.showMessageDialog(this, "Režim umístění byl zrušen přepnutím mapy.");
|
||||
}
|
||||
for (Site site : Client.site) {
|
||||
if (site.getId() == siteId) {
|
||||
model.setSite(site);
|
||||
Iterator<Node> it = pendingNodesToAdd.iterator();
|
||||
while (it.hasNext()) {
|
||||
Node node = it.next();
|
||||
if (node.getSiteId() == siteId) {
|
||||
model.addNode(new NodeView(node, this));
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
if (isWaitingForPlacement) {
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
|
||||
} else {
|
||||
setCursor(Cursor.getDefaultCursor());
|
||||
}
|
||||
repaint();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setupKeyListener() {
|
||||
addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ESCAPE && isWaitingForPlacement) {
|
||||
cancelNodePlacement();
|
||||
JOptionPane.showMessageDialog(MapView.this, "Přesun zrušen.");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2 = (Graphics2D) g.create();
|
||||
|
||||
if (lockImage != null && unlockImage != null) {
|
||||
Image img = model.getSite().isLock() ? lockImage : unlockImage;
|
||||
g2.drawImage(img, 0, 0, this);
|
||||
}
|
||||
|
||||
for (EdgeView edge : model.getEdgeViews()) {
|
||||
edge.paint(g2);
|
||||
}
|
||||
|
||||
for (NodeView node : model.getNodeViews()) {
|
||||
node.paint(g2);
|
||||
}
|
||||
|
||||
Rectangle rect = mouseHandler.getSelectionRect();
|
||||
if (rect != null) {
|
||||
g2.setColor(SELECTION_FILL);
|
||||
g2.fill(rect);
|
||||
g2.setColor(SELECTION_BORDER);
|
||||
g2.draw(rect);
|
||||
}
|
||||
|
||||
if (isWaitingForPlacement) {
|
||||
g2.setColor(Color.RED);
|
||||
g2.setFont(new Font("Arial", Font.BOLD, 16));
|
||||
String msg = "Klikněte levým tlačítkem pro umístění uzlu (pravé tlačítko / ESC pro zrušení)";
|
||||
FontMetrics fm = g2.getFontMetrics();
|
||||
int x = (getWidth() - fm.stringWidth(msg)) / 2;
|
||||
int y = getHeight() - 30;
|
||||
g2.drawString(msg, x, y);
|
||||
}
|
||||
|
||||
g2.dispose();
|
||||
}
|
||||
|
||||
public void refreshFromServer(Site site) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
if (model.getSite().getId() == site.getId()) {
|
||||
model.setSite(site);
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void addNodeFromServer(Node newNode) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
if (model.getSite().getId() == newNode.getSiteId()) {
|
||||
model.addNode(new NodeView(newNode, this));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void removeNodeFromServer(int nodeId) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
NodeView nv = model.findNodeViewById(nodeId);
|
||||
if (nv != null) {
|
||||
model.removeNode(nv);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void updateNodeStatus(int nodeId, int newStatus) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
NodeView nv = model.findNodeViewById(nodeId);
|
||||
if (nv != null) {
|
||||
nv.getNode().setStatus(newStatus);
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void updateNodePosition(int nodeId, int x, int y) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
NodeView nv = model.findNodeViewById(nodeId);
|
||||
if (nv != null) {
|
||||
nv.setLocation(x, y);
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void updateNodeData(int nodeId, String name, String ip) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
NodeView nv = model.findNodeViewById(nodeId);
|
||||
if (nv != null) {
|
||||
nv.getNode().setName(name);
|
||||
nv.getNode().setIp(ip);
|
||||
nv.recalculateDimensions();
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void requestRefreshFromServer() {
|
||||
LogFile.printDebug("MapView: Requesting refresh from server");
|
||||
JOptionPane.showMessageDialog(this, "Obnovení ze serveru - implementujte volání");
|
||||
}
|
||||
|
||||
public MapModel getModel() {
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package jnet.client.gui.mapview;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
public interface NodeRenderer {
|
||||
void paint(Graphics2D g2, NodeView nodeView);
|
||||
}
|
||||
|
|
@ -0,0 +1,224 @@
|
|||
package jnet.client.gui.mapview;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Base64;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.imageio.ImageIO;
|
||||
import jnet.client.Client;
|
||||
import jnet.client.SnmpResponseParser;
|
||||
import jnet.lib.LogFile;
|
||||
import jnet.lib.object.Node;
|
||||
import jnet.lib.object.NodeProbe;
|
||||
import jnet.lib.object.ObjectType;
|
||||
|
||||
public class NodeView {
|
||||
|
||||
public static final Font FONT_BOLD_12 = new Font("Arial", Font.BOLD, 12);
|
||||
public static final Font FONT_NORMAL_12 = new Font("Arial", Font.PLAIN, 12);
|
||||
|
||||
// Zvětšený padding pro zařízení
|
||||
private static final int PADDING_DEVICE = 30;
|
||||
private static final int PADDING_OVAL = 30;
|
||||
private static final int PADDING_CIRCLE = 25;
|
||||
|
||||
private static final Map<Integer, Image> iconCache = new HashMap<>();
|
||||
|
||||
private final Node node;
|
||||
private Image icon;
|
||||
private int centerX, centerY;
|
||||
private int width, height;
|
||||
private boolean selected = false;
|
||||
private final MapView parent;
|
||||
|
||||
private final NodeRenderer renderer;
|
||||
|
||||
private FontMetrics fmBold;
|
||||
private FontMetrics fmNormal;
|
||||
|
||||
public NodeView(Node node, MapView parent) {
|
||||
this.node = node;
|
||||
this.parent = parent;
|
||||
this.centerX = node.getX();
|
||||
this.centerY = node.getY();
|
||||
this.icon = loadIcon(node.getIcon());
|
||||
|
||||
int type = node.getType();
|
||||
if (type == 2) {
|
||||
renderer = new MapNodeRenderer();
|
||||
} else if (type == 3) {
|
||||
renderer = new StaticNodeRenderer();
|
||||
} else {
|
||||
renderer = new DeviceNodeRenderer();
|
||||
}
|
||||
|
||||
recalculateDimensions();
|
||||
}
|
||||
|
||||
private Image loadIcon(int typeId) {
|
||||
return iconCache.computeIfAbsent(typeId, id -> {
|
||||
for (ObjectType objectType : Client.objectType) {
|
||||
if (objectType.getId() == id) {
|
||||
try {
|
||||
byte[] decoded = Base64.getDecoder().decode(objectType.getImgStr());
|
||||
try (ByteArrayInputStream bis = new ByteArrayInputStream(decoded)) {
|
||||
return ImageIO.read(bis);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LogFile.printErr("NodeView: Icon load error for type " + id + ": " + e.getMessage());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
public void recalculateDimensions() {
|
||||
fmBold = parent.getFontMetrics(FONT_BOLD_12);
|
||||
fmNormal = parent.getFontMetrics(FONT_NORMAL_12);
|
||||
|
||||
String name = node.getName() != null ? node.getName() : "";
|
||||
String ip = node.getIp() != null ? node.getIp() : "";
|
||||
|
||||
int nameWidth = fmBold.stringWidth(name);
|
||||
int ipWidth = fmNormal.stringWidth(ip);
|
||||
int iconWidth = (icon != null) ? icon.getWidth(null) : 0;
|
||||
int iconHeight = (icon != null) ? icon.getHeight(null) : 0;
|
||||
|
||||
// ZMĚNA: získáme viditelné sondy
|
||||
List<NodeProbe> visibleProbes = node.getProbe() != null
|
||||
? node.getProbe().stream().filter(NodeProbe::isViewOnMap).collect(Collectors.toList())
|
||||
: java.util.Collections.emptyList();
|
||||
|
||||
int probeCount = visibleProbes.size();
|
||||
|
||||
// ZMĚNA: spočítáme maximální šířku pro text sond (název + hodnota)
|
||||
int maxProbeWidth = 0;
|
||||
for (NodeProbe probe : visibleProbes) {
|
||||
String value = probe.getValue() != null ? SnmpResponseParser.parse(probe) : "?";
|
||||
int w = fmNormal.stringWidth(value);
|
||||
if (w > maxProbeWidth) maxProbeWidth = w;
|
||||
}
|
||||
|
||||
int maxTextWidth = Math.max(nameWidth, ipWidth);
|
||||
maxTextWidth = Math.max(maxTextWidth, maxProbeWidth);
|
||||
|
||||
int type = node.getType();
|
||||
|
||||
// ZMĚNA: výška pro každou sondu (řádek)
|
||||
int probeHeight = probeCount * (fmNormal.getHeight() + 2);
|
||||
|
||||
if (type == 1) {
|
||||
// Větší vnitřní prostor
|
||||
width = Math.max(maxTextWidth, iconWidth) + PADDING_DEVICE;
|
||||
height = 8 + iconHeight + 8 + fmBold.getHeight() + 8 + fmNormal.getHeight() + 8 + probeHeight + 8;
|
||||
if (icon == null) {
|
||||
height -= iconHeight + 8;
|
||||
height += 8; // kompenzace
|
||||
}
|
||||
} else if (type == 2) {
|
||||
int textHeight = fmBold.getHeight() + 5 + fmNormal.getHeight() + probeHeight;
|
||||
width = Math.max(maxTextWidth + PADDING_OVAL, 100);
|
||||
height = Math.max(textHeight + PADDING_OVAL, 50);
|
||||
if (width < height * 1.6) {
|
||||
width = (int) (height * 1.8);
|
||||
}
|
||||
} else if (type == 3) {
|
||||
int textHeight = fmBold.getHeight() + 5 + fmNormal.getHeight() + probeHeight;
|
||||
int needed = Math.max(maxTextWidth + PADDING_CIRCLE, textHeight + PADDING_CIRCLE);
|
||||
width = Math.max(needed, 70);
|
||||
height = width;
|
||||
} else {
|
||||
width = Math.max(maxTextWidth, iconWidth) + PADDING_DEVICE;
|
||||
height = 8 + iconHeight + 8 + fmBold.getHeight() + 8 + fmNormal.getHeight() + 8 + probeHeight + 8;
|
||||
if (icon == null) {
|
||||
height -= iconHeight + 8;
|
||||
height += 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void paint(Graphics2D g2) {
|
||||
fmBold = g2.getFontMetrics(FONT_BOLD_12);
|
||||
fmNormal = g2.getFontMetrics(FONT_NORMAL_12);
|
||||
|
||||
recalculateDimensions();
|
||||
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
renderer.paint(g2, this);
|
||||
|
||||
// Výběr - silnější oranžové ohraničení (zůstává)
|
||||
if (selected) {
|
||||
Shape selShape = getShape();
|
||||
if (selShape != null) {
|
||||
g2.setColor(new Color(255, 255, 0, 60));
|
||||
g2.fill(selShape);
|
||||
g2.setStroke(new BasicStroke(3.0f));
|
||||
g2.setColor(new Color(255, 165, 0));
|
||||
g2.draw(selShape);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Shape getShape() {
|
||||
int cx = centerX;
|
||||
int cy = centerY;
|
||||
int w = width;
|
||||
int h = height;
|
||||
int type = node.getType();
|
||||
if (type == 1) {
|
||||
return new java.awt.geom.RoundRectangle2D.Double(cx - w/2, cy - h/2, w, h, 10, 10);
|
||||
} else if (type == 2) {
|
||||
return new java.awt.geom.Ellipse2D.Double(cx - w/2, cy - h/2, w, h);
|
||||
} else if (type == 3) {
|
||||
int size = Math.min(w, h);
|
||||
return new java.awt.geom.Ellipse2D.Double(cx - size/2, cy - size/2, size, size);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean contains(Point p) {
|
||||
Shape s = getShape();
|
||||
return s != null && s.contains(p);
|
||||
}
|
||||
|
||||
public void translate(int dx, int dy) {
|
||||
this.centerX += dx;
|
||||
this.centerY += dy;
|
||||
node.setX(centerX);
|
||||
node.setY(centerY);
|
||||
recalculateDimensions();
|
||||
}
|
||||
|
||||
public void setLocation(int x, int y) {
|
||||
this.centerX = x;
|
||||
this.centerY = y;
|
||||
node.setX(x);
|
||||
node.setY(y);
|
||||
recalculateDimensions();
|
||||
}
|
||||
|
||||
// Gettery
|
||||
public Node getNode() { return node; }
|
||||
public Image getIcon() { return icon; }
|
||||
public int getCenterX() { return centerX; }
|
||||
public int getCenterY() { return centerY; }
|
||||
public int getWidth() { return width; }
|
||||
public int getHeight() { return height; }
|
||||
public boolean isSelected() { return selected; }
|
||||
public void setSelected(boolean selected) { this.selected = selected; }
|
||||
public Rectangle getBounds() {
|
||||
Shape s = getShape();
|
||||
if (s != null) return s.getBounds();
|
||||
return new Rectangle(centerX, centerY, 0, 0);
|
||||
}
|
||||
public FontMetrics getFontMetricsBold() { return fmBold; }
|
||||
public FontMetrics getFontMetricsNormal() { return fmNormal; }
|
||||
}
|
||||
|
|
@ -0,0 +1,152 @@
|
|||
package jnet.client.gui.mapview;
|
||||
|
||||
import jnet.client.Client;
|
||||
import jnet.lib.LogFile;
|
||||
import jnet.lib.object.Node;
|
||||
import jnet.lib.object.ObjectType;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.geom.RoundRectangle2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Base64;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PaintSiteObject {
|
||||
|
||||
private Node node;
|
||||
private BufferedImage icon;
|
||||
private boolean selected = false;
|
||||
|
||||
// Cache ikon podle typu
|
||||
private static final Map<Integer, BufferedImage> iconCache = new HashMap<>();
|
||||
|
||||
// Fonty
|
||||
private static final Font FONT_BOLD_12 = new Font("Arial", Font.BOLD, 12);
|
||||
private static final Font FONT_NORMAL_12 = new Font("Arial", Font.PLAIN, 12);
|
||||
|
||||
// Geometrie (vypočítá se při paint)
|
||||
private int centerX, centerY;
|
||||
private int width, height;
|
||||
private RoundRectangle2D shape;
|
||||
|
||||
public PaintSiteObject(Node node) {
|
||||
this.node = node;
|
||||
this.icon = loadIcon(node.getIcon());
|
||||
}
|
||||
|
||||
private BufferedImage loadIcon(int typeId) {
|
||||
return iconCache.computeIfAbsent(typeId, id -> {
|
||||
for (ObjectType objectType : Client.objectType) {
|
||||
if (objectType.getId() == id) {
|
||||
try {
|
||||
byte[] decoded = Base64.getDecoder().decode(objectType.getImgStr());
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(decoded);
|
||||
return ImageIO.read(bis);
|
||||
} catch (IOException e) {
|
||||
LogFile.printErr("Failed to load icon for type " + id + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
public void paint(Graphics2D g2) {
|
||||
centerX = node.getX();
|
||||
centerY = node.getY();
|
||||
|
||||
FontMetrics fmBold = g2.getFontMetrics(FONT_BOLD_12);
|
||||
FontMetrics fmNormal = g2.getFontMetrics(FONT_NORMAL_12);
|
||||
|
||||
// Výpočet šířky
|
||||
int nameWidth = fmBold.stringWidth(node.getName());
|
||||
int ipWidth = fmNormal.stringWidth(node.getIp());
|
||||
int maxTextWidth = Math.max(nameWidth, ipWidth);
|
||||
int padding = 20;
|
||||
width = Math.max(maxTextWidth + padding, icon != null ? icon.getWidth() + padding : 60);
|
||||
|
||||
// Výpočet výšky
|
||||
height = 5; // horní padding
|
||||
if (icon != null) {
|
||||
height += icon.getHeight() + 5;
|
||||
}
|
||||
height += fmBold.getHeight() + 5;
|
||||
height += fmNormal.getHeight() + 5;
|
||||
height += 5; // dolní padding
|
||||
|
||||
// Pozice boxu
|
||||
int boxX = centerX - width / 2;
|
||||
int boxY = centerY - height / 2;
|
||||
|
||||
// Barva pozadí podle statusu
|
||||
Color bgColor;
|
||||
switch (node.getStatus()) {
|
||||
case 1: bgColor = new Color(83, 241, 83); break; // online
|
||||
case 2: bgColor = new Color(255, 131, 0); break; // warning
|
||||
case 3: bgColor = new Color(221, 63, 63); break; // offline
|
||||
default: bgColor = new Color(172, 172, 172);
|
||||
}
|
||||
g2.setColor(bgColor);
|
||||
shape = new RoundRectangle2D.Double(boxX, boxY, width, height, 10, 10);
|
||||
g2.fill(shape);
|
||||
|
||||
// Ohraničení pokud vybráno
|
||||
if (selected) {
|
||||
g2.setStroke(new BasicStroke(1.5f));
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.draw(shape);
|
||||
}
|
||||
|
||||
// Ikona
|
||||
int currentY = boxY + 5;
|
||||
if (icon != null) {
|
||||
int imgX = boxX + (width - icon.getWidth()) / 2;
|
||||
g2.drawImage(icon, imgX, currentY, null);
|
||||
currentY += icon.getHeight() + 5;
|
||||
}
|
||||
|
||||
// Název
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.setFont(FONT_BOLD_12);
|
||||
int textX = boxX + (width - nameWidth) / 2;
|
||||
int textY = currentY + fmBold.getAscent();
|
||||
g2.drawString(node.getName(), textX, textY);
|
||||
|
||||
// IP adresa
|
||||
currentY += fmBold.getHeight() + 5;
|
||||
g2.setFont(FONT_NORMAL_12);
|
||||
textX = boxX + (width - ipWidth) / 2;
|
||||
textY = currentY + fmNormal.getAscent();
|
||||
g2.drawString(node.getIp(), textX, textY);
|
||||
}
|
||||
|
||||
// Test kolize s bodem (pro výběr)
|
||||
public boolean contains(Point p) {
|
||||
return shape != null && shape.contains(p);
|
||||
}
|
||||
|
||||
// Posun uzlu
|
||||
public void setPosition(Point newCenter) {
|
||||
this.centerX = newCenter.x;
|
||||
this.centerY = newCenter.y;
|
||||
node.setX(newCenter.x);
|
||||
node.setY(newCenter.y);
|
||||
}
|
||||
|
||||
// Gettery
|
||||
public Node getNode() { return node; }
|
||||
public int getId() { return node.getId(); }
|
||||
public Point getCenter() { return new Point(centerX, centerY); }
|
||||
public Rectangle getBounds() {
|
||||
if (shape != null) {
|
||||
return shape.getBounds();
|
||||
}
|
||||
return new Rectangle(centerX - width/2, centerY - height/2, width, height);
|
||||
}
|
||||
public void setSelected(boolean selected) { this.selected = selected; }
|
||||
public boolean isSelected() { return selected; }
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package jnet.client.gui.mapview;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Stroke;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
|
||||
public class StaticNodeRenderer implements NodeRenderer {
|
||||
|
||||
private static final Stroke THIN_STROKE = new BasicStroke(1.0f);
|
||||
|
||||
@Override
|
||||
public void paint(Graphics2D g2, NodeView nodeView) {
|
||||
int cx = nodeView.getCenterX();
|
||||
int cy = nodeView.getCenterY();
|
||||
int size = nodeView.getWidth();
|
||||
|
||||
Ellipse2D circle = new Ellipse2D.Double(cx - size/2, cy - size/2, size, size);
|
||||
g2.setColor(new Color(211, 211, 211));
|
||||
g2.fill(circle);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.setStroke(THIN_STROKE);
|
||||
g2.draw(circle);
|
||||
|
||||
TextUtils.drawCenteredText(g2,
|
||||
nodeView.getNode().getName(),
|
||||
nodeView.getNode().getIp(),
|
||||
cx, cy,
|
||||
nodeView.getFontMetricsBold(),
|
||||
nodeView.getFontMetricsNormal());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,133 @@
|
|||
package jnet.client.gui.mapview;
|
||||
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.util.List;
|
||||
import jnet.lib.object.Node;
|
||||
import jnet.lib.object.NodeProbe;
|
||||
import jnet.client.SnmpResponseParser;
|
||||
|
||||
public class TextUtils {
|
||||
|
||||
public static void drawCenteredText(Graphics2D g2, String name, String ip, int cx, int cy,
|
||||
FontMetrics fmBold, FontMetrics fmNormal) {
|
||||
if (name == null) name = "";
|
||||
if (ip == null) ip = "";
|
||||
|
||||
if (name.isEmpty() && ip.isEmpty()) return;
|
||||
|
||||
int nameWidth = name.isEmpty() ? 0 : fmBold.stringWidth(name);
|
||||
int ipWidth = ip.isEmpty() ? 0 : fmNormal.stringWidth(ip);
|
||||
int boldHeight = fmBold.getHeight();
|
||||
int normalHeight = fmNormal.getHeight();
|
||||
|
||||
int totalHeight;
|
||||
if (!name.isEmpty() && !ip.isEmpty()) {
|
||||
totalHeight = boldHeight + 5 + normalHeight;
|
||||
} else if (!name.isEmpty()) {
|
||||
totalHeight = boldHeight;
|
||||
} else {
|
||||
totalHeight = normalHeight;
|
||||
}
|
||||
|
||||
int startY;
|
||||
if (!name.isEmpty() && !ip.isEmpty()) {
|
||||
startY = cy - totalHeight / 2 + fmBold.getAscent();
|
||||
} else if (!name.isEmpty()) {
|
||||
startY = cy + fmBold.getAscent() / 2 - fmBold.getDescent() / 2;
|
||||
} else {
|
||||
startY = cy + fmNormal.getAscent() / 2 - fmNormal.getDescent() / 2;
|
||||
}
|
||||
|
||||
g2.setColor(java.awt.Color.BLACK);
|
||||
|
||||
if (!name.isEmpty()) {
|
||||
g2.setFont(NodeView.FONT_BOLD_12);
|
||||
int x = cx - nameWidth / 2;
|
||||
g2.drawString(name, x, startY);
|
||||
}
|
||||
|
||||
if (!ip.isEmpty()) {
|
||||
g2.setFont(NodeView.FONT_NORMAL_12);
|
||||
int ipY = startY + boldHeight + 5;
|
||||
if (name.isEmpty()) {
|
||||
ipY = startY;
|
||||
}
|
||||
int x = cx - ipWidth / 2;
|
||||
g2.drawString(ip, x, ipY);
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawTextFromY(Graphics2D g2, String name, String ip, int cx, int startY,
|
||||
FontMetrics fmBold, FontMetrics fmNormal) {
|
||||
if (name == null) name = "";
|
||||
if (ip == null) ip = "";
|
||||
|
||||
if (name.isEmpty() && ip.isEmpty()) return;
|
||||
|
||||
int nameWidth = name.isEmpty() ? 0 : fmBold.stringWidth(name);
|
||||
int ipWidth = ip.isEmpty() ? 0 : fmNormal.stringWidth(ip);
|
||||
|
||||
g2.setColor(java.awt.Color.BLACK);
|
||||
|
||||
int y = startY;
|
||||
if (!name.isEmpty()) {
|
||||
g2.setFont(NodeView.FONT_BOLD_12);
|
||||
int x = cx - nameWidth / 2;
|
||||
g2.drawString(name, x, y + fmBold.getAscent());
|
||||
y += fmBold.getHeight() + 5;
|
||||
}
|
||||
|
||||
if (!ip.isEmpty()) {
|
||||
g2.setFont(NodeView.FONT_NORMAL_12);
|
||||
int x = cx - ipWidth / 2;
|
||||
g2.drawString(ip, x, y + fmNormal.getAscent());
|
||||
}
|
||||
}
|
||||
|
||||
// ZMĚNA: nová metoda pro vykreslení jména, IP a viditelných sond
|
||||
public static int drawNodeInfo(Graphics2D g2, Node node, int cx, int startY,
|
||||
FontMetrics fmBold, FontMetrics fmNormal) {
|
||||
String name = node.getName() != null ? node.getName() : "";
|
||||
String ip = node.getIp() != null ? node.getIp() : "";
|
||||
|
||||
int y = startY;
|
||||
g2.setColor(java.awt.Color.BLACK);
|
||||
|
||||
// Jméno (tučné)
|
||||
if (!name.isEmpty()) {
|
||||
g2.setFont(NodeView.FONT_BOLD_12);
|
||||
int nameWidth = fmBold.stringWidth(name);
|
||||
int x = cx - nameWidth / 2;
|
||||
g2.drawString(name, x, y + fmBold.getAscent());
|
||||
y += fmBold.getHeight() + 5;
|
||||
}
|
||||
|
||||
// IP (normální)
|
||||
if (!ip.isEmpty()) {
|
||||
g2.setFont(NodeView.FONT_NORMAL_12);
|
||||
int ipWidth = fmNormal.stringWidth(ip);
|
||||
int x = cx - ipWidth / 2;
|
||||
g2.drawString(ip, x, y + fmNormal.getAscent());
|
||||
y += fmNormal.getHeight() + 5;
|
||||
}
|
||||
|
||||
// Sondy (pouze viewOnMap = true)
|
||||
List<NodeProbe> visibleProbes = node.getProbe() != null
|
||||
? node.getProbe().stream().filter(NodeProbe::isViewOnMap).collect(java.util.stream.Collectors.toList())
|
||||
: java.util.Collections.emptyList();
|
||||
|
||||
g2.setFont(NodeView.FONT_NORMAL_12);
|
||||
for (NodeProbe probe : visibleProbes) {
|
||||
String probeName = probe.getName() != null ? probe.getName() : "";
|
||||
String value = probe.getValue() != null ? SnmpResponseParser.parse(probe) + " " + probe.getUnit() : "?";
|
||||
String text = probeName + ": " + value;
|
||||
int textWidth = fmNormal.stringWidth(text);
|
||||
int x = cx - textWidth / 2;
|
||||
g2.drawString(text, x, y + fmNormal.getAscent());
|
||||
y += fmNormal.getHeight() + 2;
|
||||
}
|
||||
|
||||
return y; // vrátí novou Y pozici
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,261 @@
|
|||
package jnet.client.gui.serversettings;
|
||||
|
||||
import jnet.client.Client;
|
||||
import jnet.client.gui.dialog.AddDeviceTypeDialog;
|
||||
import jnet.client.gui.dialog.UserDialog;
|
||||
import jnet.client.client.NettyClientManager;
|
||||
import jnet.lib.LogFile;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.SnmpProfile;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import org.snmp4j.mp.SnmpConstants;
|
||||
|
||||
public class ServerSettingsPanel extends JTabbedPane {
|
||||
|
||||
public static final int TAB_DEFAULT = 0;
|
||||
public static final int TAB_DEVICE_TYPE = 1;
|
||||
public static final int TAB_USERS = 2;
|
||||
public static final int TAB_SNMP_PROFILE = 3;
|
||||
public static final int TAB_SNMP_TEMPLATE = 4;
|
||||
|
||||
private TableDeviceType tableDeviceType;
|
||||
private TableUsers tableUsers;
|
||||
private TableSnmpProfile tableSnmpProfile;
|
||||
private TableSnmpTemplate tableSnmpTemplate;
|
||||
|
||||
public ServerSettingsPanel() {
|
||||
addTab("Základní", tabZakladni());
|
||||
addTab("Typy zařízení", tabZarizeni());
|
||||
addTab("Uživatelé", tabUsers());
|
||||
addTab("SNMP profily", tabSnmpProfile());
|
||||
addTab("SNMP šablony", tabSnmpTemplate());
|
||||
}
|
||||
|
||||
public void setTable(int tab) {
|
||||
setSelectedIndex(tab);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Základní nastavení (původní styl s null layout)
|
||||
// ------------------------------------------------------------------------
|
||||
private Component tabZakladni() {
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(null);
|
||||
|
||||
int x1 = 80;
|
||||
int x2 = 150;
|
||||
|
||||
// Nadpis
|
||||
JLabel pingLabel = new JLabel("Ping");
|
||||
pingLabel.setFont(pingLabel.getFont().deriveFont(20f));
|
||||
pingLabel.setBounds(20, 20, 150, 25);
|
||||
panel.add(pingLabel);
|
||||
|
||||
// Pole
|
||||
JTextField repeateField = new JTextField(String.valueOf(Client.serverConfig.getPingRepeat()));
|
||||
repeateField.setBounds(x1, 60, 50, 25);
|
||||
panel.add(repeateField);
|
||||
|
||||
JLabel repeateLabel = new JLabel("Opakovat ping každých ... sekund");
|
||||
repeateLabel.setBounds(x2, 60, 300, 25);
|
||||
panel.add(repeateLabel);
|
||||
|
||||
JTextField pokusuField = new JTextField(String.valueOf(Client.serverConfig.getPingAttempt()));
|
||||
pokusuField.setBounds(x1, 100, 50, 25);
|
||||
panel.add(pokusuField);
|
||||
|
||||
JLabel pokusuLabel = new JLabel("Počet pokusů před vyhodnocením offline");
|
||||
pokusuLabel.setBounds(x2, 100, 300, 25);
|
||||
panel.add(pokusuLabel);
|
||||
|
||||
JTextField timeoutField = new JTextField(String.valueOf(Client.serverConfig.getPingTimeout()));
|
||||
timeoutField.setBounds(x1, 140, 50, 25);
|
||||
panel.add(timeoutField);
|
||||
|
||||
JLabel timeoutLabel = new JLabel("Úroveň timeout (s)");
|
||||
timeoutLabel.setBounds(x2, 140, 300, 25);
|
||||
panel.add(timeoutLabel);
|
||||
|
||||
JTextField pokusuNestField = new JTextField(String.valueOf(Client.serverConfig.getInstabilityAttempt()));
|
||||
pokusuNestField.setBounds(x1, 180, 50, 25);
|
||||
panel.add(pokusuNestField);
|
||||
|
||||
JLabel pokusuNestLabel = new JLabel("Počet pokusů před vyhodnocením nestability");
|
||||
pokusuNestLabel.setBounds(x2, 180, 300, 25);
|
||||
panel.add(pokusuNestLabel);
|
||||
|
||||
JTextField nestField = new JTextField(String.valueOf(Client.serverConfig.getInstabilityLimit()));
|
||||
nestField.setBounds(x1, 220, 50, 25);
|
||||
panel.add(nestField);
|
||||
|
||||
JLabel nestLabel = new JLabel("Úroveň nestability (s)");
|
||||
nestLabel.setBounds(x2, 220, 300, 25);
|
||||
panel.add(nestLabel);
|
||||
|
||||
// Tlačítko Uložit
|
||||
JButton button = new JButton("Uložit");
|
||||
button.setBounds(x1, 300, 100, 40);
|
||||
button.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
Client.serverConfig.setPingRepeat(Integer.valueOf(repeateField.getText()));
|
||||
Client.serverConfig.setPingAttempt(Integer.valueOf(pokusuField.getText()));
|
||||
Client.serverConfig.setPingTimeout(Integer.valueOf(timeoutField.getText()));
|
||||
Client.serverConfig.setInstabilityAttempt(Integer.valueOf(pokusuNestField.getText()));
|
||||
Client.serverConfig.setInstabilityLimit(Integer.valueOf(nestField.getText()));
|
||||
NettyClientManager.sendMessage(new Message(Message.SERVER_CONFIG_EDIT, Client.serverConfig));
|
||||
JOptionPane.showMessageDialog(panel, "Nastavení uloženo.");
|
||||
} catch (NumberFormatException ex) {
|
||||
JOptionPane.showMessageDialog(panel, "Zadejte platná čísla.", "Chyba", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
});
|
||||
panel.add(button);
|
||||
|
||||
// Tlačítko Restartovat server
|
||||
JButton buttonRestart = new JButton("Restartovat server");
|
||||
buttonRestart.setBounds(x1 + 200, 300, 150, 40);
|
||||
buttonRestart.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
int result = JOptionPane.showConfirmDialog(null,
|
||||
"Opravdu chceš pokračovat?",
|
||||
"Restart serveru",
|
||||
JOptionPane.YES_NO_OPTION);
|
||||
|
||||
if (result == JOptionPane.YES_OPTION) {
|
||||
LogFile.printInfo("Odeslan pozadavek na restart serveru");
|
||||
NettyClientManager.sendMessage(new Message(Message.SERVER_RESTART, null));
|
||||
}
|
||||
}
|
||||
});
|
||||
panel.add(buttonRestart);
|
||||
|
||||
return new JScrollPane(panel);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Typy zařízení
|
||||
// ------------------------------------------------------------------------
|
||||
private JPanel tabZarizeni() {
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
||||
|
||||
tableDeviceType = new TableDeviceType();
|
||||
JScrollPane scrollPane = new JScrollPane(tableDeviceType);
|
||||
panel.add(scrollPane);
|
||||
|
||||
JButton button = new JButton("Přidat typ");
|
||||
button.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
button.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
SwingUtilities.invokeLater(() -> new AddDeviceTypeDialog().setVisible(true));
|
||||
}
|
||||
});
|
||||
panel.add(button);
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
public void refreshDeviceTypes() {
|
||||
if (tableDeviceType != null) {
|
||||
SwingUtilities.invokeLater(() -> tableDeviceType.refreshTable());
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Uživatelé
|
||||
// ------------------------------------------------------------------------
|
||||
private JPanel tabUsers() {
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
||||
|
||||
tableUsers = new TableUsers();
|
||||
panel.add(new JScrollPane(tableUsers));
|
||||
|
||||
JButton button = new JButton("Přidat uživatele");
|
||||
button.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
button.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
SwingUtilities.invokeLater(() -> new UserDialog(null, true).setVisible(true));
|
||||
}
|
||||
});
|
||||
panel.add(button);
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
public void refreshUsers() {
|
||||
if (tableUsers != null) {
|
||||
SwingUtilities.invokeLater(() -> tableUsers.refreshTable());
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// SNMP profily
|
||||
// ------------------------------------------------------------------------
|
||||
private Component tabSnmpProfile() {
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
||||
|
||||
tableSnmpProfile = new TableSnmpProfile();
|
||||
JScrollPane scrollPane = new JScrollPane(tableSnmpProfile);
|
||||
panel.add(scrollPane);
|
||||
|
||||
JButton button = new JButton("Přidat profil");
|
||||
button.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
button.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
//SwingUtilities.invokeLater(() -> new AddDeviceTypeDialog().setVisible(true));
|
||||
}
|
||||
});
|
||||
//panel.add(button);
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
public void refreshSnmpProfiles() {
|
||||
if (tableUsers != null) {
|
||||
SwingUtilities.invokeLater(() -> tableSnmpProfile.refreshTable());
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// SNMP profily
|
||||
// ------------------------------------------------------------------------
|
||||
private Component tabSnmpTemplate() {
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
||||
|
||||
tableSnmpTemplate = new TableSnmpTemplate();
|
||||
JScrollPane scrollPane = new JScrollPane(tableSnmpTemplate);
|
||||
panel.add(scrollPane);
|
||||
|
||||
JButton button = new JButton("Přidat sablonu");
|
||||
button.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
button.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
//SwingUtilities.invokeLater(() -> new AddDeviceTypeDialog().setVisible(true));
|
||||
}
|
||||
});
|
||||
//panel.add(button);
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
public void refreshSnmpTemplate() {
|
||||
if (tableUsers != null) {
|
||||
SwingUtilities.invokeLater(() -> tableSnmpTemplate.refreshTable());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
package jnet.client.gui.serversettings;
|
||||
|
||||
import jnet.client.Client;
|
||||
import jnet.lib.ResourceLoader;
|
||||
import jnet.lib.object.ObjectType;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import javax.swing.table.TableColumn;
|
||||
import java.awt.*;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Base64;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class TableDeviceType extends JTable {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(TableDeviceType.class.getName());
|
||||
private static final ConcurrentHashMap<String, ImageIcon> iconCache = new ConcurrentHashMap<>();
|
||||
|
||||
private static final String[] COLUMN_NAMES = {"Ikona", "Název zařízení"};
|
||||
|
||||
private DefaultTableModel model;
|
||||
|
||||
public TableDeviceType() {
|
||||
initTable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getColumnClass(int column) {
|
||||
return column == 0 ? ImageIcon.class : String.class;
|
||||
}
|
||||
|
||||
private void initTable() {
|
||||
model = new DefaultTableModel(COLUMN_NAMES, 0) {
|
||||
@Override
|
||||
public boolean isCellEditable(int row, int column) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
setModel(model);
|
||||
setDefaultRenderer(String.class, new CenteredRenderer());
|
||||
setRowHeight(50);
|
||||
|
||||
loadData();
|
||||
|
||||
// Nastavení šířky sloupců
|
||||
for (int i = 0; i < COLUMN_NAMES.length; i++) {
|
||||
TableColumn col = getColumnModel().getColumn(i);
|
||||
col.setPreferredWidth(col.getPreferredWidth() + 80);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadData() {
|
||||
model.setRowCount(0);
|
||||
|
||||
for (ObjectType obj : Client.objectType) {
|
||||
model.addRow(new Object[]{getIcon(obj), obj.getName()});
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshTable() {
|
||||
SwingUtilities.invokeLater(this::loadData);
|
||||
}
|
||||
|
||||
private ImageIcon getIcon(ObjectType obj) {
|
||||
return iconCache.computeIfAbsent(obj.getImgStr(), key -> {
|
||||
try {
|
||||
byte[] decoded = Base64.getDecoder().decode(key);
|
||||
var img = ImageIO.read(new ByteArrayInputStream(decoded));
|
||||
if (img != null) {
|
||||
// Zmenšení obrázku na 32x32
|
||||
Image scaled = img.getScaledInstance(32, 32, Image.SCALE_SMOOTH);
|
||||
return new ImageIcon(scaled);
|
||||
}
|
||||
return null;
|
||||
} catch (IOException e) {
|
||||
LOG.log(Level.WARNING, "Failed to decode image for: " + obj.getName(), e);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static class CenteredRenderer extends DefaultTableCellRenderer {
|
||||
@Override
|
||||
public Component getTableCellRendererComponent(JTable table, Object value,
|
||||
boolean isSelected, boolean hasFocus,
|
||||
int row, int column) {
|
||||
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
||||
if (c instanceof JLabel) {
|
||||
((JLabel) c).setHorizontalAlignment(SwingConstants.CENTER);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
package jnet.client.gui.serversettings;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import jnet.client.Client;
|
||||
import jnet.lib.object.SnmpProfile;
|
||||
import org.snmp4j.mp.SnmpConstants;
|
||||
|
||||
public class TableSnmpProfile extends JTable {
|
||||
|
||||
private DefaultTableModel model;
|
||||
private static final String[] COLUMN_NAMES = {"Název", "Verze", "Community Read", "Community Write", "Port"};
|
||||
|
||||
public TableSnmpProfile() {
|
||||
initTable();
|
||||
}
|
||||
|
||||
private void initTable() {
|
||||
model = new DefaultTableModel(COLUMN_NAMES, 0) {
|
||||
@Override
|
||||
public boolean isCellEditable(int row, int column) {
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
setModel(model);
|
||||
setRowHeight(25);
|
||||
|
||||
loadData();
|
||||
|
||||
}
|
||||
|
||||
private void loadData() {
|
||||
model.setRowCount(0);
|
||||
|
||||
for (SnmpProfile sp : Client.snmpProfile) {
|
||||
model.addRow(new Object[]{
|
||||
sp.getName(),
|
||||
getSnmpVersion(sp.getVersion()),
|
||||
sp.getCommunityRead(),
|
||||
sp.getCommunityWrite(),
|
||||
sp.getPort()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private String getSnmpVersion(int version) {
|
||||
switch (version) {
|
||||
case SnmpConstants.version1:
|
||||
return "verze 1";
|
||||
case SnmpConstants.version2c:
|
||||
return "verze 2c";
|
||||
case SnmpConstants.version3:
|
||||
return "verze 3";
|
||||
}
|
||||
return "n/a";
|
||||
}
|
||||
|
||||
public void refreshTable() {
|
||||
SwingUtilities.invokeLater(this::loadData);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
package jnet.client.gui.serversettings;
|
||||
|
||||
import java.util.List;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.RowSorter;
|
||||
import javax.swing.SortOrder;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import javax.swing.table.TableRowSorter;
|
||||
import jnet.client.Client;
|
||||
import jnet.lib.object.SnmpTemplate;
|
||||
|
||||
public class TableSnmpTemplate extends JTable {
|
||||
|
||||
private DefaultTableModel model;
|
||||
private static final String[] COLUMN_NAMES = {"Type zařízeni", "Název", "Poznámka"};
|
||||
|
||||
public TableSnmpTemplate() {
|
||||
initTable();
|
||||
}
|
||||
|
||||
private void initTable() {
|
||||
model = new DefaultTableModel(COLUMN_NAMES, 0) {
|
||||
@Override
|
||||
public boolean isCellEditable(int row, int column) {
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
setModel(model);
|
||||
setRowHeight(25);
|
||||
|
||||
loadData();
|
||||
|
||||
}
|
||||
|
||||
private void loadData() {
|
||||
model.setRowCount(0);
|
||||
|
||||
for (SnmpTemplate st : Client.snmpTemplate) {
|
||||
model.addRow(new Object[]{
|
||||
st.getDeviceType(),
|
||||
st.getName(),
|
||||
st.getDescription()
|
||||
});
|
||||
}
|
||||
|
||||
// Po načtení dat nastavit řazení podle 1. sloupce vzestupně
|
||||
TableRowSorter<DefaultTableModel> sorter = (TableRowSorter<DefaultTableModel>) getRowSorter();
|
||||
if (sorter != null) {
|
||||
sorter.setSortKeys(List.of(new RowSorter.SortKey(0, SortOrder.ASCENDING)));
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshTable() {
|
||||
SwingUtilities.invokeLater(this::loadData);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,140 @@
|
|||
package jnet.client.gui.serversettings;
|
||||
|
||||
import jnet.client.Client;
|
||||
import jnet.client.gui.dialog.UserDialog;
|
||||
import jnet.lib.ResourceLoader;
|
||||
import jnet.lib.object.User;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class TableUsers extends JTable {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(TableUsers.class.getName());
|
||||
|
||||
private static final ImageIcon ICON_YES;
|
||||
private static final ImageIcon ICON_NO;
|
||||
|
||||
static {
|
||||
ImageIcon yes = null, no = null;
|
||||
try {
|
||||
yes = new ImageIcon(ImageIO.read(ResourceLoader.getFile("img/yes.png")));
|
||||
no = new ImageIcon(ImageIO.read(ResourceLoader.getFile("img/no.png")));
|
||||
} catch (IOException e) {
|
||||
LOG.log(Level.SEVERE, "Failed to load yes/no icons", e);
|
||||
}
|
||||
ICON_YES = yes;
|
||||
ICON_NO = no;
|
||||
}
|
||||
|
||||
private static final String[] COLUMN_NAMES = {
|
||||
"ID", "Uživatel", "Přidat mapu", "Odebrat mapu",
|
||||
"Upravit mapu", "Přidat objekt", "Odebrat objekt",
|
||||
"Upravit objekt", "Nastavit server"
|
||||
};
|
||||
|
||||
private DefaultTableModel model;
|
||||
|
||||
public TableUsers() {
|
||||
initTable();
|
||||
}
|
||||
|
||||
private void initTable() {
|
||||
model = new DefaultTableModel(COLUMN_NAMES, 0) {
|
||||
@Override
|
||||
public boolean isCellEditable(int row, int column) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getColumnClass(int column) {
|
||||
return column > 1 ? ImageIcon.class : super.getColumnClass(column);
|
||||
}
|
||||
};
|
||||
|
||||
setModel(model);
|
||||
setRowHeight(25);
|
||||
|
||||
loadData();
|
||||
|
||||
// Renderer pro sloupec s obrázky (sloupec 1 = "Uživatel" – ale my tam dáváme text,
|
||||
// takže ho necháme default, obrázky jsou až od sloupce 2)
|
||||
// Pro sloupce s obrázky použijeme ImageRenderer
|
||||
for (int i = 2; i < getColumnCount(); i++) {
|
||||
getColumnModel().getColumn(i).setCellRenderer(new ImageRenderer());
|
||||
}
|
||||
|
||||
// Dvojklik pro editaci
|
||||
addMouseListener(new java.awt.event.MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(java.awt.event.MouseEvent e) {
|
||||
if (e.getClickCount() == 2) {
|
||||
int row = getSelectedRow();
|
||||
if (row != -1) {
|
||||
int id = (int) getValueAt(row, 0);
|
||||
Client.users.stream()
|
||||
.filter(u -> u.getId() == id)
|
||||
.findFirst()
|
||||
.ifPresent(user -> {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
UserDialog dialog = new UserDialog(user, false);
|
||||
dialog.setVisible(true);
|
||||
refreshTable();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void loadData() {
|
||||
model.setRowCount(0);
|
||||
|
||||
for (User u : Client.users) {
|
||||
model.addRow(new Object[]{
|
||||
u.getId(),
|
||||
u.getUsername(),
|
||||
u.isAddMap() ? ICON_YES : ICON_NO,
|
||||
u.isRemoveMap() ? ICON_YES : ICON_NO,
|
||||
u.isEditMap() ? ICON_YES : ICON_NO,
|
||||
u.isAddObject() ? ICON_YES : ICON_NO,
|
||||
u.isRemoveObject() ? ICON_YES : ICON_NO,
|
||||
u.isEditObject() ? ICON_YES : ICON_NO,
|
||||
u.isEditServer() ? ICON_YES : ICON_NO
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshTable() {
|
||||
SwingUtilities.invokeLater(this::loadData);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Vlastní renderer pro sloupce s obrázky
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
private static class ImageRenderer extends DefaultTableCellRenderer {
|
||||
@Override
|
||||
public Component getTableCellRendererComponent(JTable table, Object value,
|
||||
boolean isSelected, boolean hasFocus,
|
||||
int row, int column) {
|
||||
JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
||||
if (value instanceof ImageIcon) {
|
||||
label.setIcon((ImageIcon) value);
|
||||
label.setText(null);
|
||||
label.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
} else {
|
||||
label.setIcon(null);
|
||||
label.setText(value != null ? value.toString() : "");
|
||||
}
|
||||
return label;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import jnet.lib.Message;
|
||||
|
||||
|
||||
public class MessageRegister {
|
||||
|
||||
private final Map<Integer, Register> register = new HashMap<>();
|
||||
|
||||
// Konstruktor - při vytvoření registru se sám naplní
|
||||
public MessageRegister() {
|
||||
register.put(Message.CLIENT_UPDATE, new RegisterClientUpdate());
|
||||
register.put(Message.AUTH_REQUEST, new RegisterAuthRequest());
|
||||
register.put(Message.AUTH_OK, new RegisterAuthOk());
|
||||
register.put(Message.ONLINE_CLIENTS, new RegisterOnlineClients());
|
||||
register.put(Message.SITE_LIST, new RegisterSiteList());
|
||||
register.put(Message.SITE_NEW, new RegisterSiteNew());
|
||||
register.put(Message.NODE_STATUS_CHANGE, new RegisterNodeStatusChange());
|
||||
register.put(Message.SERVER_CONFIG, new RegisterServerConfig());
|
||||
register.put(Message.NODE_ICON_REFRESH, new RegisterNodeIconRefresh());
|
||||
register.put(Message.NODE_ICON_LIST, new RegisterNodeIconList());
|
||||
register.put(Message.USER_LIST, new RegisterUserList());
|
||||
register.put(Message.USER_REFRESH, new RegisterUserRefresh());
|
||||
register.put(Message.USER_INFO, new RegisterUserInfo());
|
||||
register.put(Message.EVENT_LIST, new RegisterEventList());
|
||||
register.put(Message.EVENT_NEW, new RegisterEventNew());
|
||||
register.put(Message.EVENT_UPDATE, new RegisterEventUpdate());
|
||||
register.put(Message.NODE_CHANGE_POSITION, new RegisterNodeChangePosition());
|
||||
register.put(Message.NODE_NEW, new RegisterNodeNew());
|
||||
register.put(Message.SITE_LOCK, new RegisterSiteLock());
|
||||
register.put(Message.NODE_REMOVE, new RegisterNodeRemove());
|
||||
register.put(Message.NODE_UPDATE, new RegisterNodeUpdate());
|
||||
register.put(Message.SNMP_PROFILE_LIST, new RegisterSnmpProfileList());
|
||||
register.put(Message.SNMP_TEST_RESULT, new RegisterSnmpTestResult());
|
||||
register.put(Message.SERVER_UPTIME_RESULT, null);
|
||||
register.put(Message.NODE_SNMP_INFO_RESULT, new RegisterSnmpNodeInfoResult());
|
||||
register.put(Message.NODE_SNMP_INTERFACE_RESULT, new RegisterSnmpNodeInterfaceResult());
|
||||
register.put(Message.NODE_CONNECTION_ADD, new RegisterNodeConnectionAdd());
|
||||
register.put(Message.NODE_CONNECTION_SNMP_INTERFACE_RESULT, new RegisterNodeConnectionSnmpInterfaceResult());
|
||||
register.put(Message.NODE_CONNECTION_TRAFFIC, new RegisterNodeConnectionTraffic());
|
||||
register.put(Message.SNMP_TEMPLATE_LIST, new RegisterSnmpTemplate());
|
||||
register.put(Message.SNMP_TEMPLATE_VALUE_MAP_LIST, new RegisterSnmpValueMapList());
|
||||
register.put(Message.SNMP_PROBE_VALUE, new RegisterSnmpProbeResult());
|
||||
register.put(Message.NODE_CONNECTION_REMOVE, new RegisterNodeConnectionRemove());
|
||||
|
||||
}
|
||||
|
||||
public Register getRegister(int typ) {
|
||||
return register.get(typ);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import jnet.lib.Message;
|
||||
|
||||
|
||||
public interface Register {
|
||||
void processing(ChannelHandlerContext ctx, Message msg);
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import jnet.client.gui.Window;
|
||||
import jnet.lib.Message;
|
||||
|
||||
|
||||
public class RegisterAuthOk implements Register {
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
|
||||
Window.setStatusBarMessage("Připojeno");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import jnet.client.Client;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.PasswordHashing;
|
||||
import jnet.lib.object.OnlineClients;
|
||||
|
||||
|
||||
public class RegisterAuthRequest implements Register {
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
String user = Client.config.getString("user");
|
||||
String password = Client.config.getString("password");
|
||||
String platform = String.valueOf(OnlineClients.PLATFORM_PC);
|
||||
String[] auth_data = {user, password, platform};
|
||||
|
||||
ctx.writeAndFlush(new Message(Message.AUTH_DATA, auth_data));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import jnet.lib.Message;
|
||||
|
||||
|
||||
public class RegisterClientUpdate implements Register {
|
||||
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import java.util.List;
|
||||
import jnet.client.Client;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.Event;
|
||||
|
||||
|
||||
public class RegisterEventList implements Register {
|
||||
|
||||
public RegisterEventList() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
Client.events = (List<Event>) msg.getMsg();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import jnet.client.Client;
|
||||
import jnet.client.gui.Window;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.Event;
|
||||
|
||||
|
||||
public class RegisterEventNew implements Register {
|
||||
|
||||
public RegisterEventNew() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
Event e = (Event) msg.getMsg();
|
||||
Client.events.add(e);
|
||||
Window.refreshEventsIfVisible();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import jnet.client.Client;
|
||||
import jnet.client.gui.Window;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.Event;
|
||||
|
||||
|
||||
public class RegisterEventUpdate implements Register {
|
||||
|
||||
public RegisterEventUpdate() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
Event e = (Event) msg.getMsg();
|
||||
for (Event event : Client.events) {
|
||||
if (e.getId() == event.getId()) {
|
||||
event.setEnd(e.getEnd());
|
||||
Window.refreshEventsIfVisible();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import jnet.client.Client;
|
||||
import jnet.client.gui.Window;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.Node;
|
||||
import jnet.lib.object.Site;
|
||||
|
||||
|
||||
public class RegisterNodeChangePosition implements Register {
|
||||
|
||||
public RegisterNodeChangePosition() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
int[] data = (int[]) msg.getMsg();
|
||||
int nodeId = data[0];
|
||||
int x = data[1];
|
||||
int y = data[2];
|
||||
|
||||
// najit node v seznamu a upravit mu pozici
|
||||
boolean changed = false;
|
||||
for (Site site : Client.site) {
|
||||
for (Node node : site.getNode()) {
|
||||
if (node.getId() == nodeId) {
|
||||
// zmenit v seznamu
|
||||
node.setX(x);
|
||||
node.setY(y);
|
||||
// aktualizovat v map view
|
||||
Window.updateNodePositionInMapView(nodeId, x, y);
|
||||
changed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (changed) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import jnet.client.Client;
|
||||
import jnet.client.gui.Window;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.NodeConnection;
|
||||
import jnet.lib.object.Site;
|
||||
|
||||
public class RegisterNodeConnectionAdd implements Register {
|
||||
|
||||
public RegisterNodeConnectionAdd() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
NodeConnection nc = (NodeConnection) msg.getMsg();
|
||||
|
||||
for (Site site : Client.site) {
|
||||
if (site.getId() == nc.getSite()) {
|
||||
// ulozeni do mistniho seznamu
|
||||
site.getNodeConnection().add(nc);
|
||||
// aktualizace map view
|
||||
Window.refreshMapView(site);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import jnet.client.Client;
|
||||
import jnet.client.gui.Window;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.Site;
|
||||
|
||||
|
||||
public class RegisterNodeConnectionRemove implements Register{
|
||||
|
||||
public RegisterNodeConnectionRemove() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
int id = (int) msg.getMsg();
|
||||
|
||||
// smazani z lokalniho seznamu
|
||||
for (Site site : Client.site) {
|
||||
// odebere ze seznamu
|
||||
site.getNodeConnection().removeIf(nodeConnection -> nodeConnection.getId() == id);
|
||||
// akutalizace gui
|
||||
Window.refreshCurrentMapView();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import java.awt.Window;
|
||||
import java.util.List;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.SwingUtilities;
|
||||
import jnet.client.gui.dialog.ConnectionDialog;
|
||||
import jnet.client.gui.dialog.node.NodeDeviceDialog;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.Interface;
|
||||
|
||||
|
||||
public class RegisterNodeConnectionSnmpInterfaceResult implements Register {
|
||||
|
||||
public RegisterNodeConnectionSnmpInterfaceResult() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
Object[] data = (Object[]) msg.getMsg();
|
||||
String frameName = (String) data[0];
|
||||
List<Interface> iface = (List<Interface>) data[1];
|
||||
|
||||
for (Window w : JFrame.getWindows()) {
|
||||
if (w instanceof JFrame && frameName.equals(w.getName())) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
((ConnectionDialog) w).updateInterface(iface);
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import java.util.List;
|
||||
import jnet.client.Client;
|
||||
import jnet.client.gui.Window;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.NodeConnection;
|
||||
import jnet.lib.object.Site;
|
||||
import jnet.lib.object.TrafficData;
|
||||
|
||||
|
||||
public class RegisterNodeConnectionTraffic implements Register {
|
||||
|
||||
public RegisterNodeConnectionTraffic() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
List<TrafficData> batch = (List<TrafficData>) msg.getMsg();
|
||||
|
||||
for (TrafficData trafficData : batch) {
|
||||
// projit listy a zapsat traffic ke connection
|
||||
boolean isSet = false;
|
||||
for (Site site : Client.site) {
|
||||
for (NodeConnection nodeConnection : site.getNodeConnection()) {
|
||||
if (nodeConnection.getId() == trafficData.deviceId) {
|
||||
nodeConnection.setRx(trafficData.inBps);
|
||||
nodeConnection.setTx(trafficData.outBps);
|
||||
isSet = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isSet) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// po skonceni aktualizovat gui
|
||||
Window.refreshCurrentMapView();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import java.util.ArrayList;
|
||||
import jnet.client.Client;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.ObjectType;
|
||||
|
||||
|
||||
public class RegisterNodeIconList implements Register{
|
||||
|
||||
public RegisterNodeIconList() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
Client.objectType = (ArrayList<ObjectType>) msg.getMsg();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import jnet.client.gui.serversettings.ServerSettingsPanel;
|
||||
import jnet.client.gui.Window;
|
||||
import jnet.lib.Message;
|
||||
|
||||
|
||||
public class RegisterNodeIconRefresh implements Register{
|
||||
|
||||
public RegisterNodeIconRefresh() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
//novy seznam už byl přijat takže jenom aktualizovat tabulku
|
||||
Window.showServerSettings(ServerSettingsPanel.TAB_DEVICE_TYPE);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import jnet.client.Client;
|
||||
import jnet.client.gui.Window;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.Node;
|
||||
import jnet.lib.object.Site;
|
||||
|
||||
|
||||
public class RegisterNodeNew implements Register{
|
||||
|
||||
public RegisterNodeNew() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
Node node = (Node) msg.getMsg();
|
||||
// vlozi do seznamu
|
||||
for (Site site : Client.site) {
|
||||
if (site.getId() == node.getSiteId()) {
|
||||
site.getNode().add(node);
|
||||
Window.addNodeInMapView(node);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import java.util.Objects;
|
||||
import jnet.client.Client;
|
||||
import jnet.client.gui.Window;
|
||||
import jnet.client.gui.maptree.MapTree;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.Site;
|
||||
|
||||
|
||||
public class RegisterNodeRemove implements Register {
|
||||
|
||||
public RegisterNodeRemove() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
int nodeId = (int) msg.getMsg();
|
||||
for (Site site : Client.site) {
|
||||
// odebere ze seznamu
|
||||
site.getNode().removeIf(node -> node.getId() == nodeId);
|
||||
// aktualizuje mapview
|
||||
Window.removeNodeFromMapView(nodeId);
|
||||
}
|
||||
// smazat z eventu
|
||||
Client.events.removeIf(event -> Objects.equals(event.getNode(), nodeId));
|
||||
|
||||
// obnovit gui
|
||||
MapTree.refreshTree();
|
||||
Client.trayIcon.refresh();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import jnet.client.Client;
|
||||
import jnet.client.gui.Window;
|
||||
import jnet.client.gui.maptree.MapTree;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.Status;
|
||||
import jnet.lib.object.Node;
|
||||
import jnet.lib.object.NodeState;
|
||||
import jnet.lib.object.Site;
|
||||
|
||||
public class RegisterNodeStatusChange implements Register {
|
||||
|
||||
public RegisterNodeStatusChange() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
NodeState ns = (NodeState) msg.getMsg();
|
||||
|
||||
// zmení status v seznamu
|
||||
boolean changed = false;
|
||||
|
||||
for (Site site : Client.site) {
|
||||
for (Node node : site.getNode()) {
|
||||
if (node.getId() == ns.getId()) {
|
||||
node.setStatus(ns.getState());
|
||||
changed = true;
|
||||
break; // ukončí vnitřní smyčku
|
||||
}
|
||||
}
|
||||
if (changed) {
|
||||
break; // ukončí vnější smyčku
|
||||
}
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
MapTree.refreshTree();
|
||||
Window.updateNodeStatusInMapView(ns.getId(), ns.getState());
|
||||
Client.trayIcon.refresh();
|
||||
|
||||
if (Client.config.getBoolean("sound")) {
|
||||
boolean newOnline = (ns.getState() == Status.OK);
|
||||
Client.soundManager.evaluateAndPlay(Client.site, newOnline);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import java.util.List;
|
||||
import jnet.client.Client;
|
||||
import jnet.client.gui.Window;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.Node;
|
||||
import jnet.lib.object.Site;
|
||||
|
||||
|
||||
public class RegisterNodeUpdate implements Register{
|
||||
|
||||
public RegisterNodeUpdate() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
Node newNode = (Node) msg.getMsg();
|
||||
for (Site site : Client.site) {
|
||||
List<Node> nodes = site.getNode(); // nebo použijte rozhraní
|
||||
for (int i = 0; i < nodes.size(); i++) {
|
||||
if (nodes.get(i).getId() == newNode.getId()) {
|
||||
// nahradi node v seznamu
|
||||
nodes.set(i, newNode);
|
||||
// aktualizace gui
|
||||
Window.refreshMapView(site);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import java.util.ArrayList;
|
||||
import jnet.client.Client;
|
||||
import jnet.client.gui.Window;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.OnlineClients;
|
||||
|
||||
|
||||
public class RegisterOnlineClients implements Register {
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
Client.onlineClients = (ArrayList<OnlineClients>) msg.getMsg();
|
||||
Window.reloadOnlineClients();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import jnet.client.Client;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.ServerConfig;
|
||||
|
||||
|
||||
public class RegisterServerConfig implements Register{
|
||||
|
||||
public RegisterServerConfig() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
Client.serverConfig = (ServerConfig) msg.getMsg();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import java.util.ArrayList;
|
||||
import jnet.client.Client;
|
||||
import jnet.client.gui.Window;
|
||||
import jnet.client.gui.maptree.MapTree;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.Site;
|
||||
|
||||
|
||||
public class RegisterSiteList implements Register {
|
||||
|
||||
public RegisterSiteList() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
Client.site = (ArrayList<Site>) msg.getMsg();
|
||||
|
||||
MapTree.refreshTree();
|
||||
Client.trayIcon.refresh();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import jnet.client.Client;
|
||||
import jnet.client.gui.Window;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.Site;
|
||||
|
||||
|
||||
public class RegisterSiteLock implements Register {
|
||||
|
||||
public RegisterSiteLock() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
Object[] data = (Object[]) msg.getMsg();
|
||||
|
||||
for (Site site : Client.site) {
|
||||
if (site.getId() == (int) data[0]) {
|
||||
// zamknout v lokalnim seznamu
|
||||
site.setLock((boolean) data[1]);
|
||||
// aktualizovat mapview
|
||||
Window.refreshMapView(site);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import java.util.ArrayList;
|
||||
import jnet.client.Client;
|
||||
import jnet.client.gui.maptree.MapTree;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.Site;
|
||||
|
||||
|
||||
public class RegisterSiteNew implements Register {
|
||||
|
||||
public RegisterSiteNew() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
Client.site.add((Site) msg.getMsg());
|
||||
|
||||
MapTree.refreshTree();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import java.awt.Window;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.SwingUtilities;
|
||||
import jnet.client.gui.dialog.node.NodeDeviceDialog;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.DeviceInfo;
|
||||
|
||||
|
||||
public class RegisterSnmpNodeInfoResult implements Register {
|
||||
|
||||
public RegisterSnmpNodeInfoResult() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
Object[] data = (Object[]) msg.getMsg();
|
||||
String frameName = (String) data[0];
|
||||
DeviceInfo info = (DeviceInfo) data[1];
|
||||
|
||||
for (Window w : JFrame.getWindows()) {
|
||||
if (w instanceof JFrame && frameName.equals(w.getName())) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
((NodeDeviceDialog) w).setDeviceInfo(info);
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import java.awt.Window;
|
||||
import java.util.List;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.SwingUtilities;
|
||||
import jnet.client.gui.dialog.node.NodeDeviceDialog;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.Interface;
|
||||
|
||||
|
||||
public class RegisterSnmpNodeInterfaceResult implements Register {
|
||||
|
||||
public RegisterSnmpNodeInterfaceResult() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
Object[] data = (Object[]) msg.getMsg();
|
||||
String frameName = (String) data[0];
|
||||
List<Interface> iface = (List<Interface>) data[1];
|
||||
|
||||
for (Window w : JFrame.getWindows()) {
|
||||
if (w instanceof JFrame && frameName.equals(w.getName())) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
((NodeDeviceDialog) w).setDeviceInterface(iface);
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import java.util.List;
|
||||
import jnet.client.Client;
|
||||
import jnet.client.gui.Window;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.Node;
|
||||
import jnet.lib.object.NodeProbe;
|
||||
import jnet.lib.object.Site;
|
||||
import jnet.lib.object.SnmpResult;
|
||||
|
||||
public class RegisterSnmpProbeResult implements Register {
|
||||
|
||||
public RegisterSnmpProbeResult() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
List<SnmpResult> batch = (List<SnmpResult>) msg.getMsg();
|
||||
|
||||
for (SnmpResult result : batch) {
|
||||
for (Site site : Client.site) {
|
||||
for (Node node : site.getNode()) {
|
||||
for (NodeProbe nodeProbe : node.getProbe()) {
|
||||
if (nodeProbe.getId() == result.getTaskId()) {
|
||||
nodeProbe.setValue(result.getValue());
|
||||
Window.refreshCurrentMapView();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import java.util.ArrayList;
|
||||
import jnet.client.Client;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.SnmpProfile;
|
||||
|
||||
|
||||
public class RegisterSnmpProfileList implements Register {
|
||||
|
||||
public RegisterSnmpProfileList() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
Client.snmpProfile = (ArrayList<SnmpProfile>) msg.getMsg();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import java.util.List;
|
||||
import jnet.client.Client;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.SnmpTemplate;
|
||||
|
||||
|
||||
public class RegisterSnmpTemplate implements Register{
|
||||
|
||||
public RegisterSnmpTemplate() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
Client.snmpTemplate = (List<SnmpTemplate>) msg.getMsg();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import java.awt.Window;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.SwingUtilities;
|
||||
import jnet.client.gui.dialog.node.NodeDeviceDialog;
|
||||
import jnet.lib.Message;
|
||||
|
||||
|
||||
public class RegisterSnmpTestResult implements Register{
|
||||
|
||||
public RegisterSnmpTestResult() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
Object[] data = (Object[]) msg.getMsg();
|
||||
String frameName = (String) data[0];
|
||||
boolean result = (boolean) data[1];
|
||||
|
||||
for (Window w : JFrame.getWindows()) {
|
||||
if (w instanceof JFrame && frameName.equals(w.getName())) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
((NodeDeviceDialog) w).showResultSnmpTest(result);
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import java.util.List;
|
||||
import jnet.client.Client;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.SnmpValueMap;
|
||||
|
||||
|
||||
public class RegisterSnmpValueMapList implements Register {
|
||||
|
||||
public RegisterSnmpValueMapList() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
Client.snmpValueMap = (List<SnmpValueMap>) msg.getMsg();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import javax.swing.SwingUtilities;
|
||||
import jnet.client.Client;
|
||||
import jnet.client.gui.Window;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.User;
|
||||
|
||||
public class RegisterUserInfo implements Register {
|
||||
|
||||
public RegisterUserInfo() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
Client.user = (User) msg.getMsg();
|
||||
// překresleni okna
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
Window.getInstance().reloadWindow();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import java.util.ArrayList;
|
||||
import jnet.client.Client;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.User;
|
||||
|
||||
|
||||
public class RegisterUserList implements Register{
|
||||
|
||||
public RegisterUserList() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
Client.users = (ArrayList<User>) msg.getMsg();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package jnet.client.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import jnet.client.gui.Window;
|
||||
import jnet.client.gui.serversettings.ServerSettingsPanel;
|
||||
import jnet.lib.Message;
|
||||
|
||||
|
||||
public class RegisterUserRefresh implements Register{
|
||||
|
||||
public RegisterUserRefresh() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
//novy seznam už byl přijat takže jenom aktualizovat tabulku
|
||||
Window.showServerSettings(ServerSettingsPanel.TAB_USERS);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
; File created : 16.08.2026 19:43:43
|
||||
|
||||
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,53 @@
|
|||
[Form]
|
||||
IPaddr=10.0.0.253:5020
|
||||
IPpassw=20BaRac20
|
||||
patha=
|
||||
pathac=
|
||||
pathaq=
|
||||
pathan=
|
||||
pathas=
|
||||
patha4=
|
||||
patha5=
|
||||
patha5r=
|
||||
save_filename=c:\sms\
|
||||
q_dbl=
|
||||
pathb=
|
||||
pathbs=
|
||||
pathb4=
|
||||
pathb5=
|
||||
Top=100
|
||||
Left=100
|
||||
Width=1000
|
||||
Height=680
|
||||
serreq=0.8
|
||||
pathpvgf=
|
||||
pathpvgc=
|
||||
scanrate=1
|
||||
unitable_sortn=100
|
||||
unitable_sortd=100
|
||||
enable_broad=1
|
||||
qpc66=0
|
||||
qpc28=0
|
||||
wrlastst=0
|
||||
ensysname=0
|
||||
passwvisible=1
|
||||
[Uback]
|
||||
0=10.0.0.253:5020
|
||||
1=
|
||||
2=
|
||||
3=
|
||||
4=
|
||||
5=
|
||||
6=
|
||||
7=
|
||||
8=
|
||||
9=
|
||||
[Form3]
|
||||
Top=100
|
||||
Left=100
|
||||
[Form4]
|
||||
Top=100
|
||||
Left=100
|
||||
[Form5]
|
||||
Top=100
|
||||
Left=100
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,13 @@
|
|||
debug = true
|
||||
port = 1225
|
||||
server = localhost
|
||||
user = michal
|
||||
start_minimalized=false
|
||||
password = 123555
|
||||
sound.offline.first=sounds/schema1/first_offline.wav
|
||||
sound.offline.other=sounds/schema1/next_offline.wav
|
||||
sound.online.one=sounds/schema1/one_online.wav
|
||||
sound.online.all=sounds/schema1/all_online.wav
|
||||
sound.volume=0.52
|
||||
sound=true
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.7 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.9 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 725 B |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue