示例#1
0
  private void addText() {
    if (isAPanel) {
      // contains the draggable text
      DraggableLabel label = new DraggableLabel(ta.getText());
      label.getElement().getStyle().setDisplay(Display.INLINE_BLOCK);
      label.getElement().getStyle().setFontSize(18, Unit.PX);
      DragNDrop.makeDraggable(
          label,
          DragConfiguration.withProxy(
              new DragNDropHandler() {

                @Override
                public void onStartDrag(String deviceId, Widget draggedWidget) {}

                @Override
                public void onEndOfDrop(
                    String deviceId,
                    Widget draggedWidget,
                    int dragProxyLeft,
                    int dragProxyTop,
                    Event event) {}

                @Override
                public boolean onDrop(
                    String deviceId,
                    Widget draggedWidget,
                    int dragProxyLeft,
                    int dragProxyTop,
                    Event event,
                    DropTargetHandler dropTarget,
                    boolean outOfBox) {
                  parent.setWidgetPosition(
                      draggedWidget,
                      dragProxyLeft - parent.getAbsoluteLeft(),
                      dragProxyTop - parent.getAbsoluteTop());
                  return true;
                }
              }));

      /*
       * add the new text in the abs panel
       */

      parent.add(label);
      textPos = setRandomPos(width, height, label);
      parent.setWidgetPosition(label, textPos[0], textPos[1]);
    }
  }
示例#2
0
  private int[] setRandomPos(int tEdWidth, int tEdHeight, DraggableLabel l) {

    int[] pos = {0, 0};
    // System.out.println("Parent:" + parent.getElement().getClientWidth() + ", label: " +
    // l.getElement().getClientWidth());
    pos[0] = randomNum(20, parent.getElement().getClientWidth() - l.getElement().getClientWidth());
    pos[1] = randomNum(20, parent.getElement().getClientHeight() - 50);

    while (pos[0] <= tEdWidth || pos[1] <= tEdHeight) {
      pos[0] =
          randomNum(20, parent.getElement().getClientWidth() - l.getElement().getClientWidth());
      pos[1] = randomNum(20, parent.getElement().getClientHeight() - 50);
    }

    return pos;
  }