Package panamagl.canvas
Class PixelScaleSupportAWT
java.lang.Object
panamagl.canvas.PixelScaleSupportAWT
Shared HiDPI plumbing for AWT and Swing canvases.
Reads the current pixel scale via
GraphicsConfiguration.getDefaultTransform() (Java 9+) and notifies registered
PixelScaleListeners when it changes. Three signals trigger a re-check:
"graphicsConfiguration"property change — fired when the component is moved between monitors of different DPI;HierarchyEvent.DISPLAYABILITY_CHANGED— captures the initial value once the component is attached to a peer;- polling on a background thread (default 200 ms) — fallback for cases where neither of the above fires (some JVMs, mixed-DPI setups).
Listeners always run on the EDT.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longDefault polling interval in milliseconds. -
Constructor Summary
ConstructorsConstructorDescriptionPixelScaleSupportAWT(Component component) PixelScaleSupportAWT(Component component, boolean pollingEnabled, long pollIntervalMs) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(panamagl.canvas.PixelScaleListener l) panamagl.canvas.PixelScalecurrent()Last value reported to listeners.longbooleanpanamagl.canvas.PixelScaleread()Read the current pixel scale from the component'sGraphicsConfiguration.voidremoveListener(panamagl.canvas.PixelScaleListener l) voidsetPollingEnabled(boolean pollingEnabled) Enable or disable the polling fallback at runtime.voidsetPollIntervalMs(long pollIntervalMs) voidstart()Install all listeners and start the polling thread (if enabled).voidstop()Remove listeners and stop polling.
-
Field Details
-
DEFAULT_POLL_INTERVAL_MS
public static final long DEFAULT_POLL_INTERVAL_MSDefault polling interval in milliseconds. Polling is enabled by default to cover platforms or JVMs where AWT does not publishgraphicsConfigurationproperty change events consistently.- See Also:
-
-
Constructor Details
-
PixelScaleSupportAWT
-
PixelScaleSupportAWT
-
-
Method Details
-
read
public panamagl.canvas.PixelScale read()Read the current pixel scale from the component'sGraphicsConfiguration. Returns the last known value if the component is not yet displayable. -
current
public panamagl.canvas.PixelScale current()Last value reported to listeners. Updated only on the EDT. -
start
public void start()Install all listeners and start the polling thread (if enabled). Idempotent — calling twice has no effect. -
stop
public void stop()Remove listeners and stop polling. Idempotent. -
addListener
public void addListener(panamagl.canvas.PixelScaleListener l) -
removeListener
public void removeListener(panamagl.canvas.PixelScaleListener l) -
isPollingEnabled
public boolean isPollingEnabled() -
setPollingEnabled
-
getPollIntervalMs
public long getPollIntervalMs() -
setPollIntervalMs
public void setPollIntervalMs(long pollIntervalMs)
-