<commit_before>/*
 * Copyright (C) 2005 - 2014 by TESIS DYNAware GmbH
 */
package de.tesis.dynaware.grapheditor.window;

import java.util.HashMap;
import java.util.Map;

import de.tesis.dynaware.grapheditor.SelectionManager;
import de.tesis.dynaware.grapheditor.model.GModel;
import de.tesis.dynaware.grapheditor.model.GNode;
import javafx.beans.InvalidationListener;
import javafx.beans.WeakInvalidationListener;
import javafx.css.PseudoClass;
import javafx.scene.shape.Rectangle;

/**
 * The minimap representation of all nodes in the graph editor.
 *
 * <p>
 * This is responsible for drawing mini versions of all nodes in a
 * {@link GModel}. This group of mini-nodes is then displayed inside the
 * {@link GraphEditorMinimap}.
 * </p>
 */
public class MinimapNodeGroup extends MinimapContentRepresentation {

	private static final String STYLE_CLASS = "minimap-node";
    private static final PseudoClass PSEUDO_CLASS_SELECTED = PseudoClass.getPseudoClass("selected");
	
    private final InvalidationListener checkSelectionListener = obs -> checkSelection();
    private final InvalidationListener checkSelectionWeakListener = new WeakInvalidationListener(checkSelectionListener);
    
    private SelectionManager selectionManager;
    
	private final Map<GNode, Rectangle> nodes = new HashMap<>();
    private GModel model;

    /**
     * Sets the selection manager instance currently in use by this graph editor.
     *
     * <p>
     * This will be used to show what nodes are currently selected.
     * <p>
     *
     * @param selectionManager a {@link SelectionManager} instance
     */
    public void setSelectionManager(final SelectionManager selectionManager) {
    	
    	if(this.selectionManager != null) {
    		this.selectionManager.getSelectedNodes().removeListener(checkSelectionWeakListener);
    	}
    	
        this.selectionManager = selectionManager;
        
        if(this.selectionManager != null) {
    		this.selectionManager.getSelectedNodes().addListener(checkSelectionWeakListener);
    	}
        checkSelection();
    }

    /**
     * Sets the model whose nodes will be drawn in the minimap.
     *
     * @param model athe {@link GModel} whose nodes are to be drawn
     */
    public void setModel(final GModel model) {
        this.model = model;
    }
    
	private void checkSelection() {

		for (final Rectangle rectangle : nodes.values()) {
			rectangle.pseudoClassStateChanged(PSEUDO_CLASS_SELECTED, false);
		}

		if (selectionManager != null) {
			for (final GNode selection : selectionManager.getSelectedNodes()) {
				nodes.get(selection).pseudoClassStateChanged(PSEUDO_CLASS_SELECTED, true);
			}
		}
	}

    /**
     * Draws the model's nodes at a scaled-down size to be displayed in the minimap.
     *
     * @param scaleFactor the ratio between the size of the content and the size of the minimap (between 0 and 1)
     */
    @Override
    public void draw(final double scaleFactor) {

        getChildren().clear();
        <commit_msg>tabs to spaces.<commit_after>/*
 * Copyright (C) 2005 - 2014 by TESIS DYNAware GmbH
 */
package de.tesis.dynaware.grapheditor.window;

import java.util.HashMap;
import java.util.Map;

import de.tesis.dynaware.grapheditor.SelectionManager;
import de.tesis.dynaware.grapheditor.model.GModel;
import de.tesis.dynaware.grapheditor.model.GNode;
import javafx.beans.InvalidationListener;
import javafx.beans.WeakInvalidationListener;
import javafx.css.PseudoClass;
import javafx.scene.shape.Rectangle;

/**
 * The minimap representation of all nodes in the graph editor.
 *
 * <p>
 * This is responsible for drawing mini versions of all nodes in a
 * {@link GModel}. This group of mini-nodes is then displayed inside the
 * {@link GraphEditorMinimap}.
 * </p>
 */
public class MinimapNodeGroup extends MinimapContentRepresentation {

    private static final String STYLE_CLASS = "minimap-node";
    private static final PseudoClass PSEUDO_CLASS_SELECTED = PseudoClass.getPseudoClass("selected");

    private final InvalidationListener checkSelectionListener = obs -> checkSelection();
    private final InvalidationListener checkSelectionWeakListener = new WeakInvalidationListener(checkSelectionListener);

    private SelectionManager selectionManager;

    private final Map<GNode, Rectangle> nodes = new HashMap<>();
    private GModel model;

    /**
     * Sets the selection manager instance currently in use by this graph
     * editor.
     *
     * <p>
     * This will be used to show what nodes are currently selected.
     * <p>
     *
     * @param selectionManager
     *            a {@link SelectionManager} instance
     */
    public void setSelectionManager(final SelectionManager selectionManager) {
    	
    	if(this.selectionManager != null) {
    		this.selectionManager.getSelectedNodes().removeListener(checkSelectionWeakListener);
    	}
    	
        this.selectionManager = selectionManager;
        
        if(this.selectionManager != null) {
    		this.selectionManager.getSelectedNodes().addListener(checkSelectionWeakListener);
    	}
        checkSelection();
    }

    /**
     * Sets the model whose nodes will be drawn in the minimap.
     *
     * @param model athe {@link GModel} whose nodes are to be drawn
     */
    public void setModel(final GModel model) {
        this.model = model;
    }
    
    private void checkSelection() {

        for (final Rectangle rectangle : nodes.values()) {
            rectangle.pseudoClassStateChanged(PSEUDO_CLASS_SELECTED, false);
        }

        if (selectionManager != null) {
            for (final GNode selection : selectionManager.getSelectedNodes()) {
                nodes.get(selection).pseudoClassStateChanged(PSEUDO_CLASS_SELECTED, true);
            }
        }
    }

    /**
     * Draws the model's nodes at a scaled-down size to be displayed in the minimap.
     *
     * @param scaleFactor the ratio between the size of the content and the size of the minimap (between 0 and 1)
     */
    @Override
    public void draw(final double scaleFactor) {

        getChildren().clear();
        
{'fraction_non_alphanumeric': 0.08523567088191822, 'fraction_numerical': 0.003284611594678929, 'mean_word_length': 3.2498255408234473, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, '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': '7592361', 'n_tokens_mistral': 1738, 'n_tokens_neox': 1661, 'n_words': 488}