<commit_before>import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Rectangle;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.PrintStream;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
import java.awt.Dimension;
import java.util.ArrayList;
import java.util.Collections;

public class GraficTest extends JPanel{
    private static final long serialVersionUID = 1L;
    private boolean applet;
    private ArrayList <Integer> selected;
    private boolean foundfirstitem;
    private int y = 5;

    public GraficTest(int x, int y, boolean applet){
        this.applet = applet;
        setSize(445, 595);
        setBackground(new Color(190, 195, 195));
        addMouseListener(new MouseAdapter(){
            public void mouseReleased(MouseEvent ev){handleClick(ev);}});}
                
    public void handleClick(MouseEvent ev){
        if(ev.getButton()==1){
            if(Repository.getTestSuiteNr()==0)return;
                getClickedItem(ev.getX(),ev.getY());
                if(selected.size()>0){
                    if(getItem(selected).getSubItemsNr()>0){getItem(selected).setVisible(!(getItem(selected).getSubItem(0).isVisible()));}
                    updateLocations(getItem(selected));}
                repaint();}}
                
    public Item getItem(ArrayList <Integer> pos){           
        Item theone1 = Repository.getTestSuita(pos.get(0));
        for(int j=1;j<pos.size();j++){
            theone1 = theone1.getSubItem(pos.get(j));}
        return theone1;}
                
    public void getClickedItem(int x, int y){
        Rectangle r = new Rectangle(x-1,y-1,2,2);
        int suitenr = Repository.getTestSuiteNr();
        selected = new ArrayList<Integer>();
        for(int i=0;i<suitenr;i++){
            if(handleClicked(r,Repository.getTestSuita(i))){
                selected.add(i);
                break;}}
        if(selected.size()>0)Collections.reverse(selected);}
        
    public boolean handleClicked(Rectangle r, Item item){
        if(r.intersects(item.getRectangle())&&item.isVisible())return true;
        else{int itemnr = item.getSubItemsNr();
            for(int i=0;i<itemnr;i++){
                if(handleClicked(r,item.getSubItem(i))){
                    selected.add(i);
                    return true;}}
            return false;}}
        
    public void updateLocations(Item suita){
        ArrayList <Integer> selected2 = (ArrayList <Integer>)suita.getPos().clone();
        if(selected2.size()>1){
            int index = selected2.get(0);
            selected2.remove(0);
            for(int i=index;i<Repository.getTestSuiteNr();i++){   
                Repository.frame.mainpanel.p2.sc.g.iterateThrough(Repository.getTestSuita(i),selected2);
                selected2 = null;}}
        else if(selected2.size()==1){
            for(int i=selected2.get(0);i<Repository.getTestSuiteNr();i++){
                Repository.frame.mainpanel.p2.sc.g.iterateThrough(Repository.getTestSuita(i),null);}}
        y=10;
        foundfirstitem=false;
        updateScroll();}
        
    public int calcPreviousPositions(Item item){
        ArrayList <Integer> pos = (ArrayList <Integer>)item.getPos().clone();
        if(pos.size()>1){
            pos.remove(pos.size()-1);
            Item temp = getItem(pos);
            return temp.getLocation()[0]+(int)(temp.getRectangle().getWidth()/2+20);}
        else{return 5;}}
        
    public void positionItem(Item item){        
        int x = calcPreviousPositions(item);
        item.setLocation(new int[]{x,y});
        y+=(int)(5+item.getRectangle().getHeight());}  
        
    public void iterateThrough(Item item, ArrayList <Integer> theone){
        int subitemsnr = item.getSubItemsNr();
        if(theone==null){
            if(item.isVisible()){
                if(!foundfirstitem)y=item.getLocation()[1];
                foundfirstitem = true;
                positionItem(item);}
            for(int i=0;i<subitemsnr;i++){    
                iterateThrough(item.getSubItem(i),null);}}
        else if(theone.size()>1){
            int index = theone.get(0);
            theone.remove(0);
            for(int i=index;i<subitemsnr;i++){
                iterateThrough(item.getSubItem(i),theone);
                theone=null;}}
        else if(theone.size()==1){
            int index = theone.get(0);
            for(int i=index;i<subitemsnr;i++){
                iterateThrough(item.getSubItem(i),null);}}}

