Results 1 to 6 of 6
  1. #1
    StevenTNorris is offline Member
    Join Date
    Oct 2011
    Posts
    9
    Rep Power
    0

    Default JDialog Not Functioning Properly

    So, my program worked fine until I wanted to add a JDialog cancel popup to one of my searches. The concept is that when a search started (running in a seperate thread), a popup appears that says "Searching....." with cancel button. When run, I get a null pointer exception on searchCancel.setVisible(true); If I remove the thread creation and start, I do not get the error, but the cancel button is unclickable. I've provided the full classes GUI and HotDocTreeWriterController. If you need more or a smaller snippet, just let me know.
    Thanks in advance!

    GUI class
    Java Code:
    package si.gui;
    
    
    import java.awt.Color;
    import java.awt.Desktop;
    import java.awt.Dialog.ModalityType;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.io.File;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Hashtable;
    import java.util.logging.Level;
    import javax.swing.BorderFactory;
    import javax.swing.BoxLayout;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JCheckBox;
    import javax.swing.JDialog;
    import javax.swing.JFileChooser;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    
    import javax.swing.UIManager;
    import javax.swing.UnsupportedLookAndFeelException;
    import javax.swing.border.CompoundBorder;
    import javax.swing.border.EmptyBorder;
    import javax.swing.border.LineBorder;
    import javax.swing.filechooser.FileFilter;
    import si.abstracts.Node;
    import si.classes.HotDocTreeWriterController;
    
    /**
     * Creates gui for hot doc tree builder
     * 
     * @author stnorris
     */
    @SuppressWarnings("serial")
    public class GUI extends JFrame{
    	
    	private JDialog searchCancel;
    	private JButton cancelButton;
    	private JLabel searchLabel;
    	private JMenu helpMenu;
    	private JLabel docAmtLabel;
    	private JMenuItem versionMenu;
    	private JMenuItem helpDocMenu;
    	private ImageIcon icon;
    	private JPanel mainPane;
    	private JPanel viewPanel;
    	private JScrollPane scrollPane;
    	private JTextField locationField;
    	private JLabel locationLabel;
    	private JButton exportButton;
    	private GridBagConstraints c;
    	private JLabel debugLabel;
    	private JCheckBox debugBox;
    	private JMenuBar menu;
    	private JMenu fileMenu;
    	private JMenuItem openMenu;
    	private JMenuItem saveMenu;
    	private JMenuItem exportMenu;
    	private JMenuItem scanFileMenu;
    	private JMenu scanMenu;
    	private JMenuItem scanLibraryMenu;
    	private JMenuItem scanFolderMenu;
    	private JMenu editMenu;
    	private JMenuItem findMenu;
    	private JMenu insertedMenu;
    	private JMenuItem insertedRegMenu;
    	private JMenuItem insertedDeepMenu;
    	private JMenuItem imageMenu;
    	private JMenu searchMenu;
    	private JMenuItem textSearchMenu;
    	private JMenuItem varSearchMenu;
    	private HotDocTreeWriterController control;
    	private JFileChooser fileChooser;
    	private TXTFilter txtFilter;
    	private HDTFilter hdtFilter;
    	private HDLFilter hdlFilter;
    	private RTFFilter rtfFilter;
    	private Hashtable<String, Node>nodes;
    	private SelectPanel selected;
    	private Hashtable<String, SelectPanel> findQueue;
    	private JFrame findFrame;
    	private JPanel findPanel;
    	private JButton findButton;
    	private JTextField findField;
    	private JPanel scanningPane;
    	private JButton scanCancel;
    	private JLabel scanning;
    	private Thread scanThread;
    	
    	/**
    	 * Creates a gui
    	 */
    	public GUI(){
    		
    		icon = new ImageIcon(ClassLoader.getSystemResource("si/images/icon.png"));
    		this.setTitle("HotDoc Tree Viewer");
    		nodes = new Hashtable<String,Node>();
    		control = new HotDocTreeWriterController(this);
    		fileChooser = new JFileChooser("Select a File");
    		docAmtLabel = new JLabel("                   0 documents.");
    		txtFilter = new TXTFilter();
    		hdtFilter = new HDTFilter();
    		hdlFilter = new HDLFilter();
    		rtfFilter = new RTFFilter();
    		viewPanel = new JPanel();
    		scrollPane = new JScrollPane(viewPanel);
    		locationField = new JTextField();
    		locationLabel = new JLabel("Location");
    		exportButton = new JButton("Export as Text");
    		debugLabel = new JLabel("Export Error Log");
    		debugBox = new JCheckBox();
    		menu = new JMenuBar();
    		fileMenu = new JMenu("File");
    		openMenu = new JMenuItem("Open");
    		saveMenu = new JMenuItem("Save");
    		exportMenu = new JMenuItem("Export");
    		scanMenu = new JMenu("Scan");
    		scanLibraryMenu = new JMenuItem("Scan Library");
    		scanFolderMenu = new JMenuItem("Scan Folder");
    		scanFileMenu = new JMenuItem("Scan File");
    		editMenu = new JMenu("Edit");
    		findMenu = new JMenuItem("Find");
    		insertedMenu = new JMenu("Check Inserts");
    		insertedRegMenu = new JMenuItem("Top Level");
    		insertedDeepMenu = new JMenuItem("Deep");
    		imageMenu = new JMenuItem("Images");
    		searchMenu = new JMenu("Search");
    		textSearchMenu = new JMenuItem("Text");
    		varSearchMenu = new JMenuItem("Variable");
    		helpMenu = new JMenu("Help");
    		versionMenu = new JMenuItem("About");
    		helpDocMenu = new JMenuItem("Documentation");
    		mainPane = new JPanel();
    		findQueue = new Hashtable<String, SelectPanel>();
    		selected = null;
    		c = new GridBagConstraints();
    		
    		findFrame = new JFrame("Find");
    		findPanel = new JPanel();
    		findButton = new JButton("Find");
    		findField = new JTextField();
    		
    		scanningPane = new JPanel();
    		scanCancel = new JButton("Cancel");
    		scanning = new JLabel("Scanning...");
    		
    		searchCancel = new JDialog(this, "Searching");
    		cancelButton = new JButton("Cancel");
    		searchLabel = new JLabel("Searching...");
    		
    		control.setLogLevel(Level.SEVERE);
    		
    		try {
    			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    		} catch (ClassNotFoundException e) {
    			e.printStackTrace();
    		} catch (InstantiationException e) {
    			e.printStackTrace();
    		} catch (IllegalAccessException e) {
    			e.printStackTrace();
    		} catch (UnsupportedLookAndFeelException e) {
    			e.printStackTrace();
    		}
    		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		this.setLayout(new GridBagLayout());
    		this.setBounds(100,100,500,500);
    		this.setMinimumSize(new Dimension(350,300));
    		this.initialize();
    		this.setVisible(true);
    	}
    	
    	/**
    	 * Filter for rtf files
    	 * 
    	 * @author stnorris
    	 */
    	private class RTFFilter extends FileFilter{
    
    		/**
    		 * Creates a hdl filter
    		 */
    		public RTFFilter(){
    		}
    		
    		@Override
    		public boolean accept(File file) {
    			if(file.getName().toLowerCase().endsWith(".rtf") || file.isDirectory()){
    				return true;
    			}
    			else{
    				return false;
    			}
    		}
    
    		@Override
    		public String getDescription() {
    			return "HDL Files";
    		}
    		
    	}
    	
    	public void errorPopup(){
    		int response = JOptionPane.showOptionDialog(this, "Finished with errors!", "Error", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, new String[]{"OK","See Errors"}, "OK");
    		if(response == 1){
    			JTextArea tempText = new JTextArea(30,70);
    			tempText.setText(control.getErrors());
    			tempText.setEditable(false);
    			tempText.setSelectionStart(0);
    			tempText.setSelectionEnd(0);
    			JScrollPane tempPane = new JScrollPane(tempText);
    			JOptionPane.showMessageDialog(this, tempPane,"Errors", JOptionPane.OK_OPTION, null);
    		}
    	}
    	
    	/**
    	 * Filter for hdl files
    	 * 
    	 * @author stnorris
    	 */
    	private class HDLFilter extends FileFilter{
    
    		/**
    		 * Creates a hdl filter
    		 */
    		public HDLFilter(){
    		}
    		
    		@Override
    		public boolean accept(File file) {
    			if(file.getName().toLowerCase().endsWith(".hdl") || file.isDirectory()){
    				return true;
    			}
    			else{
    				return false;
    			}
    		}
    
    		@Override
    		public String getDescription() {
    			return "HDL Files";
    		}
    		
    	}
    	
    	/**
    	 * Filter for hdt files
    	 * 
    	 * @author stnorris
    	 */
    	private class HDTFilter extends FileFilter{
    		
    		public HDTFilter(){}
    
    		@Override
    		public boolean accept(File file) {
    			if(file.getName().toLowerCase().endsWith(".hdt") || file.isDirectory()){
    				return true;
    			}
    			else{
    				return false;
    			}
    		}
    
    		@Override
    		public String getDescription() {
    			return "HDT Files";
    		}
    		
    	}
    	
    	/**
    	 * Filter for txt files
    	 *  
    	 * @author stnorris
    	 */
    	private class TXTFilter extends FileFilter{
    		
    		public TXTFilter(){}
    
    		@Override
    		public boolean accept(File file) {
    			if(file.getName().toLowerCase().endsWith(".txt") || file.isDirectory()){
    				return true;
    			}
    			else{
    				return false;
    			}
    		}
    
    		@Override
    		public String getDescription() {
    			return "TXT Files";
    		}
    		
    	}
    	
    	/**
    	 * Initializes gui setup
    	 */
    	private void initialize(){
    		
    		//Find frame setup
    		findPanel.setLayout(new GridBagLayout());
    		findFrame.setResizable(false);
    		findFrame.setDefaultCloseOperation(HIDE_ON_CLOSE);
    		findFrame.setSize(new Dimension(200,80));
    		c.fill = GridBagConstraints.HORIZONTAL;
    		c.gridx = 0;
    		c.gridy = 0;
    		c.gridwidth = 3;
    		c.weightx = 0;
    		c.weighty = 0;
    		c.ipadx = 0;
    		c.ipady = 0;
    		c.anchor = GridBagConstraints.BASELINE;
    		findPanel.add(findField,c);
    		c.fill = GridBagConstraints.NONE;
    		c.gridx = 1;
    		c.gridy = 2;
    		c.gridwidth = 1;
    		c.weightx = 1;
    		c.weighty = 1;
    		c.ipadx = 0;
    		c.ipady = 0;
    		c.anchor = GridBagConstraints.BASELINE;
    		findPanel.add(findButton,c);
    		findFrame.add(findPanel);
    		findFrame.setVisible(false);
    		
    		
    		//Menu setup
    		helpMenu.setMnemonic(KeyEvent.VK_H);
    		versionMenu.setMnemonic(KeyEvent.VK_A);
    		helpDocMenu.setMnemonic(KeyEvent.VK_D);
    		helpMenu.add(helpDocMenu);
    		helpMenu.add(versionMenu);
    		openMenu.setMnemonic(KeyEvent.VK_O);
    		fileMenu.add(openMenu);
    		scanMenu.setMnemonic(KeyEvent.VK_C);
    		fileMenu.add(scanMenu);
    		scanFolderMenu.setMnemonic(KeyEvent.VK_F);
    		scanMenu.add(scanFolderMenu);
    		scanLibraryMenu.setMnemonic(KeyEvent.VK_L);
    		scanMenu.add(scanLibraryMenu);
    		scanFileMenu.setMnemonic(KeyEvent.VK_I);
    		scanMenu.add(scanFileMenu);
    		saveMenu.setMnemonic(KeyEvent.VK_S);
    		fileMenu.add(saveMenu);
    		saveMenu.setEnabled(false);
    		exportMenu.setMnemonic(KeyEvent.VK_E);
    		fileMenu.add(exportMenu);
    		exportMenu.setEnabled(false);
    		fileMenu.setMnemonic(KeyEvent.VK_F);
    		findMenu.setMnemonic(KeyEvent.VK_F);
    		insertedMenu.setMnemonic(KeyEvent.VK_I);
    		insertedRegMenu.setMnemonic(KeyEvent.VK_T);
    		insertedDeepMenu.setMnemonic(KeyEvent.VK_D);
    		insertedMenu.add(insertedRegMenu);
    		insertedMenu.add(insertedDeepMenu);
    		imageMenu.setMnemonic(KeyEvent.VK_I);
    		searchMenu.setMnemonic(KeyEvent.VK_S);
    		textSearchMenu.setMnemonic(KeyEvent.VK_T);
    		varSearchMenu.setMnemonic(KeyEvent.VK_V);
    		searchMenu.add(textSearchMenu);
    		searchMenu.add(varSearchMenu);
    		searchMenu.add(imageMenu);
    		editMenu.add(findMenu);
    		editMenu.add(insertedMenu);
    		editMenu.add(searchMenu);
    		editMenu.setMnemonic(KeyEvent.VK_E);
    		editMenu.setEnabled(false);
    		menu.add(fileMenu);
    		menu.add(editMenu);
    		menu.add(helpMenu);
    		this.setJMenuBar(menu);
    		
    		//Main panel setup
    		mainPane.setLayout(new GridBagLayout());
    		mainPane.setBorder(new EmptyBorder(10,10,10,10));
    		
    		//Open label setup
    		c.fill = GridBagConstraints.NONE;
    		c.gridx = 0;
    		c.gridy = 0;
    		c.gridwidth = 1;
    		c.weightx = 0;
    		c.weighty = 0;
    		c.ipadx = 10;
    		c.ipady = 0;
    		c.anchor = GridBagConstraints.BASELINE;
    		mainPane.add(locationLabel,c);
    		
    		//Open field setup
    		c.fill = GridBagConstraints.HORIZONTAL;
    		c.gridx = 1;
    		c.gridy = 0;
    		c.gridwidth = 3;
    		c.weightx = .9;
    		c.weighty = 0;
    		c.ipadx = 0;
    		c.ipady = 0;
    		c.anchor = GridBagConstraints.BASELINE;
    		locationField.setEditable(false);
    		mainPane.add(locationField,c);
    
    		//Doc number setup
    		c.fill = GridBagConstraints.BOTH;
    		c.gridx = 0;
    		c.gridy = 1;
    		c.gridwidth = 4;
    		c.weightx = 0;
    		c.weighty = 0;
    		c.ipadx = 0;
    		c.ipady = 0;
    		c.anchor = GridBagConstraints.BASELINE;
    		mainPane.add(docAmtLabel,c);
    		
    		//View field setup
    		c.fill = GridBagConstraints.BOTH;
    		c.gridx = 0;
    		c.gridy = 2;
    		c.gridwidth = 4;
    		c.weightx = 0;
    		c.weighty = .9;
    		c.ipadx = 0;
    		c.ipady = 0;
    		c.anchor = GridBagConstraints.BASELINE;
    		scrollPane.setBorder(new CompoundBorder(new EmptyBorder(10,10,10,10), new LineBorder(Color.BLACK,1)));
    		scrollPane.setViewportView(viewPanel);
    		viewPanel.setBorder(BorderFactory.createLoweredBevelBorder());
    		viewPanel.setLayout(new BoxLayout(viewPanel, BoxLayout.Y_AXIS));
    
    		mainPane.add(scrollPane,c);
    		
    		//Debug check box setup
    		c.fill = GridBagConstraints.NONE;
    		c.gridx = 1;
    		c.gridy = 3;
    		c.gridwidth = 1;
    		c.weightx = .9;
    		c.weighty = 0;
    		c.ipadx = 0;
    		c.ipady = 0;
    		c.anchor = GridBagConstraints.BASELINE_TRAILING;
    		debugBox.setEnabled(false);
    		mainPane.add(debugBox,c);
    		
    		//Debug label setup
    		c.fill = GridBagConstraints.NONE;
    		c.gridx = 2;
    		c.gridy = 3;
    		c.gridwidth = 1;
    		c.weightx = 0;
    		c.weighty = 0;
    		c.ipadx = 20;
    		c.ipady = 0;
    		mainPane.add(debugLabel,c);
    		
    		//Export button setup
    		c.fill = GridBagConstraints.NONE;
    		c.gridx = 3;
    		c.gridy = 3;
    		c.gridwidth = 1;
    		c.weightx = 0;
    		c.weighty = 0;
    		c.ipadx = 0;
    		c.ipady = 0;
    		c.anchor = GridBagConstraints.BASELINE;
    		exportButton.setEnabled(false);
    		mainPane.add(exportButton,c);
    
    		//Scanning panel setup
    		scanningPane.setLayout(new FlowLayout());
    		scanningPane.add(scanning);
    		scanningPane.add(scanCancel);
    		
    		//Searching dialog setup
    		searchCancel.setLayout(new GridBagLayout());
    		searchCancel.setSize(100, 100);
    		c.fill = GridBagConstraints.BOTH;
    		c.gridx = 0;
    		c.gridy = 0;
    		c.gridwidth = 3;
    		c.weightx = 0;
    		c.weighty = 0;
    		c.ipadx = 0;
    		c.ipady = 20;
    		searchCancel.add(searchLabel,c);
    		c.fill = GridBagConstraints.NONE;
    		c.gridx = 1;
    		c.gridy = 1;
    		c.gridwidth = 1;
    		c.weightx = 0;
    		c.weighty = 0;
    		c.ipadx = 0;
    		c.ipady = 0;
    		searchCancel.add(cancelButton,c);
    		
    		
    		this.setLayout(new GridLayout());
    		this.getContentPane().add(mainPane);
    		
    		addListeners();
    	}
    	
    	/**
    	 * Populates pane with initial children
    	 * 
    	 * @param pane JPanel to populate
    	 */
    	private void populateViewPane(JPanel pane, Node node, int indent){
    		
    		/**
    		 * Listener for select panes
    		 * 
    		 * @author stnorris
    		 */
    		class SelectListener implements MouseListener{
    			private JScrollPane scroller;
    			
    			/**
    			 * Creates a listener for a select pane
    			 */
    			public SelectListener(JScrollPane scroller){
    				this.scroller = scroller;
    			}
    
    			@Override
    			public void mouseClicked(MouseEvent e) {
    				SelectPanel tempToggle = (SelectPanel) e.getSource();
    				if(selected  == null){
    					tempToggle.click();
    					selected = tempToggle;
    				}
    				else if(tempToggle == selected){
    					tempToggle.click();
    					selected = null;
    				}
    				else{
    					selected.click();
    					tempToggle.click();
    					selected = tempToggle;
    				}
    				scroller.scrollRectToVisible(tempToggle.getBounds());
    			}
    
    			@Override
    			public void mouseEntered(MouseEvent arg0) {
    				
    			}
    
    			@Override
    			public void mouseExited(MouseEvent arg0) {
    				
    			}
    
    			@Override
    			public void mousePressed(MouseEvent arg0) {
    				
    			}
    
    			@Override
    			public void mouseReleased(MouseEvent arg0) {
    				
    			}
    			
    		}
    		
    		/**
    		 * Listener for toggle buttons
    		 * 
    		 * @author stnorris
    		 */
    		class ToggleListener implements MouseListener{
    			
    			/**
    			 * Creates a listener for a toggle button
    			 */
    			public ToggleListener(){
    			}
    
    			@Override
    			public void mouseClicked(MouseEvent e) {
    				NodeToggle tempToggle = (NodeToggle) e.getSource();
    				JPanel tempParent = (JPanel)tempToggle.getParent().getParent();
    				JPanel tempToggleContainer = (JPanel)tempToggle.getParent();
    				
    				tempToggle.click();
    				if(tempToggle.isSelected()){
    					populateViewPane(tempParent, tempToggle.getNode(), tempToggle.getIndent());
    				}
    				else{
    					 tempParent.removeAll();
    					 tempParent.add(tempToggleContainer);
    					 tempParent.updateUI();
    				}
    			}
    
    			@Override
    			public void mouseEntered(MouseEvent arg0) {
    				
    			}
    
    			@Override
    			public void mouseExited(MouseEvent arg0) {
    				
    			}
    
    			@Override
    			public void mousePressed(MouseEvent arg0) {
    				
    			}
    
    			@Override
    			public void mouseReleased(MouseEvent arg0) {
    				
    			}
    			
    		}
    		
    		//Get and add node's children
    		Hashtable<String,Node> tempChildren = control.getChildren(node);
    		nodes.putAll(tempChildren);
    		
    		//Create components
    		SelectPanel tempPane;
    		NodeToggle tempButton;
    		JLabel tempLabel; 
    		JPanel tempMainPane;
    		ArrayList<String> keys = new ArrayList<String>(tempChildren.keySet());
    		Collections.sort(keys,String.CASE_INSENSITIVE_ORDER);
    		
    		//Add all children components
    		for(String name:keys){
    			
    			//Main pane for top-to-bottom view of children of the child
    			tempMainPane = new JPanel();
    			tempMainPane.setLayout(new BoxLayout(tempMainPane,BoxLayout.Y_AXIS));
    			tempMainPane.setBorder(new EmptyBorder(0,0,0,0));
    			
    			//Pane for left-to-right view of child (indent set by empty border
    			tempPane = new SelectPanel();
    			tempPane.addMouseListener(new SelectListener(scrollPane));
    			tempPane.setLayout(new FlowLayout(FlowLayout.LEFT));
    			tempPane.setBorder(new EmptyBorder(0,indent*15,0,0));
    			if(tempChildren.get(name).getChildren().size() > 0){
    				tempButton = new NodeToggle(tempChildren.get(name),indent+1,"si/images/minus.png","si/images/plus.png");
    				tempButton.addMouseListener(new ToggleListener());
    				tempPane.add(tempButton,c);
    			}
    			else{
    				tempButton = new NodeToggle(tempChildren.get(name),indent+1,"si/images/none.png","si/images/none.png");
    				tempButton.addMouseListener(new ToggleListener());
    				tempPane.add(tempButton,c);
    			}
    			tempLabel = new JLabel(name);
    			tempPane.add(tempLabel);
    			
    			//Add to panes
    			tempMainPane.add(tempPane);
    			pane.add(tempMainPane);
    			if(indent == 0){
    				findQueue.put(name.toUpperCase(), tempPane);
    			}
    		}
    		docAmtLabel.setText("                   "+control.getNode().getChildren().size()+" documents.");
    		pane.updateUI();
    		
    
    	}
    	
    	/**
    	 * Adds listeners for functionality
    	 */
    	private void addListeners(){
    		
    		/**
    		 * Listener for saving files
    		 * 
    		 * @author stnorris
    		 */
    		class saveListener implements ActionListener{
    
    			private JFrame parent;
    			
    			/**
    			 * Creates a openListener
    			 * 
    			 * @param parent parent frame to display open dialog in
    			 */
    			public saveListener(JFrame parent){
    				this.parent = parent;
    			}
    			
    			@Override
    			public void actionPerformed(ActionEvent e) {
    				fileChooser.setFileFilter(hdtFilter);
    				fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    				int result = fileChooser.showSaveDialog(parent);
    				if(result == JFileChooser.APPROVE_OPTION){
    					control.setLocation(fileChooser.getSelectedFile().getParent()+"\\");
    					String fileName = fileChooser.getSelectedFile().getName();
    					if(fileName.indexOf(".") > 0){
    						fileName = fileName.substring(0,fileName.indexOf("."));
    					}
    					control.setDocName(fileName);
    					if(debugBox.isSelected()){
    						control.write(false,true,true);
    					}
    					else{
    						control.write(false, true, false);
    					}
    				}
    			}
    			
    		}
    		
    		/**
    		 * Listener for opening files
    		 * 
    		 * @author stnorris
    		 */
    		class openListener implements ActionListener{
    			
    			private JFrame parent;
    			
    			/**
    			 * Creates a openListener
    			 * 
    			 * @param parent parent frame to display open dialog in
    			 */
    			public openListener(JFrame parent){
    				this.parent = parent;
    			}
    
    			@Override
    			public void actionPerformed(ActionEvent e) {
    				fileChooser.setFileFilter(hdtFilter);
    				fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    				int result = fileChooser.showOpenDialog(parent);
    				if(result == JFileChooser.APPROVE_OPTION){
    					locationField.setText(fileChooser.getSelectedFile().getPath());
    					control.setNode(fileChooser.getSelectedFile());
    					debugBox.setEnabled(true);
    					exportButton.setEnabled(true);
    					saveMenu.setEnabled(true);
    					exportMenu.setEnabled(true);
    					editMenu.setEnabled(true);
    					viewPanel.removeAll();
    					populateViewPane(viewPanel, control.getNode(),0);
    				}
    			}
    			
    		}
    		
    		/**
    		 * Listener for exporting files
    		 * 
    		 * @author stnorris
    		 */
    		class exportListener implements ActionListener {
    
    			private JFrame parent;
    			
    			/**
    			 * Creates a openListener
    			 * 
    			 * @param parent parent frame to display open dialog in
    			 */
    			public exportListener(JFrame parent){
    				this.parent = parent;
    			}
    			
    			@Override
    			public void actionPerformed(ActionEvent e) {
    				fileChooser.setDialogTitle("Export");
    				fileChooser.setFileFilter(txtFilter);
    				fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    				int result = fileChooser.showDialog(parent,"Export file");
    				if(result == JFileChooser.APPROVE_OPTION){
    					control.setLocation(fileChooser.getSelectedFile().getParent()+"\\");
    					String fileName = fileChooser.getSelectedFile().getName();
    					if(fileName.indexOf(".") > 0){
    						fileName = fileName.substring(0,fileName.indexOf("."));
    					}
    					control.setDocName(fileName);
    					if(debugBox.isSelected()){
    						control.write(true,false,true);
    					}
    					else{
    						control.write(true, false, false);
    					}
    				}
    			}
    		
    		}
    		
    		/**
    		 * Listener for find menu
    		 * 
    		 * @author stnorris
    		 */
    		class findListener implements ActionListener{
    			private String findText;
    			private SelectPanel found;
    			private JFrame parent;
    			
    			public findListener(JFrame parent){
    				this.parent = parent;
    			}
    			
    			@Override
    			public void actionPerformed(ActionEvent e) {
    				findText = JOptionPane.showInputDialog(parent,"Find");
    				if((found = findQueue.get(findText.toUpperCase())) != null){
    					if(!scrollPane.getViewport().contains(found.getParent().getLocation())){
    						scrollPane.getViewport().setViewPosition(found.getParent().getLocation());
    					}
    					if(selected == null){
    						selected = found;
    						selected.click();
    					}
    					else{
    						selected.click();
    						selected = found;
    						selected.click();
    					}
    				}
    				else{
    					JOptionPane.showMessageDialog(parent, "No matches found.","Not Found",JOptionPane.OK_OPTION,icon);
    				}
    				
    			}
    			
    		}
    		
    		/**
    		 * Listener for finding document insertion
    		 * 
    		 * @author stnorris
    		 *
    		 */
    		class insertedListener implements ActionListener{
    			private String findText;
    			private JFrame parent;
    			private ArrayList<String> insertions;
    			private boolean deepSearch;
    			
    			public insertedListener(JFrame parent, boolean deepSearch){
    				this.parent = parent;
    				this.deepSearch = deepSearch;
    			}
    			
    			@Override
    			public void actionPerformed(ActionEvent e) {
    				findText = JOptionPane.showInputDialog(parent,"Document to check for insertions");
    				if(findText != null && findText.trim() != ""){
    					if((insertions = control.checkInserted(findText,deepSearch)) != null ){
    						String tempBuild = findText+" is inserted into:\n";
    						for(String tempString:insertions){
    							tempBuild += "\n"+tempString;
    						}
    						JTextArea tempText = new JTextArea(30,30);
    						tempText.setText(tempBuild);
    						tempText.setEditable(false);
    						tempText.setSelectionStart(0);
    						tempText.setSelectionEnd(0);
    						JScrollPane tempScroll = new JScrollPane(tempText);
    						JOptionPane.showMessageDialog(parent, tempScroll, "Inserted in...", JOptionPane.OK_OPTION,icon);
    					}
    					else{
    						JOptionPane.showMessageDialog(parent, findText+" is not inserted into any documents.", "Not Found", JOptionPane.OK_OPTION, icon);
    					}
    				}
    				
    			}
    			
    		}
    		
    		/**
    		 * Listener for searches
    		 * 
    		 * @author stnorris
    		 */
    		class searchListener implements ActionListener{
    			
    			private JFrame parent;
    			private String searchType;
    			
    			public searchListener(JFrame parent,String searchType){
    				this.parent = parent;
    				this.searchType = searchType;
    			}
    			
    			@Override
    			public void actionPerformed(ActionEvent arg0) {
    				if(searchType.equals("Images")){
    					control.setRunType(HotDocTreeWriterController.SEARCH_IMAGES, null);
    				}
    				else if(searchType.equals("Variables")){
    					String var = JOptionPane.showInputDialog(parent,"Find");
    					control.setRunType(HotDocTreeWriterController.SEARCH_VARS, var);
    				}
    				else{
    					String text = JOptionPane.showInputDialog(parent,"Find");
    					control.setRunType(HotDocTreeWriterController.SEARCH_TEXT, text);
    				}
    				Thread tempThread = new Thread(control);
    				tempThread.start();
    				searchCancel.setModalityType(ModalityType.APPLICATION_MODAL);
    				searchCancel.setLocationRelativeTo(parent);
    				searchCancel.setVisible(true);
    			}
    			
    		}
    		
    		/**
    		 * Listener for scanning merges
    		 * 
    		 * 
    		 * @author stnorris
    		 *
    		 */
    		class scanListener implements ActionListener{
    
    			private JFrame parent;
    			private int type;
    			public static final int FOLDER = 2;
    			public static final int LIBRARY = 1;
    			public static final int FILE = 0;
    			
    			/**
    			 * Constructs a listener for scanning
    			 * 
    			 * @param parent parent frame
    			 * @param type type of scan
    			 */
    			public scanListener(JFrame parent,int type){
    				this.parent=parent;
    				this.type = type;
    			}
    			
    			@Override
    			public void actionPerformed(ActionEvent arg0) {
    				fileChooser.setDialogTitle("Scan");
    				int result = -1;
    				if(type == FOLDER){
    					fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    					result = fileChooser.showDialog(parent,"Scan folder");
    				}
    				else if(type == LIBRARY){
    					fileChooser.setFileFilter(hdlFilter);
    					fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    					result = fileChooser.showDialog(parent,"Scan library file");
    				}
    				else if(type == FILE){
    					fileChooser.setFileFilter(rtfFilter);
    					fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    					result = fileChooser.showDialog(parent,"Scan single file");
    				}
    				if(result == JFileChooser.APPROVE_OPTION){
    					control.resetErrorLog();
    					docAmtLabel.setText("                   0 documents.");
    					viewPanel.removeAll();
    					if(type == FOLDER){
    						control.setSource(fileChooser.getSelectedFile().getPath()+"\\");
    					}
    					else{
    						control.setSource(fileChooser.getSelectedFile().getPath());
    					}
    					control.setRunType(HotDocTreeWriterController.SCAN, null);
    					scanThread = new Thread(control);
    					scanThread.start();
    					fileMenu.setEnabled(false);
    					editMenu.setEnabled(false);
    					exportButton.setEnabled(false);
    					debugBox.setEnabled(false);
    					locationField.setText(fileChooser.getSelectedFile().getPath());
    					viewPanel.add(scanningPane);
    					viewPanel.updateUI();
    				}
    			}
    		}
    		
    		/**
    		 * Listener for version menu
    		 * 
    		 * @author stnorris
    		 */
    		class versionListener implements ActionListener{
    
    			private GUI gui;
    			
    			public versionListener(GUI gui){
    				this.gui = gui;
    			}
    			
    			@Override
    			public void actionPerformed(ActionEvent arg0) {
    				JOptionPane.showMessageDialog(gui, "HotDoc Tree Viewer\n\nVersion1.0\n\nCopyright 2011, Steven T. Norris","Version Information",JOptionPane.OK_OPTION,icon);
    				
    			}
    			
    		}
    		
    		/**
    		 * Opens help documentation
    		 * 
    		 * @author stnorris
    		 */
    		class helpDocListener implements ActionListener{
    			
    			private GUI gui;
    			
    			public helpDocListener(GUI gui){
    				this.gui = gui;
    			}
    			
    			@Override
    			public void actionPerformed(ActionEvent arg0) {
    				try {
    					if(Desktop.isDesktopSupported()){
    						String filename = ClassLoader.getSystemResource("si/documentation/User Manual.pdf").getFile();
    						filename = filename.replace("%20", " ");
    						File file = new File(filename);
    						Desktop desk = Desktop.getDesktop();
    						desk.open(file);
    					}
    					else{
    						JOptionPane.showMessageDialog(gui, "Could not load documentation.", "Error", JOptionPane.ERROR_MESSAGE);
    					}
    				} catch (IOException e) {
    					JOptionPane.showMessageDialog(gui, "Could not load documentation.", "Error", JOptionPane.ERROR_MESSAGE);
    					e.printStackTrace();
    				}
    			}
    	
    		}
    		
    		/**
    		 * Listener for scan cancels
    		 * 
    		 * @author stnorris
    		 */
    		class cancelListener implements ActionListener{
    			
    			public cancelListener(){
    			}
    			
    			@Override
    			public void actionPerformed(ActionEvent arg0) {
    				control.stopRun();
    			}
    			
    		}
    		
    		//Add listeners to menus and buttons
    		cancelButton.addActionListener(new cancelListener());
    		varSearchMenu.addActionListener(new searchListener(this,"Variables"));
    		textSearchMenu.addActionListener(new searchListener(this,"Text"));
    		helpDocMenu.addActionListener(new helpDocListener(this));
    		versionMenu.addActionListener(new versionListener(this));
    		scanFolderMenu.addActionListener(new scanListener(this, scanListener.FOLDER));
    		openMenu.addActionListener(new openListener(this));
    		saveMenu.addActionListener(new saveListener(this));
    		exportMenu.addActionListener(new exportListener(this));
    		scanLibraryMenu.addActionListener(new scanListener(this, scanListener.LIBRARY));
    		scanFileMenu.addActionListener(new scanListener(this,scanListener.FILE));
    		findMenu.addActionListener(new findListener(this));
    		insertedRegMenu.addActionListener(new insertedListener(this,false));
    		insertedDeepMenu.addActionListener(new insertedListener(this,true));
    		findButton.addActionListener(new findListener(this));
    		exportButton.addActionListener(new exportListener(this));
    		imageMenu.addActionListener(new searchListener(this,"Images"));
    		scanCancel.addActionListener(new cancelListener());
    
    	}
    	
    	/**
    	 * Sets up viewpanel when scan is finished.
    	 */
    	public void scanFinished(){
    		fileMenu.setEnabled(true);
    		if(control.getNode() != null){
    			locationField.setText(control.getNode().getFile().getAbsolutePath());
    			viewPanel.removeAll();
    			populateViewPane(viewPanel, control.getNode(),0);
    			saveMenu.setEnabled(true);
    			exportMenu.setEnabled(true);
    			editMenu.setEnabled(true);
    			exportButton.setEnabled(true);
    			debugBox.setEnabled(true);
    		}
    		else{
    			locationField.setText("");
    			viewPanel.removeAll();
    			viewPanel.updateUI();
    			saveMenu.setEnabled(false);
    			exportMenu.setEnabled(false);
    			editMenu.setEnabled(false);
    			exportButton.setEnabled(false);
    			debugBox.setEnabled(false);
    		}
    	}
    	
    	public void searchFinished(boolean cancelled,String searchType){
    		searchCancel.setModalityType(ModalityType.MODELESS);
    		searchCancel.setVisible(false);
    		if(!cancelled){
    			String tempString = control.getSearchResults();
    			JTextArea tempText = new JTextArea(30,30);
    			if(tempString != null){
    				tempText.setText(tempString);
    				tempText.setEditable(false);
    				tempText.setSelectionStart(0);
    				tempText.setSelectionEnd(0);
    				JScrollPane tempScroll = new JScrollPane(tempText);
    				JOptionPane.showMessageDialog(this, tempScroll, searchType + " in...", JOptionPane.OK_OPTION, icon);
    			}
    			else{
    				JOptionPane.showMessageDialog(this, "No matches found.", "Not Found", JOptionPane.OK_OPTION, icon);
    			}
    		}
    	}
    	
    	/**
    	 * Toggle button for nodes
    	 * 
    	 * @author stnorris
    	 */
    	private class NodeToggle extends JLabel{
    		private Node node;
    		private int indent;
    		private boolean selected;
    		private ImageIcon on;
    		private ImageIcon off;
    		
    		/**
    		 * Creates a node toggle button
    		 * 
    		 * @param node node to be toggled on
    		 */
    		public NodeToggle(Node node, int indent,String selected, String deselected){
    			this.node = node;
    			this.indent = indent;
    			on = new ImageIcon(ClassLoader.getSystemResource(selected));
    			off = new ImageIcon(ClassLoader.getSystemResource(deselected));
    			this.setIcon(off);
    			this.selected = false;
    		}
    		
    		/**
    		 * Checks for selected status
    		 * 
    		 * @return selected status
    		 */
    		public boolean isSelected(){
    			return selected;
    		}
    		
    		/**
    		 * Sets selected as a toggle
    		 */
    		public void click(){
    			if(selected){
    				selected = false;
    				this.setIcon(off);
    			}
    			else{
    				selected = true;
    				this.setIcon(on);
    			}
    		}
    		
    		/**
    		 * Gets node for the toggle button
    		 * 
    		 * @return node for toggle button
    		 */
    		public Node getNode(){
    			return node;
    		}
    		
    		/**
    		 * Returns toggle button's indent level
    		 * 
    		 * @return indent level
    		 */
    		public int getIndent(){
    			return indent;
    		}
    		
    	}
    	
    	/**
    	 * Selectable label.
    	 * 
    	 * @author stnorris
    	 */
    	private class SelectPanel extends JPanel{
    		private boolean selected;
    		private Color clear;
    	
    		/**
    		 * Creates a select label
    		 * 
    		 * @param label
    		 */
    		public SelectPanel(){
    			selected=false;
    			clear = this.getBackground();
    		}
    		
    		/**
    		 * Returns selected status
    		 * @return selected status
    		 */
    		@SuppressWarnings("unused")
    		public boolean isSelected(){
    			return selected;
    		}
    		
    		/**
    		 * Changes selected status
    		 */
    		public void click(){
    			if(selected){
    				selected = false;
    				this.setBackground(clear);
    			}
    			else{
    				selected = true;
    				this.setBackground(Color.GRAY);
    			}
    		}
    	}
    }
    HotDocTreeWriterController class
    Java Code:
    package si.classes;
    
    import java.io.BufferedReader;
    import java.io.DataInputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.ObjectInputStream;
    import java.util.ArrayList;
    import java.util.Hashtable;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    import si.abstracts.Node;
    import si.commandline.CommandLineRunner;
    import si.gui.GUI;
    
    /**
     * Used to control the building and writing of a hot doc insert tree
     * 
     * @author stnorris
     */
    public class HotDocTreeWriterController implements Runnable{
    	
    	private boolean error;
    	private String errors;
    	private final HotDocTreeScraper scraper=new HotDocTreeScraper();
    	private final DocNodeWriter writer = DocNodeWriter.getInstance();
    	private static Logger log = Logger.getLogger(CommandLineRunner.class.getName());
    	private ArrayList<Node>tempExists = new ArrayList<Node>();
    	private GUI gui;
    	private DocNode prevState;
    	private boolean threadRunning;
    	private int runType;
    	private Object runParams;
    	public static final int SCAN = 0;
    	public static final int SEARCH_TEXT = 1;
    	public static final int SEARCH_IMAGES = 2;
    	public static final int SEARCH_VARS = 3;
    	private String searchResults;
    	
    	/**
    	 * Creates the controller
    	 */
    	public HotDocTreeWriterController(GUI gui){
    		log.setLevel(Level.INFO);
    		this.gui = gui;
    	}
    	
    	/**
    	 * Sets the level for the logger
    	 * 
    	 * @param level level for logging
    	 */
    	public void setLogLevel(Level level){
    		log.setLevel(level);
    		scraper.setLogLevel(level);
    		writer.setLogLevel(level);
    	}
    	
    	/**
    	 * Adds errors to the error log
    	 * 
    	 * @param errors
    	 */
    	public void addToErrorLog(String errors){
    		writer.addToErrorLog(errors);
    	}
    	
    	/**
    	 * Sets source directory for scraper
    	 * 
    	 * @param directory
    	 */
    	public void setSource(String directory){
    		scraper.setSource(directory);
    	}
    	
    	/**
    	 * Sets location for writer
    	 * 
    	 * @param location
    	 */
    	public void setLocation(String location){
    		writer.setLocation(location);
    	}
    	
    	/**
    	 * Sets node for writer
    	 * 
    	 * @param node
    	 */
    	public void setNode(DocNode node){
    		writer.setNode(node);
    	}
    	
    	/**
    	 * Sets node based on an hdt file
    	 * 
    	 * @param nodeFile hdt file of node
    	 */
    	public void setNode(File nodeFile){
    		errors = "";
    		error = false;
    		try {
    			FileInputStream inStream = new FileInputStream(nodeFile);
    			ObjectInputStream oIn = new ObjectInputStream(inStream);
    			DocNode node = (DocNode) oIn.readObject();
    			writer.setNode(node);
    		} catch (FileNotFoundException e) {
    			error = true;
    			writer.addToErrorLog("Could not load file: " + e.getMessage());
    			e.printStackTrace();
    		} catch (IOException e) {
    			error = true;
    			writer.addToErrorLog("Could not load file: " + e.getMessage());
    			e.printStackTrace();
    		} catch (ClassNotFoundException e) {
    			error = true;
    			writer.addToErrorLog("Could not load file: " + e.getMessage());
    			e.printStackTrace();
    		}
    		checkErrors();
    	}
    	
    	public Hashtable<String,Node> getChildren(Node node){
    		Hashtable<String,Node> children = new Hashtable<String,Node>();
    		for(Node tempNode:node.getChildren()){
    			children.put(tempNode.getName(), tempNode);
    		}
    		return children;
    	}
    	
    	private void checkErrors(){
    		if(error){
    			gui.errorPopup();
    		}
    	}
    	
    	public String getErrors(){
    		return errors;
    	}
    	
    	public DocNode getNode(){
    		return writer.getNode();
    	}
    	
    	/**
    	 * Sets doc name for writer
    	 * 
    	 * @param name
    	 */
    	public void setDocName(String name){
    		writer.setDocName(name);
    	}
    	
    	/**
    	 * Builds inserts tree
    	 */
    	public void buildTree(){
    		errors = "";
    		error = false;
    		scraper.startScrape();
    		if(threadRunning){
    			writer.setNode(scraper.getResult());
    			writer.addToErrorLog("\r\r"+scraper.getErrors());
    		}
    		if (scraper.hasErrors() || writer.hasErrors()){
    			error = true;
    			errors = writer.getErrorLog();
    		}
    		checkErrors();
    	}
    	
    	/**
    	 * Checks for images in documents
    	 * 
    	 * @return String list of documents containing images
    	 */
    	public String checkImage(){
    		errors = "";
    		error = false;
    		DocNode node = writer.getNode();
    		ArrayList<DocNode> children = node.getDocChildren();
    		String tempBuild;
    		String line;
    		FileInputStream in;
    		DataInputStream inData;
    		InputStreamReader inStream;
    		BufferedReader buffIn;
    		tempBuild = "Images are in: ";
    		try {
    			log.log(Level.INFO,"Finding images...");
    			int count = 0;
    			for(DocNode child:children){
    				if(threadRunning){
    					in = new FileInputStream(child.getFile());
    					inData = new DataInputStream(in);
    					inStream = new InputStreamReader(inData);
    					buffIn = new BufferedReader(inStream);
    					log.log(Level.INFO,"Finding images for "+child.getName()+"...");
    					while((line = buffIn.readLine()) != null){
    						if(threadRunning){
    							if(line.contains("\\pict")){
    								tempBuild += "\n" + child.getName();
    								count ++;
    								break;
    							}
    						}
    						else{
    							break;
    						}
    					}
    				}
    				else{
    					break;
    				}
    			}
    			if(tempBuild.equals("Images are in: ")){
    				return null;
    			}
    			else{
    				tempBuild += "\n -Images found in " + count + " documents.-";
    				return tempBuild;
    			}
    		} catch (FileNotFoundException e) {
    			error = true;
    			errors += "File read error: " + e.getMessage();
    			e.printStackTrace();
    			checkErrors();
    			return null;
    		} catch (IOException e) {
    			error = true;
    			errors += "File read error: " + e.getMessage();
    			e.printStackTrace();
    			checkErrors();
    			return null;
    		}
    	}
    	
    	/**
    	 * Checks for variables in documents
    	 * 
    	 * @param var Variable to search for
    	 * @return String list of documents containing variable
    	 */
    	public String checkVar(String var){
    		if(var == null){
    			return null;
    		}
    		else{
    			errors = "";
    			error = false;
    			DocNode node = writer.getNode();
    			ArrayList<DocNode> children = node.getDocChildren();
    			String tempBuild;
    			String line;
    			FileInputStream in;
    			DataInputStream inData;
    			InputStreamReader inStream;
    			BufferedReader buffIn;
    			tempBuild = "Variables are in: ";
    			Pattern patternVar = Pattern.compile("[ {}():;,'+-=!]{0,1}"+var+"[ {}():;',+-=!]{0,1}");
    			Matcher matchVar = patternVar.matcher("");
    			try {
    				log.log(Level.INFO,"Finding variable...");
    				int count = 0;
    				String checkLine;
    				boolean start;
    				boolean found ;
    				for(DocNode child:children){
    					if(threadRunning){
    						checkLine = "";
    						start = false;
    						found = false;
    						in = new FileInputStream(child.getFile());
    						inData = new DataInputStream(in);
    						inStream = new InputStreamReader(inData);
    						buffIn = new BufferedReader(inStream);
    						log.log(Level.INFO,"Finding variables for "+child.getName()+"...");
    						line = buffIn.readLine();
    						//System.out.println("Check doc "+child.getName());
    						while(line != null && !found){
    							if(threadRunning){
    								if(!start){
    									if(line.contains("\\'ab")){
    										start = true;
    										checkLine = line.substring(line.indexOf("\\'ab")+4);
    										//System.out.println("-Found start. Checking "+checkLine);
    									}
    									else{
    										line = buffIn.readLine();
    										//System.out.println("\nChecking line "+line);
    									}
    								}
    								if(start){
    									if(checkLine.contains("\\'bb")){
    										start = false;
    										checkLine = checkLine.substring(0,checkLine.indexOf("\\'bb"));
    										//System.out.println("--Found end. Checking "+checkLine);
    										matchVar.reset(checkLine);
    										if(matchVar.find()){
    											//System.out.println(checkLine);
    											//System.out.println("---Variable present.");
    											tempBuild += "\n"+child.getName();
    											count++;
    											found = true;
    										}
    										//System.out.println(line);
    										line = line.substring(line.indexOf("\\'bb")+4);
    									}
    									else{
    										line = buffIn.readLine();
    										checkLine += line;
    										//System.out.println("--End not found. Checking "+checkLine);
    									}
    								}
    							}
    							else{
    								break;
    							}
    						}
    					}
    					else{
    						break;
    					}
    				}
    				if(tempBuild.equals("Variables are in: ")){
    					return null;
    				}
    				else{
    					tempBuild += "\n -Variables found in " + count + " documents.-";
    					return tempBuild;
    				}
    			} catch (FileNotFoundException e) {
    				error = true;
    				errors += "File read error: " + e.getMessage();
    				e.printStackTrace();
    				checkErrors();
    				return null;
    			} catch (IOException e) {
    				error = true;
    				errors += "File read error: " + e.getMessage();
    				e.printStackTrace();
    				checkErrors();
    				return null;
    			}
    		}
    	}
    	
    	/**
    	 * Checks for text in documents
    	 * 
    	 * @return String list of documents containing specified text
    	 */
    	public String checkString(String string){
    		if(string == null){
    			return null;
    		}
    		else{
    			errors = "";
    			error = false;
    			DocNode node = writer.getNode();
    			ArrayList<DocNode> children = node.getDocChildren();
    			String tempBuild;
    			String line;
    			FileInputStream in;
    			DataInputStream inData;
    			InputStreamReader inStream;
    			BufferedReader buffIn;
    			tempBuild = "Text found in: ";
    			try {
    				log.log(Level.INFO,"Finding "+string+"...");
    				int count = 0;
    				for(DocNode child:children){
    					if(threadRunning){
    						in = new FileInputStream(child.getFile());
    						inData = new DataInputStream(in);
    						inStream = new InputStreamReader(inData);
    						buffIn = new BufferedReader(inStream);
    						log.log(Level.INFO,"Finding "+string+" for "+child.getName()+"...");
    						while((line = buffIn.readLine()) != null){
    							if(threadRunning){
    								if(line.toLowerCase().contains(string.toLowerCase())){
    									tempBuild += "\n" + child.getName();
    									count ++;
    									break;
    								}	
    							}
    							else{
    								break;
    							}
    							
    						}
    					}
    					else{
    						break;
    					}
    				}
    				if(tempBuild.equals("Text found in: ")){
    					return null;
    				}
    				else{
    					tempBuild += "\n -Text found in " + count + " documents.-";
    					return tempBuild;
    				}
    			} catch (FileNotFoundException e) {
    				error = true;
    				errors += "File read error: " + e.getMessage();
    				e.printStackTrace();
    				checkErrors();
    				return null;
    			} catch (IOException e) {
    				error = true;
    				errors += "File read error: " + e.getMessage();
    				e.printStackTrace();
    				checkErrors();
    				return null;
    			}
    		}
    	}
    	
    	/**
    	 * Writes files
    	 */
    	public void write(){
    		writer.write();
    		if (writer.hasErrors()){
    			error = true;
    			errors = writer.getErrorLog();
    		}
    		checkErrors();
    	}
    	
    	/**
    	 * Writes files according to given parameters
    	 * @param text
    	 * @param object
    	 * @param error
    	 */
    	public void write(boolean text, boolean object, boolean error){
    		errors = "";
    		error = false;
    		writer.write(text,object,error);
    		if (writer.hasErrors()){
    			error = true;
    			errors = writer.getErrorLog();
    		}
    		checkErrors();
    	}
    	
    	/**
    	 * Resets error log
    	 */
    	public void resetErrorLog(){
    		writer.resetErrorLog();
    	}
    	
    	/**
    	 * Checks node for inserts in top level or deep mode
    	 * 
    	 * @param node node to be checked
    	 * @param name name to check for
    	 * @param deepSearch deep or top level search
    	 * @return arraylist of inserts
    	 */
    	private void innerCheckInsert(Node node, String name, boolean deepSearch, ArrayList<String> insertions){
    		ArrayList<Node> innerChildren = node.getChildren();
    		if(!tempExists.contains(node)){
    			tempExists.add(node);
    			for(Node child2:innerChildren){
    					if(!insertions.contains(node.getName()) && name.equalsIgnoreCase(child2.getName())){
    						insertions.add(node.getName());
    					}
    					if(deepSearch){
    						innerCheckInsert(child2,name,deepSearch,insertions);
    					}
    			}
    		}
    	}
    	
    	/**
    	 * Checks to see if the name is inserted into any of the node's children's children
    	 * 
    	 * @param name name to check for
    	 * @param node node to use for checking
    	 * @return
    	 */
    	public ArrayList<String> checkInserted(String name, boolean deepSearch){
    		ArrayList<String>insertions = new ArrayList<String>();
    		ArrayList<Node>tempChildren = writer.getNode().getChildren();
    		tempExists.clear();
    		for(Node child:tempChildren){
    			innerCheckInsert(child,name,deepSearch,insertions);
    		}
    		if(insertions.size()>0){
    			return insertions;
    		}
    		else{
    			return null;
    		}
    	}
    
    	/**
    	 * Stops the running thread
    	 */
    	public void stopRun(){
    		if(threadRunning){
    			threadRunning = false;
    			if(runType == HotDocTreeWriterController.SCAN){
    				scraper.stopScrape();
    				writer.setNode(prevState);
    				gui.scanFinished();
    			}
    			else{
    				String tempText = "";
    				switch(runType){
    					case(1): tempText = "Text"; break;
    					case(2): tempText = "Images"; break;
    					case(3): tempText = "Variables"; break;
    				}
    				gui.searchFinished(true, tempText);
    			}
    		}
    	}
    	
    	public String getSearchResults(){
    		return searchResults;
    	}
    	
    	/**
    	 * Sets the runtype for the thread
    	 * @param runType run type for the thread
    	 * @param parameters parameters used in thread run
    	 */
    	public void setRunType(int runType, Object parameters){
    		this.runType = runType;
    		runParams = parameters;
    	}
    	
    	@Override
    	public void run() {
    		switch(runType){
    			case(0):	threadRunning = true;
    						buildTree();
    						if(threadRunning){
    							if(gui != null){
    							gui.scanFinished();
    							}
    							threadRunning = false;
    							prevState = writer.getNode();
    						}
    						break;
    			case(1):	searchResults = checkString((String)runParams); 
    						threadRunning = false;
    						String tempText1 = "";
    						switch(runType){
    							case(1): tempText1 = "Text"; break;
    							case(2): tempText1 = "Images"; break;
    							case(3): tempText1 = "Variables"; break;
    						}
    						gui.searchFinished(false, tempText1);
    						break;
    			case(2):	searchResults = checkImage();
    						threadRunning = false;
    						String tempText2 = "";
    						switch(runType){
    							case(1): tempText2 = "Text"; break;
    							case(2): tempText2 = "Images"; break;
    							case(3): tempText2 = "Variables"; break;
    						}
    						gui.searchFinished(false, tempText2);
    						break;
    			case(3):	searchResults = checkVar((String)runParams); 
    						threadRunning = false;
    						String tempText3 = "";
    						switch(runType){
    							case(1): tempText3 = "Text"; break;
    							case(2): tempText3 = "Images"; break;
    							case(3): tempText3 = "Variables"; break;
    						}
    						gui.searchFinished(false, tempText3);
    						break;
    			default:	break;
    		}
    	}
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: JDialog Not Functioning Properly

    Hello. First off, you may wish to consider refactoring this massive ginormous god class.

    Next as to your problem, ... you've got a NPE, and you'll need to dig to find out precisely which object is null, and the full stack trace can help with this. Using the stack trace and looking on the lines it indicates, have you identified the null variable yet? If not, you'll need to post your stack trace and indicate in the code above with an easily searchable comment or something similar, the lines that are indicated in the stack trace as causing your problem.

  3. #3
    StevenTNorris is offline Member
    Join Date
    Oct 2011
    Posts
    9
    Rep Power
    0

    Default Re: JDialog Not Functioning Properly

    I mentioned above, the line throwing the NPE is the searchCancel.setVisible(true), meaning the searchCancel is the null object I would assume. This is the JDialog I mentioned.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: JDialog Not Functioning Properly

    Quote Originally Posted by StevenTNorris View Post
    I mentioned above, the line throwing the NPE is the searchCancel.setVisible(true), meaning the searchCancel is the null object I would assume. This is the JDialog I mentioned.
    Yes, I saw that, but we know that the JDialog itself is not null, else a NPE would have been thrown when you tried to de-reference it in the lines above. So more must be going on, and you'll probably want to show us your stack trace and let us know which lines it references as I mentioned above... unless you can't show it to us for some reason -- perhaps it's a state secret.

  5. #5
    StevenTNorris is offline Member
    Join Date
    Oct 2011
    Posts
    9
    Rep Power
    0

    Default Re: JDialog Not Functioning Properly

    Well, I solved the stack trace issue by moving the thread creation and start below the visibility set for the JDialog. I believe the thread was finishing too quickly and somehow causing that to happen.

    Now there is another problem though. When the thread finishes and tells the GUI to stop, the modal JDialog does not change modality or visibility until I manually close it. Is there a way to change the JDialog's visibility and modality using a script run in the background? Also, the JButton is still not clickable.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: JDialog Not Functioning Properly

    A non-clickable button suggests a Swing threading issue, that the EDT may be tied up. Your current problems are more behavioral problems and not a simple NPE type problem, and so as a more complex problem will require more effort to solve. This is hindered for us by the massive amount of code involved. I suggest that you create and post an SSCCE if you still need our help. Basically simplify the problem to help solve it.

Similar Threads

  1. Creating Jar Files with functioning input files
    By appleLove in forum NetBeans
    Replies: 1
    Last Post: 04-10-2011, 11:37 PM
  2. Replies: 6
    Last Post: 12-15-2009, 03:33 AM
  3. Word Wrap not functioning correctly?
    By zerkz in forum New To Java
    Replies: 2
    Last Post: 10-08-2009, 07:41 PM
  4. Applet not functioning
    By Shadaw in forum Java Applets
    Replies: 2
    Last Post: 12-18-2008, 06:15 AM
  5. help with jdialog
    By leonard in forum AWT / Swing
    Replies: 1
    Last Post: 08-05-2007, 06:37 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •