Exemple #1
0
  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 {
      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);
  }
Exemple #2
0
 private void updateFeedbackPosition() {
   if (isVertical()) {
     feedbackPopup.setPopupPosition(
         handle.getAbsoluteLeft() + handle.getOffsetWidth(),
         handle.getAbsoluteTop()
             + handle.getOffsetHeight() / 2
             - feedbackPopup.getOffsetHeight() / 2);
   } else {
     feedbackPopup.setPopupPosition(
         handle.getAbsoluteLeft()
             + handle.getOffsetWidth() / 2
             - feedbackPopup.getOffsetWidth() / 2,
         handle.getAbsoluteTop() - feedbackPopup.getOffsetHeight());
   }
 }
Exemple #3
0
 GWTFontMetrics getFontMetrics(Font font) {
   GWTFontMetrics metrics = fontMetrics.get(font);
   if (metrics == null) {
     measureElement.getStyle().setFontSize(font.size, Unit.PX);
     measureElement.getStyle().setFontWeight(Style.FontWeight.NORMAL);
     measureElement.getStyle().setFontStyle(Style.FontStyle.NORMAL);
     measureElement.getStyle().setProperty("fontFamily", font.name);
     measureElement.setInnerText(HEIGHT_TEXT);
     switch (font.style) {
       case BOLD:
         measureElement.getStyle().setFontWeight(Style.FontWeight.BOLD);
         break;
       case ITALIC:
         measureElement.getStyle().setFontStyle(Style.FontStyle.ITALIC);
         break;
       case BOLD_ITALIC:
         measureElement.getStyle().setFontWeight(Style.FontWeight.BOLD);
         measureElement.getStyle().setFontStyle(Style.FontStyle.ITALIC);
         break;
       default:
         break;
     }
     float height = measureElement.getOffsetHeight();
     measureElement.setInnerText(EMWIDTH_TEXT);
     float emwidth = measureElement.getOffsetWidth();
     metrics = new GWTFontMetrics(font, height, emwidth);
     fontMetrics.put(font, metrics);
   }
   return metrics;
 }
 @Override
 public int getWidth(Element e) {
   return (int)
       (e.getOffsetWidth()
           - num(curCSS(e, "paddingLeft", true))
           - num(curCSS(e, "paddingRight", true))
           - num(curCSS(e, "borderRightWidth", true))
           - num(curCSS(e, "borderRightWidth", true)));
 }
