@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
.
withLookAndFeelClass(String)
: directly set the argumentwithLookAndFeelProperty(String)
:#prop:
p. The value of the property p will be passed toUIManagerUtil.selectLookAndFeelFromSpecialName(String)
. The absence of the property is equivalent to the special name"default"
withLookAndFeelSpecial(String)
:#special:
v. The value v will passed toUIManagerUtil.selectLookAndFeelFromSpecialName(String)
withCrossPlatformLookAndFeel()
: a cross platform classwithLookAndFeelNone()
:#none
withLookAndFeelClassFromFunction(Function)
: the function will be invoked immediately. It can be used for custom LAF installation. The function can return a value forlookAndFeelClass
(nullable)
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)
.
Once UIManagerUtil.setLookAndFeel(String)
with #prop:p
is called, the property p will be #none
,
the special value for ignoring multiple calls of the setLookAndFeel.
This means that the multiple setLookAndFeel()
(or showWindow(Object)
) do not cause re-installation of the same LAF
through a property (inlcuding the default autogui.laf
),
but another way like direct specification of the LAF class will do it.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Function
<Object, GuiSwingWindow> protected Function
<Object, GuiSwingWindow> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateWindow
(Object o, boolean appRoot) if the current thread is the event dispatching thread, it will immediately create a window for o and return it.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.protected GuiSwingWindow
calling the creator, within the event-dispatching thread.shorthand forcreateWindowRelaxed(o, this::setLookAndFeel, null)
createWindowRelaxed
(Object o, Runnable beforeActionInEvent, Consumer<GuiSwingWindow> afterActionInEvent) The method runs 1) thebeforeActionInEvent
, 2)createWindowRelaxedInEvent(Object)
for o with setting the returned window to non application root, and 3) runsafterActionInEvent
.createWindowRelaxed
(Object o, Consumer<GuiSwingWindow> afterActionInEvent) shorthand forcreateWindowRelaxed(o, this::setLookAndFeel, afterActionInEvent)
protected GuiSwingWindow
calling the relaxed-creator, within the event-dispatching thread The creator is set bywithWindowCreatorRelaxed(Function)
or the default creator byGuiSwingWindow.creator()
withGuiSwingWindow.GuiSwingWindowCreator.withTypeBuilderRelaxed()
static void
display the given window and moving it to frontstatic AutoGuiShell
get()
<T> T
invokeAndWait
(Supplier<T> factory) void
set the look-and-feel ofUIManager
fromlookAndFeelClass
.static GuiSwingWindow
creates a window for o with relaxed type-binding, i.e.void
showWindow
(Object o) create a window for the object o as the application root and display it.void
showWindow
(Object o, Runnable beforeActionInEvent) shorthand forshowWindow(o, beforeActionInEvent, null)
void
showWindow
(Object o, Runnable beforeActionInEvent, Consumer<GuiSwingWindow> afterActionInEvent) create a window for the object o as the application root and display it.called fromshowLive(Object)
, creating a new window bycreateWindowRelaxed(Object)
and displaying it bydisplayLiveWindow(JFrame)
.withLookAndFeelClass
(String lookAndFeelClass) turning off the feature of the setting look-and-feel from some propertywithPrefsValuesLoadArgs
(String... args) applyGuiPreferencesLoader.parseArgs(Object, List)
for the target object.skip loading default properties of object from saved default prefs.withWindowCreator
(Function<Object, GuiSwingWindow> windowCreator) customizing the creator forcreateWindowInEvent(Object)
.withWindowCreatorRelaxed
(Function<Object, GuiSwingWindow> windowCreatorRelaxed) customizing the creator forcreateWindowRelaxedInEvent(Object)
-
Field Details
-
lookAndFeelClass
-
windowCreator
- Since:
- 1.2
-
windowCreatorRelaxed
- Since:
- 1.2
-
-
Constructor Details
-
AutoGuiShell
public AutoGuiShell()
-
-
Method Details
-
get
- Returns:
- a new instance
-
showWindow
create a window for the object o as the application root and display it. before creating the window, it sets LookAndFeel as the value oflookAndFeelClass
bysetLookAndFeel()
.The method is equivalent to the following code:
SwingUtilities.invokeLater(() -> { setLookAndFeel(); createWindow(o, true).setVisible(true); });
- Parameters:
o
- the target object
-
withCrossPlatformLookAndFeel
-
withLookAndFeelClass
- Parameters:
lookAndFeelClass
- the LAF class name or a special name which can be acceptable byUIManagerUtil.setLookAndFeel(String)
- Returns:
- this
- Since:
- 1.2
-
withLookAndFeelClassFromFunction
- Parameters:
init
- the user init process for installing LAF by custom mechanism with receiving this. the returned string will be passed towithLookAndFeelClass(String)
- Returns:
- this
- Since:
- 1.2
-
withLookAndFeelProperty
- Parameters:
p
- a system property, like "autogui.laf".- Returns:
- this with setting "#prop:p"
- Since:
- 1.3
-
withLookAndFeelSpecial
- Parameters:
v
- a special name can be passed toUIManagerUtil.selectLookAndFeelFromSpecialName(String)
- Returns:
- this with setting "#special:v"
- Since:
- 1.4
-
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 ofUIManager
fromlookAndFeelClass
. the field specifies the class name of LookAndFeel. if the value of the field is "#system" then, it uses system-look-and-feel. -
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
applyGuiPreferencesLoader.parseArgs(Object, List)
for the target object.- Parameters:
args
- the command args- Returns:
- this
- Since:
- 1.4
-
showWindow
shorthand forshowWindow(o, beforeActionInEvent, null)
- Parameters:
o
- the target objectbeforeActionInEvent
- 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 underSwingUtilities.invokeLater(Runnable)
.- Parameters:
o
- the target objectbeforeActionInEvent
- action executed before creating the window within the event dispatching thread. nullableafterActionInEvent
- action executed after creating the window within the event dispatching thread. nullable- Since:
- 1.1
-
createWindow
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 forcreateWindow(o, appRoot, null)
- Parameters:
o
- the target objectappRoot
- 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) runscreateWindowInEvent(Object)
with setting the application root of the window asappRoot
, and 2)afterActionInEvent
.- Parameters:
o
- the target objectappRoot
- if true, the returned window will clean-up windows and task-runners at closing of the windowafterActionInEvent
- 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
creates a window for o with relaxed type-binding, i.e. binding public and package-private members withoutGuiIncluded
annotations. The created window is NOT app-root (GuiSwingWindow.isApplicationRoot()
==false), thus closing the window will not callAutoCloseable.close()
to o. In order to cause the close method, you can directly callGuiSwingWindow.cleanUp()
. The method doget()
andshowWindowLive(Object)
.- Parameters:
o
- the target object- Returns:
- the created window for o
-
showWindowLive
called fromshowLive(Object)
, creating a new window bycreateWindowRelaxed(Object)
and displaying it bydisplayLiveWindow(JFrame)
.- Parameters:
o
- the target object- Returns:
- the created window for o
- Since:
- 1.3
-
displayLiveWindow
display the given window and moving it to front- Parameters:
w
- the showing window
-
createWindowRelaxed
shorthand forcreateWindowRelaxed(o, this::setLookAndFeel, null)
- Parameters:
o
- the target object- Returns:
- the created window for o
- See Also:
-
createWindowRelaxed
shorthand forcreateWindowRelaxed(o, this::setLookAndFeel, afterActionInEvent)
- Parameters:
o
- the target objectafterActionInEvent
- 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) thebeforeActionInEvent
, 2)createWindowRelaxedInEvent(Object)
for o with setting the returned window to non application root, and 3) runsafterActionInEvent
. Those steps are executed under the event dispatching thread (SwingUtilities.invokeAndWait(Runnable)
)- Parameters:
o
- the target objectbeforeActionInEvent
- null or an action for pre-process before the creating windowafterActionInEvent
- 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
-
createWindowInEvent
calling the creator, within the event-dispatching thread. The creator is set bywithWindowCreator(Function)
or the default creator byGuiSwingWindow.creator()
.- Parameters:
o
- the binding object- Returns:
- a created window
- Since:
- 1.2
-
createWindowRelaxedInEvent
calling the relaxed-creator, within the event-dispatching thread The creator is set bywithWindowCreatorRelaxed(Function)
or the default creator byGuiSwingWindow.creator()
withGuiSwingWindow.GuiSwingWindowCreator.withTypeBuilderRelaxed()
- Parameters:
o
- the binding object- Returns:
- a created window
- Since:
- 1.2
-
withWindowCreator
customizing the creator forcreateWindowInEvent(Object)
. e.g.AutoGuiShell.get() .withWindowCreator( GuiSwingWindow.creator() .withLogStatus(false)) //customizing the creator .showWindow(o);
- Parameters:
windowCreator
- the creator. the default creator isGuiSwingWindow.creator()
- Returns:
- this
- Since:
- 1.2
-
withWindowCreatorRelaxed
customizing the creator forcreateWindowRelaxedInEvent(Object)
- Parameters:
windowCreatorRelaxed
- the creator. the default creator isGuiSwingWindow.creator()
withGuiSwingWindow.GuiSwingWindowCreator.withTypeBuilderRelaxed()
- Returns:
- this
- Since:
- 1.2
-