org.jgraph.graph.CellView Java Examples

The following examples show how to use org.jgraph.graph.CellView. 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: 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 #3
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 #4
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 #5
Source File: ERDesignerGraph.java    From MogwaiERDesignerNG with GNU General Public License v3.0 5 votes vote down vote up
private void toggleVisibilityOfRelationsInSubjectArea(SubjectAreaCell aCell, boolean aVisibilityState) {

        Set<Relation> theRelationDoWork = new HashSet<>();

        SubjectArea theSA = (SubjectArea) aCell.getUserObject();
        for (Table theTable : theSA.getTables()) {
            theRelationDoWork.addAll(model.getRelations().getForeignKeysFor(theTable).stream().filter(theRelation -> theSA.getTables().contains(theRelation.getExportingTable())).collect(Collectors.toList()));
        }

        Set<DefaultGraphCell> theCellsToWork = new HashSet<>();

        for (CellView theView : getGraphLayoutCache().getAllViews()) {
            if (theView instanceof RelationEdgeView) {
                RelationEdgeView theEdgeView = (RelationEdgeView) theView;
                DefaultGraphCell theCell = (DefaultGraphCell) theEdgeView.getCell();
                if (theRelationDoWork.contains(theCell.getUserObject())) {
                    theCellsToWork.add(theCell);
                }
            }
        }

        if (theCellsToWork.size() > 0) {
            if (aVisibilityState) {
                getGraphLayoutCache().showCells(theCellsToWork.toArray(new DefaultGraphCell[theCellsToWork.size()]), true);
            } else {
                getGraphLayoutCache().hideCells(theCellsToWork.toArray(new DefaultGraphCell[theCellsToWork.size()]), true);
            }
        }
    }
 
Example #6
Source File: MicroarrayGraph.java    From chipster with MIT License 5 votes vote down vote up
/**
 * Gets all visible vertexes on the graph.
 */
public List<AbstractGraphVertex> getVisibleVertexes() {
	CellView[] views = this.getGraphLayoutCache().getCellViews();
	List<AbstractGraphVertex> vertexes = new ArrayList<AbstractGraphVertex>();
	for (CellView view : views) {
		if (view != null && view.getCell() instanceof AbstractGraphVertex) {
			AbstractGraphVertex vertex = (AbstractGraphVertex) view.getCell();
			vertexes.add(vertex);
		}
	}
	return vertexes;
}
 
Example #7
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 #8
Source File: EdgeRouter.java    From CQL with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Calculates intermediate points for multiple loops. This is the same algorithm
 * used by DefaultEdge.LoopRouting, but we scale the loop box for parallel
 * self-referencing edges.
 *
 * @param cache
 * @param edge
 *
 * @return
 */
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public List routeLoop(final GraphLayoutCache cache, final EdgeView edge) {
	final CellView sourceNode = edge.getSource();
	final List newPoints = new ArrayList();

	newPoints.add(sourceNode);

	final CellView sourceParent = (sourceNode != null) ? sourceNode.getParentView() : edge.getSourceParentView();
	if (sourceNode == null) {
		throw new RuntimeException("Internal EASIK error, please report");
	}
	final Object[] edges = DefaultGraphModel.getEdgesBetween(cache.getModel(), sourceNode.getCell(),
			sourceNode.getCell(), true);
	int position = 0;

	if (edges != null) {
		for (int i = 0; i < edges.length; i++) {
			if (edges[i] == edge.getCell()) {
				position = i;

				break;
			}
		}
	}

	if (sourceParent != null) {
		final Point2D from = AbstractCellView.getCenterPoint(sourceParent);
		final Rectangle2D rect = sourceParent.getBounds();
		final double posWidthFactor = 1.25 + 0.75 * position;
		final double posHeightFactor = 1.5 + position;
		final double width = rect.getWidth();
		final double height2 = rect.getHeight() / 2;
		double loopWidth = Math.min(20, Math.max(10, width / 8));
		double loopHeight = Math.min(30, Math.max(12, Math.max(loopWidth + 4, height2 / 2)));

		loopWidth *= posWidthFactor;
		loopHeight *= posHeightFactor;

		newPoints.add(edge.getAttributes().createPoint(from.getX() - loopWidth,
				from.getY() - height2 - loopHeight * 1.0));

		final double midpointY = from.getY() - height2 - 1.5 * loopHeight;

		newPoints.add(edge.getAttributes().createPoint(from.getX(), midpointY));
		newPoints.add(edge.getAttributes().createPoint(from.getX() + loopWidth,
				from.getY() - height2 - loopHeight * 1.0));
		newPoints.add(edge.getTarget());

		return newPoints;
	}

	return null;
}
 
Example #9
Source File: ERDesignerGraphLayout.java    From MogwaiERDesignerNG with GNU General Public License v3.0 4 votes vote down vote up
@Override
public List<Spring<CellView, VertexCellElement>> getSprings() {
    return springs;
}
 
Example #10
Source File: VertexCellElement.java    From MogwaiERDesignerNG with GNU General Public License v3.0 4 votes vote down vote up
public VertexCellElement(CellView aView) {
    view = aView;
}
 
Example #11
Source File: ERDesignerGraphUI.java    From MogwaiERDesignerNG with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void mousePressed(MouseEvent e) {
    handler = null;
    if (!e.isConsumed() && graph.isEnabled()) {
        graph.requestFocus();
        int s = graph.getTolerance();
        Rectangle2D theRectangle = graph.fromScreen(new Rectangle2D.Double(e.getX() - s, e.getY() - s, 2 * s,
                2 * s));
        lastFocus = focus;
        focus = (focus != null && focus.intersects(graph, theRectangle)) ? focus : null;
        cell = graph.getNextSelectableViewAt(focus, e.getX(), e.getY());
        if ((cell != null) && (cell.getChildViews() != null) && (cell.getChildViews().length > 0)) {
            CellView theTemp = graph.getNextViewAt(cell.getChildViews(), focus, e.getX(), e.getY());
            if (theTemp != null) {
                cell = theTemp;
            }
        }
        // if (focus == null) {
        focus = cell;
        // }
        completeEditing();
        boolean isForceMarquee = isForceMarqueeEvent(e);
        boolean isEditable = graph.isGroupsEditable() || (focus != null && focus.isLeaf());
        if (!isForceMarquee) {
            if (e.getClickCount() == graph.getEditClickCount() && focus != null && isEditable
                    && graph.isCellEditable(focus.getCell()) && handleEditTrigger(cell.getCell(), e)) {
                e.consume();
                cell = null;
            } else if (!isToggleSelectionEvent(e)) {
                if (handle != null) {
                    handle.mousePressed(e);
                    handler = handle;
                }
                // Immediate Selection
                if (!e.isConsumed() && cell != null && !graph.isCellSelected(cell.getCell())) {
                    selectCellForEvent(cell.getCell(), e);
                    focus = cell;
                    if (handle != null) {
                        handle.mousePressed(e);
                        handler = handle;
                    }
                    e.consume();
                    cell = null;
                }
            }
        }
        // Marquee Selection
        if (!e.isConsumed() && marquee != null
                && (!isToggleSelectionEvent(e) || focus == null || isForceMarquee)) {
            marquee.mousePressed(e);
            handler = marquee;
        }
    }
}
 
Example #12
Source File: ERDesignerGraphUI.java    From MogwaiERDesignerNG with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void mouseClicked(MouseEvent e) {

    int s = graph.getTolerance();

    Rectangle2D theRectangle = graph.fromScreen(new Rectangle2D.Double(e.getX() - s, e.getY() - s, 2 * s,
            2 * s));
    lastFocus = focus;
    focus = (focus != null && focus.intersects(graph, theRectangle)) ? focus : null;
    cell = graph.getNextSelectableViewAt(focus, e.getX(), e.getY());
    if ((cell != null) && (cell.getChildViews() != null) && (cell.getChildViews().length > 0)) {
        CellView theTemp = graph.getNextViewAt(cell.getChildViews(), focus, e.getX(), e.getY());
        if (theTemp != null) {
            cell = theTemp;
        }
    }
    if (focus == null) {
        focus = cell;
    }

    // Check for single click on a cell
    if (e.getClickCount() == 1 && !SwingUtilities.isRightMouseButton(e)) {
        // Check if the user clicked a subject area
        if (cell instanceof SubjectAreaCellView) {
            SubjectAreaCellView theView = (SubjectAreaCellView) cell;
            SubjectAreaCell theCell = (SubjectAreaCell) theView.getCell();

            Rectangle2D theBounds = theView.getBounds();
            Point2D theClickPoint = graph.fromScreen(e.getPoint());

            // Check if user clicked on top left corner
            if ((theClickPoint.getX() > theBounds.getX() + 5 && theClickPoint.getX() < theBounds.getX() + 20)
                    && (theClickPoint.getY() > theBounds.getY() + 5 && theClickPoint.getY() < theBounds.getY() + 20)) {

                ERDesignerGraph theGraph = (ERDesignerGraph) graph;

                // Yes, so toggle collapsed / expanded state
                if (!theCell.isExpanded()) {
                    theGraph.setSubjectAreaCellExpanded(theCell);
                } else {
                    theGraph.setSubjectAreaCellCollapsed(theCell);
                }
            }
        }
    }

    if (e.getClickCount() == graph.getEditClickCount() && !SwingUtilities.isRightMouseButton(e)) {

        if (cell != null) {
            if (handleEditTrigger(cell.getCell(), e)) {
                e.consume();
            }
        }
    }

    if (cell != null) {
        graph.scrollCellToVisible(cell.getCell());

        if (SwingUtilities.isRightMouseButton(e)) {
            List<DefaultGraphCell> theSelectionList = new ArrayList<>();
            for (Object theSelection : graph.getSelectionCells()) {
                if (theSelection instanceof DefaultGraphCell) {
                    theSelectionList.add((DefaultGraphCell) theSelection);
                }
            }

            DefaultPopupMenu theMenu = createPopupMenu(theSelectionList);
            theMenu.show(graph, e.getX(), e.getY());
        }
        e.consume();
    } else {
        if (marquee instanceof BaseTool) {
            BaseTool theTool = (BaseTool) marquee;
            if (theTool.startCreateNew(e)) {
                e.consume();
            }
        }
    }
}
 
Example #13
Source File: ERDesignerGraphUI.java    From MogwaiERDesignerNG with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected boolean startEditing(Object cell, MouseEvent event) {
    completeEditing();

    if (graph.isCellEditable(cell)) {
        CellView tmp = graphLayoutCache.getMapping(cell, false);
        cellEditor = tmp.getEditor();
        editingComponent = cellEditor.getGraphCellEditorComponent(graph, cell, graph.isCellSelected(cell));
        if (cellEditor.isCellEditable(event)) {

            editingCell = cell;
            editingComponent.validate();

            if (cellEditor.shouldSelectCell(event) && graph.isSelectionEnabled()) {
                stopEditingInCompleteEditing = false;
                try {
                    graph.setSelectionCell(cell);
                } catch (Exception e) {
                    LOGGER.error("Error setting selection cell", e);
                }
                stopEditingInCompleteEditing = true;
            }

            /*
                 * Find the component that will get forwarded all the mouse
                 * events until mouseReleased.
                 */
            Point componentPoint = SwingUtilities.convertPoint(graph, new Point(event.getX(), event.getY()),
                    editingComponent);

            /*
                 * Create an instance of BasicTreeMouseListener to handle
                 * passing the mouse/motion events to the necessary component.
                 */
            // We really want similar behavior to getMouseEventTarget,
            // but it is package private.
            Component activeComponent = SwingUtilities.getDeepestComponentAt(editingComponent, componentPoint.x,
                    componentPoint.y);
            if (activeComponent != null) {
                new MouseInputHandler(graph, activeComponent, event);
            }

            BaseEditor theDialog = (BaseEditor) editingComponent;
            event.consume();
            if (theDialog.showModal() == DialogConstants.MODAL_RESULT_OK) {
                try {
                    theDialog.applyValues();

                    erdesigner.commandNotifyAboutEdit();

                    OutlineComponent.getDefault().refresh(ERDesignerComponent.getDefault().getModel());
                } catch (Exception e1) {
                    ERDesignerComponent.getDefault().getWorldConnector().notifyAboutException(e1);
                }
            }

            editingComponent = null;

            // Mark the cell as edited, so it is resized during
            // redisplay to its new preferred size
            DefaultGraphCell theCell = (DefaultGraphCell) editingCell;
            graph.getGraphLayoutCache().editCell(theCell, theCell.getAttributes());

            graph.invalidate();
            graph.repaint();
        } else {
            editingComponent = null;
        }
    }
    return false;
}