Class ShellFactory


public final class ShellFactory extends AbstractCompositeFactory<ShellFactory,Shell>
This class provides a convenient shorthand for creating and initializing Shell. This offers several benefits over creating Shell normal way:
  • The same factory can be used many times to create several Shell instances
  • The setters on ShellFactory all return "this", allowing them to be chained
Example usage:
 Shell shell = ShellFactory.newShell(SWT.BORDER) //
                .text("My Shell") //
                .maximized(true) //
                .create(parent);
 

The above example creates a maximized shell with a text and creates the shell in "parent". Where "parent" has to be another shell.

 GridDataFactory gridDataFactory = GridDataFactory.swtDefaults();
 ShellFactory shellFactory = ShellFactory.newShell(SWT.PUSH).layout(gridDataFactory::create);
 shellFactory.text("Shell 1").create(parent);
 shellFactory.text("Shell 2").create(parent);
 shellFactory.text("Shell 3").create(parent);
 

The above example creates three shells using the same instance of ShellFactory. Note the layout method. A Supplier is used to create unique GridData for every single shell.

Since:
3.21
  • Method Details

    • create

      public final Shell create(Display display)
      Creates the shell in the given display.
      Returns:
      the created shell
      Since:
      3.28
    • newShell

      public static ShellFactory newShell(int style)
      Creates a new ShellFactory with the given style. Refer to Shell(Shell, int) for possible styles.
      Returns:
      a new ShellFactory instance
    • text

      public ShellFactory text(String text)
      Sets the receiver's text, which is the string that the window manager will typically display as the receiver's title, to the argument, which must not be null.

      Note: If control characters like '\n', '\t' etc. are used in the string, then the behavior is platform dependent.

      Returns:
      this
      See Also:
    • minimized

      public ShellFactory minimized(boolean minimized)
      Sets the minimized stated of the receiver. If the argument is true causes the receiver to switch to the minimized state, and if the argument is false and the receiver was previously minimized, causes the receiver to switch back to either the maximized or normal states.

      Note: The result of intermixing calls to setMaximized(true) and setMinimized(true) will vary by platform. Typically, the behavior will match the platform user's expectations, but not always. This should be avoided if possible.

      Parameters:
      minimized - the new minimized state
      Returns:
      this
      See Also:
    • maximized

      public ShellFactory maximized(boolean maximized)
      Sets the maximized state of the receiver. If the argument is true causes the receiver to switch to the maximized state, and if the argument is false and the receiver was previously maximized, causes the receiver to switch back to either the minimized or normal states.

      Note: The result of intermixing calls to setMaximized(true) and setMinimized(true) will vary by platform. Typically, the behavior will match the platform user's expectations, but not always. This should be avoided if possible.

      Parameters:
      maximized - the new maximized state
      Returns:
      this
      See Also:
    • fullScreen

      public ShellFactory fullScreen(boolean fullScreen)
      Sets the full screen state of the receiver. If the argument is true causes the receiver to switch to the full screen state, and if the argument is false and the receiver was previously switched into full screen state, causes the receiver to switch back to either the maximized or normal states.

      Note: The result of intermixing calls to setFullScreen(true), setMaximized(true) and setMinimized(true) will vary by platform. Typically, the behavior will match the platform user's expectations, but not always. This should be avoided if possible.

      Parameters:
      fullScreen - the new fullscreen state
      Returns:
      this
      See Also:
    • onActivate

      public ShellFactory onActivate(Consumer<ShellEvent> consumer)
      Creates a ShellListener and registers it for the activated event. If event is raised it calls the given consumer. The ShellEvent is passed to the consumer.
      Parameters:
      consumer - the consumer whose accept method is called
      Returns:
      this
      See Also:
    • onDeactivate

      public ShellFactory onDeactivate(Consumer<ShellEvent> consumer)
      Creates a ShellListener and registers it for the deactivated event. If event is raised it calls the given consumer. The ShellEvent is passed to the consumer.
      Parameters:
      consumer - the consumer whose accept method is called
      Returns:
      this
      See Also:
    • onIconify

      public ShellFactory onIconify(Consumer<ShellEvent> consumer)
      Creates a ShellListener and registers it for the iconified (minimized) event. If event is raised it calls the given consumer. The ShellEvent is passed to the consumer.
      Parameters:
      consumer - the consumer whose accept method is called
      Returns:
      this
      See Also:
    • onDeiconify

      public ShellFactory onDeiconify(Consumer<ShellEvent> consumer)
      Creates a ShellListener and registers it for the deiconified (un-minimized) event. If event is raised it calls the given consumer. The ShellEvent is passed to the consumer.
      Parameters:
      consumer - the consumer whose accept method is called
      Returns:
      this
      See Also:
    • onClose

      public ShellFactory onClose(Consumer<ShellEvent> consumer)
      Creates a ShellListener and registers it for the closed event. If event is raised it calls the given consumer. The ShellEvent is passed to the consumer.
      Parameters:
      consumer - the consumer whose accept method is called
      Returns:
      this
      See Also: