Esempio n. 1
0
  private void updateScale(double oldScale, double newScale, SVGElement svg, int cx, int cy) {

    double zoomFactor = newScale / oldScale;
    // (x in new coord system - x in old coord system)/x coordinate
    SVGGElement g = m_svgViewPort.cast();

    if (cx == 0) {
      cx = (int) (Math.ceil(svg.getOffsetWidth() / 2.0) - 1);
    }

    if (cy == 0) {
      cy = (int) (Math.ceil(svg.getOffsetHeight() / 2.0) - 1);
    }

    SVGPoint p = svg.createSVGPoint();
    p.setX(cx);
    p.setY(cy);
    p = p.matrixTransform(g.getCTM().inverse());

    SVGMatrix m =
        svg.createSVGMatrix()
            .translate(p.getX(), p.getY())
            .scale(zoomFactor)
            .translate(-p.getX(), -p.getY());
    SVGMatrix ctm = g.getCTM().multiply(m);

    consoleLog("zoomFactor: " + zoomFactor + " oldScale: " + oldScale + " newScale:" + newScale);
    D3.d3()
        .select(m_svgViewPort)
        .transition()
        .duration(1000)
        .attr("transform", matrixTransform(ctm));
  }
Esempio n. 2
0
    public PanObject(Element draggableElement, Element containerElement) {
      super(draggableElement, containerElement);

      SVGGElement g = draggableElement.cast();
      m_stateTf = g.getCTM().inverse();

      m_stateOrigin = getEventPoint(D3.getEvent()).matrixTransform(m_stateTf);
    }
Esempio n. 3
0
 private static TableCellElement findNearestParentCell(Element elem) {
   while ((elem != null)) {
     String tagName = elem.getTagName();
     if ("td".equalsIgnoreCase(tagName) || "th".equalsIgnoreCase(tagName)) {
       return elem.cast();
     }
     elem = elem.getParentElement();
   }
   return null;
 }
Esempio n. 4
0
  @PatchMethod
  static Element getParent(Element elem) {
    com.google.gwt.dom.client.Element parentElem = elem.getParentElement();

    if (parentElem == null) {
      return null;
    }

    Element parent = parentElem.cast();
    return parent;
  }
Esempio n. 5
0
  /** {@code ClickHandler} */
  @Override
  public void onClick(ClickEvent event) {
    NativeEvent nativeEvent = event.getNativeEvent();
    Element element = DOM.eventGetTarget(Event.as(nativeEvent));
    element =
        GWTUtils.getElementWithAttr((com.google.gwt.user.client.Element) element.cast(), "uid");
    Element dataQueryEl = null;
    if (element != null) {
      dataQueryEl =
          GWTUtils.findDataQueryElement((com.google.gwt.user.client.Element) element.cast());
      String uid = element.getAttribute("uid");
      String json = dataQueryEl.getAttribute("data-query");

      if (!GWTUtils.isEmpty(uid)) {
        JSONObject targetJson = null;
        if (!GWTUtils.isEmpty(json)) {
          targetJson = (JSONObject) JSONParser.parse(json);
        }
        processClickEvent(uid, targetJson);
      }
    } else {
      return;
    }
  }
Esempio n. 6
0
  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());
  }
  @AssistedInject
  public CodeMirrorEditorWidget(
      final ModuleHolder moduleHolder,
      final EventBus eventBus,
      final KeymapPrefReader keymapPrefReader,
      final CompletionResources completionResources,
      final EditorAgent editorAgent,
      @Assisted final List<String> editorModes,
      final RequireJsLoader requirejs,
      final MinimapFactory minimapFactory,
      final BasePathConstant basePathConstant,
      @Assisted final WidgetInitializedCallback widgetInitializedCallback) {
    initWidget(UIBINDER.createAndBindUi(this));

    this.keymapPrefReader = keymapPrefReader;
    this.requirejs = requirejs;
    this.showCompletion = new ShowCompletion(this, completionResources.completionCss());
    this.codemirrorBasePath = basePathConstant.basePath();

    this.codeMirror =
        moduleHolder.getModule(CodeMirrorEditorExtension.CODEMIRROR_MODULE_KEY).cast();

    this.editorOverlay = this.codeMirror.createEditor(this.panel.getElement(), getConfiguration());
    this.editorOverlay.setSize("100%", "100%");
    this.editorOverlay.refresh();

    this.positionConverter = new CodemirrorPositionConverter(this.editorOverlay);

    this.minimap = minimapFactory.createMinimap(rightGutter.<JsDivElement>cast());
    this.minimap.setDocument(getDocument());

    this.gutter = new CodemirrorGutter(this.codeMirror, this.editorOverlay);

    // just first choice for the moment
    if (editorModes != null && !editorModes.isEmpty()) {
      setMode(editorModes.get(0));
    }

    initKeyBindings();

    setupKeymap();
    eventBus.addHandler(
        KeymapChangeEvent.TYPE,
        new KeymapChangeHandler() {

          @Override
          public void onKeymapChanged(final KeymapChangeEvent event) {
            final String editorTypeKey = event.getEditorTypeKey();
            if (CodeMirrorEditorExtension.CODEMIRROR_EDITOR_KEY.equals(editorTypeKey)) {
              setupKeymap();
            }
          }
        });
    this.generationMarker = this.editorOverlay.getDoc().changeGeneration(true);

    // configure the save command to launch the save action
    // so the alternate keybinding save shortcut work (for example :w in vim)
    this.codeMirror
        .commands()
        .put(
            "save",
            CMCommandOverlay.create(
                new CMCommandOverlay.CommandFunction() {
                  @Override
                  public void execCommand(final CMEditorOverlay editor) {
                    editorAgent.getActiveEditor().doSave();
                  }
                }));

    buildKeybindingInfo();
    this.undoRedo = new CodeMirrorUndoRedo(this.editorOverlay.getDoc());
    widgetInitializedCallback.initialized(this);
  }
Esempio n. 8
0
 private SVGElement getSVGElement() {
   return m_svg.cast();
 }
Esempio n. 9
0
 /**
  * Assert that the given {@link Element} is compatible with this class and automatically typecast
  * it.
  */
 public static AudioElement as(Element elem) {
   assert elem.getTagName().equalsIgnoreCase(TAG);
   return elem.cast();
 }