List of usage examples for com.google.gwt.user.client.ui Widget getAbsoluteLeft
public int getAbsoluteLeft()
From source file:org.gwm.splice.client.desktop.DesktopManager.java
License:Apache License
public boolean canDrop(Widget widget) { RootPanel rp = RootPanel.get();//from w w w .j a v a 2 s .co m int x = widget.getAbsoluteLeft(); int y = widget.getAbsoluteTop(); int h = widget.getOffsetHeight(); int w = widget.getAbsoluteLeft(); boolean overlapX = false; boolean overlapY = false; for (Iterator iter = rp.iterator(); iter.hasNext();) { Widget child = (Widget) iter.next(); if (child == widget) { continue; } int cx = child.getAbsoluteLeft(); int cy = child.getAbsoluteTop(); int ch = child.getOffsetHeight(); int cw = child.getOffsetWidth(); if (x == cx || y == cy) { return false; } if (x > cx) { if (x <= (cx + cw)) { overlapX = true; } } else if (x < cx) { if ((x + w) >= cx) { overlapX = true; } } if (y > cy) { if (y <= (cy + ch)) { overlapY = true; } } else if (y < cy) { if ((y + h) >= cy) { overlapY = true; } } if (overlapX && overlapY) { return false; } } return true; }
From source file:org.gwt.mosaic.ui.client.layout.CustomGridLayout.java
License:Apache License
/** * Lays out the specified {@link LayoutPanel} using this layout. * <p>/*from w w w . j a v a 2 s . c o m*/ * The grid layout manager determines the size of individual widgets by * dividing the free space in the panel into equal-sized portions according to * the number of rows and columns in the layout. The container's free space * equals the container's size minus any margins and any specified horizontal * or vertical gap. * * @param layoutPanel the panel in which to do the layout * * @see org.gwt.mosaic.ui.client.layout.LayoutManager#layoutPanel(org.gwt.mosaic.ui.client.layout.LayoutPanel) */ public void layoutPanel(LayoutPanel layoutPanel) { try { if (layoutPanel == null || !init(layoutPanel)) { return; } final Dimension box = DOM.getClientSize(layoutPanel.getElement()); final int left = paddingLeftMeasure.sizeOf(layoutPanel); final int top = paddingTopMeasure.sizeOf(layoutPanel); int width = box.width - (left + paddingRightMeasure.sizeOf(layoutPanel)); int height = box.height - (top + paddingBottomMeasure.sizeOf(layoutPanel)); final int spacing = layoutPanel.getWidgetSpacing(); // adjust for spacing width -= ((cols - 1) * spacing); height -= ((rows - 1) * spacing); final int colWidth = width / cols; final int rowHeight = height / rows; for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) { Widget widget = widgetMatrix[c][r]; if (widget == null || widget == SPAN) { continue; } if (widget instanceof InternalDecoratorPanel) { widget = ((InternalDecoratorPanel) widget).getWidget(); } int cellWidth; int cellHeight; final GridLayoutData layoutData = (GridLayoutData) widget.getLayoutData(); final Widget parent = widget.getParent(); if (parent instanceof InternalDecoratorPanel) { final InternalDecoratorPanel decPanel = (InternalDecoratorPanel) parent; final int borderSizes[] = decPanel.getBorderSizes(); final Dimension decPanelFrameSize = new Dimension(borderSizes[1] + borderSizes[3], borderSizes[0] + borderSizes[0]); cellWidth = colWidth * layoutData.colspan - decPanelFrameSize.width + spacing * (layoutData.colspan - 1); cellHeight = rowHeight * layoutData.rowspan - decPanelFrameSize.height + spacing * (layoutData.rowspan - 1); } else { cellWidth = colWidth * layoutData.colspan + spacing * (layoutData.colspan - 1); cellHeight = rowHeight * layoutData.rowspan + spacing * (layoutData.rowspan - 1); } HorizontalAlignmentConstant hAlignment = layoutData.getHorizontalAlignment(); if (hAlignment == null) { hAlignment = getHorizontalAlignment(); } Dimension prefSize = null; if (hAlignment == null) { layoutData.targetLeft = left + (spacing + colWidth) * c; layoutData.targetWidth = cellWidth; } else { // (ggeorg) this call to WidgetHelper.getPreferredSize() is // required even for ALIGN_LEFT prefSize = new Dimension(preferredWidthMeasure.sizeOf(widget), preferredHeightMeasure.sizeOf(widget)); if (HasHorizontalAlignment.ALIGN_LEFT == hAlignment) { layoutData.targetLeft = left + (spacing + colWidth) * c; } else if (HasHorizontalAlignment.ALIGN_CENTER == hAlignment) { layoutData.targetLeft = left + (spacing + colWidth) * c + (cellWidth / 2) - prefSize.width / 2; } else { layoutData.targetLeft = left + (spacing + colWidth) * c + cellWidth - prefSize.width; } layoutData.targetWidth = prefSize.width; } VerticalAlignmentConstant vAlignment = layoutData.getVerticalAlignment(); if (vAlignment == null) { vAlignment = getVerticalAlignment(); } if (vAlignment == null) { layoutData.targetTop = top + (spacing + rowHeight) * r; layoutData.targetHeight = cellHeight; } else { if (prefSize == null) { // (ggeorg) this call to WidgetHelper.getPreferredSize() is // required even for ALIGN_TOP prefSize = new Dimension(preferredWidthMeasure.sizeOf(widget), preferredHeightMeasure.sizeOf(widget)); } if (HasVerticalAlignment.ALIGN_TOP == vAlignment) { layoutData.targetTop = top + (spacing + rowHeight) * r; } else if (HasVerticalAlignment.ALIGN_MIDDLE == vAlignment) { layoutData.targetTop = top + (spacing + rowHeight) * r + (cellHeight / 2) - prefSize.height / 2; } else { layoutData.targetTop = top + (spacing + rowHeight) * r + cellHeight - prefSize.height; } layoutData.targetHeight = prefSize.height; } if (layoutPanel.isAnimationEnabled()) { layoutData.setSourceLeft(widget.getAbsoluteLeft() - layoutPanel.getAbsoluteLeft()); layoutData.setSourceTop(widget.getAbsoluteTop() - layoutPanel.getAbsoluteTop()); layoutData.setSourceWidth(widget.getOffsetWidth()); layoutData.setSourceHeight(widget.getOffsetHeight()); } } } super.layoutPanel(layoutPanel); } catch (Exception e) { GWT.log(e.getMessage(), e); Window.alert(this.getClass().getName() + ".layoutPanel(): " + e.getLocalizedMessage()); } }
From source file:org.gwtportlets.portlet.client.edit.PageEditorMenuBar.java
License:Open Source License
protected void onLoad() { super.onLoad(); final Widget p = getParent(); if (!(p instanceof PopupPanel)) { return;/*from w w w.j av a 2 s .c om*/ } // reposition the popup so it does not go off screen etc p.setVisible(false); final int left = p.getAbsoluteLeft(); final int top = p.getAbsoluteTop(); LDOM.setPosition(p.getElement(), 0, 0); // put here so size is not constrained DeferredCommand.addCommand(new Command() { public void execute() { Rectangle nextTo = new Rectangle(); nextTo.x = left; nextTo.y = top; nextTo.width = 1; nextTo.height = 1; Rectangle r = LDOM.getNextToPosition(p.getOffsetWidth(), p.getOffsetHeight(), nextTo, true, 0); LDOM.setPosition(p.getElement(), r.x, r.y); p.setVisible(true); } }); }
From source file:org.gwtportlets.portlet.client.edit.row.RowLayoutEditor.java
License:Open Source License
/** * Figure out the best index for widget in our container assuming it is * dropped at clientX and clientY./* ww w .j a va 2s. c o m*/ */ private int getDropIndex(int clientX, int clientY) { int wc = container.getWidgetCount(); if (getTargetLayout().isColumn()) { for (int i = wc - 1; i >= 0; i--) { Widget w = container.getWidget(i); int top = w.getAbsoluteTop(); if (clientY >= top) { return clientY >= top + w.getOffsetHeight() * 2 / 3 ? i + 1 : i; } } } else { for (int i = wc - 1; i >= 0; i--) { Widget w = container.getWidget(i); int left = w.getAbsoluteLeft(); if (clientX >= left) { return clientX >= left + w.getOffsetWidth() * 2 / 3 ? i + 1 : i; } } } return 0; }
From source file:org.jboss.ballroom.client.util.LoadingOverlay.java
License:Open Source License
public static void on(Widget parent, boolean loading) { if (parent != null && loading) { int left = parent.getAbsoluteLeft(); int top = parent.getAbsoluteTop(); int width = parent.getOffsetWidth(); int height = parent.getOffsetHeight(); p = new PopupPanel(); //p.setStylePrimaryName("bpm-loading-overlay"); p.setWidget(new Image("images/loading_lite.gif")); p.setPopupPosition(left + (width / 2) - 15, top + (height / 2) - 15); p.show();//from w w w. j a v a 2s . c o m } else { if (p != null) { p.hide(); p = null; } } }
From source file:org.jboss.bpm.console.client.common.LoadingOverlay.java
License:Open Source License
public static void on(Widget parent, boolean loading) { if (parent != null && loading) { int left = parent.getAbsoluteLeft(); int top = parent.getAbsoluteTop(); int width = parent.getOffsetWidth(); int height = parent.getOffsetHeight(); if (width > 100 & height > 100) // workaround hidden panels {//from ww w .j a va2 s . c o m p = new PopupPanel(); p.setStylePrimaryName("bpm-loading-overlay"); p.setWidget(new Image("images/loading_lite.gif")); p.setPopupPosition(left + (width / 2) - 15, top + (height / 2) - 15); p.show(); } } else { if (p != null) { p.hide(); p = null; } } }
From source file:org.jboss.errai.workspaces.client.listeners.TabOpeningClickHandler.java
License:Apache License
public void onClick(ClickEvent event) { String initSubject = tool.getId() + ":init"; final MessageBus bus = ErraiBus.get(); if (!bus.isSubscribed(initSubject)) { bus.subscribe(initSubject, new MessageCallback() { public void callback(final Message message) { try { tool.provideWidget(new ProvisioningCallback() { public void onSuccess(final Widget instance) { instance.getElement().setId(message.get(String.class, LayoutParts.DOMID)); RootPanel.get().add(instance); LayoutHint.attach(instance, new LayoutHintProvider() { public int getHeightHint() { return Window.getClientHeight() - instance.getAbsoluteTop() - 20; }//from ww w . ja va 2s . c om public int getWidthHint() { return Window.getClientWidth() - instance.getAbsoluteLeft() - 5; } }); } public void onUnavailable() { throw new RuntimeException("Failed to create component"); } }); createConversation(message).getMessage().sendNowWith(bus); } catch (Exception e) { e.printStackTrace(); } } }); } try { /** * Being capturing all message registration activity. This is necessary if you want to use the automatic clean-up * features and close the messaging channels when the tool instance closes. */ ((ClientMessageBus) bus).beginCapture(); createMessage().toSubject("org.jboss.errai.WorkspaceLayout").command(LayoutCommands.OpenNewTab) .with(LayoutParts.ComponentID, tool.getId()).with(LayoutParts.IconURI, tool.getIcon().getUrl()) .with(LayoutParts.MultipleInstances, tool.multipleAllowed()) .with(LayoutParts.Name, tool.getName()) .with(LayoutParts.DOMID, tool.getId() + "_" + System.currentTimeMillis()) .with(LayoutParts.InitSubject, initSubject).noErrorHandling().sendNowWith(bus); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.jbpm.form.builder.ng.model.client.form.FBForm.java
License:Apache License
@Override public void add(PhantomPanel phantom, int x, int y) { for (int index = 0; index < getWidgetCount(); index++) { Widget item = getWidget(index); int left = item.getAbsoluteLeft(); int right = left + item.getOffsetWidth(); int top = item.getAbsoluteTop(); int bottom = top + item.getOffsetHeight(); if (x > left && x < right && y > top && y < bottom) { insert(phantom, index);/*from ww w .j ava2 s.c o m*/ break; } else if (x > right && y > top && y < bottom && index < (getWidgetCount() - 1)) { insert(phantom, index + 1); break; } else if (index == (getWidgetCount() - 1)) { add(phantom); break; } } }
From source file:org.jbpm.form.builder.ng.model.client.form.items.FieldSetLayoutFormItem.java
License:Apache License
@Override public void add(PhantomPanel phantom, int x, int y) { for (int index = 0; index < panel.getWidgetCount(); index++) { Widget item = panel.getWidget(index); int left = item.getAbsoluteLeft(); int right = left + item.getOffsetWidth(); int top = item.getAbsoluteTop(); int bottom = top + item.getOffsetHeight(); if (x > left && x < right && y > top && y < bottom) { panel.insert(phantom, index); break; }/*www . j a v a 2 s . c o m*/ } }
From source file:org.jbpm.form.builder.ng.model.client.form.items.HorizontalLayoutFormItem.java
License:Apache License
@Override public void add(PhantomPanel phantom, int x, int y) { Widget beforeWidget = null;/*ww w . j a v a 2 s. c om*/ for (Widget widget : this.panel) { int left = widget.getAbsoluteLeft(); int right = left + widget.getOffsetWidth(); if (x > left && x < right) { beforeWidget = widget; break; } } if (beforeWidget == null) { this.panel.add(phantom); } else { int index = this.panel.getWidgetIndex(beforeWidget); this.panel.insert(phantom, index); } }