View Javadoc
1   package org.opentrafficsim.web.animation;
2   
3   import java.awt.GraphicsConfiguration;
4   import java.awt.GraphicsDevice;
5   import java.awt.Rectangle;
6   import java.awt.geom.AffineTransform;
7   import java.awt.image.ColorModel;
8   
9   import org.opentrafficsim.base.logger.Logger;
10  
11  /**
12   * The <code>HTMLGraphicsConfiguration</code> class describes the characteristics of the HTML canvas in the browser, as a
13   * graphics destination to write to. Note that there can be several <code>GraphicsConfiguration</code> objects associated with a
14   * single graphics device, representing different drawing modes or capabilities.
15   * <p>
16   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
17   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
18   * </p>
19   * @author <a href="https://github.com/averbraeck" target="_blank">Alexander Verbraeck</a>
20   */
21  public class HtmlGraphicsConfiguration extends GraphicsConfiguration
22  {
23      /** the {@link HtmlDevice} associated with this <code>HTMLGraphicsConfiguration</code>. */
24      HtmlDevice htmlDevice;
25  
26      /** the identity AffineTransform. */
27      AffineTransform identityTransform = new AffineTransform();
28  
29      /** the bounds, TODO: which should be filled in some way by the window size in the browser. */
30      Rectangle bounds = new Rectangle(0, 0, 1920, 1080);
31  
32      /**
33       * Create a graphics configuration for the HTML device.
34       */
35      public HtmlGraphicsConfiguration()
36      {
37          Logger.ots().trace("HTMLGraphicsConfiguration.<init>");
38      }
39  
40      @Override
41      public GraphicsDevice getDevice()
42      {
43          Logger.ots().trace("HTMLGraphicsConfiguration.getDevice()");
44          return this.htmlDevice;
45      }
46  
47      /**
48       * Set the {@link HtmlDevice} associated with this <code>HTMLGraphicsConfiguration</code>.
49       * @param htmlDevice a &lt;code&gt;GraphicsDevice&lt;/code&gt; object that is associated with this
50       *            <code>HTMLGraphicsConfiguration</code>.
51       */
52      public void setDevice(final HtmlDevice htmlDevice)
53      {
54          Logger.ots().trace("HTMLGraphicsConfiguration.setDevice()");
55          this.htmlDevice = htmlDevice;
56      }
57  
58      @Override
59      public ColorModel getColorModel()
60      {
61          Logger.ots().trace("HTMLGraphicsConfiguration.getColorModel()");
62          return ColorModel.getRGBdefault();
63      }
64  
65      @Override
66      public ColorModel getColorModel(final int transparency)
67      {
68          Logger.ots().trace("HTMLGraphicsConfiguration.getColorModel()");
69          return ColorModel.getRGBdefault();
70      }
71  
72      @Override
73      public AffineTransform getDefaultTransform()
74      {
75          Logger.ots().trace("HTMLGraphicsConfiguration.getDefaultTransform()");
76          return this.identityTransform;
77      }
78  
79      @Override
80      public AffineTransform getNormalizingTransform()
81      {
82          Logger.ots().trace("HTMLGraphicsConfiguration.getNormalizingTransform()");
83          return this.identityTransform;
84      }
85  
86      @Override
87      public Rectangle getBounds()
88      {
89          Logger.ots().trace("HTMLGraphicsConfiguration.getBounds()");
90          return this.bounds;
91      }
92  
93  }