Commit 5f00875a authored by nargessalehi98's avatar nargessalehi98

Add comments

parent fd3cd71f
...@@ -5,10 +5,17 @@ import javax.swing.tree.DefaultTreeCellRenderer; ...@@ -5,10 +5,17 @@ import javax.swing.tree.DefaultTreeCellRenderer;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
/**
* present GUI of insomnia
* @author Narges Salehi
*/
public class GUI { public class GUI {
//general window
JFrame window = new JFrame(); JFrame window = new JFrame();
//splitPane to divide JFrame
JSplitPane jSplitPane2; JSplitPane jSplitPane2;
JSplitPane jSplitPane1; JSplitPane jSplitPane1;
//Component which has Listener
JMenuItem mOptions; JMenuItem mOptions;
JMenuItem exit; JMenuItem exit;
JMenuItem tSidebar; JMenuItem tSidebar;
...@@ -19,16 +26,24 @@ public class GUI { ...@@ -19,16 +26,24 @@ public class GUI {
JButton save; JButton save;
JCheckBox followRedirect; JCheckBox followRedirect;
JCheckBox systemTray; JCheckBox systemTray;
boolean checkSystemTray = false;
JTextArea newHeader; JTextArea newHeader;
JTextArea newValue; JTextArea newValue;
JPanel header; JPanel header;
static int headerCounter = 1;
JTabbedPane tab; JTabbedPane tab;
//check if system tray is on or not
boolean checkSystemTray = false;
//go to next line to add component - count lines
static int headerCounter = 1;
//check if window is full screen or not
static boolean fullScreen = false; static boolean fullScreen = false;
//check if program if toggled or not
static boolean toggleSidebar = false; static boolean toggleSidebar = false;
//check how many time we use system tray
static int runOnce; static int runOnce;
/**
* creat a new GUI
*/
public GUI() { public GUI() {
//creat a layout for panels //creat a layout for panels
GridBagLayout layout = new GridBagLayout(); GridBagLayout layout = new GridBagLayout();
...@@ -37,24 +52,26 @@ public class GUI { ...@@ -37,24 +52,26 @@ public class GUI {
window.setSize(1200, 600); window.setSize(1200, 600);
window.setLayout(new BorderLayout()); window.setLayout(new BorderLayout());
window.setVisible(true); window.setVisible(true);
//creat and add a window listener to window
windowListener windowListener = new windowListener(); windowListener windowListener = new windowListener();
window.addWindowListener(windowListener); window.addWindowListener(windowListener);
//creat a new border //creat a new border
Border border = BorderFactory.createLineBorder(Color.white, 1); Border border = BorderFactory.createLineBorder(Color.white, 1);
//creat panels //creat panels of insomnia
JPanel left = new JPanel(); JPanel left = new JPanel();
JPanel middle = new JPanel(); JPanel middle = new JPanel();
JPanel right = new JPanel(); JPanel right = new JPanel();
addJPanel(left, Color.white, border, 600, 400); addJPanel(left, Color.white, border, 600, 400);
addJPanel(middle, Color.white, border, 600, 400); addJPanel(middle, Color.white, border, 600, 400);
addJPanel(right, Color.white, border, 600, 400); addJPanel(right, Color.white, border, 600, 400);
//start from top of insomnia
//creat and design top JMenuBar
//creat and design top j menu bar //creat a listener for top Menu -menubar
topMenuActionListener topMenuHandler = new topMenuActionListener(); topMenuActionListener topMenuHandler = new topMenuActionListener();
//creat a menu bar and design it
JMenuBar topJMenu = new JMenuBar(); JMenuBar topJMenu = new JMenuBar();
topJMenu.setPreferredSize(new Dimension(0, 25)); topJMenu.setPreferredSize(new Dimension(0, 25));
window.add(topJMenu, BorderLayout.PAGE_START); //creat menu for top menu bar
JMenu application = new JMenu("Application"); JMenu application = new JMenu("Application");
application.setMnemonic('a'); application.setMnemonic('a');
mOptions = new JMenuItem("Options"); mOptions = new JMenuItem("Options");
...@@ -65,6 +82,7 @@ public class GUI { ...@@ -65,6 +82,7 @@ public class GUI {
mOptions.addActionListener(topMenuHandler); mOptions.addActionListener(topMenuHandler);
application.add(mOptions); application.add(mOptions);
application.add(exit); application.add(exit);
JMenu view = new JMenu("View"); JMenu view = new JMenu("View");
view.setMnemonic('v'); view.setMnemonic('v');
tSidebar = new JMenuItem("Toggle Sidebar"); tSidebar = new JMenuItem("Toggle Sidebar");
...@@ -75,6 +93,7 @@ public class GUI { ...@@ -75,6 +93,7 @@ public class GUI {
tFullScreen.addActionListener(topMenuHandler); tFullScreen.addActionListener(topMenuHandler);
view.add(tSidebar); view.add(tSidebar);
view.add(tFullScreen); view.add(tFullScreen);
JMenu help = new JMenu("Help"); JMenu help = new JMenu("Help");
help.setMnemonic('h'); help.setMnemonic('h');
iHelp = new JMenuItem("Help"); iHelp = new JMenuItem("Help");
...@@ -88,8 +107,9 @@ public class GUI { ...@@ -88,8 +107,9 @@ public class GUI {
topJMenu.add(application); topJMenu.add(application);
topJMenu.add(view); topJMenu.add(view);
topJMenu.add(help); topJMenu.add(help);
window.add(topJMenu, BorderLayout.PAGE_START);
//**************************************************************************************************************
//start designing left side of insomnia
//designing left panel //designing left panel
left.setLayout(layout); left.setLayout(layout);
JMenuBar jMenuBar = new JMenuBar(); JMenuBar jMenuBar = new JMenuBar();
...@@ -132,7 +152,6 @@ public class GUI { ...@@ -132,7 +152,6 @@ public class GUI {
gbc.anchor = GridBagConstraints.NORTHWEST; gbc.anchor = GridBagConstraints.NORTHWEST;
left.add(jMenuBar1, gbc); left.add(jMenuBar1, gbc);
JMenuBar jMenuBar2 = new JMenuBar(); JMenuBar jMenuBar2 = new JMenuBar();
jMenuBar2.setPreferredSize(new Dimension(0, 30)); jMenuBar2.setPreferredSize(new Dimension(0, 30));
JTextArea jTextArea = new JTextArea(" "); JTextArea jTextArea = new JTextArea(" ");
...@@ -164,8 +183,9 @@ public class GUI { ...@@ -164,8 +183,9 @@ public class GUI {
jTree.addMouseListener(getMouseListener(jTree)); jTree.addMouseListener(getMouseListener(jTree));
jTree.addFocusListener(getFocusListener(jTree)); jTree.addFocusListener(getFocusListener(jTree));
left.add(jPanel, gbc); left.add(jPanel, gbc);
//**************************************************************************** //**************************************************************************************************************
//middle //middle side of panel
//designing middle panel
middle.setLayout(new GridBagLayout()); middle.setLayout(new GridBagLayout());
JMenuBar URL = new JMenuBar(); JMenuBar URL = new JMenuBar();
URL.setPreferredSize(new Dimension(0, 50)); URL.setPreferredSize(new Dimension(0, 50));
...@@ -206,7 +226,6 @@ public class GUI { ...@@ -206,7 +226,6 @@ public class GUI {
gbc.anchor = GridBagConstraints.NORTHWEST; gbc.anchor = GridBagConstraints.NORTHWEST;
middle.add(URL, gbc); middle.add(URL, gbc);
//************************************************************************
tab = new JTabbedPane(); tab = new JTabbedPane();
JPanel body = new JPanel(); JPanel body = new JPanel();
tab.add("body", body); tab.add("body", body);
...@@ -253,20 +272,30 @@ public class GUI { ...@@ -253,20 +272,30 @@ public class GUI {
gbc.anchor = GridBagConstraints.NORTHWEST; gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.fill = GridBagConstraints.BOTH; gbc.fill = GridBagConstraints.BOTH;
middle.add(tab, gbc); middle.add(tab, gbc);
//**************************************************************************************************************
//right side of insomnia
//************************************************************************ //designing right panel
//right //set gridBagLayout for panel
right.setLayout(new GridBagLayout()); right.setLayout(new GridBagLayout());
//creat a menu bar to keep statusCode statusMassage and Time
JMenuBar data = new JMenuBar(); JMenuBar data = new JMenuBar();
//set size for menu bar
data.setPreferredSize(new Dimension(0, 50)); data.setPreferredSize(new Dimension(0, 50));
//set layout for menu bar
data.setLayout(new BorderLayout()); data.setLayout(new BorderLayout());
//creat item to keep time
JMenu time = new JMenu("14 Minutes Ago ▾"); JMenu time = new JMenu("14 Minutes Ago ▾");
//add item to menu bar
data.add(time, BorderLayout.LINE_END); data.add(time, BorderLayout.LINE_END);
//creat item to keep statusMassage
JLabel error = new JLabel("Error "); JLabel error = new JLabel("Error ");
//add item to menu bar
data.add(error, BorderLayout.LINE_START); data.add(error, BorderLayout.LINE_START);
//creat item to keep statusCode
JLabel tt = new JLabel("0 ms 0 B"); JLabel tt = new JLabel("0 ms 0 B");
//add item to menu bar
data.add(tt, BorderLayout.CENTER); data.add(tt, BorderLayout.CENTER);
//set gridBagConstrains for add menu bar to right panel
gbc.gridx = 0; gbc.gridx = 0;
gbc.gridy = 0; gbc.gridy = 0;
gbc.weightx = 1; gbc.weightx = 1;
...@@ -275,35 +304,49 @@ public class GUI { ...@@ -275,35 +304,49 @@ public class GUI {
gbc.gridwidth = 1; gbc.gridwidth = 1;
gbc.fill = GridBagConstraints.HORIZONTAL; gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.anchor = GridBagConstraints.NORTHWEST; gbc.anchor = GridBagConstraints.NORTHWEST;
//add menu bar to panel
right.add(data, gbc); right.add(data, gbc);
//creat a tabbedPane
JTabbedPane tab1 = new JTabbedPane(); JTabbedPane tab1 = new JTabbedPane();
//creat a panel
JPanel preview = new JPanel(); JPanel preview = new JPanel();
//set layout for panel
preview.setLayout(new GridBagLayout()); preview.setLayout(new GridBagLayout());
//creat a text area for massage body
JTextArea massageBody = new JTextArea(); JTextArea massageBody = new JTextArea();
massageBody.setBackground(Color.lightGray); massageBody.setBackground(Color.lightGray);
//add panel to tabbedPane
tab1.add("Preview", preview); tab1.add("Preview", preview);
//creat a combo box to keep massage type
JComboBox comboBox = new JComboBox(); JComboBox comboBox = new JComboBox();
//add types
comboBox.addItem("Raw"); comboBox.addItem("Raw");
comboBox.addItem("Visual Preview"); comboBox.addItem("Visual Preview");
comboBox.addItem("JSON"); comboBox.addItem("JSON");
//set gridBagConstrains for adding component to panel
gbc.gridy = 0; gbc.gridy = 0;
gbc.gridx = 0; gbc.gridx = 0;
gbc.weightx = 1; gbc.weightx = 1;
gbc.weighty = 0; gbc.weighty = 0;
gbc.fill = GridBagConstraints.HORIZONTAL; gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.anchor = GridBagConstraints.NORTHWEST; gbc.anchor = GridBagConstraints.NORTHWEST;
//add combobox to panel
preview.add(comboBox, gbc); preview.add(comboBox, gbc);
gbc.gridy = 1; gbc.gridy = 1;
gbc.weighty = 1; gbc.weighty = 1;
gbc.fill = GridBagConstraints.BOTH; gbc.fill = GridBagConstraints.BOTH;
//add text area to panel
preview.add(massageBody, gbc); preview.add(massageBody, gbc);
//creat a panel for header
JPanel header2 = new JPanel(); JPanel header2 = new JPanel();
//set layout for header
header2.setLayout(new GridBagLayout()); header2.setLayout(new GridBagLayout());
//add header to tabbedPane
tab1.add("Header", header2); tab1.add("Header", header2);
//add item to header
JLabel name = new JLabel("Name"); JLabel name = new JLabel("Name");
JLabel value = new JLabel("value"); JLabel value = new JLabel("value");
//set gridBagConstrains for adding item
gbc.gridy = 0; gbc.gridy = 0;
gbc.gridx = 0; gbc.gridx = 0;
gbc.weightx = 1; gbc.weightx = 1;
...@@ -320,7 +363,7 @@ public class GUI { ...@@ -320,7 +363,7 @@ public class GUI {
gbc.weighty = 1; gbc.weighty = 1;
gbc.fill = GridBagConstraints.HORIZONTAL; gbc.fill = GridBagConstraints.HORIZONTAL;
header2.add(copyToClipboard, gbc); header2.add(copyToClipboard, gbc);
//creat other panel
JPanel cookies = new JPanel(); JPanel cookies = new JPanel();
tab1.add("Cookies", cookies); tab1.add("Cookies", cookies);
JPanel timeline = new JPanel(); JPanel timeline = new JPanel();
...@@ -330,23 +373,43 @@ public class GUI { ...@@ -330,23 +373,43 @@ public class GUI {
gbc.weighty = 1; gbc.weighty = 1;
gbc.fill = GridBagConstraints.BOTH; gbc.fill = GridBagConstraints.BOTH;
right.add(tab1, gbc); right.add(tab1, gbc);
//dividing window by JSplitPane
//add right and middle panel to one splitPane
jSplitPane2 = new JSplitPane(SwingConstants.VERTICAL, middle, right); jSplitPane2 = new JSplitPane(SwingConstants.VERTICAL, middle, right);
//set divider location for splitPane
jSplitPane2.setDividerLocation(400); jSplitPane2.setDividerLocation(400);
//set size of divider
jSplitPane2.setDividerSize(2); jSplitPane2.setDividerSize(2);
//add above splitPane And left panel on splitPane
jSplitPane1 = new JSplitPane(SwingConstants.VERTICAL, left, jSplitPane2); jSplitPane1 = new JSplitPane(SwingConstants.VERTICAL, left, jSplitPane2);
//set divider location for splitPane
jSplitPane1.setDividerLocation(400); jSplitPane1.setDividerLocation(400);
//set size of divider
jSplitPane1.setDividerSize(2); jSplitPane1.setDividerSize(2);
//add splitPane to window
window.add(jSplitPane1); window.add(jSplitPane1);
} }
//end of GUI //end of GUI
/**
* creat a panel with given data
* @param jPanel JPanel
* @param color of panel
* @param border of panel
* @param height of panel
* @param weight of panel
*/
public void addJPanel(JPanel jPanel, Color color, Border border, int height, int weight) { public void addJPanel(JPanel jPanel, Color color, Border border, int height, int weight) {
jPanel.setBackground(color); jPanel.setBackground(color);
jPanel.setBorder(border); jPanel.setBorder(border);
jPanel.setSize(weight, height); jPanel.setSize(weight, height);
} }
//------------------------------------------------------------------------------------------------------------------
/**
* this class has copied from stackOverFlow
* @return
*/
private static DefaultTreeCellRenderer getDefaultTreeCellRenderer() { private static DefaultTreeCellRenderer getDefaultTreeCellRenderer() {
DefaultTreeCellRenderer defaultTreeCellRenderer = new DefaultTreeCellRenderer(); DefaultTreeCellRenderer defaultTreeCellRenderer = new DefaultTreeCellRenderer();
defaultTreeCellRenderer.setBackgroundSelectionColor(Color.blue); defaultTreeCellRenderer.setBackgroundSelectionColor(Color.blue);
...@@ -403,7 +466,7 @@ public class GUI { ...@@ -403,7 +466,7 @@ public class GUI {
} }
}; };
} }
//------------------------------------------------------------------------------------------------------------------
/** /**
* class perform listener for top menu * class perform listener for top menu
*/ */
...@@ -483,6 +546,9 @@ public class GUI { ...@@ -483,6 +546,9 @@ public class GUI {
} }
} }
/**
* Performs listener for buttons
*/
private class ButtonListener implements ActionListener { private class ButtonListener implements ActionListener {
@Override @Override
...@@ -554,6 +620,9 @@ public class GUI { ...@@ -554,6 +620,9 @@ public class GUI {
} }
} }
/**
* Performs mouseListener to text areas - adding new component
*/
private class mouseClicker extends MouseAdapter { private class mouseClicker extends MouseAdapter {
@Override @Override
...@@ -602,9 +671,13 @@ public class GUI { ...@@ -602,9 +671,13 @@ public class GUI {
} }
} }
/**
* Performs listener for window - controlling system tray
*/
private class windowListener extends WindowAdapter { private class windowListener extends WindowAdapter {
@Override @Override
public void windowClosing(WindowEvent e) { public void windowClosing(WindowEvent e) {
//check if program already is in system tray or not
if (runOnce == 0 && checkSystemTray) { if (runOnce == 0 && checkSystemTray) {
setSystemTray(); setSystemTray();
runOnce++; runOnce++;
...@@ -612,6 +685,10 @@ public class GUI { ...@@ -612,6 +685,10 @@ public class GUI {
} }
} }
/**
* Provide adding program to system tray
* copied from StackOverFlow
*/
public void setSystemTray() { public void setSystemTray() {
//Check the SystemTray is supported //Check the SystemTray is supported
if (!SystemTray.isSupported()) { if (!SystemTray.isSupported()) {
......
import javax.swing.*; import javax.swing.*;
/**
* Run the program
* @author Narges Salehi
*/
public class Main { public class Main {
//choosing look and fell
public static void main(String[] args) { public static void main(String[] args) {
try { try {
for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
...@@ -13,6 +17,7 @@ public class Main { ...@@ -13,6 +17,7 @@ public class Main {
} catch (Exception e) { } catch (Exception e) {
// If Nimbus is not available, you can set the GUI to another look and feel. // If Nimbus is not available, you can set the GUI to another look and feel.
} }
//creat a new GUI
GUI gui=new GUI(); GUI gui=new GUI();
} }
} }
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