Exemple #5
0
  /**
   * Collects the position information of the given UI object and returns a position info bean.
   *
   * <p>
   *
   * @param element the object to read the position data from
   * @return the position data
   */
  public static PositionBean generatePositionInfo(Element element) {

    PositionBean result = new PositionBean();
    result.setHeight(element.getOffsetHeight());
    result.setWidth(element.getOffsetWidth());
    result.setTop(element.getAbsoluteTop());
    result.setLeft(element.getAbsoluteLeft());
    return result;
  }
  public int getTabsEffectiveWidth() {
    if (getWidgetCount() == 0) return 0;

    Element parent = getTabBarElement();
    if (parent == null) {
      return 0;
    }
    Element lastChild = getLastChildElement(parent);
    if (lastChild == null) {
      return 0;
    }
    return lastChild.getOffsetLeft() + lastChild.getOffsetWidth();
  }
  private void drawGraph(GWTGraph g, boolean now) {

    if (now) {
      m_graphDrawerNoTransition.updateGraph(g);
    } else {
      m_graphDrawer.updateGraph(g);
    }

    // TODO: working here
    SVGRect bbox = getSVGElement().getBBox();
    SVGGElement map = m_svgViewPort.cast();
    SVGRect mapBbox = map.getBBox();
    double referenceScale = 0.4;
    int x = bbox.getX();
    int y = bbox.getY();
    int width = (int) (mapBbox.getWidth() * referenceScale);
    int height = (int) (mapBbox.getHeight() * referenceScale);

    int viewPortWidth = (int) (m_svg.getOffsetWidth() * referenceScale);
    int viewPortHeight = (int) (m_svg.getOffsetHeight() * referenceScale);

    m_referenceMapViewport.setAttribute("width", "" + viewPortWidth);
    m_referenceMapViewport.setAttribute("height", "" + viewPortHeight);

    m_referenceMap.setAttribute(
        "transform",
        "translate("
            + (m_svg.getOffsetWidth() - width)
            + " "
            + (m_svg.getOffsetHeight() - height)
            + ")");

    // TODO: Fix this calc

    m_scaledMap.setAttribute(
        "viewBox", x + " " + y + " " + mapBbox.getWidth() + " " + mapBbox.getHeight());
  }
  private void display(Widget panel, Element underlyingMarker) {
    // Bail if the underlying marker isn't wide enough
    if (underlyingMarker.getOffsetWidth() < 250) return;

    // Get the 'virtual' parent -- this is the Ace scroller that houses all
    // of the Ace content, where we want our icons to live. We need them
    // to live here so that they properly hide when the user scrolls and
    // e.g. markers are only partially visible.
    Element virtualParent = DomUtils.getParent(underlyingMarker, 3);

    // We'd prefer to use 'getOffsetTop()' here, but that seems to give
    // some janky dimensions due to how the Ace layers are ... layered,
    // so we manually compute it.
    int top = underlyingMarker.getAbsoluteTop() - virtualParent.getAbsoluteTop();

    panel.getElement().getStyle().setTop(top, Unit.PX);
    virtualParent.appendChild(panel.getElement());
  }
  public WidgetArea(Widget widget, Widget reference) {
    setLeft(widget.getAbsoluteLeft());
    setTop(widget.getAbsoluteTop());

    if (reference != null) {
      setLeft(
          getLeft() - reference.getAbsoluteLeft() - DOMUtil.getBorderLeft(reference.getElement()));
      setTop(getTop() - reference.getAbsoluteTop() - DOMUtil.getBorderTop(reference.getElement()));
    }
    setRight(getLeft() + widget.getOffsetWidth());
    setBottom(getTop() + widget.getOffsetHeight());

    Element elem = widget.getElement().getOffsetParent();
    Element p;

    while (elem != null && (p = elem.getOffsetParent()) != null) {
      int left = elem.getAbsoluteLeft();

      if (getLeft() < left) {
        setLeft(left);
      }

      int top = elem.getAbsoluteTop();
      if (getTop() < top) {
        setTop(top);
      }

      int bottom = top + elem.getOffsetHeight();
      if (getBottom() > bottom) {
        setBottom(bottom);
      }

      int right = left + elem.getOffsetWidth();
      if (getRight() > right) {
        setRight(right);
      }

      elem = p;
    }
  }
  @Override
  public void onBrowserEvent(Event event) {
    GWT.log("slider mouse event: " + DOM.eventGetTypeString(event));
    if (DOM.eventGetType(event) == Event.ONCONTEXTMENU) {

      event.stopPropagation();
      event.preventDefault();

      int x = event.getClientX();
      int y = event.getClientY();
      NodeList<Node> children = getChildren().get(0).getElement().getChildNodes();
      for (int i = 0; i < children.getLength(); i++) {
        Node child = children.getItem(i);
        Element widget = (Element) child;
        String id = widget.getId();
        GWT.log("checking " + id + " to see if its the rightclicked element");
        int left = widget.getAbsoluteLeft();
        int width = widget.getOffsetWidth();
        int top = widget.getAbsoluteTop();
        int height = widget.getOffsetHeight();

        if (left < x && left + width > x && top < y && top + height > y) {

          this.clickedElement = DOM.getElementById(id);

          GWT.log(editor.getElement().getId() + " context menu for " + id);
          GWT.log("positioning context menu at " + event.getClientX() + "x" + event.getClientY());
          contextMenu.show(event.getClientX(), event.getClientY(), menu);
          break;
        }
      }

    } else if (DOM.eventGetType(event) == Event.ONCLICK) {
      ContextMenu.hide();
    }
    super.onBrowserEvent(event);
  }
