public GUI(Client client) {

		this.setTitle("Collaborative Editor");
		this.client = client;
		this.fileSystem = client.fileSystem;
		this.fileSystem.addView(this);
		this.currentFile = fileSystem.getFile().get(notNullIndex());
		this.document = currentFile.getDoc();
		this.docName = currentFile.getDocName();

		// create GUI title
		guiTitle = new JLabel("Welcome to Collaborative Editor!");
		getContentPane().add(guiTitle);

		// create GUI Image
		ImageIcon icon1 = new ImageIcon("image/writing-2.jpg",
		        "Collaborative Editing");
		JLabel guiPicture = new JLabel(icon1);

		// create JButton
		ImageIcon newIcon = new ImageIcon("image/new.png");
		createNew = new JButton(newIcon);
		getContentPane().add(createNew);
		createNew.addActionListener(new createDocListener());
		createNew.setToolTipText("Create New File");

		// delete JButton
		ImageIcon deleteIcon = new ImageIcon("image/delete.png");
		delete = new JButton(deleteIcon);
		getContentPane().add(delete);
		delete.addActionListener(new deleteDocListener());
		delete.setToolTipText("Delete Current File");

		// create drop-down box
		JLabel dropDownHeader = new JLabel("-Select Document-");
		fileList = new JComboBox();
		fileSystem.guiWantDoc();
		fileList.addActionListener(new dropDownListener());
		getContentPane().add(dropDownHeader);
		getContentPane().add(fileList);

		// display document name
		documentName = new JLabel("-Current File (click to rename)-");
		getContentPane().add(documentName);
		documentNameField = new JTextField(docName);
		documentNameField.setEditable(false);
		documentNameField.addMouseListener(new ChangeDocNameListener());

		// create an editor pane
		editArea = new JTextPane();
		editArea.setDocument(document);
		editArea.setCaretPosition(0); // text-insertion point
		JScrollPane editScrollPane = new JScrollPane(editArea);
		editScrollPane.setPreferredSize(new Dimension(500, 300));
		getContentPane().add(editScrollPane);

		// create a edit history table
		editHistory = new JTextArea();
		editHistory.setEditable(false);
		JScrollPane historyScrollPane = new JScrollPane(editHistory);
		historyScrollPane.setPreferredSize(new Dimension(500, 80));
		getContentPane().add(historyScrollPane);

		// Set up the menu bar
		actions = createActionTable(editArea);
		
		// create file menu
		JMenu filemenu = new JMenu("File");
		filemenu.setMnemonic(KeyEvent.VK_F);
		JMenuItem newFileMenu = new JMenuItem("New File");
		newFileMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,
		        ActionEvent.ALT_MASK));
		newFileMenu.addActionListener(new createDocListener());
		
		JMenuItem deleteFileMenu = new JMenuItem("Delete");
		deleteFileMenu.setAccelerator(KeyStroke.getKeyStroke(
				KeyEvent.VK_D,ActionEvent.ALT_MASK));
		deleteFileMenu.addActionListener(new deleteDocListener());
		
		JMenuItem saveFileMenu = new JMenuItem("Save as...");
		saveFileMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S
				,ActionEvent.ALT_MASK));
		saveFileMenu.addActionListener(new saveDocListener());
		
		filemenu.add(newFileMenu);
		filemenu.add(deleteFileMenu);
		filemenu.addSeparator();
		filemenu.add(saveFileMenu);
		

		// create edit menu
		JMenu editmenu = new JMenu("Edit");
		editmenu.setMnemonic('E');

		Action cutAction = new DefaultEditorKit.CutAction();
		cutAction.putValue(Action.NAME, "Cut");
		editmenu.add(cutAction);

		Action copyAction = new DefaultEditorKit.CopyAction();
		copyAction.putValue(Action.NAME, "Copy");
		editmenu.add(copyAction);

		Action pasteAction = new DefaultEditorKit.PasteAction();
		pasteAction.putValue(Action.NAME, "Paste");
		editmenu.add(pasteAction);

		editmenu.addSeparator();

		Action backAction = getActionByName(DefaultEditorKit.backwardAction);
		backAction.putValue(Action.NAME, "Caret Back");
		editmenu.add(backAction);

		Action forwardAction = getActionByName(DefaultEditorKit.forwardAction);
		forwardAction.putValue(Action.NAME, "Caret Forward");
		editmenu.add(forwardAction);

		Action upAction = getActionByName(DefaultEditorKit.upAction);
		upAction.putValue(Action.NAME, "Caret Up");
		editmenu.add(upAction);

		Action downAction = getActionByName(DefaultEditorKit.downAction);
		downAction.putValue(Action.NAME, "Caret Down");
		editmenu.add(downAction);

		editmenu.addSeparator();

		Action selectAllAction = getActionByName(DefaultEditorKit.selectAllAction);
		selectAllAction.putValue(Action.NAME, "Select All");
		editmenu.add(selectAllAction);

		JMenuBar mb = new JMenuBar();
		mb.add(filemenu);
		mb.add(editmenu);
		setJMenuBar(mb);

		// set up file chooser
		log = new JTextArea(5, 20);
		log.setMargin(new Insets(5, 5, 5, 5));
		log.setEditable(false);
		
		
		fc = new JFileChooser(){
		    @Override
		    public void approveSelection(){
		        File f = getSelectedFile();
		        if(f.exists() && getDialogType() == SAVE_DIALOG){
		            int result = JOptionPane.showConfirmDialog(
		            		gui,"The file exists. Would you like to overwrite?",
		            		"Existing file", JOptionPane.YES_NO_CANCEL_OPTION);
		            switch(result){
		                case JOptionPane.YES_OPTION:
		                    super.approveSelection();
		                    return;
		                case JOptionPane.NO_OPTION:
		                    return;
		                case JOptionPane.CLOSED_OPTION:
		                    return;
		                case JOptionPane.CANCEL_OPTION:
		                    cancelSelection();
		                    return;
		            }
		        }
		        super.approveSelection();
		    }
		};
		ImageIcon openIcon = new ImageIcon("image/open.png");
		openButton = new JButton(openIcon);
		openButton.addActionListener(new loadDocListener());
		openButton.setToolTipText("Open a New File");
		
		ImageIcon saveIcon = new ImageIcon("image/save.png");
		saveButton = new JButton(saveIcon);
		saveButton.addActionListener(new saveDocListener());
		saveButton.setToolTipText("Save and Export");
		

		// Add hot-key commands
		addHotKey();

		// add listeners
		JPanel statusPane = new JPanel(new GridLayout(1, 1));
		CaretListenerLabel caretListenerLabel = new CaretListenerLabel(
		        "Caret Status");
		statusPane.add(caretListenerLabel);
		editArea.addCaretListener(caretListenerLabel);

		// set layout

		// 1. parent window
		gui = new JPanel(new BorderLayout(5, 5));
		gui.setBorder(new TitledBorder("Azure v1.2"));

		// top panel: document name, create new document, change theme
		JPanel plafComponents = new JPanel(new FlowLayout(FlowLayout.CENTER,5,3));
		
		JPanel displayDocName = new JPanel(new BorderLayout());
		displayDocName.add(documentName, BorderLayout.NORTH);
		displayDocName.add(documentNameField, BorderLayout.SOUTH);

		plafComponents.add(createNew);
		plafComponents.add(openButton);
		plafComponents.add(delete);
		plafComponents.add(saveButton);
		plafComponents.add(displayDocName);

		JPanel plafSubComp = new JPanel(new BorderLayout(3, 3));

		plafSubComp.setBorder(new TitledBorder("Choose Theme"));

		final UIManager.LookAndFeelInfo[] plafInfos = UIManager
		        .getInstalledLookAndFeels();
		String[] plafNames = new String[plafInfos.length];
		for (int ii = 0; ii < plafInfos.length; ii++) {
			plafNames[ii] = plafInfos[ii].getName();
		}
		final JComboBox plafChooser = new JComboBox(plafNames);
		plafSubComp.add(plafChooser, BorderLayout.CENTER);


		plafComponents.add(plafSubComp);

		plafChooser.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent ae) {
				int index = plafChooser.getSelectedIndex();
				try {
					UIManager.setLookAndFeel(plafInfos[index].getClassName());
					SwingUtilities.updateComponentTreeUI(getRootPane());
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});

		JPanel upperPortion = new JPanel(new BorderLayout());
		upperPortion.add(guiPicture, BorderLayout.NORTH);
		upperPortion.add(plafComponents, BorderLayout.SOUTH);

		gui.add(upperPortion, BorderLayout.NORTH);

		// left panel
		// left panel: drop down file list
		JPanel dynamicLabels = new JPanel(new BorderLayout(4, 4));
		dynamicLabels.setBorder(new TitledBorder("Control Panel"));
		gui.add(dynamicLabels, BorderLayout.WEST);

		JPanel selectDoc = new JPanel(new BorderLayout());
		selectDoc.add(dropDownHeader, BorderLayout.NORTH);
		selectDoc.add(fileList, BorderLayout.SOUTH);

		// left panel: control buttons
		JPanel controlButtons = new JPanel(new GridLayout(2, 2));
		ImageIcon cutIcon = new ImageIcon("image/cut.png");
		cutButton = new JButton(cutAction);
		cutButton.setText("");
		cutButton.setIcon(cutIcon);
		cutButton.setToolTipText("cut");
		controlButtons.add(cutButton);

		ImageIcon copyIcon = new ImageIcon("image/copy.png");
		copyButton = new JButton(copyAction);
		copyButton.setIcon(copyIcon);
		copyButton.setText("");
		copyButton.setToolTipText("copy");
		controlButtons.add(copyButton);

		ImageIcon pasteIcon = new ImageIcon("image/paste.png");
		pasteButton = new JButton(pasteAction);
		pasteButton.setIcon(pasteIcon);
		pasteButton.setText("");
		pasteButton.setToolTipText("paste");
		controlButtons.add(pasteButton);

		ImageIcon selectAllIcon = new ImageIcon("image/selectAll.png");
		selectAllButton = new JButton(selectAllAction);
		selectAllButton.setIcon(selectAllIcon);
		selectAllButton.setText("");
		selectAllButton.setToolTipText("select all");
		controlButtons.add(selectAllButton);

		dynamicLabels.add(selectDoc, BorderLayout.NORTH);
		dynamicLabels.add(controlButtons, BorderLayout.SOUTH);

		// right panel
		JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
		        editScrollPane, historyScrollPane);
		gui.add(splitPane, BorderLayout.CENTER);

		// set background color
		Color color = new Color(240, 248, 255);
		documentName.setBackground(color);
		controlButtons.setBackground(color);
		upperPortion.setBackground(color);
		plafSubComp.setBackground(color);
		dropDownHeader.setBackground(color);
		dynamicLabels.setBackground(color);
		gui.setBackground(color);
		splitPane.setBackground(color);
		plafComponents.setBackground(color);


		Thread t = new UpdateListener(client);
		t.start();
		
		// at the end
		this.setContentPane(gui);
		this.pack();
		this.setLocationRelativeTo(null);
		try {
			this.setLocationByPlatform(true);
			this.setMinimumSize(this.getSize());
		} catch (Throwable ignoreAndContinue) {
		}
		this.setVisible(true);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

	}