From af3203a1e2bcbc7adfe4d2b9c382313e53f84253 Mon Sep 17 00:00:00 2001 From: Alexis Delhaie Date: Wed, 16 Sep 2020 18:49:40 +0200 Subject: [PATCH] Cleaning repo --- .gitignore | 84 ++++ README.md | 4 + javafx.bootstrap/.gitignore | 362 +++++++++++++++ javafx.bootstrap/javafx.bootstrap.sln | 31 ++ .../javafx.bootstrap/javafx.bootstrap.rc | 71 +++ .../javafx.bootstrap/javafx.bootstrap.vcxproj | 157 +++++++ .../javafx.bootstrap.vcxproj.filters | 37 ++ javafx.bootstrap/javafx.bootstrap/main.cpp | 32 ++ javafx.bootstrap/javafx.bootstrap/resource.h | 16 + src/META-INF/MANIFEST.MF | 6 + .../alexisdelhaie/endpoint/Controller.java | 413 ++++++++++++++++++ src/ovh/alexisdelhaie/endpoint/Main.java | 32 ++ .../alexisdelhaie/endpoint/URLGenerator.java | 99 +++++ src/ovh/alexisdelhaie/endpoint/about.fxml | 43 ++ src/ovh/alexisdelhaie/endpoint/banner.png | Bin 0 -> 44264 bytes .../alexisdelhaie/endpoint/configuration.fxml | 20 + .../endpoint/http/HttpClient.java | 135 ++++++ .../alexisdelhaie/endpoint/http/Request.java | 102 +++++ .../endpoint/http/RequestBuilder.java | 94 ++++ .../alexisdelhaie/endpoint/http/Response.java | 130 ++++++ src/ovh/alexisdelhaie/endpoint/icon.png | Bin 0 -> 22975 bytes .../alexisdelhaie/endpoint/impl/EditCell.java | 135 ++++++ .../alexisdelhaie/endpoint/mainwindow.fxml | 21 + .../alexisdelhaie/endpoint/model/Param.java | 49 +++ .../alexisdelhaie/endpoint/responsetab.fxml | 58 +++ 25 files changed, 2131 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 javafx.bootstrap/.gitignore create mode 100644 javafx.bootstrap/javafx.bootstrap.sln create mode 100644 javafx.bootstrap/javafx.bootstrap/javafx.bootstrap.rc create mode 100644 javafx.bootstrap/javafx.bootstrap/javafx.bootstrap.vcxproj create mode 100644 javafx.bootstrap/javafx.bootstrap/javafx.bootstrap.vcxproj.filters create mode 100644 javafx.bootstrap/javafx.bootstrap/main.cpp create mode 100644 javafx.bootstrap/javafx.bootstrap/resource.h create mode 100644 src/META-INF/MANIFEST.MF create mode 100644 src/ovh/alexisdelhaie/endpoint/Controller.java create mode 100644 src/ovh/alexisdelhaie/endpoint/Main.java create mode 100644 src/ovh/alexisdelhaie/endpoint/URLGenerator.java create mode 100644 src/ovh/alexisdelhaie/endpoint/about.fxml create mode 100644 src/ovh/alexisdelhaie/endpoint/banner.png create mode 100644 src/ovh/alexisdelhaie/endpoint/configuration.fxml create mode 100644 src/ovh/alexisdelhaie/endpoint/http/HttpClient.java create mode 100644 src/ovh/alexisdelhaie/endpoint/http/Request.java create mode 100644 src/ovh/alexisdelhaie/endpoint/http/RequestBuilder.java create mode 100644 src/ovh/alexisdelhaie/endpoint/http/Response.java create mode 100644 src/ovh/alexisdelhaie/endpoint/icon.png create mode 100644 src/ovh/alexisdelhaie/endpoint/impl/EditCell.java create mode 100644 src/ovh/alexisdelhaie/endpoint/mainwindow.fxml create mode 100644 src/ovh/alexisdelhaie/endpoint/model/Param.java create mode 100644 src/ovh/alexisdelhaie/endpoint/responsetab.fxml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e9e224c --- /dev/null +++ b/.gitignore @@ -0,0 +1,84 @@ +############################## +## Java +############################## +.mtj.tmp/ +*.class +*.jar +*.war +*.ear +*.nar +hs_err_pid* + +############################## +## Maven +############################## +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +pom.xml.bak +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +.mvn/wrapper/maven-wrapper.jar + +############################## +## Gradle +############################## +bin/ +build/ +.gradle +.gradletasknamecache +gradle-app.setting +!gradle-wrapper.jar + +############################## +## IntelliJ +############################## +out/ +.idea/ +.idea_modules/ +*.iml +*.ipr +*.iws + +############################## +## Eclipse +############################## +.settings/ +bin/ +tmp/ +.metadata +.classpath +.project +*.tmp +*.bak +*.swp +*~.nib +local.properties +.loadpath +.factorypath + +############################## +## NetBeans +############################## +nbproject/private/ +build/ +nbbuild/ +dist/ +nbdist/ +nbactions.xml +nb-configuration.xml + +############################## +## Visual Studio Code +############################## +.vscode/ +.code-workspace + +############################## +## OS X +############################## +.DS_Store \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..451965a --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# EndPoint: API Tester +This project replace the ugly [cURLing](https://github.com/alexlegarnd/cURLing) + +It require Gluon JavaFX 14 and Java 14 diff --git a/javafx.bootstrap/.gitignore b/javafx.bootstrap/.gitignore new file mode 100644 index 0000000..3a8542d --- /dev/null +++ b/javafx.bootstrap/.gitignore @@ -0,0 +1,362 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd \ No newline at end of file diff --git a/javafx.bootstrap/javafx.bootstrap.sln b/javafx.bootstrap/javafx.bootstrap.sln new file mode 100644 index 0000000..9d7f31f --- /dev/null +++ b/javafx.bootstrap/javafx.bootstrap.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30503.244 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "javafx.bootstrap", "javafx.bootstrap\javafx.bootstrap.vcxproj", "{B546CB97-CDCE-4317-8AAD-73E76BD19003}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B546CB97-CDCE-4317-8AAD-73E76BD19003}.Debug|x64.ActiveCfg = Debug|x64 + {B546CB97-CDCE-4317-8AAD-73E76BD19003}.Debug|x64.Build.0 = Debug|x64 + {B546CB97-CDCE-4317-8AAD-73E76BD19003}.Debug|x86.ActiveCfg = Debug|Win32 + {B546CB97-CDCE-4317-8AAD-73E76BD19003}.Debug|x86.Build.0 = Debug|Win32 + {B546CB97-CDCE-4317-8AAD-73E76BD19003}.Release|x64.ActiveCfg = Release|x64 + {B546CB97-CDCE-4317-8AAD-73E76BD19003}.Release|x64.Build.0 = Release|x64 + {B546CB97-CDCE-4317-8AAD-73E76BD19003}.Release|x86.ActiveCfg = Release|Win32 + {B546CB97-CDCE-4317-8AAD-73E76BD19003}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0CDBFE75-E4C2-4545-9553-310226645509} + EndGlobalSection +EndGlobal diff --git a/javafx.bootstrap/javafx.bootstrap/javafx.bootstrap.rc b/javafx.bootstrap/javafx.bootstrap/javafx.bootstrap.rc new file mode 100644 index 0000000..222a172 --- /dev/null +++ b/javafx.bootstrap/javafx.bootstrap/javafx.bootstrap.rc @@ -0,0 +1,71 @@ +// Microsoft Visual C++ generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "winres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (United States) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""winres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// 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" + +#endif // English (United States) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/javafx.bootstrap/javafx.bootstrap/javafx.bootstrap.vcxproj b/javafx.bootstrap/javafx.bootstrap/javafx.bootstrap.vcxproj new file mode 100644 index 0000000..6be60f2 --- /dev/null +++ b/javafx.bootstrap/javafx.bootstrap/javafx.bootstrap.vcxproj @@ -0,0 +1,157 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {b546cb97-cdce-4317-8aad-73e76bd19003} + javafxbootstrap + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + + + Windows + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + + + Windows + true + true + true + + + + + Level3 + true + _DEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + + + Windows + true + + + + + Level3 + true + true + true + NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + stdcpp17 + + + Windows + true + true + true + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/javafx.bootstrap/javafx.bootstrap/javafx.bootstrap.vcxproj.filters b/javafx.bootstrap/javafx.bootstrap/javafx.bootstrap.vcxproj.filters new file mode 100644 index 0000000..d5ed7ea --- /dev/null +++ b/javafx.bootstrap/javafx.bootstrap/javafx.bootstrap.vcxproj.filters @@ -0,0 +1,37 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + + + Header Files + + + + + Resource Files + + + + + Resource Files + + + \ No newline at end of file diff --git a/javafx.bootstrap/javafx.bootstrap/main.cpp b/javafx.bootstrap/javafx.bootstrap/main.cpp new file mode 100644 index 0000000..72aa108 --- /dev/null +++ b/javafx.bootstrap/javafx.bootstrap/main.cpp @@ -0,0 +1,32 @@ +#include +#include +#include +#include +#pragma comment(lib,"user32.lib") + +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdParam, int iCmdShow) +{ + STARTUPINFO si; + PROCESS_INFORMATION pi; + + ZeroMemory(&si, sizeof(si)); + 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")); + if (!CreateProcess(NULL, command, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) + { + CloseHandle(&pi.hProcess); + CloseHandle(&pi.hThread); + int msgboxID = MessageBox( + NULL, + TEXT("Unable to start the JVM. Try reinstalling the program to fix this problem."), + TEXT("EndPoint bootstrap"), + MB_ICONHAND | MB_OK | MB_DEFBUTTON1 + ); + return -1; + } + CloseHandle(&pi.hProcess); + CloseHandle(&pi.hThread); + return 0; +} \ No newline at end of file diff --git a/javafx.bootstrap/javafx.bootstrap/resource.h b/javafx.bootstrap/javafx.bootstrap/resource.h new file mode 100644 index 0000000..e1e111d --- /dev/null +++ b/javafx.bootstrap/javafx.bootstrap/resource.h @@ -0,0 +1,16 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by javafx.bootstrap.rc +// +#define IDI_ICON2 102 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 103 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF new file mode 100644 index 0000000..f0d972d --- /dev/null +++ b/src/META-INF/MANIFEST.MF @@ -0,0 +1,6 @@ +Manifest-Version: 1.0 +Main-Class: ovh.alexisdelhaie.endpoint.Main +Class-Path: src.zip javafx-swt.jar javafx.web.jar javafx.base.jar javafx + .fxml.jar javafx.media.jar javafx.swing.jar javafx.controls.jar javafx. + graphics.jar + diff --git a/src/ovh/alexisdelhaie/endpoint/Controller.java b/src/ovh/alexisdelhaie/endpoint/Controller.java new file mode 100644 index 0000000..5a19baa --- /dev/null +++ b/src/ovh/alexisdelhaie/endpoint/Controller.java @@ -0,0 +1,413 @@ +package ovh.alexisdelhaie.endpoint; + +import javafx.application.Platform; +import javafx.beans.property.StringProperty; +import javafx.collections.FXCollections; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.fxml.Initializable; +import javafx.geometry.Orientation; +import javafx.scene.Node; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.control.*; +import javafx.scene.control.cell.PropertyValueFactory; +import javafx.scene.image.Image; +import javafx.scene.layout.Pane; +import javafx.scene.paint.Color; +import javafx.stage.Modality; +import javafx.stage.Stage; +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.impl.EditCell; +import ovh.alexisdelhaie.endpoint.model.Param; + +import java.io.IOException; +import java.net.URL; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.ResourceBundle; +import java.util.function.Function; + +public class Controller implements Initializable { + + private enum StatusColor { + INFORMATION("#53baf5"), + SUCCESS("#7ccf16"), + REDIRECTION("#b153f5"), + ERROR_CLIENT("#f5ca53"), + ERROR_SERVER("#f55353"), + DEFAULT("BLACK"); + + private final String hex; + + StatusColor(String s) { + hex = s; + } + + public String getHex() { + return hex; + } + } + + private enum RequestTab { + PARAMS(0), + AUTHORIZATION(1), + HEADERS(2), + BODY(3), + RESPONSE(4); + + private final int index; + + RequestTab (int i) { index = i; } + public int getIndex() { return index; } + } + + @FXML + private ChoiceBox httpMethod; + @FXML + private TabPane tabs; + @FXML + private TextField requestInput; + @FXML + private Pane runningIndicatorPane; + + private Stage primaryStage; + private HashMap requests; + + @Override + public void initialize(URL location, ResourceBundle resources) { + requests = new HashMap<>(); + String[] method = { "GET", "POST", "HEAD", "PUT", "DELETE" }; + httpMethod.setItems(FXCollections.observableArrayList(method)); + httpMethod.setValue(method[0]); + tabs.getSelectionModel().selectedItemProperty().addListener( + (ov, t, t1) -> requestInput.setText((t1 != null) ? requests.get(t1.hashCode()) : "") + ); + createNewTab(); + } + + private Tab newTab() { + SplitPane sp = new SplitPane(); + + Tab params = new Tab("Params", createParamTable()); + Tab auth = new Tab("Authorization"); + Tab headers = new Tab("Headers", createParamTable()); + Tab body = new Tab("Body", new TextArea()); + Tab response = new Tab("Response", createResponseTab()); + + TabPane options = new TabPane(); + TextArea ta = new TextArea(); + + options.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE); + options.getTabs().addAll(params, auth, headers, body, response); + sp.getItems().add(options); + sp.getItems().add(ta); + sp.setOrientation(Orientation.VERTICAL); + + return new Tab("untitled", sp); + } + + @SuppressWarnings("unchecked") + private ScrollPane createResponseTab() { + ScrollPane sp = new ScrollPane(); + Pane p = new Pane(); + sp.setContent(p); + try { + Parent xml = FXMLLoader.load(getClass().getResource("responsetab.fxml")); + p.getChildren().add(xml); + TableView headers = (TableView) p.lookup("#headers"); + headers.getColumns().get(0).setCellValueFactory(new PropertyValueFactory<>("name")); + headers.getColumns().get(1).setCellValueFactory(new PropertyValueFactory<>("value")); + } catch (IOException e) { + System.err.println(e.getMessage()); + } + return sp; + } + + private TableView createParamTable() { + TableView paramsTable = new TableView<>(); + + TableColumn name = createColumn("Name", Param::name); + TableColumn value = createColumn("Value", Param::value); + + name.prefWidthProperty().bind(paramsTable.widthProperty().multiply(0.5)); + value.prefWidthProperty().bind(paramsTable.widthProperty().multiply(0.5)); + + name.setOnEditCommit(t -> { + TableView tv = t.getTableView(); + t.getRowValue().name().set(t.getNewValue()); + manageEmptyCells(t, tv); + }); + value.setOnEditCommit(t -> { + TableView tv = t.getTableView(); + t.getRowValue().value().set(t.getNewValue()); + manageEmptyCells(t, tv); + }); + + paramsTable.getColumns().add(name); + paramsTable.getColumns().add(value); + + paramsTable.setEditable(true); + paramsTable.getItems().add(new Param()); + + return paramsTable; + } + + private void manageEmptyCells(TableColumn.CellEditEvent t, TableView tv) { + if (t.getRowValue().isEmpty() && tv.getItems().size() > 1) { + tv.getItems().remove(t.getRowValue()); + } + if (!tv.getItems().get(tv.getItems().size() - 1).isEmpty()) { + tv.getItems().add(new Param()); + } + requestInput.setText(URLGenerator.processNewUrl(getParamsMap(), requestInput.getText())); + } + + private TableColumn createColumn(String title, Function property) { + TableColumn col = new TableColumn<>(title); + col.setCellValueFactory(cellData -> property.apply(cellData.getValue())); + + col.setCellFactory(column -> EditCell.createStringEditCell()); + return col ; + } + + @FXML + private void start() { + runningIndicatorPane.setVisible(true); + new Thread(() -> { + final String method = httpMethod.getValue(); + Optional +