commit b65f631cb78aa9815dd725f2f854a120836821e8 Author: Alexis Delhaie Date: Wed Oct 16 22:14:19 2019 +0200 Creation des dialogs diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..5cfaef1 --- /dev/null +++ b/.classpath @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e660fd9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +bin/ diff --git a/.idea/$PRODUCT_WORKSPACE_FILE$ b/.idea/$PRODUCT_WORKSPACE_FILE$ new file mode 100644 index 0000000..79be354 --- /dev/null +++ b/.idea/$PRODUCT_WORKSPACE_FILE$ @@ -0,0 +1,19 @@ + + + + + + + 11 + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..1763e15 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..16251f1 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..507f6c3 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1571245908473 + + + + + + \ No newline at end of file diff --git a/.project b/.project new file mode 100644 index 0000000..bb70022 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + cURLing + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/cURLing.iml b/cURLing.iml new file mode 100644 index 0000000..9c5aa9b --- /dev/null +++ b/cURLing.iml @@ -0,0 +1,161 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/ovh/alexisdelhaie/curling/Runtime.java b/src/ovh/alexisdelhaie/curling/Runtime.java new file mode 100644 index 0000000..25dfed5 --- /dev/null +++ b/src/ovh/alexisdelhaie/curling/Runtime.java @@ -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(); + } +} diff --git a/src/ovh/alexisdelhaie/curling/windows/AddHeader.form b/src/ovh/alexisdelhaie/curling/windows/AddHeader.form new file mode 100644 index 0000000..f20aaab --- /dev/null +++ b/src/ovh/alexisdelhaie/curling/windows/AddHeader.form @@ -0,0 +1,96 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/ovh/alexisdelhaie/curling/windows/AddHeader.java b/src/ovh/alexisdelhaie/curling/windows/AddHeader.java new file mode 100644 index 0000000..78e37d9 --- /dev/null +++ b/src/ovh/alexisdelhaie/curling/windows/AddHeader.java @@ -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; + } +} diff --git a/src/ovh/alexisdelhaie/curling/windows/BasicAuthenticationDialog.form b/src/ovh/alexisdelhaie/curling/windows/BasicAuthenticationDialog.form new file mode 100644 index 0000000..88b0920 --- /dev/null +++ b/src/ovh/alexisdelhaie/curling/windows/BasicAuthenticationDialog.form @@ -0,0 +1,96 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/ovh/alexisdelhaie/curling/windows/BasicAuthenticationDialog.java b/src/ovh/alexisdelhaie/curling/windows/BasicAuthenticationDialog.java new file mode 100644 index 0000000..a57e7ea --- /dev/null +++ b/src/ovh/alexisdelhaie/curling/windows/BasicAuthenticationDialog.java @@ -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; + } +} diff --git a/src/ovh/alexisdelhaie/curling/windows/FormEncodedDialog.form b/src/ovh/alexisdelhaie/curling/windows/FormEncodedDialog.form new file mode 100644 index 0000000..1c7fbda --- /dev/null +++ b/src/ovh/alexisdelhaie/curling/windows/FormEncodedDialog.form @@ -0,0 +1,128 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/ovh/alexisdelhaie/curling/windows/FormEncodedDialog.java b/src/ovh/alexisdelhaie/curling/windows/FormEncodedDialog.java new file mode 100644 index 0000000..716ee36 --- /dev/null +++ b/src/ovh/alexisdelhaie/curling/windows/FormEncodedDialog.java @@ -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 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; + } +} diff --git a/src/ovh/alexisdelhaie/curling/windows/MainWindow.form b/src/ovh/alexisdelhaie/curling/windows/MainWindow.form new file mode 100644 index 0000000..6e2c697 --- /dev/null +++ b/src/ovh/alexisdelhaie/curling/windows/MainWindow.form @@ -0,0 +1,141 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/ovh/alexisdelhaie/curling/windows/MainWindow.java b/src/ovh/alexisdelhaie/curling/windows/MainWindow.java new file mode 100644 index 0000000..e4f2118 --- /dev/null +++ b/src/ovh/alexisdelhaie/curling/windows/MainWindow.java @@ -0,0 +1,67 @@ +package ovh.alexisdelhaie.curling.windows; + +import javax.swing.*; +import java.awt.*; + +public class MainWindow extends JDialog { + + private DefaultListModel 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); + } +}