<commit_before>package com.ikai.photosharing.client.widgets;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyPressEvent;
import com.google.gwt.event.dom.client.KeyPressHandler;
import com.google.gwt.event.dom.client.MouseDownEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.ikai.photosharing.client.services.UserImageService;
import com.ikai.photosharing.client.services.UserImageServiceAsync;
import com.ikai.photosharing.shared.LoginInfo;
import com.ikai.photosharing.shared.Tag;
import com.ikai.photosharing.shared.UploadedImage;

/**
 * 
 * This class represents the ImageOverlay that pops up when a User clicks on an
 * Image. It also provides listeners for management, tagging, and other
 * functions which are considered "Menu" type functions for a given image.
 * 
 * @author <NAME>
 * 
 */
public class ImageOverlay extends Composite {

	private static ImageOverlayUiBinder uiBinder = GWT
			.create(ImageOverlayUiBinder.class);

	UserImageServiceAsync imageService = GWT.create(UserImageService.class);

	interface ImageOverlayUiBinder extends UiBinder<Widget, ImageOverlay> {
	}

	@UiField
	Button deleteButton;

	@UiField
	Image image;

	@UiField
	Label timestamp;

	protected UploadedImage uploadedImage;
	LoginInfo loginInfo;
	PhotoGallery gallery;

	public ImageOverlay(UploadedImage uploadedImage, LoginInfo loginInfo,
			PhotoGallery gallery) {
		this.gallery = gallery;
		this.uploadedImage = uploadedImage;
		this.loginInfo = loginInfo;

		initWidget(uiBinder.createAndBindUi(this));

		image.setUrl(uploadedImage.getServingUrl());
		timestamp.setText("Created at:" + uploadedImage.getCreatedAt());

		if (loginInfo != null
				&& (loginInfo.getId().equals(uploadedImage.getOwnerId()))) {
			deleteButton.setText("Delete image");
			deleteButton.setVisible(true);
		} else {
			deleteButton.setVisible(false);
		}

	}

	@UiHandler("image")
	void onClickImage(MouseDownEvent e) {
		Element imageElement = e.getRelativeElement();
		int x = e.getRelativeX(imageElement);
		int y = e.getRelativeY(imageElement);
		// Window.alert("X: " + x + " Y: "+ y);
		TagDialog tagDialog = new TagDialog(image, x, y);
		tagDialog.showAndFocus();

	}

	/**
	 * 
	 * Handles clicking of the delete button if owned.
	 * 
	 * @param {{@link ClickEvent} e
	 */
	@UiHandler("deleteButton")
	void onClick(ClickEvent e) {
		final ImageOverlay overlay = this;
		imageService.deleteImage(uploadedImage.getKey(),
				new AsyncCallback<Void>() {

					@Override
					public void onSuccess(Void result) {
						gallery.refreshGallery();
						overlay.removeFromParent();
					}

					@Override
					public void onFailure(Throwable caught) {
						// TODO Auto-generated method stub

					}
				});

	}

	private class TagDialog extends DialogBox {
		
		private TextBox textBox;

		public TagDialog(Image image, final int x, final int y) {

			// Set the dialog box's caption.
			setText("Tagging X: " + x + " Y: " + y);

			int dialogX = image.getAbsoluteLeft() + x;
			int dialogY = image.getAbsoluteTop() + y;

			setPopupPosition(dialogX, dialogY);

			VerticalPanel tagPanel = new VerticalPanel();

			textBox = new TextBox();
			tagPanel.add(textBox);

			textBox.addKeyPressHandler(new KeyPressHandler() {

				@Override
				public void onKeyPress(KeyPressEvent event) {
					if (event.getCharCode() == KeyCodes.KEY_ENTER) {
						saveTag(x, y, textBox);
					}

				}
			});

			Button ok = new Button("Tag");
			ok.addClickHandler(new ClickHandler() {
				public void onClick(ClickEvent event) {
					saveTag(x, y, textBox);
				}<commit_msg>Adding autohide<commit_after>package com.ikai.photosharing.client.widgets;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyPressEvent;
import com.google.gwt.event.dom.client.KeyPressHandler;
import com.google.gwt.event.dom.client.MouseDownEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.ikai.photosharing.client.services.UserImageService;
import com.ikai.photosharing.client.services.UserImageServiceAsync;
import com.ikai.photosharing.shared.LoginInfo;
import com.ikai.photosharing.shared.Tag;
import com.ikai.photosharing.shared.UploadedImage;

/**
 * 
 * This class represents the ImageOverlay that pops up when a User clicks on an
 * Image. It also provides listeners for management, tagging, and other
 * functions which are considered "Menu" type functions for a given image.
 * 
 * @author <NAME>
 * 
 */
public class ImageOverlay extends Composite {

	private static ImageOverlayUiBinder uiBinder = GWT
			.create(ImageOverlayUiBinder.class);

	UserImageServiceAsync imageService = GWT.create(UserImageService.class);

	interface ImageOverlayUiBinder extends UiBinder<Widget, ImageOverlay> {
	}

	@UiField
	Button deleteButton;

	@UiField
	Image image;

	@UiField
	Label timestamp;

	protected UploadedImage uploadedImage;
	LoginInfo loginInfo;
	PhotoGallery gallery;

	public ImageOverlay(UploadedImage uploadedImage, LoginInfo loginInfo,
			PhotoGallery gallery) {
		this.gallery = gallery;
		this.uploadedImage = uploadedImage;
		this.loginInfo = loginInfo;

		initWidget(uiBinder.createAndBindUi(this));

		image.setUrl(uploadedImage.getServingUrl());
		timestamp.setText("Created at:" + uploadedImage.getCreatedAt());

		if (loginInfo != null
				&& (loginInfo.getId().equals(uploadedImage.getOwnerId()))) {
			deleteButton.setText("Delete image");
			deleteButton.setVisible(true);
		} else {
			deleteButton.setVisible(false);
		}

	}

	@UiHandler("image")
	void onClickImage(MouseDownEvent e) {
		Element imageElement = e.getRelativeElement();
		int x = e.getRelativeX(imageElement);
		int y = e.getRelativeY(imageElement);
		// Window.alert("X: " + x + " Y: "+ y);
		TagDialog tagDialog = new TagDialog(image, x, y);
		tagDialog.showAndFocus();

	}

	/**
	 * 
	 * Handles clicking of the delete button if owned.
	 * 
	 * @param {{@link ClickEvent} e
	 */
	@UiHandler("deleteButton")
	void onClick(ClickEvent e) {
		final ImageOverlay overlay = this;
		imageService.deleteImage(uploadedImage.getKey(),
				new AsyncCallback<Void>() {

					@Override
					public void onSuccess(Void result) {
						gallery.refreshGallery();
						overlay.removeFromParent();
					}

					@Override
					public void onFailure(Throwable caught) {
						// TODO Auto-generated method stub

					}
				});

	}

	/**
	 * @author <NAME>
	 *
	 *	 This is the dialog box to ask the user to tag the image
	 */
	private class TagDialog extends DialogBox {
		
		private TextBox textBox;

		public TagDialog(Image image, final int x, final int y) {

			// Set the dialog box's caption.
			setText("Tagging X: " + x + " Y: " + y);
			
			setAutoHideEnabled(true);

			int dialogX = image.getAbsoluteLeft() + x;
			int dialogY = image.getAbsoluteTop() + y;

			setPopupPosition(dialogX, dialogY);

			VerticalPanel tagPanel = new VerticalPanel();

			textBox = new TextBox();
			tagPanel.add(textBox);

			textBox.addKeyPressHandler(new KeyPressHandler() {

				@Override
				public void onKeyPress(KeyPressEvent event) {
					if (event.getCharCode() == KeyCodes.KEY_ENTER) {
						saveTag(x, y, textBox);
					}

				}
			});

			Button ok = new Button("Tag");
			ok.addClickHandler(new ClickHandler() {
				public void onClick(ClickEvent event) {
					saveTag(x, y, textBox);
				}
{'fraction_non_alphanumeric': 0.11620725151549811, 'fraction_numerical': 0.0, 'mean_word_length': 4.167848699763593, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '2889487', 'n_tokens_mistral': 3160, 'n_tokens_neox': 2786, 'n_words': 587}