package eu.ydp.empiria.player.client.controller.feedback.player;

import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.dom.client.Style.Visibility;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.RootPanel;

import eu.ydp.empiria.player.client.module.media.MediaWrapper;

/**
 * This is needed to enable native events on media object. 
 * In other case sound can be heard, but will not produce any @HTML5MediaEventsType events.
 * Panel is hidden it because contains ugly, native controls.
 */
public class MediaObjectToDocumentInsertManager {

	public void addMediaToDocumentAndHideControls(Object object) {
		FlowPanel hiddenPanel = createPanel();
		hidePanel(hiddenPanel);
		addMediaObjectToPanel(object, hiddenPanel);
		addPanelToRootPanel(hiddenPanel);
	}

	private void addPanelToRootPanel(FlowPanel hiddenPanel) {
		RootPanel.get().add(hiddenPanel);
	}

	private void addMediaObjectToPanel(Object object, FlowPanel hiddenPanel) {
		MediaWrapper<?> mediaWrapper = (MediaWrapper<?>) object;
		hiddenPanel.add(mediaWrapper.getMediaObject());
	}

	private FlowPanel createPanel() {
		return new FlowPanel();
	}

	private void hidePanel(FlowPanel hiddenPanel) {
		hiddenPanel.getElement().getStyle().setWidth(1d, Unit.PX);
		hiddenPanel.getElement().getStyle().setHeight(1d, Unit.PX);
		hiddenPanel.getElement().getStyle().setVisibility(Visibility.VISIBLE);
	}

}

@@ -57,24 +57,65 @@
 .player;%0D%0A%0D%0A
+import com.google.gwt.dom.client.Style;%0D%0A
 import com.g
@@ -200,16 +200,60 @@
 ility;%0D%0A
+import com.google.gwt.user.client.Element;%0D%0A
 import c
@@ -341,16 +341,62 @@
 tPanel;%0D
+%0Aimport com.google.gwt.user.client.ui.Widget;%0D
 %0A%0D%0Aimpor
@@ -786,25 +786,37 @@
 rols(Object 
-o
+mediaWrapperO
 bject) %7B%0D%0A%09%09
@@ -821,31 +821,25 @@
 %09%09FlowPanel 
-hiddenP
+p
 anel = creat
@@ -857,31 +857,25 @@
 %09%09hidePanel(
-hiddenP
+p
 anel);%0D%0A%09%09ad
@@ -898,23 +898,29 @@
 nel(
-object, hiddenP
+mediaWrapperObject, p
 anel
@@ -945,23 +945,17 @@
 otPanel(
-hiddenP
+p
 anel);%0D%0A
@@ -1106,17 +1106,29 @@
 (Object 
-o
+mediaWrapperO
 bject, F
@@ -1128,39 +1128,33 @@
 ject, FlowPanel 
-hiddenP
+p
 anel) %7B%0D%0A%09%09Media
@@ -1201,64 +1201,153 @@
 ?%3E) 
-object;%0D%0A%09%09hiddenPanel.add(mediaWrapper.getMediaObject()
+mediaWrapperObject;%0D%0A%09%09Object mediaObject = mediaWrapper.getMediaObject();%0D%0A%09%09Widget mediaWidget = (Widget) mediaObject;%0D%0A%09%09panel.add(mediaWidget
 );%0D%0A
@@ -1447,39 +1447,33 @@
 Panel(FlowPanel 
-hiddenP
+p
 anel) %7B%0D%0A%09%09hidde
@@ -1471,105 +1471,127 @@
 %0D%0A%09%09
-hiddenPanel.getElement().getStyle().setWidth(1d, Unit.PX);%0D%0A%09%09hiddenPanel.getElement().getS
+Element element = panel.getElement();%0D%0A%09%09Style style = element.getStyle();%0D%0A%09%09%0D%0A%09%09style.setWidth(1d, Unit.PX);%0D%0A%09%09s
 tyle
-()
 .set
@@ -1618,43 +1618,13 @@
 %0D%0A%09%09
-hiddenPanel.getElement().getS
+s
 tyle
-()
 .set
@@ -1649,15 +1649,14 @@
 ity.
-VISIBLE
+HIDDEN
 );%0D%0A

Clean code - sweeping issue YPUB-5224