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); }
/** * Sets the bounds of this node based on the icon and text size. Takes into consideration the * maximum node width too. */ private void updateBounds() { PBounds textBounds = textNode.getBounds(); double w = (3 * PADDING_X) + iconWidth + ICON_GAP + textBounds.getWidth(); double h = (2 * PADDING_Y) + Math.max(iconHeight, textBounds.getHeight()); setBounds(getX(), getY(), w, h); }
@Override protected void paint(PPaintContext paintContext) { // update the text paint - the super paint method doesn't call our getTextPaint() method Paint p = getTextPaint(); if (!p.equals(super.getTextPaint())) { ignoreInvalidatePaint = true; setTextPaint(getTextPaint()); ignoreInvalidatePaint = false; } // the font is never set in the super paint class? paintContext.getGraphics().setFont(getFont()); super.paint(paintContext); }
@Override public boolean setBounds(double x, double y, double width, double height) { // TODO handle maximum width? boolean changed = super.setBounds(x, y, width, height); if (changed) { if (pImage != null) { pImage.setBounds(getX() + PADDING_X, getY() + PADDING_Y, iconWidth, iconHeight); } textNode.setBounds(getX() + PADDING_X + iconWidth + ICON_GAP, getY() + PADDING_Y, textNode.getWidth(), textNode.getHeight()); updateArcLocations(); invalidatePaint(); fireChangeListeners(); } return changed; }
public void setHighlighted(boolean highlighted) { if (this.highlighted != highlighted) { this.highlighted = highlighted; bubbleNode(); textNode.invalidatePaint(); invalidatePaint(); } }
public void setSelected(boolean selected) { if (this.selected != selected) { this.selected = selected; updateArcs(); textNode.invalidatePaint(); invalidatePaint(); } }