Creation des dialogs
This commit is contained in:
12
src/ovh/alexisdelhaie/curling/Runtime.java
Normal file
12
src/ovh/alexisdelhaie/curling/Runtime.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package ovh.alexisdelhaie.curling;
|
||||
|
||||
import ovh.alexisdelhaie.curling.windows.MainWindow;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class Runtime {
|
||||
public static void main(String[] args) {
|
||||
MainWindow window = new MainWindow();
|
||||
window.showFrame();
|
||||
}
|
||||
}
|
||||
96
src/ovh/alexisdelhaie/curling/windows/AddHeader.form
Normal file
96
src/ovh/alexisdelhaie/curling/windows/AddHeader.form
Normal file
@@ -0,0 +1,96 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ovh.alexisdelhaie.curling.windows.AddHeader">
|
||||
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="10" left="10" bottom="10" right="10"/>
|
||||
<constraints>
|
||||
<xy x="48" y="188" width="436" height="163"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="94766" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<hspacer id="98af6">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<grid id="9538f" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="true" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="e7465" class="javax.swing.JButton" binding="buttonOK">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="OK"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="5723f" class="javax.swing.JButton" binding="buttonCancel">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Cancel"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="e3588" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="72dff" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Key"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="fb2ca" class="javax.swing.JTextField" binding="keyField">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="f8957" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Value"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="61af2" class="javax.swing.JTextField" binding="valueField">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
72
src/ovh/alexisdelhaie/curling/windows/AddHeader.java
Normal file
72
src/ovh/alexisdelhaie/curling/windows/AddHeader.java
Normal file
@@ -0,0 +1,72 @@
|
||||
package ovh.alexisdelhaie.curling.windows;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class AddHeader extends JDialog {
|
||||
|
||||
public static String WINDOW_TITLE = "Ajouter une en-tête";
|
||||
|
||||
private JPanel contentPane;
|
||||
private JButton buttonOK;
|
||||
private JButton buttonCancel;
|
||||
private JTextField keyField;
|
||||
private JTextField valueField;
|
||||
|
||||
private String value;
|
||||
|
||||
public AddHeader() {
|
||||
this.value = "";
|
||||
setContentPane(contentPane);
|
||||
setModal(true);
|
||||
setTitle(WINDOW_TITLE);
|
||||
getRootPane().setDefaultButton(buttonOK);
|
||||
|
||||
buttonOK.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onOK();
|
||||
}
|
||||
});
|
||||
|
||||
buttonCancel.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onCancel();
|
||||
}
|
||||
});
|
||||
|
||||
// call onCancel() when cross is clicked
|
||||
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
onCancel();
|
||||
}
|
||||
});
|
||||
|
||||
// call onCancel() on ESCAPE
|
||||
contentPane.registerKeyboardAction(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onCancel();
|
||||
}
|
||||
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
||||
}
|
||||
|
||||
private void onOK() {
|
||||
if(!keyField.getText().isBlank()) {
|
||||
value = keyField.getText();
|
||||
if(!valueField.getText().isBlank()) {
|
||||
value += String.format(": %s", valueField.getText());
|
||||
}
|
||||
}
|
||||
dispose();
|
||||
}
|
||||
|
||||
private void onCancel() {
|
||||
dispose();
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
pack();
|
||||
setVisible(true);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ovh.alexisdelhaie.curling.windows.BasicAuthenticationDialog">
|
||||
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="10" left="10" bottom="10" right="10"/>
|
||||
<constraints>
|
||||
<xy x="48" y="54" width="436" height="297"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="94766" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<hspacer id="98af6">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<grid id="9538f" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="true" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="e7465" class="javax.swing.JButton" binding="buttonOK">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="OK"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="5723f" class="javax.swing.JButton" binding="buttonCancel">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Cancel"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="e3588" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="8207b" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Username"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="6459c" class="javax.swing.JTextField" binding="textField1" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="1c26c" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Password"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="b5c19" class="javax.swing.JPasswordField" binding="passwordField1" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
@@ -0,0 +1,90 @@
|
||||
package ovh.alexisdelhaie.curling.windows;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Base64;
|
||||
|
||||
public class BasicAuthenticationDialog extends JDialog {
|
||||
|
||||
public static String HTTP_AUTH_BASIC_PATTERN = "Authorization: Basic %s";
|
||||
public static String WINDOW_TITLE = "Authentification HTTP";
|
||||
|
||||
private JPanel contentPane;
|
||||
private JButton buttonOK;
|
||||
private JButton buttonCancel;
|
||||
private JTextField textField1;
|
||||
private JPasswordField passwordField1;
|
||||
|
||||
private String value = "";
|
||||
|
||||
public BasicAuthenticationDialog() {
|
||||
setContentPane(contentPane);
|
||||
setModal(true);
|
||||
setTitle(WINDOW_TITLE);
|
||||
getRootPane().setDefaultButton(buttonOK);
|
||||
|
||||
buttonOK.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onOK();
|
||||
}
|
||||
});
|
||||
|
||||
buttonCancel.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onCancel();
|
||||
}
|
||||
});
|
||||
|
||||
// call onCancel() when cross is clicked
|
||||
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
onCancel();
|
||||
}
|
||||
});
|
||||
|
||||
// call onCancel() on ESCAPE
|
||||
contentPane.registerKeyboardAction(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onCancel();
|
||||
}
|
||||
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
||||
}
|
||||
|
||||
private void onOK() {
|
||||
if(!isUsernameBlank() && !isPasswordBlank()) {
|
||||
String user = textField1.getText();
|
||||
String password = new String(passwordField1.getPassword());
|
||||
byte[] authEncodedBytes = Base64.getEncoder()
|
||||
.encode(String.format("%s:%s", user, password).getBytes());
|
||||
try {
|
||||
String authEncoded = new String(authEncodedBytes, "UTF-8");
|
||||
value = String.format(HTTP_AUTH_BASIC_PATTERN, authEncoded);
|
||||
dispose();
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
JOptionPane.showMessageDialog(this, "Le format UTF-8 n'est pas supporté");
|
||||
}
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(this, "Vous devez remplir les 2 champs");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isPasswordBlank() {
|
||||
return passwordField1.getPassword().length == 0;
|
||||
}
|
||||
|
||||
private boolean isUsernameBlank() {
|
||||
return textField1.getText().isBlank();
|
||||
}
|
||||
|
||||
private void onCancel() {
|
||||
dispose();
|
||||
}
|
||||
|
||||
public String showDialog() {
|
||||
pack();
|
||||
setVisible(true);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
128
src/ovh/alexisdelhaie/curling/windows/FormEncodedDialog.form
Normal file
128
src/ovh/alexisdelhaie/curling/windows/FormEncodedDialog.form
Normal file
@@ -0,0 +1,128 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ovh.alexisdelhaie.curling.windows.FormEncodedDialog">
|
||||
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="4" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="10" left="10" bottom="10" right="10"/>
|
||||
<constraints>
|
||||
<xy x="48" y="54" width="436" height="346"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="94766" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="3" vsize-policy="1" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<hspacer id="98af6">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<grid id="9538f" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="true" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="e7465" class="javax.swing.JButton" binding="buttonOK">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="OK"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="5723f" class="javax.swing.JButton" binding="buttonCancel">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Cancel"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<component id="fc73f" class="javax.swing.JButton" binding="addButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Add"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="e3588" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<scrollpane id="1d719">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="3c2f3" class="javax.swing.JList" binding="list1" default-binding="true">
|
||||
<constraints/>
|
||||
<properties/>
|
||||
</component>
|
||||
</children>
|
||||
</scrollpane>
|
||||
</children>
|
||||
</grid>
|
||||
<component id="60e85" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Key"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="5b04f" class="javax.swing.JTextField" binding="keyField">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="947ac" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Content"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="328a" class="javax.swing.JTextArea" binding="valueField">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="50"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="3fe5d" class="javax.swing.JComboBox" binding="encodageField">
|
||||
<constraints>
|
||||
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<model>
|
||||
<item value="Plain"/>
|
||||
<item value="base64"/>
|
||||
</model>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
118
src/ovh/alexisdelhaie/curling/windows/FormEncodedDialog.java
Normal file
118
src/ovh/alexisdelhaie/curling/windows/FormEncodedDialog.java
Normal file
@@ -0,0 +1,118 @@
|
||||
package ovh.alexisdelhaie.curling.windows;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Base64;
|
||||
|
||||
public class FormEncodedDialog extends JDialog {
|
||||
|
||||
public static String WINDOW_TITLE = "Formulaire de données";
|
||||
|
||||
private JPanel contentPane;
|
||||
private JButton buttonOK;
|
||||
private JButton buttonCancel;
|
||||
private JTextField keyField;
|
||||
private JTextArea valueField;
|
||||
private JList list1;
|
||||
private JButton addButton;
|
||||
private JComboBox encodageField;
|
||||
|
||||
private String resultValue = "";
|
||||
private DefaultListModel<String> model;
|
||||
public static String[] UNENCODED_CHAR = {"!", "*", "'", "(", ")", ";", ":", "@", "&", "=", "+", "$", ",", "/", "?", "#", "[", "]"};
|
||||
public static String[] ENCODED_CHAR = {"%21", "%2A", "%27", "%28", "%29", "%3B", "%3A", "%40", "%26", "%3D", "%2B", "%24", "%2C", "%2F", "%3F", "%23", "%5B", "%5D"};
|
||||
|
||||
public FormEncodedDialog() {
|
||||
setContentPane(contentPane);
|
||||
setModal(true);
|
||||
setTitle(WINDOW_TITLE);
|
||||
model = new DefaultListModel<>();
|
||||
list1.setModel(model);
|
||||
|
||||
addButton.addActionListener((event) -> {
|
||||
String key = keyField.getText();
|
||||
String value = "";
|
||||
if(encodageField.getSelectedItem().equals("base64")) {
|
||||
value = encodeValue(encodeBase64(valueField.getText()));
|
||||
} else {
|
||||
value = encodeValue(valueField.getText());
|
||||
}
|
||||
clearField();
|
||||
String keyValue = String.format("%s=%s", key, value);
|
||||
model.addElement(keyValue);
|
||||
list1.updateUI();
|
||||
});
|
||||
|
||||
buttonOK.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onOK();
|
||||
}
|
||||
});
|
||||
|
||||
buttonCancel.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onCancel();
|
||||
}
|
||||
});
|
||||
|
||||
// call onCancel() when cross is clicked
|
||||
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
onCancel();
|
||||
}
|
||||
});
|
||||
|
||||
// call onCancel() on ESCAPE
|
||||
contentPane.registerKeyboardAction(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onCancel();
|
||||
}
|
||||
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
||||
}
|
||||
|
||||
private String encodeBase64(String text) {
|
||||
byte[] encoded = Base64.getEncoder().encode(text.getBytes());
|
||||
try {
|
||||
return new String(encoded, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private void onOK() {
|
||||
for(int i = 0; i < model.getSize(); i++) {
|
||||
if(i == 0) {
|
||||
resultValue = (String)model.get(i);
|
||||
} else {
|
||||
resultValue += String.format("&%s", (String)model.get(i));
|
||||
}
|
||||
}
|
||||
dispose();
|
||||
}
|
||||
|
||||
private void clearField() {
|
||||
keyField.setText("");
|
||||
valueField.setText("");
|
||||
}
|
||||
|
||||
private String encodeValue(String s) {
|
||||
String result = s;
|
||||
for(int i = 0; i < UNENCODED_CHAR.length ; i++) {
|
||||
result = result.replace(UNENCODED_CHAR[i], ENCODED_CHAR[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void onCancel() {
|
||||
// add your code here if necessary
|
||||
dispose();
|
||||
}
|
||||
|
||||
public String showDialog() {
|
||||
pack();
|
||||
setVisible(true);
|
||||
return resultValue;
|
||||
}
|
||||
}
|
||||
141
src/ovh/alexisdelhaie/curling/windows/MainWindow.form
Normal file
141
src/ovh/alexisdelhaie/curling/windows/MainWindow.form
Normal file
@@ -0,0 +1,141 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ovh.alexisdelhaie.curling.windows.MainWindow">
|
||||
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="6" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="10" left="10" bottom="10" right="10"/>
|
||||
<constraints>
|
||||
<xy x="48" y="54" width="739" height="412"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none" title="cURLing"/>
|
||||
<children>
|
||||
<component id="15009" class="javax.swing.JTextArea" binding="textArea1" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="0" column="3" row-span="5" col-span="2" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="50"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<editable value="false"/>
|
||||
<focusable value="false"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="b4b69" class="javax.swing.JComboBox" binding="comboBox1" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<model>
|
||||
<item value="HTTP"/>
|
||||
<item value="HTTPS"/>
|
||||
</model>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="dc7ca" class="javax.swing.JComboBox" binding="comboBox2" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<model>
|
||||
<item value="GET"/>
|
||||
<item value="POST"/>
|
||||
<item value="DELETE"/>
|
||||
<item value="PUT"/>
|
||||
</model>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="3d00f" class="javax.swing.JTextField" binding="textField1" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="adde4" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Custom headers"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="1286d" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Body datas"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="627e7" class="javax.swing.JButton" binding="xFormEncodedButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<label value="Add X-form-encoded values"/>
|
||||
<text value="Add X-form-encoded values"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="10f69" class="javax.swing.JProgressBar" binding="progressBar1" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="5" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="76150" class="javax.swing.JButton" binding="newHeaderButton">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<label value="New header"/>
|
||||
<text value="New header"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="3d3b2" class="javax.swing.JButton" binding="addAuthButton">
|
||||
<constraints>
|
||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<label value="Basic authentication"/>
|
||||
<text value="Basic authentication"/>
|
||||
</properties>
|
||||
</component>
|
||||
<scrollpane id="4befb">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="3" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="9adda" class="javax.swing.JList" binding="list1" default-binding="true">
|
||||
<constraints/>
|
||||
<properties/>
|
||||
</component>
|
||||
</children>
|
||||
</scrollpane>
|
||||
<scrollpane id="cdcdf">
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="2" col-span="3" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="f5002" class="javax.swing.JTextArea" binding="bodyArea">
|
||||
<constraints/>
|
||||
<properties/>
|
||||
</component>
|
||||
</children>
|
||||
</scrollpane>
|
||||
<component id="c866d" class="javax.swing.JButton" binding="runButton">
|
||||
<constraints>
|
||||
<grid row="5" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<enabled value="false"/>
|
||||
<label value="Start"/>
|
||||
<text value="Start"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
67
src/ovh/alexisdelhaie/curling/windows/MainWindow.java
Normal file
67
src/ovh/alexisdelhaie/curling/windows/MainWindow.java
Normal file
@@ -0,0 +1,67 @@
|
||||
package ovh.alexisdelhaie.curling.windows;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class MainWindow extends JDialog {
|
||||
|
||||
private DefaultListModel<String> model;
|
||||
|
||||
private JPanel contentPane;
|
||||
private JTextField textField1;
|
||||
private JTextArea textArea1;
|
||||
private JComboBox comboBox1;
|
||||
private JComboBox comboBox2;
|
||||
private JButton xFormEncodedButton;
|
||||
private JTextArea bodyArea;
|
||||
private JProgressBar progressBar1;
|
||||
private JList list1;
|
||||
private JButton newHeaderButton;
|
||||
private JButton addAuthButton;
|
||||
private JButton runButton;
|
||||
|
||||
public static int WINDOW_HEIGHT = 700;
|
||||
public static int WINDOW_WIDTH = 1100;
|
||||
public static String WINDOW_TITLE = "cURLing";
|
||||
|
||||
public MainWindow() {
|
||||
super((Dialog) null);
|
||||
setTitle(WINDOW_TITLE);
|
||||
model = new DefaultListModel<>();
|
||||
list1.setModel(model);
|
||||
setContentPane(contentPane);
|
||||
setMinimumSize(new Dimension(WINDOW_WIDTH, WINDOW_HEIGHT));
|
||||
setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
|
||||
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
||||
|
||||
newHeaderButton.addActionListener((event) -> {
|
||||
AddHeader ah = new AddHeader();
|
||||
String header = ah.getValue();
|
||||
model.addElement(header);
|
||||
list1.updateUI();
|
||||
});
|
||||
|
||||
addAuthButton.addActionListener((event) -> {
|
||||
if(addAuthButton.isEnabled()) {
|
||||
BasicAuthenticationDialog bad = new BasicAuthenticationDialog();
|
||||
String auth = bad.showDialog();
|
||||
if(!auth.isBlank()) {
|
||||
addAuthButton.setEnabled(false);
|
||||
model.addElement(auth);
|
||||
list1.updateUI();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
xFormEncodedButton.addActionListener((event) -> {
|
||||
FormEncodedDialog fe = new FormEncodedDialog();
|
||||
String datas = fe.showDialog();
|
||||
bodyArea.setText(datas);
|
||||
});
|
||||
}
|
||||
|
||||
public void showFrame() {
|
||||
pack();
|
||||
setVisible(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user