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      @Override
47      public GraphicsDevice[] getScreenDevices() throws HeadlessException
48      {
49          CategoryLogger.filter(Cat.WEB).trace("HTMLGraphicsEnvironment.getScreenDevices()");
50          return new GraphicsDevice[] {this.htmlDevice};
51      }
52  
53      @Override
54      public GraphicsDevice getDefaultScreenDevice() throws HeadlessException
55      {
56          CategoryLogger.filter(Cat.WEB).trace("HTMLGraphicsEnvironment.getDefaultScreenDevice()");
57          return this.htmlDevice;
58      }
59  
60      @Override
61      public Graphics2D createGraphics(BufferedImage img)
62      {
63          CategoryLogger.filter(Cat.WEB).trace("HTMLGraphicsEnvironment.createGraphics()");
64          return this.graphics2D;
65      }
66  
67      @Override
68      public Font[] getAllFonts()
69      {
70          CategoryLogger.filter(Cat.WEB).trace("HTMLGraphicsEnvironment.getAllFonts()");
71          return new Font[] {};
72      }
73  
74      @Override
75      public String[] getAvailableFontFamilyNames()
76      {
77          CategoryLogger.filter(Cat.WEB).trace("HTMLGraphicsEnvironment.getAvailableFontFamilyNames()");
78          return new String[] {};
79      }
80  
81      @Override
82      public String[] getAvailableFontFamilyNames(Locale l)
83      {
84          CategoryLogger.filter(Cat.WEB).trace("HTMLGraphicsEnvironment.getAvailableFontFamilyNames()");
85          return new String[] {};
86      }
87  
88  }