Class SWindow

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.dialog.Dialog
com.vaadin.swingbridge.surrogates.SWindow
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasAriaRole, com.vaadin.flow.component.HasComponents, com.vaadin.flow.component.HasComponentsOfType<com.vaadin.flow.component.Component>, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasTheme, com.vaadin.flow.component.shared.HasThemeVariant<com.vaadin.flow.component.dialog.DialogVariant>, ComponentMixin, ContainerMixin, JComponentMixin, Serializable
Direct Known Subclasses:
SFrame, SJInternalFrame, SJWindow

@StyleSheet("emul/swindow.css") public class SWindow extends com.vaadin.flow.component.dialog.Dialog implements JComponentMixin
Surrogate for Window: the Window-level listener surface (WindowListener / WindowFocusListener / WindowStateListener) plus the stateless / WARN-on-meaningful-change accessors that AWT defines on Window without requiring per-instance state. Concrete subclasses (SFrame, future SJDialog) — both Dialog-backed — layer Frame / Dialog state on top.

Split with subclasses

  • SWindow carries: listener-family registration + fire helpers, id → process-method routing, stateless Window-level accessors whose value can be answered without instance fields (isFocusableWindow, getWarningString, isAlwaysOnTopSupported, isAutoRequestFocus, toFront / toBack no-ops, pack no-op, empty focus-traversal-keys, empty icon-images).
  • Subclasses carry: anything that stores state (visible shadow, owner / ownedWindows, defaultCloseOperation, title, contentPane), peer-subscription (OpenedChangeListener mirroring for setVisible / dispose), and the setVisible / dispose paths that invoke the fire helpers here.

Window listener families don't funnel through Registrations because Vaadin 25 surfaces no server-side counterpart for WINDOW_ACTIVATED / WINDOW_ICONIFIED / etc. — they're server-side-fire-only (SD_listeners_without_analog shape). Storage lives directly on this class via listenerList, a EventListenerList shared by the three families with type-keyed add/remove. Firing is driven by the subclass's lifecycle (setVisible, dispose, peer close) calling the fireWindowEvent family here.

Always-inert today: iconify / deiconify / activate / deactivate / state-changed / gained-focus / lost-focus. Ported for API parity and so migrated code compiles; no dispatch path drives them. Storage + removal still work so listener-list introspection is honest.

