<commit_before>
/*
 *  Copyright (C) 2004  The Concord Consortium, Inc.,
 *  10 Concord Crossing, Concord, MA 01741
 *
 *  Web Site: http://www.concord.org
 *  Email: <EMAIL>
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

/*
 * Last modification information:
 * $Revision: 1.3 $
 * $Date: 2005-03-02 07:30:57 $
 * $Author: maven $
 *
 * Licence Information
 * Copyright 2004 The Concord Consortium 
*/
package org.concord.datagraph.ui;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.Point2D;

import javax.swing.event.ChangeEvent;

import org.concord.graph.engine.CoordinateSystem;
import org.concord.graph.engine.DefaultControllable;
import org.concord.graph.engine.GraphArea;
import org.concord.graph.engine.Graphable;
import org.concord.graph.examples.BoxTextLabel;


/**
 * DataPointLabel
 * Class name and description
 *
 * Date created: Mar 1, 2005
 *
 * @author imoncada<p>
 *
 */
public class DataPointLabel extends BoxTextLabel
{
	//Temporary x,y point to link
	protected Point2D dataPoint;
	
	protected Point2D displayDataPoint;
	
	private boolean dataPointChanged = true;
	
	private boolean mouseInsideDataPoint = false;
	
	protected Point2D originalDataPoint;
	
	/**
	 * 
	 */
	public DataPointLabel()
	{
		this("Message");
	}
	
	/**
	 * 
	 */
	public DataPointLabel(String msg)
	{
		super(msg);
		dataPoint = new Point2D.Double(1,1);
		
		displayDataPoint = new Point2D.Double();
		originalDataPoint = new Point2D.Double();
	}
	
	/**
	 * @see org.concord.graph.engine.Graphable#update()
	 */
	public void update()
	{
		super.update();
		if (dataPointChanged){
			CoordinateSystem cs = graphArea.getCoordinateSystem();
			displayDataPoint = cs.transformToDisplay(dataPoint);
			dataPointChanged = false;
		}
	}
	/**
	 * @see org.concord.graph.engine.Drawable#draw(java.awt.Graphics2D)
	 */
	public void draw(Graphics2D g)
	{
		if (needUpdate){
			update();
			needUpdate = false;
		}
		
		Color oldColor = g.getColor();
		Stroke oldStroke = g.getStroke();
		Shape oldClip = g.getClip();
		Font oldFont = g.getFont();
		
		graphArea.clipGraphics(g);
		
		drawDataPointLink(g);

		super.draw(g);
		
		drawDataPoint(g);
		
		g.setColor(oldColor);
		g.setStroke(oldStroke);
		g.setClip(oldClip);
		g.setFont(oldFont);
	}

	/**
	 * 
	 */
	protected void drawDataPoint(Graphics2D g)
	{
		if (isSelected()){
			if (mouseInsideDataPoint){
				g.setColor(Color.red);
			}
			else{
				g.setColor(foreColor);
			}
			g.setStroke(getStroke());
			
			g.drawLine((int)displayDataPoint.getX() - 3, (int)displayDataPoint.getY() - 3,
					(int)displayDataPoint.getX() + 3, (int)displayDataPoint.getY() + 3);
			g.drawLine((int)displayDataPoint.getX() - 3, (int)displayDataPoint.getY() + 3,
					(int)displayDataPoint.getX() + 3, (int)displayDataPoint.getY() - 3);
		}
	}

	/**
	 * @param g
	 */
	protected void drawDataPointLink(Graphics2D g)
	{
		g.setColor(foreColor);
		g.setStroke(getStroke());
		
		g.drawLine((int)displayDataPoint.getX(), (int)displayDataPoint.getY(),
				(int)(displayPositionFin.getX() + displayPositionIni.getX())/2, 
				(int)(displayPositionFin.getY() + displayPositionIni.getY())/2);
	}
	
	/**
	 * @return Returns the dataPoint.
	 */
	public Point2D getDataPoint()
	{
		return dataPoint;
	}
	
	/**
	 * @param dataPoint The dataPoint to set.
	 */
	public void setDataPoint(Point2D dataPoint)
	{
		this.dataPoint = dataPoint;
		dataPointChanged = true;
		needUpdate = true;
		notifyChange();
	}
	
	/**
	 * @see javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent)
	 */
	public void stateChanged(ChangeEvent e)
	{
		dataPointChanged = true;
		super.stateChanged(e);
	}
	
	
	/**
	 * @see org.concord.graph.engine.MouseMotionReceiver#mouseMoved(java.awt.Point)
	 */<commit_msg>Added pop-up menu to label for edit and delete<commit_after>
/*
 *  Copyright (C) 2004  The Concord Consortium, Inc.,
 *  10 Concord Crossing, Concord, MA 01741
 *
 *  Web Site: http://www.concord.org
 *  Email: <EMAIL>
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

/*
 * Last modification information:
 * $Revision: 1.4 $
 * $Date: 2005-03-03 05:59:24 $
 * $Author: imoncada $
 *
 * Licence Information
 * Copyright 2004 The Concord Consortium 
*/
package org.concord.datagraph.ui;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.Point2D;

import javax.swing.event.ChangeEvent;

import org.concord.graph.engine.CoordinateSystem;
import org.concord.graph.examples.BoxTextLabel;


/**
 * DataPointLabel
 * Class name and description
 *
 * Date created: Mar 1, 2005
 *
 * @author imoncada<p>
 *
 */
public class DataPointLabel extends BoxTextLabel
{
	//Temporary x,y point to link
	protected Point2D dataPoint;
	
