net.algart.drawing3d
Class SimpleColoringRule

java.lang.Object
  extended by net.algart.drawing3d.SimpleColoringRule
All Implemented Interfaces:
ColoringRule

public class SimpleColoringRule
extends java.lang.Object
implements ColoringRule

Simple implementation of ColoringRule interface, which returns some given color for all inheritors of some given class.

More precisely, this rule works with some fixed requiredClass, passed to the constructor, and isApplicable(Object item) method returns true if and only if requiredClass.isInstance(item). The method getColor(Object) of this class always returns the fixed color, also passed to the constructor.

This class is thread-safe: it can be used simultaneously in several threads.

AlgART Laboratory 2010

Since:
JDK 1.5
Version:
1.0
Author:
Daniel Alievsky

Constructor Summary
Constructor and Description
SimpleColoringRule(java.lang.Class<?> requiredClass, java.awt.Color color)
          Creates new instance of this class.
 
Method Summary
Modifier and Type Method and Description
 java.awt.Color getColor()
          Returns the color, which will be returned by getColor(Object) method.
 java.awt.Color getColor(java.lang.Object item)
          Returns the color of the specified object.
 boolean isApplicable(java.lang.Object item)
          Checks whether this coloring rule is applicable to the given object (item), i.e. this coloring rule "knows" which color should be used for drawing this object.
 void setColor(java.awt.Color color)
          Sets the color, which will be returned by getColor(Object) method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleColoringRule

public SimpleColoringRule(java.lang.Class<?> requiredClass,
                          java.awt.Color color)
Creates new instance of this class. In the created object, isApplicable(Object item) method is equivalent to requiredClass.isInstance(item), where requiredClass is the argument of this constructor.

Parameters:
requiredClass - the class, which will be checked by isApplicable(Object) method. Cannot be changed in future.
color - the color, which will be returned by getColor(Object) method.
Method Detail

getColor

public java.awt.Color getColor()
Returns the color, which will be returned by getColor(Object) method.

Returns:
the current color.

setColor

public void setColor(java.awt.Color color)
Sets the color, which will be returned by getColor(Object) method.

Parameters:
color - new current color.

isApplicable

public boolean isApplicable(java.lang.Object item)
Description copied from interface: ColoringRule
Checks whether this coloring rule is applicable to the given object (item), i.e. this coloring rule "knows" which color should be used for drawing this object. If this method returns false, you should not call ColoringRule.getColor(Object) method of this interface for this object: it can throw an exception. If this method returns true, you can freely use ColoringRule.getColor(Object) method.

If this method returns false for the given item for all coloring rules, available in Drawer3D object, then this item is not drawn by the Drawer3D.draw(java.util.Collection) method.

The argument of this method can be null; in this case, this method returns false.

Specified by:
isApplicable in interface ColoringRule
Parameters:
item - the object which you want to draw; can be null, then this method returns false.
Returns:
true if this coloring rule can be used for this item.

getColor

public java.awt.Color getColor(java.lang.Object item)
Description copied from interface: ColoringRule
Returns the color of the specified object. If ColoringRule.isApplicable(Object) returns false, this method usually throws ClassCastException, but other runtime exceptions are also possible.

Specified by:
getColor in interface ColoringRule
Parameters:
item - some 3D object.
Returns:
color of this item.