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