	protected Point2D displayDataPoint;
	
	private boolean dataPointChanged = true;
	
	private boolean mouseInsideDataPoint = false;
	
	protected Point2D originalDataPoint;
	
	/**
	 * 
	 */
	public DataPointLabel()
	{
		this("Message");
	}
	
	public DataPointLabel(boolean newNote)
	{
		this();
		this.newNote = newNote;
	}
	
	/**
	 * 
	 */
	public DataPointLabel(String msg)
	{
		super(msg);
		dataPoint = new Point2D.Double(1,1);
		
		displayDataPoint = new Point2D.Double();
		originalDataPoint = new Point2D.Double();
	}
	
	/**
	 * @see org.concord.graph.engine.Graphable#update()
	 */
	public void update()
	{
		super.update();
		if (dataPointChanged){
			CoordinateSystem cs = graphArea.getCoordinateSystem();
			displayDataPoint = cs.transformToDisplay(dataPoint);
			dataPointChanged = false;
		}
	}
	/**
	 * @see org.concord.graph.engine.Drawable#draw(java.awt.Graphics2D)
	 */
	public void draw(Graphics2D g)
	{
		//Don't draw new notes
		if (newNote) return;
		
		if (needUpdate){
			update();
			needUpdate = false;
		}
		
		Color oldColor = g.getColor();
		Stroke oldStroke = g.getStroke();
		Shape oldClip = g.getClip();
		Font oldFont = g.getFont();
		
		graphArea.clipGraphics(g);
		
		drawDataPointLink(g);

		super.draw(g);
		
		drawDataPoint(g);
		
		g.setColor(oldColor);
		g.setStroke(oldStroke);
		g.setClip(oldClip);
		g.setFont(oldFont);
	}

	/**
	 * 
	 */
	protected void drawDataPoint(Graphics2D g)
	{
		if (isSelected()){
			if (mouseInsideDataPoint){
				g.setColor(Color.red);
			}
			else{
				g.setColor(foreColor);
			}
			g.setStroke(getStroke());
			
			g.drawLine((int)displayDataPoint.getX() - 3, (int)displayDataPoint.getY() - 3,
					(int)displayDataPoint.getX() + 3, (int)displayDataPoint.getY() + 3);
			g.drawLine((int)displayDataPoint.getX() - 3, (int)displayDataPoint.getY() + 3,
					(int)displayDataPoint.getX() + 3, (int)displayDataPoint.getY() - 3);
		}
		else{
			g.setColor(foreColor);

			g.setStroke(getStroke());
			
			g.fillOval((int)(displayDataPoint.getX() - 3.5), (int)(displayDataPoint.getY() - 3.5),
					7, 7);
		}
	}

	/**
	 * @param g
	 */
	protected void drawDataPointLink(Graphics2D g)
	{
		g.setColor(foreColor);
		g.setStroke(getStroke());
		
		g.drawLine((int)displayDataPoint.getX(), (int)displayDataPoint.getY(),
				(int)(displayPositionFin.getX() + displayPositionIni.getX())/2, 
				(int)(displayPositionFin.getY() + displayPositionIni.getY())/2);
	}
	
	/**
	 * @return Returns the dataPoint.
	 */
	public Point2D getDataPoint()
	{
		return dataPoint;
	}
	
	/**
	 * @param dataPoint The dataPoint to set.
	 */
	public void setDataPoint(Point2D dataPoint)
	{
		this.dataPoint = dataPoint;
		dataPointChanged = true;
		needUpdate = true;
		notifyChange();
	}
	
	/**
	 * @param p
	 */
	protected void addAtPoint(Point p)
	{
		CoordinateSystem cs = graphArea.getCoordinateSystem();
		setDataPoint(cs.transformToWorld(p));
		Point2D dataDisplay = cs.transformToDisplay(dataPoint);
		Point2D locDisplay = new Point2D.Double(
				dataDisplay.getX() + 20, dataDisplay.getY() - 40);
		setLocation(cs.transformToWorld(locDisplay));
	}
	
	/**
	 * @see javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent)
	 */
	public void stateChanged(ChangeEvent e)
	{
		dataPointChanged = true;
		super.stateChanged(e);
	}
	
	
	/**
	 * @see org.concord.graph.engine.MouseMotionReceiver#mouseMoved(java.awt.Point)
	 */
{'fraction_non_alphanumeric': 0.1271186440677966, 'fraction_numerical': 0.01746589499793303, 'mean_word_length': 3.663614457831325, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3219248', 'n_tokens_mistral': 3691, 'n_tokens_neox': 3231, 'n_words': 766}