1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.templating.editor.client.widget;
35
36
37 import static info.magnolia.templating.editor.client.jsni.JavascriptUtils.getI18nMessage;
38
39 import com.google.gwt.core.client.GWT;
40 import com.google.gwt.event.dom.client.ClickEvent;
41 import com.google.gwt.event.dom.client.ClickHandler;
42 import com.google.gwt.event.dom.client.HasClickHandlers;
43 import com.google.gwt.event.dom.client.KeyCodes;
44 import com.google.gwt.event.dom.client.LoadEvent;
45 import com.google.gwt.event.dom.client.LoadHandler;
46 import com.google.gwt.event.shared.HandlerRegistration;
47 import com.google.gwt.user.client.Event;
48 import com.google.gwt.user.client.Event.NativePreviewEvent;
49 import com.google.gwt.user.client.ui.Frame;
50 import com.google.gwt.user.client.ui.PopupPanel;
51
52
53
54
55
56
57 public class PreviewChannel extends PopupPanel implements ClickHandler, HasClickHandlers {
58
59 private String landscapeCssStyleSuffix = "Landscape";
60 private String portraitCssStyleSuffix = "Portrait";
61 private String deviceType = "smartphone";
62
63
64
65
66 public enum Orientation {
67 PORTRAIT, LANDSCAPE
68 }
69
70 private Orientation currentOrientation = Orientation.LANDSCAPE;
71
72 public PreviewChannel(final String url, final Orientation orientation, final String deviceType) {
73 this.deviceType = deviceType;
74 this.currentOrientation = orientation;
75
76 setStylePrimaryName("mobilePreview");
77
78 addStyleName(orientation == Orientation.LANDSCAPE ? deviceType + landscapeCssStyleSuffix : deviceType + portraitCssStyleSuffix);
79
80 setAnimationEnabled(true);
81 setAutoHideEnabled(true);
82 setModal(true);
83 setGlassEnabled(true);
84 setGlassStyleName("mgnlEditorPreviewBackground");
85
86 getElement().setTitle(getI18nMessage("editor.preview.rotate.js"));
87
88 addClickHandler(this);
89
90 final Frame iframe = new Frame(url);
91 iframe.setStylePrimaryName("mobilePreviewIframe");
92 iframe.addLoadHandler(new LoadHandler() {
93
94 @Override
95 public void onLoad(LoadEvent event) {
96
97
98 }
99 });
100
101 add(iframe);
102 }
103
104 public Orientation getOrientation() {
105 return currentOrientation;
106 }
107
108 public String getDeviceType() {
109 return deviceType;
110 }
111
112 public String getLandscapeCssStyleSuffix() {
113 return landscapeCssStyleSuffix;
114 }
115
116 public String getPortraitCssStyleSuffix() {
117 return portraitCssStyleSuffix;
118 }
119
120 @Override
121 public void onClick(ClickEvent event) {
122
123 GWT.log("currentOrientation is "+currentOrientation.toString());
124
125 if(currentOrientation == Orientation.LANDSCAPE) {
126 currentOrientation = Orientation.PORTRAIT;
127 removeStyleName(getDeviceType() + landscapeCssStyleSuffix);
128 addStyleName(getDeviceType() + portraitCssStyleSuffix);
129 } else {
130 currentOrientation = Orientation.LANDSCAPE;
131 removeStyleName(getDeviceType() + portraitCssStyleSuffix);
132 addStyleName(getDeviceType() + landscapeCssStyleSuffix);
133 }
134 center();
135 }
136
137 @Override
138 public HandlerRegistration addClickHandler(ClickHandler handler) {
139 return addDomHandler(handler, ClickEvent.getType());
140 }
141
142 @Override
143
144 protected void onPreviewNativeEvent(NativePreviewEvent event) {
145 super.onPreviewNativeEvent(event);
146 if (event.getTypeInt() == Event.ONKEYDOWN && event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE) {
147 hide();
148 }
149 }
150 }