001 package com.croftsoft.core.animation.painter;
002
003 import java.awt.Graphics2D;
004 import javax.swing.JComponent;
005
006 import com.croftsoft.core.animation.ComponentPainter;
007 import com.croftsoft.core.lang.NullArgumentException;
008 import com.croftsoft.core.util.ArrayLib;
009
010 /*********************************************************************
011 * Makes a ComponentPainter array look like a single ComponentPainter.
012 *
013 * @version
014 * 2003-07-05
015 * @since
016 * 2002-03-06
017 * @author
018 * <a href="https://www.croftsoft.com/">David Wallace Croft</a>
019 *********************************************************************/
020
021 public final class ArrayComponentPainter
022 implements ComponentPainter
023 //////////////////////////////////////////////////////////////////////
024 //////////////////////////////////////////////////////////////////////
025 {
026
027 private ComponentPainter [ ] componentPainters;
028
029 //////////////////////////////////////////////////////////////////////
030 // constructor methods
031 //////////////////////////////////////////////////////////////////////
032
033 public ArrayComponentPainter (
034 ComponentPainter [ ] componentPainters )
035 //////////////////////////////////////////////////////////////////////
036 {
037 setComponentPainters ( componentPainters );
038 }
039
040 public ArrayComponentPainter ( )
041 //////////////////////////////////////////////////////////////////////
042 {
043 this ( new ComponentPainter [ 0 ] );
044 }
045
046 //////////////////////////////////////////////////////////////////////
047 // accessor/mutator methods
048 //////////////////////////////////////////////////////////////////////
049
050 public ComponentPainter [ ] getComponentPainters ( )
051 //////////////////////////////////////////////////////////////////////
052 {
053 return componentPainters;
054 }
055
056 public void add ( ComponentPainter componentPainter )
057 //////////////////////////////////////////////////////////////////////
058 {
059 componentPainters = ( ComponentPainter [ ] )
060 ArrayLib.append ( componentPainters, componentPainter );
061 }
062
063 public void setComponentPainters (
064 ComponentPainter [ ] componentPainters )
065 //////////////////////////////////////////////////////////////////////
066 {
067 NullArgumentException.check (
068 this.componentPainters = componentPainters );
069 }
070
071 //////////////////////////////////////////////////////////////////////
072 //////////////////////////////////////////////////////////////////////
073
074 /*********************************************************************
075 * Paints each element in the ComponentPainter array.
076 *********************************************************************/
077 public void paint (
078 JComponent component,
079 Graphics2D graphics )
080 //////////////////////////////////////////////////////////////////////
081 {
082 for ( int i = 0; i < componentPainters.length; i++ )
083 {
084 componentPainters [ i ].paint ( component, graphics );
085 }
086 }
087
088 //////////////////////////////////////////////////////////////////////
089 //////////////////////////////////////////////////////////////////////
090 }