<commit_before>package eu.ydp.empiria.player.client.controller;

import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.Style;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import eu.ydp.empiria.player.client.preloader.view.ProgressBundle;
import eu.ydp.gwtutil.client.proxy.RootPanelDelegate;
import eu.ydp.gwtutil.client.proxy.WindowDelegate;

@Singleton
public class ContentPreloader {

    private static final String MAIN_PRELOADER_ID = "mainPreloader";
    private final RootPanelDelegate rootPanelDelegate;

    private final WindowDelegate windowDelegate;
    private final ProgressBundle progressBundle;

    private Image mainPreloader;

    @Inject
    public ContentPreloader(ProgressBundle progressBundle, WindowDelegate windowDelegate, RootPanelDelegate rootPanelDelegate) {
        this.progressBundle = progressBundle;
        this.windowDelegate = windowDelegate;
        this.rootPanelDelegate = rootPanelDelegate;
    }

    public void setPreloader() {
        RootPanel preloaderWidget = rootPanelDelegate.getRootPanel(MAIN_PRELOADER_ID);
        if (preloaderWidget == null) {
            ImageResource progressImage = progressBundle.getProgressImage();
            mainPreloader = new Image(progressImage);
        } else {
            mainPreloader = Image.wrap(preloaderWidget.getElement());
        }
        RootPanel rootPanel = rootPanelDelegate.getRootPanel();
        rootPanel.add(mainPreloader);

        int halfWidth = windowDelegate.getClientWidth() / 2;
        int halfHeight = windowDelegate.getClientHeight() / 2;
        centerMainPreloader(halfWidth, halfHeight, mainPreloader.getElement());
    }

    private void centerMainPreloader(int x, int y, Element preloaderElement) {
        preloaderElement.setId(MAIN_PRELOADER_ID);
        preloaderElement.getStyle().setPosition(Style.Position.ABSOLUTE);
        int leftOffset = x - preloaderElement.getOffsetWidth() / 2;
        preloaderElement.getStyle().setLeft(leftOffset, Style.Unit.PX);
        int topOffset = y - preloaderElement.getOffsetHeight() / 2;
        preloaderElement.getStyle().setTop(topOffset, Style.Unit.PX);
    }

    public void removePreloader() {
        if (mainPreloader.isAttached()) {
            mainPreloader.removeFromParent();
        }
    }
}<commit_msg>[YPUB-7352] Workaround for gwt test cases<commit_after>package eu.ydp.empiria.player.client.controller;

import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.Style;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import eu.ydp.empiria.player.client.preloader.view.ProgressBundle;
import eu.ydp.gwtutil.client.proxy.RootPanelDelegate;
import eu.ydp.gwtutil.client.proxy.WindowDelegate;

@Singleton
public class ContentPreloader {

    private static final String MAIN_PRELOADER_ID = "mainPreloader";
    private final RootPanelDelegate rootPanelDelegate;

    private final WindowDelegate windowDelegate;
    private final ProgressBundle progressBundle;

    private Image mainPreloader;

    @Inject
    public ContentPreloader(ProgressBundle progressBundle, WindowDelegate windowDelegate, RootPanelDelegate rootPanelDelegate) {
        this.progressBundle = progressBundle;
        this.windowDelegate = windowDelegate;
        this.rootPanelDelegate = rootPanelDelegate;
    }

    public void setPreloader() {
        RootPanel preloaderWidget = rootPanelDelegate.getRootPanel(MAIN_PRELOADER_ID);
        if (preloaderWidget == null) {
            ImageResource progressImage = progressBundle.getProgressImage();
            mainPreloader = new Image(progressImage);
        } else {
            mainPreloader = Image.wrap(preloaderWidget.getElement());
        }
        RootPanel rootPanel = rootPanelDelegate.getRootPanel();
        rootPanel.add(mainPreloader);

        int halfWidth = windowDelegate.getClientWidth() / 2;
        int halfHeight = windowDelegate.getClientHeight() / 2;
        centerMainPreloader(halfWidth, halfHeight, mainPreloader.getElement());
    }

    private void centerMainPreloader(int x, int y, Element preloaderElement) {
        preloaderElement.setId(MAIN_PRELOADER_ID);
        preloaderElement.getStyle().setPosition(Style.Position.ABSOLUTE);
        int leftOffset = x - preloaderElement.getOffsetWidth() / 2;
        preloaderElement.getStyle().setLeft(leftOffset, Style.Unit.PX);
        int topOffset = y - preloaderElement.getOffsetHeight() / 2;
        preloaderElement.getStyle().setTop(topOffset, Style.Unit.PX);
    }

    public void removePreloader() {
        if (mainPreloader != null && mainPreloader.isAttached()) {
            mainPreloader.removeFromParent();
        }
    }
}
{'fraction_non_alphanumeric': 0.09225535321192715, 'fraction_numerical': 0.0024014408645187113, 'mean_word_length': 3.728476821192053, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4742886', 'n_tokens_mistral': 1402, 'n_tokens_neox': 1419, 'n_words': 255}