P
pditty
Gast
hat jemand tipps und tricks zum thema JGraph??? außerdem hab ich Probleme ein JGraph in einen View zu implementieren, ich hoffe ihr könnt mir dabei weiterhelfen
public void createPartControl(Composite parent) {
final Composite c=new Composite(parent,SWT.NONE);
c.addPaintListener (new PaintListener () {
public void paintControl (PaintEvent event) {
HelloWorld hw=new HelloWorld(c);
}
});
public class HelloWorld {
public HelloWorld([b]Composite c[/b]) {
// Construct Model and Graph
GraphModel model = new DefaultGraphModel();
JGraph graph = new JGraph(model);
// Control-drag should clone selection
graph.setCloneable(true);
// Enable edit without final RETURN keystroke
graph.setInvokesStopCellEditing(true);
// When over a cell, jump to its default port (we only
// have one, anyway)
graph.setJumpToDefaultPort(true);
// Insert all three cells in one call, so we need an
// array to store them
DefaultGraphCell[] cells = new DefaultGraphCell[3];
// Create Hello Vertex
cells[0] = createVertex("Hello", 20, 20, 40, 20,
null, false);
// Create World Vertex
cells[1] = createVertex("World", 140, 140, 40, 20,
Color.ORANGE, true);
// Create Edge
DefaultEdge edge = new DefaultEdge();
// Fetch the ports from the new vertices,
// and connect them with the edge
edge.setSource(cells[0].getChildAt(0));
edge.setTarget(cells[1].getChildAt(0));
cells[2] = edge;
// Set Arrow Style for edge
int arrow = GraphConstants.ARROW_CLASSIC;
GraphConstants.setLineEnd(edge.getAttributes(), arrow);
GraphConstants.setEndFill(edge.getAttributes(), true);
// Insert the cells via the cache, so they get selected
graph.getGraphLayoutCache().insert(cells);
// Show in Frame
[b]JFrame frame = new JFrame();
frame.setContentPane(graph);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);[/b] }
public static DefaultGraphCell createVertex(String name, double x,
double y, double w, double h, Color bg, boolean raised) {
// Create vertex with the given name
DefaultGraphCell cell = new DefaultGraphCell(name);
// Set bounds
GraphConstants.setBounds(cell.getAttributes(),
new Rectangle2D.Double(x, y, w, h));
// Set fill color
if (bg != null) {
GraphConstants.setGradientColor(
cell.getAttributes(), Color.orange);
GraphConstants.setOpaque(
cell.getAttributes(), true);
}
// Set raised border
if (raised)
GraphConstants.setBorder(
cell.getAttributes(),
BorderFactory.createRaisedBevelBorder());
else
// Set black border
GraphConstants.setBorderColor(
cell.getAttributes(), Color.black);
// Add a Port
DefaultPort port = new DefaultPort();
cell.add(port);
port.setParent(cell);
return cell;
}
}
pditty hat gesagt.:hab grad gelesen dass es die möglichkeit gibt swing in swt einzubetten, vielleicht liegt auch darin das problem, hoffe mir kann irgendjemand helfen....
pditty hat gesagt.:klar wird Composite c nicht verwendet, weil ich ja bisher keine möglichkeit gefunden hab, c und graph zu verbinden...
habs beispielsweise mit
hab mir gef schon angeschaut, find jgraph aber irgendwie schöner, sieht besser aus und wirkt dynamischer... oder gibts in gef auch die möglichkeit verschiedene objekte mit der maus zu verschieben??? verbinden geht ja mittels PolylineConnection aber hab noch nichts gefunden was dem vom jgraph entspricht...
JGraph graph = new JGraph(c);
Titel | Forum | Antworten | Datum | |
---|---|---|---|---|
M | JGraph Kante ohne Objekte | AWT, Swing, JavaFX & SWT | 2 | |
J | JGraph Problem! | AWT, Swing, JavaFX & SWT | 2 | |
G | JGraph | AWT, Swing, JavaFX & SWT | 6 |