Class CanvasAWTAdapter

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int DEFAULT_MAX_FPS
      Default maximum frames per second.
    • Constructor Summary

      Constructors 
      Constructor Description
      CanvasAWTAdapter​(java.awt.Component target, boolean strictThreadControl)
      The java.awt.Component that is passed to the constructors is interacted with by the code in this class with only three calls to it: (1) Component.createImage(int,int), (2) Component.createImage(java.awt.image.ImageProducer), and (3) Component.repaint().
      CanvasAWTAdapter​(java.awt.Component target, boolean strictThreadControl, int maxFramesPerSecond)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void destroy()
      The component using this adapter should call destroy() when the adapter is no longer needed.
      java.awt.Image produceImage​(int width, int height)
      Images are useful for doing double buffering.
      java.awt.Image produceImage​(java.awt.image.ImageProducer prod)
      getGraphics() on the returned image will fail; in other words the returned image is good for rendering and not so good for drawing onto.
      void requestUpdate()
      This method triggers a call to update(Graphics) on a corresponding AbstractCanvas.
      void setUpdatable​(VisiblyUpdatable updatable)
      Should be regarded as part of the construction of an instance.
      java.awt.Rectangle update​(java.awt.Graphics g)
      This should be called directly from update(Graphics) of the java.awt.Component using this adapter.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_MAX_FPS

        public static final int DEFAULT_MAX_FPS
        Default maximum frames per second. This affects the time gap between successive frames. Successive frames won't be allowed to be too close together in time proximity, for the sake of not exhausting CPU resources. A value of zero or negative is interpreted to mean no limit. Currently this value is set to two hundred, which means that a five millisecond gap is neccessary between successive frames of animation, at least. This gap is imposed by the logic in this class.
        See Also:
        Constant Field Values
    • Constructor Detail

      • CanvasAWTAdapter

        public CanvasAWTAdapter​(java.awt.Component target,
                                boolean strictThreadControl)
        The java.awt.Component that is passed to the constructors is interacted with by the code in this class with only three calls to it: (1) Component.createImage(int,int), (2) Component.createImage(java.awt.image.ImageProducer), and (3) Component.repaint(). To that extent the Component is expected to behave as documented by the Java specification, also in regards to its current state. In a sense this Component can be considered to be a "peer".

        However, the Component is expected to keep its end of the bargain, which is the requirement to call CanvasAWTAdapter.update(Graphics) whenever Component.update(Graphics) is invoked by the system.

        The public access to this class and its constructors is left intact, even though in practice a programmer will rarely find the need to access this class directly, unless it is desired to embed an AbstractCanvas (or one of its derivatives) inside of a larger application while using the native Java widget hierarchy. In most cases a programmer will choose to use either FrameAWTStub or AppletAWTStub, both of which hide the implementation/usage details of CanvasAWTAdapter and BoardAWTAdapter.

        See Also:
        FrameAWTStub, BoardAWTAdapter
      • CanvasAWTAdapter

        public CanvasAWTAdapter​(java.awt.Component target,
                                boolean strictThreadControl,
                                int maxFramesPerSecond)
        Parameters:
        maxFramesPerSecond - maximum frames per second; a value of zero or a negative value is interpreted to mean no FPS limit.
        See Also:
        CanvasAWTAdapter(Component,boolean)
    • Method Detail

      • setUpdatable

        public void setUpdatable​(VisiblyUpdatable updatable)
        Should be regarded as part of the construction of an instance. Call this only once, and right after the constructor, before any other methods are called. The reason why this updatable does not get passed in as a constructor parameter is because the constructor of the updatable object, in practice, oftentimes takes this CanvasAWTStub as one of its constructor parameters.
      • destroy

        public void destroy()
        The component using this adapter should call destroy() when the adapter is no longer needed. This will free up any threads that are waiting in requestUpdate().
        Specified by:
        destroy in interface Destroyable
      • produceImage

        public java.awt.Image produceImage​(int width,
                                           int height)
        Description copied from interface: CanvasAWTStub
        Images are useful for doing double buffering. The returned image can be rendered and it can be drawn into by way of getGraphics().
        Specified by:
        produceImage in interface CanvasAWTStub
      • produceImage

        public java.awt.Image produceImage​(java.awt.image.ImageProducer prod)
        Description copied from interface: CanvasAWTStub
        getGraphics() on the returned image will fail; in other words the returned image is good for rendering and not so good for drawing onto.
        Specified by:
        produceImage in interface CanvasAWTStub
      • requestUpdate

        public void requestUpdate()
        Description copied from interface: CanvasAWTStub
        This method triggers a call to update(Graphics) on a corresponding AbstractCanvas. This method blocks until the update() method finishes. By agreement, this method shall only be called by a corresponding AbstractCanvas, and only by the thread invoking AbstractCanvas.run().
        Specified by:
        requestUpdate in interface CanvasAWTStub
      • update

        public java.awt.Rectangle update​(java.awt.Graphics g)
        This should be called directly from update(Graphics) of the java.awt.Component using this adapter. Calls to this method are always expected to be in the same thread: the JVM's event thread.