    public void updateScroll(){
        int y1=0;
        for(int i=0;i<Repository.getTestSuiteNr();i++){
            if(Repository.getTestSuita(i).isVisible())y1 = getLastY(Repository.getTestSuita(i),y1);}
        if(y1>getHeight()){
            setPreferredSize(new Dimension(425,y1+10));
            revalidate();}
        if(getHeight()>595){
            if(y1<getHeight()-10){
                setPreferredSize(new Dimension(425,y1+10));
                revalidate();}
            if(y1<595){
                setPreferredSize(new Dimension(445,595));
                revalidate();}}}
            
            
    public int getLastY(Item item, int height){
        if(height<=(item.getRectangle().getY()+item.getRectangle().getHeight())){
            height=(int)(item.getRectangle().getY()+item.getRectangle().getHeight());        
            int nr = item.getSubItemsNr()-1;
            for(int i=nr;i>=0;i--){
                if(item.getSubItem(i).isVisible()){height = getLastY(item.getSubItem(i),height);}}
            return height;}
        else return height;}

    public void paint(Graphics g){
        g.setColor(Color.WHITE);
        g.fillRect(0,0,getWidth(),getHeight());
        g.setColor(Color.BLACK);
        int suitenr = Repository.getTestSuiteNr();
        for(int i=0;i<suitenr;i++){
            handlePaintItem(Repository.getTestSuita(i),g);}}
            
