<commit_before>// PathVisio,
// a tool for data visualization and analysis using Biological Pathways
// Copyright 2006-2007 BiGCaT Bioinformatics
//
// Licensed under the Apache License, Version 2.0 (the "License"); 
// you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at 
// 
// http://www.apache.org/licenses/LICENSE-2.0 
//  
// Unless required by applicable law or agreed to in writing, software 
// distributed under the License is distributed on an "AS IS" BASIS, 
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
// See the License for the specific language governing permissions and 
// limitations under the License.
//
package graphics;

import java.awt.BasicStroke;
import java.awt.Shape;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;

import util.SwtUtils;
import data.GmmlDataObject;
import data.GmmlEvent;
import data.LineStyle;
import data.LineType;
 
/**
 * This class implements and handles a line
 */
public class GmmlLine extends GmmlGraphics
{
	private GmmlHandle handleStart;
	private GmmlHandle handleEnd;
	public GmmlHandle getHandleEnd() { return handleEnd; }
	private static final long serialVersionUID = 1L;
	
	/**
	 * Constructor for this class
	 * @param canvas - the GmmlDrawing this line will be part of
	 */
	public GmmlLine(GmmlDrawing canvas, GmmlDataObject o)
	{
		super(canvas, o);
		drawingOrder = GmmlDrawing.DRAW_ORDER_LINE;
		handleStart	= new GmmlHandle(GmmlHandle.DIRECTION_FREE, this, canvas);
		handleEnd	= new GmmlHandle(GmmlHandle.DIRECTION_FREE, this, canvas);
		setHandleLocation();
	}
		
	public void draw(PaintEvent e, GC buffer)
	{
		double endx = gdata.getEndX();
		double endy = gdata.getEndY();
		double startx = gdata.getStartX();
		double starty = gdata.getStartY();

		Color c = null;
		if (isSelected())
		{
			c = SwtUtils.changeColor(c, selectColor, e.display);
		}
		else 
		{
			c = SwtUtils.changeColor(c, gdata.getColor(), e.display);
		}
		buffer.setForeground (c);
		buffer.setBackground (c);
		
		buffer.setLineWidth (1);
		int ls = gdata.getLineStyle();
		if (ls == LineStyle.SOLID)
		{
			buffer.setLineStyle (SWT.LINE_SOLID);
		}
		else if (ls == LineStyle.DASHED)
		{ 
			buffer.setLineStyle (SWT.LINE_DASH);
		}			

		double s = Math.sqrt(((endx-startx)*(endx-startx)) + ((endy - starty)*(endy - starty)));
		
		switch (gdata.getLineType())
		{
		
			case LineType.LINE:
				buffer.drawLine ((int)startx, (int)starty, (int)endx, (int)endy);
				break;
			case LineType.ARROW:				
				buffer.drawLine ((int)startx, (int)starty, (int)endx, (int)endy);
				drawArrowhead(buffer);
				break;
			case LineType.TBAR:
			{
				s /= 8;
	
				double capx1 = ((-endy + starty)/s) + endx;
				double capy1 = (( endx - startx)/s) + endy;
				double capx2 = (( endy - starty)/s) + endx;
				double capy2 = ((-endx + startx)/s) + endy;
	<commit_msg>Fixed bug #67: line dash<commit_after>// PathVisio,
// a tool for data visualization and analysis using Biological Pathways
// Copyright 2006-2007 BiGCaT Bioinformatics
//
// Licensed under the Apache License, Version 2.0 (the "License"); 
// you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at 
// 
// http://www.apache.org/licenses/LICENSE-2.0 
//  
// Unless required by applicable law or agreed to in writing, software 
// distributed under the License is distributed on an "AS IS" BASIS, 
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
// See the License for the specific language governing permissions and 
// limitations under the License.
//
package graphics;

import java.awt.BasicStroke;
import java.awt.Shape;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;

import util.SwtUtils;
import data.GmmlDataObject;
import data.GmmlEvent;
import data.LineStyle;
import data.LineType;
 
/**
 * This class implements and handles a line
 */
public class GmmlLine extends GmmlGraphics
{
	private GmmlHandle handleStart;
	private GmmlHandle handleEnd;
	public GmmlHandle getHandleEnd() { return handleEnd; }
	private static final long serialVersionUID = 1L;
	
	/**
	 * Constructor for this class
	 * @param canvas - the GmmlDrawing this line will be part of
	 */
	public GmmlLine(GmmlDrawing canvas, GmmlDataObject o)
	{
		super(canvas, o);
		drawingOrder = GmmlDrawing.DRAW_ORDER_LINE;
		handleStart	= new GmmlHandle(GmmlHandle.DIRECTION_FREE, this, canvas);
		handleEnd	= new GmmlHandle(GmmlHandle.DIRECTION_FREE, this, canvas);
		setHandleLocation();
	}
		
	public void draw(PaintEvent e, GC buffer)
	{
		double endx = gdata.getEndX();
		double endy = gdata.getEndY();
		double startx = gdata.getStartX();
		double starty = gdata.getStartY();

		Color c = null;
		if (isSelected())
		{
			c = SwtUtils.changeColor(c, selectColor, e.display);
		}
		else 
		{
			c = SwtUtils.changeColor(c, gdata.getColor(), e.display);
		}
		buffer.setForeground (c);
		buffer.setBackground (c);
		
		buffer.setLineWidth (1);
		int ls = gdata.getLineStyle();
		if (ls == LineStyle.SOLID)
		{
			buffer.setLineStyle (SWT.LINE_SOLID);
		}
		else if (ls == LineStyle.DASHED)
		{ 
			// TODO: This works well on windows. I wonder if this is the same on all platforms
			buffer.setLineDash (new int[] {4, 4});
		}			

		double s = Math.sqrt(((endx-startx)*(endx-startx)) + ((endy - starty)*(endy - starty)));
		
		switch (gdata.getLineType())
		{
		
			case LineType.LINE:
				buffer.drawLine ((int)startx, (int)starty, (int)endx, (int)endy);
				break;
			case LineType.ARROW:				
				buffer.drawLine ((int)startx, (int)starty, (int)endx, (int)endy);
				drawArrowhead(buffer);
				break;
			case LineType.TBAR:
			{
				s /= 8;
	
				double capx1 = ((-endy + starty)/s) + endx;
				double capy1 = (( endx - startx)/s) + endy;
				double capx2 = (( endy - starty)/s) + endx;
				double capy2 = ((-endx + startx)/s) + endy;
	
{'fraction_non_alphanumeric': 0.11954245207024328, 'fraction_numerical': 0.007410987594651201, 'mean_word_length': 3.5714285714285716, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4099695', 'n_tokens_mistral': 2367, 'n_tokens_neox': 2119, 'n_words': 595}