Java源码示例:org.jgraph.JGraph

示例1
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);
}
 
示例2
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;
}
 
示例3
/**
 * 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);
}
 
示例4
/**
 *
 *
 * @param graph
 */
private UndoAction(JGraph graph) {
	super("Undo");

	this.graph = graph;

	putValue(Action.MNEMONIC_KEY, KeyEvent.VK_U);
}
 
示例5
@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;
}
 
示例6
@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());
}
 
示例7
@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;
}
 
示例8
@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;
}
 
示例9
@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;
}
 
示例10
@Override
public Component getGraphCellEditorComponent(JGraph aGraph, Object aValue, boolean arg2) {

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

    return theEditor;
}
 
示例11
/**
 * {@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);
}
 
示例12
/**
 * 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);

}
 
示例13
/**
 * 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();

}
 
示例14
/**
 * 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;
}
 
示例15
/**
 *
 *
 * @param sketch
 */
public UndoAction(Sketch sketch) {
	this((JGraph) sketch);

	putValue(Action.SHORT_DESCRIPTION, "Undo the last change made to the sketch");
}
 
示例16
/**
 *
 *
 * @param view
 */
public UndoAction(View view) {
	this((JGraph) view);

	putValue(Action.SHORT_DESCRIPTION, "Undo the last change made to the view");
}
 
示例17
@Override
public boolean isEditing(JGraph aGraph) {
    return false;
}
 
示例18
/**
 *
 *
 * @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);
}
 
示例19
@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);
}
 
示例20
/**
 * Accessor for the JGraph
 * 
 * @return the JGraph
 */
public JGraph getGraph() {
	return graph;
}
 
示例21
/**
 *
 *
 * @param sketch
 */
public RedoAction(Sketch sketch) {
	this((JGraph) sketch);
}
 
示例22
/**
 *
 *
 * @param view
 */
public RedoAction(View view) {
	this((JGraph) view);
}