View Javadoc
1   package nl.tudelft.simulation.dsol.web.animation;
2   
3   import java.awt.Font;
4   import java.awt.Graphics2D;
5   import java.awt.GraphicsDevice;
6   import java.awt.GraphicsEnvironment;
7   import java.awt.HeadlessException;
8   import java.awt.image.BufferedImage;
9   import java.util.Locale;
10  
11  import org.djutils.logger.CategoryLogger;
12  
13  import nl.tudelft.simulation.dsol.logger.Cat;
14  
15  /**
16   * HTMLGraphicsEnvironment.java.
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 HtmlGraphicsEnvironment extends GraphicsEnvironment
24  {
25      /** the (dummy) device to use in the graphics environment. */
26      HtmlDevice htmlDevice;
27  
28      /** the canvas to draw on. */
29      HtmlGraphics2d graphics2D;
30  
31      /** the (dummy) configuration to use. */
32      HtmlGraphicsConfiguration graphicsConfiguration;
33  
34      /**
35       * 
36       */
37      public HtmlGraphicsEnvironment()
38      {
39          CategoryLogger.filter(Cat.WEB).trace("HTMLGraphicsEnvironment.<init>");
40          this.graphics2D = new HtmlGraphics2d();
41          this.graphicsConfiguration = new HtmlGraphicsConfiguration();
42          this.htmlDevice = new HtmlDevice(this.graphicsConfiguration);
43          this.graphicsConfiguration.setDevice(this.htmlDevice);
44      }
45  
46      /** {@inheritDoc} */
47      @Override
48      public GraphicsDevice[] getScreenDevices() throws HeadlessException
49      {
50          CategoryLogger.filter(Cat.WEB).trace("HTMLGraphicsEnvironment.getScreenDevices()");
51          return new GraphicsDevice[] {this.htmlDevice};
52      }
53  
54      /** {@inheritDoc} */
55      @Override
56      public GraphicsDevice getDefaultScreenDevice() throws HeadlessException
57      {
58          CategoryLogger.filter(Cat.WEB).trace("HTMLGraphicsEnvironment.getDefaultScreenDevice()");
59          return this.htmlDevice;
60      }
61  
62      /** {@inheritDoc} */
63      @Override
64      public Graphics2D createGraphics(BufferedImage img)
65      {
66          CategoryLogger.filter(Cat.WEB).trace("HTMLGraphicsEnvironment.createGraphics()");
67          return this.graphics2D;
68      }
69  
70      /** {@inheritDoc} */
71      @Override
72      public Font[] getAllFonts()
73      {
74          CategoryLogger.filter(Cat.WEB).trace("HTMLGraphicsEnvironment.getAllFonts()");
75          return new Font[] {};
76      }
77  
78      /** {@inheritDoc} */
79      @Override
80      public String[] getAvailableFontFamilyNames()
81      {
82          CategoryLogger.filter(Cat.WEB).trace("HTMLGraphicsEnvironment.getAvailableFontFamilyNames()");
83          return new String[] {};
84      }
85  
86      /** {@inheritDoc} */
87      @Override
88      public String[] getAvailableFontFamilyNames(Locale l)
89      {
90          CategoryLogger.filter(Cat.WEB).trace("HTMLGraphicsEnvironment.getAvailableFontFamilyNames()");
91          return new String[] {};
92      }
93  
94  }