<commit_before>package edu.mit.csail.uid;

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.imageio.*;


class TargetOffsetPane extends JPanel implements MouseListener, MouseWheelListener, ChangeListener{
   final static int DEFAULT_H = 300;
   final static float DEFAULT_PATTERN_RATIO=0.4f;
   ScreenImage _simg;
   BufferedImage _img;
   Match _match;

   int _viewX, _viewY, _viewW, _viewH;
   float _zoomRatio, _ratio;
   Location _tar = new Location(0,0);
   Location _offset = new Location(0,0);
   JSpinner txtX, txtY;

   public TargetOffsetPane(ScreenImage simg, String patFilename, Location initOffset){
      _simg = simg;
      _ratio = DEFAULT_PATTERN_RATIO;
      Rectangle r = _simg.getROI();
      int w = DEFAULT_H/r.height*r.width;
      setPreferredSize(new Dimension(w, DEFAULT_H));

      Finder f = new Finder(_simg, new Region(simg.getROI()));
      f.find(patFilename);
      if(f.hasNext()){
         _match = f.next();
         if(initOffset!=null)
            setTarget(initOffset.x, initOffset.y);
         else
            setTarget(0,0);
      }
      try {
         _img = ImageIO.read(new File(patFilename));
      } catch (IOException e) {
         Debug.error("Can't load " + patFilename);
      }
      addMouseListener(this);
      addMouseWheelListener(this);
   }

   static String _I(String key, Object... args){ 
      return I18N._I(key, args);
   }


   private void zoomToMatch(){
      Rectangle scr = _simg.getROI();
      _viewW = (int)(_match.w/_ratio);
      _zoomRatio = getWidth()/(float)_viewW;
      _viewH = (int)(getHeight()/_zoomRatio);
      _viewX = _match.x + _match.w/2 - _viewW/2;
      _viewY = _match.y + _match.h/2 - _viewH/2;
   }

   public void setTarget(int dx, int dy){
      Debug.log(3, "new target: " + dx + "," + dy);
      if(_match != null){
         Location center = _match.getCenter();
         _tar.x = center.x + dx;
         _tar.y = center.y + dy;
      }
      else{
         _tar.x = dx;
         _tar.y = dy;
      }

      _offset = new Location(dx, dy);
      if(txtX != null){
         txtX.setValue(new Integer(dx));
         txtY.setValue(new Integer(dy));
      }
      repaint();
   }

   public void mousePressed ( MouseEvent me ) {
      Location tar = convertViewToScreen(me.getPoint());
      Debug.log(4, "click: " + me.getPoint() + " -> " + tar);
      if(_match != null){
         Location center = _match.getCenter();
         setTarget(tar.x-center.x, tar.y-center.y);
      }
      else{
         setTarget(tar.x, tar.y);
      }
   }

   public void mouseWheelMoved(MouseWheelEvent e) {
      int rot = e.getWheelRotation();
      if(rot<0){
         if(_ratio*1 < 5)
            _ratio *= 1.1;
      }
      else{
         if(_ratio*_img.getWidth() > 20)
            _ratio *= 0.9;
      }
      repaint();
   }
   public void mouseClicked ( MouseEvent me ) { }

   public void mouseReleased ( MouseEvent me ) {
   }

   public void mouseEntered ( MouseEvent me ) { }

   public void mouseExited ( MouseEvent me ) { }

   private static Color COLOR_BG_LINE = new Color(210,210,210,130);
   void paintRulers(Graphics g2d){
      int step = (int)(10*_zoomRatio);
      int h = getHeight(), w = getWidth();
      if(h%2==1)  h--;
      if(w%2==1)  w--;
      g2d.setColor(COLOR_BG_LINE);
      for(int x=w/2;x>=0;x-=step){
         g2d.drawLine(x, 0, x, h);
         g2d.drawLine(w-x, 0, w-x, h);
      }
      for(int y=h/2;y>=0;y-=step){
         g2d.drawLine(0, y, w, y);
         g2d.drawLine(0, h-y, w, h-y);
      }
   }

   void paintBackground(Graphics g2d){
      g2d.setColor(Color.WHITE);
      g2d.fillRect(0, 0, getWidth(), getHeight());
   }

