Class Layer1ApiAlertGuiMessage
- All Implemented Interfaces:
Layer1ApiStrategiesEchoMessagesLayer.StrategyEchoMessageFromLayer
public class Layer1ApiAlertGuiMessage extends java.lang.Object implements Layer1ApiStrategiesEchoMessagesLayer.StrategyEchoMessageFromLayer
Use this message to send GUI panels for configuration of Layer1ApiSoundAlertMessage's, created by
your addon (specified via source).
Internally Bookmap caches these messages, and if you want to remove your GUI panels -
send another Layer1ApiAlertGuiMessage with the same id
and isAdd = false
Note: for now multiple GUI's for alerts from the same addon are not allowed.
If your addon sends multiple Layer1ApiAlertGuiMessage's with
isAdd = true - an exception will be
thrown, and the addon will be unloaded. If you want to show a another GUI -
you can un-register the previous one and then register another one.
However, in most cases the provided functionality of guiPanelsProvider
should be enough, as your Function can return different StrategyPanel[]
For an overview of the notification system, take a look at Layer1ApiSoundAlertMessage javadoc
Example of an addon that registers custom GUI panels
To keep the example simple, lets create an addon, whose sole purpose is to add a (very basic) GUI panel to the Bookmap.
As always, we start with defining an entrypoint for our addon:
@Layer1Attachable@Layer1StrategyName("Simple alert GUI demo")@Layer1ApiVersion(Layer1ApiVersionValue.VERSION2)public class SimpleAlertGuiDemo implements Layer1ApiFinishable { private final Layer1ApiProvider provider; public SimpleAlertGuiDemo(Layer1ApiProvider provider) { this.provider = provider; } }
Next, lets define the panels that we want to show. Here we will implement a rather basic example. However, we are only showing the concept, and you can make your GUIs as complex as you like.
Here we will create an inner class that extends StrategyPanel
private static class SimpleGuiPanel extends StrategyPanel {
public SimpleGuiPanel() {
super("Simple alert GUI demo");
add(new JLabel("Hello from Simple alert GUI demo!"));
}
}
Moving on to the key part - sending our GUI to Bookmap. For that we should
use Layer1ApiAlertGuiMessage:
public SimpleAlertGuiDemo(Layer1ApiProvider provider) {
this.provider = provider;
guiMessage = Layer1ApiAlertGuiMessage
.builder()
.setSource(SimpleAlertGuiDemo.class)
.setGuiPanelsProvider(declarationMessage -> new StrategyPanel[]{new SimpleGuiPanel()})
.build();
provider.sendUserMessage(guiMessage);
}
And this should do the job. New GUI panels should appear in File -> Alerts -> Configure alerts -> Add alert....
It is also important to know that it is possible to remove your custom GUI panels from Bookmap:
@Override
public void finish() {
if (guiMessage != null) {
Layer1ApiAlertGuiMessage removeGuiMessage = new Builder(guiMessage)
.setIsAdd(false)
.build();
provider.sendUserMessage(removeGuiMessage);
}
}
Full example source code can be found in
DemoStrategies
project on Github - check out
velox.api.layer1.simpledemo.alerts.simplegui.SimpleAlertGuiDemo- See Also:
Layer1ApiSoundAlertMessage, DemoStrategies
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLayer1ApiAlertGuiMessage.Builder -
Field Summary
Fields Modifier and Type Field Description java.util.function.Function<Layer1ApiSoundAlertDeclarationMessage,StrategyPanel[]>guiPanelsProviderFunction that returns GUI panels based onLayer1ApiSoundAlertDeclarationMessage
If your GUI panels are opened with the intent to declare a new alert - the passed argument is null.java.lang.StringidId can be used to reference this messagebooleanisAddTrue if this message adds GUI panels.java.lang.Class<?>sourceClass that created this message.java.lang.StringstrategyNameName of the strategy that created this message, extracted fromLayer1StrategyName.value(), displayed on the UI -
Method Summary
Modifier and Type Method Description static Layer1ApiAlertGuiMessage.Builderbuilder()Creates builder to buildLayer1ApiAlertGuiMessage.java.lang.StringtoString()
-
Field Details
-
id
public final java.lang.String idId can be used to reference this message -
source
public final java.lang.Class<?> sourceClass that created this message. The class must be annotated withLayer1StrategyName -
strategyName
public final java.lang.String strategyNameName of the strategy that created this message, extracted fromLayer1StrategyName.value(), displayed on the UI -
guiPanelsProvider
public final java.util.function.Function<Layer1ApiSoundAlertDeclarationMessage,StrategyPanel[]> guiPanelsProviderFunction that returns GUI panels based onLayer1ApiSoundAlertDeclarationMessage
If your GUI panels are opened with the intent to declare a new alert - the passed argument is null. Otherwise a user wants to modify an existingLayer1ApiSoundAlertDeclarationMessage- in that case the function obtains this declaration as an argument. You can use this declaration to pre-populate fields in your GUI. -
isAdd
public final boolean isAddTrue if this message adds GUI panels. Otherwise, the panels from a message with the sameidwill be removed
-
-
Method Details
-
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-
builder
Creates builder to buildLayer1ApiAlertGuiMessage.- Returns:
- created builder
-