org.jgraph.graph.DefaultGraphCell Java Examples
The following examples show how to use
org.jgraph.graph.DefaultGraphCell.
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: ERDesignerGraph.java From MogwaiERDesignerNG with GNU General Public License v3.0 | 6 votes |
/** * Create a new subject area for a set of cells. * * @param aCells the cells to add to the subject area */ public void commandAddToNewSubjectArea(List<DefaultGraphCell> aCells) { SubjectArea theArea = new SubjectArea(); theArea.setExpanded(true); SubjectAreaCell theSubjectAreaCell = new SubjectAreaCell(theArea); for (DefaultGraphCell theCell : aCells) { Object theUserObject = theCell.getUserObject(); if (theUserObject instanceof Table) { theArea.getTables().add((Table) theUserObject); } if (theUserObject instanceof View) { theArea.getViews().add((View) theUserObject); } } getGraphLayoutCache().insertGroup(theSubjectAreaCell, aCells.toArray()); model.addSubjectArea(theArea); getGraphLayoutCache().toBack(new Object[]{theSubjectAreaCell}); }
Example #2
Source File: GraphVisitor.java From Pydev with Eclipse Public License 1.0 | 6 votes |
public DefaultGraphCell createVertex(String name, double x, double y, Color bg, boolean raised) { // Create vertex with the given name DefaultGraphCell cell = new DefaultGraphCell(name); GraphConstants.setBorder(cell.getAttributes(), BorderFactory.createEtchedBorder()); GraphConstants.setBounds(cell.getAttributes(), new Rectangle2D.Double(x, y, 10, 10)); GraphConstants.setResize(cell.getAttributes(), true); GraphConstants.setAutoSize(cell.getAttributes(), true); // Set fill color if (bg != null) { GraphConstants.setOpaque(cell.getAttributes(), true); GraphConstants.setGradientColor(cell.getAttributes(), bg); } // Set raised border if (raised) GraphConstants.setBorder(cell.getAttributes(), BorderFactory.createRaisedBevelBorder()); else // Set black border GraphConstants.setBorderColor(cell.getAttributes(), Color.black); return cell; }
Example #3
Source File: GraphVisitor.java From Pydev with Eclipse Public License 1.0 | 6 votes |
@Override protected Object unhandled_node(SimpleNode node) throws Exception { DefaultGraphCell cell = null; String caption = node.toString(); parentAddPort(); cell = createVertex(caption, indent, depth, nodeColor, false); DefaultEdge edge = createConnection(cell); cells.add(cell); cells.add(edge); incrementPosition(cell); return null; }
Example #4
Source File: ERDesignerGraph.java From MogwaiERDesignerNG with GNU General Public License v3.0 | 5 votes |
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 #5
Source File: Main.java From SIMVA-SoS with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private static void positionVertexAt(Object vertex, int x, int y) { DefaultGraphCell cell = jgAdapter.getVertexCell(vertex); AttributeMap attr = cell.getAttributes(); AttributeMap map = new AttributeMap(); GraphConstants.setBounds(map, new Rectangle2D.Double(50, 50, 90, 30)); GraphConstants.setBorder(map, BorderFactory.createRaisedBevelBorder()); GraphConstants.setBackground(map, Color.BLUE); GraphConstants.setForeground(map, Color.white); GraphConstants.setFont(map, GraphConstants.DEFAULTFONT.deriveFont(Font.BOLD, 12)); GraphConstants.setOpaque(map, true); Rectangle2D bounds = GraphConstants.getBounds(map); Rectangle2D newBounds = new Rectangle2D.Double(x, y, bounds.getWidth(), bounds.getHeight()); GraphConstants.setBounds(map, newBounds); GraphConstants.setBounds(attr, newBounds); AttributeMap cellAttr = new AttributeMap(); if (findGoalByName((String) vertex).isSliced) cellAttr.put(cell, map); else cellAttr.put(cell, attr); jgAdapter.edit(cellAttr, null, null, null); }
Example #6
Source File: GraphView.java From Pydev with Eclipse Public License 1.0 | 5 votes |
private void loadGraph(String fileName) throws FileNotFoundException, IOException, Throwable { ASTGraph ast = new ASTGraph(); ParseOutput objects = ast.parseFile(fileName); graph.setGraphLayoutCache(new GraphLayoutCache()); DefaultGraphCell[] cells = ast.generateTree((SimpleNode) objects.ast); graph.getGraphLayoutCache().insert(cells); graph.clearSelection(); }
Example #7
Source File: ASTGraph.java From Pydev with Eclipse Public License 1.0 | 5 votes |
public DefaultGraphCell[] generateTree(SimpleNode node) throws IOException, Exception { GraphVisitor visitor = new GraphVisitor(); node.accept(visitor); DefaultGraphCell[] cells = visitor.getCells(); return cells; }
Example #8
Source File: GraphVisitor.java From Pydev with Eclipse Public License 1.0 | 5 votes |
public GraphVisitor() throws IOException { cells = new ArrayList<DefaultGraphCell>(); stack = new FastStack<DefaultGraphCell>(50); depth = 0; indent = 0; nodeColor = Color.GRAY; }
Example #9
Source File: GraphVisitor.java From Pydev with Eclipse Public License 1.0 | 5 votes |
private DefaultEdge createConnection(DefaultGraphCell cell) { DefaultEdge edge = new DefaultEdge(); edge.setSource(stack.peek().getChildAt(0)); edge.setTarget(cell); // Set Arrow Style for edge int arrow = GraphConstants.ARROW_TECHNICAL; GraphConstants.setLineEnd(edge.getAttributes(), arrow); GraphConstants.setEndFill(edge.getAttributes(), true); return edge; }
Example #10
Source File: GraphVisitor.java From Pydev with Eclipse Public License 1.0 | 5 votes |
/** * Entry point */ @Override public Object visitModule(Module node) throws Exception { // String caption = node.toString(); DefaultGraphCell moduleCell = createVertex("Module", indent, depth, nodeColor, false); cells.add(moduleCell); incrementPosition(moduleCell); traverse(node); return null; }
Example #11
Source File: ERDesignerGraphUI.java From MogwaiERDesignerNG with GNU General Public License v3.0 | 4 votes |
@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 #12
Source File: ERDesignerGraphUI.java From MogwaiERDesignerNG with GNU General Public License v3.0 | 4 votes |
@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; }
Example #13
Source File: GraphVisitor.java From Pydev with Eclipse Public License 1.0 | 4 votes |
public DefaultGraphCell[] getCells() { return cells.toArray(new DefaultGraphCell[0]); }
Example #14
Source File: GraphVisitor.java From Pydev with Eclipse Public License 1.0 | 4 votes |
private void incrementPosition(DefaultGraphCell cell) { stack.push(cell); indent += INDENT_STEP; depth += DEPTH_STEP; }
Example #15
Source File: ERDesignerGraphUI.java From MogwaiERDesignerNG with GNU General Public License v3.0 | 3 votes |
private DefaultPopupMenu createPopupMenu(List<DefaultGraphCell> aCells) { DefaultPopupMenu theMenu = new DefaultPopupMenu(ResourceHelper .getResourceHelper(ERDesignerBundle.BUNDLE_NAME)); List<ModelItem> theItems = aCells.stream().map(theCell -> (ModelItem) theCell.getUserObject()).collect(Collectors.toList()); ContextMenuFactory.addActionsToMenu(erdesigner, theMenu, theItems); UIInitializer.getInstance().initialize(theMenu); return theMenu; }