<commit_before>package fi.csc.microarray.client.visualisation.methods.gbrowser.track;

import java.awt.Color;
import java.awt.Point;
import java.awt.geom.Point2D;
import java.util.Collection;
import java.util.LinkedList;

import fi.csc.microarray.client.visualisation.methods.gbrowser.DataSource;
import fi.csc.microarray.client.visualisation.methods.gbrowser.View;
import fi.csc.microarray.client.visualisation.methods.gbrowser.dataFetcher.AreaRequestHandler;
import fi.csc.microarray.client.visualisation.methods.gbrowser.dataFetcher.AreaResultListener;
import fi.csc.microarray.client.visualisation.methods.gbrowser.drawable.Drawable;
import fi.csc.microarray.client.visualisation.methods.gbrowser.drawable.LineDrawable;
import fi.csc.microarray.client.visualisation.methods.gbrowser.fileFormat.ColumnType;
import fi.csc.microarray.client.visualisation.methods.gbrowser.fileFormat.FileParser;
import fi.csc.microarray.client.visualisation.methods.gbrowser.fileFormat.Strand;
import fi.csc.microarray.client.visualisation.methods.gbrowser.message.AreaRequest;
import fi.csc.microarray.client.visualisation.methods.gbrowser.message.BpCoord;
import fi.csc.microarray.client.visualisation.methods.gbrowser.message.BpCoordRegion;
import fi.csc.microarray.client.visualisation.methods.gbrowser.message.Chromosome;
import fi.csc.microarray.client.visualisation.methods.gbrowser.message.FsfStatus;

public abstract class Track implements AreaResultListener {

	protected View view;
	protected DataSource file;
	protected Strand strand = Strand.FORWARD;

	public Track(View view, DataSource file) {
		this.view = view;
		this.file = file;
	}

	public Track(View view, DataSource file, Class<? extends AreaRequestHandler> handler, FileParser inputParser) {
		this(view, file);
		view.getQueueManager().createQueue(file, handler, inputParser);
	}

	/**
	 * Should be called after Track object is created, but can't be merged to constructor, because the coming areaResult event could cause
	 * call to track object before it's constructed.
	 */
	public void initializeListener() {
		if (file != null) {
			view.getQueueManager().addResultListener(file, this);
		} else {
			System.out.println("Track has no file: " + this);
		}
	}

	public abstract Collection<Drawable> getDrawables();

	protected View getView() {
		return view;
	}

	public void updateData() {
		if (file != null && this.getMaxHeight() > 0) {
			FsfStatus status = new FsfStatus();
			status.clearQueues = true;
			status.concise = isConcised();

			Collection<ColumnType> defCont = getDefaultContents();
			
			BpCoordRegion requestRegion = new BpCoordRegion(view.getBpRegion());
			requestRegion.start.bp -= 1000;
			requestRegion.end.bp += 1000;
			
			if (requestRegion.start.bp < 0) {
				requestRegion.start.bp = 0l;
			}

			view.getQueueManager().addAreaRequest(file, new AreaRequest(requestRegion, defCont, status), true);
		}
	}

	public abstract Collection<ColumnType> getDefaultContents();

	public abstract boolean isConcised();

	public Collection<Drawable> getEmptyDrawCollection() {
		return new LinkedList<Drawable>();
	}

	public int getMaxHeight() {
		return Integer.MAX_VALUE;
	}

	public void setStrand(Strand s) {
		this.strand = s;
	}

	public Strand getStrand() {
		return strand;
	}

	private Point2D[] arrowPoints = new Point2D[] { new Point.Double(0, 0.25), new Point.Double(0.5, 0.25), new Point.Double(0.5, 0), new Point.Double(1, 0.5), new Point.Double(0.5, 1), new Point.Double(0.5, 0.75), new Point.Double(0, 0.75), new Point.Double(0, 0.25) };

