This class exists as an abstraction layer to remove AWT from PApplet. It is a staging area for AWT-specific code that's shared by the Java2D, JavaFX, and JOGL renderers. Once PSurfaceFX and PSurfaceJOGL have their own implementations, these methods will move to PSurfaceAWT.
| 38 | * their own implementations, these methods will move to PSurfaceAWT. |
| 39 | */ |
| 40 | public class ShimAWT implements PConstants { |
| 41 | /* |
| 42 | PGraphics graphics; |
| 43 | PApplet sketch; |
| 44 | |
| 45 | |
| 46 | public ShimAWT(PApplet sketch) { |
| 47 | this.graphics = graphics; |
| 48 | this.sketch = sketch; |
| 49 | } |
| 50 | */ |
| 51 | static private ShimAWT instance; |
| 52 | |
| 53 | final private GraphicsDevice[] displayDevices; |
| 54 | |
| 55 | final private int displayWidth; |
| 56 | final private int displayHeight; |
| 57 | |
| 58 | |
| 59 | /** Only needed for display functions */ |
| 60 | static private ShimAWT getInstance() { |
| 61 | if (instance == null) { |
| 62 | instance = new ShimAWT(); |
| 63 | } |
| 64 | return instance; |
| 65 | } |
| 66 | |
| 67 | |
| 68 | private ShimAWT() { |
| 69 | // Need the list of display devices to be queried already for usage below. |
| 70 | // https://github.com/processing/processing/issues/3295 |
| 71 | // https://github.com/processing/processing/issues/3296 |
| 72 | // Not doing this from a static initializer because it may cause |
| 73 | // PApplet to cache and the values to stick through subsequent runs. |
| 74 | // Instead make it a runtime thing and a local variable. |
| 75 | GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); |
| 76 | GraphicsDevice device = ge.getDefaultScreenDevice(); |
| 77 | displayDevices = ge.getScreenDevices(); |
| 78 | |
| 79 | // // Default or unparsed will be -1, spanning will be 0, actual displays will |
| 80 | // // be numbered from 1 because it's too weird to say "display 0" in prefs. |
| 81 | // if (display > 0 && display <= displayDevices.length) { |
| 82 | // device = displayDevices[display-1]; |
| 83 | // } |
| 84 | // When this was called, display will always be unset (even in 3.x), |
| 85 | // since this happens before settings() is called. |
| 86 | |
| 87 | // Set displayWidth and displayHeight for people still using those. |
| 88 | DisplayMode displayMode = device.getDisplayMode(); |
| 89 | displayWidth = displayMode.getWidth(); |
| 90 | displayHeight = displayMode.getHeight(); |
| 91 | } |
| 92 | |
| 93 | |
| 94 | static public int getDisplayWidth() { |
| 95 | return getInstance().displayWidth; |
| 96 | } |
| 97 |
nothing calls this directly
no outgoing calls
no test coverage detected