Let's create our own extension.
The first thing we need is to import PetepLib.jar (from distribution/api) to our project and then create package petep with class PetepExtension.
You can download the final extension project on GitHub.
public class PetepExtension extends Extension {
public PetepExtension(String path) {
super(path);
}
@Override
public String getCode() {
return "example";
}
@Override
public String getName() {
return "Example extension.";
}
@Override
public String getDescription() {
return "Example extension for developers.";
}
@Override
public String getVersion() {
return "0.0.1";
}
@Override
public void init(ExtensionHelper helper) {
Logger.getGlobal().info("Example extension loaded!");
}
@Override
public void initGui(GuiHelper helper) {
Logger.getGlobal().info("Example extension GUI loaded!");
}
}
Now we can export our extension to .JAR file and import it to our project. If we run PETEP from command line, we should see our logs.
Let's also create a simple empty Tab in both application and settings by adding the following code to initGui method:
try {
Parent appTab = FXMLLoader.load(getClass().getResource("/fxml/ExampleTab.fxml"));
Parent settingsTab = FXMLLoader.load(getClass().getResource("/fxml/ExampleTab.fxml"));
helper.registerTab("Example Tab 1", appTab);
helper.registerSettingsTab("Example Tab 2", settingsTab);
} catch (IOException e) {
Logger.getGlobal().log(Level.SEVERE, "Could not load example tab.", e);
}
Example FXML tab template:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane prefHeight="37.0" prefWidth="90.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label layoutX="10.0" layoutY="10.0" styleClass="heading-2" text="Example Tab" AnchorPane.leftAnchor="10.0" AnchorPane.topAnchor="10.0" />
</children>
</AnchorPane>
We should see obth tabs added to the extension after deploying it again.