Module org.autogui

Class AutoGuiShell

java.lang.Object
org.autogui.swing.AutoGuiShell

public class AutoGuiShell extends Object
a launcher of automatic GUI binding.
     @GuiIncluded
     public class MyApp {
         public static void main(String[] args) {
             AutoGuiShell.get().showWindow(new MyApp());
         }

         @GuiIncluded public String input;
         @GuiIncluded public void action() {
             System.out.println("hello " + input);
         }
     }
 

for jshell: the static method showLive(Object) relaxes accessibility and annotations

     jshell> /env -class-path target/autogui-1.0-SNAPSHOT.jar
     jshell> class Hello {
        ...>   String value;
        ...>   void action() {
        ...>     System.out.println(value);
        ...>   }
        ...> }
     jshell> import org.autogui.swing.*
     jshell> AutoGuiShell.showLive(new Hello())
 

Setting Look and Feel

configured by the field lookAndFeelClass which can be set by the following withLookAndFeel... methods. The default value is #prop:autogui.laf.

In setLookAndFeel(), the lookAndFeelClass will be passed to UIManagerUtil.setLookAndFeel(String).

For example, the JVM option -Dautogui.laf=metal with the default configuration resets the property by the concrete MetalLookAndFeel class-name and sets to metal-laf thanks to UIManagerUtil.setLookAndFeel(String).

  • Field Details

  • Constructor Details

    • AutoGuiShell

      public AutoGuiShell()
  • Method Details

    • get

      public static AutoGuiShell get()
      Returns:
      a new instance
    • showWindow

      public void showWindow(Object o)
      create a window for the object o as the application root and display it. before creating the window, it sets LookAndFeel as the value of lookAndFeelClass by setLookAndFeel().

      The method is equivalent to the following code:

        SwingUtilities.invokeLater(() -> {
            setLookAndFeel();
            createWindow(o, true).setVisible(true);
        });
        
      Parameters:
      o - the target object
    • withCrossPlatformLookAndFeel

      public AutoGuiShell withCrossPlatformLookAndFeel()
    • withLookAndFeelClass

      public AutoGuiShell withLookAndFeelClass(String lookAndFeelClass)
      Parameters:
      lookAndFeelClass - the LAF class name or a special name which can be acceptable by UIManagerUtil.setLookAndFeel(String)
      Returns:
      this
      Since:
      1.2
    • withLookAndFeelClassFromFunction

      public AutoGuiShell withLookAndFeelClassFromFunction(Function<AutoGuiShell,String> init)
      Parameters:
      init - the user init process for installing LAF by custom mechanism with receiving this. the returned string will be passed to withLookAndFeelClass(String)
      Returns:
      this
      Since:
      1.2
    • withLookAndFeelProperty

      public AutoGuiShell withLookAndFeelProperty(String p)
      Parameters:
      p - a system property, like "autogui.laf".
      Returns:
      this with setting "#prop:p"
      Since:
      1.3
    • withLookAndFeelSpecial

      public AutoGuiShell withLookAndFeelSpecial(String v)
      Parameters:
      v - a special name can be passed to UIManagerUtil.selectLookAndFeelFromSpecialName(String)
      Returns:
      this with setting "#special:v"
      Since:
      1.4
    • withLookAndFeelNone

      public AutoGuiShell withLookAndFeelNone()
      turning off the feature of the setting look-and-feel from some property
      Returns:
      this with setting "#none"
      Since:
      1.3
    • setLookAndFeel

      public void setLookAndFeel()
      set the look-and-feel of UIManager from lookAndFeelClass. the field specifies the class name of LookAndFeel. if the value of the field is "#system" then, it uses system-look-and-feel.
    • withPrefsValuesLoadSkip

      public AutoGuiShell withPrefsValuesLoadSkip()
      skip loading default properties of object from saved default prefs. The method is useful when the target object's properties are already set: e.g.
           GuiPreferencesLoader.get().parseArgs(obj, args); //control loading prefs by args
           AutoGuiShell.get()
               .withPrefsValuesLoadSkip() //skip loading prefs
               .showWindow(obj);
       
      Returns:
      this
      Since:
      1.4
    • withPrefsValuesLoadArgs

      public AutoGuiShell withPrefsValuesLoadArgs(String... args)
      Parameters:
      args - the command args
      Returns:
      this
      Since:
      1.4
    • showWindow

      public void showWindow(Object o, Runnable beforeActionInEvent)
      shorthand for showWindow(o, beforeActionInEvent, null)
      Parameters:
      o - the target object
      beforeActionInEvent - action executed before creating the window
      See Also:
    • showWindow

      public void showWindow(Object o, Runnable beforeActionInEvent, Consumer<GuiSwingWindow> afterActionInEvent)
      create a window for the object o as the application root and display it. The method runs 1) beforeActionInEvent, and 2) createWindow(Object, boolean, Consumer) with (o,true,afterActionInEvent) and showing the returned window. The steps are executed under SwingUtilities.invokeLater(Runnable).
      Parameters:
      o - the target object
      beforeActionInEvent - action executed before creating the window within the event dispatching thread. nullable
      afterActionInEvent - action executed after creating the window within the event dispatching thread. nullable
      Since:
      1.1
    • createWindow

      public GuiSwingWindow createWindow(Object o, boolean appRoot)
      if the current thread is the event dispatching thread, it will immediately create a window for o and return it. otherwise, it invoke the same task to the event dispatching thread and waits it. It is shorthand for createWindow(o, appRoot, null)
      Parameters:
      o - the target object
      appRoot - if true, the returned window will clean-up windows and task-runners at closing of the window.
      Returns:
      the created window for o, with default component-set
      See Also:
    • createWindow

      public GuiSwingWindow createWindow(Object o, boolean appRoot, Consumer<GuiSwingWindow> afterActionInEvent)
      if the current thread is the event dispatching thread, it will immediately create a window for o and return it. otherwise, it invokes the same task to the event dispatching thread and waits it. the afterActionInEvent will be executed within the event dispatching thread after creating the window. The method 1) runs createWindowInEvent(Object) with setting the application root of the window as appRoot, and 2) afterActionInEvent.
      Parameters:
      o - the target object
      appRoot - if true, the returned window will clean-up windows and task-runners at closing of the window
      afterActionInEvent - null or an action with the created window, executed within the event dispatching thread
      Returns:
      the created window for o, with default component-set
      Since:
      1.1
    • showLive

      public static GuiSwingWindow showLive(Object o)
      creates a window for o with relaxed type-binding, i.e. binding public and package-private members without GuiIncluded annotations. The created window is NOT app-root (GuiSwingWindow.isApplicationRoot()==false), thus closing the window will not call AutoCloseable.close() to o. In order to cause the close method, you can directly call GuiSwingWindow.cleanUp(). The method do get() and showWindowLive(Object).
      Parameters:
      o - the target object
      Returns:
      the created window for o
    • showWindowLive

      public GuiSwingWindow showWindowLive(Object o)
      called from showLive(Object), creating a new window by createWindowRelaxed(Object) and displaying it by displayLiveWindow(JFrame).
      Parameters:
      o - the target object
      Returns:
      the created window for o
      Since:
      1.3
    • displayLiveWindow

      public static void displayLiveWindow(JFrame w)
      display the given window and moving it to front
      Parameters:
      w - the showing window
    • createWindowRelaxed

      public GuiSwingWindow createWindowRelaxed(Object o)
      shorthand for createWindowRelaxed(o, this::setLookAndFeel, null)
      Parameters:
      o - the target object
      Returns:
      the created window for o
      See Also:
    • createWindowRelaxed

      public GuiSwingWindow createWindowRelaxed(Object o, Consumer<GuiSwingWindow> afterActionInEvent)
      shorthand for createWindowRelaxed(o, this::setLookAndFeel, afterActionInEvent)
      Parameters:
      o - the target object
      afterActionInEvent - null or an action with the created window, executed within the event dispatching thread
      Returns:
      the created window for o, with relaxed component-set. Note that the created window does not become application root.
      Since:
      1.1
    • createWindowRelaxed

      public GuiSwingWindow createWindowRelaxed(Object o, Runnable beforeActionInEvent, Consumer<GuiSwingWindow> afterActionInEvent)
      The method runs 1) the beforeActionInEvent, 2) createWindowRelaxedInEvent(Object) for o with setting the returned window to non application root, and 3) runs afterActionInEvent. Those steps are executed under the event dispatching thread (SwingUtilities.invokeAndWait(Runnable))
      Parameters:
      o - the target object
      beforeActionInEvent - null or an action for pre-process before the creating window
      afterActionInEvent - null or an action with the created window, executed within the event dispatching thread
      Returns:
      the created window for o, with relaxed component-set. Note that the created window does not become application root.
      Since:
      1.3
    • invokeAndWait

      public <T> T invokeAndWait(Supplier<T> factory)
    • createWindowInEvent

      protected GuiSwingWindow createWindowInEvent(Object o)
      calling the creator, within the event-dispatching thread. The creator is set by withWindowCreator(Function) or the default creator by GuiSwingWindow.creator().
      Parameters:
      o - the binding object
      Returns:
      a created window
      Since:
      1.2
    • createWindowRelaxedInEvent

      protected GuiSwingWindow createWindowRelaxedInEvent(Object o)
      calling the relaxed-creator, within the event-dispatching thread The creator is set by withWindowCreatorRelaxed(Function) or the default creator by GuiSwingWindow.creator() with GuiSwingWindow.GuiSwingWindowCreator.withTypeBuilderRelaxed()
      Parameters:
      o - the binding object
      Returns:
      a created window
      Since:
      1.2
    • withWindowCreator

      public AutoGuiShell withWindowCreator(Function<Object,GuiSwingWindow> windowCreator)
      customizing the creator for createWindowInEvent(Object). e.g.
            AutoGuiShell.get()
                .withWindowCreator(
                    GuiSwingWindow.creator()
                          .withLogStatus(false)) //customizing the creator
                .showWindow(o);
        
      Parameters:
      windowCreator - the creator. the default creator is GuiSwingWindow.creator()
      Returns:
      this
      Since:
      1.2
    • withWindowCreatorRelaxed

      public AutoGuiShell withWindowCreatorRelaxed(Function<Object,GuiSwingWindow> windowCreatorRelaxed)
      customizing the creator for createWindowRelaxedInEvent(Object)
      Parameters:
      windowCreatorRelaxed - the creator. the default creator is GuiSwingWindow.creator() with GuiSwingWindow.GuiSwingWindowCreator.withTypeBuilderRelaxed()
      Returns:
      this
      Since:
      1.2