<commit_before>package org.sagebionetworks.web.client.widget.entity;

import org.gwtbootstrap3.client.ui.html.Div;
import org.sagebionetworks.web.client.DisplayUtils;
import org.sagebionetworks.web.client.SageImageBundle;
import org.sagebionetworks.web.client.SynapseJSNIUtils;
import org.sagebionetworks.web.client.widget.modal.Dialog;

import org.sagebionetworks.web.client.utils.Callback;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
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.ErrorEvent;
import com.google.gwt.event.dom.client.ErrorHandler;
import com.google.gwt.event.dom.client.LoadEvent;
import com.google.gwt.event.dom.client.LoadHandler;
import com.google.gwt.event.logical.shared.AttachEvent;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.user.client.ui.Frame;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;

public class PreviewWidgetViewImpl extends FocusPanel implements PreviewWidgetView, IsWidget{
	private Presenter presenter;
	private SynapseJSNIUtils synapseJSNIUtils;
	private boolean isCode;
	private SageImageBundle sageImageBundle;
	private Dialog previewDialog;
	private Widget dialogContent;
	@Inject
	public PreviewWidgetViewImpl(SynapseJSNIUtils synapseJsniUtils, 
			SageImageBundle sageImageBundle, 
			final Dialog previewDialog) {
		this.synapseJSNIUtils = synapseJsniUtils;
		this.sageImageBundle = sageImageBundle;
		this.previewDialog = previewDialog;
		previewDialog.configure("", null, "Close", new Dialog.Callback() {
			@Override
			public void onDefault() {
				hideFullscreenPreview();
			}
			
			@Override
			public void onPrimary() {
			}
		}, false);
		previewDialog.addStyleName("modal-fullscreen");
		addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				showFullscreenPreview();
			}
		});
		addStyleName("imageButton");
	}
	
	private void showFullscreenPreview() {
		dialogContent = getWidget();
		dialogContent.removeFromParent();
		Div panel = new Div();
		panel.addStyleName("margin-right-20");
		panel.add(dialogContent);
		previewDialog.add(panel);
		previewDialog.show();
	}
	private void hideFullscreenPreview() {
		dialogContent.removeFromParent();
		PreviewWidgetViewImpl.this.add(dialogContent);
		previewDialog.hide();

	}
	
	@Override
	public void setPresenter(Presenter presenter) {
		this.presenter = presenter;
	}
	
	@Override
	public Widget asWidget() {
		return this;
	}
	
	@Override
	public void setImagePreview(final String fullFileUrl) {
		clear();
		Image fullImage = new Image();
		fullImage.addStyleName("maxWidth100 maxHeight100 margin-left-20");
		fullImage.addErrorHandler(new ErrorHandler() {
			@Override
		    public void onError(ErrorEvent event) {
				presenter.imagePreviewLoadFailed(event);
		    }
		});
		add(fullImage);
		fullImage.setUrl(fullFileUrl);
	}
	
	@Override
	public void showLoading() {
		clear();
		add(new HTMLPanel(DisplayUtils.getLoadingHtml(sageImageBundle)));
	}
	@Override
	public void setPreviewWidget(Widget w) {
		clear();
		add(w.asWidget());
	}
	
	@Override
	public void setCodePreview(String code) {
		clear();
		add(new HTMLPanel(getCodeHtml(code)));
		synapseJSNIUtils.highlightCodeBlocks();
		isCode = true;
	}
	
	private String getCodeHtml(String code) {
		StringBuilder sb = new StringBuilder();
		sb.append("<pre style=\"overflow:auto;white-space:pre;\"><code style=\"background-color:white;\">");
		sb.append(code);
		sb.append("</code></pre>");
		return sb.toString();
	}
	
	@Override<commit_msg>only support full-screen modal for image preview<commit_after>package org.sagebionetworks.web.client.widget.entity;

import org.gwtbootstrap3.client.ui.html.Div;
import org.sagebionetworks.web.client.DisplayUtils;
import org.sagebionetworks.web.client.SageImageBundle;
import org.sagebionetworks.web.client.SynapseJSNIUtils;
import org.sagebionetworks.web.client.widget.modal.Dialog;

import org.sagebionetworks.web.client.utils.Callback;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
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.ErrorEvent;
import com.google.gwt.event.dom.client.ErrorHandler;
import com.google.gwt.event.dom.client.LoadEvent;
import com.google.gwt.event.dom.client.LoadHandler;
import com.google.gwt.event.logical.shared.AttachEvent;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.user.client.ui.Frame;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;

public class PreviewWidgetViewImpl extends FlowPanel implements PreviewWidgetView, IsWidget{
	private Presenter presenter;
	private SynapseJSNIUtils synapseJSNIUtils;
	private boolean isCode;
	private SageImageBundle sageImageBundle;
	private Dialog previewDialog;
	private Widget dialogContent;
	@Inject
	public PreviewWidgetViewImpl(SynapseJSNIUtils synapseJsniUtils, 
			SageImageBundle sageImageBundle, 
			final Dialog previewDialog) {
		this.synapseJSNIUtils = synapseJsniUtils;
		this.sageImageBundle = sageImageBundle;
		this.previewDialog = previewDialog;
		previewDialog.configure("", null, "Close", new Dialog.Callback() {
			@Override
			public void onDefault() {
				hideFullscreenPreview();
			}
			
			@Override
			public void onPrimary() {
			}
		}, false);
		previewDialog.addStyleName("modal-fullscreen");
	}
	
	private void showFullscreenPreview() {
		dialogContent = getWidget(0);
		dialogContent.removeFromParent();
		Div panel = new Div();
		panel.addStyleName("margin-right-20");
		panel.add(dialogContent);
		previewDialog.add(panel);
		previewDialog.show();
	}
	private void hideFullscreenPreview() {
		dialogContent.removeFromParent();
		add(dialogContent);
		previewDialog.hide();
	}
	
	@Override
	public void setPresenter(Presenter presenter) {
		this.presenter = presenter;
	}
	
	@Override
	public Widget asWidget() {
		return this;
	}
	
	@Override
	public void setImagePreview(final String fullFileUrl) {
		clear();
		Image fullImage = new Image();
		fullImage.addStyleName("imageButton maxWidth100 maxHeight100 margin-left-20");
		fullImage.addErrorHandler(new ErrorHandler() {
			@Override
		    public void onError(ErrorEvent event) {
				presenter.imagePreviewLoadFailed(event);
		    }
		});
		add(fullImage);
		fullImage.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				showFullscreenPreview();
			}
		});
		fullImage.setUrl(fullFileUrl);
	}
	
	@Override
	public void showLoading() {
		clear();
		add(new HTMLPanel(DisplayUtils.getLoadingHtml(sageImageBundle)));
	}
	@Override
	public void setPreviewWidget(Widget w) {
		clear();
		add(w.asWidget());
	}
	
	@Override
	public void setCodePreview(String code) {
		clear();
		add(new HTMLPanel(getCodeHtml(code)));
		synapseJSNIUtils.highlightCodeBlocks();
		isCode = true;
	}
	
	private String getCodeHtml(String code) {
		StringBuilder sb = new StringBuilder();
		sb.append("<pre style=\"overflow:auto;white-space:pre;\"><code style=\"background-color:white;\">");
		sb.append(code);
		sb.append("</code></pre>");
		return sb.toString();
	}
	
	@Override
{'fraction_non_alphanumeric': 0.11880060728744939, 'fraction_numerical': 0.002909919028340081, 'mean_word_length': 5.113689095127611, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '5400032', 'n_tokens_mistral': 2753, 'n_tokens_neox': 2548, 'n_words': 439}