private void positionVertexAt(Object vertex, int x, int y) { DefaultGraphCell cell = m_jgAdapter.getVertexCell(vertex); AttributeMap attr = cell.getAttributes(); Rectangle2D b = GraphConstants.getBounds(attr); Rectangle2D newBounds = new Rectangle2D.Double(x, y, 5, 5); GraphConstants.setBounds(attr, newBounds); AttributeMap cellAttr = new AttributeMap(); cellAttr.put(cell, attr); m_jgAdapter.edit(cellAttr, null, null, null); }
private void setVertexColor(Object vertex, Color color) { DefaultGraphCell cell = m_jgAdapter.getVertexCell(vertex); AttributeMap attr = cell.getAttributes(); GraphConstants.setBackground(attr, color); AttributeMap cellAttr = new AttributeMap(); cellAttr.put(cell, attr); m_jgAdapter.edit(cellAttr, null, null, null); }
@Override public AttributeMap getDefaultEdgeAttributes() { AttributeMap map = new AttributeMap(); GraphConstants.setLineEnd(map, GraphConstants.ARROW_TECHNICAL); GraphConstants.setEndFill(map, true); GraphConstants.setLabelAlongEdge(map, true); GraphConstants.setForeground(map, Color.decode("#25507C")); // GraphConstants.setFont(map, GraphConstants.DEFAULTFONT.deriveFont(Font.BOLD, 12)); GraphConstants.setLineColor(map, Color.decode("#7AA1E6")); return map; }
@SuppressWarnings("unchecked") private void positionVertexAt(Object vertex, int x, int y) { DefaultGraphCell cell = m_jgAdapter_.getVertexCell(vertex); AttributeMap attr = cell.getAttributes(); Rectangle2D bounds = GraphConstants.getBounds(attr); Rectangle2D newBounds = new Rectangle2D.Double(x, y, bounds.getWidth(), bounds.getHeight()); GraphConstants.setBounds(attr, newBounds); // TODO: Clean up generics once JGraph goes generic AttributeMap cellAttr = new AttributeMap(); cellAttr.put(cell, attr); m_jgAdapter_.edit(cellAttr, null, null, null); }
/** * Sets new value to horizontal and vertical positions * * @param x * @param y */ public void setPosition(Point point) { Map attrs = new Hashtable(); GraphConstants.setBounds( attrs, new Rectangle2D.Double(point.getX(), point.getY(), getDefaultWidth(), getDefaultHeight())); graph.getGraphLayoutCache().editCell(this, attrs); graph.repaint(); }
public CLierInterface( VueDPGraphe d, ArrayList pointsAncrageIntermediaires, IeppCell ieppsource, IeppCell ieppdestination) { this.diagramme = d; pointsAncrage = pointsAncrageIntermediaires; AllAttribute = GraphConstants.createMap(); cellS = ieppsource; cellD = ieppdestination; portS = ieppsource.getPortComp(); portD = ieppdestination.getPortComp(); }
/** * 往流程图编辑器中增加一个元素 * * @param ele */ public DefaultGraphCell insertFlowElement(FlowElementObject ele) { if (this.graph == null) return null; if (ele.getId() == 0) { int id = (new IDService()).getProcessID(); ele.setId(id); } DefaultGraphCell cell = new DefaultGraphCell(); cell.setUserObject(ele); if (ele.getImageResource() != null) { GraphConstants.setIcon(cell.getAttributes(), UIUtil.loadImageIcon(ele.getImageResource())); } // 自动设置大小 // GraphConstants.setAutoSize(cell.getAttributes(), true); GraphConstants.setOpaque(cell.getAttributes(), true); // GraphConstants.setBackground(cell.getAttributes(), Color.YELLOW); GraphConstants.setLineColor(cell.getAttributes(), Color.RED); GraphConstants.setLineWidth(cell.getAttributes(), 1.5f); GraphConstants.setLineStyle(cell.getAttributes(), GraphConstants.STYLE_SPLINE); // GraphConstants.setSizeable(cell.getAttributes(),false); GraphConstants.setBorder( cell.getAttributes(), BorderFactory.createLineBorder(Color.BLACK)); // 外框颜色 // GraphConstants.setBounds(cell.getAttributes(), new // Rectangle2D.Double( // 10, 10, 80, 40)); GraphConstants.setBounds( cell.getAttributes(), new Rectangle2D.Double( ele.getLeft().doubleValue(), ele.getTop().doubleValue(), ele.getWidth().doubleValue(), ele.getHeight().doubleValue())); GraphConstants.setEditable(cell.getAttributes(), false); cell.addPort(); this.graph.getGraphLayoutCache().insert(cell); // 向图形编辑器写入处理后的图片. return cell; }
public java.awt.Component getRendererComponent(JGraph jg, boolean b1, boolean b2, boolean b3) { CellViewRenderer renderer = null; try { ingenias.editor.entities.GTPursues ent = (ingenias.editor.entities.GTPursues) ((DefaultGraphCell) this.getCell()).getUserObject(); this.renderer1.setEntity(ent); JPanel uop = (JPanel) this.renderer1.getRendererComponent(null, null, false, false, false); if (ent.getPrefs().getView() == ingenias.editor.entities.ViewPreferences.ViewType.LABEL) { NAryEdge naryedge = (NAryEdge) this.getCell(); DefaultEdge[] edge = naryedge.getRepresentation(); AttributeMap am = edge[0].getAttributes(); GraphConstants.setLabelAlongEdge(am, true); GraphConstants.setExtraLabels(am, new Object[] {ent.getLabel()}); GraphConstants.setExtraLabelPositions( am, new Point2D[] {new Point2D.Double(GraphConstants.PERMILLE * 7 / 8, -20)}); edge[0].setAttributes(am); } return (Component) uop; } catch (Exception e) { e.printStackTrace(); ingenias.editor.Log.getInstance().log("WARNING!!!" + e.getMessage()); } return super.getRendererComponent(jg, b1, b2, b3); }
// From GraphSelectionListener Interface public void valueChanged(GraphSelectionEvent e) { // 设置工具条相关按钮的可用性 editor.mainToolBar.setActionEnabled(MainActions.ACTION_GROUP, graph.getSelectionCount() > 1); // Update Button States based on Current Selection boolean enabled = !graph.isSelectionEmpty(); editor.mainToolBar.setActionEnabled(MainActions.ACTION_DELETE, enabled); editor.mainToolBar.setActionEnabled(MainActions.ACTION_UNGROUP, enabled); editor.mainToolBar.setActionEnabled(MainActions.ACTION_TOFRONT, enabled); editor.mainToolBar.setActionEnabled(MainActions.ACTION_TOBACK, enabled); editor.mainToolBar.setActionEnabled(MainActions.ACTION_COPY, enabled); editor.mainToolBar.setActionEnabled(MainActions.ACTION_CUT, enabled); if (graph.getSelectionCount() > 0) { Object c = graph.getSelectionCell(); if (c instanceof DefaultGraphCell) { DefaultGraphCell cell = (DefaultGraphCell) c; Object uo = cell.getUserObject(); Rectangle2D rect = GraphConstants.getBounds(cell.getAttributes()); if (rect != null) { editor.messageView.warn( "rect=" + rect.getX() + ":" + rect.getY() + rect.getWidth() + ":" + rect.getHeight()); } if (uo instanceof FlowElementObject) { editor.propertiesView.resetProperties(((FlowElementObject) uo).getProperties()); } else { // System.out.println("uo="+uo); undo(); editor.messageView.warn("不能这样操作,请在操作左加的属性值"); // System.out.println("不能这样操作"); // editor.propertiesView.resetProperties(null); } } else { undo(); // editor.propertiesView.resetProperties(null); editor.messageView.warn("不能这样操作,操作对像,不能识别" + c.getClass().getName()); } } else { editor.propertiesView.resetProperties(graph.getGraphInfo().getProperties()); } // System.out.println("Change"); }
/** * 创建连接线的相关属性 * * @return */ public Map createEdgeAttributes() { Map map = new Hashtable(); // Add a Line End Attribute GraphConstants.setLineEnd(map, GraphConstants.ARROW_TECHNICAL); // Add a label along edge attribute GraphConstants.setLabelAlongEdge(map, false); GraphConstants.setEndFill(map, true); GraphConstants.setLineWidth(map, 1.0f); GraphConstants.setLineColor(map, Color.black); GraphConstants.setEditable(map, false); return map; }
/** * Creates and returns a map of attributes to be used as defaults for vertex attributes. * * @return a map of attributes to be used as defaults for vertex attributes. */ public static AttributeMap createDefaultVertexAttributes() { AttributeMap map = new AttributeMap(); Color c = Color.decode("#FF9900"); GraphConstants.setBounds(map, new Rectangle2D.Double(50, 50, 90, 30)); GraphConstants.setBorder(map, BorderFactory.createRaisedBevelBorder()); GraphConstants.setBackground(map, c); GraphConstants.setForeground(map, Color.white); GraphConstants.setFont(map, GraphConstants.DEFAULTFONT.deriveFont(Font.BOLD, 12)); GraphConstants.setOpaque(map, true); return map; }
/** * Creates and returns a map of attributes to be used as defaults for edge attributes, depending * on the specified graph. * * @param jGraphTGraph the graph for which default edge attributes to be created. * @return a map of attributes to be used as default for edge attributes. */ public static <V, E> AttributeMap createDefaultEdgeAttributes(Graph<V, E> jGraphTGraph) { AttributeMap map = new AttributeMap(); if (jGraphTGraph instanceof DirectedGraph<?, ?>) { GraphConstants.setLineEnd(map, GraphConstants.ARROW_TECHNICAL); GraphConstants.setEndFill(map, true); GraphConstants.setEndSize(map, 10); } GraphConstants.setForeground(map, Color.decode("#25507C")); GraphConstants.setFont(map, GraphConstants.DEFAULTFONT.deriveFont(Font.BOLD, 12)); GraphConstants.setLineColor(map, Color.decode("#7AA1E6")); return map; }
/** * Constructor for graph * * @param x * @param y * @param data * @param graph */ public AbstractGraphVertex(int x, int y, DataItem data, MicroarrayGraph graph) { super(data); this.graph = graph; this.setPosition(new Point(x, y)); GraphConstants.setGradientColor(this.getAttributes(), DEFAULT_VERTEX_COLOR); GraphConstants.setBorderColor(this.getAttributes(), Color.black); GraphConstants.setOpaque(this.getAttributes(), true); GraphConstants.setVerticalAlignment(this.getAttributes(), JLabel.TOP); Font font = GraphConstants.getFont(this.getAttributes()); font = font.deriveFont((float) font.getSize() + 3); GraphConstants.setFont(this.getAttributes(), font); }
@Override public AttributeMap getDefaultVertexAttributes() { AttributeMap map = new AttributeMap(); // we set the bounds only to force the layout manager to use minimum size shapes // this way the auto sizing mechanism will immediately generate the optimum sized shapes // TODO I am not sure how exactly setBounds(...) works with setAutoSize(...) GraphConstants.setBounds(map, new Rectangle2D.Double(0, 0, 100, 100)); GraphConstants.setAutoSize(map, true); GraphConstants.setBackground(map, Color.LIGHT_GRAY); GraphConstants.setForeground(map, Color.BLACK); GraphConstants.setOpaque(map, true); // GraphConstants.setFont(map, GraphConstants.DEFAULTFONT.deriveFont(Font.BOLD, 12)); GraphConstants.setBorderColor(map, Color.black); // we want to have the nodes represented as circles // but, the auto size property overrides this and // ellipses are created CellConstants.setVertexShape(map, MultiLineVertexRenderer.SHAPE_CIRCLE); return map; }
/** @see java.awt.event.ActionListener#actionPerformed(ActionEvent) */ public void actionPerformed(ActionEvent e) { AttributeMap map = new AttributeMap(); GraphConstants.setHorizontalAlignment(map, JLabel.RIGHT); setSelectionAttributes(map); }
public Map createEdgeAttributes() { Map map = super.createEdgeAttributes(); // Adds a parallel edge router GraphConstants.setRouting(map, ParallelEdgeRouter.getSharedInstance()); return map; }
public Map createCellAttributes(Point2D point) { Map map = super.createCellAttributes(point); GraphConstants.setInset(map, 5); return map; }
public void setPosition(Point parent, int levelHeight) { int nextLevelHeight = 0; for (Iterator it = children.iterator(); it.hasNext(); ) { nextLevelHeight = Math.max(nextLevelHeight, ((TreeNode) it.next()).height); } if (parent == null) { Rectangle2D b = view.getBounds(); Rectangle bounds = new Rectangle( (int) b.getX(), (int) b.getY(), (int) b.getWidth(), (int) b.getHeight()); Point p = bounds.getLocation(); if (centerRoot) { int lw = getLeftWidth(); int rw = getRightWidth(); int h = getHeight(); Insets i = graph.getInsets(); if (orientation == SwingConstants.NORTH) { bounds.x = lw - (width / 2); bounds.y = i.top; } else if (orientation == SwingConstants.EAST) { bounds.x = (i.left + h) - width; bounds.y = lw - (height / 2); } else if (orientation == SwingConstants.SOUTH) { bounds.x = lw - (width / 2); bounds.y = i.top + h; } else if (orientation == SwingConstants.WEST) { bounds.x = i.right; bounds.y = lw - (width / 2); } Object cell = view.getCell(); Map attributes = GraphConstants.createAttributes(cell, GraphConstants.BOUNDS, bounds); graph.getGraphLayoutCache().edit(attributes, null, null, null); if ((orientation == SwingConstants.WEST) || (orientation == SwingConstants.EAST)) { graph.setPreferredSize(new Dimension(h + i.left + i.right, lw + rw + i.top + i.bottom)); } else { graph.setPreferredSize(new Dimension(lw + rw + i.left + i.right, h + i.top + i.bottom)); } p = bounds.getLocation(); } if ((orientation == SwingConstants.WEST) || (orientation == SwingConstants.EAST)) { int tmp = p.x; p.x = p.y; p.y = tmp; } if ((orientation == SwingConstants.NORTH) || (orientation == SwingConstants.WEST)) { parent = new Point(p.x + (width / 2), p.y + height); } else if ((orientation == SwingConstants.SOUTH) || (orientation == SwingConstants.EAST)) { parent = new Point(p.x + (width / 2), p.y); } for (Iterator it = children.iterator(); it.hasNext(); ) { ((TreeNode) it.next()).setPosition(parent, nextLevelHeight); } return; } if (combineLevelNodes) { levelHeight = this.levelheight; } Rectangle cellBounds = new Rectangle(width, height); if ((orientation == SwingConstants.NORTH) || (orientation == SwingConstants.WEST)) { cellBounds.x = (x + parent.x) - (width / 2); cellBounds.y = parent.y + levelDistance; } else { cellBounds.x = (x + parent.x) - (width / 2); cellBounds.y = parent.y - levelDistance - levelheight; } if (alignment == SwingConstants.CENTER) { cellBounds.y += ((levelHeight - height) / 2); } else if (alignment == SwingConstants.BOTTOM) { cellBounds.y += (levelHeight - height); } if ((orientation == SwingConstants.WEST) || (orientation == SwingConstants.EAST)) { int tmp = cellBounds.x; cellBounds.x = cellBounds.y; cellBounds.y = tmp; tmp = cellBounds.width; cellBounds.width = cellBounds.height; cellBounds.height = tmp; } Object cell = view.getCell(); Map attributes = GraphConstants.createAttributes(cell, GraphConstants.BOUNDS, cellBounds); graph.getGraphLayoutCache().edit(attributes, null, null, null); if ((orientation == SwingConstants.NORTH) || (orientation == SwingConstants.WEST)) { y = parent.y + levelDistance + levelHeight; } else { y = parent.y - levelDistance - levelHeight; } for (Iterator it = children.iterator(); it.hasNext(); ) { ((TreeNode) it.next()).setPosition(new Point(x + parent.x, y), nextLevelHeight); } }
/** * Gets the vertex bounds * * @return */ public Rectangle2D getBounds() { return GraphConstants.getBounds(this.getAttributes()); }