Hi,

\n

I want to add/delete Ports dynamically. the Background is, that i want to add a Port to a Vertice if there EdgeCount is 0(If the Vertice have no Edges i want to add a Port , then you can see ther eis a Node and i can connect to it.)

\n

I tried it this way:

\n

mViewer is a mxGraphComponent

\n
private void DoPort(){\n    mxCell pCell = new mxCell();\n\n    //Need to set Position of the Port to the Center of the Cell\n    mxGeometry pGeo = new mxGeometry(0,0.5,PORT_DIAMETER,PORT_DIAMETER);\n    pGeo.setOffset(new mxPoint(-PORT_RADIUS,-PORT_RADIUS));\n    pGeo.setRelative(true);\n\n    mxCell port = new mxCell(null,pGeo,"shape=ellipse;perimeter=ellipsePerimeter");\n\n    for(Object i : mViewer.getGraph().getChildVertices(mViewer.getGraph().getDefaultParent())){\n        pCell = (mxCell) i;\n        mViewer.getGraph().getModel().beginUpdate();\n        try{\n            if(pCell.getEdgeCount()==0){\n                mViewer.getGraph().addCell(port,i);\n            }else{\n                Object[] removeCells = new Object[1];\n                removeCells[0] = port;\n                mViewer.getGraph().removeCells(removeCells);\n            }\n        }finally{\n            mViewer.getGraph().getModel().endUpdate();\n        }\n    }\n\n}\n
\n

But it dont work. By the way i use Images as Backgrounds for my cells. I hope this isn't a Problem.

\n

Maybe you know a Solution.

asked 31 May '11, 02:16

ImproSnake's gravatar image

ImproSnake
30416
accept rate: 0%

Be the first one to answer this question!
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:

×194
×66
×6

Asked: 31 May '11, 02:16

Seen: 2,417 times

Last updated: 31 May '11, 02:16