List of usage examples for com.google.gwt.user.client Window getClientWidth
public static int getClientWidth()
From source file:next.i.view.widgets.XImage.java
License:Apache License
/** * Creates an image with a specified URL. The load event will be fired once * the image at the given URL has been retrieved by the browser. * //w w w. j a va2s. com * @param url * the URL of the image to be displayed */ public XImage(String url) { super(url); addLoadHandler(new LoadHandler() { @Override public void onLoad(LoadEvent event) { Element element = event.getRelativeElement(); if (element == XImage.this.getElement()) { int originalHeight = XImage.this.getOffsetHeight(); int originalWidth = XImage.this.getOffsetWidth(); int clientW = Window.getClientWidth(); int clientH = Window.getClientHeight(); // Window.alert("originalHeight=" + originalHeight + // ", originalWidth=" + originalWidth); int size = 0; if (clientH > clientW) { size = clientW; } else { size = clientH; } size = size - 20/* padding */; // FIXME add orientation listener if (originalHeight > originalWidth) { XImage.this.setHeight(size + "px"); } else { XImage.this.setWidth(size + "px"); } } } }); }
From source file:next.interfaces.controller.DemoUtils.java
License:Apache License
public static void openGit(String source, final String url) { final XFlexTable tbl = new XFlexTable(); final XButton btnCopy = new XButton("Copy", XButtonType.Shadow); btnCopy.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { markText(tbl.getWidget(0, 0).getElement()); }// ww w.j ava 2 s . c o m }); final XButton btnGit = new XButton("View in GitHub", XButtonType.Shadow); btnGit.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { // Window.open(Globals.GIT_HOST + url + ".java", "_tab", ""); // Utils.loadUrl(Globals.GIT_HOST + url + ".java"); // This click handler seems to work best openURL(Globals.GIT_HOST + url + ".java"); } }); tbl.getElement().setId("codeText"); String codeUrl = url.substring(url.lastIndexOf("/") + 1); HTTP.doGet(Globals.SOURCE_PATH.replace("$", codeUrl), new ResponseReader() { public void onSuccess(Response resp) { tbl.setWidget(0, 0, new HTML("<pre>" + toHighlighted(resp.getText()) + "</pre>")); tbl.setWidget(1, 0, btnCopy); tbl.setWidget(1, 1, btnGit); } }); final XPopup popup = new XPopup(); XDragScrollView view = new XDragScrollView(); view.addStyleName("codeDemo"); tbl.setWidget(0, 0, new XSpinner()); tbl.setCellSpacing(10); FlexCellFormatter fcf = tbl.getFlexCellFormatter(); fcf.setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_TOP); fcf.setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_LEFT); fcf.setVerticalAlignment(1, 0, HasVerticalAlignment.ALIGN_TOP); fcf.setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_RIGHT); fcf.setVerticalAlignment(1, 1, HasVerticalAlignment.ALIGN_TOP); fcf.setHorizontalAlignment(1, 1, HasHorizontalAlignment.ALIGN_LEFT); fcf.setColSpan(0, 0, 2); fcf.setWidth(1, 0, "50%"); fcf.setWidth(1, 1, "50%"); view.add(tbl); int h = Window.getClientHeight(); int w = Window.getClientWidth(); popup.setWidget(view); // mobile phone if (h + w < 1000) { popup.setTop("35px"); popup.setRight("5%"); popup.setLeft("5%"); popup.setBottom("40px"); } else { popup.setTop("35px"); popup.setRight("5%"); popup.setLeft("10%"); popup.setBottom("30%"); } popup.show(); }
From source file:next.keyboard.ui.Main.java
License:Apache License
void initModuleLoad() { final RootPanel rootPanel = RootPanel.get("root"); rootPanel.setVisible(false);//from w ww. j av a2 s . c o m final UiGinjector ctx = UiGinjector.INSTANCE; // init and make it visible // ctx.getUiSingleton().getWalletLeftMenu().show(); rootPanel.add(new TextBoxWidget(ctx.getEventBus())); rootPanel.setVisible(true); RootPanel loadingPanel = RootPanel.get("loading"); loadingPanel.setVisible(false); // Used for debuggin only Window.addResizeHandler(new ResizeHandler() { @Override public void onResize(ResizeEvent event) { int cH = Window.getClientHeight(); int cW = Window.getClientWidth(); int scH = Window.getScrollTop(); int scL = Window.getScrollLeft(); Logger.debug("clientHeight:" + cH + ", clientWidth:" + cW + "| scrollTop:" + scH + ", scrollLeft:" + scL); } }); listenEventUpdates(ctx.getEventBus()); // ctx.getEventBus().fireEvent(new LsShowSportsEvent(true)); // RootPanel.get("root").setVisible(false); }
From source file:next.tablet.client.TabletEntryPoint.java
License:Apache License
public void initModuleLoad() { final RootPanel rootPanel = RootPanel.get("root"); rootPanel.setVisible(false);/*from w w w. j ava 2 s. c o m*/ final UiGinjector ctx = UiGinjector.INSTANCE; // init and make it visible ctx.getUiSingleton().getWalletLeftMenu().show(); ctx.getUiSingleton().getTopMenu().show(); ctx.getUiSingleton().getTopMenu().getBackCommand().execute(); ctx.getUiSingleton().getImagePage(); // init ctx.getEventBus().fireEvent(new ShowBackButtonEvent(Type.GAMES)); rootPanel.setVisible(true); RootPanel loadingPanel = RootPanel.get("loading"); loadingPanel.setVisible(false); // Used for debuggin only Window.addResizeHandler(new ResizeHandler() { @Override public void onResize(ResizeEvent event) { int cH = Window.getClientHeight(); int cW = Window.getClientWidth(); int scH = Window.getScrollTop(); int scL = Window.getScrollLeft(); Logger.debug("clientHeight:" + cH + ", clientWidth:" + cW + "| scrollTop:" + scH + ", scrollLeft:" + scL); } }); // listenForEventUpdates(); // ctx.getEventBus().fireEvent(new LsShowSportsEvent(true)); // RootPanel.get("root").setVisible(false); Timer t2 = new Timer() { public void run() { ctx.getUiSingleton().getNotificationPage().doShow(); } }; t2.schedule(5000); }
From source file:nl.mpi.tg.eg.experiment.client.presenter.AbstractStimulusPresenter.java
License:Open Source License
protected void touchInputReportSubmit(final Stimulus currentStimulus, final int dataChannel) { if (touchInputCapture != null) { final String touchReport = touchInputCapture.getTouchReport(Window.getClientWidth(), Window.getClientHeight()); submissionService.submitTagPairValue(userResults.getUserData().getUserId(), getSelfTag(), dataChannel, "touchInputReport", currentStimulus.getUniqueId(), touchReport, duration.elapsedMillis()); // // todo: perhaps this is a bit heavy on local storage but at least only one touch event would be stored // JSONObject storedStimulusJSONObject = localStorage.getStoredJSONObject(userResults.getUserData().getUserId(), currentStimulus); // storedStimulusJSONObject = (storedStimulusJSONObject == null) ? new JSONObject() : storedStimulusJSONObject; // storedStimulusJSONObject.put("touchInputReport", new JSONString(touchReport)); // localStorage.setStoredJSONObject(userResults.getUserData().getUserId(), currentStimulus, storedStimulusJSONObject); }/*from w ww. j a v a 2 s . c o m*/ touchInputCapture = null; }
From source file:nl.mpi.tg.eg.experiment.client.view.AbstractView.java
License:Open Source License
public AbstractView() { super(Style.Unit.PX); setWidth(Window.getClientWidth() + "px"); setHeight(Window.getClientHeight() + "px"); Window.addResizeHandler(new ResizeHandler() { @Override//from w w w.j a va 2 s . co m public void onResize(ResizeEvent event) { int height = event.getHeight(); setHeight(height + "px"); int width = event.getWidth(); setWidth(width + "px"); parentResized(height, width, "px"); } }); }
From source file:nl.mpi.tg.eg.experiment.client.view.AbstractView.java
License:Open Source License
public void resizeView() { int height = Window.getClientHeight(); setHeight(height + "px"); int width = Window.getClientWidth(); setWidth(width + "px"); parentResized(height, width, "px"); }
From source file:nl.mpi.tg.eg.experiment.client.view.ColourPickerCanvasView.java
License:Open Source License
public ColourPickerCanvasView() throws CanvasError { setStylePrimaryName("stimulusScreen"); final int clientHeight = Window.getClientHeight(); final int clientWidth = Window.getClientWidth(); final int minClient = (clientHeight > clientWidth) ? clientWidth : clientHeight; stimulusTextHeight = (int) (minClient * 0.08); selectedColourPanelHeight = (int) (minClient * 0.25); selectedColourPanelWidth = (int) (minClient * 0.47); // buttonTextHeight = (int) (minClient * 0.05); buttonHeight = (int) (minClient * 0.1); buttonWidth = (int) (minClient * 0.47); stimulusPanel = new VerticalPanel(); stimulusPanel.addStyleName("stimulusPanel"); stimulusPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); outerGrid = new Grid(2, 2); innerGrid = new Grid(6, 2); pickerPanel = new Grid(1, 2); progressPanel = new Grid(1, 3); progressPanel.setWidth("100%"); infoButton = new Button(); infoButton.addStyleName("stimulusHelpButton"); // infoButton.getElement().getStyle().setFontSize(buttonTextHeight, Unit.PX); selectedColourPanel = new VerticalPanel(); progressLabel = new Label(); progressLabel.addStyleName("stimulusProgressLabel"); mainCanvas = Canvas.createIfSupported(); hueCanvas = Canvas.createIfSupported(); if (mainCanvas == null || hueCanvas == null) { throw new CanvasError("Failed to create a canvas for the stimulus screen."); } else {//from ww w .j a v a2s . c o m pickerPanel.setCellPadding(5); pickerPanel.setWidget(0, 0, mainCanvas); pickerPanel.setWidget(0, 1, hueCanvas); final Label selectedColourLabel = new Label(""); selectedColourLabel.setHeight(selectedColourPanelHeight + "px"); selectedColourLabel.setWidth(selectedColourPanelWidth + "px"); selectedColourPanel.add(selectedColourLabel); mainCanvas.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { event.preventDefault(); setColour(event, mainCanvas, selectedColourPanel); } }); hueCanvas.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { event.preventDefault(); setHue(event, hueCanvas); setColour(event, hueCanvas, selectedColourPanel); } }); mainCanvas.addTouchStartHandler(new TouchStartHandler() { @Override public void onTouchStart(TouchStartEvent event) { event.preventDefault(); setColour(event, mainCanvas, selectedColourPanel); } }); mainCanvas.addTouchMoveHandler(new TouchMoveHandler() { @Override public void onTouchMove(TouchMoveEvent event) { event.preventDefault(); setColour(event, mainCanvas, selectedColourPanel); } }); mainCanvas.addTouchEndHandler(new TouchEndHandler() { @Override public void onTouchEnd(TouchEndEvent event) { event.preventDefault(); setColour(event, mainCanvas, selectedColourPanel); } }); hueCanvas.addTouchStartHandler(new TouchStartHandler() { @Override public void onTouchStart(TouchStartEvent event) { event.preventDefault(); setHue(event, hueCanvas); setColour(event, hueCanvas, selectedColourPanel); } }); hueCanvas.addTouchMoveHandler(new TouchMoveHandler() { @Override public void onTouchMove(TouchMoveEvent event) { event.preventDefault(); setHue(event, hueCanvas); setColour(event, hueCanvas, selectedColourPanel); } }); hueCanvas.addTouchEndHandler(new TouchEndHandler() { @Override public void onTouchEnd(TouchEndEvent event) { event.preventDefault(); setHue(event, hueCanvas); setColour(event, hueCanvas, selectedColourPanel); } }); } progressPanel.setWidget(0, 1, progressLabel); progressPanel.setWidget(0, 2, infoButton); progressPanel.setStylePrimaryName("headerPanel"); progressPanel.getColumnFormatter().setWidth(1, "100%"); addNorth(progressPanel, 50); add(outerGrid); }
From source file:nl.mpi.tg.eg.experiment.client.view.ComplexView.java
License:Open Source License
protected void addSizeAttributes(final Element imageElement, int percentOfPage, int maxHeight, int maxWidth) { imageElement.getStyle().setProperty("imageOrientation", "from-image"); // the image-orientation style is not supported by most browsers yet if (percentOfPage > 0) { scaledImagesList.add(new ImageEntry(imageElement, percentOfPage)); // image.getElement().getStyle().setProperty("width", percentOfPage + "%"); // image.getElement().getStyle().setProperty("height", "auto"); resizeImage(imageElement, Window.getClientHeight(), Window.getClientWidth(), percentOfPage); } else {// w w w . ja v a 2 s. c o m if (maxWidth > 0) { imageElement.getStyle().setProperty("maxWidth", maxWidth + "%"); } if (maxHeight > 0) { imageElement.getStyle().setProperty("maxHeight", maxHeight + "%"); } } }
From source file:nl.mpi.tg.eg.experiment.client.view.ComplexView.java
License:Open Source License
public void showHtmlPopup(String popupText, final PresenterEventListner... buttonListeners) { final PopupPanel popupPanel = new PopupPanel(false); // the close action to this panel causes background buttons to be clicked popupPanel.setGlassEnabled(true);/*from ww w . j av a 2 s . c o m*/ popupPanel.setStylePrimaryName("svgPopupPanel"); final VerticalPanel popupverticalPanel = new VerticalPanel(); final HTML htmlText = new HTML(new SafeHtmlBuilder().appendHtmlConstant(popupText).toSafeHtml()); htmlText.setStylePrimaryName("popupTextBox"); popupverticalPanel.add(htmlText); popupverticalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); final HorizontalPanel buttonPanel = new HorizontalPanel(); for (final PresenterEventListner buttonListener : buttonListeners) { final SingleShotEventListner okSingleShotEventListner = new SingleShotEventListner() { @Override protected void singleShotFired() { popupPanel.hide(); buttonListener.eventFired(null, null); } }; final Button okButton = new Button(buttonListener.getLabel()); if (buttonListener.getStyleName() != null && !buttonListener.getStyleName().isEmpty()) { okButton.addStyleName(buttonListener.getStyleName()); } okButton.addClickHandler(okSingleShotEventListner); okButton.addTouchStartHandler(okSingleShotEventListner); okButton.addTouchMoveHandler(okSingleShotEventListner); okButton.addTouchEndHandler(okSingleShotEventListner); buttonPanel.add(okButton); } popupverticalPanel.add(buttonPanel); popupPanel.setWidget(popupverticalPanel); popupPanel.setPopupPositionAndShow(new PopupPanel.PositionCallback() { @Override public void setPosition(int offsetWidth, int offsetHeight) { final int topPosition = Window.getClientHeight() / 2 - offsetHeight; // topPosition is used to make sure the dialogue is above the half way point on the screen to avoid the software keyboard covering the box // topPosition is also checked to make sure it does not show above the top of the page popupPanel.setPopupPosition(Window.getClientWidth() / 2 - offsetWidth / 2, (topPosition < 0) ? 0 : topPosition); } }); }