   void paintPatternOnly(Graphics g2d){
      int patW = (int)(getWidth()*_ratio);
      _zoomRatio = patW/(float)_img.getWidth();
      int patH = (int)(_img.getHeight()*_zoomRatio);;
      int patX = getWidth()/2-patW/2, patY = getHeight()/2-patH/2;<commit_msg>fixed zoom level in TargetOffsetPane<commit_after>package edu.mit.csail.uid;

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.imageio.*;


class TargetOffsetPane extends JPanel implements MouseListener, MouseWheelListener, ChangeListener{
   final static int DEFAULT_H = 300;
   final static float DEFAULT_PATTERN_RATIO=0.4f;
   ScreenImage _simg;
   BufferedImage _img;
   Match _match;

   int _viewX, _viewY, _viewW, _viewH;
   float _zoomRatio, _ratio;
   Location _tar = new Location(0,0);
   Location _offset = new Location(0,0);
   JSpinner txtX, txtY;

   public TargetOffsetPane(ScreenImage simg, String patFilename, Location initOffset){
      _simg = simg;
      _ratio = DEFAULT_PATTERN_RATIO;
      Rectangle r = _simg.getROI();
      int w = DEFAULT_H/r.height*r.width;
      setPreferredSize(new Dimension(w, DEFAULT_H));

      Finder f = new Finder(_simg, new Region(simg.getROI()));
      f.find(patFilename);
      if(f.hasNext()){
         _match = f.next();
         if(initOffset!=null)
            setTarget(initOffset.x, initOffset.y);
         else
            setTarget(0,0);
      }
      try {
         _img = ImageIO.read(new File(patFilename));
      } catch (IOException e) {
         Debug.error("Can't load " + patFilename);
      }
      addMouseListener(this);
      addMouseWheelListener(this);
   }

   static String _I(String key, Object... args){ 
      return I18N._I(key, args);
   }


   private void zoomToMatch(){
      Rectangle scr = _simg.getROI();
      _viewW = (int)(_match.w/_ratio);
      _zoomRatio = getWidth()/(float)_viewW;
      _viewH = (int)(getHeight()/_zoomRatio);
      _viewX = _match.x + _match.w/2 - _viewW/2;
      _viewY = _match.y + _match.h/2 - _viewH/2;
   }

   public void setTarget(int dx, int dy){
      Debug.log(3, "new target: " + dx + "," + dy);
      if(_match != null){
         Location center = _match.getCenter();
         _tar.x = center.x + dx;
         _tar.y = center.y + dy;
      }
      else{
         _tar.x = dx;
         _tar.y = dy;
      }

      _offset = new Location(dx, dy);
      if(txtX != null){
         txtX.setValue(new Integer(dx));
         txtY.setValue(new Integer(dy));
      }
      repaint();
   }

   public void mousePressed ( MouseEvent me ) {
      Location tar = convertViewToScreen(me.getPoint());
      Debug.log(4, "click: " + me.getPoint() + " -> " + tar);
      if(_match != null){
         Location center = _match.getCenter();
         setTarget(tar.x-center.x, tar.y-center.y);
      }
      else{
         setTarget(tar.x, tar.y);
      }
   }

   public void mouseWheelMoved(MouseWheelEvent e) {
      int rot = e.getWheelRotation();
      int patW = (int)(getWidth()*_ratio);
      float zoomRatio = patW/(float)_img.getWidth();
      int patH = (int)(_img.getHeight()*_zoomRatio);;
      if(rot<0){
         if(patW < 2*getWidth() && patH < 2*getHeight())
            _ratio *= 1.1;
      }
      else{
         if(patW > 20 && patH > 20)
            _ratio *= 0.9;
      }
      repaint();
   }
   public void mouseClicked ( MouseEvent me ) { }

   public void mouseReleased ( MouseEvent me ) {
   }

   public void mouseEntered ( MouseEvent me ) { }

   public void mouseExited ( MouseEvent me ) { }

   private static Color COLOR_BG_LINE = new Color(210,210,210,130);
   void paintRulers(Graphics g2d){
      int step = (int)(10*_zoomRatio);
      if(step<2) step = 2;
      int h = getHeight(), w = getWidth();
      if(h%2==1)  h--;
      if(w%2==1)  w--;
      g2d.setColor(COLOR_BG_LINE);
      for(int x=w/2;x>=0;x-=step){
         g2d.drawLine(x, 0, x, h);
         g2d.drawLine(w-x, 0, w-x, h);
      }
      for(int y=h/2;y>=0;y-=step){
         g2d.drawLine(0, y, w, y);
         g2d.drawLine(0, h-y, w, h-y);
      }
   }

   void paintBackground(Graphics g2d){
      g2d.setColor(Color.WHITE);
      g2d.fillRect(0, 0, getWidth(), getHeight());
   }

   void paintPatternOnly(Graphics g2d){
      int patW = (int)(getWidth()*_ratio);
      _zoomRatio = patW/(float)_img.getWidth();
      int patH = (int)(_img.getHeight()*_zoomRatio);;
      int patX = getWidth()/2-patW/2, patY = getHeight()/2-patH/2;
{'fraction_non_alphanumeric': 0.14443909484833894, 'fraction_numerical': 0.017332691381800675, 'mean_word_length': 2.3517547398144414, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 12, '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': '1115188', 'n_tokens_mistral': 3012, 'n_tokens_neox': 2926, 'n_words': 619}