This page is intended to provide information on small chunks of code that are of general use, but are not necessarily fully functional blocks. If you are stuck on a coding problem then search this page for the topic/function/keyword of interest, an index is not provided as the list of contents is expected to grow unwieldy.
Note, if some of the code is not visible in the examples below just copy the code and paste it into a text editor to see it all.
FileChooser Filter, DeferredChooser, FileFilter, FileNameExtensionFilter By monkeyboy
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
import se.datadosen.jalbum.DeferredChooser;
DeferredChooser fc = new DeferredChooser(JFileChooser.class);
FileFilter filter = new FileNameExtensionFilter(
"JPEG file", new String[] {"jpg", "jpeg"}
);
fc.setFileFilter(filter);
ui.fc.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int fcReturn = fc.showOpenDialog(window);
if (fcReturn == JFileChooser.APPROVE_OPTION) {
//Your code
}
}
});
Engine, UI, UI2Bean, get settings by David Ekholm
Settings in the user interface don’t get transferred to the JAlbum engine until album generation starts. To update the engine, so all gui settings are correctly reflected use UI2Bean before accessing the engine, e.g.
window.UI2Bean(); engine.getDirectory();
Or query the UI components directly, e.g.
window.directory.getText()
window.bean2UI(), UI, by David Ekholm to refresh the interface from a script
window.bean2UI()
It will copy the settings from the engine object to the user interface.
Rows, cols, override, reset by David Ekholm
To reset the number of rows and cols during album generation, for example to have the root index with 6 rows and 2 cols, but sub-directories indexes with 5 cols and 4 rows. Use hints.jap to set the rows and cols to 6 and 2 then in index.htt use
If(level == 0) {
engine.setRows(4);
engine.setCols(5);
}
ProcessTemplateFile, templates, vars, custom variables by David Ekholm
To pass skin variables from one template to another for processing, e.g. pass variableA from index.htt to MyTemplate.htt:
Map vars = new HashMap();
vars.put("variableA", variableA);
vars.put("variableB", variableB);
vars.put("variableC", variableC);
engine.processTemplateFile(
new File(skinDirectory, "MyTemplate.htt"),
new File(outputDirectory, "MyTemplate.html"),
vars);
jAlbumListener, event, engine, onload, UI, get, set by David Ekholm
To monitor and change settings in onload.bsh when album creation starts and stops. In the example below the page extentension, normally ‘.html’ is changed to ‘.php’ if a skin setting is selected.
import se.datadosen.jalbum.event.*;
window.addJAlbumListener(new JAlbumAdapter() {
String pageExtension;
public void albumCreationStarted(JAlbumEvent e) {
pageExtension = engine.getPageExtension();
if (ui.skinSettingName.isSelected())
engine.setPageExtension(".php");
}
public void albumCreationFinished(JAlbumEvent e) {
engine.setPageExtension(pageExtension);
engine.bean2UI();
}
});