Exemple #11
0
 private boolean isPseudoMarker(Element el) {
   return el.getOffsetHeight() == 0 || el.getOffsetWidth() == 0;
 }
    private void beginDrag(Event evt) {
      String docId = initDragParams_.getDocId();
      int dragTabWidth = initDragWidth_;

      // set drag element state
      dragTabsHost_ = getTabBarElement();
      dragScrollHost_ = dragTabsHost_.getParentElement();
      outOfBounds_ = 0;
      candidatePos_ = null;
      startPos_ = null;

      // attempt to determine which tab the cursor is over
      Point hostPos = DomUtils.getRelativePosition(Document.get().getBody(), dragTabsHost_);
      int dragX = evt.getClientX() - hostPos.getX();
      for (int i = 0; i < dragTabsHost_.getChildCount(); i++) {
        Node node = dragTabsHost_.getChild(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
          int left =
              DomUtils.leftRelativeTo(dragTabsHost_, Element.as(node))
                  - dragScrollHost_.getScrollLeft();
          int right = left + Element.as(node).getOffsetWidth();
          if (left <= dragX && dragX <= right) {
            candidatePos_ = i;
            break;
          }
        }
      }

      // let the rest of the IDE know we're dragging (this will enable us to
      // disable drag targets that might otherwise be happy to accept the
      // data)
      curState_ = STATE_DRAGGING;
      events_.fireEvent(
          new DocTabDragStateChangedEvent(DocTabDragStateChangedEvent.STATE_DRAGGING));

      // the relative position of the last node determines how far we
      // can drag
      dragMax_ =
          DomUtils.leftRelativeTo(dragTabsHost_, getLastChildElement(dragTabsHost_))
              + getLastChildElement(dragTabsHost_).getClientWidth();
      lastCursorX_ = evt.getClientX();

      // account for cursor starting out of bounds (e.g. dragging into
      // empty space on the right of the panel)
      if (lastCursorX_ > dragMax_ + (initDragParams_.getCursorOffset()))
        outOfBounds_ = (lastCursorX_ - dragMax_) - initDragParams_.getCursorOffset();

      // attempt to ascertain whether the element being dragged is one of
      // our own documents
      for (DocTab tab : docTabs_) {
        if (tab.getDocId() == docId) {
          dragElement_ = tab.getElement().getParentElement().getParentElement();
          break;
        }
      }

      // if we couldn't find the horizontal drag position in any tab, append
      // to the end
      if (candidatePos_ == null) {
        candidatePos_ = dragTabsHost_.getChildCount();
      }

      destPos_ = candidatePos_;

      // if we're dragging one of our own documents, figure out its physical
      // position
      if (dragElement_ != null) {
        for (int i = 0; i < dragTabsHost_.getChildCount(); i++) {
          if (dragTabsHost_.getChild(i) == dragElement_) {
            startPos_ = i;
            break;
          }
        }
      }

      // compute the start location for the drag
      if (candidatePos_ >= dragTabsHost_.getChildCount()) {
        Element lastTab = getLastChildElement(dragTabsHost_);
        lastElementX_ = DomUtils.leftRelativeTo(dragTabsHost_, lastTab) + lastTab.getOffsetWidth();
      } else {
        lastElementX_ =
            DomUtils.leftRelativeTo(
                dragTabsHost_, Element.as(dragTabsHost_.getChild(candidatePos_)));
      }

      // if we're dragging one of our own tabs, snap it out of the
      // tabset
      if (dragElement_ != null) {
        dragElement_.getStyle().setPosition(Position.ABSOLUTE);
        dragElement_.getStyle().setLeft(lastElementX_, Unit.PX);
        dragElement_.getStyle().setZIndex(100);
        Scheduler.get()
            .scheduleDeferred(
                new ScheduledCommand() {
                  @Override
                  public void execute() {
                    dragElement_.getStyle().setDisplay(Display.NONE);
                  }
                });
      }

      // create the placeholder that shows where this tab will go when the
      // mouse is released
      dragPlaceholder_ = Document.get().createDivElement();
      dragPlaceholder_.getStyle().setWidth(dragTabWidth - 4, Unit.PX);
      dragPlaceholder_.getStyle().setHeight(dragTabsHost_.getClientHeight() - 3, Unit.PX);
      dragPlaceholder_.getStyle().setDisplay(Display.INLINE_BLOCK);
      dragPlaceholder_.getStyle().setPosition(Position.RELATIVE);
      dragPlaceholder_.getStyle().setFloat(Float.LEFT);
      dragPlaceholder_.getStyle().setBorderStyle(BorderStyle.DOTTED);
      dragPlaceholder_.getStyle().setBorderColor("#A1A2A3");
      dragPlaceholder_.getStyle().setBorderWidth(1, Unit.PX);
      dragPlaceholder_.getStyle().setMarginLeft(1, Unit.PX);
      dragPlaceholder_.getStyle().setMarginRight(1, Unit.PX);
      dragPlaceholder_.getStyle().setProperty("borderTopLeftRadius", "4px");
      dragPlaceholder_.getStyle().setProperty("borderTopRightRadius", "4px");
      dragPlaceholder_.getStyle().setProperty("borderBottom", "0px");
      if (candidatePos_ < dragTabsHost_.getChildCount()) {
        dragTabsHost_.insertBefore(dragPlaceholder_, dragTabsHost_.getChild(candidatePos_));
      } else {
        dragTabsHost_.appendChild(dragPlaceholder_);
      }
    }
  public void ensureSelectedTabIsVisible(boolean animate) {
    if (currentAnimation_ != null) {
      currentAnimation_.cancel();
      currentAnimation_ = null;
    }

    Element selectedTab =
        (Element)
            DomUtils.findNode(
                getElement(),
                true,
                false,
                new NodePredicate() {
                  public boolean test(Node n) {
                    if (n.getNodeType() != Node.ELEMENT_NODE) return false;
                    return ((Element) n).getClassName().contains("gwt-TabLayoutPanelTab-selected");
                  }
                });
    if (selectedTab == null) {
      return;
    }
    selectedTab = selectedTab.getFirstChildElement().getFirstChildElement();

    Element tabBar = getTabBarElement();

    if (!isVisible() || !isAttached() || tabBar.getOffsetWidth() == 0) return; // not yet loaded

    final Element tabBarParent = tabBar.getParentElement();

    final int start = tabBarParent.getScrollLeft();
    int end =
        DomUtils.ensureVisibleHoriz(
            tabBarParent, selectedTab, padding_, padding_ + rightMargin_, true);

    // When tabs are closed, the overall width shrinks, and this can lead
    // to cases where there's too much empty space on the screen
    Node lastTab = getLastChildElement(tabBar);
    if (lastTab == null || lastTab.getNodeType() != Node.ELEMENT_NODE) return;
    int edge =
        DomUtils.getRelativePosition(tabBarParent, Element.as(lastTab)).x
            + Element.as(lastTab).getOffsetWidth();
    end = Math.min(end, Math.max(0, edge - (tabBarParent.getOffsetWidth() - rightMargin_)));

    if (edge <= tabBarParent.getOffsetWidth() - rightMargin_) end = 0;

    if (start != end) {
      if (!animate) {
        tabBarParent.setScrollLeft(end);
      } else {
        final int finalEnd = end;
        currentAnimation_ =
            new Animation() {
              @Override
              protected void onUpdate(double progress) {
                double delta = (finalEnd - start) * progress;
                tabBarParent.setScrollLeft((int) (start + delta));
              }

              @Override
              protected void onComplete() {
                if (this == currentAnimation_) {
                  tabBarParent.setScrollLeft(finalEnd);
                  currentAnimation_ = null;
                }
              }
            };
        currentAnimation_.run(Math.max(200, Math.min(1500, Math.abs(end - start) * 2)));
      }
    }
  }
