org.jgraph.JGraph Java Examples

The following examples show how to use org.jgraph.JGraph. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GraphRenderer.java    From chipster with MIT License 6 votes vote down vote up
/**
 * Overrides the parent implementation to return the value component stored
 * in the user object instead of this renderer if a value component exists.
 * This applies some of the values installed to this renderer to the value
 * component (border, opaque) if the latter is a JComponent.
 * 
 * @return Returns a configured renderer for the specified view.
 */
@Override
public Component getRendererComponent(JGraph graph, CellView view,
		boolean sel, boolean focus, boolean preview) {
	isSelected = sel;
	graphForeground = graph.getForeground();
	isGroup = view.getCell() instanceof GroupVertex;
	isPhenodata = view.getCell() instanceof PhenodataVertex;
	if(view.getCell() instanceof AbstractGraphVertex){
		if(isGroup){
			vertex = (GroupVertex)view.getCell();
		} else if(isPhenodata){
			vertex = (PhenodataVertex)view.getCell();
		} else {
			vertex = (GraphVertex)view.getCell();
		}
	}
	this.graph = graph;
	
	return super.getRendererComponent(graph, view, sel, focus, preview);
}
 
Example #2
Source File: GraphView.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
private JGraph setupGraph() {
    // 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);

    return graph;
}
 
Example #3
Source File: Main.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
private void adjustDisplaySettings(JGraph jg) {
    jg.setPreferredSize(DEFAULT_SIZE);

    Color c = DEFAULT_BG_COLOR;
    String colorStr = null;

    try {
        colorStr = getParameter("bgcolor");
    } catch (Exception e) {
    }

    if (colorStr != null) {
        c = Color.decode(colorStr);
    }

    jg.setBackground(c);
}
 
Example #4
Source File: TableCellView.java    From MogwaiERDesignerNG with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Component getRendererComponent(JGraph aGraph, CellView aView, boolean aSelected, boolean aHasFocus,
									  boolean aPreview) {

	TableCellView theView = (TableCellView) aView;
	table = (Table) ((TableCell) theView.getCell()).getUserObject();
	selected = aSelected;

	ERDesignerGraph theGraph = (ERDesignerGraph) aGraph;
	includeComments = theGraph.isDisplayComments();
	displayLevel = theGraph.getDisplayLevel();
	displayOrder = theGraph.getDisplayOrder();

	return this;
}
 
Example #5
Source File: Birdview.java    From microba with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Makes this component track the provided graph and scroller. Set
 * parameters to <code>null</code> to unbind thie component.
 * 
 * @param graph
 *            the graph component. May be <code>null</code>
 * @param scroller
 *            the croller, usually the one that holds the graph. May be
 *            <code>null</code>
 */
public void setTrackingFor(JGraph graph, JScrollPane scroller) {
	if (this.peerGraph != null) {
		this.peerGraph.getModel().removeGraphModelListener(scrollerListener);
		this.peerGraph.removePropertyChangeListener(graphPropertyChangeListener);
	}

	this.peerGraph = graph;

	if (this.peerGraph != null) {
		this.peerGraph.getModel().addGraphModelListener(scrollerListener);
		this.peerGraph.addPropertyChangeListener(graphPropertyChangeListener);

		this.displayGraph.setGraphLayoutCache(peerGraph.getGraphLayoutCache());

	} else {
		this.displayGraph.setGraphLayoutCache(new GraphLayoutCache());
	}

	//
	if (this.peerScroller != null) {
		this.peerScroller.getHorizontalScrollBar().removeAdjustmentListener(
				scrollerListener);
		this.peerScroller.getVerticalScrollBar().removeAdjustmentListener(
				scrollerListener);
	}

	this.peerScroller = scroller;

	if (this.peerScroller != null) {
		this.peerScroller.getHorizontalScrollBar().addAdjustmentListener(
				scrollerListener);
		this.peerScroller.getVerticalScrollBar().addAdjustmentListener(
				scrollerListener);
	}

	update();
	repaint();

}
 
Example #6
Source File: Birdview.java    From microba with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Constructor.
 * 
 * @param doc
 *            document to track. May be <code>null</code>
 */
