diff --git a/README.md b/README.md
index cc0effb..05653ca 100644
--- a/README.md
+++ b/README.md
@@ -5,17 +5,6 @@ Just send a GET, POST, PUT or DELETE HTTP request on a server and get it's respo
# Build
-You need JavaFX 14, you can download it [here](https://gluonhq.com/products/javafx/)
+⚠ Nothing is working for now
-I use the language level 14 of Java, if you want to use Java 11, you need to refactor some Switches/Cases
-
-Tested (and compiled) on Windows 10 and IntelliJ
-
-# Known issues
-
-* Issue with HTTPS on IIS (SSL Handshake failed)
-
-# Binaries
-
-Compiled binaries with installer downloadable [here](https://alexisdelhaie.ovh/dlcenter/endpoint-installer.exe). (There is no fancy web page now)
-This installer are based on [chronos-installer-bootstrap](https://github.com/alexlegarnd/chronos-installer-bootstrap) and [chronos-installer](https://github.com/alexlegarnd/chronos-installer)
\ No newline at end of file
+I use the language level 15 of Java, if you want to use Java 11, you need to refactor some Switches/Cases
diff --git a/javafx.bootstrap/javafx.bootstrap/icon.ico b/javafx.bootstrap/javafx.bootstrap/icon.ico
new file mode 100644
index 0000000..2c0ff3c
Binary files /dev/null and b/javafx.bootstrap/javafx.bootstrap/icon.ico differ
diff --git a/javafx.bootstrap/javafx.bootstrap/javafx.bootstrap.rc b/javafx.bootstrap/javafx.bootstrap/javafx.bootstrap.rc
index 222a172..6ad1bf4 100644
--- a/javafx.bootstrap/javafx.bootstrap/javafx.bootstrap.rc
+++ b/javafx.bootstrap/javafx.bootstrap/javafx.bootstrap.rc
@@ -52,7 +52,7 @@ END
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
-IDI_ICON2 ICON "C:\\Users\\robof\\Downloads\\icon.ico"
+IDI_ICON2 ICON ".\\icon.ico"
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
diff --git a/javafx.bootstrap/javafx.bootstrap/main.cpp b/javafx.bootstrap/javafx.bootstrap/main.cpp
index 72aa108..5365560 100644
--- a/javafx.bootstrap/javafx.bootstrap/main.cpp
+++ b/javafx.bootstrap/javafx.bootstrap/main.cpp
@@ -13,7 +13,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdParam
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
- LPTSTR command = _tcsdup(TEXT(".\\runtime\\bin\\javaw.exe --module-path \".\\lib\" --add-modules javafx.controls,javafx.fxml -jar .\\app\\EndPoint.jar"));
+ LPTSTR command = _tcsdup(TEXT(".\\runtime\\bin\\javaw.exe -cp .\\app\\EndPoint.jar ovh.alexisdelhaie.endpoint.Application"));
if (!CreateProcess(NULL, command, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
{
CloseHandle(&pi.hProcess);
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..d11feaa
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,36 @@
+
+
+ 4.0.0
+
+ ovh.alexisdelhaie
+ EndPoint
+ 0.1.3
+
+
+ 15
+
+
+
+
+
+ com.fasterxml.jackson.core
+ jackson-core
+ 2.11.3
+
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+ 2.11.3
+
+
+
+ com.formdev
+ flatlaf
+ 0.43
+
+
+
+
\ No newline at end of file
diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF
deleted file mode 100644
index 091c70a..0000000
--- a/src/META-INF/MANIFEST.MF
+++ /dev/null
@@ -1,3 +0,0 @@
-Manifest-Version: 1.0
-Main-Class: ovh.alexisdelhaie.endpoint.Main
-
diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..c0393eb
--- /dev/null
+++ b/src/main/java/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Main-Class: ovh.alexisdelhaie.endpoint.Application
+
diff --git a/src/main/java/ovh/alexisdelhaie/endpoint/Application.java b/src/main/java/ovh/alexisdelhaie/endpoint/Application.java
new file mode 100644
index 0000000..0f65b7b
--- /dev/null
+++ b/src/main/java/ovh/alexisdelhaie/endpoint/Application.java
@@ -0,0 +1,21 @@
+package ovh.alexisdelhaie.endpoint;
+
+import com.formdev.flatlaf.FlatIntelliJLaf;
+import ovh.alexisdelhaie.endpoint.utils.Tools;
+
+import javax.swing.*;
+import java.awt.*;
+import java.io.IOException;
+
+public class Application {
+
+ public static void main(String[] args) throws UnsupportedLookAndFeelException, IOException {
+ UIManager.setLookAndFeel(new FlatIntelliJLaf());
+ MainWindow dialog = new MainWindow();
+ dialog.pack();
+ dialog.setTitle("EndPoint");
+ dialog.setVisible(true);
+ Tools.centerFrame(dialog);
+ }
+
+}
diff --git a/src/main/java/ovh/alexisdelhaie/endpoint/MainWindow.form b/src/main/java/ovh/alexisdelhaie/endpoint/MainWindow.form
new file mode 100644
index 0000000..83b9eb6
--- /dev/null
+++ b/src/main/java/ovh/alexisdelhaie/endpoint/MainWindow.form
@@ -0,0 +1,127 @@
+
+
diff --git a/src/main/java/ovh/alexisdelhaie/endpoint/MainWindow.java b/src/main/java/ovh/alexisdelhaie/endpoint/MainWindow.java
new file mode 100644
index 0000000..354d1f1
--- /dev/null
+++ b/src/main/java/ovh/alexisdelhaie/endpoint/MainWindow.java
@@ -0,0 +1,243 @@
+package ovh.alexisdelhaie.endpoint;
+
+import ovh.alexisdelhaie.endpoint.builder.TabBuilder;
+import ovh.alexisdelhaie.endpoint.configuration.ConfigurationDialog;
+import ovh.alexisdelhaie.endpoint.configuration.ConfigurationProperties;
+import ovh.alexisdelhaie.endpoint.http.HttpClient;
+import ovh.alexisdelhaie.endpoint.http.Request;
+import ovh.alexisdelhaie.endpoint.http.RequestBuilder;
+import ovh.alexisdelhaie.endpoint.http.Response;
+import ovh.alexisdelhaie.endpoint.utils.MessageDialog;
+
+import javax.imageio.ImageIO;
+import javax.swing.*;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
+import java.awt.*;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.io.IOException;
+import java.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
+import java.util.HashMap;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class MainWindow extends JFrame {
+
+ private enum StatusColor {
+ INFORMATION("#53baf5"),
+ SUCCESS("#7ccf16"),
+ REDIRECTION("#b153f5"),
+ ERROR_CLIENT("#f5ca53"),
+ ERROR_SERVER("#f55353");
+
+ private final String hex;
+
+ StatusColor(String s) {
+ hex = s;
+ }
+
+ public String getHex() {
+ return hex;
+ }
+ }
+
+ // Constants
+ public final static int WIDTH = 1280;
+ public final static int HEIGHT = 720;
+
+ private JPanel contentPane;
+ private JComboBox methodBox;
+ private JTextField urlField;
+ private JButton sendButton;
+ private JTabbedPane tabbedPane1;
+ private JButton newTabButton;
+ private JProgressBar progressBar1;
+ private JLabel statusLabel;
+ private JButton settingsButton;
+
+ private final ConfigurationProperties props;
+ private final HashMap urls;
+
+ private final ConcurrentHashMap controlState;
+ private final ConcurrentHashMap responses;
+
+ public MainWindow() throws IOException {
+ props = new ConfigurationProperties();
+ controlState = new ConcurrentHashMap<>();
+ responses = new ConcurrentHashMap<>();
+ urls = new HashMap<>();
+ setIconImage(ImageIO.read(MainWindow.class.getResource("/icon.png")));
+ setContentPane(contentPane);
+ setMinimumSize(new Dimension(WIDTH, HEIGHT));
+ setSize(WIDTH, HEIGHT);
+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ TabBuilder.create(tabbedPane1, "New request", urls, urlField);
+ Component tab = tabbedPane1.getSelectedComponent();
+ urls.put(tab.hashCode(), "");
+ enableControl(true, tab.hashCode());
+ settingsButton.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ super.mouseClicked(e);
+ ConfigurationDialog.showDialog(props);
+ }
+ });
+ newTabButton.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ super.mouseClicked(e);
+ TabBuilder.create(tabbedPane1, "New request", urls, urlField);
+ Component tab = tabbedPane1.getSelectedComponent();
+ urls.put(tab.hashCode(), "");
+ enableControl(true, tab.hashCode());
+ showStatus(tab.hashCode());
+ }
+ });
+ sendButton.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ super.mouseClicked(e);
+ if (!urlField.getText().isBlank()) {
+ sendRequest();
+ } else {
+ MessageDialog.info("Url field empty", "Please enter an url");
+ }
+ }
+ });
+ tabbedPane1.addChangeListener(e -> {
+ if (tabbedPane1.getSelectedIndex() != -1) {
+ int hashCode = tabbedPane1.getSelectedComponent().hashCode();
+ urlField.setText(urls.get(hashCode));
+ enableControl(controlState.get(hashCode), hashCode);
+ showStatus(tab.hashCode());
+ }
+ });
+ urlField.getDocument().addDocumentListener(new DocumentListener() {
+ public void changedUpdate(DocumentEvent e) {
+ warn();
+ }
+ public void removeUpdate(DocumentEvent e) {
+ warn();
+ }
+ public void insertUpdate(DocumentEvent e) {
+ warn();
+ }
+
+ public void warn() {
+ if (tabbedPane1.getSelectedIndex() != -1) {
+ urls.put(tabbedPane1.getSelectedComponent().hashCode(), urlField.getText());
+ }
+ }
+ });
+ }
+
+ private void sendRequest() {
+ Optional possibleTab = getSelectedTab();
+ if (possibleTab.isPresent()) {
+ JSplitPane tab = possibleTab.get();
+ int tabHashCode = tab.hashCode();
+ statusLabel.setVisible(false);
+ enableControl(false, tabHashCode);
+ int i = tabbedPane1.indexOfComponent(tab);
+ JTextArea responseBody = TabBuilder.getResponseArea(i);
+ responseBody.setForeground(Color.black);
+ responseBody.setText("");
+ JTextArea bodyField = TabBuilder.getBody(i);
+ new Thread(() -> {
+ try {
+ String url = urlField.getText();
+ HttpClient h = new HttpClient(props);
+ Request r = new RequestBuilder(url)
+ .setCustomHeaders(TabBuilder.getHeaders(i))
+ .build();
+ Optional possibleRes = Optional.empty();
+ switch ((String) Objects.requireNonNull(methodBox.getSelectedItem())) {
+ case "GET" -> possibleRes = h.get(r);
+ case "POST" -> possibleRes = h.post(r, bodyField.getText());
+ case "PUT" -> possibleRes = h.put(r, bodyField.getText());
+ case "DELETE" -> possibleRes = h.delete(r);
+ case "HEAD" -> possibleRes = h.head(r);
+ }
+ if (possibleRes.isPresent()) {
+ Response res = possibleRes.get();
+ responses.put(tabHashCode, res);
+ responseBody.setText(res.getBody());
+ }
+ } catch (KeyManagementException | IOException | NoSuchAlgorithmException e) {
+ responseBody.setForeground(Color.red);
+ responseBody.setText(e.getMessage());
+ if (responses.containsKey(tabHashCode)) {
+ responses.remove(tabHashCode);
+ showStatus(tabHashCode);
+ }
+ } finally {
+ enableControl(true, tabHashCode);
+ showStatus(tabHashCode);
+ }
+ }).start();
+ } else {
+ MessageDialog.error("Error", "Cannot get current tab");
+ }
+ }
+
+ private void enableControl(Boolean state, int hashCode) {
+ if (Objects.nonNull(state)) {
+ controlState.put(hashCode, state);
+ if (tabbedPane1.getSelectedComponent().hashCode() == hashCode) {
+ sendButton.setEnabled(state);
+ urlField.setEnabled(state);
+ methodBox.setEnabled(state);
+ progressBar1.setIndeterminate(!state);
+ }
+ }
+ }
+
+ private void showStatus(int hashCode) {
+ if (controlState.get(hashCode) && responses.containsKey(hashCode) &&
+ tabbedPane1.getSelectedComponent().hashCode() == hashCode) {
+ statusLabel.setForeground(Color.BLACK);
+ Response res = responses.get(hashCode);
+ final StringBuilder sb = new StringBuilder();
+ if (res.getStatusCode() != -1) {
+ sb.append(res.getStatusCode())
+ .append(" ")
+ .append(res.getStatus())
+ .append(" (in ")
+ .append(res.getTime())
+ .append(" ms)");
+ if (res.getStatusCode() >= 100 && res.getStatusCode() < 200) {
+ statusLabel.setForeground(Color.decode(StatusColor.INFORMATION.getHex()));
+ } else if (res.getStatusCode() >= 200 && res.getStatusCode() < 300) {
+ statusLabel.setForeground(Color.decode(StatusColor.SUCCESS.getHex()));
+ } else if (res.getStatusCode() >= 300 && res.getStatusCode() < 400) {
+ statusLabel.setForeground(Color.decode(StatusColor.REDIRECTION.getHex()));
+ } else if (res.getStatusCode() >= 400 && res.getStatusCode() < 500) {
+ statusLabel.setForeground(Color.decode(StatusColor.ERROR_CLIENT.getHex()));
+ } else if (res.getStatusCode() >= 500) {
+ statusLabel.setForeground(Color.decode(StatusColor.ERROR_SERVER.getHex()));
+ }
+ } else {
+ sb.append("in ")
+ .append(res.getTime())
+ .append(" ms");
+ }
+
+ statusLabel.setText(sb.toString());
+ statusLabel.setVisible(true);
+ } else {
+ statusLabel.setVisible(false);
+ }
+ }
+
+ private Optional getSelectedTab() {
+ Component c = tabbedPane1.getSelectedComponent();
+ if (c instanceof JSplitPane) {
+ return Optional.of((JSplitPane) c);
+ }
+ return Optional.empty();
+ }
+
+}
diff --git a/src/main/java/ovh/alexisdelhaie/endpoint/builder/TabBuilder.java b/src/main/java/ovh/alexisdelhaie/endpoint/builder/TabBuilder.java
new file mode 100644
index 0000000..881a393
--- /dev/null
+++ b/src/main/java/ovh/alexisdelhaie/endpoint/builder/TabBuilder.java
@@ -0,0 +1,142 @@
+package ovh.alexisdelhaie.endpoint.builder;
+
+import ovh.alexisdelhaie.endpoint.utils.Tools;
+import ovh.alexisdelhaie.endpoint.utils.adapter.CustomDeleteMouseAdapter;
+import ovh.alexisdelhaie.endpoint.utils.adapter.CustomNewMouseAdapter;
+import ovh.alexisdelhaie.endpoint.utils.adapter.DeleteParamMouseAdapter;
+import ovh.alexisdelhaie.endpoint.utils.adapter.NewParamMouseAdapter;
+
+import javax.swing.*;
+import javax.swing.table.DefaultTableModel;
+import java.awt.*;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.util.HashMap;
+
+public class TabBuilder {
+
+ private static final HashMap indexes = new HashMap<>();
+
+ public static void create(JTabbedPane tab, String label, HashMap urls, JTextField urlField) {
+ Component c = tab.add("", buildMainPanel(urlField));
+ int index = tab.indexOfComponent(c);
+ updateIndexes(index);
+ tab.setTabComponentAt(index, buildTabPanel(tab, c, label, urls));
+ tab.setSelectedComponent(c);
+ }
+
+ private static void updateIndexes(int index) {
+ indexes.put("main[" + index + "].responseTextArea", indexes.get("main[waiting].responseTextArea"));
+ indexes.put("main[" + index + "].body", indexes.get("main[waiting].body"));
+ indexes.put("main[" + index + "].params", indexes.get("main[waiting].params"));
+ indexes.put("main[" + index + "].headers", indexes.get("main[waiting].headers"));
+ indexes.remove("main[waiting].responseTextArea");
+ indexes.remove("main[waiting].body");
+ indexes.remove("main[waiting].params");
+ indexes.remove("main[waiting].headers");
+ }
+
+ private static JPanel buildTabPanel(JTabbedPane tab, Component c, String label, HashMap urls) {
+ JPanel p = new JPanel(new GridBagLayout());
+ p.setOpaque(false);
+ JLabel l = new JLabel(label);
+ GridBagConstraints g = new GridBagConstraints();
+ g.gridx = 0;
+ g.gridy = 0;
+ g.weightx = 1;
+ p.add(l, g);
+ g.gridx++;
+ g.weightx = 0;
+ p.add(buildCloseButton(tab, c, urls), g);
+ return p;
+ }
+
+ private static JButton buildCloseButton(JTabbedPane tab, Component c, HashMap urls) {
+ JButton b = new JButton("×");
+ b.setBorderPainted(false);
+ b.setFocusPainted(false);
+ b.setOpaque(false);
+ b.setContentAreaFilled(false);
+ b.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ super.mouseClicked(e);
+ urls.remove(c.hashCode());
+ tab.remove(c);
+ }
+ });
+ return b;
+ }
+
+ private static JSplitPane buildMainPanel(JTextField urlField) {
+ JTextArea t = new JTextArea();
+ t.setBackground(Color.WHITE);
+ t.setEditable(false);
+ JScrollPane sp = new JScrollPane(t);
+ indexes.put("main[waiting].responseTextArea", t);
+ return new JSplitPane(
+ JSplitPane.VERTICAL_SPLIT,
+ buildParametersTabbedPane(urlField),
+ sp
+ );
+ }
+
+ private static JTabbedPane buildParametersTabbedPane(JTextField urlField) {
+ JTabbedPane p = new JTabbedPane();
+ p.add("Params", buildParamsTab(true, urlField));
+ p.add("Authorization", new JPanel());
+ p.add("Headers", buildParamsTab(false, null));
+ JTextArea body = new JTextArea();
+ indexes.put("main[waiting].body", body);
+ p.add("Body", body);
+ return p;
+ }
+
+ public static JTextArea getResponseArea(int index) {
+ return (JTextArea) indexes.get("main[" + index + "].responseTextArea");
+ }
+
+ public static JTextArea getBody(int index) {
+ return (JTextArea) indexes.get("main[" + index + "].body");
+ }
+
+ public static HashMap getParams(int index) {
+ JTable t = (JTable) indexes.get("main[" + index + "].params");
+ return Tools.tableToHashMap(t);
+ }
+
+ public static HashMap getHeaders(int index) {
+ JTable t = (JTable) indexes.get("main[" + index + "].headers");
+ return Tools.tableToHashMap(t);
+ }
+
+ private static JPanel buildParamsTab(boolean isParam, JTextField urlField) {
+ String[] headers = {"Keys", "Values"};
+ DefaultTableModel model = new DefaultTableModel(new Object[][]{}, headers);
+ JPanel p = new JPanel();
+ JTable t = new JTable(model);
+ indexes.put((isParam) ? "main[waiting].params" : "main[waiting].headers", t);
+ JButton addButton = new JButton("New");
+ JButton delButton = new JButton("Remove");
+ delButton.setEnabled(false);
+ t.getSelectionModel().addListSelectionListener(event -> delButton.setEnabled(t.getSelectedRows().length > 0));
+ if (isParam) {
+ addButton.addMouseListener(new NewParamMouseAdapter(t, urlField));
+ delButton.addMouseListener(new DeleteParamMouseAdapter(t, urlField));
+ } else {
+ addButton.addMouseListener(new CustomNewMouseAdapter(t));
+ delButton.addMouseListener(new CustomDeleteMouseAdapter(t));
+ }
+ p.add(addButton);
+ p.add(delButton);
+ p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
+
+ JPanel pp = new JPanel();
+ pp.add(p);
+ JScrollPane sp = new JScrollPane(t);
+ pp.add(sp);
+ pp.setLayout(new BoxLayout(pp, BoxLayout.Y_AXIS));
+ return pp;
+ }
+
+}
diff --git a/src/main/java/ovh/alexisdelhaie/endpoint/configuration/AboutDialog.form b/src/main/java/ovh/alexisdelhaie/endpoint/configuration/AboutDialog.form
new file mode 100644
index 0000000..4703c1d
--- /dev/null
+++ b/src/main/java/ovh/alexisdelhaie/endpoint/configuration/AboutDialog.form
@@ -0,0 +1,63 @@
+
+
diff --git a/src/main/java/ovh/alexisdelhaie/endpoint/configuration/AboutDialog.java b/src/main/java/ovh/alexisdelhaie/endpoint/configuration/AboutDialog.java
new file mode 100644
index 0000000..d4dc42f
--- /dev/null
+++ b/src/main/java/ovh/alexisdelhaie/endpoint/configuration/AboutDialog.java
@@ -0,0 +1,37 @@
+package ovh.alexisdelhaie.endpoint.configuration;
+
+import ovh.alexisdelhaie.endpoint.utils.Tools;
+
+import javax.swing.*;
+import java.awt.*;
+
+public class AboutDialog extends JDialog {
+
+ public static final int WIDTH = 450;
+ public static final int HEIGHT = 500;
+
+ public static final String VERSION = "0.1.3";
+
+ private JPanel contentPane;
+ private JLabel version;
+ private JLabel javaVersion;
+
+ private AboutDialog() {
+ setContentPane(contentPane);
+ setModal(true);
+ setTitle("About EndPoint");
+ version.setText("Version: " + VERSION + " (NOT FINISHED)");
+ javaVersion.setText("Software: Java " + System.getProperty("java.version") + " (GUI: Java Swing)");
+ }
+
+ public static void showDialog() {
+ AboutDialog dialog = new AboutDialog();
+ dialog.setModal(true);
+ dialog.setMinimumSize(new Dimension(WIDTH, HEIGHT));
+ dialog.setMaximumSize(new Dimension(WIDTH, HEIGHT));
+ dialog.setResizable(false);
+ Tools.centerFrame(dialog);
+ dialog.setVisible(true);
+ }
+
+}
diff --git a/src/main/java/ovh/alexisdelhaie/endpoint/configuration/ConfigurationDialog.form b/src/main/java/ovh/alexisdelhaie/endpoint/configuration/ConfigurationDialog.form
new file mode 100644
index 0000000..f45007c
--- /dev/null
+++ b/src/main/java/ovh/alexisdelhaie/endpoint/configuration/ConfigurationDialog.form
@@ -0,0 +1,175 @@
+
+
diff --git a/src/main/java/ovh/alexisdelhaie/endpoint/configuration/ConfigurationDialog.java b/src/main/java/ovh/alexisdelhaie/endpoint/configuration/ConfigurationDialog.java
new file mode 100644
index 0000000..50ad4c1
--- /dev/null
+++ b/src/main/java/ovh/alexisdelhaie/endpoint/configuration/ConfigurationDialog.java
@@ -0,0 +1,64 @@
+package ovh.alexisdelhaie.endpoint.configuration;
+
+import ovh.alexisdelhaie.endpoint.utils.Tools;
+
+import javax.swing.*;
+import java.awt.*;
+
+public class ConfigurationDialog extends JDialog {
+
+ public static final int WIDTH = 450;
+ public static final int HEIGHT = 700;
+
+ private JPanel contentPane;
+ private JButton buttonOK;
+ private JCheckBox allowInvalidSsl;
+ private JCheckBox allowDowngrade;
+ private JComboBox httpVersion;
+ private JSpinner timeout;
+ private JButton aboutButton;
+
+ private final ConfigurationProperties props;
+
+ private ConfigurationDialog(ConfigurationProperties props) {
+ setContentPane(contentPane);
+ setModal(true);
+ getRootPane().setDefaultButton(buttonOK);
+ setTitle("Settings");
+ this.props = props;
+ buttonOK.addActionListener(e -> onOK());
+ aboutButton.addActionListener(e -> AboutDialog.showDialog());
+ allowInvalidSsl.setSelected(this.props.getBooleanProperty("allowInvalidSsl", false));
+ allowDowngrade.setSelected(this.props.getBooleanProperty("allowDowngrade", true));
+ httpVersion.setSelectedItem(this.props.getStringProperty("httpVersion", "HTTP/1.0"));
+ timeout.setValue(this.props.getIntegerProperty("timeout", 10000));
+
+ allowInvalidSsl.addActionListener((e) -> {
+ this.props.setProperty("allowInvalidSsl", String.valueOf(allowInvalidSsl.isSelected()));
+ });
+ allowDowngrade.addActionListener((e) -> {
+ this.props.setProperty("allowDowngrade", String.valueOf(allowDowngrade.isSelected()));
+ });
+ httpVersion.addActionListener((e) -> {
+ this.props.setProperty("httpVersion", (String) httpVersion.getSelectedItem());
+ });
+ timeout.addChangeListener((e) -> {
+ this.props.setProperty("timeout", String.valueOf(timeout.getValue()));
+ });
+
+ }
+
+ private void onOK() {
+ dispose();
+ }
+
+ public static void showDialog(ConfigurationProperties props) {
+ ConfigurationDialog dialog = new ConfigurationDialog(props);
+ dialog.setModal(true);
+ dialog.setMinimumSize(new Dimension(WIDTH, HEIGHT));
+ dialog.setMaximumSize(new Dimension(WIDTH, HEIGHT));
+ dialog.setResizable(false);
+ Tools.centerFrame(dialog);
+ dialog.setVisible(true);
+ }
+}
diff --git a/src/ovh/alexisdelhaie/endpoint/configuration/ConfigurationProperties.java b/src/main/java/ovh/alexisdelhaie/endpoint/configuration/ConfigurationProperties.java
similarity index 77%
rename from src/ovh/alexisdelhaie/endpoint/configuration/ConfigurationProperties.java
rename to src/main/java/ovh/alexisdelhaie/endpoint/configuration/ConfigurationProperties.java
index a2a5b21..6616350 100644
--- a/src/ovh/alexisdelhaie/endpoint/configuration/ConfigurationProperties.java
+++ b/src/main/java/ovh/alexisdelhaie/endpoint/configuration/ConfigurationProperties.java
@@ -2,7 +2,7 @@ package ovh.alexisdelhaie.endpoint.configuration;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
-import javafx.scene.control.Alert;
+import ovh.alexisdelhaie.endpoint.utils.MessageDialog;
import java.io.File;
import java.io.IOException;
@@ -52,15 +52,18 @@ public class ConfigurationProperties {
return defaultB;
}
+ public int getIntegerProperty(String key, int defaultI) {
+ if (properties.containsKey(key)) {
+ return Integer.parseInt(properties.get(key));
+ }
+ return defaultI;
+ }
+
private void save() {
try {
mapper.writeValue(new File(filepath), properties);
} catch (Exception e) {
- Alert alert = new Alert(Alert.AlertType.ERROR);
- alert.setTitle("Cannot save settings");
- alert.setHeaderText("There was an error while saving settings file");
- alert.setContentText(e.getMessage());
- alert.showAndWait();
+ MessageDialog.error("Cannot save settings", "There was an error while saving settings file");
}
}
@@ -71,11 +74,7 @@ public class ConfigurationProperties {
properties = mapper.readValue(f, new TypeReference