整理格式

This commit is contained in:
peng
2021-10-29 10:52:57 +08:00
parent b74033acf1
commit d674b43a16
20 changed files with 86 additions and 98 deletions

View File

@@ -4,9 +4,6 @@ import com.dayrain.views.HomePage;
import javafx.application.Application; import javafx.application.Application;
import javafx.stage.Stage; import javafx.stage.Stage;
import java.io.File;
public class ApplicationStarter extends Application { public class ApplicationStarter extends Application {
public static void main(String[] args) { public static void main(String[] args) {

View File

@@ -1,14 +1,12 @@
package com.dayrain.component; package com.dayrain.component;
import com.dayrain.utils.FileUtils; import com.dayrain.utils.FileUtils;
import com.fasterxml.jackson.databind.util.BeanUtil;
import java.awt.*;
public class ConfigHolder { public class ConfigHolder {
private static Configuration configuration; private static Configuration configuration;
private ConfigHolder(){} private ConfigHolder() {
}
public synchronized static Configuration init() { public synchronized static Configuration init() {
configuration = FileUtils.load(); configuration = FileUtils.load();

View File

@@ -14,7 +14,7 @@ public class Configuration {
private int intLen; private int intLen;
private List<ServerConfig>serverConfigs; private List<ServerConfig> serverConfigs;
public Configuration() { public Configuration() {
} }

View File

@@ -18,11 +18,11 @@ public class ConsoleLog {
public static void log(ServerUrl serverUrl, String params, String resp) { public static void log(ServerUrl serverUrl, String params, String resp) {
String log = logs.getOrDefault(serverUrl.getServerName(), null); String log = logs.getOrDefault(serverUrl.getServerName(), null);
if(log == null || NO_REQUEST.equals(log)) { if (log == null || NO_REQUEST.equals(log)) {
log = ""; log = "";
} }
if(params == null || "".equals(params)) { if (params == null || "".equals(params)) {
params = ""; params = "";
} }
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
@@ -38,27 +38,18 @@ public class ConsoleLog {
log += stringBuilder.toString(); log += stringBuilder.toString();
logs.put(serverUrl.getServerName(), log); logs.put(serverUrl.getServerName(), log);
if(serverUrl.getServerName().equals(logArea.getServerName())) { if (serverUrl.getServerName().equals(logArea.getServerName())) {
if(NO_REQUEST.equals(logArea.getText())) { if (NO_REQUEST.equals(logArea.getText())) {
logArea.setText(log); logArea.setText(log);
}else { } else {
logArea.appendText(log); logArea.appendText(log);
} }
logArea.setScrollTop(Double.MAX_VALUE); logArea.setScrollTop(Double.MAX_VALUE);
} }
} }
public static String getLog(String serverName) {
if(logs.containsKey(serverName)) {
return logs.get(serverName);
}
logs.put(serverName, NO_REQUEST);
return NO_REQUEST;
}
public static void resetTextArea(String serverName) { public static void resetTextArea(String serverName) {
if(!logs.containsKey(serverName)) { if (!logs.containsKey(serverName)) {
logs.put(serverName, NO_REQUEST); logs.put(serverName, NO_REQUEST);
} }

View File

@@ -24,11 +24,11 @@ public class RequestHandler implements HttpHandler {
public void handle(HttpExchange exchange) throws IOException { public void handle(HttpExchange exchange) throws IOException {
RequestType requestType = serverUrl.getRequestType(); RequestType requestType = serverUrl.getRequestType();
String param = null; String param = null;
if(RequestType.GET.equals(requestType)) { if (RequestType.GET.equals(requestType)) {
param = handleGetRequest(exchange); param = handleGetRequest(exchange);
} }
if(RequestType.POST.equals(requestType)) { if (RequestType.POST.equals(requestType)) {
param = handlePostRequest(exchange); param = handlePostRequest(exchange);
} }
@@ -36,7 +36,7 @@ public class RequestHandler implements HttpHandler {
ConsoleLog.log(serverUrl, param, resp); ConsoleLog.log(serverUrl, param, resp);
response(exchange, resp); response(exchange, resp);
} }
private String handleGetRequest(HttpExchange exchange) { private String handleGetRequest(HttpExchange exchange) {
return exchange.getRequestURI().getQuery(); return exchange.getRequestURI().getQuery();
@@ -50,7 +50,7 @@ public class RequestHandler implements HttpHandler {
private void response(HttpExchange exchange, String jsonBody) { private void response(HttpExchange exchange, String jsonBody) {
try { try {
exchange.sendResponseHeaders(200, jsonBody.length()); exchange.sendResponseHeaders(200, jsonBody.length());
exchange.setAttribute("Content-Type","application/json; charset=utf-8"); exchange.setAttribute("Content-Type", "application/json; charset=utf-8");
OutputStream outputStream = exchange.getResponseBody(); OutputStream outputStream = exchange.getResponseBody();
outputStream.write(jsonBody.getBytes(StandardCharsets.UTF_8)); outputStream.write(jsonBody.getBytes(StandardCharsets.UTF_8));
outputStream.close(); outputStream.close();
@@ -61,7 +61,7 @@ public class RequestHandler implements HttpHandler {
private String replaceResp(String resp) { private String replaceResp(String resp) {
if(resp == null || "".equals(resp)) { if (resp == null || "".equals(resp)) {
return resp; return resp;
} }
@@ -82,14 +82,14 @@ public class RequestHandler implements HttpHandler {
private String randomString(int len) { private String randomString(int len) {
String res = UUID.randomUUID().toString(); String res = UUID.randomUUID().toString();
if(len > res.length()) { if (len > res.length()) {
len = res.length(); len = res.length();
} }
return UUID.randomUUID().toString().substring(0, len); return UUID.randomUUID().toString().substring(0, len);
} }
private int randomInt(int len) { private int randomInt(int len) {
int res = (int) Math.pow(10, len - 1 ); int res = (int) Math.pow(10, len - 1);
return res + (int) (Math.pow(10, len - 1) * Math.random()); return res + (int) (Math.pow(10, len - 1) * Math.random());
} }

View File

@@ -1,5 +1,5 @@
package com.dayrain.component; package com.dayrain.component;
public enum RequestType { public enum RequestType {
GET,POST; GET, POST;
} }

View File

@@ -8,6 +8,7 @@ import java.util.concurrent.Executors;
/** /**
* 服务 * 服务
*
* @author peng * @author peng
* @date 2021/10/25 * @date 2021/10/25
*/ */
@@ -31,14 +32,14 @@ public class Server implements Runnable {
addContext(serverUrl); addContext(serverUrl);
} }
httpServer.start(); httpServer.start();
System.out.println("" +serverConfig.getServerName() + "】服务已开启..."); System.out.println("" + serverConfig.getServerName() + "】服务已开启...");
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
public void stop() { public void stop() {
if(httpServer != null) { if (httpServer != null) {
System.out.println("" + serverConfig.getServerName() + "】服务已关闭..."); System.out.println("" + serverConfig.getServerName() + "】服务已关闭...");
httpServer.stop(0); httpServer.stop(0);
} }

View File

@@ -14,12 +14,12 @@ public class ServerConfig {
/** /**
* 请求url集合 * 请求url集合
*/ */
private List<ServerUrl>serverUrls; private List<ServerUrl> serverUrls;
public ServerConfig() { public ServerConfig() {
} }
public ServerConfig(String serverName, int port, List<ServerUrl>serverUrls) { public ServerConfig(String serverName, int port, List<ServerUrl> serverUrls) {
this.serverName = serverName; this.serverName = serverName;
this.port = port; this.port = port;
this.serverUrls = serverUrls; this.serverUrls = serverUrls;

View File

@@ -22,6 +22,7 @@ import java.util.ArrayList;
/** /**
* 添加server * 添加server
*
* @author peng * @author peng
* @date 2021/10/28 * @date 2021/10/28
*/ */

View File

@@ -29,6 +29,7 @@ import java.util.List;
/** /**
* 添加路径 * 添加路径
*
* @author peng * @author peng
* @date 2021/10/27 * @date 2021/10/27
*/ */
@@ -61,7 +62,7 @@ public class AddUrlHandler implements EventHandler<ActionEvent> {
urlField.setPrefWidth(80); urlField.setPrefWidth(80);
Label methodLabel = LabelFactory.getLabel("请求方式:"); Label methodLabel = LabelFactory.getLabel("请求方式:");
ChoiceBox<String>choiceBox = new ChoiceBox<>(); ChoiceBox<String> choiceBox = new ChoiceBox<>();
choiceBox.setItems(FXCollections.observableArrayList("POST", "GET")); choiceBox.setItems(FXCollections.observableArrayList("POST", "GET"));
choiceBox.setValue("POST"); choiceBox.setValue("POST");
urlField.setPrefWidth(80); urlField.setPrefWidth(80);
@@ -103,7 +104,7 @@ public class AddUrlHandler implements EventHandler<ActionEvent> {
String name = nameField.getText(); String name = nameField.getText();
List<ServerUrl> serverUrls = serverConfig.getServerUrls(); List<ServerUrl> serverUrls = serverConfig.getServerUrls();
for (ServerUrl serverUrl : serverUrls) { for (ServerUrl serverUrl : serverUrls) {
if(serverUrl.getUrlName().equals(name)) { if (serverUrl.getUrlName().equals(name)) {
return; return;
} }
} }
@@ -114,7 +115,7 @@ public class AddUrlHandler implements EventHandler<ActionEvent> {
ServerUrl serverUrl = new ServerUrl(serverConfig.getServerName(), name, url, type.equals(RequestType.POST.name()) ? RequestType.POST : RequestType.GET, resp); ServerUrl serverUrl = new ServerUrl(serverConfig.getServerName(), name, url, type.equals(RequestType.POST.name()) ? RequestType.POST : RequestType.GET, resp);
serverUrls.add(serverUrl); serverUrls.add(serverUrl);
ServerThread serverThread = threadMap.getOrDefault(serverConfig.getServerName(), null); ServerThread serverThread = threadMap.getOrDefault(serverConfig.getServerName(), null);
if(serverThread != null) { if (serverThread != null) {
serverThread.addContext(serverUrl); serverThread.addContext(serverUrl);
} }
ListViewHelper.addAndRefresh(serverUrl, serverUrlListView); ListViewHelper.addAndRefresh(serverUrl, serverUrlListView);

View File

@@ -11,6 +11,7 @@ import java.io.File;
/** /**
* 导出配置文件 * 导出配置文件
*
* @author peng * @author peng
* @date 2021/10/28 * @date 2021/10/28
*/ */
@@ -31,14 +32,14 @@ public class ExportConfigHandler implements EventHandler<ActionEvent> {
stage.initOwner(primaryStage); stage.initOwner(primaryStage);
FileChooser fileChooser = new FileChooser(); FileChooser fileChooser = new FileChooser();
String projectName = configuration.getProjectName(); String projectName = configuration.getProjectName();
if(projectName == null) { if (projectName == null) {
projectName = ""; projectName = "";
} }
projectName += "server"; projectName += "server";
fileChooser.setTitle("导出配置"); fileChooser.setTitle("导出配置");
fileChooser.setInitialFileName(projectName + ".json"); fileChooser.setInitialFileName(projectName + ".json");
File file = fileChooser.showSaveDialog(stage); File file = fileChooser.showSaveDialog(stage);
if(file != null) { if (file != null) {
FileUtils.saveConfig(configuration, file); FileUtils.saveConfig(configuration, file);
} }
} }

View File

@@ -13,6 +13,7 @@ import java.io.File;
/** /**
* 导入配置文件 * 导入配置文件
*
* @author peng * @author peng
* @date 2021/10/28 * @date 2021/10/28
*/ */
@@ -37,7 +38,7 @@ public class ImportConfigHandler implements EventHandler<ActionEvent> {
fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("只能导入json文件", "*.json")); fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("只能导入json文件", "*.json"));
File file = fileChooser.showOpenDialog(stage); File file = fileChooser.showOpenDialog(stage);
if(file != null) { if (file != null) {
Configuration loadConfig = FileUtils.load(file); Configuration loadConfig = FileUtils.load(file);
ConfigHolder.replace(loadConfig); ConfigHolder.replace(loadConfig);
FileUtils.saveConfig(loadConfig); FileUtils.saveConfig(loadConfig);

View File

@@ -10,8 +10,10 @@ import javafx.scene.paint.Color;
import javafx.scene.shape.Circle; import javafx.scene.shape.Circle;
import java.util.HashMap; import java.util.HashMap;
/** /**
* 服务启动与关闭控制器 * 服务启动与关闭控制器
*
* @author peng * @author peng
* @date 2021/10/27 * @date 2021/10/27
*/ */
@@ -35,15 +37,15 @@ public class StartServerHandler implements EventHandler<ActionEvent> {
@Override @Override
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
String serverName = serverConfig.getServerName(); String serverName = serverConfig.getServerName();
if(threadMap.containsKey(serverName)) { if (threadMap.containsKey(serverName)) {
ServerThread serverThread = threadMap.get(serverName); ServerThread serverThread = threadMap.get(serverName);
if(serverThread != null) { if (serverThread != null) {
serverThread.stopServer(); serverThread.stopServer();
} }
threadMap.remove(serverName); threadMap.remove(serverName);
openButton.setText("开启服务"); openButton.setText("开启服务");
statusCircle.setFill(Color.RED); statusCircle.setFill(Color.RED);
}else { } else {
ServerThread serverThread = new ServerThread(new Server(serverConfig)); ServerThread serverThread = new ServerThread(new Server(serverConfig));
serverThread.start(); serverThread.start();
threadMap.put(serverName, serverThread); threadMap.put(serverName, serverThread);

View File

@@ -2,7 +2,6 @@ package com.dayrain.handle;
import com.dayrain.component.ConfigHolder; import com.dayrain.component.ConfigHolder;
import com.dayrain.component.Configuration; import com.dayrain.component.Configuration;
import com.dayrain.component.ServerConfig;
import com.dayrain.style.ButtonFactory; import com.dayrain.style.ButtonFactory;
import com.dayrain.style.LabelFactory; import com.dayrain.style.LabelFactory;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;

View File

@@ -18,7 +18,7 @@ public class ButtonFactory {
button.setText(text); button.setText(text);
button.setPrefWidth(100); button.setPrefWidth(100);
button.setPrefHeight(50); button.setPrefHeight(50);
button.setFont(Font.font("Microsoft YaHei",15)); button.setFont(Font.font("Microsoft YaHei", 15));
button.setTextFill(Color.WHITE); button.setTextFill(Color.WHITE);
button.setBackground(new Background(bgf)); button.setBackground(new Background(bgf));
return button; return button;

View File

@@ -7,7 +7,7 @@ public class LabelFactory {
public static Label getLabel(String text) { public static Label getLabel(String text) {
Label label = new Label(text); Label label = new Label(text);
label.setFont(Font.font("Microsoft YaHei",18)); label.setFont(Font.font("Microsoft YaHei", 18));
return label; return label;
} }
} }

View File

@@ -1,8 +1,6 @@
package com.dayrain.utils; package com.dayrain.utils;
import com.dayrain.ApplicationStarter;
import com.dayrain.component.Configuration; import com.dayrain.component.Configuration;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.BufferedReader; import java.io.BufferedReader;
@@ -10,22 +8,20 @@ import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
public class FileUtils{ public class FileUtils {
public static void saveConfig(Configuration configuration){ public static void saveConfig(Configuration configuration) {
saveConfig(configuration, getConfigFile()); saveConfig(configuration, getConfigFile());
} }
public static void saveConfig(Configuration configuration, File file){ public static void saveConfig(Configuration configuration, File file) {
BufferedWriter bufferedWriter = null; BufferedWriter bufferedWriter = null;
try { try {
@@ -35,9 +31,9 @@ public class FileUtils{
bufferedWriter.flush(); bufferedWriter.flush();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
}finally { } finally {
try { try {
if(bufferedWriter != null) { if (bufferedWriter != null) {
bufferedWriter.close(); bufferedWriter.close();
} }
} catch (IOException e) { } catch (IOException e) {
@@ -63,9 +59,9 @@ public class FileUtils{
return "".equals(configStr.toString()) ? new Configuration(1200, 800, 8, 8) : new ObjectMapper().readValue(configStr.toString(), Configuration.class); return "".equals(configStr.toString()) ? new Configuration(1200, 800, 8, 8) : new ObjectMapper().readValue(configStr.toString(), Configuration.class);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
}finally { } finally {
try { try {
if(bufferedReader != null) { if (bufferedReader != null) {
bufferedReader.close(); bufferedReader.close();
} }
} catch (IOException e) { } catch (IOException e) {
@@ -78,7 +74,7 @@ public class FileUtils{
public static String getFromInputStream(InputStream inputStream) { public static String getFromInputStream(InputStream inputStream) {
try { try {
byte[]buf = new byte[4096]; byte[] buf = new byte[4096];
int len = 0; int len = 0;
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
while ((len = inputStream.read(buf)) != -1) { while ((len = inputStream.read(buf)) != -1) {
@@ -95,10 +91,10 @@ public class FileUtils{
private static File getConfigFile() { private static File getConfigFile() {
String property = System.getProperty("user.dir"); String property = System.getProperty("user.dir");
File file = new File(property + File.separator + "config" + File.separator + "config.json"); File file = new File(property + File.separator + "config" + File.separator + "config.json");
if(!file.exists()) { if (!file.exists()) {
File dir = new File(property + File.separator + "config"); File dir = new File(property + File.separator + "config");
if(!dir.exists()) { if (!dir.exists()) {
dir.mkdirs(); dir.mkdirs();
} }

View File

@@ -6,17 +6,17 @@ import javafx.scene.control.ListView;
public class ListViewHelper { public class ListViewHelper {
public static void addAndRefresh(ServerUrl serverUrl, ListView<ServerUrl>serverUrls) { public static void addAndRefresh(ServerUrl serverUrl, ListView<ServerUrl> serverUrls) {
serverUrls.getItems().add(serverUrl); serverUrls.getItems().add(serverUrl);
refresh(serverUrls); refresh(serverUrls);
} }
public static void deleteAndRefresh(ServerUrl serverUrl, ListView<ServerUrl>serverUrls) { public static void deleteAndRefresh(ServerUrl serverUrl, ListView<ServerUrl> serverUrls) {
serverUrls.getItems().remove(serverUrl); serverUrls.getItems().remove(serverUrl);
refresh(serverUrls); refresh(serverUrls);
} }
public static void refresh(ListView<ServerUrl>serverUrls) { public static void refresh(ListView<ServerUrl> serverUrls) {
ObservableList<ServerUrl> items = serverUrls.getItems(); ObservableList<ServerUrl> items = serverUrls.getItems();
serverUrls.setItems(null); serverUrls.setItems(null);
serverUrls.setItems(items); serverUrls.setItems(items);

View File

@@ -1,7 +1,5 @@
package com.dayrain.views; package com.dayrain.views;
import com.dayrain.handle.UpdateRandomLenHandler;
import com.dayrain.style.ButtonFactory;
import com.dayrain.component.ConfigHolder; import com.dayrain.component.ConfigHolder;
import com.dayrain.component.Configuration; import com.dayrain.component.Configuration;
import com.dayrain.component.ConsoleLog; import com.dayrain.component.ConsoleLog;
@@ -15,11 +13,12 @@ import com.dayrain.handle.DeleteUrlHandler;
import com.dayrain.handle.ExportConfigHandler; import com.dayrain.handle.ExportConfigHandler;
import com.dayrain.handle.ImportConfigHandler; import com.dayrain.handle.ImportConfigHandler;
import com.dayrain.handle.StartServerHandler; import com.dayrain.handle.StartServerHandler;
import com.dayrain.handle.UpdateRandomLenHandler;
import com.dayrain.handle.UpdateServerConfigHandler; import com.dayrain.handle.UpdateServerConfigHandler;
import com.dayrain.handle.UpdateUrlHandler; import com.dayrain.handle.UpdateUrlHandler;
import com.dayrain.server.ServerThread; import com.dayrain.server.ServerThread;
import com.dayrain.style.ButtonFactory;
import com.dayrain.style.LabelFactory; import com.dayrain.style.LabelFactory;
import com.dayrain.utils.FileUtils;
import javafx.beans.binding.Bindings; import javafx.beans.binding.Bindings;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
@@ -47,10 +46,8 @@ import javafx.scene.paint.Color;
import javafx.scene.shape.Circle; import javafx.scene.shape.Circle;
import javafx.scene.text.Font; import javafx.scene.text.Font;
import javafx.stage.Stage; import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import javafx.util.Callback; import javafx.util.Callback;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@@ -63,8 +60,6 @@ public class HomePage {
private HashMap<String, ServerThread> threadMap = new HashMap<>(); private HashMap<String, ServerThread> threadMap = new HashMap<>();
private List<ListView<ServerUrl>> listViews = new ArrayList<>();
private VBox serverContainer; private VBox serverContainer;
private LogArea logArea; private LogArea logArea;
@@ -140,7 +135,7 @@ public class HomePage {
editButton.setOnAction(new UpdateServerConfigHandler(serverConfig, primaryStage)); editButton.setOnAction(new UpdateServerConfigHandler(serverConfig, primaryStage));
deleteButton.setOnAction(new DeleteServerHandler(serverConfig, configuration, this)); deleteButton.setOnAction(new DeleteServerHandler(serverConfig, configuration, this));
headBox.getChildren().addAll(openButton, editButton, deleteButton, addButton, statusCircle); headBox.getChildren().addAll(openButton, editButton, deleteButton, addButton, statusCircle);
HBox.setMargin(statusCircle, new Insets(0,0,0,30)); HBox.setMargin(statusCircle, new Insets(0, 0, 0, 30));
headBox.setSpacing(20d); headBox.setSpacing(20d);
headBox.setAlignment(Pos.CENTER); headBox.setAlignment(Pos.CENTER);
//添加url //添加url
@@ -159,7 +154,7 @@ public class HomePage {
titledPane.setOnMouseClicked(new EventHandler<MouseEvent>() { titledPane.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override @Override
public void handle(MouseEvent event) { public void handle(MouseEvent event) {
if(!serverConfig.getServerName().equals(logArea.getServerName())) { if (!serverConfig.getServerName().equals(logArea.getServerName())) {
ConsoleLog.resetTextArea(serverConfig.getServerName()); ConsoleLog.resetTextArea(serverConfig.getServerName());
} }
} }
@@ -179,15 +174,15 @@ public class HomePage {
serverListViews.setCellFactory(new Callback<ListView<ServerUrl>, ListCell<ServerUrl>>() { serverListViews.setCellFactory(new Callback<ListView<ServerUrl>, ListCell<ServerUrl>>() {
@Override @Override
public ListCell<ServerUrl> call(ListView<ServerUrl> param) { public ListCell<ServerUrl> call(ListView<ServerUrl> param) {
ListCell<ServerUrl> listCell =new ListCell<ServerUrl>() { ListCell<ServerUrl> listCell = new ListCell<ServerUrl>() {
@Override @Override
protected void updateItem(ServerUrl item, boolean empty) { protected void updateItem(ServerUrl item, boolean empty) {
super.updateItem(item, empty); super.updateItem(item, empty);
if(empty || item == null) { if (empty || item == null) {
setText(null); setText(null);
setGraphic(null); setGraphic(null);
}else { } else {
BorderPane urlPane = new BorderPane(); BorderPane urlPane = new BorderPane();
HBox labelBox = new HBox(); HBox labelBox = new HBox();
@@ -202,7 +197,7 @@ public class HomePage {
Button deleteButton = ButtonFactory.getButton("删除"); Button deleteButton = ButtonFactory.getButton("删除");
btnBox.setSpacing(15d); btnBox.setSpacing(15d);
btnBox.getChildren().addAll(configButton, deleteButton); btnBox.getChildren().addAll(configButton, deleteButton);
HBox.setMargin(deleteButton, new Insets(0, 20,0,0)); HBox.setMargin(deleteButton, new Insets(0, 20, 0, 0));
deleteButton.setOnAction(new DeleteUrlHandler(item, serverConfig, serverListViews, HomePage.this)); deleteButton.setOnAction(new DeleteUrlHandler(item, serverConfig, serverListViews, HomePage.this));
configButton.setOnAction(new UpdateUrlHandler(item, serverListViews, primaryStage)); configButton.setOnAction(new UpdateUrlHandler(item, serverListViews, primaryStage));
@@ -227,7 +222,7 @@ public class HomePage {
public void refreshServerContainer() { public void refreshServerContainer() {
serverContainer.getChildren().removeAll(serverContainer.getChildren()); serverContainer.getChildren().removeAll(serverContainer.getChildren());
List<ServerConfig> serverConfigs = configuration.getServerConfigs(); List<ServerConfig> serverConfigs = configuration.getServerConfigs();
if(serverConfigs == null || serverConfigs.size() == 0) { if (serverConfigs == null || serverConfigs.size() == 0) {
serverConfigs = new ArrayList<>(); serverConfigs = new ArrayList<>();
configuration.setServerConfigs(serverConfigs); configuration.setServerConfigs(serverConfigs);
} }
@@ -258,7 +253,7 @@ public class HomePage {
public Background getBackGround() { public Background getBackGround() {
BackgroundFill backgroundFill = new BackgroundFill(Color.GRAY, new CornerRadii(1), BackgroundFill backgroundFill = new BackgroundFill(Color.GRAY, new CornerRadii(1),
new Insets(0.0,0.0,0.0,0.0)); new Insets(0.0, 0.0, 0.0, 0.0));
return new Background(backgroundFill); return new Background(backgroundFill);
} }
} }

View File

@@ -1,21 +1,26 @@
{ {
"projectName" : "HTTP SERVER 模拟器", "projectName": "HTTP SERVER 模拟器",
"width" : 1200, "width": 1200,
"height" : 800, "height": 800,
"serverConfigs" : [ { "serverConfigs": [
"serverName" : "WMS", {
"port" : 8082, "serverName": "WMS",
"serverUrls" : [ { "port": 8082,
"urlName" : "登录", "serverUrls": [
"url" : "/login", {
"serverName" : "WMS", "urlName": "登录",
"requestType" : "POST", "url": "/login",
"responseBody" : "{\n\t\"success\": \"ok\"\n}", "serverName": "WMS",
"headerMap" : null "requestType": "POST",
} ] "responseBody": "{\n\t\"success\": \"ok\"\n}",
}, { "headerMap": null
"serverName" : "WCS", }
"port" : 8083, ]
"serverUrls" : [ ] },
} ] {
"serverName": "WCS",
"port": 8083,
"serverUrls": []
}
]
} }