public Birdview() {

	displayGraph = new JGraph();
	displayGraph.setEnabled(false);
	displayGraph.setAntiAliased(true);
	displayGraph.addMouseListener(selfMouseListener);
	displayGraph.addMouseMotionListener(selfMouseListener);

	this.setLayout(null);
	this.addComponentListener(new SelfResizeListener());
	this.add(displayGraph);

}
 
Example #7
Source File: Main.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void init() {
    // create a visualization using JGraph, via an adapter
    jgAdapter = new JGraphModelAdapter<>(g);

    JGraph jgraph = new JGraph(jgAdapter);

    adjustDisplaySettings(jgraph);
    getContentPane().add(jgraph);
    resize(DEFAULT_SIZE);
}
 
Example #8
Source File: CellEditorFactory.java    From MogwaiERDesignerNG with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Component getGraphCellEditorComponent(JGraph aGraph, Object aValue, boolean arg2) {

    BaseEditor theEditor = createEditDialogForValue(aGraph, aValue);
    theEditor.validate();

    return theEditor;
}
 
Example #9
Source File: CommentCellView.java    From MogwaiERDesignerNG with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Component getRendererComponent(JGraph aGraph, CellView aView, boolean aSelected, boolean aHasFocus,
                                      boolean aPreview) {

    CommentCellView theView = (CommentCellView) aView;
    Comment theComment = (Comment) ((CommentCell) theView.getCell()).getUserObject();
    textarea.setText(theComment.getComment());
    selected = aSelected;
    visible = true;

    return this;
}
 
Example #10
Source File: SubjectAreaCellView.java    From MogwaiERDesignerNG with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Component getRendererComponent(JGraph aGraph, CellView aView, boolean aSelected, boolean aHasFocus,
                                      boolean aPreview) {

    SubjectAreaCellView theView = (SubjectAreaCellView) aView;
    SubjectAreaCell theCell = (SubjectAreaCell) aView.getCell();
    subjectArea = (SubjectArea) ((SubjectAreaCell) theView.getCell()).getUserObject();
    selected = aSelected;
    expanded = theCell.isExpanded();

    return this;
}
 
Example #11
Source File: DefaultPortView.java    From MogwaiERDesignerNG with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean intersects(JGraph aGraph, Rectangle2D aRect) {
    GraphCell theCell = (GraphCell) getParentView().getCell();
    Rectangle2D theBounds = GraphConstants.getBounds(theCell.getAttributes());

    return theBounds.contains(aRect.getX(), aRect.getY());
}
 
Example #12
Source File: ViewCellView.java    From MogwaiERDesignerNG with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Component getRendererComponent(JGraph aGraph, CellView aView, boolean aSelected, boolean aHasFocus,
									  boolean aPreview) {

	ViewCellView theView = (ViewCellView) aView;
	view = (View) ((ViewCell) theView.getCell()).getUserObject();
	selected = aSelected;

	ERDesignerGraph theGraph = (ERDesignerGraph) aGraph;
	displayOrder = theGraph.getDisplayOrder();
	includeComments = theGraph.isDisplayComments();

	return this;
}
 
Example #13
Source File: UndoAction.java    From CQL with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 *
 *
 * @param graph
 */
private UndoAction(JGraph graph) {
	super("Undo");

	this.graph = graph;

	putValue(Action.MNEMONIC_KEY, KeyEvent.VK_U);
}
 
Example #14
Source File: ModelVertexRenderer.java    From CQL with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Returns the renderer component after initializing it
 * 
 * @param graph   The graph (really a M in disguise)
 * @param view    The cell view
 * @param sel     If the view is selected or not
 * @param focus   If the view has focus or not
 * @param preview If the graph is in preview mode or not
 * @return The renderer component fully initialized
 */
