<commit_before>package com.christophdietze.jack.client.view;

import com.christophdietze.jack.client.presenter.PromotionPresenter;
import com.christophdietze.jack.client.resources.MyClientBundle;
import com.christophdietze.jack.client.resources.MyCss;
import com.christophdietze.jack.client.resources.PieceImageProvider;
import com.christophdietze.jack.client.util.UiUtils;
import com.christophdietze.jack.shared.board.ChessUtils;
import com.christophdietze.jack.shared.board.Piece;
import com.christophdietze.jack.shared.board.PieceType;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.CloseEvent;
import com.google.gwt.event.logical.shared.CloseHandler;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.PopupPanel.PositionCallback;
import com.google.inject.Inject;
import com.google.inject.Singleton;

/**
 * <p>
 * <img class='gallery' src='doc-files/PromotionMoveEvent.jpg'>
 * </p>
 */
@Singleton
public class PromotionView implements PromotionPresenter.View {

	private static MyCss CSS = MyClientBundle.CSS;

	private PromotionPresenter model;
	private BoardPanel boardView;
	private PopupPanel whitePopupPanel;
	private PopupPanel blackPopupPanel;
	private boolean pieceSelected = false;

	@Inject
	public PromotionView(PromotionPresenter model, BoardPanel boardView) {
		this.model = model;
		this.boardView = boardView;

		whitePopupPanel = createPopupPanel(true);
		blackPopupPanel = createPopupPanel(false);

		model.bindView(this);
	}

	@Override
	public void showPopup(int toIndex) {
		pieceSelected = false;
		int rank = ChessUtils.toRank(toIndex);
		assert rank == 0 || rank == 7;
		final PopupPanel popup = rank == 0 ? blackPopupPanel : whitePopupPanel;
		final Widget reference = boardView.getSquares()[toIndex];
		popup.setPopupPositionAndShow(new PositionCallback() {
			public void setPosition(int offsetWidth, int offsetHeight) {
				UiUtils.setPopupPositionAtTopLeft(popup, reference);
			}
		});
	}

	private PopupPanel createPopupPanel(boolean isWhite) {
		final PopupPanel popupPanel = new PopupPanel(true);<commit_msg>refactoring<commit_after>package com.christophdietze.jack.client.view;

import com.christophdietze.jack.client.presenter.PromotionPresenter;
import com.christophdietze.jack.client.resources.MyClientBundle;
import com.christophdietze.jack.client.resources.MyCss;
import com.christophdietze.jack.client.resources.PieceImageProvider;
import com.christophdietze.jack.client.util.UiUtils;
import com.christophdietze.jack.shared.board.ChessUtils;
import com.christophdietze.jack.shared.board.Piece;
import com.christophdietze.jack.shared.board.PieceType;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.CloseEvent;
import com.google.gwt.event.logical.shared.CloseHandler;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.PopupPanel.PositionCallback;
import com.google.inject.Inject;
import com.google.inject.Singleton;

/**
 * <p>
 * <img class='gallery' src='doc-files/PromotionMoveEvent.jpg'>
 * </p>
 */
@Singleton
public class PromotionView implements PromotionPresenter.View {

	private static MyCss CSS = MyClientBundle.CSS;

	private PromotionPresenter model;
	private BoardPanel boardPanel;
	private PopupPanel whitePopupPanel;
	private PopupPanel blackPopupPanel;
	private boolean pieceSelected = false;

	@Inject
	public PromotionView(PromotionPresenter model, BoardPanel boardView) {
		this.model = model;
		this.boardPanel = boardView;

		whitePopupPanel = createPopupPanel(true);
		blackPopupPanel = createPopupPanel(false);

		model.bindView(this);
	}

	@Override
	public void showPopup(int toIndex) {
		pieceSelected = false;
		int rank = ChessUtils.toRank(toIndex);
		assert rank == 0 || rank == 7;
		final PopupPanel popup = rank == 0 ? blackPopupPanel : whitePopupPanel;
		final Widget reference = boardPanel.getSquares()[toIndex];
		popup.setPopupPositionAndShow(new PositionCallback() {
			public void setPosition(int offsetWidth, int offsetHeight) {
				UiUtils.setPopupPositionAtTopLeft(popup, reference);
			}
		});
	}

	private PopupPanel createPopupPanel(boolean isWhite) {
		final PopupPanel popupPanel = new PopupPanel(true);
{'fraction_non_alphanumeric': 0.10567177054129825, 'fraction_numerical': 0.0012939400474444684, 'mean_word_length': 5.712011577424023, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '830265', 'n_tokens_mistral': 1559, 'n_tokens_neox': 1506, 'n_words': 263}