<commit_before>package com.akjava.gwt.lib.client.experimental;

import java.util.ArrayList;
import java.util.List;

import com.akjava.gwt.lib.client.CanvasUtils;
import com.akjava.lib.common.graphics.Rect;
import com.google.gwt.canvas.client.Canvas;
import com.google.gwt.dom.client.ImageElement;
import com.google.gwt.editor.client.LeafValueEditor;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

public class RectListEditor extends VerticalPanel implements LeafValueEditor<List<Rect>>{
	
	private AreaSelectionControler areaControler;

	private List<Rect> rectangles=new ArrayList<Rect>();
	
	private HorizontalPanel optionButtonContainer;//for future expand
	public HorizontalPanel getOptionButtonContainer() {
		return optionButtonContainer;
	}
	
	public Canvas getCanvas(){
		return areaControler.getCanvas();
	}
	
	public void doPlus(){
		if(!areaControler.getSelectionRect().hasWidthAndHeight()){
			return;
		}
		
		if(!rectangles.contains(areaControler.getSelectionRect())){
			rectangles.add(areaControler.getSelectionRect().copy());
		}
		areaControler.getSelectionRect().clear();
		
		areaControler.updateRect();
		getCanvas().setFocus(true);
	}
	
	public RectListEditor(){
		HorizontalPanel buttons=new HorizontalPanel();
		buttons.setSpacing(4);
		add(buttons);
		Button plusBt=new Button("+",new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				doPlus();
				//bugs it's gone if exist same rect
				//need size
				
			}
		});
		buttons.add(plusBt);
		plusBt.setWidth("80px");
		Button minusBt=new Button("-",new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				//bugs same size is gone
				rectangles.remove(areaControler.getSelectionRect());
				if(rectangles.size()>0){
					rectangles.get(rectangles.size()-1).copyTo(areaControler.getSelectionRect());
					rectangles.remove(rectangles.size()-1);
				}else{
					areaControler.getSelectionRect().clear();
				}
				areaControler.updateRect();
				getCanvas().setFocus(true);
			}
		});
		buttons.add(minusBt);
		minusBt.setWidth("80px");
		optionButtonContainer=new HorizontalPanel();
		buttons.add(optionButtonContainer);
		areaControler = new AreaSelectionControler(){
			@Override
			public void drawExtra(Canvas canvas){
				if(areaControler.getSelectionRect().hasWidthAndHeight()){
					canvas.getContext2d().setStrokeStyle("#fff");
				}else{
					canvas.getContext2d().setStrokeStyle("#888");
				}
				
				for(Rect rect:rectangles){
					if(!rect.equals(areaControler.getSelectionRect())){
						canvas.getContext2d().strokeRect(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
					}
				}
			}
			@Override
			public boolean canContinueStart(int x,int y){
				for(Rect rect:rectangles){
					if(rect.contains(x, y)){
						if(areaControler.getSelectionRect().hasWidthAndHeight()){
							rectangles.add(areaControler.getSelectionRect().copy());
						}
						
						rect.copyTo(areaControler.getSelectionRect());
						rectangles.remove(rect);
						updateRect();
						return false;
					}
				}
				
				return true;
			}
		};
		add(areaControler.getCanvas());
		
		
	}
	public void setBackgroundImage(ImageElement imageElement){
	
			CanvasUtils.setSize(areaControler.getCanvas(), imageElement.getWidth(), imageElement.getHeight());
			areaControler.getCanvas().setVisible(true);
			
			areaControler.setSpace(imageElement.getWidth(), imageElement.getHeight());
			
			CanvasUtils.setBackgroundImage(areaControler.getCanvas(), imageElement.getSrc());
			areaControler.updateRect();
		
	}
	
	public void clearBackgroundImage(){<commit_msg>support temporaly readonly mode<commit_after>package com.akjava.gwt.lib.client.experimental;

import java.util.ArrayList;
import java.util.List;

import com.akjava.gwt.lib.client.CanvasUtils;
import com.akjava.lib.common.graphics.Rect;
import com.google.gwt.canvas.client.Canvas;
import com.google.gwt.dom.client.ImageElement;
import com.google.gwt.editor.client.LeafValueEditor;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

public class RectListEditor extends VerticalPanel implements LeafValueEditor<List<Rect>>{
	
	private AreaSelectionControler areaControler;

	private List<Rect> rectangles=new ArrayList<Rect>();
	
	private HorizontalPanel optionButtonContainer;//for future expand
	public HorizontalPanel getOptionButtonContainer() {
		return optionButtonContainer;
	}
	
	public Canvas getCanvas(){
		return areaControler.getCanvas();
	}
	
	private boolean readOnly;

	private HorizontalPanel plusMinusButtons;
	
	public boolean isReadOnly() {
		return readOnly;
	}

	public void setReadOnly(boolean readOnly) {
		this.readOnly = readOnly;
		plusMinusButtons.setVisible(!readOnly);
	}

	public void doPlus(){
		if(!areaControler.getSelectionRect().hasWidthAndHeight()){
			return;
		}
		
		if(!rectangles.contains(areaControler.getSelectionRect())){
			rectangles.add(areaControler.getSelectionRect().copy());
		}
		areaControler.getSelectionRect().clear();
		
		areaControler.updateRect();
		getCanvas().setFocus(true);
	}
	
	public RectListEditor(){
		plusMinusButtons = new HorizontalPanel();
		plusMinusButtons.setSpacing(4);
		add(plusMinusButtons);
		Button plusBt=new Button("+",new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				doPlus();
				//bugs it's gone if exist same rect
				//need size
				
			}
		});
		plusMinusButtons.add(plusBt);
		plusBt.setWidth("80px");
		Button minusBt=new Button("-",new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				//bugs same size is gone
				rectangles.remove(areaControler.getSelectionRect());
				if(rectangles.size()>0){
					rectangles.get(rectangles.size()-1).copyTo(areaControler.getSelectionRect());
					rectangles.remove(rectangles.size()-1);
				}else{
					areaControler.getSelectionRect().clear();
				}
				areaControler.updateRect();
				getCanvas().setFocus(true);
			}
		});
		plusMinusButtons.add(minusBt);
		minusBt.setWidth("80px");
		optionButtonContainer=new HorizontalPanel();
		plusMinusButtons.add(optionButtonContainer);
		areaControler = new AreaSelectionControler(){
			@Override
			public void drawExtra(Canvas canvas){
				if(areaControler.getSelectionRect().hasWidthAndHeight()){
					canvas.getContext2d().setStrokeStyle("#fff");
				}else{
					canvas.getContext2d().setStrokeStyle("#888");
				}
				
				for(Rect rect:rectangles){
					if(!rect.equals(areaControler.getSelectionRect())){
						canvas.getContext2d().strokeRect(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
					}
				}
			}
			@Override
			public boolean canContinueStart(int x,int y){
				for(Rect rect:rectangles){
					if(rect.contains(x, y)){
						if(areaControler.getSelectionRect().hasWidthAndHeight()){
							rectangles.add(areaControler.getSelectionRect().copy());
						}
						
						rect.copyTo(areaControler.getSelectionRect());
						rectangles.remove(rect);
						updateRect();
						return false;
					}
				}
				
				if(readOnly){//can't edit
					return false;
				}
				
				return true;
			}
		};
		add(areaControler.getCanvas());
		
		
	}
	public void setBackgroundImage(ImageElement imageElement){
	
			CanvasUtils.setSize(areaControler.getCanvas(), imageElement.getWidth(), imageElement.getHeight());
			areaControler.getCanvas().setVisible(true);
			
			areaControler.setSpace(imageElement.getWidth(), imageElement.getHeight());
			
			CanvasUtils.setBackgroundImage(areaControler.getCanvas(), imageElement.getSrc());
			areaControler.updateRect();
		
	}
	
	public void clearBackgroundImage(){
{'fraction_non_alphanumeric': 0.1300251256281407, 'fraction_numerical': 0.0035175879396984926, 'mean_word_length': 4.4527397260273975, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '3314481', 'n_tokens_mistral': 2943, 'n_tokens_neox': 2416, 'n_words': 374}