Hello,

I want to modify the Edge-creating Drag and Drop method of the Vertexlabels in JGraphx. I like to make them "jumping" to the next Vertex, when I´m get near to a Vertex while Dragging. I´ve searched about 8 Hours for an solution but didn´t find some really helpful thing. The "mxGraphHandler.prototype.guidesEnabled" Property, which is suggested in an Answer in this forum I didn´t found. I guess it is only for JavaScript, is it?

Is there an easy way to make Draged Edges magnetic (gluing) to Vertices?

Thank You for your Help

asked 28 Sep '12, 08:17

Koreatanne's gravatar image

Koreatanne
211
accept rate: 0%


One week later I´m able to answer my Own Question. I have Override mxGraphComponent.getCellat

Code looks like this:

...

@Override

public Object getCellAt(int x, int y, boolean hitSwimlaneContent, Object parent) {

     ...
  if (result != null)
  {
    return result;
  }
  else if (graph.isCellVisible(cell))
      {     
    mxCellState state = view.getState(cell); 
    mxCell targetCell = (mxCell) cell;

    if (    targetCell != null && targetCell.isVertex()     && 
        getConnectionHandler().isConnecting() && state != null)
    {                                                       
        Rectangle cellConstraints = new Rectangle((int)state.getX(),
        (int)state.getY(), (int)state.getWidth(), (int)state.getHeight());

            if (intersectsMagnetic(cellConstraints, new Point(x,y), 30) && 
            (!graph.isSwimlane(cell) || hitSwimlaneContent || 
            (transparentSwimlaneContent &&    
                !canvas.hitSwimlaneContent(this, state, x, y))))
        {
            return cell;
        }

    //normal getCellAt Routine
    if (state != null && canvas.intersects(this, hit, state) &&            
        ...         
}
    ...

private boolean intersectsMagnetic(Rectangle dest, Point p, int tol)
{   
    return dest.getX() - tol <= p.x
        && dest.getY() - tol <= p.y
        && dest.getX() + dest.getWidth() + tol >= p.x
        && dest.getY() + dest.getHeight() + tol >= p.y;         
}
link

answered 11 Oct '12, 06:58

Koreatanne's gravatar image

Koreatanne
211
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×37

Asked: 28 Sep '12, 08:17

Seen: 910 times

Last updated: 11 Oct '12, 06:58