Annotations-Toolbar: Einbinden eines Commands zum Beenden des Annotations-Erstellmodus
Beispiel zum Einfügen eines Commands zum Beenden des Annotations-Erstellmodus in die Annotations-Toolbar.
Die Commands für das Anlegen von Annotationen werden in der com.levigo.jadice.appbase.AnnotationProfileAwareToolBar-Klasse aus dem Annotationsprofil erstellt, hier hat man die Möglichkeit ein weiteres Command zum Beenden des Annotations-Erstellmodus einzufügen. Die AnnotationProfileAwareToolBar-Implementation muss angepasst werden, der Quellcode ist in der lib/appbase/jadice-appbase-x.x.x.x-sources.jar Datei unter com/levigo/jadice/appbase/AnnotationProfileAwareToolBar.java zu finden. Hier muss das zusätzliche Command in der Methode populateComponent(...) Methode am Anfang eingefügt werden, z.B.:
private boolean stopAnnoCreationCmdAdded = false;
private void populateComponent(final TypeSet typeSet, JComponent componentToPopulate) {
if (!stopAnnoCreationCmdAdded) {
final AbstractDocumentCommand cmdStopAnnoCreation = new AbstractDocumentCommand() {
@Override
protected void execute() {
getPageView().getToolManager().getTool(AnnotationTool.class).setEditMode();
}
@Override
protected boolean canExecute() {
return getPageView().getToolManager().getTool(AnnotationTool.class).getCreateMode() != null;
}
};
final Icon iconStopAnnoCreation = UIManager.getIcon("Jadice.icons.TB_NORMAL");
final CommandAction cmdActionStopAnnoCreation = new CommandAction(//
context, // context
Arrays.<Command> asList(cmdStopAnnoCreation), // command
"",//
"",//
"Annotation erstellen beenden",//
null, // long description; not used.
iconStopAnnoCreation, //
iconStopAnnoCreation, //
"",//
null, // accelerator key
0, // mnemonic key
null // other options
);
addActionToComponent(componentToPopulate, cmdActionStopAnnoCreation);
// Auf 'true' setzen, damit das Command nur einmal hinzugefügt wird
stopAnnoCreationCmdAdded = true;
}
...
} In der Annotationstoolbar erscheint oben nun ein zusätzliches Icon.
Das Einbinden der angepassten Toolbar-Implementation kann man im Code der BasicJadicePanel-Klasse sehen, siehe com/levigo/jadice/demo/BasicJadicePanel.java, Methode createJadiceAnnotationToolbar():
protected JToolBar createJadiceAnnotationToolbar() {
return annoTools = new MyAnnotationProfileAwareToolBar(getPageView(), getContext());
}