super(frame, "ApplyTemplate");
}
// Called from FileMenu when it is selected.
void update() {
ComboFrame frame = getComboFrame();
Document doc = (frame != null) ? frame.getDocument() : null;
if (doc == null) {
setEnabled(false);
return;
}
try {
removeAll();
List<TemplateKey> keys = TemplateDatabase.getTemplateKeys();
if (! keys.isEmpty()) {
for (final TemplateKey key : keys) {
JMenuItem templateItem = new JMenuItem(key.toString());
templateItem.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent event) {
ComboFrame frame = getComboFrame();
Application.applyTemplate(frame, key);
}
}
);
add(templateItem);