	public DocEdit(PrintWriter outputStream, String documentName, String user, String content, String collaboratorNames, int versionID){
		super(documentName);
		this.version = versionID;
		this.cursorPosition = 0;
		out = outputStream;
		this.docName = documentName;
		this.userName = user;
		this.docContent = content;
		this.collaboratorNames = collaboratorNames;
		welcomeLabel = new JLabel("Welcome " + userName + "!");
		exitButton = new JButton("Exit Doc");
		collabLabel = new JLabel("Collaborators: ");
		collaborators = new JLabel(collaboratorNames);
		messageLabel = new JLabel("Messages will appear here.");
		latexButton = new JButton("Latex View");
		latexDisplay = new MyPanel();
		closeLatexButton = new JButton("<");
		closeLatexButton.setVisible(false);
		latexDisplay.setVisible(false);
		textArea = new JTextArea();
		scrollText = new JScrollPane(textArea);
		scrollText.setMinimumSize(new Dimension(700, 700));
		textArea.setText(docContent);
		textArea.setCaretPosition(cursorPosition);
		textDocument = textArea.getDocument();
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		GroupLayout layout = new GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		layout.setAutoCreateGaps(true);
		layout.setAutoCreateContainerGaps(true);
		GroupLayout.ParallelGroup hGroup = layout.createParallelGroup();
		hGroup.addGroup(
				layout.createParallelGroup()
					.addGroup(layout.createSequentialGroup()
							.addComponent(collabLabel)
							.addComponent(collaborators)
							)
					.addComponent(welcomeLabel)
					.addComponent(messageLabel)
					);
		hGroup.addGroup(
				layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
					.addComponent(exitButton)
					.addGroup(layout.createSequentialGroup()							
							.addComponent(scrollText)
							.addComponent(latexDisplay)
							)
					.addGroup(layout.createSequentialGroup()
							.addComponent(closeLatexButton)
							.addComponent(latexButton)
							)
					);
		layout.setHorizontalGroup(hGroup);
		GroupLayout.SequentialGroup vGroup = layout.createSequentialGroup();
		vGroup.addGroup(
					layout.createParallelGroup(GroupLayout.Alignment.CENTER)
						.addComponent(welcomeLabel)
						.addComponent(exitButton)
					);
		vGroup.addGroup(
					layout.createParallelGroup()
						.addComponent(collabLabel)
						.addComponent(collaborators)
					);
		vGroup.addGroup(
					layout.createParallelGroup()
						.addComponent(scrollText)
						.addComponent(latexDisplay)
					);
		vGroup.addGroup(
					layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
						.addComponent(messageLabel)
						.addComponent(closeLatexButton)
						.addComponent(latexButton)
					);
		layout.setVerticalGroup(vGroup);
		latexButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e){
				if (latexDisplay.isVisible()){
					String content = textArea.getText();
					if (Latex.isLatex(content)){
						TeXIcon icon = Latex.getLatex(content);
						BufferedImage b = new BufferedImage(icon.getIconWidth(),
								icon.getIconHeight(), BufferedImage.TYPE_4BYTE_ABGR);
						icon.paintIcon(new JLabel(), b.getGraphics(), 0, 0);
						b.getGraphics().drawImage(b, 0, 0, null);
						latexDisplay.updateImage(b);
						latexDisplay.repaint();
					}
				}
				else{
					latexDisplay.setVisible(true);
					int height = scrollText.getHeight();
					int width = scrollText.getWidth();
					latexDisplay.setMinimumSize(new Dimension(width/2, height));
					scrollText.setMinimumSize(new Dimension(width/2, height));
					latexButton.setText("Render");
					closeLatexButton.setVisible(true);
					packFrame();
				}
			}
		});
		closeLatexButton.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent e){				
				latexDisplay.setVisible(false);
				closeLatexButton.setVisible(false);
				latexButton.setText("Latex View");
			}	
		});
		exitButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e){
				exitDocument();	
			}
		});		
		documentListener = new DocumentListener() {
			@Override
			public void changedUpdate(DocumentEvent e) {
				System.out.println("CHANGED!");
			}
			@Override
			public void insertUpdate(DocumentEvent e) {
				try {
					int position = e.getOffset();
					int length = e.getLength();
					String change = textDocument.getText(position, length);
					if (change.equals("\n")) {
						out.println("CHANGE|" + userName + "|" + docName + "|" + position + "|" + "\t" + "|" + length + "|" + version);
					}  else if (! change.equals("")){
						out.println("CHANGE|" + userName + "|" + docName + "|" + position + "|" + change + "|" + length + "|" + version);
					}
				} catch (BadLocationException e1) {
					throw new UnsupportedOperationException();
				}
			}
			@Override
			public void removeUpdate(DocumentEvent e) {
				int position = e.getOffset();
				int length = e.getLength();
				out.println("CHANGE|" + userName + "|" + docName + "|" + position + "|" + length + "|" + version);
			}
		};
		this.addListener();
		this.pack();
	}

	public DocEdit(PrintWriter outputStream, String documentName, String user, String content, String collaboratorNames, int versionID){
		super(documentName);
		this.version = versionID;
		this.cursorPosition = 0;
		out = outputStream;
		this.docName = documentName;
		this.userName = user;
		this.docContent = content;
		this.collaboratorNames = collaboratorNames;
		welcomeLabel = new JLabel("Welcome " + userName + "!");
		exitButton = new JButton("Exit Doc");
		collabLabel = new JLabel("Collaborators: ");
		collaborators = new JLabel(collaboratorNames);
		messageLabel = new JLabel("Messages will appear here.");
		latexButton = new JButton("Latex View");
		latexDisplay = new MyPanel();
		closeLatexButton = new JButton("<");
		closeLatexButton.setVisible(false);
		latexDisplay.setVisible(false);
		textArea = new JTextArea();
		scrollText = new JScrollPane(textArea);
		scrollText.setMinimumSize(new Dimension(700, 700));
		textArea.setText(docContent);
		textArea.setCaretPosition(cursorPosition);
		textDocument = textArea.getDocument();
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		GroupLayout layout = new GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		layout.setAutoCreateGaps(true);
		layout.setAutoCreateContainerGaps(true);
		GroupLayout.ParallelGroup hGroup = layout.createParallelGroup();
		hGroup.addGroup(
				layout.createParallelGroup()
					.addGroup(layout.createSequentialGroup()
							.addComponent(collabLabel)
							.addComponent(collaborators)
							)
					.addComponent(welcomeLabel)
					.addComponent(messageLabel)
					);
		hGroup.addGroup(
				layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
					.addComponent(exitButton)
					.addGroup(layout.createSequentialGroup()							
							.addComponent(scrollText)
							.addComponent(latexDisplay)
							)
					.addGroup(layout.createSequentialGroup()
							.addComponent(closeLatexButton)
							.addComponent(latexButton)
							)
					);
		layout.setHorizontalGroup(hGroup);
		GroupLayout.SequentialGroup vGroup = layout.createSequentialGroup();
		vGroup.addGroup(
					layout.createParallelGroup(GroupLayout.Alignment.CENTER)
						.addComponent(welcomeLabel)
						.addComponent(exitButton)
					);
		vGroup.addGroup(
					layout.createParallelGroup()
						.addComponent(collabLabel)
						.addComponent(collaborators)
					);
		vGroup.addGroup(
					layout.createParallelGroup()
						.addComponent(scrollText)
						.addComponent(latexDisplay)
					);
		vGroup.addGroup(
					layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
						.addComponent(messageLabel)
						.addComponent(closeLatexButton)
						.addComponent(latexButton)
					);
		layout.setVerticalGroup(vGroup);
		latexButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e){
				if (latexDisplay.isVisible()){
					String content = textArea.getText();
					if (Latex.isLatex(content)){
						TeXIcon icon = Latex.getLatex(content);
						BufferedImage b = new BufferedImage(icon.getIconWidth(),
								icon.getIconHeight(), BufferedImage.TYPE_4BYTE_ABGR);
						icon.paintIcon(new JLabel(), b.getGraphics(), 0, 0);
						b.getGraphics().drawImage(b, 0, 0, null);
						latexDisplay.updateImage(b);
						latexDisplay.repaint();
					}
				}
				else{
					latexDisplay.setVisible(true);
					int height = scrollText.getHeight();
					int width = scrollText.getWidth();
					latexDisplay.setMinimumSize(new Dimension(width/2, height));
					scrollText.setMinimumSize(new Dimension(width/2, height));
					latexButton.setText("Render");
					closeLatexButton.setVisible(true);
					packFrame();
				}
			}
		});
		closeLatexButton.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent e){				
				latexDisplay.setVisible(false);
				closeLatexButton.setVisible(false);
				latexButton.setText("Latex View");
			}	
		});
		exitButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e){
				exitDocument();	
			}
		});		
		documentListener = new DocumentListener() {
			@Override
			public void changedUpdate(DocumentEvent e) {
				System.out.println("CHANGED!");
			}
			@Override
			public void insertUpdate(DocumentEvent e) {
				try {
					int position = e.getOffset();
					int length = e.getLength();
					cursorPosition = position + length;
					String change = textDocument.getText(position, length);
					if (change.equals("\n")) {
						out.println("CHANGE|" + userName + "|" + docName + "|" + position + "|" + "\t" + "|" + length + "|" + version);
					}  else if (! change.equals("")){
						out.println("CHANGE|" + userName + "|" + docName + "|" + position + "|" + change + "|" + length + "|" + version);
					}
				} catch (BadLocationException e1) {
					throw new UnsupportedOperationException();
				}
			}
			@Override
			public void removeUpdate(DocumentEvent e) {
				int position = e.getOffset();
				int length = e.getLength();
				cursorPosition = length;
				out.println("CHANGE|" + userName + "|" + docName + "|" + position + "|" + length + "|" + version);
			}
		};
		this.addListener();
		this.pack();
	}
