skip to main content
Programmer's documentation > Essential Features > Managers > Blinking of graphic objects
 
Blinking of graphic objects
Describes the three types of blinking mode supported by Rogue Wave® JViews.
*Introduction
*Briefly introduces the blinking mode.
Introduction
Blinking is the periodical change of the drawing of a graphic object. A blinking object drags attention and can be used to indicate a specific alarm state of an object. Rogue Wave JViews supports three kinds of blinking:
*visibility blinking: the object becomes periodically visible and invisible;
*color and paint blinking: the color or paint of an object changes periodically;
*blinking actions: an arbitrary property change is performed periodically on the object.
The blinking mode of a view determines whether a view displays the blinking effects. Usually it is not needed to display any blinking effect on the overview, and therefore the blinking can be switched off for this view by using the following code:
managerView.setBlinkingMode(IlvManagerView.BLINKING_DISABLED);
Visibility blinking
All graphic objects support visibility blinking. In this case, they are periodically shown and hidden. You simply have to set the blinking timing, as in the following example:
graphic.setBlinkingOnPeriod(1000);
graphic.setBlinkingOffPeriod(2000);
The object is now shown every 3 seconds: it is visible for 1 second and hidden for 2 seconds. All objects with the same blinking timing will blink synchronously. Since the blinking mode requires a periodical redraw, it is recommended to use the same timing for many objects when possible, otherwise the performance of the system will degrade by too many unsynchronized draw operations.
The blinking of the object starts when both the "on-period" and the "off-period" are not 0. The visibility blinking is a drawing mechanism and does not change the visible flag of the graphic object, that is, the method isVisible()called on the graphic object remains unchanged whether the blinking mode currently hides or shows the object.
Blinking colors and paints
The class IlvBlinkingColor represents a blinking color. It can be used as color of those properties of IlvGraphic objects that expect a java.awt.Color as parameter and are documented to support blinking colors. A blinking color changes the visible color periodically.
java.awt.Color color = new IlvBlinkingColor(Color.green, Color.blue, 1000, 1000);
IlvLine line = new IlvLine();
line.setForeground(color);
This line object switches periodically from green to blue every second. It is also possible to create colors or paints that switch between multiple states:
Color color = new IlvBlinkingMultiColor(1000, Color.blue, Color.red, Color.green, Color.yellow);
Paint redGreen = new GradientPaint(0, 0, Color.red, 0, 100, Color.green);
Paint blueYellow = new GradientPaint(0, 0, Color.blue, 100, 0, Color.yellow);
Paint blackWhite = new GradientPaint(0, 0, Color.black, 0, 100, Color.white);
Paint paint1 = new IlvBlinkingPaint(redGreen, blueYellow, 1000, 2000);
Paint paint2 = new IlvBlinkingMultiPaint(1000, redGreen, blueYellow, blackWhite);
The first color switches from blue to red to green to yellow back to blue. paint1 switches between 2 gradient paints, it stays 1 second red-green, then 2 seconds blue-yellow. paint2 switches every second between 3 gradient paints.
The classes IlvBlinkingColor, IlvBlinkingMultiColor, IlvBlinkingPaint, IlvBlinkingMultiPaint can only be used in combination with Java API objects. They work if the set method of a property expects java.awt.Color or java.awt.Paint and is documented to support blinking colors or paints. They have no blinking effect when used as colors for other objects such as JComponent or JPanel.
NOTE Since blinking requires a periodical redraw, it is recommended to use the same timing for many blinking colors and paints when possible, otherwise the performance of the system will degrade by too many unsynchronized draw operations.
Adding blinking facilities into your own IlvGraphic subclass
If you implement your own subclass of Java API, this subclass might have various colors or paints that are used to draw specific parts of the graphic objects. To enable these colors and paints to support blinking, you need to register them as blinking resources by calling the method
void registerBlinkingResource(Object oldResource, Object newResource);
You must register the colors and paints whenever they change, that is, in setter methods, copy constructors, stream-constructors and so on. Here is an example class that supports blinking color and paint properly:
import ilog.views.internal.impl.IlvUtility2D;
 
