<commit_before>/**
 * @author <NAME>
 * @since February 19, 2015
 * @version 0.1.0
 */

package edu.millersville.cs.bitsplease;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.EventHandler;
import javafx.event.EventTarget;
import javafx.scene.Node;
import javafx.scene.control.Toggle;
import javafx.scene.input.MouseEvent;
import edu.millersville.cs.bitsplease.model.UMLClassSymbol;
import edu.millersville.cs.bitsplease.model.UMLDocument;
import edu.millersville.cs.bitsplease.model.UMLSymbol;
import edu.millersville.cs.bitsplease.view.DocumentViewPane;
import edu.millersville.cs.bitsplease.view.EditorAction;
import edu.millersville.cs.bitsplease.view.UMLEditorPane;
import edu.millersville.cs.bitsplease.view.UMLObjectView;

public class GUIController implements ChangeListener<Toggle>, EventHandler<MouseEvent> {
	
	private UMLEditorPane editorPane;
	
	// State Variables
	private UMLSymbol selectedUMLSymbol;
	private EditorAction currentEditorAction = EditorAction.SELECT;
	private UMLDocument currentDocument;
	
	/**
	 * Default constructor for class.
	 */
	public GUIController() {
		currentDocument = new UMLDocument();
		
		editorPane = new UMLEditorPane();
		setSelectedUMLSymbol(null);
		
		editorPane.getToolBarPane().selectedToggleProperty().addListener(this);
		setCurrentEditorAction(currentEditorAction);
		
		editorPane.getDocumentViewPane().addEventHandler(MouseEvent.MOUSE_CLICKED, this);
	}

	/**
	 * @return the editorPane
	 */
	public UMLEditorPane getEditorPane() {
		return editorPane;
	}

	/**
	 * @return the selectedUMLSymbol
	 */
	public UMLSymbol getSelectedUMLSymbol() {
		return selectedUMLSymbol;
	}

	/**
	 * @param selectedUMLSymbol the selectedUMLSymbol to set
	 */
	public void setSelectedUMLSymbol(UMLSymbol selectedUMLSymbol) {
		this.selectedUMLSymbol = selectedUMLSymbol;
		editorPane.getPropertiesPane().updatePane(selectedUMLSymbol);
	}

	/**
	 * @return the currentEditorAction
	 */
	public EditorAction getCurrentEditorAction() {
		return currentEditorAction;
	}

	/**
	 * @param newEditorAction the currentEditorAction to set
	 */
	public void setCurrentEditorAction(EditorAction newEditorAction) {
		this.currentEditorAction = newEditorAction;
		editorPane.getToolBarPane().setSelectedEditorAction(newEditorAction);
	}

	@Override
	public void changed(ObservableValue<? extends Toggle> observable,
			Toggle oldValue, Toggle newValue) {
		if (newValue != null) {
			currentEditorAction = (EditorAction) newValue.getUserData();
		}
	}

	@Override
	public void handle(MouseEvent e) {
		switch (currentEditorAction) {
		case CREATE_CLASS:
			currentDocument.addClass(e.getX(),e.getY(), 100, 100);
			UMLObjectView objView = new UMLObjectView((UMLClassSymbol) currentDocument.getObjectList().get(currentDocument.getObjectList().size()-1));
			editorPane.getDocumentViewPane().addUMLSymbol(objView);;
			break;
		case SELECT:
			setSelectedUMLSymbol(resolveUMLSymbolObject((Node) e.getTarget()));
			//System.out.println(selectedUMLSymbol);
		default:
			break;
		}
	}
	
