Commit 5f00875a authored by nargessalehi98's avatar nargessalehi98

Add comments

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