/**
 * A new class.
 */
public class MyClass extends IlvGraphic
{
    // the default color is not a blinking color
    private static Color _defaultColor = Color.black;
 
    private Color _color = _defaultColor;
    private Paint _paint = _defaultColor;
 
    /**
     * The default constructor.
     */
    public MyClass()
    {
        super();
        // the default color black does not blink, hence
        // no blinking resource must be registered.
    }
 
    /**
     * The copy constructor.
     */
    public MyClass(MyClass source)
    {
        super(source);
        Color oldColor = _color;
        Paint oldPaint = _paint;
        _color = source._color;
        _paint = source._paint;
        registerBlinkingResource(oldColor, _color);
        registerBlinkingResource(oldPaint, _paint);
 
        // or alternatively
        // setColor(source.getColor());
        // setPaint(source.getPaint());
        // then omit the additional calls of registerBlinkingResource
    }
 
    /**
     * The input stream constructor.
     */
    public MyClass(IlvInputStream stream) throws IlvReadFileException
    {
        super(stream);
        Color oldColor = _color;
        Paint oldPaint = _paint;
        _color = stream.readColor("color");
        _paint = stream.readPaint("paint");
 
        registerBlinkingResource(oldColor, _color);
        registerBlinkingResource(oldPaint, _paint);
 
        // or alternatively
        // setColor(stream.readColor("color"));
        // setPaint(IlvUtility2D.readPaint(stream, "paint", "p"));
        // then omit the additional calls of registerBlinkingResource
    }
 
    /**
     * Writes the object to an IVL file.
     */
    public void write(IlvOutputStream stream)
        throws IOException
    {
        super.write(stream);
        stream.write("color", _color);
        stream.writePaint(_paint, "paint", _defaultColor);
    }
 
    /**
     * Sets the color.
     * As Bean Property, you can use the property editor
     * ilog.views.util.beans.editor.IlvBlinkingColorPropertyEditor
     * which supports blinking.
     */
    public void setColor(Color c)
    {
        if (c == null)
            c = _defaultColor;
 
        Color oldColor = _color;
        _color = c;
        registerBlinkingResource(oldColor, c);
    }
 
    /**
     * Returns the color.
     */
    public Color getColor()
    {
        return _color;
    }
 
    /**
     * Sets the color.
     * As Bean Property, you can use the property editor
     * ilog.views.util.beans.editor.IlvBlinkingPaintPropertyEditor
     * which supports blinking.
     */
    public void setPaint(Paint p)
    {
        if (p == null)
            p = _defaultColor;
 
        Paint oldPaint = _paint;
        _paint = p;
        registerBlinkingResource(oldPaint, c);
    }
 
    /**
     * Returns the paint.
     */
    public Paint getPaint()
    {
        return _paint;
    }
}
Blinking actions
Visibility blinking and color blinking are optimized cases of blinking. In general, you can define an arbitrary action that is periodically performed on the object.
IlvMarker marker = new IlvMarker();
IlvBlinkingAction action = new IlvBlinkingAction(1000,1000) {
    protected void changeState(IlvGraphic obj, boolean isOn) {
        // no applyToObject necessary because the caller does it already for us
        IlvMarker marker = (IlvMarker)obj;
        if (isOn) {
            marker.setType(IlvMarker.IlvMarkerCircle);
        } else {
            marker.setType(IlvMarker.IlvMarkerSquare);
        }
    }
};
marker.setBlinkingAction(action);
In this example, the marker type is periodically changed every second from circle to square. By using the class IlvBlinkingMultiAction, it is even possible to perform an arbitrary number of steps periodically on the graphic object.
NOTE Blinking actions that change the bounding box of the graphic object work correctly but they are very inefficient. Since blinking requires a periodical redraw, it is recommended to use the same timings for many blinking actions when possible, otherwise the performance of the system will degrade by too many unsynchronized draw operations.

Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.