package com.onaro.sanscreen.client.view.topology; import ilog.views.IlvManagerView; import ilog.views.IlvManagerViewDecoration; import ilog.views.swing.IlvJScrollManagerView; import java.awt.AlphaComposite; import java.awt.Color; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; /** * A means to paint an error message across the center of the given topology scroll view. Based on TopologyWatermark * * @author Joshuae */ public class TopologyErrorMessage implements IlvManagerViewDecoration { /** Error message's font size. */ private static final int FONT_SIZE = 40; /** Opaqueness of the text displayed in the error message. */ private static final AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.25f); /** Error message's font type. */ private static final Font font = new Font(Font.SANS_SERIF, Font.BOLD, FONT_SIZE); private volatile String message = ""; /** A panel containing an two scrollbars.*/ private IlvJScrollManagerView netGraphScrollManager; /** * Constructor. * * @param netGraphScrollManager ILog scroll manager. */ public TopologyErrorMessage(IlvJScrollManagerView netGraphScrollManager) { this.netGraphScrollManager = netGraphScrollManager; } /** * Logic that take place during the rendering of the netGraphScrollManager */ public void paint(final Graphics g, final IlvManagerView ilvManagerView) { Graphics2D g2 = (Graphics2D) g; // Setting for the: geometry, coordinate transformations, color management, and text layout. g2.setComposite(alpha); g2.setColor(Color.BLACK); g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2.setFont(font); FontMetrics fm = g.getFontMetrics(); // useful measurements. int height = netGraphScrollManager.getHeight(); int width = netGraphScrollManager.getWidth(); int fontHeight = fm.getHeight(); int stringWidth = fm.stringWidth(message); g.drawString(message, (width - stringWidth)/2, (height - fontHeight)/2); } public void setMessage(String message) { if (message == null) { throw new IllegalArgumentException("message cannot be null"); } this.message = message; } }