protected DefaultGraphCell createEntityCell(Entity entity) { DefaultGraphCell cell = new DefaultGraphCell(getCellMetadata(entity)); GraphConstants.setResize(cell.getAttributes(), true); GraphConstants.setBorder(cell.getAttributes(), new LineBorder(Color.BLACK)); GraphConstants.setEditable(cell.getAttributes(), false); entityCells.put(entity.getName(), cell); cell.addPort(); return cell; }
DefaultGraphCell gm = new DefaultGraphCell("GraphModel"); attributes.put(gm, createBounds(new AttributeMap(), 20, 100, Color.blue)); gm.addPort(null, "GraphModel/Center"); DefaultGraphCell dgm = new DefaultGraphCell("DefaultGraphModel"); attributes.put(dgm, createBounds(new AttributeMap(), 20, 180, Color.blue)); dgm.addPort(null, "DefaultGraphModel/Center"); DefaultEdge dgmImplementsGm = new DefaultEdge("implements"); cs.connect(dgmImplementsGm, gm.getChildAt(0), dgm.getChildAt(0)); attributes.put(dgmImplementsGm, implementStyle); DefaultGraphCell modelGroup = new DefaultGraphCell("ModelGroup"); modelGroup.add(gm); modelGroup.add(dgm); modelGroup.add(dgmImplementsGm); DefaultGraphCell jc = new DefaultGraphCell("JComponent"); attributes.put(jc, createBounds(new AttributeMap(), 180, 20, Color.green)); jc.addPort(null, "JComponent/Center"); DefaultGraphCell jg = new DefaultGraphCell("JGraph"); attributes.put(jg, createBounds(new AttributeMap(), 180, 100, Color.green)); jg.addPort(null, "JGraph/Center"); DefaultEdge jgExtendsJc = new DefaultEdge("extends"); cs.connect(jgExtendsJc, jc.getChildAt(0), jg.getChildAt(0)); attributes.put(jgExtendsJc, extendStyle); DefaultGraphCell cu = new DefaultGraphCell("ComponentUI");
/** * Creates a graph cell and initializes it with the specified user object. * The GraphCell allows children only if specified. * * @param userObject an Object provided by the user that constitutes * the cell's data * @param storageMap the storage attribute map for this cell * @param children array of children */ public DefaultGraphCell(Object userObject, AttributeMap storageMap, MutableTreeNode[] children) { super(userObject, true); setAttributes(storageMap); if (children != null) for (int i = 0; i < children.length; i++) add(children[i]); }
/** * Creates a shallow copy of the cell including a copy of the user object. * Subclassers can override the cloneUserObject to provide a custom user * object cloning mechanism. */ protected Object cloneCell(Object cellObj) { if (cellObj instanceof DefaultGraphCell) { // Clones the cell DefaultGraphCell cell = (DefaultGraphCell) cellObj; DefaultGraphCell clone = (DefaultGraphCell) cell.clone(); // Clones the user object clone.setUserObject(cloneUserObject(cell.getUserObject())); return clone; } return cellObj; }
/** * Fetch the data in a text/plain format. */ public String getPlainData() { if (cells[0] instanceof DefaultGraphCell) { Object obj = ((DefaultGraphCell) cells[0]).getUserObject(); if (obj != null) return obj.toString(); } return cells[0].toString(); }
Object userobject=dgc.getUserObject(); CellView currentview=this.ids.editor.getGraph().getGraphLayoutCache().getMapping(dgc,false); Map attributes=dgc.getAttributes(); Rectangle2D loc=GraphConstants.getBounds(attributes); double dirx=0; DefaultGraphCell otherdgc = (DefaultGraphCell) gm.getRootAt(i); if (otherdgc!=dgc){ Map otheratts=otherdgc.getAttributes(); Rectangle2D otherloc=GraphConstants.getBounds(otheratts); if (otherloc!=null){ for (int j=0;j<otherdgc.getChildCount();j++){ if (gm.isPort(otherdgc.getChildAt(j))){ Iterator edges = gm.edges(otherdgc.getChildAt(j)); while (edges.hasNext()){ DefaultEdge de=(DefaultEdge)edges.next(); Map sourceat=source.getAttributes(); Map targetat=target.getAttributes(); Rectangle2D locporto = GraphConstants.getBounds(sourceat); Rectangle2D locportt=GraphConstants.getBounds(targetat); double module=Math.sqrt(p.x*p.x+p.y*p.y); if (module!=0){ Map m=dgc.getAttributes(); Rectangle2D loc=GraphConstants.getBounds(m); if (loc!=null){
DefaultGraphCell mapCell = new DefaultGraphCell(); createdObjects.add(mapCell); array.add((DefaultGraphCell) cell.getChildAt(0)); // port GraphConstants.setBounds(isolatedObjects.get(isolatedIndex).getAttributes(), new Rectangle2D.Double(pref.width - posX, pref.height - 3 * posY / 2, 10, 10)); isolatedIndex += 2; // because every 2nd object is port
/** * Changes the <code>attributes</code> of the cell. * * @deprecated Use getAttributes().applyMap */ public Map changeAttributes(Map change) { return getAttributes().applyMap(change); }
private void createArrow(K source, K target) { if (!arrowAlreadyExist(source, target)) { DefaultGraphCell[] arrowCell = new DefaultGraphCell[1]; DefaultEdge edge = new DefaultEdge(); edge.setSource(stateCells.get(source).getChildAt(0)); edge.setTarget(stateCells.get(target).getChildAt(0)); arrowCell[0] = edge; int arrow = GraphConstants.ARROW_TECHNICAL; GraphConstants.setLineEnd(edge.getAttributes(), arrow); GraphConstants.setEndFill(edge.getAttributes(), true); graph.getGraphLayoutCache().insert(arrowCell); Set<K> targetSet = arrows.get(source); if (targetSet == null) { targetSet = EnumSet.noneOf(keyType); arrows.put(source, targetSet); } targetSet.add(target); } }
public void restoreContraints(DefaultGraphCell cell) { Entity ent=(Entity)cell.getUserObject(); Hashtable<DefaultGraphCell, Dimension> cellDimension = entityConstraints .get(this.hashCode()+":"+cell.hashCode() + ":" + ent.getPrefs(jg.getModel().getAttributes(cell)).getView()); Hashtable<Object, Map> changes = new Hashtable<Object, Map>(); if (cellDimension != null) { for (DefaultGraphCell dgc : cellDimension.keySet()) { if (dgc.getAttributes() != null) { // still exists Map oldmap = dgc.getAttributes(); Rectangle oldbounds = GraphConstants.getBounds(oldmap) .getBounds(); oldbounds.setSize(cellDimension.get(dgc)); GraphConstants.setBounds(oldmap, oldbounds); changes.put(dgc, oldmap); } } jg.getModel().edit(changes, null, null, null); jg.invalidate(); jg.repaint(); } }
&& !(objs[k] instanceof NAryEdge) && !(objs[k] instanceof DefaultEdge)) { if (((DefaultGraphCell)objs[k]).getChildCount()>0){ Iterator edges = graph.getModel().edges(((DefaultGraphCell)objs[k]).getChildAt(0));
private void updateStateMachine() { if (oldStateDiagram) { this.repaint(); } else { K currentStateKey = stateMachine.getCurrentStateKey(); DefaultGraphCell currentStateCell = stateCells.get(currentStateKey); GraphConstants.setBackground(graph.getAttributes(currentStateCell), Color.RED); currentStateCell.setAttributes(graph.getAttributes(currentStateCell)); for (Entry<K, DefaultGraphCell> entry : stateCells.entrySet()) { if (entry.getKey() != currentStateKey) { DefaultGraphCell stateCell = entry.getValue(); GraphConstants.setBackground(graph.getAttributes(stateCell), Color.CYAN); stateCell.setAttributes(graph.getAttributes(stateCell)); } } graph.repaint(); graph.refresh(); } }
String text = ( (DefaultGraphCell) (this.getCell())).getUserObject(). toString(); if (text.equals("null") || text.length() == 0 ) { Class objectClass = ( (DefaultGraphCell) (this.getCell())).getUserObject(). getClass(); text = "<<" + rec.setSize(new Dimension(length, height + 5)); GraphConstants.setBounds(m, rec); ((DefaultGraphCell)this.getCell()).setAttributes(m);
/** * Utility method to create a port for this cell. The method adds a port * at a fixed relative offset within the cell. If the offset is null * then a floating port is added. * @param offset the offset of the port within the cell * @return the port created */ public Object addPort(Point2D offset) { return addPort(offset, null); }
private boolean evaluateIfDefaultGraphCellHasToBeHighlighted( DefaultGraphCell dgc, boolean found, DefaultGraphCell toPaint) { if (dgc.getChildCount() > 0) { for (Object objectport : dgc.getChildren()) { if (objectport instanceof DefaultPort) { DefaultPort port = (DefaultPort) objectport; Iterator<DefaultEdge> edges = graph.getModel().edges(port); while (edges.hasNext() && !found) { DefaultEdge next = edges.next(); found = found || ((DefaultPort) (next.getTarget())) .getParent().equals(toPaint) || ((DefaultPort) (next.getSource())) .getParent().equals(toPaint); } } } } return found; }
public Vector<Hashtable<String,String>> getPossibleRoleAssignment(String relationshipType, String[] connectedEntities) throws NotFound{ Vector<GraphCell> entities=new Vector<GraphCell>(); for (String entityID:connectedEntities) { DefaultGraphCell entity = findEntity(entityID); if (entity==null){ // the entity may have not been created yet as graphical object // The object manager may know about it. if (this.ids.om.findUserObject(entityID).size()>0) entity=new DefaultGraphCell(this.ids.om.findUserObject(entityID).firstElement()); else throw new ingenias.exception.NotFound("Entity "+entityID+" that you tried to connect did not exist in any graph "); } //throw new ingenias.exception.NotFound("Entity "+entityID+" that you tried to connect did not exist in any graph "); entities.add(entity); } GraphCell[] selected=new GraphCell[entities.size()]; selected=entities.toArray(selected); NAryEdge nEdge=(NAryEdge) RelationshipFactory.getNRelationshipInstance(relationshipType, selected,browser); Vector<Hashtable<String, String>> result = convertToVectorHashtable(connectedEntities, selected, nEdge); return result; }
/** * Create a clone of the cell. The cloning of the user object is deferred to * the cloneUserObject() method. The source and target references are set to * null. * * @return Object a clone of this object. */ public Object clone() { DefaultEdge edge = (DefaultEdge) super.clone(); edge.source = null; edge.target = null; return edge; }
for (DefaultGraphCell dgc : children) { if (dgc.getChildCount()>0){ Iterator it = jg.getModel().edges(dgc.getFirstChild()); // takes the
public Vector<DefaultGraphCell> getCell(JGraph model, Object o){ Object[] roots=model.getRoots(); Vector<DefaultGraphCell> results=new Vector<DefaultGraphCell>(); for (int k=0;k<roots.length;k++){ if (((DefaultGraphCell)roots[k]).getUserObject() == o) results.add((DefaultGraphCell)roots[k]); } return results; }
@Override protected void postProcessEntity(Entity entity, DefaultGraphCell cell) { super.postProcessEntity(entity, cell); GraphConstants.setBackground(cell.getAttributes(), ENTITY_COLOR); GraphConstants.setOpaque(cell.getAttributes(), true); }