Exemple #14
0
  /**
   * Returns a position info representing the dimensions of all visible child elements of the given
   * panel (excluding elements with position:absolute). If the panel has no visible child elements,
   * it's outer dimensions are returned.
   *
   * <p>
   *
   * @param panel the panel
   * @param levels the levels to traverse down the DOM tree
   * @param includeSelf <code>true</code> to include the outer dimensions of the given panel
   * @return the position info
   */
  public static PositionBean getInnerDimensions(Element panel, int levels, boolean includeSelf) {

    boolean first = true;
    int top = 0;
    int left = 0;
    int bottom = 0;
    int right = 0;
    // if overflow is set to hidden, use the outer dimensions
    if (!Overflow.HIDDEN.getCssName().equals(DomUtil.getCurrentStyle(panel, Style.overflow))) {
      if (!includeSelf) {
        // check for any text content
        NodeList<Node> children = panel.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
          if ((children.getItem(i).getNodeType() == Node.TEXT_NODE)
              && (children.getItem(i).getNodeValue().trim().length() > 0)) {
            includeSelf = true;
            break;
          }
        }
      }
      if (includeSelf) {
        top = panel.getAbsoluteTop();
        left = panel.getAbsoluteLeft();
        bottom = top + panel.getOffsetHeight();
        right = left + panel.getOffsetWidth();
        first = false;
      }
      Element child = panel.getFirstChildElement();
      while (child != null) {
        String tagName = child.getTagName();
        if (tagName.equalsIgnoreCase("br")
            || tagName.equalsIgnoreCase("tr")
            || tagName.equalsIgnoreCase("thead")
            || tagName.equalsIgnoreCase("tfoot")
            || tagName.equalsIgnoreCase("script")
            || tagName.equalsIgnoreCase("style")) {
          // ignore tags with no relevant position info
          child = child.getNextSiblingElement();
          continue;
        }
        String positioning = DomUtil.getCurrentStyle(child, Style.position);
        if (!Display.NONE.getCssName().equals(DomUtil.getCurrentStyle(child, Style.display))
            && !(positioning.equalsIgnoreCase(Position.ABSOLUTE.getCssName())
                || positioning.equalsIgnoreCase(Position.FIXED.getCssName()))) {
          PositionBean childDimensions =
              levels > 0
                  ? getInnerDimensions(child, levels - 1, true)
                  : generatePositionInfo(panel);
          if (first) {
            first = false;
            top = childDimensions.getTop();
            left = childDimensions.getLeft();
            bottom = top + childDimensions.getHeight();
            right = left + childDimensions.getWidth();
          } else {
            int wTop = childDimensions.getTop();
            top = top < wTop ? top : wTop;
            int wLeft = childDimensions.getLeft();
            left = left < wLeft ? left : wLeft;
            int wBottom = wTop + childDimensions.getHeight();
            bottom = bottom > wBottom ? bottom : wBottom;
            int wRight = wLeft + childDimensions.getWidth();
            right = right > wRight ? right : wRight;
          }
        }
        child = child.getNextSiblingElement();
      }
    }
    if (!first) {
      PositionBean result = new PositionBean();
      result.setHeight(bottom - top);
      result.setWidth(right - left);
      result.setTop(top);
      result.setLeft(left);
      return result;
    } else {
      return generatePositionInfo(panel);
    }
  }
