com.mxgraph.view.mxGraph.snap()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(5.9k)|赞(0)|评价(0)|浏览(107)

本文整理了Java中com.mxgraph.view.mxGraph.snap()方法的一些代码示例,展示了mxGraph.snap()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。mxGraph.snap()方法的具体详情如下:
包路径:com.mxgraph.view.mxGraph
类名称:mxGraph
方法名:snap

mxGraph.snap介绍

[英]Snaps the given numeric value to the grid if is true.
[中]如果为true,则将给定的数值捕捉到网格。

代码示例

代码示例来源:origin: org.tinyjee.jgraphx/jgraphx

  1. /**
  2. * Returns an mxPoint representing the given event in the unscaled,
  3. * non-translated coordinate space and applies the grid.
  4. */
  5. public mxPoint getPointForEvent(MouseEvent e, boolean addOffset)
  6. {
  7. double s = graph.getView().getScale();
  8. mxPoint tr = graph.getView().getTranslate();
  9. double off = (addOffset) ? graph.getGridSize() / 2 : 0;
  10. double x = graph.snap(e.getX() / s - tr.getX() - off);
  11. double y = graph.snap(e.getY() / s - tr.getY() - off);
  12. return new mxPoint(x, y);
  13. }

代码示例来源:origin: com.github.vlsi.mxgraph/jgraphx

  1. /**
  2. * Returns an mxPoint representing the given event in the unscaled,
  3. * non-translated coordinate space and applies the grid.
  4. */
  5. public mxPoint getPointForEvent(MouseEvent e, boolean addOffset)
  6. {
  7. double s = graph.getView().getScale();
  8. mxPoint tr = graph.getView().getTranslate();
  9. double off = (addOffset) ? graph.getGridSize() / 2 : 0;
  10. double x = graph.snap(e.getX() / s - tr.getX() - off);
  11. double y = graph.snap(e.getY() / s - tr.getY() - off);
  12. return new mxPoint(x, y);
  13. }

代码示例来源:origin: com.github.vlsi.mxgraph/jgraphx

  1. /**
  2. *
  3. */
  4. protected mxPoint transformScreenPoint(double x, double y)
  5. {
  6. mxGraph graph = graphComponent.getGraph();
  7. mxPoint tr = graph.getView().getTranslate();
  8. double scale = graph.getView().getScale();
  9. return new mxPoint(graph.snap(x / scale - tr.getX()), graph.snap(y
  10. / scale - tr.getY()));
  11. }

代码示例来源:origin: org.tinyjee.jgraphx/jgraphx

  1. /**
  2. *
  3. */
  4. protected mxPoint transformScreenPoint(double x, double y)
  5. {
  6. mxGraph graph = graphComponent.getGraph();
  7. mxPoint tr = graph.getView().getTranslate();
  8. double scale = graph.getView().getScale();
  9. return new mxPoint(graph.snap(x / scale - tr.getX()), graph.snap(y
  10. / scale - tr.getY()));
  11. }

代码示例来源:origin: com.github.vlsi.mxgraph/jgraphx

  1. dxg = graph.snap(dxg);
  2. dyg = graph.snap(dyg);

代码示例来源:origin: org.tinyjee.jgraphx/jgraphx

  1. dxg = graph.snap(dxg);
  2. dyg = graph.snap(dyg);

代码示例来源:origin: com.github.vlsi.mxgraph/jgraphx

  1. dx = graph.snap(dx);
  2. dy = graph.snap(dy);
  3. int x = (int) graph.snap(rect.x);
  4. int y = (int) graph.snap(rect.y);
  5. rect.width = (int) graph.snap(rect.width - x + rect.x);
  6. rect.height = (int) graph.snap(rect.height - y + rect.y);
  7. rect.x = x;
  8. rect.y = y;

代码示例来源:origin: org.tinyjee.jgraphx/jgraphx

  1. dx = graph.snap(dx);
  2. dy = graph.snap(dy);
  3. int x = (int) graph.snap(rect.x);
  4. int y = (int) graph.snap(rect.y);
  5. rect.width = (int) graph.snap(rect.width - x + rect.x);
  6. rect.height = (int) graph.snap(rect.height - y + rect.y);
  7. rect.x = x;
  8. rect.y = y;

代码示例来源:origin: com.github.vlsi.mxgraph/jgraphx

  1. /**
  2. *
  3. */
  4. public Object createTargetVertex(MouseEvent e, Object source)
  5. {
  6. mxGraph graph = graphComponent.getGraph();
  7. Object clone = graph.cloneCells(new Object[] { source })[0];
  8. mxIGraphModel model = graph.getModel();
  9. mxGeometry geo = model.getGeometry(clone);
  10. if (geo != null)
  11. {
  12. mxPoint point = graphComponent.getPointForEvent(e);
  13. geo.setX(graph.snap(point.getX() - geo.getWidth() / 2));
  14. geo.setY(graph.snap(point.getY() - geo.getHeight() / 2));
  15. }
  16. return clone;
  17. }

