public DrawnIconVertexDemo(final Deployment dm) {
this.dmodel = dm;
// create a simple graph for the demo
graph = new DirectedSparseGraph<Vertex, Edge>();
vv = new VisualizationViewer<Vertex, Edge>(new SpringLayout2<Vertex, Edge>(graph));
vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.cyan));
vv.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.cyan));
vv.getRenderContext().setVertexIconTransformer(vertexColor);
vv.getRenderContext().setVertexFillPaintTransformer(new PickableVertexPaintTransformer<Vertex>(vv.getPickedVertexState(), Color.white, Color.yellow));
vv.getRenderContext().setEdgeDrawPaintTransformer(edgeColor);
vv.setBackground(Color.white);
// add my listener for ToolTips
vv.setVertexToolTipTransformer(new ToStringLabeller<Vertex>());
}
@Override
public <V> Component getVertexLabelRendererComponent(final JComponent vv, final Object value, final Font fnt, final boolean sel, final V vertex) {
final DefaultVertexLabelRenderer renderer = (DefaultVertexLabelRenderer) super.getVertexLabelRendererComponent(vv, value, fnt, sel, vertex);
final AbstractTopologyComponent data = (AbstractTopologyComponent) vertex;
renderer.setHorizontalTextPosition(SwingConstants.CENTER);
renderer.setVerticalTextPosition(SwingConstants.BOTTOM);
renderer.setText(TopologyUtils.getDisplayName(data, StatsHandler.getInstance().getShowIPHandler().isShowIP()));
String path = null;
Color background = Color.white;
Color backgroundSelected = Color.blue;
final Color foreground = sel ? AbstractTreeCellRenderer.DEFAULT_SELECTION_FOREGROUND : AbstractTreeCellRenderer.DEFAULT_FOREGROUND;
if (baseFont == null) {
final Font f2 = renderer.getFont();
baseFont = new Font(f2.getFontName(), f2.getStyle(), 10);
boldFont = new Font(baseFont.getName(), Font.BOLD, baseFont.getSize());
italicFont = new Font(baseFont.getName(), Font.ITALIC, baseFont.getSize());
boldItalicFont = new Font(baseFont.getName(), Font.BOLD|Font.ITALIC, baseFont.getSize());
}
Font font = baseFont;
if (data.isDriver()) {
final JPPFClientConnection c = ((TopologyDriver) data).getConnection();
if (c == null) {
path = AbstractTreeCellRenderer.DRIVER_ICON;
background = AbstractTreeCellRenderer.INACTIVE_COLOR;
} else if (c.getStatus().isWorkingStatus()) {
path = AbstractTreeCellRenderer.DRIVER_ICON;
background = AbstractTreeCellRenderer.ACTIVE_COLOR;
font = boldFont;
} else {
path = AbstractTreeCellRenderer.DRIVER_INACTIVE_ICON;
background = AbstractTreeCellRenderer.INACTIVE_COLOR;
backgroundSelected = AbstractTreeCellRenderer.INACTIVE_SELECTION_COLOR;
font = boldItalicFont;
}
} else {
path = GuiUtils.computeNodeIconKey((TopologyNode) data);
if (((TopologyNode) data).getStatus() != TopologyNodeStatus.UP) {
background = AbstractTreeCellRenderer.INACTIVE_COLOR;
backgroundSelected = AbstractTreeCellRenderer.INACTIVE_SELECTION_COLOR;
font = italicFont;
}
}
if (font != null) renderer.setFont(font);
final ImageIcon icon = GuiUtils.loadIcon(path);
renderer.setIcon(icon);
renderer.setBackground(sel ? backgroundSelected : background);
renderer.setForeground(foreground);
return renderer;
}