<commit_before>package fr.vergne.taskmanager.gui.gantt;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Calendar;
import java.util.Date;

import javax.swing.AbstractAction;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.SpringLayout;

import fr.vergne.taskmanager.gui.gantt.TimeBar.UnitDescriptor;
import fr.vergne.taskmanager.task.Task;
import fr.vergne.taskmanager.task.TaskList;

// FIXME paint the cursor after the time slots of the time bars
@SuppressWarnings("serial")
public class Gantt extends JPanel {

	private final TimeBar highTimeBar = new TimeBar();
	private final TimeBar lowTimeBar = new TimeBar() {
		public void paint(Graphics arg0) {
			super.paint(arg0);

			UnitDescriptor ref = lowTimeBar.getCurrentDescriptor();
			long refValue = ref.getUnitMultiplicator() * ref.getUnitStep();
			for (UnitDescriptor desc : highTimeBar.getDescriptors()) {
				long descValue = desc.getUnitMultiplicator()
						* desc.getUnitStep();
				if (descValue >= 3 * refValue) {
					highTimeBar.setForcedDescriptor(desc);
					break;
				}
			}
		};
	};
	private final PeriodCanvas periodCanvas = new PeriodCanvas();
	private final JScrollPane periodPane = new JScrollPane(periodCanvas);
	private final JPanel timeCursor = new JPanel();
	private final SpringLayout layout = new SpringLayout();
	private long median = new Date().getTime();
	private long radius = 1800000;
	private final Thread cursorThread;

