Commit 557c0d2d authored by 9731301's avatar 9731301

change the gui type and sperate one class to 3 more classes

parent ece9abad
This diff is collapsed.
import java.awt.*;
import java.io.IOException; import java.io.IOException;
public class Insomnia { public class Insomnia {
public static void main(String [] args) throws IOException { public static void main(String [] args) throws IOException {
InsomniaGUI insomniaGUI = new InsomniaGUI(); InsomniaGUI insomniaGUI = new InsomniaGUI();
Frame frame = new Frame();
} }
} }
This diff is collapsed.
import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class LeftPanel extends JPanel {
Border border = BorderFactory.createLineBorder(Color.BLACK,3);
VerticalFlowLayout vfLayout = new VerticalFlowLayout();
JButton addRequest = new JButton("Add 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));
//left panel (list of requests)
public void createLeftPanel() {
menu.setFont(new Font("Arial",20,15 ));
menu.setBorder(border);
menu.setPreferredSize(new Dimension(200,60));
up_left.add(menu);
up_left.add(addRequest);
up_left.setBackground(Color.GRAY);
requestList.setBackground(Color.GRAY);
addRequest.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
int i = 1;
JLabel jLabel= new JLabel("request"+i);
requestList.add(jLabel);
i++;
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
});
this.setLayout(new BorderLayout());
this.setBackground(Color.GRAY);
this.add(up_left, BorderLayout.NORTH);
this.add(scrollRequests, BorderLayout.CENTER);
this.setBackground(Color.LIGHT_GRAY);
}
public JButton getAddRequest() {
return addRequest;
}
public JMenu getMenu() {
return menu;
}
public JPanel getRequestList() {
return requestList;
}
public JScrollPane getScrollRequests() {
return scrollRequests;
}
public JPanel getUp_left() {
return up_left;
}
}
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class RequestPanel extends JPanel {
private VerticalFlowLayout vfLayout = new VerticalFlowLayout();
private JPanel body = new JPanel();
private JPanel auth = new JPanel();
private JPanel query = new JPanel();
private JPanel mainCenterHeader = new JPanel(vfLayout);
private JScrollPane scrollPane_Header_Request = new JScrollPane(mainCenterHeader);
JPanel docs = new JPanel();
JTabbedPane tabbedPaneCenterRequest = new JTabbedPane();
JTextField headerField = new JTextField("header");
JTextField valueField = new JTextField("value");
JCheckBox checkBox = new JCheckBox();
JButton delete = new JButton();
JPanel rightOfHeader = new JPanel();
JPanel center_header = new JPanel(new GridLayout(1,2));
JPanel header = new JPanel(new BorderLayout());
String s []={"Patch","Put","Post","Delete","Get"};
JComboBox centerMenu = new JComboBox(s);
JTextField URLTextField = new JTextField("http://api.myproduct.com/v1/users");
JButton sendButton = new JButton("send");
JPanel centerUp = new JPanel(new BorderLayout());
public JTabbedPane tabbedPaneCenterRequest() throws IOException {
Border border = BorderFactory.createLineBorder(Color.BLACK,3);
BufferedImage master;
master = ImageIO.read(new File("C:\\Users\\Lenovo\\IdeaProjects\\Insomnia\\src\\image\\535246.png"));
Image scaled = master.getScaledInstance(20,20, java.awt.Image.SCALE_SMOOTH);
body.setBackground(Color.GRAY);
auth.setBackground(Color.GRAY);
query.setBackground(Color.GRAY);
mainCenterHeader.setBackground(Color.GRAY);
scrollPane_Header_Request.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
docs.setBackground(Color.GRAY);
//request-center
tabbedPaneCenterRequest.setBackground(Color.GRAY);
tabbedPaneCenterRequest.add("Body" , body);
tabbedPaneCenterRequest.add("Auth" , auth);
tabbedPaneCenterRequest.add("Query" , query);
tabbedPaneCenterRequest.add("Header" , scrollPane_Header_Request);
tabbedPaneCenterRequest.add("Docs" , docs);
headerField.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
JTextField newHeaderField = new JTextField("header");
newHeaderField.setBorder(border);
JTextField newValueField = new JTextField("value");
newValueField.setBorder(border);
JCheckBox newCheckBox = new JCheckBox();
JButton newDelete = new JButton();
newDelete.setPreferredSize(new Dimension(20,20));
newDelete.setIcon(new ImageIcon(scaled));
JPanel newRightOfHeader = new JPanel();
newRightOfHeader.add(newCheckBox);
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);
mainCenterHeader.add(newHeader );
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
});
RequestPanel.TextFieldHandler textFieldHandler = new TextFieldHandler(headerField,mainCenterHeader,border);//create a actionListener
headerField.setFocusable(true);
headerField.addActionListener( textFieldHandler);
headerField.setBorder(border);
valueField.setBorder(border);
delete.setIcon(new ImageIcon(scaled));
delete.setPreferredSize(new Dimension(20,20));
rightOfHeader.add(checkBox);
rightOfHeader.add(delete);
center_header.add(headerField);
center_header.add(valueField);
header.add(rightOfHeader,BorderLayout.EAST);
header.add(center_header,BorderLayout.CENTER);
mainCenterHeader.add(header);
return tabbedPaneCenterRequest;
}
//request_up
public JPanel centerUp(){
centerMenu.setFont(new Font("Arial",20,15 ));
centerUp.add(centerMenu , BorderLayout.WEST);
centerUp.add(URLTextField , BorderLayout.CENTER);
centerUp.add(sendButton , BorderLayout.EAST);
return centerUp;
}
class TextFieldHandler implements ActionListener {
JTextField headerField ;
JPanel mainCenterHeader;
Border border;
private TextFieldHandler(JTextField headerField , JPanel mainCenterHeader , Border border){
this.headerField = headerField;
this.mainCenterHeader = mainCenterHeader;
this.border = border;
}
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("++++++++++++");
if (!headerField.getText().equals("") ) {
JTextField newHeaderField = new JTextField("header");
newHeaderField.setBorder(border);
JTextField newValueField = new JTextField("value");
newValueField.setBorder(border);
JCheckBox newCheckBox = new JCheckBox();
JButton newDelete = new JButton(new ImageIcon("C:\\Users\\Lenovo\\IdeaProjects\\Insomnia\\src\\image\\1000582.png"));
JPanel newRightOfHeader = new JPanel();
newRightOfHeader.add(newCheckBox);
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);
mainCenterHeader.add(newHeader);
}
}
}
public void createRequestPanel() throws IOException {
addToMainRequestPanel(centerUp() , tabbedPaneCenterRequest());
}
public void addToMainRequestPanel(JPanel centerUp ,JTabbedPane tabbedPaneCenterRequest ){
this.setLayout(new BorderLayout());
this.add(centerUp,BorderLayout.NORTH);
this.add(tabbedPaneCenterRequest , BorderLayout.CENTER);
}
public JPanel getRightOfHeader() {
return rightOfHeader;
}
public JPanel getCenter_header() {
return center_header;
}
public JPanel getBody() {
return body;
}
public JPanel getAuth() {
return auth;
}
public JPanel getQuery() {
return query;
}
public JPanel getMainCenterHeader() {
return mainCenterHeader;
}
public JScrollPane getScrollPane_Header_Request() {
return scrollPane_Header_Request;
}
public JPanel getDocs() {
return docs;
}
public JTabbedPane getTabbedPaneCenterRequest() {
return tabbedPaneCenterRequest;
}
public JPanel getHeader() {
return header;
}
public JComboBox getCenterMenu() {
return centerMenu;
}
public JPanel getCenterUp() {
return centerUp;
}
}
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);
private VerticalFlowLayout vfLayout = new VerticalFlowLayout();
private JPanel row = new JPanel();
private JTextArea massageBody = new JTextArea();
private JPanel mainCenterHeader_respond = new JPanel(vfLayout);
private JScrollPane scrollPane_Header_Respond = new JScrollPane(mainCenterHeader_respond);
private JPanel header_MainPanel = new JPanel(new BorderLayout());
private JButton copyToClipBoard = new JButton("copy to clip board");
private JPanel cookie = new JPanel();
private JPanel timeline = new JPanel(new BorderLayout());
private JTabbedPane tabbedPaneCenterResponse = new JTabbedPane();
private JTextField headerField2 = new JTextField("header");
public JTabbedPane tabbedPaneCenterResponse() {
massageBody.setPreferredSize(new Dimension(200, 300));
row.add(massageBody);
row.setBackground(Color.GRAY);
scrollPane_Header_Respond.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
mainCenterHeader_respond.setBackground(Color.GRAY);
header_MainPanel.setBackground(Color.GRAY);
header_MainPanel.add(scrollPane_Header_Respond, BorderLayout.CENTER);
header_MainPanel.add(copyToClipBoard, BorderLayout.SOUTH);
cookie.setBackground(Color.GRAY);
timeline.setBackground(Color.GRAY);
tabbedPaneCenterResponse.setBackground(Color.GRAY);
tabbedPaneCenterResponse.add("Row", row);
tabbedPaneCenterResponse.add("Header", header_MainPanel);
tabbedPaneCenterResponse.add("Cookie", cookie);
tabbedPaneCenterResponse.add("Timeline", timeline);
headerField2.setEditable(false);
headerField2.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
System.out.println(")))))))))))");
// if (!headerField2.getText().equals("") ) {
JTextField newHeaderField = new JTextField("header");
newHeaderField.setEditable(false);
newHeaderField.setBorder(border);
JTextField newValueField = new JTextField("value");
newValueField.setEditable(false);
newValueField.setBorder(border);
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(new_center_header, BorderLayout.CENTER);
mainCenterHeader_respond.add(newHeader);
// }
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
});
headerField2.setBorder(border);
JTextField valueField2 = new JTextField("value");
valueField2.setEditable(false);
valueField2.setBorder(border);
JPanel center_header2 = new JPanel(new GridLayout(1, 2));
center_header2.add(headerField2);
center_header2.add(valueField2);
JPanel header2 = new JPanel(new BorderLayout());
header2.add(center_header2, BorderLayout.CENTER);
mainCenterHeader_respond.add(header2);
return tabbedPaneCenterResponse;
}
public JPanel up_response() {
JPanel up_response = new JPanel();
JLabel label1 = new JLabel("ok");
label1.setBorder(border);
JLabel label2 = new JLabel("s");
label2.setBorder(border);
JLabel label3 = new JLabel("KB");
label3.setBorder(border);
up_response.add(label1);
up_response.add(label2);
up_response.add(label3);
return up_response;
}
public void createRespondPanel(){
addToMainRespondPanel(tabbedPaneCenterResponse() , up_response());
}
public void addToMainRespondPanel(JTabbedPane tabbedPaneCenterResponse, JPanel up_response){
this.setLayout(new BorderLayout());
this.add(tabbedPaneCenterResponse , BorderLayout.CENTER);
this.add(up_response,BorderLayout.NORTH);
}
public JTextArea getMassageBody() {
return massageBody;
}
public JPanel getMainCenterHeader_respond() {
return mainCenterHeader_respond;
}
public JScrollPane getScrollPane_Header_Respond() {
return scrollPane_Header_Respond;
}
public JPanel getHeader_MainPanel() {
return header_MainPanel;
}
public JButton getCopyToClipBoard() {
return copyToClipBoard;
}
public JPanel getCookie() {
return cookie;
}
public JPanel getTimeline() {
return timeline;
}
public JTabbedPane getTabbedPaneCenterResponse() {
return tabbedPaneCenterResponse;
}
public JTextField getHeaderField2() {
return headerField2;
}
public JPanel getRow() {
return row;
}
}
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