	protected Collection<? extends Drawable> getArrowDrawables(int x, int y, int width, int height) {

		Collection<Drawable> parts = getEmptyDrawCollection();<commit_msg>view sized AreaRequests used again<commit_after>package fi.csc.microarray.client.visualisation.methods.gbrowser.track;

import java.awt.Color;
import java.awt.Point;
import java.awt.geom.Point2D;
import java.util.Collection;
import java.util.LinkedList;

import fi.csc.microarray.client.visualisation.methods.gbrowser.DataSource;
import fi.csc.microarray.client.visualisation.methods.gbrowser.View;
import fi.csc.microarray.client.visualisation.methods.gbrowser.dataFetcher.AreaRequestHandler;
import fi.csc.microarray.client.visualisation.methods.gbrowser.dataFetcher.AreaResultListener;
import fi.csc.microarray.client.visualisation.methods.gbrowser.drawable.Drawable;
import fi.csc.microarray.client.visualisation.methods.gbrowser.drawable.LineDrawable;
import fi.csc.microarray.client.visualisation.methods.gbrowser.fileFormat.ColumnType;
import fi.csc.microarray.client.visualisation.methods.gbrowser.fileFormat.FileParser;
import fi.csc.microarray.client.visualisation.methods.gbrowser.fileFormat.Strand;
import fi.csc.microarray.client.visualisation.methods.gbrowser.message.AreaRequest;
import fi.csc.microarray.client.visualisation.methods.gbrowser.message.BpCoord;
import fi.csc.microarray.client.visualisation.methods.gbrowser.message.Chromosome;
import fi.csc.microarray.client.visualisation.methods.gbrowser.message.FsfStatus;

public abstract class Track implements AreaResultListener {

	protected View view;
	protected DataSource file;
	protected Strand strand = Strand.FORWARD;

	public Track(View view, DataSource file) {
		this.view = view;
		this.file = file;
	}

	public Track(View view, DataSource file, Class<? extends AreaRequestHandler> handler, FileParser inputParser) {
		this(view, file);
		view.getQueueManager().createQueue(file, handler, inputParser);
	}

	/**
	 * Should be called after Track object is created, but can't be merged to constructor, because the coming areaResult event could cause
	 * call to track object before it's constructed.
	 */
	public void initializeListener() {
		if (file != null) {
			view.getQueueManager().addResultListener(file, this);
		} else {
			System.out.println("Track has no file: " + this);
		}
	}

	public abstract Collection<Drawable> getDrawables();

	protected View getView() {
		return view;
	}

	public void updateData() {
		if (file != null && this.getMaxHeight() > 0) {
			FsfStatus status = new FsfStatus();
			status.clearQueues = true;
			status.concise = isConcised();

			Collection<ColumnType> defCont = getDefaultContents();

			view.getQueueManager().addAreaRequest(file, new AreaRequest(view.getBpRegion(), defCont, status), true);
		}
	}

	public abstract Collection<ColumnType> getDefaultContents();

	public abstract boolean isConcised();

	public Collection<Drawable> getEmptyDrawCollection() {
		return new LinkedList<Drawable>();
	}

	public int getMaxHeight() {
		return Integer.MAX_VALUE;
	}

	public void setStrand(Strand s) {
		this.strand = s;
	}

	public Strand getStrand() {
		return strand;
	}

	private Point2D[] arrowPoints = new Point2D[] { new Point.Double(0, 0.25), new Point.Double(0.5, 0.25), new Point.Double(0.5, 0), new Point.Double(1, 0.5), new Point.Double(0.5, 1), new Point.Double(0.5, 0.75), new Point.Double(0, 0.75), new Point.Double(0, 0.25) };

	protected Collection<? extends Drawable> getArrowDrawables(int x, int y, int width, int height) {

		Collection<Drawable> parts = getEmptyDrawCollection();
{'fraction_non_alphanumeric': 0.1147748000561246, 'fraction_numerical': 0.01122491932089238, 'mean_word_length': 5.203655352480418, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 21, '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': '538087', 'n_tokens_mistral': 2410, 'n_tokens_neox': 2194, 'n_words': 476}