	public Gantt() {
		initComponents();

		addKeyListener(new KeyListener() {

			@Override
			public void keyTyped(KeyEvent arg0) {
				// do nothing
			}

			@Override
			public void keyReleased(KeyEvent event) {
				if (event.getKeyCode() == KeyEvent.VK_PAGE_UP) {
					zoom(0.8);
				} else if (event.getKeyCode() == KeyEvent.VK_PAGE_DOWN) {
					zoom(1.0 / 0.8);
				} else if (event.getKeyCode() == KeyEvent.VK_F5) {
					resetDisplay();
				} else if (event.getKeyCode() == KeyEvent.VK_LEFT) {
					goTo(new Date((long) (median - radius * 0.1)));
				} else if (event.getKeyCode() == KeyEvent.VK_RIGHT) {
					goTo(new Date((long) (median + radius * 0.1)));
				} else {
					// do nothing
				}
			}

			@Override
			public void keyPressed(KeyEvent arg0) {
				// do nothing
			}
		});

		cursorThread = new Thread(new Runnable() {

			@Override
			public void run() {
				while (true) {
					try {
						Thread.sleep(Math.min(Math.max(radius / 1000, 100),
								1000));
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					updateCursor();
					validate();
				}
			}
		});
		cursorThread.start();
	}

	public void resetDisplay() {
		periodCanvas.setMinDate(periodCanvas.getActualMinDate());
		periodCanvas.setMaxDate(periodCanvas.getActualMaxDate());
		long min = periodCanvas.getMinDate().getTime();
		long max = periodCanvas.getMaxDate().getTime();
		median = (max + min) / 2;
		radius = median - min;
		repaint();
	}

	private void initComponents() {
		initTimeBars();

		add(lowTimeBar);
		add(highTimeBar);
		add(periodPane);
		periodPane
				.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		add(timeCursor);
		timeCursor.setBackground(Color.GREEN);

		setLayout(layout);
		layout.putConstraint(SpringLayout.NORTH, highTimeBar, 0,
				SpringLayout.NORTH, this);
		layout.putConstraint(SpringLayout.WEST, highTimeBar, 0,
				SpringLayout.WEST, this);
		layout.putConstraint(SpringLayout.EAST, highTimeBar, 0,
				SpringLayout.EAST, this);

		layout.putConstraint(SpringLayout.NORTH, lowTimeBar, 0,
				SpringLayout.SOUTH, highTimeBar);
		layout.putConstraint(SpringLayout.WEST, lowTimeBar, 0,
				SpringLayout.WEST, this);
		layout.putConstraint(SpringLayout.EAST, lowTimeBar, 0,
				SpringLayout.EAST, this);

		layout.putConstraint(SpringLayout.NORTH, periodPane, 0,
				SpringLayout.SOUTH, lowTimeBar);
		layout.putConstraint(SpringLayout.WEST, periodPane, 0,
				SpringLayout.WEST, this);<commit_msg>Remove constant scroll bar.<commit_after>package fr.vergne.taskmanager.gui.gantt;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Calendar;
import java.util.Date;

import javax.swing.AbstractAction;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.SpringLayout;

import fr.vergne.taskmanager.gui.gantt.TimeBar.UnitDescriptor;
import fr.vergne.taskmanager.task.Task;
import fr.vergne.taskmanager.task.TaskList;

// FIXME paint the cursor after the time slots of the time bars
@SuppressWarnings("serial")
public class Gantt extends JPanel {

	private final TimeBar highTimeBar = new TimeBar();
	private final TimeBar lowTimeBar = new TimeBar() {
		public void paint(Graphics arg0) {
			super.paint(arg0);

			UnitDescriptor ref = lowTimeBar.getCurrentDescriptor();
			long refValue = ref.getUnitMultiplicator() * ref.getUnitStep();
			for (UnitDescriptor desc : highTimeBar.getDescriptors()) {
				long descValue = desc.getUnitMultiplicator()
						* desc.getUnitStep();
				if (descValue >= 3 * refValue) {
					highTimeBar.setForcedDescriptor(desc);
					break;
				}
			}
		};
	};
	private final PeriodCanvas periodCanvas = new PeriodCanvas();
	private final JScrollPane periodPane = new JScrollPane(periodCanvas);
	private final JPanel timeCursor = new JPanel();
	private final SpringLayout layout = new SpringLayout();
	private long median = new Date().getTime();
	private long radius = 1800000;
	private final Thread cursorThread;

	public Gantt() {
		initComponents();

		addKeyListener(new KeyListener() {

			@Override
			public void keyTyped(KeyEvent arg0) {
				// do nothing
			}

			@Override
			public void keyReleased(KeyEvent event) {
				if (event.getKeyCode() == KeyEvent.VK_PAGE_UP) {
					zoom(0.8);
				} else if (event.getKeyCode() == KeyEvent.VK_PAGE_DOWN) {
					zoom(1.0 / 0.8);
				} else if (event.getKeyCode() == KeyEvent.VK_F5) {
					resetDisplay();
				} else if (event.getKeyCode() == KeyEvent.VK_LEFT) {
					goTo(new Date((long) (median - radius * 0.1)));
				} else if (event.getKeyCode() == KeyEvent.VK_RIGHT) {
					goTo(new Date((long) (median + radius * 0.1)));
				} else {
					// do nothing
				}
			}

			@Override
			public void keyPressed(KeyEvent arg0) {
				// do nothing
			}
		});

		cursorThread = new Thread(new Runnable() {

			@Override
			public void run() {
				while (true) {
					try {
						Thread.sleep(Math.min(Math.max(radius / 1000, 100),
								1000));
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					updateCursor();
					validate();
				}
			}
		});
		cursorThread.start();
	}

	public void resetDisplay() {
		periodCanvas.setMinDate(periodCanvas.getActualMinDate());
		periodCanvas.setMaxDate(periodCanvas.getActualMaxDate());
		long min = periodCanvas.getMinDate().getTime();
		long max = periodCanvas.getMaxDate().getTime();
		median = (max + min) / 2;
		radius = median - min;
		repaint();
	}

	private void initComponents() {
		initTimeBars();

		add(lowTimeBar);
		add(highTimeBar);
		add(periodPane);
		add(timeCursor);
		timeCursor.setBackground(Color.GREEN);

		setLayout(layout);
		layout.putConstraint(SpringLayout.NORTH, highTimeBar, 0,
				SpringLayout.NORTH, this);
		layout.putConstraint(SpringLayout.WEST, highTimeBar, 0,
				SpringLayout.WEST, this);
		layout.putConstraint(SpringLayout.EAST, highTimeBar, 0,
				SpringLayout.EAST, this);

		layout.putConstraint(SpringLayout.NORTH, lowTimeBar, 0,
				SpringLayout.SOUTH, highTimeBar);
		layout.putConstraint(SpringLayout.WEST, lowTimeBar, 0,
				SpringLayout.WEST, this);
		layout.putConstraint(SpringLayout.EAST, lowTimeBar, 0,
				SpringLayout.EAST, this);

		layout.putConstraint(SpringLayout.NORTH, periodPane, 0,
				SpringLayout.SOUTH, lowTimeBar);
		layout.putConstraint(SpringLayout.WEST, periodPane, 0,
				SpringLayout.WEST, this);
{'fraction_non_alphanumeric': 0.12165692250279886, 'fraction_numerical': 0.010697847991043662, 'mean_word_length': 3.959901295496607, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4261106', 'n_tokens_mistral': 3086, 'n_tokens_neox': 2593, 'n_words': 556}