List of usage examples for com.google.gwt.user.client Window getScrollLeft
public static int getScrollLeft()
From source file:com.vaadin.v7.client.ui.VSlider.java
License:Apache License
private void setValueByEvent(Event event, boolean updateToServer) { double v = min; // Fallback to min final int coord = getEventPosition(event); final int handleSize, baseSize, baseOffset; if (isVertical()) { handleSize = handle.getOffsetHeight(); baseSize = base.getOffsetHeight(); baseOffset = base.getAbsoluteTop() - Window.getScrollTop() - handleSize / 2; } else {//from w w w .j av a 2s . c o m handleSize = handle.getOffsetWidth(); baseSize = base.getOffsetWidth(); baseOffset = base.getAbsoluteLeft() - Window.getScrollLeft() + handleSize / 2; } if (isVertical()) { v = (baseSize - (coord - baseOffset)) / (double) (baseSize - handleSize) * (max - min) + min; } else { v = (coord - baseOffset) / (double) (baseSize - handleSize) * (max - min) + min; } if (v < min) { v = min; } else if (v > max) { v = max; } setValue(v, updateToServer); }
From source file:com.xpn.xwiki.cbdf.client.CBDF.java
License:Open Source License
/** * This method handles the mouse double click event on any graphic object and in the graphic canvas * @param graphicObject The graphic object which has been double clicked * @param event A reference to the mouse event *///from w ww . j a v a2 s . c om public void mouseDblClicked(GraphicObject graphicObject, Event event) { /** if it's a polyline, then we close it's path and therefore finish it */ if (action.isPolyline() && (curr_obj != null)) { ((Path) this.curr_obj).closePath(); curr_obj = null; aux_obj = null; /** if the user double clicked on a text object, a textbox or the text itself, this method spawns a Textarea above the text in the canvas so that the user can edit the text that was created., */ } else if (action.isSelect() && (graphicObject != null) && (graphicObject.getType() == 7 || graphicObject.getType() == 8)) { this.curr_obj = graphicObject; /** TextArea initialization */ this.editor = new TextArea(); this.editor.setWidth((int) (graphicObject.getBounds().getWidth() + 20) + "px"); this.editor.setHeight((int) (graphicObject.getBounds().getHeight() + 20) + "px"); if (graphicObject.getType() == 7) { this.editor.setText(((Text) graphicObject).getText()); } else { this.editor.setText(((TextBox) graphicObject).text.getText()); } /** We add a keyboard listener to handle the Esc key. In the event of a Esc key, the TextArea should disapear and the text object should be updated. */ this.editor.addKeyboardListener(new KeyboardListenerAdapter() { public void onKeyDown(Widget sender, char keyCode, int modifiers) { if (keyCode == (char) KEY_ESCAPE) { editor.cancelKey(); aux_obj = null; aux_obj = new Text(editor.getText()); if (curr_obj.getType() == 7) { ((Text) aux_obj).setFont(((Text) curr_obj).getFont()); addTextObject(aux_obj, (int) curr_obj.getX(), (int) curr_obj.getY()); canvas.remove(((Text) curr_obj).bounder); } else { ((Text) aux_obj).setFont(((TextBox) curr_obj).text.getFont()); addTextObject(aux_obj, (int) ((TextBox) curr_obj).text.getX(), (int) ((TextBox) curr_obj).text.getY()); canvas.remove(((TextBox) curr_obj).text); } canvas.remove(curr_obj); curr_obj = null; curr_obj = new TextBox(aux_obj.getBounds(), (Text) aux_obj); addTextBox(curr_obj, (int) aux_obj.getBounds().getX(), (int) aux_obj.getBounds().getY()); ((Text) aux_obj).bounder = (TextBox) curr_obj; Color textColor = new Color(aux_obj.getFillColor().getRed(), aux_obj.getFillColor().getGreen(), aux_obj.getFillColor().getBlue(), 0); curr_obj.setFillColor(textColor); curr_obj.setStroke(textColor, 1); aux_obj = null; curr_obj = null; apanel.remove(editor); editor = null; } } }); this.apanel.add(editor, (int) this.curr_obj.getX() + this.canvas.getAbsoluteLeft() - Window.getScrollLeft() - 2, (int) this.curr_obj.getY() + this.canvas.getAbsoluteTop() - Window.getScrollTop() - 2); } }
From source file:com.xpn.xwiki.cbdf.client.CBDF.java
License:Open Source License
/** * This method handles the mouse click event on any graphic object and in the graphic canvas * @param graphicObject The graphic object which has been double clicked * @param event A reference to the mouse event *///w ww . ja v a 2s. c om public void mouseClicked(GraphicObject graphicObject, Event event) { int x, y; /** if there's no graphic Object selected, we unSelect any other that was previously selected */ if (action.isSelect() && (graphicObject == null)) { if (curr_obj != null) { this.unSelect(); this.restoreStyle(); } } else { x = DOM.eventGetClientX(event) - canvas.getAbsoluteLeft() + Window.getScrollLeft(); y = DOM.eventGetClientY(event) - canvas.getAbsoluteTop() + Window.getScrollTop(); if (action.isPolyline() && curr_obj == null) { /* If there is no Polyline object created, starts to draw a Polyline */ curr_obj = new Path(); ((Path) curr_obj).moveTo(x, y); addGraphicObject(curr_obj, 0, 0); this.currentPath = ((Path) this.curr_obj).commands; } } }
From source file:com.xpn.xwiki.cbdf.client.CBDF.java
License:Open Source License
/** * This method handles the mouse mouve event on any graphic object and in the graphic canvas. * Mainly, this class is used to animate the object's creation so that the user can have an idea of the final object before it really creates it. * @param graphicObject The graphic object over which the mouse move has been done * @param event A reference to the mouse event *//*ww w . ja v a 2 s . c o m*/ public void mouseMoved(GraphicObject graphicObject, Event event) { int x, y; x = DOM.eventGetClientX(event) - canvas.getAbsoluteLeft() + Window.getScrollLeft(); y = DOM.eventGetClientY(event) - canvas.getAbsoluteTop() + Window.getScrollTop(); if (action.isSelect()) { /** If the user clicked on the object, it then performs a translation */ if ((isMovable) && (curr_obj != null)) { curr_obj.uTranslate(x - lastPosition[0], y - lastPosition[1]); transformPoints.uTranslate(x - lastPosition[0], y - lastPosition[1]); lastPosition[0] = x; lastPosition[1] = y; /** If the user has clicked on a Transformation Point, it performs the given transformation */ } else if (isTransformable) { transformObject(x, y); } /* Drawing with pencil. This adds a new point to the path */ } else if (action.isPencil() && (curr_obj != null)) { ((Path) curr_obj).lineTo(x, y); /* Drawing a line. This updates the line end point */ } else if (action.isLine() && (curr_obj != null)) { canvas.remove(curr_obj); curr_obj = new Line(0, 0, x - objPosition[0], y - objPosition[1]); addGraphicObject(curr_obj, objPosition[0], objPosition[1]); /* Drawing a rectangle. This updates the rectangle's size and position*/ } else if (action.isRectangle() && (curr_obj != null)) { canvas.remove(curr_obj); /* Lower right corner */ if (x > objPosition[0] && y > objPosition[1]) { curr_obj = new Rect(x - objPosition[0], y - objPosition[1]); addGraphicObject(curr_obj, objPosition[0], objPosition[1]); /* Upper right corner*/ } else if (x > objPosition[0] && y < objPosition[1]) { curr_obj = new Rect(x - objPosition[0], objPosition[1] - y); addGraphicObject(curr_obj, objPosition[0], y); /* Lower left corner*/ } else if (x < objPosition[0] && y > objPosition[1]) { curr_obj = new Rect(objPosition[0] - x, y - objPosition[1]); addGraphicObject(curr_obj, x, objPosition[1]); /* Upper left corner*/ } else if (x < objPosition[0] && y < objPosition[1]) { curr_obj = new Rect(objPosition[0] - x, objPosition[1] - y); addGraphicObject(curr_obj, x, y); } /* Drawing a circle. This updates the circle's diameter */ } else if (action.isCircle() && (curr_obj != null)) { int abs_x = Math.abs(x - objPosition[0]); int abs_y = Math.abs(y - objPosition[1]); canvas.remove(curr_obj); if (abs_x > abs_y) { curr_obj = new Circle(abs_x); } else { curr_obj = new Circle(abs_y); } addGraphicObject(curr_obj, objPosition[0], objPosition[1]); /* Drawing a ellipse. This updates both ellipse's diameters */ } else if (action.isEllipse() && (curr_obj != null)) { canvas.remove(curr_obj); /* Lower right corner */ if (x > objPosition[0] + 1 && y > objPosition[1] + 1) { curr_obj = new Ellipse((x - objPosition[0]) / 2, (y - objPosition[1]) / 2); addGraphicObject(curr_obj, objPosition[0] + ((x - objPosition[0]) / 2), objPosition[1] + ((y - objPosition[1]) / 2)); /* Upper right corner*/ } else if (x > objPosition[0] + 1 && y + 1 < objPosition[1]) { curr_obj = new Ellipse((x - objPosition[0]) / 2, (objPosition[1] - y) / 2); addGraphicObject(curr_obj, objPosition[0] + ((x - objPosition[0]) / 2), objPosition[1] - ((objPosition[1] - y) / 2)); /* Lower left corner*/ } else if (x + 1 < objPosition[0] && y > objPosition[1] + 1) { curr_obj = new Ellipse((objPosition[0] - x) / 2, (y - objPosition[1]) / 2); addGraphicObject(curr_obj, objPosition[0] - ((objPosition[0] - x) / 2), objPosition[1] + ((y - objPosition[1]) / 2)); /* Upper left corner*/ } else if (x + 1 < objPosition[0] && y + 1 < objPosition[1]) { curr_obj = new Ellipse((objPosition[0] - x) / 2, (objPosition[1] - y) / 2); addGraphicObject(curr_obj, objPosition[0] - ((objPosition[0] - x) / 2), objPosition[1] - ((objPosition[1] - y) / 2)); } /** Drawing a TextBox. This updates the TextBox's size and position. */ } else if (action.isTextBox() && (curr_obj != null)) { canvas.remove(curr_obj); /* Lower right corner */ if (x > objPosition[0] && y > objPosition[1]) { curr_obj = new com.objetdirect.tatami.client.gfx.TextBox(x - objPosition[0], y - objPosition[1], null); addTextBox(curr_obj, objPosition[0], objPosition[1]); /* Upper right corner*/ } else if (x > objPosition[0] && y < objPosition[1]) { curr_obj = new com.objetdirect.tatami.client.gfx.TextBox(x - objPosition[0], objPosition[1] - y, null); addTextBox(curr_obj, objPosition[0], y); /* Lower left corner*/ } else if (x < objPosition[0] && y > objPosition[1]) { curr_obj = new com.objetdirect.tatami.client.gfx.TextBox(objPosition[0] - x, y - objPosition[1], null); addTextBox(curr_obj, x, objPosition[1]); /* Upper left corner*/ } else if (x < objPosition[0] && y < objPosition[1]) { curr_obj = new com.objetdirect.tatami.client.gfx.TextBox(objPosition[0] - x, objPosition[1] - y, null); addTextBox(curr_obj, x, y); } /** Drawing a polyline, this updates the current point's position */ } else if (this.action.isPolyline() && (this.curr_obj != null)) { if (DOM.eventGetButton(event) == Event.BUTTON_LEFT) { this.canvas.remove(this.curr_obj); this.curr_obj = new Path(this.currentPath); ((Path) this.curr_obj).smoothCurveTo(x, y, lastPosition[0], lastPosition[1]); this.addGraphicObject(this.curr_obj, 0, 0); } else { this.canvas.remove(this.curr_obj); this.curr_obj = new Path(this.currentPath); ((Path) this.curr_obj).lineTo(x, y); this.addGraphicObject(this.curr_obj, 0, 0); } } }
From source file:com.xpn.xwiki.cbdf.client.CBDF.java
License:Open Source License
/** * This method handles the mouse press event on any graphic object and in the graphic canvas. * It's mainly used to start creating objects and also to select objects. * @param graphicObject The graphic object which has been pressed * @param event A reference to the mouse event *///from w ww . j a v a 2 s. c o m public void mousePressed(GraphicObject graphicObject, Event event) { int x, y; x = DOM.eventGetClientX(event) - canvas.getAbsoluteLeft() + Window.getScrollLeft(); y = DOM.eventGetClientY(event) - canvas.getAbsoluteTop() + Window.getScrollTop(); if (!action.isSelect() && !action.isPolyline() && !action.isTextBox() && !action.isPencil()) { switch (action.getAction()) { case Action.LINE: /* Starts to draw a line */ curr_obj = new Line(0, 0, 1, 1); break; case Action.RECTANGLE: /* Starts to draw a rectangle */ curr_obj = new Rect(1, 1); break; case Action.CIRCLE: /* Starts to draw a circle */ curr_obj = new Circle(1); break; case Action.ELLIPSE: /* Starts to draw a Ellipse */ curr_obj = new Ellipse(1, 1); break; } lastPosition[0] = x; lastPosition[1] = y; objPosition[0] = x; objPosition[1] = y; addGraphicObject(curr_obj, x, y); /* Selects a object */ } else if (action.isSelect() && (graphicObject != null)) { /** If there was another object previously selected, unselect it. */ if (curr_obj != null && graphicObject != curr_obj && graphicObject.getGroup() != transformPoints) { unSelect(); } /** If we didn't click on any Transform Point, then we select the object. */ if ((graphicObject.getGroup() != transformPoints)) { if (curr_obj == null) { Rectangle bnds = graphicObject.getBounds(); if (bnds != null) { /** This may seem strange but for some object types, mainly Paths and Ellipses, Tatami's method getBounds() will return null until the object is translated. */ graphicObject.translate(1, 1); graphicObject.translate(-1, -1); if (bnds.getHeight() == 0 && bnds.getWidth() == 0) { bnds = graphicObject.getBounds(); } this.backupStyle(); fillOpacity.setValue(graphicObject.uGetFillColor().getAlpha()); strokeOpacity.setValue(graphicObject.getStrokeColor().getAlpha()); currentFillColor = graphicObject.uGetFillColor(); DOM.setStyleAttribute(fill.getElement(), "backgroundColor", currentFillColor.toCss(false)); currentFillColor.setAlpha(graphicObject.uGetFillColor().getAlpha()); currentStrokeColor = graphicObject.getStrokeColor(); DOM.setStyleAttribute(stroke.getElement(), "backgroundColor", currentStrokeColor.toCss(false)); this.currentStrokeSize.setValue(graphicObject.getStrokeWidth()); //chooseStrokeSize(graphicObject.getStrokeWidth()-1, graphicObject.getStrokeWidth()); createTransformPoints(bnds, graphicObject); } curr_obj = graphicObject; } lastPosition[0] = x; lastPosition[1] = y; objPosition[0] = x; objPosition[1] = y; isMovable = true; /** if the user clicked on a transform point, this settles the variables for the object tranformation. */ } else { lastPosition[0] = x; lastPosition[1] = y; isTransformable = true; aux_obj = curr_obj; curr_obj = graphicObject; currRotation = 0.0; if (curr_obj == transformPointers[Action.ROTATE]) { canvas.remove(transformPoints); transformPoints.clear(); } } /** Starts to draw a TextBox. * To add usability, a Text object is allways composed by a Text object and a TextBox. The TextBox is simillar to a Rectangle but it's alpha values are set to 0(it's transparent) and has the size of the text's bounds. * This allows the user to select a Text object more easily because now he has a rectangle with the size of the Text's boundaries to click on. The TextBox contains a link to the Text (and also the Text to the TextBox) so when a user click on it, we know which Text Object is selected and perform the given actions on it as well. * Note: This weren't supported by Tatami, i had to implement it. * */ } else if (this.action.isTextBox()) { this.curr_obj = new com.objetdirect.tatami.client.gfx.TextBox(1.0, 1.0, null); this.lastPosition[0] = x; this.lastPosition[1] = y; this.objPosition[0] = x; this.objPosition[1] = y; this.addTextBox(this.curr_obj, x, y); } else if (this.action.isPencil()) { /* Starts to draw with the pencil */ curr_obj = new Path(); ((Path) curr_obj).moveTo(x, y); Color fill = new Color(this.currentFillColor.getRed(), this.currentFillColor.getGreen(), this.currentFillColor.getBlue(), 0); objPosition[0] = x; objPosition[1] = y; curr_obj.setFillColor(fill); curr_obj.setStroke(currentStrokeColor, currentStrokeSize.getValue()); canvas.add(curr_obj, 0, 0); /* Otherwise it adds a new point in the Polyline */ } else if (this.action.isPolyline() && curr_obj != null) { this.lastPosition[0] = x; this.lastPosition[1] = y; } }
From source file:com.xpn.xwiki.cbdf.client.CBDF.java
License:Open Source License
/** * This method handles the mouse release event on any graphic object and in the graphic canvas * @param graphicObject The graphic object over which the mouse release has been done * @param event A reference to the mouse event *///from w ww .j a va 2 s. co m public void mouseReleased(GraphicObject graphicObject, Event event) { int x, y; x = DOM.eventGetClientX(event) - canvas.getAbsoluteLeft() + Window.getScrollLeft(); y = DOM.eventGetClientY(event) - canvas.getAbsoluteTop() + Window.getScrollTop(); /** If we were draing with the pencil, then we need to finish it */ if ((curr_obj != null) && action.isPencil()) { curr_obj = null; /** If we were with a object selected, we need to update the variables to finish the transformation or translation, given the case. */ } else if ((curr_obj != null) && action.isSelect()) { if (isTransformable) { /** This is needed because to increase performance during object rotation, the transform points aren't displayed. This is needed because this class is performing the Transform Points rotation and not Tatami(it doesn't works..). */ if (curr_obj == transformPointers[Action.ROTATE]) { Rectangle bnds = aux_obj.getBounds(); canvas.remove(transformPoints); transformPoints.clear(); createTransformPoints(bnds, aux_obj); } curr_obj = aux_obj; isTransformable = false; } else { isMovable = false; } /** If we were creating a TextBox, then we create a TextArea to allow the user to write and handle the Esc key functionality. */ } else if (curr_obj != null && action.isTextBox()) { this.action.setAction(Action.TEXT); this.editor = new TextArea(); this.editor.setWidth((int) (this.curr_obj.getBounds().getWidth() + 2) + "px"); this.editor.setHeight((int) (this.curr_obj.getBounds().getHeight() + 2) + "px"); this.editor.setFocus(true); this.editor.setEnabled(true); this.editor.addKeyboardListener(new KeyboardListenerAdapter() { public void onKeyDown(Widget sender, char keyCode, int modifiers) { if (keyCode == (char) KEY_ESCAPE) { int size = Integer .parseInt(currentFontSize.getItemText(currentFontSize.getSelectedIndex())); int x = (int) aux_obj.getX(), y = (int) aux_obj.getY(); editor.cancelKey(); curr_obj = new Text(editor.getText()); ((Text) curr_obj).setFont(currFont); addTextObject(curr_obj, x + (int) ((1.0 / 4.0) * size), y + (size) + (int) ((1.0 / 4.0) * size)); canvas.remove(aux_obj); aux_obj = new TextBox(curr_obj.getBounds(), (Text) curr_obj); addTextBox(aux_obj, (int) curr_obj.getBounds().getX(), (int) curr_obj.getBounds().getY()); ((Text) curr_obj).bounder = (TextBox) aux_obj; Color textColor = new Color(curr_obj.getFillColor().getRed(), curr_obj.getFillColor().getGreen(), curr_obj.getFillColor().getBlue(), 0); aux_obj.setFillColor(textColor); aux_obj.setStroke(textColor, 1); aux_obj = null; curr_obj = null; apanel.remove(editor); editor = null; action.setAction(Action.TEXTBOX); } } }); this.apanel.add(editor, (int) this.curr_obj.getX() + this.canvas.getAbsoluteLeft() - Window.getScrollLeft() - 2, (int) this.curr_obj.getY() + this.canvas.getAbsoluteTop() - Window.getScrollTop() - 2); this.aux_obj = this.curr_obj; this.curr_obj = null; } else if (curr_obj != null && this.action.isPolyline()) { this.canvas.remove(curr_obj); this.curr_obj = new Path(this.currentPath); if (x != this.lastPosition[0] && y != this.lastPosition[1]) { ((Path) this.curr_obj).smoothCurveTo(x, y, lastPosition[0], lastPosition[1]); } else { ((Path) this.curr_obj).lineTo(x, y); } this.addGraphicObject(this.curr_obj, 0, 0); this.currentPath = ((Path) this.curr_obj).commands; } else if (curr_obj != null) { curr_obj = null; } }
From source file:com.zipsoft.widgets.client.lazylayout.VLazyLayout.java
License:Apache License
private void setScrollTop(final int topPx) { com.google.gwt.dom.client.Element parent = getElement(); while (parent != null && parent.getScrollTop() <= 0) { parent = parent.getOffsetParent(); }/*from w w w .j av a 2 s.co m*/ if (parent != null) { parent.setScrollTop(topPx); debug("setting scrolltop to " + topPx); } else { final int currentScrollLeft = Window.getScrollLeft(); Window.scrollTo(currentScrollLeft, topPx); debug("setting scrolltop for window to " + topPx); } scrollingWasProgrammaticallyAdjusted = true; }
From source file:cz.filmtit.client.PageHandler.java
License:Open Source License
/** * Loads the pageToLoad. Sets pageLoaded. Uses * * @param evenIfAlreadyLoaded reload the page if already loaded *///from w w w . j a v a 2s. c om private void loadPageToLoad(boolean evenIfAlreadyLoaded) { if ((pageToLoad != pageLoaded) || evenIfAlreadyLoaded) { // unloading TranslationWorkspace if (pageLoaded == Page.TranslationWorkspace && TranslationWorkspace.getCurrentWorkspace() != null) { TranslationWorkspace.getCurrentWorkspace().setStopLoading(true); } // scroll to top if not prevented if (grabScrollToTop()) { Window.scrollTo(Window.getScrollLeft(), 0); } switch (pageToLoad) { case Blank: new Blank(); break; case ChangePassword: new ChangePassword(); break; case AuthenticationValidationWindow: new AuthenticationValidationWindow(); break; case TranslationWorkspace: if (documentId == -1) { loadPage(Page.UserPage); Gui.log("failure on loading document: documentId -1 is not valid!"); } else { new LoadDocumentFromDB(documentId); } break; case DocumentCreator: reshowCurrentDocumentCreator(); break; case UserPage: new UserPage(); break; case WelcomeScreen: new WelcomeScreen(); break; case Settings: new Settings(); break; case Help: new Help(); break; // no other situation should happen default: Gui.log("ERROR: Cannot load the page " + pageToLoad); return; } Gui.log("Loaded page " + pageToLoad); pageLoaded = pageToLoad; if (isFullPage(pageLoaded)) { // set the correct menu item Gui.getGuiStructure().activateMenuItem(pageLoaded); } } else { Gui.log("Not loading page " + pageToLoad + " because it is already loaded."); } }
From source file:cz.filmtit.client.pages.Settings.java
License:Open Source License
private void reactivate() { Window.scrollTo(Window.getScrollLeft(), 0); setUsername.setEnabled(true);//from w w w . j a va 2s .co m setPassword.setEnabled(true); setPasswordRepeat.setEnabled(true); setEmail.setEnabled(true); setPermalogin.setEnabled(true); setMaxSuggestions.setEnabled(true); setUseMT.setEnabled(true); btnSave.setEnabled(true); btnReset.setEnabled(true); }
From source file:cz.filmtit.client.pages.TranslationWorkspace.java
License:Open Source License
/** * Scrolls the page so that the subgestbox isvisible to the user. *//*from w w w. j a v a 2 s . c o m*/ public void ensureVisible(SubgestBox subbox) { Window.scrollTo(Window.getScrollLeft(), getScrollOffsetY(subbox.getElement()) - getVideoHeight() - (Window.getClientHeight() - getVideoHeight()) * 2 / 5); }