List of usage examples for com.google.gwt.user.client.ui Widget getAbsoluteTop
public int getAbsoluteTop()
From source file:cc.alcina.framework.gwt.client.util.WidgetUtils.java
License:Apache License
public static void scrollIntoViewWhileKeepingRect(Rect bounds, Widget widget, int pad) { // assume widget is below bounds int scrollTop = Window.getScrollTop(); int clientHeight = Window.getClientHeight(); int widgetTop = widget.getAbsoluteTop(); int widgetHeight = widget.getOffsetHeight(); if (widgetTop + widgetHeight + pad > scrollTop + clientHeight) { int bestDeltaDown = widgetTop + widgetHeight + pad - (scrollTop + clientHeight); int delta = Math.min(bounds.y1 - scrollTop, bestDeltaDown); delta = Math.max(0, delta); smoothScrollTo(scrollTop + delta, widget); }/*from ww w. ja v a 2 s. co m*/ }
From source file:cc.alcina.framework.gwt.client.widget.RelativePopupValidationFeedback.java
License:Apache License
@Override public void handleException(Object source, ValidationException exception) { final Widget w = (Widget) source; resolve(source);/*from w ww .j av a2 s . c o m*/ if (!DomUtils.isVisibleAncestorChain(w.getElement())) { return; } Widget suppressValidationFeedbackFor = RenderContext.get().getSuppressValidationFeedbackFor(); if (suppressValidationFeedbackFor != null && suppressValidationFeedbackFor.getElement().isOrHasChild(w.getElement())) { return; } final RelativePopup p = new RelativePopup(); p.setVisible(false); popups.put(source, p); WidgetByElementTracker.get().register(p); p.setStyleName("gwittir-ValidationPopup"); if (getCss() != null) { p.addStyleName(getCss()); } if (exception instanceof ProcessingServerValidationException) { ProcessingServerValidationException psve = (ProcessingServerValidationException) exception; FlowPanel fp = new FlowPanel(); fp.setStyleName("gwittir-ServerValidation"); fp.add(new InlineLabel(this.getMessage(exception))); p.add(fp); psve.setSourceWidget(source); psve.setFeedback(this); } else { p.add(renderExceptionWidget(exception)); } int x = w.getAbsoluteLeft(); int y = w.getAbsoluteTop(); Widget pw = WidgetUtils.getPositioningParent(w); ComplexPanel cp = WidgetUtils.complexChildOrSelf(pw); if (!(pw instanceof RootPanel)) { x -= pw.getAbsoluteLeft(); y -= pw.getAbsoluteTop(); } cp.add(p); if (this.position == BOTTOM) { y += w.getOffsetHeight(); } else if (this.position == RIGHT) { x += w.getOffsetWidth(); } else if (this.position == LEFT) { x -= p.getOffsetWidth(); } else if (this.position == TOP) { y -= p.getOffsetHeight(); } Element h = p.getElement(); Style style = h.getStyle(); style.setPosition(Position.ABSOLUTE); style.setLeft(x, Unit.PX); style.setTop(y, Unit.PX); if (this.position == BOTTOM) { style.setWidth(w.getOffsetWidth(), Unit.PX); } p.setVisible(true); if (w instanceof SourcesPropertyChangeEvents) { // GWT.log("is PCE", null); PropertyChangeListener attachListener = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent propertyChangeEvent) { if (((Boolean) propertyChangeEvent.getNewValue()).booleanValue()) { p.setVisible(true); } else { p.setVisible(false); } } }; listeners.put(w, attachListener); ((SourcesPropertyChangeEvents) w).addPropertyChangeListener("attached", attachListener); ((SourcesPropertyChangeEvents) w).addPropertyChangeListener("visible", attachListener); } }
From source file:cc.kune.common.client.tooltip.Tooltip.java
License:GNU Affero Public License
/** * Calculate position./* ww w. j a v a 2 s . c o m*/ * * @return the tooltip position */ private TooltipPosition calculatePosition(final Widget forWidget) { return TooltipPositionCalculator.calculate(Window.getClientWidth(), Window.getClientHeight(), forWidget.getAbsoluteLeft(), forWidget.getAbsoluteTop(), forWidget.getOffsetWidth(), forWidget.getOffsetHeight(), getTip().getWidth(), getTip().getHeight()); }
From source file:cc.kune.common.client.ui.MaskWidget.java
License:GNU Affero Public License
@Override public void mask(final IsWidget widget, final String message) { label.setText(message);/*from ww w . j av a2 s . c om*/ setPopupPositionAndShow(new PositionCallback() { @Override public void setPosition(final int offsetWidth, final int offsetHeight) { final Widget asWidget = widget.asWidget(); final int w = asWidget.getOffsetWidth(); final int h = asWidget.getOffsetHeight(); MaskWidget.this.setPopupPosition(asWidget.getAbsoluteLeft(), asWidget.getAbsoluteTop()); getElement().getStyle().setWidth(w, Unit.PX); getElement().getStyle().setHeight(h, Unit.PX); flow.getElement().getStyle().setTop((h - flow.getOffsetHeight()) / 2d, Unit.PX); flow.getElement().getStyle().setLeft((w - flow.getOffsetWidth()) / 2d, Unit.PX); } }); }
From source file:ch.heftix.mailxel.client.MailOverviewCellTable.java
License:Open Source License
private void init(final boolean withoutSearch, final MailServiceAsync mailxelService, final MailxelPanel mailxelPanel) { this.mailxelService = mailxelService; TextColumn<Envelope> toColumn = new TextColumn<Envelope>() { public String getValue(Envelope env) { return env.to; }/*from w w w.j av a 2s. c o m*/ }; TextColumn<Envelope> dateColumn = new TextColumn<Envelope>() { public String getValue(Envelope env) { return env.date; } }; TextColumn<Envelope> gtdColumn = new TextColumn<Envelope>() { public String getValue(Envelope env) { return env.GTD; } }; TextColumn<Envelope> aColumn = new TextColumn<Envelope>() { public String getValue(Envelope env) { return Integer.toString(env.nattach); } }; rf = grid.getRowFormatter(); // header grid.setText(LABEL_ROW, C_FROM, "From"); grid.setText(LABEL_ROW, C_TO, "To"); grid.setText(LABEL_ROW, C_DATE, "Date"); grid.setText(LABEL_ROW, C_GTD, "GTD"); grid.setText(LABEL_ROW, C_ATTACHMENT, "A"); // subjectPanel.add(new Label("Subject")); // grid.setWidget(LABEL_ROW, C_SUBJECT, subjectPanel); grid.setText(LABEL_ROW, C_SUBJECT, "Subject"); ColumnFormatter fmt = grid.getColumnFormatter(); fmt.setWidth(C_FROM, "75px"); fmt.setWidth(C_TO, "75px"); fmt.setWidth(C_DATE, "75px"); fmt.setWidth(C_GTD, "50px"); fmt.setWidth(C_ATTACHMENT, "10px"); fmt.setWidth(C_SUBJECT, "400px"); final KeyPressHandler kbla = new KeyPressHandler() { public void onKeyPress(KeyPressEvent keyPressEvent) { if (KeyCodes.KEY_ENTER == keyPressEvent.getCharCode()) { currentPage = 0; startMessageSearch(mailxelService, mailxelPanel); } } }; fts = new TextBox(); fts.setTitle("full text search"); fts.setWidth("700px"); fts.addKeyPressHandler(kbla); final Image nextPage = new Image("img/resultset_next.png"); nextPage.setTitle("Next Page"); nextPage.setStylePrimaryName("mailxel-toolbar-item"); nextPage.addClickHandler(new ClickHandler() { public void onClick(ClickEvent sender) { currentPage++; startMessageSearch(mailxelService, mailxelPanel); } }); final Image prevPage = new Image("img/resultset_previous.png"); prevPage.setTitle("Previous Page"); prevPage.setStylePrimaryName("mailxel-toolbar-item"); prevPage.addClickHandler(new ClickHandler() { public void onClick(ClickEvent sender) { if (currentPage > 0) { currentPage--; } startMessageSearch(mailxelService, mailxelPanel); } }); // paginatePanel.add(attachmentName); searchPanel.add(fts); searchPanel.add(prevPage); searchPanel.add(nextPage); grid.addClickHandler(new ClickHandler() { public void onClick(ClickEvent clickEvent) { Cell cell = grid.getCellForEvent(clickEvent); if (null == cell) { return; } final int row = cell.getRowIndex(); final int col = cell.getCellIndex(); // row >= FIRST_PAYLOAD_ROW: skip header // col > 0: skip first col; contains a checkbox with separate // listener if (row >= first_payload_row && col > 0) { Envelope env = envelopes.get(row - first_payload_row); if (col == C_ATTACHMENT && env.nattach > 0) { // show popup with attachment details mailxelService.getAttachments(env.id, new AsyncCallback<List<AttachmentTO>>() { public void onSuccess(List<AttachmentTO> result) { PopupPanel pop = new PopupPanel(true); AttachmentBar ab = new AttachmentBar(mailxelService); for (AttachmentTO aTO : result) { ab.addAttachement(aTO, mailxelPanel, null); } pop.add(ab); Widget tmp = (Image) grid.getWidget(row, col); int x = tmp.getAbsoluteLeft(); int y = tmp.getAbsoluteTop(); pop.setPopupPosition(x, y); pop.show(); } public void onFailure(Throwable caught) { // ignore } }); } else if (991 == env.curcatid) { // edit message rf.setStylePrimaryName(row, "row-selected"); MailTO mt = new MailTO(); final MailSendGrid sg = new MailSendGrid(mailxelService, mailxelPanel, mt, MailSendGrid.TYPE_NEW); sg.setMailDetail(env.id); mailxelPanel.addTab(sg, env.from + ": " + env.subject); } else { // open a detail tab rf.setStylePrimaryName(row, "row-selected"); cl.setCursorPosition(row - first_payload_row); addDetailTab(mailxelService, mailxelPanel, env); } } } }); if (!withoutSearch) { add(searchPanel); } ScrollPanel sp = new ScrollPanel(); sp.add(grid); add(sp); }
From source file:ch.heftix.mailxel.client.MailOverviewGrid.java
License:Open Source License
private void init(final boolean withoutSearch, final MailServiceAsync mailxelService, final MailxelPanel mailxelPanel) { this.mailxelService = mailxelService; rf = grid.getRowFormatter();//from w ww . j a v a 2 s . c om // header grid.setText(LABEL_ROW, C_FROM, "From"); grid.setText(LABEL_ROW, C_TO, "To"); grid.setText(LABEL_ROW, C_DATE, "Date"); grid.setText(LABEL_ROW, C_GTD, "GTD"); grid.setText(LABEL_ROW, C_ATTACHMENT, "A"); // subjectPanel.add(new Label("Subject")); // grid.setWidget(LABEL_ROW, C_SUBJECT, subjectPanel); grid.setText(LABEL_ROW, C_SUBJECT, "Subject"); ColumnFormatter fmt = grid.getColumnFormatter(); fmt.setWidth(C_FROM, "75px"); fmt.setWidth(C_TO, "75px"); fmt.setWidth(C_DATE, "75px"); fmt.setWidth(C_GTD, "50px"); fmt.setWidth(C_ATTACHMENT, "10px"); fmt.setWidth(C_SUBJECT, "400px"); final KeyPressHandler kbla = new KeyPressHandler() { public void onKeyPress(KeyPressEvent keyPressEvent) { if (KeyCodes.KEY_ENTER == keyPressEvent.getCharCode()) { currentPage = 0; startMessageSearch(mailxelService, mailxelPanel); } } }; fts = new TextBox(); fts.setTitle("full text search"); fts.setWidth("700px"); fts.addKeyPressHandler(kbla); final Image nextPage = new Image("img/resultset_next.png"); nextPage.setTitle("Next Page"); nextPage.setStylePrimaryName("mailxel-toolbar-item"); nextPage.addClickHandler(new ClickHandler() { public void onClick(ClickEvent sender) { currentPage++; startMessageSearch(mailxelService, mailxelPanel); } }); final Image prevPage = new Image("img/resultset_previous.png"); prevPage.setTitle("Previous Page"); prevPage.setStylePrimaryName("mailxel-toolbar-item"); prevPage.addClickHandler(new ClickHandler() { public void onClick(ClickEvent sender) { if (currentPage > 0) { currentPage--; } startMessageSearch(mailxelService, mailxelPanel); } }); // paginatePanel.add(attachmentName); searchPanel.add(fts); searchPanel.add(prevPage); searchPanel.add(nextPage); grid.addClickHandler(new ClickHandler() { public void onClick(ClickEvent clickEvent) { Cell cell = grid.getCellForEvent(clickEvent); if (null == cell) { return; } final int row = cell.getRowIndex(); final int col = cell.getCellIndex(); // row >= FIRST_PAYLOAD_ROW: skip header // col > 0: skip first col; contains a checkbox with separate // listener if (row >= first_payload_row && col > 0) { Envelope env = envelopes.get(row - first_payload_row); if (col == C_ATTACHMENT && env.nattach > 0) { // show popup with attachment details mailxelService.getAttachments(env.id, new AsyncCallback<List<AttachmentTO>>() { public void onSuccess(List<AttachmentTO> result) { PopupPanel pop = new PopupPanel(true); AttachmentBar ab = new AttachmentBar(mailxelService); for (AttachmentTO aTO : result) { ab.addAttachement(aTO, mailxelPanel, null); } pop.add(ab); Widget tmp = (Image) grid.getWidget(row, col); int x = tmp.getAbsoluteLeft(); int y = tmp.getAbsoluteTop(); pop.setPopupPosition(x, y); pop.show(); } public void onFailure(Throwable caught) { // ignore } }); } else if (991 == env.curcatid) { // edit message rf.setStylePrimaryName(row, "row-selected"); MailTO mt = new MailTO(); final MailSendGrid sg = new MailSendGrid(mailxelService, mailxelPanel, mt, MailSendGrid.TYPE_NEW); sg.setMailDetail(env.id); mailxelPanel.addTab(sg, env.from + ": " + env.subject); } else { // open a detail tab rf.setStylePrimaryName(row, "row-selected"); cl.setCursorPosition(row - first_payload_row); addDetailTab(mailxelService, mailxelPanel, env); } } } }); if (!withoutSearch) { add(searchPanel); } ScrollPanel sp = new ScrollPanel(); sp.add(grid); add(sp); }
From source file:ch.heftix.mailxel.client.PopupMenu.java
License:Open Source License
public PopupMenu(final Widget sourceWidget) { // create pop-up menu super(true);/*from w w w.j a v a 2s .c om*/ menuBar.setVisible(true); add(menuBar); int x = sourceWidget.getAbsoluteLeft(); int y = sourceWidget.getAbsoluteTop(); setPopupPosition(x, y); }
From source file:ch.unifr.pai.twice.dragndrop.client.MPDragNDrop.java
License:Apache License
/** * Returns the drop target that has the highest priority and that has the biggest intersection area with the given element. * //from w w w . j a va 2 s.c om * @param e * @return a tuple of the drop target widget and the intersecting area or null if the element does not intersect with another element */ protected Tuple<Widget, Long> getHoverDropTarget(Element e) { Set<Widget> affected = getAffectedDropTargets(e); if (affected == null || affected.isEmpty()) return null; Widget max = null; long maxArea = 0; for (Widget target : affected) { boolean widgetIsLeftOfTarget = target.getAbsoluteLeft() - e.getAbsoluteLeft() > 0; boolean widgetIsTopOfTarget = target.getAbsoluteTop() - e.getAbsoluteTop() > 0; long collision = getCollisionArea(widgetIsLeftOfTarget ? e : target.getElement(), widgetIsLeftOfTarget ? target.getElement() : e, widgetIsTopOfTarget ? e : target.getElement(), widgetIsTopOfTarget ? target.getElement() : e); if (collision > maxArea || max == null) { max = target; maxArea = collision; } } return new Tuple<Widget, Long>(max, maxArea); }
From source file:ch.unifr.pai.twice.dragndrop.client.MPDragNDrop.java
License:Apache License
/** * This method looks up all the drop targets which are intersecting with the given element. If the drop targets differ in their priorities ({@link Priority} * ), only widgets of the highest priority are returned. * //from w ww.j a v a2 s . c o m * @param e * - a HTML element (typically the HTML element of the dragged widget) * @return the drop target widgets which are intersecting with the given element and do have the highest priority */ protected Set<Widget> getAffectedDropTargets(Element e) { int w1X = e.getAbsoluteLeft(); int w1Y = e.getAbsoluteTop(); int w1Width = e.getOffsetWidth(); int w1Height = e.getOffsetHeight(); Map<Integer, HashSet<Widget>> targets = new HashMap<Integer, HashSet<Widget>>(); for (Widget w2 : dropTargetRegistry.keySet()) { int w2X = w2.getAbsoluteLeft(); int w2Y = w2.getAbsoluteTop(); boolean xCollision = w1X < w2X ? w2X - w1X < w1Width : w1X - w2X < w2.getOffsetWidth(); boolean yCollision = w1Y < w2Y ? w2Y - w1Y < w1Height : w1Y - w2Y < w2.getOffsetHeight(); String idStyle = w2.getElement().getId() != null && !w2.getElement().getId().equals("") ? "hover-" + w2.getElement().getId() : null; if (xCollision && yCollision) { if (idStyle != null) { e.addClassName(idStyle); } DropTargetHandler h = dropTargetRegistry.get(w2); if (h != null) { int prio = h.getPriority().getValue(); HashSet<Widget> widgetsForPrio = targets.get(prio); if (widgetsForPrio == null) { widgetsForPrio = new HashSet<Widget>(); targets.put(prio, widgetsForPrio); } widgetsForPrio.add(w2); } } else if (idStyle != null) { e.removeClassName(idStyle); } } if (targets.isEmpty()) return null; int maxprio = 0; for (Integer i : targets.keySet()) { if (i > maxprio) { maxprio = i; } } return targets.get(maxprio); }
From source file:com.allen_sauer.gwt.dnd.client.drop.AbsolutePositionDropController.java
License:Apache License
@Override public void onEnter(DragContext context) { super.onEnter(context); assert draggableList.size() == 0; dropTargetClientWidth = DOMUtil.getClientWidth(dropTarget.getElement()); dropTargetClientHeight = DOMUtil.getClientHeight(dropTarget.getElement()); calcDropTargetOffset();//from w w w . jav a 2 s .co m int draggableAbsoluteLeft = context.draggable.getAbsoluteLeft(); int draggableAbsoluteTop = context.draggable.getAbsoluteTop(); for (Widget widget : context.selectedWidgets) { Draggable draggable = new Draggable(widget); draggable.positioner = makePositioner(widget); draggable.relativeX = widget.getAbsoluteLeft() - draggableAbsoluteLeft; draggable.relativeY = widget.getAbsoluteTop() - draggableAbsoluteTop; draggableList.add(draggable); } }