Exemple #15
0
  public GWTGraphics(final Panel panel, final LGame game, final GWTSetting cfg) {
    super(game, new GWTGL20(), new Scale(cfg.scaleFactor));

    this.config = cfg;
    Document doc = Document.get();
    this.dummyCanvas = doc.createCanvasElement();
    this.dummyCtx = dummyCanvas.getContext2d();

    Element root = panel.getElement();

    this.rootElement = root;

    measureElement = doc.createDivElement();
    measureElement.getStyle().setVisibility(Style.Visibility.HIDDEN);
    measureElement.getStyle().setPosition(Style.Position.ABSOLUTE);
    measureElement.getStyle().setTop(-500, Unit.PX);
    measureElement.getStyle().setOverflow(Style.Overflow.VISIBLE);
    measureElement.getStyle().setWhiteSpace(Style.WhiteSpace.NOWRAP);
    root.appendChild(measureElement);

    mouseScale = config.scaleFactor / Loon.devicePixelRatio();

    canvas = Document.get().createCanvasElement();
    root.appendChild(canvas);
    if (config.scaling()) {
      setSize(
          config.width_zoom > 0 ? config.width_zoom : root.getOffsetWidth(),
          config.height_zoom > 0 ? config.height_zoom : root.getOffsetHeight());
    } else {
      setSize(
          config.width > 0 ? config.width : root.getOffsetWidth(),
          config.height > 0 ? config.height : root.getOffsetHeight());
    }
    WebGLContextAttributes attrs = WebGLContextAttributes.create();
    attrs.setAntialias(config.antiAliasing);
    attrs.setStencil(config.stencil);
    attrs.setAlpha(config.transparentCanvas);
    attrs.setPremultipliedAlpha(config.premultipliedAlpha);
    attrs.setPreserveDrawingBuffer(config.preserveDrawingBuffer);

    WebGLRenderingContext glc = WebGLRenderingContext.getContext(canvas, attrs);
    if (glc == null) {
      throw new RuntimeException("Unable to create GL context");
    }

    ((GWTGL20) gl).init(glc);

    if (config.scaling()) {
      glc.viewport(0, 0, config.width_zoom, config.height_zoom);
    } else {
      glc.viewport(0, 0, config.width, config.height);
    }

    if (config.fullscreen) {
      Window.addResizeHandler(
          new ResizeHandler() {
            @Override
            public void onResize(ResizeEvent event) {
              if (getScreenWidthJSNI() == event.getWidth()
                  && getScreenHeightJSNI() == event.getHeight()) {
                float width = LSystem.viewSize.width(), height = LSystem.viewSize.height();
                experimentalScale =
                    Math.min(getScreenWidthJSNI() / width, getScreenHeightJSNI() / height);

                int yOfs = (int) ((getScreenHeightJSNI() - height * experimentalScale) / 3.f);
                int xOfs = (int) ((getScreenWidthJSNI() - width * experimentalScale) / 2.f);
                rootElement.setAttribute(
                    "style",
                    "width:"
                        + experimentalScale * width
                        + "px; "
                        + "height:"
                        + experimentalScale * height
                        + "px; "
                        + "position:absolute; left:"
                        + xOfs
                        + "px; top:"
                        + yOfs);
                Document.get().getBody().addClassName("fullscreen");
              } else {
                experimentalScale = 1;
                rootElement.removeAttribute("style");
                Document.get().getBody().removeClassName("fullscreen");
              }
            }
          });
    }

    Loon.self.addHandler(
        new OrientationChangedHandler() {
          @Override
          public void onChanged(Orientation newOrientation) {
            int width = Loon.self.getContainerWidth();
            int height = Loon.self.getContainerHeight();
            game.log().info("update screen size width :" + width + " height :" + height);
            setSize(width, height);
          }
        });
  }