<commit_before>package satori.test;

import java.awt.Point;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.swing.BoxLayout;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.TransferHandler;

import satori.common.SException;
import satori.common.SList;
import satori.common.SListener;
import satori.common.SListener2;
import satori.common.ui.SPane;
import satori.common.ui.SScrollPane;
import satori.main.SFrame;
import satori.problem.STestSuiteImpl;
import satori.problem.ui.STestSnapTransfer;

public class STestPane implements SList<STestImpl>, SPane {
	private final TestCaseMetadata meta;
	private final STestSuiteImpl suite;
	private final STestFactory factory;
	
	private List<SRowView> rows = new ArrayList<SRowView>();
	private List<STestImpl> tests = new ArrayList<STestImpl>();
	
	private JPanel pane;
	private SScrollPane scroll_pane;
	
	private SListener<STestImpl> new_test_listener = new SListener<STestImpl>() {
		@Override public void call(STestImpl unused) {
			STestImpl test = factory.createNew();
			suite.addTest(test);
			add(test);
		}
	};
	private SListener<STestImpl> close_test_listener = new SListener<STestImpl>() {
		@Override public void call(STestImpl test) {
			remove(test);
			suite.removeTest(test);
		}
	};
	
	private static class MoveTestTransferable implements Transferable {
		private final STestTransfer data;
		public MoveTestTransferable(STestTransfer data) { this.data = data; }
		@Override public DataFlavor[] getTransferDataFlavors() {
			DataFlavor[] flavors = new DataFlavor[1];
			flavors[0] = STestTransfer.flavor;
			return flavors;
		}
		@Override public boolean isDataFlavorSupported(DataFlavor flavor) {
			return flavor.match(STestTransfer.flavor);
		}
		@Override public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
			if (flavor.match(STestTransfer.flavor)) return data;
			else throw new UnsupportedFlavorException(flavor);
		}
	}
	private class TestTransferHandler extends TransferHandler implements SListener2<STestImpl, MouseEvent> {
		private STestImpl test;
		
		@Override public boolean canImport(TransferSupport support) {
			if ((support.getSourceDropActions() & COPY) != COPY) return false;
			support.setDropAction(COPY);
			if (support.isDataFlavorSupported(STestSnapTransfer.flavor)) return true;
			if (support.isDataFlavorSupported(STestTransfer.flavor)) {
				Transferable t = support.getTransferable();
				STestTransfer data;
				try { data = (STestTransfer)t.getTransferData(STestTransfer.flavor); }
				catch(UnsupportedFlavorException ex) { return false; }
				catch(IOException ex) { return false; }
				return data.getTestSuite() == suite;
			}
			return false;
		}
		@Override public boolean importData(TransferSupport support) {
			if (!support.isDrop()) return false;
			Transferable t = support.getTransferable();
			if (support.isDataFlavorSupported(STestSnapTransfer.flavor)) {
				STestSnapTransfer data;
				try { data = (STestSnapTransfer)t.getTransferData(STestSnapTransfer.flavor); }
				catch(UnsupportedFlavorException ex) { return false; }
				catch(IOException ex) { return false; }
				List<STestImpl> tests = new ArrayList<STestImpl>();
				for (STestSnap snap : data.get()) {
					if (suite.hasTest(snap.getId())) continue;
					try { tests.add(factory.create(snap)); }
					catch(SException ex) { SFrame.showErrorDialog(ex); return false; }
				}
				Point pos = support.getDropLocation().getDropPoint();
				int index = (int)Math.round((pos.getX()-120)/120);
				if (index < 0) index = 0;
				if (index > tests.size()) index = tests.size();
				for (STestImpl test : tests) suite.addTest(test, index++);
				add(tests, index);
				return true;
			}
			else if (support.isDataFlavorSupported(STestTransfer.flavor)) {
				STestTransfer data;
				try { data = (STestTransfer)t.getTransferData(STestTransfer.flavor); }
				catch(UnsupportedFlavorException ex) { return false; }
				catch(IOException ex) { return false; }
				if (data.getTestSuite() != suite) return false;
				STestImpl test = data.getTest();
				Point pos = support.getDropLocation().getDropPoint();
				int index = (int)Math.round((pos.getX()-120)/120);
				if (index < 0) index = 0;
				if (index > tests.size()) index = tests.size();
				suite.moveTest(test, index);
				move(test, index);
				return true;
			}
			else return false;
		}<commit_msg>fixed bugs in test drag support<commit_after>package satori.test;

import java.awt.Point;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.swing.BoxLayout;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.TransferHandler;

import satori.common.SException;
import satori.common.SList;
import satori.common.SListener;
import satori.common.SListener2;
import satori.common.ui.SPane;
import satori.common.ui.SScrollPane;
import satori.main.SFrame;
import satori.problem.STestSuiteImpl;
import satori.problem.ui.STestSnapTransfer;

public class STestPane implements SList<STestImpl>, SPane {
	private final TestCaseMetadata meta;
	private final STestSuiteImpl suite;
	private final STestFactory factory;
	
	private List<SRowView> rows = new ArrayList<SRowView>();
	private List<STestImpl> tests = new ArrayList<STestImpl>();
	
	private JPanel pane;
	private SScrollPane scroll_pane;
	
	private SListener<STestImpl> new_test_listener = new SListener<STestImpl>() {
		@Override public void call(STestImpl unused) {
			STestImpl test = factory.createNew();
			suite.addTest(test);
			add(test);
		}
	};
	private SListener<STestImpl> close_test_listener = new SListener<STestImpl>() {
		@Override public void call(STestImpl test) {
			remove(test);
			suite.removeTest(test);
		}
	};
	
	private static class MoveTestTransferable implements Transferable {
		private final STestTransfer data;
		public MoveTestTransferable(STestTransfer data) { this.data = data; }
		@Override public DataFlavor[] getTransferDataFlavors() {
			DataFlavor[] flavors = new DataFlavor[1];
			flavors[0] = STestTransfer.flavor;
			return flavors;
		}
		@Override public boolean isDataFlavorSupported(DataFlavor flavor) {
			return flavor.match(STestTransfer.flavor);
		}
		@Override public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
			if (flavor.match(STestTransfer.flavor)) return data;
			else throw new UnsupportedFlavorException(flavor);
		}
	}
	private class TestTransferHandler extends TransferHandler implements SListener2<STestImpl, MouseEvent> {
		private STestImpl test;
		
		@Override public boolean canImport(TransferSupport support) {
			if ((support.getSourceDropActions() & COPY) != COPY) return false;
			support.setDropAction(COPY);
			if (support.isDataFlavorSupported(STestSnapTransfer.flavor)) return true;
			if (support.isDataFlavorSupported(STestTransfer.flavor)) {
				Transferable t = support.getTransferable();
				STestTransfer data;
				try { data = (STestTransfer)t.getTransferData(STestTransfer.flavor); }
				catch(UnsupportedFlavorException ex) { return false; }
				catch(IOException ex) { return false; }
				return data.getTestSuite() == suite;
			}
			return false;
		}
		@Override public boolean importData(TransferSupport support) {
			if (!support.isDrop()) return false;
			Transferable t = support.getTransferable();
			if (support.isDataFlavorSupported(STestSnapTransfer.flavor)) {
				STestSnapTransfer data;
				try { data = (STestSnapTransfer)t.getTransferData(STestSnapTransfer.flavor); }
				catch(UnsupportedFlavorException ex) { return false; }
				catch(IOException ex) { return false; }
				List<STestImpl> new_tests = new ArrayList<STestImpl>();
				for (STestSnap snap : data.get()) {
					if (suite.hasTest(snap.getId())) continue;
					try { new_tests.add(factory.create(snap)); }
					catch(SException ex) { SFrame.showErrorDialog(ex); return false; }
				}
				Point pos = support.getDropLocation().getDropPoint();
				int index = (int)Math.round((pos.getX()-120)/120);
				if (index < 0) index = 0;
				if (index > tests.size()) index = tests.size();
				int cur_index = index;
				for (STestImpl test : new_tests) suite.addTest(test, cur_index++);
				add(new_tests, index);
				return true;
			}
			else if (support.isDataFlavorSupported(STestTransfer.flavor)) {
				STestTransfer data;
				try { data = (STestTransfer)t.getTransferData(STestTransfer.flavor); }
				catch(UnsupportedFlavorException ex) { return false; }
				catch(IOException ex) { return false; }
				if (data.getTestSuite() != suite) return false;
				STestImpl test = data.getTest();
				Point pos = support.getDropLocation().getDropPoint();
				int index = (int)Math.round((pos.getX()-120)/120);
				if (index < 0) index = 0;
				if (index > tests.size()) index = tests.size();
				suite.moveTest(test, index);
				move(test, index);
				return true;
			}
			else return false;
		}
{'fraction_non_alphanumeric': 0.11004630128136104, 'fraction_numerical': 0.004307095940562076, 'mean_word_length': 4.768944099378882, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, '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': '6952052', 'n_tokens_mistral': 3266, 'n_tokens_neox': 2885, 'n_words': 658}