Commit 2b7258bf authored by 9731301's avatar 9731301

add saveRequest button

parent fa3710c7
......@@ -7,14 +7,39 @@
</component>
<component name="ChangeListManager">
<list default="true" id="f2dd20fb-7e97-49ef-9dfe-5631626d7912" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/Requests/test.insomnia" afterDir="false" />
<change afterPath="$PROJECT_DIR$/Requests/test2.insomnia" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/InsomniaGUI$1.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/InsomniaGUI$1.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/InsomniaGUI$2.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/InsomniaGUI$2.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/InsomniaGUI$3.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/InsomniaGUI$3.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/InsomniaGUI$4.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/InsomniaGUI$4.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/InsomniaGUI$5.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/InsomniaGUI$5.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/InsomniaGUI$6.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/InsomniaGUI$6.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/InsomniaGUI$exitApp$1.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/InsomniaGUI$exitApp$1.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/InsomniaGUI$exitApp$2.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/InsomniaGUI$exitApp$2.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/InsomniaGUI$exitApp.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/InsomniaGUI$exitApp.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/InsomniaGUI.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/InsomniaGUI.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/LeftPanel$1$1.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/LeftPanel$1$1.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/LeftPanel$1.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/LeftPanel$1.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/LeftPanel$MouseRequestClick.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/LeftPanel$MouseRequestClick.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/LeftPanel.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/LeftPanel.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/RequestPanel$10.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/RequestPanel$10.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/RequestPanel$11.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/RequestPanel$11.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/RequestPanel$12.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/RequestPanel$12.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/RequestPanel$13.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/RequestPanel$13.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/RequestPanel$2.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/RequestPanel$2.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/RequestPanel$7.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/RequestPanel$7.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/RequestPanel$8.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/RequestPanel$8.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/RequestPanel$9.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/RequestPanel$9.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/RequestPanel.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/GUI/RequestPanel.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/parser/RequestData.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/parser/RequestData.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/parser/ResponseData.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/parser/ResponseData.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/parser/Saver.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/parser/Saver.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/insomnia/GUI/InsomniaGUI.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/insomnia/GUI/InsomniaGUI.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/insomnia/GUI/LeftPanel.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/insomnia/GUI/LeftPanel.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/insomnia/GUI/RequestPanel.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/insomnia/GUI/RequestPanel.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/insomnia/GUI/RespondPanel.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/insomnia/GUI/RespondPanel.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/insomnia/parser/Parser.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/insomnia/parser/Parser.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/insomnia/parser/RequestLoader.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/insomnia/parser/RequestLoader.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/insomnia/parser/RequestData.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/insomnia/parser/RequestData.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/insomnia/parser/ResponseData.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/insomnia/parser/ResponseData.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/insomnia/parser/Saver.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/insomnia/parser/Saver.java" afterDir="false" />
</list>
......@@ -152,6 +177,7 @@
<workItem from="1590757579057" duration="2543000" />
<workItem from="1590934179600" duration="31544000" />
<workItem from="1591024948574" duration="21598000" />
<workItem from="1591127468443" duration="6374000" />
</task>
<servers />
</component>
......@@ -182,30 +208,30 @@
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="402" y="167" key="FileChooserDialogImpl/0.0.1536.824@0.0.1536.824" timestamp="1590494460700" />
<state width="1493" height="105" key="GridCell.Tab.0.bottom" timestamp="1591046612712">
<state width="1493" height="105" key="GridCell.Tab.0.bottom" timestamp="1591133602250">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="105" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1591046612712" />
<state width="1493" height="105" key="GridCell.Tab.0.center" timestamp="1591046612712">
<state width="1493" height="105" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1591133602250" />
<state width="1493" height="105" key="GridCell.Tab.0.center" timestamp="1591133602250">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="105" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1591046612712" />
<state width="1493" height="105" key="GridCell.Tab.0.left" timestamp="1591046612712">
<state width="1493" height="105" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1591133602250" />
<state width="1493" height="105" key="GridCell.Tab.0.left" timestamp="1591133602247">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="105" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1591046612712" />
<state width="1493" height="105" key="GridCell.Tab.0.right" timestamp="1591046612712">
<state width="1493" height="105" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1591133602247" />
<state width="1493" height="105" key="GridCell.Tab.0.right" timestamp="1591133602250">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="105" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1591046612712" />
<state width="1493" height="105" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1591133602250" />
<state x="249" y="0" key="SettingsEditor" timestamp="1590962002174">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="249" y="0" key="SettingsEditor/0.0.1536.824@0.0.1536.824" timestamp="1590962002174" />
<state x="425" y="237" key="com.intellij.ide.util.TipDialog" timestamp="1591025053132">
<state x="425" y="237" key="com.intellij.ide.util.TipDialog" timestamp="1591127805670">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="425" y="237" key="com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824" timestamp="1591025053132" />
<state x="425" y="237" key="com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824" timestamp="1591127805670" />
<state x="499" y="179" key="extract.method.dialog" timestamp="1590145349556">
<screen x="0" y="0" width="1536" height="824" />
</state>
......@@ -214,10 +240,10 @@
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="209" y="33" key="new project wizard/0.0.1536.824@0.0.1536.824" timestamp="1590495277464" />
<state x="163" y="189" key="run.anything.popup" timestamp="1590953965770">
<state x="163" y="189" key="run.anything.popup" timestamp="1591133239834">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="163" y="189" key="run.anything.popup/0.0.1536.824@0.0.1536.824" timestamp="1590953965770" />
<state x="163" y="189" key="run.anything.popup/0.0.1536.824@0.0.1536.824" timestamp="1591133239834" />
<state x="46" y="145" width="672" height="678" key="search.everywhere.popup" timestamp="1590952691529">
<screen x="0" y="0" width="1536" height="824" />
</state>
......
......@@ -5,6 +5,7 @@ package com.insomnia.GUI;
* @version 0.0
*/
import com.insomnia.parser.RequestData;
import com.insomnia.parser.ResponseData;
import javax.swing.*;
......@@ -19,6 +20,7 @@ import static java.awt.Frame.*;
public class InsomniaGUI {
JFrame frame ;
RespondPanel response;
RequestPanel request;
ResponseData data_req = null;
public void load(ResponseData d){
......@@ -26,6 +28,15 @@ public class InsomniaGUI {
response.load(d);
}
public boolean hasRequest(){
return data_req!=null;
}
public void loadRequest (RequestData r){
request.load(r);
}
public InsomniaGUI() throws IOException {
frame = new JFrame();
frame.setTitle("Insomnia");
......@@ -34,14 +45,14 @@ public class InsomniaGUI {
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
RequestPanel request = new RequestPanel(this);
request = new RequestPanel(this);
request.createRequestPanel();
response = new RespondPanel();
response.createRespondPanel();
JPanel panelRight = new JPanel(new GridLayout(1 ,2 ));
panelRight.add(request);
panelRight.add(response);
LeftPanel leftPanel = new LeftPanel();
LeftPanel leftPanel = new LeftPanel(this);
leftPanel.createLeftPanel();
//menu upper_Items
......
......@@ -10,16 +10,21 @@ import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
public class LeftPanel extends JPanel {
Border border = BorderFactory.createLineBorder(Color.BLACK,3);
VerticalFlowLayout vfLayout = new VerticalFlowLayout();
JButton addRequest = new JButton("Add Request");
JButton addRequest = new JButton("Save Request");
JMenu menu = new JMenu("Insomnia");
JPanel requestList = new JPanel(vfLayout);
JScrollPane scrollRequests = new JScrollPane(requestList);
JPanel up_left = new JPanel(new GridLayout(2,1));
InsomniaGUI main_class;
public LeftPanel (InsomniaGUI m){
main_class = m;
}
//left panel (list of requests)
public void createLeftPanel() {
......@@ -33,8 +38,11 @@ public class LeftPanel extends JPanel {
addRequest.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
RequestData requestData = new RequestData();
ResponseData responseData = new ResponseData(requestData);
if (!main_class.hasRequest()){
JOptionPane.showMessageDialog(main_class.frame,"You need to send a request first.","Error",JOptionPane.ERROR_MESSAGE);
return;
}
JFrame newRequestFrame = new JFrame("request name");
JLabel label = new JLabel("new request");
JTextField textField = new JTextField();
......@@ -49,20 +57,39 @@ public class LeftPanel extends JPanel {
newRequestFrame.add(panel);
newRequestFrame.setPreferredSize(new Dimension(200,200));
newRequestFrame.setVisible(true);
requestData.setName(textField.getText());
create.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
requestData.setName(textField.getText());
JButton newRequest = new JButton(requestData.getName());
newRequest.addMouseListener(new MouseRequestClick(requestData , responseData ));
String name = textField.getText();
//Check Request exist
//Save Request
ResponseData data = main_class.data_req;
data.getRequestData().setName(name);
new Saver().saveRequestAndResponse(data);
//Add Request to list
JButton newRequest = new JButton(name);
newRequest.addMouseListener(new MouseRequestClick(name));
requestList.add(newRequest);
requestList.validate();
//ToDo:add action listener to button requests
}
});
}
});
for(File f : Saver.getRequestFiles()){
String name = f.getName();
if (name.endsWith(".insomnia")) {
name = name.substring(0,name.length()-9);
JButton newRequest = new JButton(name);
newRequest.addMouseListener(new MouseRequestClick(name));
requestList.add(newRequest);
}
}
requestList.validate();
this.setLayout(new BorderLayout());
this.setBackground(Color.GRAY);
this.add(up_left, BorderLayout.NORTH);
......@@ -91,16 +118,17 @@ public class LeftPanel extends JPanel {
}
private class MouseRequestClick extends MouseAdapter {
Saver saver = new Saver();
RequestData requestData = new RequestData();
ResponseData responseData = new ResponseData(requestData);
MouseRequestClick(RequestData requestData , ResponseData responseData){
this.requestData = requestData;
this.responseData = responseData;
String name;
MouseRequestClick(String name){
this.name =name;
}
@Override
public void mouseClicked(MouseEvent e){
super.mouseClicked(e);
ResponseData data = new Saver().readRequestAndResponse(name);
data.getRequestData().setName("");
main_class.load(data);
main_class.loadRequest(data.getRequestData());
}
}
}
......
......@@ -38,7 +38,7 @@ public class RequestPanel extends JPanel {
private JPanel rightOfHeader = new JPanel();
private JPanel center_header = new JPanel(new GridLayout(1,2));
private JPanel header = new JPanel(new BorderLayout());
private String s []={"Patch","Put","Post","Delete","Get"};
private String s []={"Get","Post","Put","Delete"};
private JComboBox centerMenu = new JComboBox(s);
private JTextField URLTextField = new JTextField("http://api.myproduct.com/v1/users");
private JButton sendButton = new JButton("send");
......@@ -212,8 +212,8 @@ public class RequestPanel extends JPanel {
int selectedItem = -2;
MouseAdapter body_insert = null;
void initBody(){
if (selectedItem == Json_FormData.getSelectedIndex()) return;
void initBody(String... args){
if (args.length==0 && selectedItem == Json_FormData.getSelectedIndex()) return;
selectedItem = Json_FormData.getSelectedIndex();
if(body_pane.getComponentCount()>0) {
......@@ -231,6 +231,7 @@ public class RequestPanel extends JPanel {
};
textArea.setToolTipText("Enter JSON");
textArea.setBorder(border);
if (args.length>0) textArea.setText(args[0]);
body_pane.add(textArea);
} else if(Json_FormData.getSelectedItem().equals("Binary Data")){
JTextField path = new JTextField("File Path"){
......@@ -239,6 +240,7 @@ public class RequestPanel extends JPanel {
return new Dimension(body_pane.getSize().width-16,28);
}
};
if (args.length>0) path.setText(args[0]);
path.setBorder(border);
body_pane.add(path,BorderLayout.NORTH);
......@@ -258,12 +260,6 @@ public class RequestPanel extends JPanel {
}
});
}else {
BufferedImage master = null;
try {
master = ImageIO.read(new File("C:\\Users\\Lenovo\\IdeaProjects\\Insomnia\\src\\image\\535246.png"));
} catch (IOException e) {
}
final Image scaled = master.getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH);
final JPanel vl = new JPanel(vfLayout) {
@Override
......@@ -274,52 +270,70 @@ public class RequestPanel extends JPanel {
body_pane.add(vl);
if (body_insert==null){
MouseAdapter deleteClick = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
JButton Btn = (JButton) e.getSource();
//to repair showing
vl.remove(((JPanel) Btn.getParent()).getParent());
vl.revalidate();
vl.repaint();
}
};
body_insert = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e != null && !isLastComponent(((Component) e.getSource()).getParent().getParent(), vl)) return;
JTextField newHeaderField = new JTextField("key");
newHeaderField.addMouseListener(this);
newHeaderField.setBorder(border);
JTextField newValueField = new JTextField("value");
newValueField.setBorder(border);
JButton newDelete = new JButton();
newDelete.setPreferredSize(new Dimension(20, 20));
newDelete.setIcon(new ImageIcon(scaled));
newDelete.addMouseListener(deleteClick);
JPanel newRightOfHeader = new JPanel();
newRightOfHeader.add(newDelete);
JPanel new_center_header = new JPanel(new GridLayout(1, 2));
new_center_header.add(newHeaderField);
new_center_header.add(newValueField);
JPanel newHeader = new JPanel(new BorderLayout());
newHeader.add(newRightOfHeader, BorderLayout.EAST);
newHeader.add(new_center_header, BorderLayout.CENTER);
vl.add(newHeader);
vl.validate();
addBody();
}
};
}
body_insert.mouseClicked(null);
if (args.length==0) body_insert.mouseClicked(null);
}
body_pane.revalidate();
body_pane.repaint();
}
private void addBody(String... args){
Border border = BorderFactory.createLineBorder(Color.BLACK,3);
BufferedImage master = null;
try {
master = ImageIO.read(new File("C:\\Users\\Lenovo\\IdeaProjects\\Insomnia\\src\\image\\535246.png"));
} catch (IOException e) {
}
final Image scaled = master.getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH);
JTextField newHeaderField = new JTextField("key");
newHeaderField.addMouseListener(body_insert);
newHeaderField.setBorder(border);
JTextField newValueField = new JTextField("value");
newValueField.setBorder(border);
if (args.length>0){
newHeaderField.setText(args[0]);
newValueField.setText(args[1]);
}
JButton newDelete = new JButton();
newDelete.setPreferredSize(new Dimension(20, 20));
newDelete.setIcon(new ImageIcon(scaled));
final JPanel vl = (JPanel) body_pane.getComponent(0);
newDelete.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
JButton Btn = (JButton) e.getSource();
//to repair showing
vl.remove(((JPanel) Btn.getParent()).getParent());
vl.revalidate();
vl.repaint();
}
});
JPanel newRightOfHeader = new JPanel();
newRightOfHeader.add(newDelete);
JPanel new_center_header = new JPanel(new GridLayout(1, 2));
new_center_header.add(newHeaderField);
new_center_header.add(newValueField);
JPanel newHeader = new JPanel(new BorderLayout());
newHeader.add(newRightOfHeader, BorderLayout.EAST);
newHeader.add(new_center_header, BorderLayout.CENTER);
vl.add(newHeader);
vl.validate();
}
//request_up
public JPanel centerUp(){
sendButton.addMouseListener(new MouseAdapter() {
......@@ -362,6 +376,48 @@ public class RequestPanel extends JPanel {
}
public void load (RequestData r){
switch (r.getMethod()){
case "PUT":
centerMenu.setSelectedIndex(2);
break;
case "POST":
centerMenu.setSelectedIndex(1);
break;
case "DELETE":
centerMenu.setSelectedIndex(3);
break;
default:
centerMenu.setSelectedIndex(0);
break;
}
URLTextField.setText(r.getUrl());
if (r.isJson()){
Json_FormData.setSelectedIndex(1);
initBody(r.getBody());
}else if(r.getUploadPath().length()>1){
Json_FormData.setSelectedIndex(2);
initBody(r.getUploadPath());
}else{
Json_FormData.setSelectedIndex(0);
initBody("r");
if (body_insert!=null &&!r.getBody().isEmpty()) {
if (!r.getBody().contains("&")) {
String[] f1 = r.getBody().split("=");
addBody(f1);
} else {
String[] mFields = r.getBody().split("&");
for (String f : mFields) {
String[] f0 = f.split("=");
addBody(f0);
}
}
}
}
}
public void createRequestPanel() throws IOException {
addToMainRequestPanel(centerUp() , tabbedPaneCenterRequest());
......
......@@ -5,10 +5,11 @@
* version: 0.0
*/
package com.insomnia.parser;
import java.io.Serializable;
import java.util.HashMap;
public class RequestData {
private String name;
public class RequestData implements Serializable {
private String name = "";
//methods requests
public static String GET = "GET", POST = "POST", DELETE="DELETE", PUT="PUT";
//address of request
......
......@@ -3,14 +3,11 @@
*/
package com.insomnia.parser;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.*;
import java.util.List;
import java.util.Map;
public class ResponseData {
public class ResponseData implements Serializable {
private RequestData requestData;
private long startTime,finalTime;
......@@ -145,4 +142,5 @@ public class ResponseData {
public void setStatus(int status) {
this.status = status;
}
}
......@@ -63,9 +63,9 @@ public class Saver {
}
}
public void saveRequest2 (RequestData data) {
public void saveRequestAndResponse (ResponseData data) {
String fileName = data.getName()+".insomnia";
String fileName = data.getRequestData().getName()+".insomnia";
File file = new File(getRequestsDir(),fileName);
try {
......@@ -82,12 +82,12 @@ public class Saver {
}
}
public RequestData readRequest (String fileName){
public ResponseData readRequestAndResponse (String fileName){
try {
FileInputStream file = new FileInputStream(new File(getRequestsDir(),fileName));
FileInputStream file = new FileInputStream(new File(getRequestsDir(),fileName+".insomnia"));
ObjectInputStream in = new ObjectInputStream(file);
RequestData data = (RequestData) in.readObject();
ResponseData data = (ResponseData) in.readObject();
in.close();
file.close();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment