<commit_before>package org.aksw.limes.core.gui.view.graphBuilder;

import java.util.ArrayList;
import java.util.Collections;

import org.aksw.limes.core.gui.controller.GraphBuildController;
import org.aksw.limes.core.gui.model.Config;
import org.aksw.limes.core.gui.model.metric.Node;
import org.aksw.limes.core.gui.model.metric.Output;
import org.aksw.limes.core.gui.view.ToolBox;

import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;

/**
 * Class to graphically represent link specifications as linked {@link org.aksw.limes.core.gui.view.graphBuilder.NodeView}
 * @author <NAME> {@literal <} soz11ffe{@literal @}
 *         studserv.uni-leipzig.de{@literal >}
 *
 */
public class GraphBuildView extends Canvas {

    /**
     * Corresponding GraphBuildController
     */
    public GraphBuildController graphBuildController;

    /**
     * List of nodes in the Canvas
     */
    public ArrayList<NodeView> nodeList;

    /**
     * Reversed List of nodes in Canvas to correctly display dragging
     */
    public ArrayList<NodeView> reversedNodeList;
    /**
     * True if Linking Process is running
     */
    public boolean isLinking;
    /**
     * Node to Link in linking Process
     */
    public NodeView linkNode;
    /**
     * Boolean to check if Graph was edited
     */
    public boolean edited = false;
    /**
     * Boolean to check if another ContextMenu is open
     */
    public boolean contextMenuIsShown = false;
    /**
     * True if Node was clicked
     */
    private boolean nodeClicked;
    /**
     * Index of clicked Node
     */
    private NodeView clickedNode;
    /**
     * Context Menu to show on secondary MouseClick
     */
    private NodeContextMenu contextMenu;
    /**
     * Mouseposition on Canvas
     */
    private double[] mousePosition = {0, 0};

    /**
     * Constructor initializes nodeList and adds a new output node.
     * Creates the corresponding controller with config
     *
     * @param currentConfig
     *         Current used Configmodel
     *	@param toolbox toolbox of the main view
     */
    public GraphBuildView(Config currentConfig, ToolBox toolbox) {
        widthProperty().addListener(evt -> draw());
        heightProperty().addListener(evt -> draw());
        this.nodeList = new ArrayList<NodeView>();
        this.reversedNodeList = (ArrayList<NodeView>) nodeList.clone();
        Collections.reverse(reversedNodeList);
        this.nodeClicked = false;
        this.isLinking = false;
        addNode(300, 300, 2, new Output());
        this.graphBuildController = new GraphBuildController(currentConfig,
                this, toolbox);
    }

    /**
     * Constructor initializes nodeList and adds a new output node.
     * Creates the corresponding controller with config
     * @param toolbox toolbox of the main view
     */
    public GraphBuildView(ToolBox toolbox) {
        widthProperty().addListener(evt -> draw());
        heightProperty().addListener(evt -> draw());
        this.nodeList = new ArrayList<NodeView>();
        this.reversedNodeList = (ArrayList<NodeView>) nodeList.clone();
        Collections.reverse(reversedNodeList);
        this.nodeClicked = false;
        this.isLinking = false;
        addNode(300, 300, 2, new Output());
        this.graphBuildController = new GraphBuildController(this, toolbox);
    }

    /**
     * Set Resizablity to true,overwrite default Canvas Property
     */
    @Override
    public boolean isResizable() {
        return true;
    }

    @Override
    /**
     * Set Width of Canvas
     * @param height height
     */
    public double prefWidth(double width) {
        return getWidth();
    }

    /**
     * Set Height of Canvas
     *
     * @param height height
     */
    @Override
    public double prefHeight(double height) {
        return getHeight();
    }

    /**
     * Set Current Config model
     *
     * @param config
     *         Currently used Config
     */
    public void setCurrentConfig(Config config) {
        this.graphBuildController.setConfig(config);
    }

    /**
     * Add eventlisteners Begin drawing
     */
    public void start() {
        this.addEventHandler(
                MouseEvent.MOUSE_CLICKED,
                e -> {
//					for (NodeView node : this.nodeList) {
//					}
                    if (isLinking) {
                        for (NodeView node : nodeList) {
                            if (node.contains((int) e.getX(), (int) e.getY())) {
                                isLinking = false;
                                if (linkNode.addParent(node)) {
                                } else {
                                    Alert alert = new Alert(
                                            AlertType.INFORMATION);
                                    alert.setContentText("Clicked Node is no valid Parent!");
                                    alert.showAndWait();
                                }
                                edited = true;
                                draw();
                                break;
                            }
                        }
                    }
                });
        this.addEventHandler(MouseEvent.MOUSE_PRESSED, e -> {
            if (e.getButton().equals(MouseButton.PRIMARY)) {
                if (e.getClickCount() == 2) {
                    int index = 0;
                    // boolean clickedOutput = false;
                    for (NodeView node : nodeList) {
                        if (node.contains((int) e.getX(), (int) e.getY())) {
                            clickedNode = nodeList.get(index);
                            break;
                        }
                        index++;
                    }
                    if (clickedNode.nodeShape == NodeView.OPERATOR
                            || clickedNode.nodeShape == NodeView.OUTPUT) {<commit_msg>Implemented closing of NodeContextMenu when clicking anywhere<commit_after>package org.aksw.limes.core.gui.view.graphBuilder;

import java.util.ArrayList;
import java.util.Collections;

import org.aksw.limes.core.gui.controller.GraphBuildController;
import org.aksw.limes.core.gui.model.Config;
import org.aksw.limes.core.gui.model.metric.Node;
import org.aksw.limes.core.gui.model.metric.Output;
import org.aksw.limes.core.gui.view.ToolBox;

import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;

/**
 * Class to graphically represent link specifications as linked {@link org.aksw.limes.core.gui.view.graphBuilder.NodeView}
 * @author <NAME> {@literal <} soz11ffe{@literal @}
 *         studserv.uni-leipzig.de{@literal >}
 *
 */
public class GraphBuildView extends Canvas {

    /**
     * Corresponding GraphBuildController
     */
    public GraphBuildController graphBuildController;

    /**
     * List of nodes in the Canvas
     */
    public ArrayList<NodeView> nodeList;

    /**
     * Reversed List of nodes in Canvas to correctly display dragging
     */
    public ArrayList<NodeView> reversedNodeList;
    /**
     * True if Linking Process is running
     */
    public boolean isLinking;
    /**
     * Node to Link in linking Process
     */
    public NodeView linkNode;
    /**
     * Boolean to check if Graph was edited
     */
    public boolean edited = false;
    /**
     * Boolean to check if another ContextMenu is open
     */
    public boolean contextMenuIsShown = false;
    /**
     * True if Node was clicked
     */
    private boolean nodeClicked;
    /**
     * Index of clicked Node
     */
    private NodeView clickedNode;
    /**
     * Context Menu to show on secondary MouseClick
     */
    private NodeContextMenu contextMenu;
    /**
     * Mouseposition on Canvas
     */
    private double[] mousePosition = {0, 0};

    /**
     * Constructor initializes nodeList and adds a new output node.
     * Creates the corresponding controller with config
     *
     * @param currentConfig
     *         Current used Configmodel
     *	@param toolbox toolbox of the main view
     */
    public GraphBuildView(Config currentConfig, ToolBox toolbox) {
        widthProperty().addListener(evt -> draw());
        heightProperty().addListener(evt -> draw());
        this.nodeList = new ArrayList<NodeView>();
        this.reversedNodeList = (ArrayList<NodeView>) nodeList.clone();
        Collections.reverse(reversedNodeList);
        this.nodeClicked = false;
        this.isLinking = false;
        addNode(300, 300, 2, new Output());
        this.graphBuildController = new GraphBuildController(currentConfig,
                this, toolbox);
    }

    /**
     * Constructor initializes nodeList and adds a new output node.
     * Creates the corresponding controller with config
     * @param toolbox toolbox of the main view
     */
    public GraphBuildView(ToolBox toolbox) {
        widthProperty().addListener(evt -> draw());
        heightProperty().addListener(evt -> draw());
        this.nodeList = new ArrayList<NodeView>();
        this.reversedNodeList = (ArrayList<NodeView>) nodeList.clone();
        Collections.reverse(reversedNodeList);
        this.nodeClicked = false;
        this.isLinking = false;
        addNode(300, 300, 2, new Output());
        this.graphBuildController = new GraphBuildController(this, toolbox);
    }

    /**
     * Set Resizablity to true,overwrite default Canvas Property
     */
    @Override
    public boolean isResizable() {
        return true;
    }

    @Override
    /**
     * Set Width of Canvas
     * @param height height
     */
    public double prefWidth(double width) {
        return getWidth();
    }

    /**
     * Set Height of Canvas
     *
     * @param height height
     */
    @Override
    public double prefHeight(double height) {
        return getHeight();
    }

    /**
     * Set Current Config model
     *
     * @param config
     *         Currently used Config
     */
    public void setCurrentConfig(Config config) {
        this.graphBuildController.setConfig(config);
    }

    /**
     * Add eventlisteners Begin drawing
     */
    public void start() {
        this.addEventHandler(
                MouseEvent.MOUSE_CLICKED,
                e -> {
                    if (isLinking) {
                        for (NodeView node : nodeList) {
                            if (node.contains((int) e.getX(), (int) e.getY())) {
                                isLinking = false;
                                if (linkNode.addParent(node)) {
                                } else {
                                    Alert alert = new Alert(
                                            AlertType.INFORMATION);
                                    alert.setContentText("Clicked Node is no valid Parent!");
                                    alert.showAndWait();
                                }
                                edited = true;
                                draw();
                                break;
                            }
                        }
                    }
                });
        this.addEventHandler(MouseEvent.MOUSE_PRESSED, e -> {
            if(contextMenuIsShown){
        	contextMenu.hide();
        	contextMenuIsShown = false;
            }
            if (e.getButton().equals(MouseButton.PRIMARY)) {
                if (e.getClickCount() == 2) {
                    int index = 0;
                    // boolean clickedOutput = false;
                    for (NodeView node : nodeList) {
                        if (node.contains((int) e.getX(), (int) e.getY())) {
                            clickedNode = nodeList.get(index);
                            break;
                        }
                        index++;
                    }
                    if (clickedNode.nodeShape == NodeView.OPERATOR
                            || clickedNode.nodeShape == NodeView.OUTPUT) {
{'fraction_non_alphanumeric': 0.09671084928816888, 'fraction_numerical': 0.003272786777941417, 'mean_word_length': 1.7126054150022192, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '423407', 'n_tokens_mistral': 3263, 'n_tokens_neox': 3132, 'n_words': 780}