/** * */ protected void paintBackgroundImage(Graphics g) { if (backgroundImage != null) { mxPoint translate = graph.getView().getTranslate(); double scale = graph.getView().getScale(); g.drawImage(backgroundImage.getImage(), (int) (translate.getX() * scale), (int) (translate.getY() * scale), (int) (backgroundImage.getIconWidth() * scale), (int) (backgroundImage.getIconHeight() * scale), this); } }
/** * */ protected void paintBackgroundImage(Graphics g) { if (backgroundImage != null) { mxPoint translate = graph.getView().getTranslate(); double scale = graph.getView().getScale(); g.drawImage(backgroundImage.getImage(), (int) (translate.getX() * scale), (int) (translate.getY() * scale), (int) (backgroundImage.getIconWidth() * scale), (int) (backgroundImage.getIconHeight() * scale), this); } }
/** * 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); }
/** * */ protected mxPoint transformScreenPoint(double x, double y) { mxGraph graph = graphComponent.getGraph(); mxPoint tr = graph.getView().getTranslate(); double scale = graph.getView().getScale(); return new mxPoint(graph.snap(x / scale - tr.getX()), graph.snap(y / scale - tr.getY())); }
/** * */ protected mxPoint transformScreenPoint(double x, double y) { mxGraph graph = graphComponent.getGraph(); mxPoint tr = graph.getView().getTranslate(); double scale = graph.getView().getScale(); return new mxPoint(graph.snap(x / scale - tr.getX()), graph.snap(y / scale - tr.getY())); }
/** * Returns the top, left corner of the given cell. */ protected mxPoint getOriginForCell(Object cell) { mxPoint result = origins.get(cell); if (result == null) { mxGraph graph = graphComponent.getGraph(); if (cell != null) { result = new mxPoint(getOriginForCell(graph.getModel() .getParent(cell))); mxGeometry geo = graph.getCellGeometry(cell); // TODO: Handle offset, relative geometries etc if (geo != null) { result.setX(result.getX() + geo.getX()); result.setY(result.getY() + geo.getY()); } } if (result == null) { mxPoint t = graph.getView().getTranslate(); result = new mxPoint(-t.getX(), -t.getY()); } origins.put(cell, result); } return result; }
origin.setY(origin.getY() + y0); mxPoint t = getView().getTranslate(); getView().setTranslate( new mxPoint(t.getX() - x0, t.getY() - y0)); origin.setY(origin.getY() + dy); mxPoint t = getView().getTranslate(); getView().setTranslate( new mxPoint(t.getX() - dx, t.getY() - dy));
/** * Returns the top, left corner of the given cell. */ protected mxPoint getOriginForCell(Object cell) { mxPoint result = origins.get(cell); if (result == null) { mxGraph graph = graphComponent.getGraph(); if (cell != null) { result = new mxPoint(getOriginForCell(graph.getModel() .getParent(cell))); mxGeometry geo = graph.getCellGeometry(cell); // TODO: Handle offset, relative geometries etc if (geo != null) { result.setX(result.getX() + geo.getX()); result.setY(result.getY() + geo.getY()); } } if (result == null) { mxPoint t = graph.getView().getTranslate(); result = new mxPoint(-t.getX(), -t.getY()); } origins.put(cell, result); } return result; }
/** * */ 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; }
/** * */ public void mouseReleased(MouseEvent e) { if (graphComponent.isEnabled() && isEnabled() && !e.isConsumed() && current != null) { mxGraph graph = graphComponent.getGraph(); double scale = graph.getView().getScale(); mxPoint tr = graph.getView().getTranslate(); current.setX(current.getX() / scale - tr.getX()); current.setY(current.getY() / scale - tr.getY()); current.setWidth(current.getWidth() / scale); current.setHeight(current.getHeight() / scale); Object cell = insertCell(current); eventSource.fireEvent(new mxEventObject(mxEvent.INSERT, "cell", cell)); e.consume(); } reset(); }
/** * Returns the vector between the current rendered state and the future * location of the state after the display will be updated. */ protected mxPoint getDelta(mxCellState state) { mxGraph graph = graphComponent.getGraph(); mxPoint origin = getOriginForCell(state.getCell()); mxPoint translate = graph.getView().getTranslate(); double scale = graph.getView().getScale(); mxPoint current = new mxPoint(state.getX() / scale - translate.getX(), state.getY() / scale - translate.getY()); return new mxPoint((origin.getX() - current.getX()) * scale, (origin .getY() - current.getY()) * scale); }
/** * */ public mxGraphTransferable createGraphTransferable( mxGraphComponent graphComponent, Object[] cells, ImageIcon icon) { mxGraph graph = graphComponent.getGraph(); mxPoint tr = graph.getView().getTranslate(); double scale = graph.getView().getScale(); mxRectangle bounds = graph.getPaintBounds(cells); // Removes the scale and translation from the bounds bounds.setX(bounds.getX() / scale - tr.getX()); bounds.setY(bounds.getY() / scale - tr.getY()); bounds.setWidth(bounds.getWidth() / scale); bounds.setHeight(bounds.getHeight() / scale); return createGraphTransferable(graphComponent, cells, bounds, icon); }
/** * Returns the vector between the current rendered state and the future * location of the state after the display will be updated. */ protected mxPoint getDelta(mxCellState state) { mxGraph graph = graphComponent.getGraph(); mxPoint origin = getOriginForCell(state.getCell()); mxPoint translate = graph.getView().getTranslate(); double scale = graph.getView().getScale(); mxPoint current = new mxPoint(state.getX() / scale - translate.getX(), state.getY() / scale - translate.getY()); return new mxPoint((origin.getX() - current.getX()) * scale, (origin .getY() - current.getY()) * scale); }
/** * */ public void mouseReleased(MouseEvent e) { if (graphComponent.isEnabled() && isEnabled() && !e.isConsumed() && current != null) { mxGraph graph = graphComponent.getGraph(); double scale = graph.getView().getScale(); mxPoint tr = graph.getView().getTranslate(); current.setX(current.getX() / scale - tr.getX()); current.setY(current.getY() / scale - tr.getY()); current.setWidth(current.getWidth() / scale); current.setHeight(current.getHeight() / scale); Object cell = insertCell(current); eventSource.fireEvent(new mxEventObject(mxEvent.INSERT, "cell", cell)); e.consume(); } reset(); }
/** * */ public mxGraphTransferable createGraphTransferable( mxGraphComponent graphComponent, Object[] cells, ImageIcon icon) { mxGraph graph = graphComponent.getGraph(); mxPoint tr = graph.getView().getTranslate(); double scale = graph.getView().getScale(); mxRectangle bounds = graph.getPaintBounds(cells); // Removes the scale and translation from the bounds bounds.setX(bounds.getX() / scale - tr.getX()); bounds.setY(bounds.getY() / scale - tr.getY()); bounds.setWidth(bounds.getWidth() / scale); bounds.setHeight(bounds.getHeight() / scale); return createGraphTransferable(graphComponent, cells, bounds, icon); }
/** * * @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; }
&& (delta.getX() != 0 || delta.getY() != 0)) mxPoint translate = graph.getView().getTranslate(); double scale = graph.getView().getScale();