/** * 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; }
/** * 往流程图编辑器中增加一个元素 * * @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; }