    public void handlePaintItem(Item item, Graphics g){
        drawItem(item,g);
        int subitemnr = item.getSubItemsNr();
        if(subitemnr>0&&item.getSubItem(0).isVisible()){<commit_msg>latest version<commit_after>import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Rectangle;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.PrintStream;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
import java.awt.Dimension;
import java.util.ArrayList;
import java.util.Collections;

public class GraficTest extends JPanel{
    private static final long serialVersionUID = 1L;
    private boolean applet;
    private ArrayList <Integer> selected;
    private boolean foundfirstitem;
    private int y = 5;

    public GraficTest(int x, int y, boolean applet){
        this.applet = applet;
        setSize(445, 595);
        setBackground(new Color(190, 195, 195));
        addMouseListener(new MouseAdapter(){
            public void mouseReleased(MouseEvent ev){handleClick(ev);}});}
                
    public void handleClick(MouseEvent ev){
        if(ev.getButton()==1){
            if(Repository.getTestSuiteNr()==0)return;
                getClickedItem(ev.getX(),ev.getY());
                if(selected.size()>0){
                    if(getItem(selected).getSubItemsNr()>0){getItem(selected).setVisible(!(getItem(selected).getSubItem(0).isVisible()));}
                    updateLocations(getItem(selected));}
                repaint();}}
                
    public Item getItem(ArrayList <Integer> pos){           
        Item theone1 = Repository.getTestSuita(pos.get(0));
        for(int j=1;j<pos.size();j++){
            theone1 = theone1.getSubItem(pos.get(j));}
        return theone1;}
                
    public void getClickedItem(int x, int y){
        Rectangle r = new Rectangle(x-1,y-1,2,2);
        int suitenr = Repository.getTestSuiteNr();
        selected = new ArrayList<Integer>();
        for(int i=0;i<suitenr;i++){
            if(handleClicked(r,Repository.getTestSuita(i))){
                selected.add(i);
                break;}}
        if(selected.size()>0)Collections.reverse(selected);}
        
    public boolean handleClicked(Rectangle r, Item item){
        if(r.intersects(item.getRectangle())&&item.isVisible())return true;
        else{int itemnr = item.getSubItemsNr();
            for(int i=0;i<itemnr;i++){
                if(handleClicked(r,item.getSubItem(i))){
                    selected.add(i);
                    return true;}}
            return false;}}
        
    public void updateLocations(Item suita){
        ArrayList <Integer> selected2 = (ArrayList <Integer>)suita.getPos().clone();
        if(selected2.size()>1){
            int index = selected2.get(0);
            selected2.remove(0);
            for(int i=index;i<Repository.getTestSuiteNr();i++){   
                Repository.frame.mainpanel.p2.sc.g.iterateThrough(Repository.getTestSuita(i),selected2);
                selected2 = null;}}
        else if(selected2.size()==1){
            for(int i=selected2.get(0);i<Repository.getTestSuiteNr();i++){
                Repository.frame.mainpanel.p2.sc.g.iterateThrough(Repository.getTestSuita(i),null);}}
        y=10;
        foundfirstitem=false;
        updateScroll();}
        
    public int calcPreviousPositions(Item item){
        ArrayList <Integer> pos = (ArrayList <Integer>)item.getPos().clone();
        if(pos.size()>1){
            pos.remove(pos.size()-1);
            Item temp = getItem(pos);
            return temp.getLocation()[0]+(int)(temp.getRectangle().getWidth()/2+20);}
        else{return 5;}}
        
    public void positionItem(Item item){        
        int x = calcPreviousPositions(item);
        item.setLocation(new int[]{x,y});
        y+=(int)(5+item.getRectangle().getHeight());}  
        
    public void iterateThrough(Item item, ArrayList <Integer> theone){
        int subitemsnr = item.getSubItemsNr();
        if(theone==null){
            if(item.isVisible()){
                if(!foundfirstitem)y=item.getLocation()[1];
                foundfirstitem = true;
                positionItem(item);}
            for(int i=0;i<subitemsnr;i++){    
                iterateThrough(item.getSubItem(i),null);}}
        else if(theone.size()>1){
            int index = theone.get(0);
            theone.remove(0);
            for(int i=index;i<subitemsnr;i++){
                iterateThrough(item.getSubItem(i),theone);
                theone=null;}}
        else if(theone.size()==1){
            int index = theone.get(0);
            for(int i=index;i<subitemsnr;i++){
                iterateThrough(item.getSubItem(i),null);}}}

    public void updateScroll(){
        int y1=0;
        for(int i=0;i<Repository.getTestSuiteNr();i++){
            if(Repository.getTestSuita(i).isVisible())y1 = getLastY(Repository.getTestSuita(i),y1);}
        if(y1>getHeight()){
            setPreferredSize(new Dimension(425,y1+10));
            revalidate();}
        if(getHeight()>595){
            if(y1<getHeight()-10){
                setPreferredSize(new Dimension(425,y1+10));
                revalidate();}
            if(y1<595){
                setPreferredSize(new Dimension(445,595));
                revalidate();}}}
            
    public int getLastY(Item item, int height){
        if(height<=(item.getRectangle().getY()+item.getRectangle().getHeight())){
            height=(int)(item.getRectangle().getY()+item.getRectangle().getHeight());        
            int nr = item.getSubItemsNr()-1;
            for(int i=nr;i>=0;i--){
                if(item.getSubItem(i).isVisible()){height = getLastY(item.getSubItem(i),height);}}
            return height;}
        else return height;}

    public void paint(Graphics g){
        g.setColor(Color.WHITE);
        g.fillRect(0,0,getWidth(),getHeight());
        g.setColor(Color.BLACK);
        int suitenr = Repository.getTestSuiteNr();
        for(int i=0;i<suitenr;i++){
            handlePaintItem(Repository.getTestSuita(i),g);}}
            
    public void handlePaintItem(Item item, Graphics g){
        drawItem(item,g);
        int subitemnr = item.getSubItemsNr();
        if(subitemnr>0&&item.getSubItem(0).isVisible()){
{'fraction_non_alphanumeric': 0.1429263565891473, 'fraction_numerical': 0.01744186046511628, 'mean_word_length': 2.3682349741637205, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 39, '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': '2006583', 'n_tokens_mistral': 3882, 'n_tokens_neox': 3747, 'n_words': 600}