Hi all, this could be a silly question but I am quite confused.

\n

I have to represent complex vertices instead of only a rectangle with a label (as per default). Let's say these vertices have to contain a list of text (e.g. JTextField) or in general a Canvas representing content (taken from a model) that can be modified.

\n

I looked into the examples, but I am not quite sure how should I takle this problem. \nShould I do something like SchemaEditor.java thus creating a custom render?

\n

I noticed this doesn't use the object, i.e. when adding vertices with graph.insertVertex(parent, id, object, x, y, h, w).. the object in this example is just an editable label that is not even shown (double clicking on the custom render of the vertex I can even edit this hidden label).. so what is this object about?

\n

This brings me to the second example: UserObject.java, here they create a custom object and pass it to the vertex.. but this object is a DOM element, why? Could it be something else? Could it be represented with another render instead of a simple label?

\n

How can I create a custom object in my model, pass it to the vertex and show a custom render which takes this object as source?

\n

I am not asking for a complete solution, just some clarifications to show me the right path :)

\n

Thanks,

\n

-s

asked 15 Mar '12, 09:57

fusio's gravatar image

fusio
91211
accept rate: 11%


The most straightforward way (I think) is to

\n
    \n
  1. Extend mxBasicShape (look to the other mxXXXShape classes for inspiration)
  2. \n
  3. Register the shape with mxGraph2DCanvas mxGraphics2DCanvas.putShape("myShape", new MyShape() ); in the initializer for your app.
  4. \n
  5. When creating vertices, add "shape=myShape;" to the style String argument.
  6. \n
\n

The user object can be anything, think DefaultMutableTreeNode. You can hide the labels I think, mxGraph.setLabelsVisible() or something.

\n

Good luck

link

answered 16 Mar '12, 01:39

Earthumb's gravatar image

Earthumb
2616
accept rate: 16%

edited 16 Mar '12, 01:43

Ok, so I am looking into mxRectangleShape: it seems I can get the object doing ((mxCell) state.getCell()).getValue() but where does it actually use it?

\n

I mean, where do they add/get the label? (shape only defines the container, right?)

(16 Mar '12, 02:46) fusio

check mxGraph.getLabel() and mxGraph.convertValueToString()

(16 Mar '12, 06:28) Earthumb

label is being painted by another shape (mxTextShape or similiar). Check mxGraph2DCanvas.drawLabel()

(16 Mar '12, 06:30) Earthumb

I see, thanks.
\n

\n

I ended up not needing it, I am using overlays to add swing components (labels), after having created a new shape as background :) a bit cumbersome to manage zoom but it seems to be working.

(16 Mar '12, 07:37) fusio
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:

×194
×79
×17
×16

Asked: 15 Mar '12, 09:57

Seen: 2,799 times

Last updated: 16 Mar '12, 07:37