Commit b5ed2d2c authored by kiana's avatar kiana

Initial commit

parents
Pipeline #5158 failed with stages
File added
import javax.print.DocFlavor;
import java.awt.event.ActionListener;
import java.awt.event.TextEvent;
import java.awt.event.TextListener;
import java.io.*;
import java.net.*;
import java.awt.event.ActionEvent;
import java.util.List;
import java.util.Map;
import java.util.Random;
public class Action {
URL obj1;
HttpURLConnection con;
InsomniaFrame insomnia;
NewRequest request;
RequestList requestList;
Response response;
Menu menu;
String completeRequest;
String value;
String key;
String address;
public void save(String fileName, String str) throws IOException {
//System.out.println(str);
File file = new File(fileName);
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
writer.write(str);
writer.close();
File temp = File.createTempFile("file", ".txt", file.getParentFile());
String delete = "-S";
String deleteSave = "--save";
String charset = "UTF-8";
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), charset));
PrintWriter writerForDelete = new PrintWriter(new OutputStreamWriter(new FileOutputStream(temp), charset));
for (String line; (line = reader.readLine()) != null; ) {
line = line.replace(delete, "");
line = line.replace(deleteSave, "");
writerForDelete.println(line);
}
reader.close();
writerForDelete.close();
file.delete();
temp.renameTo(file);
}
public HttpURLConnection connect(URL url, HttpURLConnection connection) {
try {
URLConnection urlConnection = url.openConnection();
if (urlConnection instanceof HttpURLConnection) {
connection = (HttpURLConnection) urlConnection;
//connection.setRequestMethod(requestType);
}
return connection;
} catch (IOException e) {
System.out.println("E" + e.getMessage());
return null;
}
}
public void firstConnect(){
address = "http://google.com";
String link_url = address;
try {
obj1 = new URL(link_url); //URL Connection Created...
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
con = (HttpURLConnection) obj1.openConnection(); //Http URL Connection Created...
} catch (IOException e) {
e.printStackTrace();
}
}
public Action() {
// System.out.println(address);
// try {
// con.setRequestMethod("GET");
// } catch (ProtocolException e) {
// e.printStackTrace();
// }
//
firstConnect();
insomnia = new InsomniaFrame();
request = new NewRequest(insomnia.frame, insomnia.p1, insomnia.tab1);
request.body(request.textAreaBody, insomnia.p1, insomnia.frame, insomnia.tab1);
request.auth(insomnia.frame, insomnia.p2, insomnia.tab1);
request.query(insomnia.frame, insomnia.p3, insomnia.tab1);
request.header(insomnia.frame, insomnia.p4, insomnia.tab1);
request.docs(insomnia.frame, insomnia.p5, insomnia.tab1);
requestList = new RequestList(insomnia.frame, insomnia.panel1);
//response part3
response = new Response(insomnia.frame);
response.header(insomnia.frame, insomnia.tab2);
response.messageBody(insomnia.frame, insomnia.tab2);
//menus
menu = new Menu(insomnia.frame, insomnia.panel1);
requestMethod();
gettingURL();
gettingHeaders();
saveButton();
connect(obj1, con);
request.URL.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
con.connect();
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
StringBuffer responseBuffer = new StringBuffer();
String lines;
while ((lines = in.readLine()) != null){
responseBuffer.append(lines + "\n");
}
in.close();
response.responseBody.setText(responseBuffer.toString());
responseHeader();
response.ok.setText(con.getResponseCode() + " " + con.getResponseMessage());
System.out.println("Connection Response Message : "+con.getResponseMessage());
System.out.println("RESPONE:" + con.getRequestMethod());
System.out.println(con.getResponseCode());
System.out.println(con.getRequestMethod() + "100000000");
con.disconnect();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
});
insomnia.showGui();
}
public void saveButton() {
request.save.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Random random = new Random();
int k = random.nextInt(100000);
String fileName = "savedRequest" + k;
try {
save(fileName, completeRequest);
} catch (IOException ex) {
ex.printStackTrace();
}
}
});
}
public void requestMethod() {
request.request.addActionListener(new ActionListener() {//add actionlistner to listen for change
@Override
public void actionPerformed(ActionEvent e) {
String requestMethod = (String) request.request.getSelectedItem();//get the selected item
// try {
// con.setRequestMethod(requestMethod);
// } catch (ProtocolException ex) {
// ex.printStackTrace();
// }
}
});
}
public void gettingURL() {
request.URL.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
String textDialogue = request.textAreaSend.getText();
System.out.println(textDialogue);
address = textDialogue;
try {
obj1 = new URL(address); //URL Connection Created...
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
con = (HttpURLConnection) obj1.openConnection(); //Http URL Connection Created...
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(address);
try {
con.setRequestMethod("GET");
} catch (ProtocolException e) {
e.printStackTrace();
}
connect(obj1, con);
}
});
}
public void gettingHeaders(){
request.URL.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
key = request.keyHeader1.getText();
System.out.println(key);
}
});
request.URL.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
value = request.valueHeader1.getText();
System.out.println(value);
}
});
request.URL.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (key != null && value != null)
con.setRequestProperty(key, value);
}
});
}
public void responseHeader() {
//get header by 'key'
//String server = con.getHeaderField("Server");
request.URL.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Map<String, List<String>> map = con.getHeaderFields();
for (Map.Entry<String, List<String>> entry : map.entrySet()) {
response.responseHeaders.setText("Key : " + entry.getKey() +
" ,Value : " + entry.getValue());
}
}
});
}
}
public class ConsoleColors {
public static final String RESET = "\033[0m"; // Text Reset
public static final String WHITE_BOLD_BRIGHT = "\033[1;97m"; // WHITE
public static final String BLACK_BACKGROUND_BRIGHT = "\033[0;100m";// BLACK
public static final String RED_BACKGROUND_BRIGHT = "\033[0;101m";// RED
public static final String GREEN_BACKGROUND_BRIGHT = "\033[0;102m";// GREEN
public static final String YELLOW_BACKGROUND_BRIGHT = "\033[0;103m";// YELLOW
public static final String BLUE_BACKGROUND_BRIGHT = "\033[0;104m";// BLUE
}
\ No newline at end of file
import javax.swing.*;
import java.awt.*;
import javax.swing.border.Border;
public class InsomniaFrame {
JFrame frame;
JPanel panel;
ConsoleColors consoleColors;
JLabel label;
JPanel panel1;
JPanel panel2;
JPanel panel3;
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
JPanel p3 = new JPanel();
JPanel p4 = new JPanel();
JPanel p5 = new JPanel();
JTabbedPane tab1;
JTabbedPane tab2;
//JSplitPane splitPane;
public InsomniaFrame(){
panel1 = new JPanel();
panel2 = new JPanel();
panel3 = new JPanel();
tab1 = new JTabbedPane();
tab2 = new JTabbedPane();
consoleColors = new ConsoleColors();
frame = new JFrame("Insomnia");
panel = new JPanel();
label = new JLabel();
frame.setBackground(Color.BLACK);
frame.setSize(1500,800);// 2000, 1000
frame.setPreferredSize(new Dimension(1500, 800));
frame.setResizable(true);
frame.setLocation(50,50);
frame.setLayout(null);
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
frame.getContentPane().setBackground(Color.GRAY);
// splitPane = new JSplitPane();
frame.setBackground(Color.BLUE);
label.setText("");
JSplitPane sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, panel3, tab1);
JSplitPane sp2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, sp, panel1);
frame.add(sp2, BorderLayout.CENTER);
//frame.add(panel);
}
public void showGui(){
frame.setVisible(true);
}
}
import javax.swing.*;
import java.awt.EventQueue;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
public class Main {
public static void main(String[] args) {
Action action = new Action();
// InsomniaFrame insomnia = new InsomniaFrame();
// NewRequest request = new NewRequest(insomnia.frame, insomnia.p1,insomnia.tab1);
// request.body(request.textAreaBody, insomnia.p1, insomnia.frame, insomnia.tab1);
// request.auth(insomnia.frame, insomnia.p2, insomnia.tab1);
// request.query(insomnia.frame, insomnia.p3, insomnia.tab1);
// request.header(insomnia.frame, insomnia.p4, insomnia.tab1);
// request.docs(insomnia.frame, insomnia.p5, insomnia.tab1);
//
// RequestList requestList = new RequestList(insomnia.frame, insomnia.panel1);
// //response part3
// Response response = new Response(insomnia.frame);
// response.header(insomnia.frame, insomnia.tab2);
// response.messageBody(insomnia.frame, insomnia.tab2);
// //menus
// Menu menu = new Menu(insomnia.frame, insomnia.panel1);
//
// insomnia.showGui();
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.reflect.InvocationTargetException;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Window;
import java.lang.reflect.Method;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.KeyStroke;
import java.lang.reflect.Method;
public class Menu {
JMenuBar menuBar;
JMenuItem menuItem;
JMenu application;
JMenu view;
JMenu help;
JMenu options;
JMenu exit;
JMenuItem hideOnTray;
JMenuItem toggleFullScreen;
JMenuItem toggleSidebar;
JMenuItem helpHelp;
JMenuItem about;
JLabel labelHelp;
JLabel labelAbout;
JButton test;
boolean hasBeenClicked = false;
boolean isClicked = false;
/**
* for menu
* add application menu and its submenus
* add view menu and its submenus
* add help menu and its submenus
* added actionListener to menuItems
* @param frame
*/
public Menu(JFrame frame, JPanel panel){
//Create the menu bar.
menuBar = new JMenuBar();
test = new JButton("testtt");
//Build the application menu.
application = new JMenu("Application");
application.setMnemonic(KeyEvent.VK_A);
application.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items");
menuBar.add(application);
//Build view menu
view = new JMenu("View");
view.setMnemonic(KeyEvent.VK_A);
view.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items");
menuBar.add(view);
//Build Help menu
help = new JMenu("Help");
help.setMnemonic(KeyEvent.VK_A);
help.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items");
menuBar.add(help);
//toggleFullScreen menu item
view.addSeparator();
toggleFullScreen = new JMenuItem("Toggle Full Screen");
toggleFullScreen.setMnemonic(KeyEvent.VK_S);
view.add(toggleFullScreen);
//toggleFullScreen.add(test);
toggleFullScreen.setMnemonic( 'F' );
toggleFullScreen.setAccelerator(KeyStroke.getKeyStroke('F'));
toggleFullScreen.addActionListener(
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (!isClicked)
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
else
frame.setSize(frame.getPreferredSize());
isClicked = !isClicked;
}
}
);
view.add(toggleFullScreen);
//toggleSideBar submenu
view.addSeparator();
toggleSidebar = new JMenuItem("Toggle Sidebar");
toggleFullScreen.setMnemonic(KeyEvent.VK_S);
view.add(toggleSidebar);
//toggleSidebar.setAccelerator(KeyStroke.getKeyStroke('S'));
toggleSidebar.addActionListener(
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(!hasBeenClicked) {
panel.setVisible(false);
}
else {
panel.setVisible(true);
}
hasBeenClicked = !hasBeenClicked;
}
}
);
//About menuItem
labelAbout = new JLabel("<html>Email: k.kasiri@aut.ac.ir<br/>Student number: 9831006<br/>Name: kiana</html> ", SwingConstants.CENTER);
help.addSeparator();
about = new JMenuItem("About");
about.setMnemonic(KeyEvent.VK_A);
help.add(about);
about.setMnemonic( 'A' );
about.setAccelerator(KeyStroke.getKeyStroke('A'));
about.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent e )
{
JOptionPane.showMessageDialog(frame, labelAbout);
}
}
);
//Help menu item
labelHelp = new JLabel("something to help you , it's in the next phase:))");
help.addSeparator();
helpHelp = new JMenuItem("Help");
helpHelp.setMnemonic(KeyEvent.VK_H);
help.add(helpHelp);
helpHelp.setMnemonic( 'H' );
helpHelp.setAccelerator(KeyStroke.getKeyStroke('H'));
helpHelp.addActionListener(
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e)
{
JOptionPane.showMessageDialog(frame, labelHelp);
}
}
);
//options submenu
application.addSeparator();
options = new JMenu("Options");
options.setMnemonic(KeyEvent.VK_S);
application.add(options);
//a group of check box menu items for option submenu
options.addSeparator();
JCheckBoxMenuItem cbMenuItem = new JCheckBoxMenuItem("exit/system tray");
cbMenuItem.setMnemonic(KeyEvent.VK_C);
options.add(cbMenuItem);
cbMenuItem = new JCheckBoxMenuItem("follow redirect");
cbMenuItem.setMnemonic(KeyEvent.VK_H);
options.add(cbMenuItem);
final JPopupMenu popup = new JPopupMenu();
// New project menu item
JMenuItem menuItem = new JMenuItem("New Project...",
new ImageIcon("images/newproject.png"));
menuItem.setMnemonic(KeyEvent.VK_P);
menuItem.getAccessibleContext().setAccessibleDescription(
"New Project");
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(frame, "New Project clicked!");
}
});
popup.add(menuItem);
menuBar.add(popup);
// New File menu item
menuItem = new JMenuItem("New File...",
new ImageIcon("images/newfile.png"));
menuItem.setMnemonic(KeyEvent.VK_F);
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(frame, "New File clicked!");
}
});
popup.add(menuItem);
menuBar.add(popup);
//exit submenu
application.addSeparator();
exit = new JMenu("Exit");
exit.setMnemonic(KeyEvent.VK_S);
application.add(exit);
JMenuItem exitExit = new JMenuItem("Exit");
exit.add(exitExit);
//actionListener for exit
class exitApp implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
exitExit.addActionListener(new exitApp());
exitExit.setAccelerator(KeyStroke.getKeyStroke('E'));
frame.setJMenuBar(menuBar);
//system hide tray
hideOnTray = new JMenuItem("Hide on system tray");
exit.add(hideOnTray);
hideOnTray.addActionListener(
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
frame.setExtendedState(JFrame.ICONIFIED);
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
}
});
}
}
);
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class NewRequest {
JTextArea textAreaBody;
JButton URL;
TextArea textAreaSend;
JButton save;
JComboBox request;
JTextField keyHeader1;
JTextField valueHeader1;
JTextField keyHeader2;
JTextField valueHeader2;
JCheckBox statusHeader1;
JButton trashHeader1;
JCheckBox statusHeader2;
JButton trashHeader2;
JCheckBox statusQuery1;
JButton trashQuery1;
JCheckBox statusQuery2;
JButton trashQuery2;
JButton addHeader;
JButton addQuery;
JTextField keyQuery1;
JTextField valueQuery1;
JTextField keyQuery2;
JTextField valueQuery2;
/**
* constructor
* @param frame
* @param p1
* @param tab
*/
public NewRequest(JFrame frame, JPanel p1,JTabbedPane tab){
URL = new JButton("Send");
URL.setLocation(800,50);
URL.setSize(100,50);
frame.add(URL);
textAreaSend = new TextArea();
textAreaSend.setBounds(500,50,300,50);
frame.add(textAreaSend);
String[] requestString ={"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD", "CUSTOM METHOD"};
request = new JComboBox(requestString);
request.setBounds(400,50,100,50);
frame.add(request);
//save button
save = new JButton("Save");
save.setLocation(800,120);
save.setSize(100,40);
frame.add(save);
//body tab
textAreaBody = new JTextArea(35,30);
textAreaBody.setBackground(Color.LIGHT_GRAY);
p1.add(textAreaBody);
tab.setBounds(400,150,500,650);
tab.setBackground(Color.PINK);
frame.add(tab);
frame.setLayout(null);
frame.setVisible(true);
}
/**
* adding Body Tab to the frame
* adding a check box and textArea for body tab
* @param textAreaBody
* @param p1
* @param frame
* @param tab
*/
public void body(JTextArea textAreaBody, JPanel p1, JFrame frame, JTabbedPane tab){
p1.setBackground(Color.LIGHT_GRAY);
String[] bodyStrings = { "JSN", "XML", "YAML", "EDN", "Other" };
JComboBox bodyList = new JComboBox(bodyStrings);
p1.add(bodyList);
bodyList.setBounds(100,100,200,100);
p1.add(textAreaBody);
tab.add("Body" ,p1);
Label bodyLabel = new Label("Select a body type from above");
p1.add(bodyLabel);
bodyLabel.setBounds(50,50,100,50);
frame.add(tab);
}
/**
* adding Header Tab
* adding double textFields and trash Icon
* adding an "add" icon
* @param frame
* @param p4
* @param tab
*/
public void header(JFrame frame, JPanel p4, JTabbedPane tab){
JPanel head = new JPanel();
keyHeader1 = new JTextField();
valueHeader1 = new JTextField();
keyHeader2 = new JTextField();
valueHeader2 = new JTextField();
statusHeader1 = new JCheckBox();
trashHeader1 = new JButton("X");
statusHeader2 = new JCheckBox();
trashHeader2 = new JButton("X");
addHeader = new JButton("Add");
p4.setBackground(Color.LIGHT_GRAY);
//p4.setSize(300,300);
p4.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.VERTICAL;
gbc.ipadx = 10;
gbc.gridx = 0;
gbc.gridy = 0;
p4.add(addHeader, gbc);
gbc.fill = GridBagConstraints.VERTICAL;
gbc.ipadx = 150;
gbc.gridx = 0;
gbc.gridy = 1;
p4.add(keyHeader1, gbc);
gbc.gridx = 1;
gbc.gridy = 1;
p4.add(valueHeader1, gbc);
gbc.ipadx = 20;
gbc.gridx = 2;
gbc.gridy = 1;
p4.add(statusHeader1, gbc);
//head.add(statusHeader1, gbc);
gbc.gridx = 3;
gbc.gridy = 1;
p4.add(trashHeader1, gbc);
//head.add(trashHeader1, gbc);
gbc.fill = GridBagConstraints.VERTICAL;
gbc.ipadx = 150;
gbc.gridx = 0;
gbc.gridy = 2;
p4.add(keyHeader2, gbc);
//head.add(keyHeader2, gbc);
gbc.gridx = 1;
gbc.gridy = 2;
p4.add(valueHeader2, gbc);
//head.add(valueHeader2, gbc);
gbc.ipadx = 20;
gbc.gridx = 2;
gbc.gridy = 2;
p4.add(statusHeader2, gbc);
//head.add(statusHeader2);
gbc.gridx = 3;
gbc.gridy = 2;
p4.add(trashHeader2, gbc);
//head.add(trashHeader2);
// addHeader.addActionListener(
// new ActionListener() {
// @Override
// public void actionPerformed(ActionEvent e) {
// p4.add(head);
// }
// }
// );
tab.add("Header",p4);
frame.add(tab);
}
/**
* Adding Query Tab
* adding double textFields and trash Icon
* adding an "add" icon
* @param frame
* @param p3
* @param tab
*/
public void query(JFrame frame, JPanel p3, JTabbedPane tab){
keyQuery1 = new JTextField();
valueQuery1 = new JTextField();
keyQuery2 = new JTextField();
valueQuery2 = new JTextField();
statusQuery1 = new JCheckBox();
statusQuery2 = new JCheckBox();
trashQuery1 = new JButton("X");
trashQuery2 = new JButton("X");
addQuery = new JButton("Add");
p3.setBackground(Color.LIGHT_GRAY);
p3.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.VERTICAL;
gbc.ipadx = 10;
gbc.gridx = 0;
gbc.gridy = 0;
p3.add(addQuery, gbc);
gbc.fill = GridBagConstraints.VERTICAL;
gbc.ipadx = 150;
gbc.gridx = 0;
gbc.gridy = 1;
p3.add(keyQuery1, gbc);
gbc.gridx = 1;
gbc.gridy = 1;
p3.add(valueQuery1, gbc);
gbc.ipadx = 20;
gbc.gridx = 2;
gbc.gridy = 1;
p3.add(statusQuery1, gbc);
gbc.gridx = 3;
gbc.gridy = 1;
p3.add(trashQuery1, gbc);
gbc.fill = GridBagConstraints.VERTICAL;
gbc.ipadx = 150;
gbc.gridx = 0;
gbc.gridy = 2;
p3.add(keyQuery2, gbc);
gbc.gridx = 1;
gbc.gridy = 2;
p3.add(valueQuery2, gbc);
gbc.ipadx = 20;
gbc.gridx = 2;
gbc.gridy = 2;
p3.add(statusQuery2, gbc);
gbc.gridx = 3;
gbc.gridy = 2;
p3.add(trashQuery2, gbc);
tab.add("Query",p3);
frame.add(tab);
}
/**
* adding Auth Tab
* @param frame
* @param p2
* @param tab
*/
public void auth(JFrame frame, JPanel p2, JTabbedPane tab){
p2.setBackground(Color.LIGHT_GRAY);
tab.add("Auth",p2);
}
/**
* adding Docs Tab
* @param frame
* @param p5
* @param tab
*/
public void docs(JFrame frame, JPanel p5, JTabbedPane tab){
p5.setBackground(Color.LIGHT_GRAY);
tab.add("Auth",p5);
}
}
import javax.swing.*;
import java.awt.*;
public class RequestList {
private JLabel savedRequests;
private JButton request1;
private JLabel requestType1;
private JButton request2;
private JLabel requestType2;
private JButton request3;
private JLabel requestType3;
private JLabel label;
/**
* constructor
*
* @param frame
* @param panel1
*/
public RequestList(JFrame frame, JPanel panel1) {
savedRequests = new JLabel("SAVED REQUESTS");
// panel1 = new JPanel();
//panel1.add(savedRequests);
request1 = new JButton("request1");
request1.setContentAreaFilled(false);
request1.setOpaque(true);
request1.setBackground(Color.orange);
request2 = new JButton("request2");
request2.setContentAreaFilled(false);
request2.setOpaque(true);
request2.setBackground(Color.blue);
request3 = new JButton("request3");
request3.setContentAreaFilled(false);
request3.setOpaque(true);
request3.setBackground(Color.yellow);
String type;
requestType1 = new JLabel("GET");
requestType1.setOpaque(true);
requestType1.setBackground(Color.orange);
requestType2 = new JLabel("POST");
requestType2.setOpaque(true);
requestType2.setBackground(Color.blue);
requestType3 = new JLabel("PUT");
requestType3.setOpaque(true);
requestType3.setBackground(Color.yellow);
label = new JLabel("Insomnia");
label.setLocation(40, 0);
label.setSize(100, 50);
Font labelFont = label.getFont();
String labelText = label.getText();
label.setForeground(Color.cyan);
label.setFont(new Font(labelFont.getName(), Font.PLAIN, 50));
//label.setFont();
//panel1.add(label);
// panel1.add(requestType1);
// panel1.add(request1);
//
// panel1.add(requestType2);
// panel1.add(request2);
//
// panel1.add(requestType3);
// panel1.add(request3);
GridBagConstraints gbc = new GridBagConstraints();
GridBagLayout layout = new GridBagLayout();
panel1.setLayout(layout);
gbc.fill = GridBagConstraints.VERTICAL;
gbc.ipadx = 60;
gbc.gridx = 0;
gbc.gridy = 0;
panel1.add(label, gbc);
gbc.fill = GridBagConstraints.VERTICAL;
gbc.ipadx = 40;
gbc.ipady = 30;
gbc.gridx = 0;
gbc.gridy = 1;
panel1.add(request1, gbc);
gbc.ipadx = 40;
gbc.ipady = 30;
gbc.gridx = 1;
gbc.gridy = 1;
gbc.gridwidth = 2;
panel1.add(requestType1, gbc);
gbc.fill = GridBagConstraints.VERTICAL;
gbc.ipadx = 40;
gbc.ipady = 30;
gbc.gridx = 0;
gbc.gridy = 2;
panel1.add(request2, gbc);
gbc.ipadx = 40;
gbc.ipady = 30;
gbc.gridx = 1;
gbc.gridy = 2;
gbc.gridwidth = 2;
panel1.add(requestType2, gbc);
gbc.fill = GridBagConstraints.VERTICAL;
gbc.ipadx = 40;
gbc.ipady = 30;
gbc.gridx = 0;
gbc.gridy = 3;
panel1.add(request3, gbc);
gbc.ipadx = 40;
gbc.ipady = 30;
gbc.gridx = 1;
gbc.gridy = 3;
gbc.gridwidth = 2;
panel1.add(requestType3, gbc);
panel1.setBounds(0, 0, 405, 800);
panel1.setBackground(Color.DARK_GRAY);
frame.add(panel1);
}
}
import javax.swing.*;
import java.awt.*;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
public class Response {
//JTabbedPane tab;
JButton ok;
JButton time;
JButton quality;
JPanel panel1;
JPanel panel2;
JComboBox box;
JButton copyToClipBoard;
JTextField keyHeader1;
JTextField valueHeader1;
JTextField keyHeader2;
JTextField valueHeader2;
JCheckBox status1;
JButton trash1;
JCheckBox status2;
JButton trash2;
JTextArea responseBody;
JScrollPane scroll;
JTextArea responseHeaders;
/**
* constructor
* @param frame
*/
public Response(JFrame frame){
ok = new JButton("200 OK");
ok.setForeground(Color.GREEN);
time = new JButton("3.34s");
time.setBackground(Color.LIGHT_GRAY);
quality = new JButton("14.7KB");
quality.setBackground(Color.LIGHT_GRAY);
ok.setBounds(950, 50, 80,50);
time.setBounds(1030, 50, 80, 50);
quality.setBounds(1110, 50, 80, 50);
frame.add(ok);
frame.add(time);
frame.add(quality);
//tab = new JTabbedPane();
}
/**
* adding Header Tab
* adding double TextFields
* adding clipToClipboard Button
* @param frame
* @param tab
*/
public void header (JFrame frame, JTabbedPane tab){
panel1 = new JPanel();
copyToClipBoard = new JButton("Copy To Clipboard");
tab.setBounds(900,150,500,650);
panel1.setBackground(Color.LIGHT_GRAY);
responseHeaders = new JTextArea();
panel1.add(responseHeaders);
keyHeader1 = new JTextField();
valueHeader1 = new JTextField();
keyHeader2 = new JTextField();
valueHeader2 = new JTextField();
status1 = new JCheckBox();
trash1 = new JButton("X");
status2 = new JCheckBox();
trash2 = new JButton("X");
panel1.setBackground(Color.LIGHT_GRAY);
panel1.setSize(300,300);
panel1.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.VERTICAL;
gbc.ipadx = 100;
gbc.gridx = 0;
gbc.gridy = 1;
panel1.add(keyHeader1, gbc);
gbc.gridx = 1;
gbc.gridy = 1;
panel1.add(valueHeader1, gbc);
gbc.ipadx = 20;
gbc.gridx = 2;
gbc.gridy = 1;
panel1.add(status1, gbc);
gbc.ipadx = 5;
gbc.gridx = 3;
gbc.gridy = 1;
panel1.add(trash1, gbc);
gbc.fill = GridBagConstraints.VERTICAL;
gbc.ipadx = 100;
gbc.gridx = 0;
gbc.gridy = 2;
panel1.add(keyHeader2, gbc);
gbc.gridx = 1;
gbc.gridy = 2;
panel1.add(valueHeader2, gbc);
gbc.ipadx = 20;
gbc.gridx = 2;
gbc.gridy = 2;
panel1.add(status2, gbc);
gbc.ipadx = 5;
gbc.gridx = 3;
gbc.gridy = 2;
panel1.add(trash2, gbc);
gbc.fill = GridBagConstraints.BELOW_BASELINE_TRAILING;
gbc.ipadx = 50;
gbc.gridx = 3;
gbc.gridy = 3;
panel1.add(copyToClipBoard, gbc);
tab.add("HEADER", panel1);
frame.add(tab);
}
/**
* adding messageBody Tab
* Adding combo box
* @param frame
* @param tab
*/
public void messageBody(JFrame frame, JTabbedPane tab){
panel2 = new JPanel();
responseBody = new JTextArea(30,38);
responseBody.setSize(30,30);
responseBody.setLocation(100,100);
responseBody.setBackground(Color.LIGHT_GRAY);
panel2.setBackground(Color.LIGHT_GRAY);
String[] messageString = {"RAW", "PREVIEW"};
box = new JComboBox(messageString);
panel2.add(box);
panel2.setBorder(new TitledBorder(new EtchedBorder(), "Display Area"));
responseBody.setLineWrap(true);
responseBody.setEditable(false); // set textArea non-editable
scroll = new JScrollPane(responseBody, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
//scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scroll.setForeground(Color.DARK_GRAY);
panel2.add(scroll);
//panel2.add(responseBody);
tab.add("MESSAGE BODY", panel2);
frame.add(tab);
}
}
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