See Also:
  • Constructor Details

    • SWindow

      public SWindow()
      Untitled, no owner.
    • SWindow

      public SWindow(SWindow owner)
      With owner. Null owner is a top-level window. Subscribes to the Dialog peer's OpenedChangeEvent so user-initiated closes round-trip back into the visible shadow and fire WINDOW_CLOSING via processWindowEvent(SWindowEvent).
  • Method Details

    • addWindowListener

      public void addWindowListener(SWindowListener l)
      Register an SWindowListener. Storage only — firing is driven by the subclass's lifecycle (e.g. SFrame.setVisible fires SWindowEvent.WINDOW_OPENED through fireWindowEvent(int)). Null listener silently ignored, matching EventListenerList's contract.
    • removeWindowListener

      public void removeWindowListener(SWindowListener l)
      Remove a previously registered SWindowListener. No-op on unregistered.
    • getWindowListeners

      public SWindowListener[] getWindowListeners()
      Registered SWindowListeners in registration order. Empty array when none.
    • addWindowFocusListener

      public void addWindowFocusListener(SWindowFocusListener l)
    • removeWindowFocusListener

      public void removeWindowFocusListener(SWindowFocusListener l)
      Remove a previously registered SWindowFocusListener.
    • getWindowFocusListeners

      public SWindowFocusListener[] getWindowFocusListeners()
      Registered SWindowFocusListeners. Always empty in practice — no dispatch path today.
    • addWindowStateListener

      public void addWindowStateListener(SWindowStateListener l)
    • removeWindowStateListener

      public void removeWindowStateListener(SWindowStateListener l)
      Remove a previously registered SWindowStateListener.
    • getWindowStateListeners

      public SWindowStateListener[] getWindowStateListeners()
      Registered SWindowStateListeners. Always empty in practice — no state transitions.
    • fireWindowEvent

      public void fireWindowEvent(int id)
      Fire one of the non-focus, non-state ids (OPENED / CLOSING / CLOSED / ICONIFIED / DEICONIFIED / ACTIVATED / DEACTIVATED) through processWindowEvent(SWindowEvent). Skipped when no SWindowListener is registered.
    • fireWindowFocusEvent

      public void fireWindowFocusEvent(int id, com.vaadin.flow.component.Component opposite)
      Fire SWindowEvent.WINDOW_GAINED_FOCUS / SWindowEvent.WINDOW_LOST_FOCUS. opposite is always null today — browser focus transitions don't surface the opposite server-side.
    • fireWindowStateEvent

      public void fireWindowStateEvent(int oldState, int newState)
      Fire SWindowEvent.WINDOW_STATE_CHANGED. Never called today (no iconify / maximize in our Dialog-backed Window); preserved so a future slice that models window state can plug straight in.
    • processWindowEvent

      public void processWindowEvent(SWindowEvent e)
      Dispatch the non-focus, non-state ids to registered SWindowListeners. null guard matches ComponentMixin's process family — a smoke-test null probe shouldn't crash.
    • processWindowFocusEvent

      public void processWindowFocusEvent(SWindowEvent e)
      Dispatch WINDOW_GAINED_FOCUS / WINDOW_LOST_FOCUS to focus listeners.
    • processWindowStateEvent

      public void processWindowStateEvent(SWindowEvent e)
      Dispatch WINDOW_STATE_CHANGED to state listeners.
    • processEvent

      public void processEvent(AWTEvent e)
      Top-level AWT-event router. Only SWindowEvent ids dispatch here; every other event type falls through (non-Window events wouldn't have been passed in). Matches AWT's shape — Window.processEvent routes by id then delegates to the Container/Component chain for non-Window ids.
    • isFocusableWindow

      public boolean isFocusableWindow()
      JDK Frame/Dialog default is true. We don't model focus traversal (R_infra_not_surface) so the gate never rejects anyone — true is the honest "can this window take focus at all?" answer callers check.
    • getWarningString

      public String getWarningString()
      AWT's applet-sandbox banner. No SecurityManager runs in a Vaadin server, so we're always trusted — null is AWT's correct answer.
    • isAlwaysOnTopSupported

      public boolean isAlwaysOnTopSupported()
      We don't honor always-on-top (browsers have no window z-order).
    • isAutoRequestFocus

      public boolean isAutoRequestFocus()
    • isAlwaysOnTop

      public boolean isAlwaysOnTop()
      AWT default; setter WARNs on true.
    • isLocationByPlatform

      public boolean isLocationByPlatform()
      AWT default; setter WARNs on true.
    • getShape

      public Shape getShape()
      We can't render non-rectangular windows (DOM is rectangular).
    • getOpacity

      public float getOpacity()
      AWT default; we don't model transparency.
    • getFocusableWindowState

      public boolean getFocusableWindowState()
      AWT default; setter WARNs on false.
    • isValidateRoot

      public boolean isValidateRoot()
      Window is always a validate-root in AWT. Resolves the mixin diamond with JComponentMixin.isValidateRoot() (which returns false) — Window's contract wins because a Frame / Dialog IS-A Window, and migrated code that walks revalidate stops here.
      Specified by:
      isValidateRoot in interface JComponentMixin
    • isActive

      public boolean isActive()
      No OS window-manager concept — false is the honest default.
    • isFocused

      public boolean isFocused()
      Browser tab focus isn't tracked server-side.
    • getFocusOwner

      public com.vaadin.flow.component.Component getFocusOwner()
      Focus traversal isn't modeled (R_infra_not_surface).
    • getMostRecentFocusOwner

      public com.vaadin.flow.component.Component getMostRecentFocusOwner()
      Focus traversal isn't modeled (R_infra_not_surface).
    • isFocusCycleRoot

      public boolean isFocusCycleRoot()
      Window in AWT is always-true; we return false for parity with Container's silent-false default since no focus-cycle walker exists either way (R_infra_not_surface). Flip if focus modeling lands.
    • getFocusCycleRootAncestor

      public com.vaadin.flow.component.Component getFocusCycleRootAncestor()
      No parent Container above a Window.
    • getFocusTraversalKeys

      public Set<AWTKeyStroke> getFocusTraversalKeys(int id)
      Focus traversal isn't modeled (R_infra_not_surface).
    • getIconImages

      public List<Image> getIconImages()
      Icons aren't wired to the browser (favicons are route-level).
    • getInputContext

      public InputContext getInputContext()
      No IME subsystem; null matches AWT's pre-IM default.
    • setAlwaysOnTop

      public void setAlwaysOnTop(boolean b)
      WARN on true — no z-order in a browser tab. Silent on false (default).
    • setLocationByPlatform

      public void setLocationByPlatform(boolean b)
      WARN on true — browsers don't position tabs. Silent on false.
    • setShape

      public void setShape(Shape shape)
      WARN on non-null — non-rectangular shapes don't render.
    • setOpacity

      public void setOpacity(float opacity)
      WARN — transparency isn't modeled.
    • setFocusableWindowState

      public void setFocusableWindowState(boolean b)
      WARN on false — we have no focus subsystem to opt out of.
    • setAutoRequestFocus

      public void setAutoRequestFocus(boolean b)
      WARN on false — auto-focus behavior isn't modeled.
    • setFocusCycleRoot

      public void setFocusCycleRoot(boolean b)
      WARN on true — no cycle-root traversal machinery.
    • setIconImages

      public void setIconImages(List<? extends Image> icons)
      Silent accept — icons don't wire to the browser (favicons belong to the route, not a Window). Apps routinely set icons at startup; logging each call would swamp real warnings.
    • setIconImage

      public void setIconImage(Image icon)
      Convenience for setIconImages(List.of(icon)) — same silent-accept.
    • toFront

      public void toFront()
      Silent no-op — browsers auto-stack overlays; apps pair this with setVisible routinely.
    • toBack

      public void toBack()
      Silent no-op — no z-order in a browser tab.
    • pack

      public void pack()
      Silent no-op — the Dialog peer auto-sizes to content, and we have no pixel numbers to reconcile (R_layouts_close_enough). Apps call pack() routinely as a "finalise layout" gesture; WARN-per-call would swamp logs.
    • applyResourceBundle

      public void applyResourceBundle(ResourceBundle bundle)
      WARN — ResourceBundle-driven UI text isn't modeled.
    • applyResourceBundle

      public void applyResourceBundle(String baseName)
    • createBufferStrategy

      public void createBufferStrategy(int numBuffers)
      WARN — no BufferStrategy / offscreen-buffer pipeline.
    • createBufferStrategy

      public void createBufferStrategy(int numBuffers, BufferCapabilities caps) throws AWTException
      Throws:
      AWTException
    • getBufferStrategy

      public BufferStrategy getBufferStrategy()
      WARN — no BufferStrategy.
    • setLocation

      public void setLocation(int x, int y)
      Position the overlay's top-left corner at viewport pixel (x, y). Setting an explicit position takes the Dialog out of its default centered placement; centerOnScreen() restores it.
      Specified by:
      setLocation in interface ComponentMixin
    • setSize

      public void setSize(int width, int height)
      Pixel size for the overlay — Dialog's own width/height channel.
      Specified by:
      setSize in interface ComponentMixin
    • setBounds

      public void setBounds(int x, int y, int width, int height)
      Specified by:
      setBounds in interface ComponentMixin
    • centerOnScreen

      public void centerOnScreen()
      Clear any explicit setLocation(int, int) placement and return to the Dialog overlay's default centered position.
    • setUndecoratedChrome

      public void setUndecoratedChrome(boolean undecorated)
      Toggle the emul-undecorated overlay class: strips the Dialog's border radius, content padding, and header (title + SFrame's close-X chrome) so the window renders as a bare content rect — Swing's undecorated-window shape. The box-shadow stays: in a browser the window floats over live page content, not a desktop, and a shadowless rect there is illegible (documented R_layouts_close_enough divergence; see emul/swindow.css).

      Always on for SJWindow (javax.swing.JWindow is undecorated by definition); driven by setUndecorated on SFrame and the emulator-layer Frame / Dialog / JFrame.

    • isUndecoratedChrome

      public boolean isUndecoratedChrome()
      Vaadin-first read-back of setUndecoratedChrome(boolean).
    • setLocationRelativeTo

      public void setLocationRelativeTo(com.vaadin.flow.component.Component c)
      Re-center the window. AWT semantics: null centers on screen; a visible component argument centers over that component. We map both to viewport-centering (centerOnScreen()) — the browser has no screen geometry to compute a component-relative position from, and a centered overlay is the close-enough answer for the "center over my main window" idiom (the main window effectively IS the viewport). R_layouts_close_enough divergence, accepted.
    • setEnabled

      public void setEnabled(boolean enabled)
      Fires no "enabled" property change, unlike every other JComponentMixin implementor. The bound "enabled" property is JComponent's, and java.awt.Window — with Frame, JFrame, JDialog and JWindow under it — is not a JComponent; it inherits java.awt.Component.setEnabled, which fires nothing bound (SD_property_fanout_audit).

      This class takes JComponentMixin for its helper surface (border, tooltip, name), not because a window is a JComponent, so the mixin's JComponent-level property fan-out has to be suppressed here. One override covers SFrame, SJFrame, SJDialog and SJWindow by inheritance.

      Specified by:
      setEnabled in interface ComponentMixin
      Specified by:
      setEnabled in interface com.vaadin.flow.component.HasEnabled
      Specified by:
      setEnabled in interface JComponentMixin
    • fireOpenedEvent

      protected void fireOpenedEvent()
      First-show fire (WINDOW_OPENED), gated by everShown in setVisible(boolean).
    • fireClosingEvent

      protected void fireClosingEvent()
      User-close fire (WINDOW_CLOSING). Routed through processWindowEvent(SWindowEvent) directly (not fireWindowEvent(int)) so a close-op switch overridden by SJFrame / SJDialog applies even when no WindowListener is registered.
    • fireClosedEvent

      protected void fireClosedEvent()
      Dispose fire (WINDOW_CLOSED), from dispose().
    • addComponentListener

      public void addComponentListener(SComponentListener listener)
      Override of ComponentMixin.addComponentListener(SComponentListener) — the default wiring dispatches COMPONENT_SHOWN on peer attach / COMPONENT_HIDDEN on detach, which assumes attach ↔ visibility. That assumption doesn't hold for SWindow: the Dialog peer stays attached across setVisible(false) (only detaches on dispose()), so attach-driven fires misrepresent the show/hide transitions we care about. Instead we register with a no-op Vaadin-registration and drive the dispatch from setVisible(boolean) / onPeerOpenedChanged(boolean) / dispose() directly via fireComponentEvent(int).
      Specified by:
      addComponentListener in interface ComponentMixin
    • setVisible

      public void setVisible(boolean b)
      Mirror first, then drive the peer under preventPeerEvents. setVisible(true) attaches us at the point attachForShow(UI) picks (IllegalStateException when there is no current UI — a narrow D_never_fail_on_gaps carve-out for an environment we genuinely can't recover from). Refiring WINDOW_OPENED is gated on everShown, which dispose() resets so a dispose→show cycle fires again.
      Overrides:
      setVisible in class com.vaadin.flow.component.dialog.Dialog
    • dispose

      public void dispose()
      AWT: close the window, release the native peer, fire WINDOW_CLOSED, walk removeNotify. Our peer is this and can't be nulled — we achieve "non-displayable" by detaching from the UI. everShown resets so a subsequent setVisible(boolean) refires WINDOW_OPENED — AWT's dispose-then-show contract.

      The detach waits for the client's closed event when the browser is animating a close, so the overlay can hand focus back while its content is still in the DOM (SD_detach_after_closed). Until then the peer sits attached and closed, the state setVisible(false) leaves it in.

    • getOwner

      public SWindow getOwner()
    • getOwnedWindows

      public SWindow[] getOwnedWindows()
      Dereference each WeakReference, keep live ones, opportunistically drop cleared entries. Mirrors JDK Window.getOwnedWindows()'s weak-ref pruning. Logically independent of peer attachment state — an owner link persists whether the owned window is displayed or not.
    • getWindows

      public static List<SWindow> getWindows()
      Every SWindow reachable from the current UI. Walks the component tree for SWindow instances, then descends each SWindow's owned-tree so an attached owner pulls in its owned windows even when those aren't individually opened.
    • getOwnerlessWindows

      public static List<SWindow> getOwnerlessWindows()
      Subset of getWindows() with owner == null.
    • paramString

      public String paramString()
      Diagnostic — mirrors the shape of java.awt.Window.paramString(). Subclasses (SFrame) override and chain super to add Frame-/Dialog-specific fields like title.