代码示例来源:origin: org.tinyjee.jgraphx/jgraphx

  1. /**
  2. *
  3. */
  4. public Object createTargetVertex(MouseEvent e, Object source)
  5. {
  6. mxGraph graph = graphComponent.getGraph();
  7. Object clone = graph.cloneCells(new Object[] { source })[0];
  8. mxIGraphModel model = graph.getModel();
  9. mxGeometry geo = model.getGeometry(clone);
  10. if (geo != null)
  11. {
  12. mxPoint point = graphComponent.getPointForEvent(e);
  13. geo.setX(graph.snap(point.getX() - geo.getWidth() / 2));
  14. geo.setY(graph.snap(point.getY() - geo.getHeight() / 2));
  15. }
  16. return clone;
  17. }

代码示例来源:origin: org.tinyjee.jgraphx/jgraphx

  1. /**
  2. *
  3. */
  4. public mxPoint snapScaledPoint(mxPoint pt, double dx, double dy)
  5. {
  6. if (pt != null)
  7. {
  8. double scale = graph.getView().getScale();
  9. mxPoint trans = graph.getView().getTranslate();
  10. pt.setX((graph.snap(pt.getX() / scale - trans.getX() + dx / scale) + trans
  11. .getX()) * scale - dx);
  12. pt.setY((graph.snap(pt.getY() / scale - trans.getY() + dy / scale) + trans
  13. .getY()) * scale - dy);
  14. }
  15. return pt;
  16. }

代码示例来源:origin: com.github.vlsi.mxgraph/jgraphx

  1. /**
  2. *
  3. */
  4. public mxPoint snapScaledPoint(mxPoint pt, double dx, double dy)
  5. {
  6. if (pt != null)
  7. {
  8. double scale = graph.getView().getScale();
  9. mxPoint trans = graph.getView().getTranslate();
  10. pt.setX((graph.snap(pt.getX() / scale - trans.getX() + dx / scale) + trans
  11. .getX()) * scale - dx);
  12. pt.setY((graph.snap(pt.getY() / scale - trans.getY() + dy / scale) + trans
  13. .getY()) * scale - dy);
  14. }
  15. return pt;
  16. }

代码示例来源:origin: org.tinyjee.jgraphx/jgraphx

  1. dx = graph.snap(dx / scale);
  2. dy = graph.snap(dy / scale);

代码示例来源:origin: com.github.vlsi.mxgraph/jgraphx

  1. dx = graph.snap(dx / scale);
  2. dy = graph.snap(dy / scale);

代码示例来源:origin: org.tinyjee.jgraphx/jgraphx

  1. dx = graph.snap(dx / scale) * scale;
  2. dy = graph.snap(dy / scale) * scale;

代码示例来源:origin: com.github.vlsi.mxgraph/jgraphx

  1. dx = graph.snap(dx / scale) * scale;
  2. dy = graph.snap(dy / scale) * scale;

代码示例来源:origin: org.tinyjee.jgraphx/jgraphx

  1. handler.setOffset(new Point((int) graph.snap(dx / scale),
  2. (int) graph.snap(dy / scale)));
  3. pt.translate(dx, dy);

代码示例来源:origin: com.github.vlsi.mxgraph/jgraphx

  1. handler.setOffset(new Point((int) graph.snap(dx / scale),
  2. (int) graph.snap(dy / scale)));
  3. pt.translate(dx, dy);

代码示例来源:origin: com.github.vlsi.mxgraph/jgraphx

  1. /**
  2. *
  3. * @param point
  4. * @param gridEnabled
  5. * @return Returns the scaled, translated and grid-aligned point.
  6. */
  7. protected mxPoint convertPoint(mxPoint point, boolean gridEnabled)
  8. {
  9. mxGraph graph = graphComponent.getGraph();
  10. double scale = graph.getView().getScale();
  11. mxPoint trans = graph.getView().getTranslate();
  12. double x = point.getX() / scale - trans.getX();
  13. double y = point.getY() / scale - trans.getY();
  14. if (gridEnabled)
  15. {
  16. x = graph.snap(x);
  17. y = graph.snap(y);
  18. }
  19. point.setX(x - state.getOrigin().getX());
  20. point.setY(y - state.getOrigin().getY());
  21. return point;
  22. }

代码示例来源:origin: org.tinyjee.jgraphx/jgraphx

  1. /**
  2. *
  3. * @param point
  4. * @param gridEnabled
  5. * @return Returns the scaled, translated and grid-aligned point.
  6. */
  7. protected mxPoint convertPoint(mxPoint point, boolean gridEnabled)
  8. {
  9. mxGraph graph = graphComponent.getGraph();
  10. double scale = graph.getView().getScale();
  11. mxPoint trans = graph.getView().getTranslate();
  12. double x = point.getX() / scale - trans.getX();
  13. double y = point.getY() / scale - trans.getY();
  14. if (gridEnabled)
  15. {
  16. x = graph.snap(x);
  17. y = graph.snap(y);
  18. }
  19. point.setX(x - state.getOrigin().getX());
  20. point.setY(y - state.getOrigin().getY());
  21. return point;
  22. }

相关文章

mxGraph类方法