Compiling your skin's user interface has two advantages. First, the skin will load faster. For a skin with simple options, the difference isn't noticeable, but for a skin with a lot of panels and fields, it can make quite a difference. Second, working in an IDE like NetBeans will warn you about things like syntax errors, misspelled variable names, and so on, so that you can correct them before you ever compile the interface. With an interpreted onload.bsh, it's more a matter of "modify, see if it crashes when you load the skin, try to figure out why, modify again...."
So, some instructions, and the source files for a basic DemoSkin skin that can serve as a model. Pathnames assume Windows - in macOS, things naturally won't be in the same places. Questions? Please post them in Skin development.
Step one, installing the Java JDK, JavaFX SDK, and NetBeans.
Install OpenJDK 17: https://jdk.java.net/17/. This has no installers, alas. Unzip the file, and stash the extracted files in the same place your existing JDK folders are, like C:\Program Files\Java\.
Install OpenJFX SDK: https://gluonhq.com/products/javafx/. Scroll down a bit, and grab the version 17 release. Ditto on the lack of installers - unzip and move it to the same place your JDK's live.
You should end up with your JDK 17 stuff neatly organized in the same place - see screenshot winjdk.png.
The NetBeans installer won't be able to find JDK 17, because it wasn't "installed" by Windows. If you have installed the standard Java 8 JRE, the NetBeans installer will use it. Get it here: https://www.oracle.com/java/technologies/javase-jre8-downloads.html. If not, you can run the installer from a command line, but tell it where to find JDK 17:
You can save some installation space by customizing the installation and de-selecting the PHP and Java EE modules, which aren't needed for compiling a jAlbum skin user interface.
The first time NetBeans is used after a fresh install, it may prompt for the installation of various modules which, for licensing reasons, may not be bundled with the application. If you encounter any such prompts, agree to them, and let NetBeans install what it needs.
Name the project - for example DemoSkin. If you want to name the project for your own skin instead, like MySkin, change all references in the following instructions and in the attached source files to match that name.
In the Projects pane, right-click DemoSkin, and choose Properties.
Under Sources, go to Source/Binary Format, and choose JDK 8. This will make it possible for users of the 32-bit version of Windows 7 to use the skin (for these users, the current version of jAlbum is bundled with Java 8 rather than Java 14).
Under Libraries, go to Java Platform, and choose JDK 17.
Under Libraries, Compile, click the plus sign next to Classpath, choose Add JAR/Folder, navigate to C:\Program Files\jAlbum\lib and choose jalbum-core.jar.
Click the plus sign next to Classpath again, choose Add JAR/Folder, navigate to C:\Program Files\Java\javafx-sdk-188.8.131.52\lib and choose javafx.graphics.jar.
Under Build, Packaging, check both Compress JAR File and Build JAR after Compiling.
OK out of Properties.
In the Projects pane, right-click Source Packages and choose New, Java Class.
Create a new Java class named DemoSkin and click Finish. Repeat, and create one named SkinModel.
If you're also going to create a custom UI panel, i.e., a panel for applying some settings to individual images or folders, which appears on the right side when you're in "edit" mode for an image or folder, create two more new Java classes, one named DemoSkinCustom and one named SlideModel. For a real-world example of a custom UI, see https://jgromit.com/pluto/man/pluto_image-specific.html.
Copy the contents of the attached source files to the appropriate source classes in NetBeans. You could, instead, exit NetBeans, then in Windows Explorer or Finder, replace the four files under NetBeansProjects\Sources\DemoSkin\src with the attached files.
In each of the source files you have just created, hit ALT-SHIFT-F to clean up the formatting.
If you're not seeing any red error markers, you're ready to compile. Click the "hammer" icon in the toolbar. You will get one compiler warning about the classpath - ignore it.
Outside of NetBeans, navigate to NetBeansProjects\DemoSkin\dist, and copy DemoSkin.jar to the lib subdirectory of your skin directory.
In your skin directory, your onload.bsh should be just a one-liner:
Copy the attached skin.properties file to your skin directory. For the About tab in the UI, the UI needs a few things, like a version number, an author, a home page, and a link to the forum section.
Launch jAlbum and choose your skin.
Before going "final" with your skin, it's a good idea to do a "clean and compile," using the "hammer and broom" icon. This gets rid of leftover classes (which often result when you've been changing panel configurations in your skin), and may result in a smaller .jar file.
Re: Compiling a skin's user interface
16 Dec 18, 05:33
in response to: JeffTucker
Step four, taking your existing skin's UI and converting it.
You'll need to stash your original onload.bsh somewhere so that you can copy things out of it.
If you try to copy your entire existing onload.bsh into NetBeans, you'll be chasing down problems forever, without being able to compile the UI until all the errors are fixed. I would suggest, instead, that you tackle one of your existing panels at a time. Define the variables in the SkinModel.java source file (type and default value), then edit YourSkin.java to define the UI fields, set up the StateMonitor()'s (if any), and lay out the panel.
My example uses anonymous inner classes, which I find much easier to maintain - it lets you move things from one panel to another without having to edit every reference to a variable that's on the panel. No more ui.varName or panelName.varName. If you use anonymous inner classes in onload.bsh, skin loading can be very slow, but in a compiled UI it's not an issue.
A lot of things are pretty much the same in a compiled UI as they are in an interpreted one, though Java is fussier about things like data typing than BeanShell is.
At any time, you can clean up your formatting by hitting ALT-SHIFT-F. You can automatically insert any missing imports with CTRL-SHIFT-I.
When you're ready to compile (don't even try it if there are any red error markers in NetBeans - it won't compile), click the hammer icon on the toolbar. When compilation is complete, copy NetBeansProjects\YourSkin\dist\YourSkin.jar to your skin's lib directory.
Do my examples show the only way to do things, or even the absolute best way? Not at all. They just show how I'm doing things in my skins, and these approaches work for me. Keeping things grouped the way they are (field definitions, monitors, layout, etc.) tends to keep me out of "improperly nested hell." And yes, you will find yourself there at some stage of the game. One thing to remember - when you enter an opening curly brace in NetBeans, it will automatically supply the closing one. But control panel definitions also require a closing semi-colon, which you have to enter manually. So before you even start populating a control panel with fields, close the sucker - that will cut down on the "endless red markers" phenomenon.
If you're wondering how to do some of the fancier things you might see in my skin's UI's, the source files are all bundled with the skins - burrow down into the skin directory to find the files.
Re: Compiling a skin's user interface
16 Dec 18, 05:39
in response to: JeffTucker
So, is this all worth the effort? Yes. Absolutely yes. The initial hurdle is large, but once you've done it, you're home-free. It is much easier to maintain a compiled UI than it is to maintain an interpreted onload.bsh.
You won't spend endless time hunting down the little typo that's preventing your skin from loading - in NetBeans, the second you mis-type a variable name, you'll get a red underline that alerts you to the error.
You won't have to head-scratch when your failure to include a toString() when you're checking a user choice causes mysterious errors. NetBeans will warn you about a data type mismatch.
And your skin will load in a fraction of the time.
One little time-saving tip: you can set up your NetBeans project so that it compiles the skin interface directly into the live version of the skin in jAlbum. See the attached screenshot. This eliminates the step of copying and pasting the .jar file. Just remember that there's no "undo" command, so keep a backup of your unmodified skin.
If you do this, you can, with jAlbum running, compile the skin, go to jAlbum, hit CTRL-R to reload the skin, and test the results.
But if you do this, you can't do the final clean and compile with jAlbum running, because the skin's lib directory is locked against deletion. Close jAlbum before doing this final compile.