<commit_before>package edu.berkeley.guir.prefusex.controls;

import java.awt.event.MouseEvent;
import java.util.Iterator;

import edu.berkeley.guir.prefuse.EdgeItem;
import edu.berkeley.guir.prefuse.VisualItem;
import edu.berkeley.guir.prefuse.ItemRegistry;
import edu.berkeley.guir.prefuse.NodeItem;
import edu.berkeley.guir.prefuse.activity.Activity;
import edu.berkeley.guir.prefuse.event.ControlAdapter;

/**
 * <p>
 * A ControlListener that sets the highlighted status (using the
 * {@link edu.berkeley.guir.prefuse.VisualItem#setHighlighted(boolean)
 * VisualItem.setHighlighted} method) for nodes neighboring the node 
 * currently under the mouse pointer. The highlight flag can then be used
 * by a color function to change node appearance as desired.
 * </p>
 *
 * @version 1.0
 * @author <a href="http://jheer.org"><NAME></a> prefuse(AT)jheer.org
 */
public class NeighborHighlightControl extends ControlAdapter {

    private Activity update = null;
    
    /**
     * Creates a new highlight control.
     */
    public NeighborHighlightControl() {
        this(null);
    } //
    
    /**
     * Creates a new highlight control that runs the given activity
     * whenever the neighbor highlight changes.
     * @param update the update Activity to run
     */
    public NeighborHighlightControl(Activity update) {
        this.update = update;
    } //
    
    public void itemEntered(VisualItem item, MouseEvent e) {
        if ( item instanceof NodeItem )
            setNeighborHighlight((NodeItem)item, true);
    } //
    
    public void itemExited(VisualItem item, MouseEvent e) {
        if ( item instanceof NodeItem )
            setNeighborHighlight((NodeItem)item, false);
    } //
    
    public void itemReleased(VisualItem item, MouseEvent e) {
        if ( item instanceof NodeItem )
            setNeighborHighlight((NodeItem)item, false);
    } //
    
    public void setNeighborHighlight(NodeItem n, boolean state) {
        ItemRegistry registry = n.getItemRegistry();
        synchronized ( registry ) {
            Iterator iter = n.getEdges();
            while ( iter.hasNext() ) {
                EdgeItem eitem = (EdgeItem)iter.next();
                NodeItem nitem = (NodeItem)eitem.getAdjacentNode(n);
                eitem.setHighlighted(state);
                nitem.setHighlighted(state);
                registry.touch(nitem.getItemClass());
                registry.touch(eitem.getItemClass());
            }
        }
        if ( update != null )
            update.runNow();
    } //
    
} // end of class NeighborHighlightControl<commit_msg>Added parameter for highlighting with invisible edges<commit_after>package edu.berkeley.guir.prefusex.controls;

import java.awt.event.MouseEvent;
import java.util.Iterator;

import edu.berkeley.guir.prefuse.EdgeItem;
import edu.berkeley.guir.prefuse.VisualItem;
import edu.berkeley.guir.prefuse.ItemRegistry;
import edu.berkeley.guir.prefuse.NodeItem;
import edu.berkeley.guir.prefuse.activity.Activity;
import edu.berkeley.guir.prefuse.event.ControlAdapter;

/**
 * <p>
 * A ControlListener that sets the highlighted status (using the
 * {@link edu.berkeley.guir.prefuse.VisualItem#setHighlighted(boolean)
 * VisualItem.setHighlighted} method) for nodes neighboring the node 
 * currently under the mouse pointer. The highlight flag can then be used
 * by a color function to change node appearance as desired.
 * </p>
 *
 * @version 1.0
 * @author <a href="http://jheer.org"><NAME></a> prefuse(AT)jheer.org
 */
public class NeighborHighlightControl extends ControlAdapter {

    private Activity update = null;
    private boolean highlightWithInvisibleEdge = false;
    
    /**
     * Creates a new highlight control.
     */
    public NeighborHighlightControl() {
        this(null);
    } //
    
    /**
     * Creates a new highlight control that runs the given activity
     * whenever the neighbor highlight changes.
     * @param update the update Activity to run
     */
    public NeighborHighlightControl(Activity update) {
        this.update = update;
    } //
    
    public void itemEntered(VisualItem item, MouseEvent e) {
        if ( item instanceof NodeItem )
            setNeighborHighlight((NodeItem)item, true);
    } //
    
    public void itemExited(VisualItem item, MouseEvent e) {
        if ( item instanceof NodeItem )
            setNeighborHighlight((NodeItem)item, false);
    } //
    
    public void itemReleased(VisualItem item, MouseEvent e) {
        if ( item instanceof NodeItem )
            setNeighborHighlight((NodeItem)item, false);
    } //
    
    public void setNeighborHighlight(NodeItem n, boolean state) {
        ItemRegistry registry = n.getItemRegistry();
        synchronized ( registry ) {
            Iterator iter = n.getEdges();
            while ( iter.hasNext() ) {
                EdgeItem eitem = (EdgeItem)iter.next();
                NodeItem nitem = (NodeItem)eitem.getAdjacentNode(n);
                if (eitem.isVisible() || highlightWithInvisibleEdge) {
                    eitem.setHighlighted(state);
                    registry.touch(eitem.getItemClass());
                    nitem.setHighlighted(state);
                    registry.touch(nitem.getItemClass());
                }
            }
        }
        if ( update != null )
            update.runNow();
    } //
    
    /**
     * Indicates if neighbor nodes with edges currently not visible still
     * get highlighted.
     * @return true if neighbors with invisible edges still get highlighted,
     * false otherwise.
     */
    public boolean isHighlightWithInvisibleEdge() {
        return highlightWithInvisibleEdge;
    } //
   
    /**
     * Determines if neighbor nodes with edges currently not visible still
     * get highlighted.
     * @param highlightWithInvisibleEdge assign true if neighbors with invisible
     * edges should still get highlighted, false otherwise.
     */
    public void setHighlightWithInvisibleEdge(boolean highlightWithInvisibleEdge) {
        this.highlightWithInvisibleEdge = highlightWithInvisibleEdge;
    } //
    
} // end of class NeighborHighlightControl
{'fraction_non_alphanumeric': 0.09317073170731707, 'fraction_numerical': 0.0006504065040650406, 'mean_word_length': 2.6097417840375585, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '1893209', 'n_tokens_mistral': 1708, 'n_tokens_neox': 1662, 'n_words': 434}