Package com.diffplug.common.swt
Class Shells
- java.lang.Object
-
- com.diffplug.common.swt.Shells
-
public class Shells extends java.lang.Object
A fluent builder for creating SWTShell
s.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description 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).static Shells
builder(int style, com.diffplug.common.swt.Coat coat)
Creates a new Shells for this Coat.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.Shells
dontSetPositionOrSize()
Prevents setting any size or position.Shell
openOn(Shell parent)
Opens the shell on this parent shell.Shell
openOnActive()
Opens the shell on the currently active shell.void
openOnActiveBlocking()
Opens the shell on the currently active shell and blocks.void
openOnAndBlock(Shell parent)
Deprecated.foropenOnBlocking(Shell)
- same behavior, but name is consistent with the others.void
openOnBlocking(Shell parent)
Opens the shell on this parent and blocks.Shell
openOnDisplay()
Opens the shell as a root shell.void
openOnDisplayBlocking()
Opens the shell as a root shell and blocks.Shells
setAlpha(int alpha)
Sets the alpha for this Shell.Shells
setBounds(ControlWrapper wrapper)
CallssetBounds(Rectangle)
to match this control.Shells
setBounds(Rectangle bounds)
Sets the full bounds for this shell.Shells
setBounds(Control control)
CallssetBounds(Rectangle)
to match this control.Shells
setCloseOnEscape(boolean closeOnEscape)
Determines whether the shell will close on escape, defaults to false.Shells
setDontOpen(boolean dontOpen)
If true, the "openOn" methods will create the shell but not actually open them.Shells
setImage(Image image)
Sets the title image for this Shell.Shells
setLocation(Corner corner, Point position)
Sets the absolute location of the the given corner of this shell.Shells
setLocation(Point openPosition)
Sets the absolute location of the top-left of this shell.Shells
setPositionIncludesTrim(boolean positionIncludesTrim)
If true, size and location will set the the "outside" of the Shell - including the trim.Shells
setRectangle(Rectangle rect)
CallssetLocation(Point)
andsetSize(Point)
in one line.Shells
setSize(int x, int y)
Shells
setSize(Point size)
Sets the size for this Shell.Shells
setTitle(java.lang.String title)
Sets the title for this Shell.
-
-
-
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.
-
setAlpha
public Shells setAlpha(int alpha)
Sets the alpha for this Shell.
-
setBounds
public Shells setBounds(Rectangle bounds)
Sets the full bounds for this shell. Delegates tosetRectangle(Rectangle)
and {@link #setPositionIncludesTrim(true)}.
-
setBounds
public Shells setBounds(Control control)
CallssetBounds(Rectangle)
to match this control.
-
setBounds
public Shells setBounds(ControlWrapper wrapper)
CallssetBounds(Rectangle)
to match this control.
-
setRectangle
public Shells setRectangle(Rectangle rect)
CallssetLocation(Point)
andsetSize(Point)
in one line.
-
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
-
setSize
public Shells setSize(int x, int y)
- See Also:
setSize(Point)
-
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.
-
openOnAndBlock
@Deprecated public void openOnAndBlock(Shell parent)
Deprecated.foropenOnBlocking(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.
-
-