<commit_before>
package com.badlogic.gdx.scenes.scene2d.utils;

import com.badlogic.gdx.Input.Buttons;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.utils.Array;

import javax.swing.tree.DefaultTreeCellEditor.EditorContainer;

/** Manages drag and drop operations through registered drag sources and drop targets.
 * @author <NAME> */
public class DragAndDrop {
	Source source;
	Payload payload;
	Actor dragActor;
	Target target;
	boolean isValidTarget;
	Array<Target> targets = new Array();
	private float tapSquareSize = 8;
	private int button;
	float dragActorX = 14, dragActorY = -20;
	long dragStartTime;
	int dragTime = 250;

	public void addSource (final Source source) {
		DragListener listener = new DragListener() {
			public void dragStart (InputEvent event, float x, float y, int pointer) {
				dragStartTime = System.currentTimeMillis();
				payload = source.dragStart(event, getTouchDownX(), getTouchDownY(), pointer);
				event.stop();
			}

			public void drag (InputEvent event, float x, float y, int pointer) {
				if (payload == null) return;
				Stage stage = event.getStage();

				// Find target.
				Target newTarget = null;
				isValidTarget = false;
				Actor hit = event.getStage().hit(event.getStageX(), event.getStageY(), false);
				if (hit != null) {
					for (int i = 0, n = targets.size; i < n; i++) {
						Target target = targets.get(i);
						if (!target.actor.isAscendant(hit)) continue;
						newTarget = target;
						target.actor.stageToLocalCoordinates(Vector2.tmp.set(event.getStageX(), event.getStageY()));
						isValidTarget = target.drag(source, payload, Vector2.tmp.x, Vector2.tmp.y, pointer);
						break;
					}
				}
				if (newTarget != target) {
					if (target != null) target.reset(source, payload);<commit_msg>DragAndDrop, prefer touchable targets, but still check non-touchable.<commit_after>
package com.badlogic.gdx.scenes.scene2d.utils;

import com.badlogic.gdx.Input.Buttons;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.utils.Array;

import javax.swing.tree.DefaultTreeCellEditor.EditorContainer;

/** Manages drag and drop operations through registered drag sources and drop targets.
 * @author <NAME> */
public class DragAndDrop {
	Source source;
	Payload payload;
	Actor dragActor;
	Target target;
	boolean isValidTarget;
	Array<Target> targets = new Array();
	private float tapSquareSize = 8;
	private int button;
	float dragActorX = 14, dragActorY = -20;
	long dragStartTime;
	int dragTime = 250;

	public void addSource (final Source source) {
		DragListener listener = new DragListener() {
			public void dragStart (InputEvent event, float x, float y, int pointer) {
				dragStartTime = System.currentTimeMillis();
				payload = source.dragStart(event, getTouchDownX(), getTouchDownY(), pointer);
				event.stop();
			}

			public void drag (InputEvent event, float x, float y, int pointer) {
				if (payload == null) return;
				Stage stage = event.getStage();

				// Find target.
				Target newTarget = null;
				isValidTarget = false;
				Actor hit = event.getStage().hit(event.getStageX(), event.getStageY(), true); // Prefer touchable actors.
				if (hit == null) hit = event.getStage().hit(event.getStageX(), event.getStageY(), false);
				if (hit != null) {
					for (int i = 0, n = targets.size; i < n; i++) {
						Target target = targets.get(i);
						if (!target.actor.isAscendant(hit)) continue;
						newTarget = target;
						target.actor.stageToLocalCoordinates(Vector2.tmp.set(event.getStageX(), event.getStageY()));
						isValidTarget = target.drag(source, payload, Vector2.tmp.x, Vector2.tmp.y, pointer);
						break;
					}
				}
				if (newTarget != target) {
					if (target != null) target.reset(source, payload);
{'fraction_non_alphanumeric': 0.12204822271936366, 'fraction_numerical': 0.008451404424558787, 'mean_word_length': 3.9073170731707316, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '373317', 'n_tokens_mistral': 1467, 'n_tokens_neox': 1263, 'n_words': 338}