JGraph e EllipseCells

0 respostas
A

Olá estou fazendo meu estágio de conclusão de curso e preciso de ajuda, pois nao consigo criar EllipseCell com JGraph ja procurei em diversos sites até encontrei tutoriais falando sobre como implementar uma EllipseCell porém muito incompleto aqui está a citação da parte sobre EllipseCell

Adding new Cell Types to a Graph

The following code was taken from JGraphpad (<a href="http://start.jgraph.com">http://start.jgraph.com</a>) to

illustrate how to add new cell types and renderers. The code adds an oval

vertex to the graph. The easiest way to do this is by extending JGraph. Since

JGraph implements the CellViewFactory interface, it is in charge of

creating views.

When creating a view, JGraph assumes a cell is a vertex if it is not an

instance of Edge or Port, and calls the createVertexView method. Thus,

we only need to override this method to identify an oval vertex (based on a

typetest) and return the corresponding view.

// Overrides JGraph.createVertexView

protected VertexView createVertexView(Object v,

GraphModel model,

CellMapper cm) {

// Return an EllipseView for EllipseCells

if (v instanceof EllipseCell)

return new EllipseView(v, model, cm);

// Else Call Superclass

return super.createVertexView(v, model, cm);

}

The oval vertex is represented by the EllipseCell class, which is an

extension of the DefaultGraphCell class, and offers no additional

methods. It is only used to distinguish oval vertices from normal vertices.

// Define EllipseCell

public class EllipseCell extends DefaultGraphCell {

// Empty Constructor

public EllipseCell() {

this(null);

}

// Construct Cell for Userobject

public EllipseCell(Object userObject) {

super(userObject);

7

The JGraph Tutorial

}

}

The EllipseView is needed to define the special visual aspects of an

ellipse. It contains an inner class which serves as a renderer that provides the

painting code. The view and renderer are extensions of the VertexView and

VertexRenderer classes, respectively. The methods that need to be

overridden are getPerimeterPoint to return the perimeter point for

ellipses, getRenderer to return the correct renderer, and the renderer?s

paint method.

// Define the View for an EllipseCell

public class EllipseView extends VertexView {

static EllipseRenderer renderer = new EllipseRenderer();

// Constructor for Superclass

public EllipseView(Object cell, GraphModel model,

CellMapper cm) { super(cell, model, cm); }

// Returns Perimeter Point for Ellipses

public Point getPerimeterPoint(Point source, Point p) {  }

// Returns the Renderer for this View

protected CellViewRenderer getRenderer() {

return renderer;

}

// Define the Renderer for an EllipseView

static class EllipseRenderer extends VertexRenderer {

public void paint(Graphics g) {  }

}

}

The reason for overriding getRenderer instead of

getRendererComponent is that the AbstractCellView class, from which

we inherit, already provides a default implementation of this method that

returns a configured CellViewRenderer, which in turn is retrieved through

the method that was overridden.

por favor alguem poderia me ajudar ???

sites para referencia

www.jgraph.com
biblioteca jgraph

Muito obrigado a todos

Criado 18 de junho de 2008
Respostas 0
Participantes 1