Commit 3162db31 authored by 9731301's avatar 9731301

add some changes

parent e891b2da
......@@ -8,11 +8,16 @@
<component name="ChangeListManager">
<list default="true" id="f2dd20fb-7e97-49ef-9dfe-5631626d7912" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/insomnia/parser/Insomnia.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/insomnia/parser/Insomnia.java" 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$/src/com/insomnia/GUI/Insomnia.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/insomnia/GUI/Insomnia.java" 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/RequestData.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/insomnia/parser/RequestData.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/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>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
......@@ -153,7 +158,8 @@
<workItem from="1591205535989" duration="8740000" />
<workItem from="1591376356200" duration="7395000" />
<workItem from="1591474740815" duration="314000" />
<workItem from="1591548369519" duration="737000" />
<workItem from="1591548369519" duration="6526000" />
<workItem from="1591614811869" duration="23168000" />
</task>
<servers />
</component>
......@@ -168,10 +174,10 @@
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="518" y="216" key="#com.intellij.fileTypes.FileTypeChooser/0.0.1536.824@0.0.1536.824" timestamp="1591133961860" />
<state x="472" y="159" key="#com.intellij.ide.util.MemberChooser" timestamp="1591034675582">
<state x="472" y="159" key="#com.intellij.ide.util.MemberChooser" timestamp="1591640326733">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="472" y="159" key="#com.intellij.ide.util.MemberChooser/0.0.1536.824@0.0.1536.824" timestamp="1591034675582" />
<state x="472" y="159" key="#com.intellij.ide.util.MemberChooser/0.0.1536.824@0.0.1536.824" timestamp="1591640326733" />
<state x="499" y="197" key="#com.intellij.ide.util.TreeClassChooserDialog" timestamp="1590961999762">
<screen x="0" y="0" width="1536" height="824" />
</state>
......@@ -180,38 +186,38 @@
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="499" y="160" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog/0.0.1536.824@0.0.1536.824" timestamp="1590603376669" />
<state x="369" y="145" key="ANALYSIS_DLG_com.intellij.analysis.BaseAnalysisAction$1" timestamp="1589304315504">
<state x="369" y="145" key="ANALYSIS_DLG_com.intellij.analysis.BaseAnalysisAction$1" timestamp="1591643836542">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="369" y="145" key="ANALYSIS_DLG_com.intellij.analysis.BaseAnalysisAction$1/0.0.1536.824@0.0.1536.824" timestamp="1589304315504" />
<state x="402" y="167" key="FileChooserDialogImpl" timestamp="1590494460700">
<state x="369" y="145" key="ANALYSIS_DLG_com.intellij.analysis.BaseAnalysisAction$1/0.0.1536.824@0.0.1536.824" timestamp="1591643836542" />
<state x="402" y="167" key="FileChooserDialogImpl" timestamp="1591643834959">
<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="154" key="GridCell.Tab.0.bottom" timestamp="1591216845298">
<state x="402" y="167" key="FileChooserDialogImpl/0.0.1536.824@0.0.1536.824" timestamp="1591643834959" />
<state width="1493" height="154" key="GridCell.Tab.0.bottom" timestamp="1591643837235">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="154" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1591216845298" />
<state width="1493" height="154" key="GridCell.Tab.0.center" timestamp="1591216845298">
<state width="1493" height="154" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1591643837235" />
<state width="1493" height="154" key="GridCell.Tab.0.center" timestamp="1591643837234">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="154" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1591216845298" />
<state width="1493" height="154" key="GridCell.Tab.0.left" timestamp="1591216845298">
<state width="1493" height="154" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1591643837234" />
<state width="1493" height="154" key="GridCell.Tab.0.left" timestamp="1591643837233">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="154" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1591216845298" />
<state width="1493" height="154" key="GridCell.Tab.0.right" timestamp="1591216845298">
<state width="1493" height="154" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1591643837233" />
<state width="1493" height="154" key="GridCell.Tab.0.right" timestamp="1591643837235">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="154" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1591216845298" />
<state width="1493" height="154" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1591643837235" />
<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="1591548525191">
<state x="425" y="237" key="com.intellij.ide.util.TipDialog" timestamp="1591614884627">
<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="1591548525191" />
<state x="425" y="237" key="com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824" timestamp="1591614884627" />
<state x="499" y="179" key="extract.method.dialog" timestamp="1590145349556">
<screen x="0" y="0" width="1536" height="824" />
</state>
......
package com.insomnia.GUI;
import java.awt.*;
import java.io.IOException;
......
......@@ -7,36 +7,25 @@ package com.insomnia.GUI;
import com.insomnia.parser.RequestData;
import com.insomnia.parser.ResponseData;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
import static com.sun.glass.ui.Cursor.setVisible;
import static java.awt.Frame.*;
public class InsomniaGUI {
JFrame frame ;
RespondPanel response;
RequestPanel request;
ResponseData data_req = null;
public void load(ResponseData d){
data_req = d;
response.load(d);
}
public boolean hasRequest(){
return data_req!=null;
}
public void loadRequest (RequestData r){
request.load(r);
}
private JFrame frame ;
private RespondPanel response;
private RequestPanel request;
private ResponseData data_req = null;
/**
* create a insomnia gui
* @throws IOException
*/
public InsomniaGUI() throws IOException {
frame = new JFrame();
frame.setTitle("Insomnia");
......@@ -286,4 +275,75 @@ public class InsomniaGUI {
}
}
/**
* this method is for loading data for sending data and get the response
* @param d
*/
public void load(ResponseData d){
data_req = d;
response.load(d);
}
/**
* this method checks that is there any request here or not
*/
public boolean hasRequest(){
return data_req!=null;
}
/**
* @param r is the request data
*/
public void loadRequest (RequestData r){
request.load(r);
}
/**
* @return the frame of app
*/
public JFrame getFrame() {
return frame;
}
/**
*set the frame of app
*/
public void setFrame(JFrame frame) {
this.frame = frame;
}
/**
* get the response panel
* @return the response panel
*/
public RespondPanel getResponse() {
return response;
}
/**
* set the response panel
*/
public void setResponse(RespondPanel response) {
this.response = response;
}
/**
*
* @return the request panel
*/
public RequestPanel getRequest() {
return request;
}
/**
*set the request panel
*/
public void setRequest(RequestPanel request) {
this.request = request;
}
public ResponseData getData_req() {
return data_req;
}
}
......@@ -40,7 +40,7 @@ public class LeftPanel extends JPanel {
public void mouseClicked(MouseEvent e) {
if (!main_class.hasRequest()){
JOptionPane.showMessageDialog(main_class.frame,"You need to send a request first.","Error",JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(main_class.getFrame(),"You need to send a request first.","Error",JOptionPane.ERROR_MESSAGE);
return;
}
JFrame newRequestFrame = new JFrame("request name");
......@@ -66,7 +66,7 @@ public class LeftPanel extends JPanel {
newRequestFrame.setVisible(false);
//Save Request
ResponseData data = main_class.data_req;
ResponseData data = main_class.getData_req();
data.getRequestData().setName(name);
new Saver().saveRequestAndResponse(data);
//Add Request to list
......@@ -74,7 +74,6 @@ public class LeftPanel extends JPanel {
newRequest.addMouseListener(new MouseRequestClick(name));
requestList.add(newRequest);
requestList.validate();
//ToDo:add action listener to button requests
}
});
}
......@@ -98,10 +97,18 @@ public class LeftPanel extends JPanel {
this.setBackground(Color.LIGHT_GRAY);
}
/**
*
* @return the addRequest button
*/
public JButton getAddRequest() {
return addRequest;
}
/**
*
* @return the menu
*/
public JMenu getMenu() {
return menu;
}
......@@ -118,6 +125,7 @@ public class LeftPanel extends JPanel {
return up_left;
}
private class MouseRequestClick extends MouseAdapter {
String name;
MouseRequestClick(String name){
......
/**
* represents a panel for requests
*/
package com.insomnia.GUI;
import com.insomnia.parser.*;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.text.Utilities;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.DataInput;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
......@@ -95,6 +95,9 @@ public class RequestPanel extends JPanel {
return tabbedPaneCenterRequest;
}
/**
*this method is for adding headers
*/
private void addHeader(String... args){
try {
Border border = BorderFactory.createLineBorder(Color.BLACK, 3);
......@@ -150,14 +153,30 @@ public class RequestPanel extends JPanel {
}
}
/**
*
* @param c is component
* @return the component is the last one or not
*/
boolean isLastComponent(Component c){
return isLastComponent(c,mainCenterHeader);
}
/**
*
* @param c is component
* @param p is a panel
* @return the component is the last one or not
*/
boolean isLastComponent(Component c,JPanel p){
return p.getComponent(p.getComponentCount()-1)==c;
}
/**
*
* @return the headers
*/
public HashMap<String,String> getHeaders(){
HashMap<String,String> headers = new HashMap<>();
for(Component c : mainCenterHeader.getComponents()){
......@@ -241,6 +260,10 @@ public class RequestPanel extends JPanel {
int selectedItem = -2;
MouseAdapter body_insert = null;
/**
*create the body layout
*/
void initBody(String... args){
if (args.length==0 && selectedItem == Json_FormData.getSelectedIndex()) return;
selectedItem = Json_FormData.getSelectedIndex();
......@@ -325,6 +348,9 @@ public class RequestPanel extends JPanel {
}
/**
*add component to the body
*/
private void addBody(String... args){
Border border = BorderFactory.createLineBorder(Color.BLACK,3);
BufferedImage master = null;
......@@ -494,7 +520,10 @@ public class RequestPanel extends JPanel {
}
/**
*
* @return body panel
*/
public JPanel getBody() {
return body;
}
......
/**
* represents a panel for responds that contains response data and components and action listeners
* @zahra_fatehi
* @version 0.0
*/
package com.insomnia.GUI;
import com.insomnia.parser.ResponseData;
import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class RespondPanel extends JPanel {
private Border border = BorderFactory.createLineBorder(Color.BLACK,3);
......
/**
* Parser represents a class to get data from console as sting and find and set requestData fields
* @zahra_fatehi
* @version 0.0
*/
package com.insomnia.parser;
import java.util.ArrayList;
import java.util.HashMap;
public class Parser {
/**
*
* @param args are the fields data
* @return an arrayList of args
*/
public static ArrayList<String> fixArgs(String[] args){
ArrayList<String> args2 = new ArrayList<>();
String f = "";
......@@ -98,7 +107,11 @@ public class Parser {
return requestData;
}
/**
* this method is to find the kind of method we wanna use
* @param v is the name of method that maybe is with lower case or trim
* @return the expected method
*/
public static String findMethod(String v){
switch (v.toUpperCase().trim()){
case "GET":
......@@ -106,12 +119,16 @@ public class Parser {
case "DELETE":
case "PUT":
return v.toUpperCase().trim();
default:
return "GET";
}
}
/**
*this method is to find the value
* @param v is the value which has \ at the beginning and at the end
* @return the expected value
*/
static String findParamValue(String v){
if (v.startsWith("\"") && v.endsWith("\"")){
return v.substring(1,v.length()-1);
......@@ -119,6 +136,11 @@ public class Parser {
return v;
}
/**
* this method is for finding args
* @param v is the ard with -
* @return the arg
*/
static String findArg (String v){
if (v.startsWith("--")){
return v.substring(2);
......
/**
* this class represents a class which contains a method to load data from RequestData class and set the ResponseData class fields
*/
package com.insomnia.parser;
import javax.net.ssl.HttpsURLConnection;
import java.io.*;
......@@ -10,7 +13,11 @@ import java.nio.file.Paths;
import java.util.HashMap;
public class RequestLoader {
/**
* a method to load request data and get response data
* @param data is the information we get from request
*
*/
public static ResponseData run (RequestData data){
String boundary = "*****" + System.currentTimeMillis() + "*****";
ResponseData responseData = new ResponseData(data);
......
/**
* ResponseData represents a class that contains responses data and has some methods to keep these information
* @zahra_fatehi
* @version 0.0
*/
package com.insomnia.parser;
......@@ -19,20 +21,35 @@ public class ResponseData implements Serializable {
private String errorMessage = "";
private long size;
/**
* create a response data with request data
* @param data is the request data
*/
public ResponseData (RequestData data){
this.requestData = data;
startTime = System.currentTimeMillis();
}
/**
* @return the time of finishing finalTime
*/
public ResponseData finish(){
finalTime = System.currentTimeMillis();
return this;
}
/**
* set size of requestData
* @param size
*/
public void setSize(long size) {
this.size = size;
}
/**
*
* @return the size of request data
*/
public long getSize() {
return size;
}
......@@ -77,10 +94,18 @@ public class ResponseData implements Serializable {
return finalTime;
}
/**
*
* @return the time of start processing data
*/
public long getStartTime() {
return startTime;
}
/**
*
* @return true of processing is successful or not
*/
public boolean isSuccessful() {
return successful;
}
......@@ -108,6 +133,10 @@ public class ResponseData implements Serializable {
this.errorMessage = errorMessage;
}
/**
*
* @param status is the status of response data
*/
public void setStatus(int status) {
this.status = status;
}
......
/**
* represents a class that contains some methods to save requests
* @zahra_fatehi
* @version 0.0
*/
package com.insomnia.parser;
import java.io.*;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Saver {
private static final String appName = "Insomnia";
//get address of app
/**
* get the direction app(insomnia)
* @return the the direction of he app as string
*/
public static String getDirApp(){
return System.getProperty("user.dir");
}
/**
* get the outputs of requests direction
* @return the address of where we save requests
*/
public static String getOutputDir(){
File f = new File(getDirApp(),"Outputs");
f.mkdir();
return f.toString();
}
/**
*
* @return
*/
public static String getRequestsDir(){
File f = new File(getDirApp(),"Requests");
f.mkdir();
......@@ -58,6 +72,10 @@ public class Saver {
}
}
/**
* this method saves the requests and their responses
* @param data is the request data
*/
public void saveRequestAndResponse (ResponseData data) {
String fileName = data.getRequestData().getName()+".insomnia";
......@@ -77,6 +95,11 @@ public class Saver {
}
}
/**
* this method is for read responses from a file
* @param fileName is the name of the file where requests and responses will be save there
* @return the response data
*/
public ResponseData readRequestAndResponse (String fileName){
try {
FileInputStream file = new FileInputStream(new File(getRequestsDir(),fileName+".insomnia"));
......@@ -93,6 +116,11 @@ public class Saver {
return null;
}
/**
* this method is for saving responses in a file
* @param data is the response data
* @param stream
*/
public static void saveResponse(ResponseData data, InputStream stream) {
if (!data.getRequestData().getOutput().equals("-null")){
String fileName;
......@@ -121,6 +149,10 @@ public class Saver {
}
}
/**
* this method is for getting files
* @return the files of requests
*/
public static File[] getRequestFiles(){
return new File(getRequestsDir()).listFiles();
}
......
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