	private UMLSymbol resolveUMLSymbolObject(Node target) {
		UMLSymbol result;
		
		if (target != null) {
			if (target instanceof UMLObjectView) {
				result = ((UMLObjectView)target).getUmlClassSymbol();
			} else if (target instanceof DocumentViewPane) {
				result = null;
			} else {
				result = resolveUMLSymbolObject(target.getParent());
			}
		} else {
			result = null;
		}
		
		return result;
	}
}<commit_msg>class object deletion functioning (issue #2)<commit_after>/**
 * @author <NAME>
 * @since February 19, 2015
 * @version 0.1.0
 */

package edu.millersville.cs.bitsplease;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.EventHandler;
import javafx.event.EventTarget;
import javafx.scene.Node;
import javafx.scene.control.Toggle;
import javafx.scene.input.MouseEvent;
import edu.millersville.cs.bitsplease.model.UMLClassSymbol;
import edu.millersville.cs.bitsplease.model.UMLDocument;
import edu.millersville.cs.bitsplease.model.UMLSymbol;
import edu.millersville.cs.bitsplease.view.DocumentViewPane;
import edu.millersville.cs.bitsplease.view.EditorAction;
import edu.millersville.cs.bitsplease.view.UMLEditorPane;
import edu.millersville.cs.bitsplease.view.UMLObjectView;

public class GUIController implements ChangeListener<Toggle>, EventHandler<MouseEvent> {
	
	private UMLEditorPane editorPane;
	
	// State Variables
	private UMLSymbol selectedUMLSymbol;
	private EditorAction currentEditorAction = EditorAction.SELECT;
	private UMLDocument currentDocument;
	
	/**
	 * Default constructor for class.
	 */
	public GUIController() {
		currentDocument = new UMLDocument();
		
		editorPane = new UMLEditorPane();
		setSelectedUMLSymbol(null);
		
		editorPane.getToolBarPane().selectedToggleProperty().addListener(this);
		setCurrentEditorAction(currentEditorAction);
		
		editorPane.getDocumentViewPane().addEventHandler(MouseEvent.MOUSE_CLICKED, this);
	}

	/**
	 * @return the editorPane
	 */
	public UMLEditorPane getEditorPane() {
		return editorPane;
	}

	/**
	 * @return the selectedUMLSymbol
	 */
	public UMLSymbol getSelectedUMLSymbol() {
		return selectedUMLSymbol;
	}

	/**
	 * @param selectedUMLSymbol the selectedUMLSymbol to set
	 */
	public void setSelectedUMLSymbol(UMLSymbol selectedUMLSymbol) {
		this.selectedUMLSymbol = selectedUMLSymbol;
		editorPane.getPropertiesPane().updatePane(selectedUMLSymbol);
	}

	/**
	 * @return the currentEditorAction
	 */
	public EditorAction getCurrentEditorAction() {
		return currentEditorAction;
	}

	/**
	 * @param newEditorAction the currentEditorAction to set
	 */
	public void setCurrentEditorAction(EditorAction newEditorAction) {
		this.currentEditorAction = newEditorAction;
		editorPane.getToolBarPane().setSelectedEditorAction(newEditorAction);
	}

	@Override
	public void changed(ObservableValue<? extends Toggle> observable,
			Toggle oldValue, Toggle newValue) {
		if (newValue != null) {
			currentEditorAction = (EditorAction) newValue.getUserData();
		}
	}

	@Override
	public void handle(MouseEvent e) {
		switch (currentEditorAction) {
		case CREATE_CLASS:
			currentDocument.addClass(e.getX(),e.getY(), 100, 100);
			
			//TODO: add a method in UMLDocument to add created object
			UMLObjectView objView = new UMLObjectView((UMLClassSymbol) currentDocument.getObjectList().get(currentDocument.getObjectList().size()-1));
			editorPane.getDocumentViewPane().addUMLSymbol(objView);
			setSelectedUMLSymbol(objView.getUmlClassSymbol());
			
			break;
		case SELECT:
			setSelectedUMLSymbol(resolveUMLSymbolObject((Node) e.getTarget()));
			//System.out.println(selectedUMLSymbol);
			break;
		case DELETE:
			setSelectedUMLSymbol(null);
			UMLObjectView toDelete = resolveUMLObjectView((Node)e.getTarget());
			if (toDelete != null) {
				currentDocument.getObjects().remove(toDelete.getUmlClassSymbol());
				editorPane.getDocumentViewPane().getChildren().remove(toDelete);
				e.consume();
			}
		default:
			break;
		}
	}
	
	private UMLSymbol resolveUMLSymbolObject(Node target) {
		UMLSymbol result;
		
		if (target != null) {
			if (target instanceof UMLObjectView) {
				result = ((UMLObjectView)target).getUmlClassSymbol();
			} else if (target instanceof DocumentViewPane) {
				result = null;
			} else {
				result = resolveUMLSymbolObject(target.getParent());
			}
		} else {
			result = null;
		}
		
		return result;
	}
	
	private UMLObjectView resolveUMLObjectView(Node target) {
		UMLObjectView result;
		
		if (target != null) {
			if (target instanceof UMLObjectView) {
				result = (UMLObjectView)target;
			} else if (target instanceof DocumentViewPane) {
				result = null;
			} else {
				result = resolveUMLObjectView(target.getParent());
			}
		} else {
			result = null;
		}
		
		return result;
	}
}
{'fraction_non_alphanumeric': 0.10510204081632653, 'fraction_numerical': 0.004209183673469388, 'mean_word_length': 4.917735849056604, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3222395', 'n_tokens_mistral': 2708, 'n_tokens_neox': 2394, 'n_words': 459}