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;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.concurrent.atomic.AtomicBoolean;
import com.onaro.sanscreen.client.prefs.GeneralPreferenceManager;
/**
* Implements a "watermark" in each of the corners of the topology view (formation of 4).
*
* It's possible to set a number of options at run-time that affect the visualization of this watermark.
* Because there is no requirement yet only the watermark's text has been implemented to take changes
* dynamically by using SANscreen's settings.
*
*
* The following static parameters could in the "future" be modified at run-time. *
netGraphScrollManager
*/
public void paint(final Graphics g, final IlvManagerView ilvManagerView) {
if (!isWatermarkEnabled.get())
return;
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);
fm = g.getFontMetrics();
// useful measurements.
int height = netGraphScrollManager.getHeight();
int width = netGraphScrollManager.getWidth();
int fontHeight = fm.getHeight();
int stringWidth = fm.stringWidth(watermark);
// top-left corner
g.drawString(watermark, MARGIN, fontHeight - MARGIN);
// bottom-left corner
g.drawString(watermark, MARGIN, height - fontHeight + MARGIN);
// top-right corner
g.drawString(watermark, width - stringWidth - 4 * MARGIN, fontHeight - MARGIN);
// bottom-left corner
g.drawString(watermark, width - stringWidth - 4 * MARGIN, height - fontHeight + MARGIN);
}
/**
* Receive notifications after the "publisher" fires the change events.
* @see {@link GeneralPreferenceManager#setTopologyWatermarkEnabled}
*/
public void propertyChange(PropertyChangeEvent evt) {
final String propName = evt.getPropertyName();
if (GeneralPreferenceManager.SERVER_PREF_TOPOLOGY_WATERMARK_ENABLED.equals(propName)) {
Boolean newValue = (Boolean) evt.getNewValue();
if (newValue != null) {
isWatermarkEnabled.set(newValue);
netGraphScrollManager.repaint();
}
}
if (GeneralPreferenceManager.SERVER_PREF_TOPOLOGY_WATERMARK_TEXT.equals(propName)) {
String newValue = (String) evt.getNewValue();
if (newValue != null) {
watermark = newValue;
netGraphScrollManager.repaint();
}
}
}
}