/** * Returns an mxPoint representing the given event in the unscaled, * non-translated coordinate space and applies the grid. */ public mxPoint getPointForEvent(MouseEvent e, boolean addOffset) { double s = graph.getView().getScale(); mxPoint tr = graph.getView().getTranslate(); double off = (addOffset) ? graph.getGridSize() / 2 : 0; double x = graph.snap(e.getX() / s - tr.getX() - off); double y = graph.snap(e.getY() / s - tr.getY() - off); return new mxPoint(x, y); }
/** * Returns an mxPoint representing the given event in the unscaled, * non-translated coordinate space and applies the grid. */ public mxPoint getPointForEvent(MouseEvent e, boolean addOffset) { double s = graph.getView().getScale(); mxPoint tr = graph.getView().getTranslate(); double off = (addOffset) ? graph.getGridSize() / 2 : 0; double x = graph.snap(e.getX() / s - tr.getX() - off); double y = graph.snap(e.getY() / s - tr.getY() - off); return new mxPoint(x, y); }
/** * */ public Object createTargetVertex(MouseEvent e, Object source) { mxGraph graph = graphComponent.getGraph(); Object clone = graph.cloneCells(new Object[] { source })[0]; mxIGraphModel model = graph.getModel(); mxGeometry geo = model.getGeometry(clone); if (geo != null) { mxPoint point = graphComponent.getPointForEvent(e); geo.setX(graph.snap(point.getX() - geo.getWidth() / 2)); geo.setY(graph.snap(point.getY() - geo.getHeight() / 2)); } return clone; }
/** * */ public Object createTargetVertex(MouseEvent e, Object source) { mxGraph graph = graphComponent.getGraph(); Object clone = graph.cloneCells(new Object[] { source })[0]; mxIGraphModel model = graph.getModel(); mxGeometry geo = model.getGeometry(clone); if (geo != null) { mxPoint point = graphComponent.getPointForEvent(e); geo.setX(graph.snap(point.getX() - geo.getWidth() / 2)); geo.setY(graph.snap(point.getY() - geo.getHeight() / 2)); } return clone; }
/** * */ public mxPoint snapScaledPoint(mxPoint pt, double dx, double dy) { if (pt != null) { double scale = graph.getView().getScale(); mxPoint trans = graph.getView().getTranslate(); pt.setX((graph.snap(pt.getX() / scale - trans.getX() + dx / scale) + trans .getX()) * scale - dx); pt.setY((graph.snap(pt.getY() / scale - trans.getY() + dy / scale) + trans .getY()) * scale - dy); } return pt; }
/** * */ public mxPoint snapScaledPoint(mxPoint pt, double dx, double dy) { if (pt != null) { double scale = graph.getView().getScale(); mxPoint trans = graph.getView().getTranslate(); pt.setX((graph.snap(pt.getX() / scale - trans.getX() + dx / scale) + trans .getX()) * scale - dx); pt.setY((graph.snap(pt.getY() / scale - trans.getY() + dy / scale) + trans .getY()) * scale - dy); } return pt; }
/** * * @param point * @param gridEnabled * @return Returns the scaled, translated and grid-aligned point. */ protected mxPoint convertPoint(mxPoint point, boolean gridEnabled) { mxGraph graph = graphComponent.getGraph(); double scale = graph.getView().getScale(); mxPoint trans = graph.getView().getTranslate(); double x = point.getX() / scale - trans.getX(); double y = point.getY() / scale - trans.getY(); if (gridEnabled) { x = graph.snap(x); y = graph.snap(y); } point.setX(x - state.getOrigin().getX()); point.setY(y - state.getOrigin().getY()); return point; }
/** * * @param point * @param gridEnabled * @return Returns the scaled, translated and grid-aligned point. */ protected mxPoint convertPoint(mxPoint point, boolean gridEnabled) { mxGraph graph = graphComponent.getGraph(); double scale = graph.getView().getScale(); mxPoint trans = graph.getView().getTranslate(); double x = point.getX() / scale - trans.getX(); double y = point.getY() / scale - trans.getY(); if (gridEnabled) { x = graph.snap(x); y = graph.snap(y); } point.setX(x - state.getOrigin().getX()); point.setY(y - state.getOrigin().getY()); return point; }