Class Shells


  • public class Shells
    extends java.lang.Object
    A fluent builder for creating SWT Shells.
    • Method Detail

      • builder

        public static Shells builder​(int style,
                                     com.diffplug.common.swt.Coat coat)
        Creates a new Shells for this Coat.
      • setTitle

        public Shells setTitle​(java.lang.String title)
        Sets the title for this Shell.
      • setImage

        public Shells setImage​(Image image)
        Sets the title image for this Shell.
      • setAlpha

        public Shells setAlpha​(int alpha)
        Sets the alpha for this Shell.
      • setSize

        public Shells setSize​(@Nullable
                              Point size)
        Sets the size for this Shell.
        • If `size` is null, or both components are `<= 0`, the shell will be packed as tightly as possible.
        • If both components are `> 0`, the shell will be set to that size.
        • If one component is `<= 0`, the positive dimension will be constrained and the other dimension will be packed as tightly as possible.
        Throws:
        java.lang.IllegalArgumentException - if size is non-null and both components are negative
      • setLocation

        public Shells setLocation​(Point openPosition)
        Sets the absolute location of the top-left of this shell. If the value is null, the shell will open:
        • if there is a parent shell, below and to the right of the parent
        • if there isn't a parent shell, at the current cursor position
      • setLocation

        public Shells setLocation​(Corner corner,
                                  Point position)
        Sets the absolute location of the the given corner of this shell. If the value is null, the shell will open:
        • if there is a parent shell, below and to the right of the parent
        • if there isn't a parent shell, at the current cursor position
      • setPositionIncludesTrim

        public Shells setPositionIncludesTrim​(boolean positionIncludesTrim)
        If true, size and location will set the the "outside" of the Shell - including the trim. If false, it will set the "inside" of the Shell - not including the trim. Default value is true.
      • setDontOpen

        public Shells setDontOpen​(boolean dontOpen)
        If true, the "openOn" methods will create the shell but not actually open them. This is rare and a little awkward, might get changed someday: https://github.com/diffplug/durian-swt/issues/4
      • setCloseOnEscape

        public Shells setCloseOnEscape​(boolean closeOnEscape)
        Determines whether the shell will close on escape, defaults to false.
      • openOn

        public Shell openOn​(Shell parent)
        Opens the shell on this parent shell.
      • openOnAndBlock

        @Deprecated
        public void openOnAndBlock​(Shell parent)
        Deprecated.
        for openOnBlocking(Shell) - same behavior, but name is consistent with the others.
      • openOnBlocking

        public void openOnBlocking​(Shell parent)
        Opens the shell on this parent and blocks.
      • active

        public static Shell active()
        Returns the active shell using the following logic: - the active shell needs to be visible, and it can't be a temporary pop-up (it needs to have a toolbar) - if it's invisible or temporary, we trust its top-left position as the "user position" - if there's no shell at all, we use the mouse cursor as the "user position" - we iterate over every shell, and find the ones that are underneath the "user position" - of the candidate shells, we return the one which is nested the deepest on Windows and OS X, the active shell is the one that currently has user focus on Linux, the last created shell (even if it is invisible) will count as the active shell This is a problem because some things create a fake hidden shell to act as a parent for other operations (specifically our right-click infrastructure). This means that on linux, the user right-clicks, a fake shell is created to show a menu, the selected action opens a new shell which uses "openOnActive", then the menu closes and disposes its fake shell, which promptly closes the newly created shell. as a workaround, if an active shell is found, but it isn't visible, we count that as though there isn't an active shell we have a similar workaround for no-trim ON_TOP shells, which are commonly used for context-sensitive popups which may close soon after
      • openOnActive

        public Shell openOnActive()
        Opens the shell on the currently active shell.
      • dontSetPositionOrSize

        public Shells dontSetPositionOrSize()
        Prevents setting any size or position. Does not prevent changing the location and size to ensure that the shell is on-screen.
      • openOnActiveBlocking

        public void openOnActiveBlocking()
        Opens the shell on the currently active shell and blocks.
      • openOnDisplay

        public Shell openOnDisplay()
        Opens the shell as a root shell.
      • openOnDisplayBlocking

        public void openOnDisplayBlocking()
        Opens the shell as a root shell and blocks.
      • confirmClose

        public static Disposable confirmClose​(Shell shell,
                                              java.lang.String title,
                                              java.lang.String question,
                                              java.lang.Runnable runOnClose)
        Prevents the given shell from closing without prompting. Returns a Subscription which can cancel this blocking.