@Override
@SuppressWarnings("unchecked")
public Component getRendererComponent(JGraph graph, CellView view, boolean sel, boolean focus, boolean preview) {
	this.model = (M) graph;
	this.selected = sel;
	this.preview = preview;
	this.hasFocus = focus;

	ModelVertex<F, GM, M, N, E> v = (ModelVertex<F, GM, M, N, E>) view.getCell();

	// If the constraint is hidden, return a completely empty JPanel that
	// doesn't paint anything
	if ((v instanceof ModelConstraint) && !((ModelConstraint<F, GM, M, N, E>) v).isVisible()) {
		return new JPanel() {

			private static final long serialVersionUID = -8516030326162065848L;

			@Override
			public void paint(Graphics g) {
			}
		};
	}

	// if entity moved, set overview as dirty FIXME(if not working properly,
	// may be because of int casting and off by one)
	if ((int) (view.getBounds().getX()) != v.getX() || (int) (view.getBounds().getY()) != v.getY()) {
		model.setDirty();
	}

	// Initialize panel
	removeAll();
	setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

	// Add in entity/constraint label
	add(_entity = new JPanel(new GridLayout(1, 1)));
	_entity.add(_entityLabel = new JLabel(v.getName(), SwingConstants.CENTER));

	N myNode = (N) v;

	// Add in attributes
	_attributes = new JPanel(new GridLayout(0, 1));

	add(_attributes);

	for (EntityAttribute<F, GM, M, N, E> att : myNode.getEntityAttributes()) {
		_attributes.add(new JLabel(" @ " + att.getName()));
	}

	if ((_attributes.getComponentCount() == 0) || !model.getFrame().getShowAttsVal()) {
		_attributes.setVisible(false);
	}

	// Add in unique keys
	_uniqueKeys = new JPanel(new GridLayout(0, 1));

	add(_uniqueKeys);

	for (UniqueKey<F, GM, M, N, E> key : myNode.getUniqueKeys()) {
		_uniqueKeys.add(new JLabel(" $ " + key.getKeyName()));
	}

	if ((_uniqueKeys.getComponentCount() == 0) || !model.getFrame().getShowAttsVal()) {
		_uniqueKeys.setVisible(false);
	}

	@SuppressWarnings("rawtypes")
	Map attributes = view.getAllAttributes();

	installAttributes(v, attributes);

	// Set desired size
	setSize(getPreferredSize());

	return this;
}
 
Example #15
Source File: UndoAction.java    From CQL with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 *
 *
 * @param view
 */
public UndoAction(View view) {
	this((JGraph) view);

	putValue(Action.SHORT_DESCRIPTION, "Undo the last change made to the view");
}
 
Example #16
Source File: ERDesignerGraphUI.java    From MogwaiERDesignerNG with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean isEditing(JGraph aGraph) {
    return false;
}
 
Example #17
Source File: UndoAction.java    From CQL with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 *
 *
 * @param sketch
 */
public UndoAction(Sketch sketch) {
	this((JGraph) sketch);

	putValue(Action.SHORT_DESCRIPTION, "Undo the last change made to the sketch");
}
 
Example #18
Source File: LayoutTest.java    From JQF with BSD 2-Clause "Simplified" License 3 votes vote down vote up
@Fuzz
public void testWithGenerator(@GraphModel(nodes=10, edges=25) DirectedGraph graph) {
    JGraphModelAdapter adapter = new JGraphModelAdapter(graph);

    Assume.assumeFalse(new CycleDetector<>(graph).detectCycles());

    JGraph jgraph = new JGraph(adapter);


    JGraphLayout layout = new JGraphHierarchicalLayout();
    JGraphFacade facade = new JGraphFacade(jgraph);
    layout.run(facade);
}
 
Example #19
Source File: RedoAction.java    From CQL with GNU Affero General Public License v3.0 3 votes vote down vote up
/**
 *
 *
 * @param graph
 */
private RedoAction(JGraph graph) {
	super("Redo");

	putValue(Action.SHORT_DESCRIPTION, "Redo the last undone change");

	this.graph = graph;

	putValue(Action.MNEMONIC_KEY, KeyEvent.VK_R);
}
 
Example #20
Source File: RedoAction.java    From CQL with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 *
 *
 * @param view
 */
public RedoAction(View view) {
	this((JGraph) view);
}
 
Example #21
Source File: RedoAction.java    From CQL with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 *
 *
 * @param sketch
 */
public RedoAction(Sketch sketch) {
	this((JGraph) sketch);
}
 
Example #22
Source File: GraphUI.java    From CQL with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * Accessor for the JGraph
 * 
 * @return the JGraph
 */
public JGraph getGraph() {
	return graph;
}