/** * Sets the node types - this maps a background color/gradient to each type. * * @param types */ public void setTypes(Collection<? extends Object> types) { setNodeTypes(types); }
/** * Sets the node types - this is done to map a background color/gradient to each node type. * * @param nodeTypes the node types to add */ public void setNodeTypes(Collection<? extends Object> nodeTypes) { for (Object type : nodeTypes) { addNodeType(type); } }
/** * Adds the node type and maps a color/gradient to it which is used as the background color for * the node. If the node type already exists then nothing is done. * * @param type the node type to add */ public void addNodeType(Object type) { if (!nodeTypeToPaint.containsKey(type)) { Color color = getNextDefaultColor(); GradientPaint paint = new GradientPaint(0, 0, Color.white, 0, 20, color, true); nodeTypeToPaint.put(type, paint); } }
public MainFrame() { super("Baby Shrimp Test"); SampleGraphModel model = new SampleGraphModel(); this.graph = new FlatGraph(model); // color the nodes based on node type DefaultGraphNodeStyle nodeStyle = new DefaultGraphNodeStyle(); nodeStyle.setNodeTypes(model.getNodeTypes()); this.graph.setGraphNodeStyle(nodeStyle); // color the arcs based on arc type DefaultGraphArcStyle arcStyle = new DefaultGraphArcStyle(); arcStyle.setArcTypes(model.getArcTypes()); this.graph.setGraphArcStyle(arcStyle); initialize(); // run the initial layout on the nodes //SwingUtilities.invokeLater(new Runnable() { // public void run() { // try { // Thread.sleep(100); // } catch (InterruptedException e) { // } // graph.performLayout(); //} //}); }
/** * Returns the background paint for the node. If the node's type has a mapped color/paint then * that is returned, otherwise the default node background paint is returned. */ public Paint getBackgroundPaint(GraphNode node) { return getTypePaint(node.getType()); }
public DefaultGraphNode(Object userObject, String text, Icon icon, Object type) { super(); this.userObject = userObject; this.changeListeners = new ArrayList<ChangeListener>(); this.style = new DefaultGraphNodeStyle(); this.selected = false; this.highlighted = false; this.matching = false; this.arcs = new ArrayList<GraphArc>(); this.setPickable(true); this.setChildrenPickable(false); textNode = new GraphTextNode(); // make this node match the text size textNode.setConstrainWidthToTextWidth(true); textNode.setConstrainHeightToTextHeight(true); textNode.setPickable(false); addChild(textNode); setText(text); setIcon(icon); setType(type); }
public Point2D getOverlayIconPosition(GraphNode graphNode, Icon icon) { return getOverlayIconPosition(graphNode); }
public Point2D getOverlayIconPosition(GraphNode graphNode) { if (overlayIconPosition != null) { return overlayIconPosition; } // if no position is set, return a default position of top left return getTopLeft(graphNode.getBounds()); }
public DefaultGraphNodeStyle() { loadDefaultColors(); this.nextColorIndex = 0; this.nodeTypeToPaint = new HashMap<Object, Paint>(); this.defaultNodeColor = BG; this.bgPaint = new GradientPaint(0, 0, Color.white, 0, 20, defaultNodeColor, true); borderPaint = Color.black; borderHighlightPaint = Color.black; borderSelectionPaint = Color.blue; borderMatchingPaint = new Color(0, 224, 0); textPaint = Color.black; tooltipBackground = defaultColors[0]; tooltipTextColor = GraphicsUtils.getTextColor(tooltipBackground); borderStroke = new PFixedWidthStroke(1f); borderHighlightStroke = new PFixedWidthStroke(2f); borderSelectionStroke = borderHighlightStroke; textFont = PText.DEFAULT_FONT; textHighlightFont = textFont; textSelectionFont = textFont; //.deriveFont(Font.BOLD); tooltipFont = textFont; }
public void paintIcon(Component c, Graphics g, int x, int y) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setPaint(getTypePaint(type)); g2.fillRoundRect(x + 1, y + 1, width - 2, height - 2, 5, 5); g2.setPaint(borderPaint); g2.setStroke(new BasicStroke(1)); g2.drawRoundRect(x + 1, y + 1, width - 2, height - 2, 5, 5); } };
public AbstractGraph() { super(); this.model = new DefaultGraphModel(); this.graphModelListeners = new ArrayList<GraphModelListener>(); this.layouts = new ArrayList<LayoutAction>(); addDefaultLayouts(); this.graphPopupListener = new GraphPopupListener(); getCamera().addInputEventListener(graphPopupListener); this.filterManager = new FilterManager(this); this.filterManager.addFilterChangedListener(filterListener); this.selectedNodes = new NodeCollection(); selectedNodes.addCollectionListener(selectionListener); this.matchingNodes = new NodeCollection(); matchingNodes.addCollectionListener(matchingListener); this.nodeStyle = new DefaultGraphNodeStyle(); this.arcStyle = new DefaultGraphArcStyle(); addFocusListener(focusListener); // register to use our custom tooltips CustomToolTipManager.sharedInstance().registerComponent(this); initializeLayers(); // this is needed to handle keyboard events getRoot().getDefaultInputManager().setKeyboardFocus(new KeyHandlerDelegate(getCamera())); }
nodeStyle.setNodeTypes(model.getNodeTypes()); this.graph.setGraphNodeStyle(nodeStyle);