001 package com.croftsoft.core.animation.collector;
002
003 import java.awt.Rectangle;
004
005 import com.croftsoft.core.animation.RepaintCollector;
006 import com.croftsoft.core.util.ArrayLib;
007
008 /*********************************************************************
009 * Simply collects the repaint requests.
010 *
011 * @version
012 * 2002-12-01
013 * @since
014 * 2002-12-01
015 * @author
016 * <a href="http://www.CroftSoft.com/">David Wallace Croft</a>
017 *********************************************************************/
018
019 public class SimpleRepaintCollector
020 implements RepaintCollector
021 //////////////////////////////////////////////////////////////////////
022 //////////////////////////////////////////////////////////////////////
023 {
024
025 private int count;
026
027 private Rectangle [ ] repaintRegions;
028
029 //////////////////////////////////////////////////////////////////////
030 // constructor methods
031 //////////////////////////////////////////////////////////////////////
032
033 public SimpleRepaintCollector ( )
034 //////////////////////////////////////////////////////////////////////
035 {
036 repaintRegions = new Rectangle [ 0 ];
037 }
038
039 //////////////////////////////////////////////////////////////////////
040 // accessor methods
041 //////////////////////////////////////////////////////////////////////
042
043 public int getCount ( ) { return count; }
044
045 public Rectangle [ ] getRepaintRegions ( )
046 //////////////////////////////////////////////////////////////////////
047 {
048 return repaintRegions;
049 }
050
051 //////////////////////////////////////////////////////////////////////
052 // mutator methods
053 //////////////////////////////////////////////////////////////////////
054
055 public void repaint (
056 int x,
057 int y,
058 int width,
059 int height )
060 //////////////////////////////////////////////////////////////////////
061 {
062 if ( count == repaintRegions.length )
063 {
064 repaintRegions = ( Rectangle [ ] ) ArrayLib.append (
065 repaintRegions, new Rectangle ( x, y, width, height ) );
066 }
067 else
068 {
069 repaintRegions [ count ].setBounds ( x, y, width, height );
070 }
071
072 count++;
073 }
074
075 public void repaint ( )
076 //////////////////////////////////////////////////////////////////////
077 {
078 repaint ( 0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE );
079 }
080
081 public void reset ( )
082 //////////////////////////////////////////////////////////////////////
083 {
084 count = 0;
085 }
086
087 //////////////////////////////////////////////////////////////////////
088 //////////////////////////////////////////////////////////////////////
089 }