public abstract class DocumentViewerFactory extends Object
createViewer(com.biomatters.geneious.publicapi.documents.AnnotatedPluginDocument[]).
A plugin may provide a set of DocumentViewerFactories
via GeneiousPlugin.getDocumentViewerFactories().
The following example shows how to create a DocumentViewerFactory as an anonymous inner class. In this
example, the factory creates viewers that display a single sequence with large text.
new DocumentViewerFactory(){
//This method creates a DocumentViewer from an array of AnnotatedPluginDocument objects
//Since the DocumentSelectionSignature (see below) allows only single documents to be passed,
//we can safely assume that the array is of length 1.
public DocumentViewer createViewer(final AnnotatedPluginDocument[] docs){
return new DocumentViewer(){
final String residues = ((SequenceDocument)docs[0].getDocument()).getSequenceString().toUpperCase();
final Font font = new Font("monospaced",Font.PLAIN,48);
//The DocumentViewer class contains one abstract method
//to get a component for viewing.
public JPanel getComponent(){
JPanel canvas = new JPanel(){
public void paintComponent(Graphics g){
//we need to clear the background
g.setColor(Color.white);
g.fillRect(0,0,getWidth(),getHeight());
//then draw the sequence string onto the canvas
g.setColor(Color.black);
g.setFont(font);
g.drawString(residues,10,50);
}
public Dimension getPreferredSize(){
//this calculates how wide the text is going to be.
FontRenderContext frc = new FontRenderContext(new AffineTransform(), false, false);
Rectangle2D fontBounds = font.getStringBounds(residues, frc);
return new Dimension((int)fontBounds.getWidth()+20,(int)fontBounds.getHeight()+60);
}
};
//we put the main canvas into a JScrollPane in case the sequence is bigger than the viewer window.
JScrollPane scroller = new JScrollPane(canvas);
//since we return a JPanel, we need to put the JScrollPane into a new JPanel
JPanel holder = new JPanel(new BorderLayout());
holder.add(scroller,BorderLayout.CENTER);
return holder;
}
//DocumentViewer contains two methods for printing, getExtendedPrintable and getPrintable
//it is suggested that you use getExtendedPrintable for more full-featured printing
public ExtendedPrintable getExtendedPrintable(){
return new ExtendedPrintable(){
//see ExtendedPrintable for an example implementation.
};
}
//This method allows the viewer to link in to Geneious's search feature.
public Findable getFindable(){
return new Findable(){
//see Findable for an example implementation.
};
}
//if a NoLongerViewedListener is supplied, Geneious will call it when the document is moved
//offscreen. isTemporary is true if the user is switching to another viewer of the same document
//and false otherwise.
//NoLongerViewedReason has two possible values, NO_SPECIFIC_REASON and DOCUMENT_GENERATED. You may
//want to check for this if you want to display a special message to the user when a new document is
//generated.
public NoLongerViewedListener getNoLongerViewedListener(){
return new NoLongerViewedListener(){
//see NoLongerViewedListener for an example implementation.
};
}
//Providing an ActionProvider allows your plugin to link in to some of Geneious actions.
//In this example we are allowing the sequence to be copied to the clipboard when the user
//selects "Copy" from the edit menu.
public ActionProvider getActionProvider() {
return new ActionProvider(){
//see ActionProvider for an example implementation.
};
}
};
}
//DocumentViewerFactories tell Geneious what types of documents they can accept with a list of DocumentSelectionSignature objects.
//This particular DocumentViewerFactory accepts a single SequenceDocument
public DocumentSelectionSignature[] getSelectionSignatures(){
return new DocumentSelectionSignature[]{new DocumentSelectionSignature(SequenceDocument.class,1,1)};
}
public String getHelp(){
return "A Viewer";
}
public String getDescription(){
return "Ludicrous, isn't it?";
}
//This is the string that is used for the name of the tab in the viewer window
public String getName(){
return "Ludicrously Giant Sequence View";
}
};
| Modifier and Type | Class and Description |
|---|---|
static class |
DocumentViewerFactory.ViewPrecedence
Viewer precedence level.
|
| Constructor and Description |
|---|
DocumentViewerFactory() |
| Modifier and Type | Method and Description |
|---|---|
abstract DocumentViewer |
createViewer(AnnotatedPluginDocument[] annotatedDocuments)
Viewer as a Java component.
|
abstract String |
getDescription()
Description of the viewers purpose and how it is accessed.
|
abstract String |
getHelp()
Get help.
|
Icons |
getIcons()
An icon which will be displayed (at 16x16) next to the viewer name in the tabbed pane.
|
String |
getKeyForPerDocumentPreferencesNeededDuringInitialization()
Returns the name of an additional XML key used with PerDocumentPreferences for viewers that need access to the preferences during their swing thread initialization.
|
abstract String |
getName()
Viewer user visible name.
|
List<GeneiousAction> |
getPossibleExternalActions()
Get a list of
GeneiousActions for viewer actions that should be displayed in the main menu
or other location outside the viewer's toolbar. |
DocumentViewerFactory.ViewPrecedence |
getPrecedence()
Provide a rough guide about the social status of the viewer.
|
abstract DocumentSelectionSignature[] |
getSelectionSignatures()
Specifies the type of document(s) viewer can display.
|
boolean |
isDisplayableInSecondaryFrame()
If false then this viewer will never be available in secondary frames which the
user opens (by double clicking or selecting and "Open in new window" action).
|
boolean |
isDisplayedInHelpPanel()
A viewer can be displayed as a tab in the help panel on the right hand side of
the main window.
|
boolean |
isProOnly()
Returns true if DocumentViewers created by this factory requires an active license.
|
boolean |
loadInternalPluginDocuments() |
public abstract String getName()
DocumentViewer.getName() to provide a name that better matches the data.DocumentViewer.getName()public abstract String getDescription()
public abstract String getHelp()
public abstract DocumentSelectionSignature[] getSelectionSignatures()
public abstract DocumentViewer createViewer(AnnotatedPluginDocument[] annotatedDocuments)
AnnotatedPluginDocument.getDocumentOrNull() on any
of the given annotatedDocuments and safely rely on it not returning null. Or alternatively use AnnotatedPluginDocument.getDocumentOrCrash()
which won't crash when called from inside createViewer. Note that if the DocumentViewer returns false from loadInternalPluginDocuments() then this won't be true.
May return null to have no viewer displayed (this should only be
used if the selection signature is not sufficient).annotatedDocuments - documents to display. list is guaranteed to match one of the signatures.public DocumentViewerFactory.ViewPrecedence getPrecedence()
public boolean loadInternalPluginDocuments()
AnnotatedPluginDocument.getDocumentOrNull(),
false if not. If this is true then the program will load the document first so it can display a progress bar to the user.
Should be false for viewers which deal only with AnnotatedPluginDocuments and never PluginDocuments so
the viewer can be displayed quickly without first loading the internal documents.public boolean isDisplayedInHelpPanel()
public String getKeyForPerDocumentPreferencesNeededDuringInitialization()
public boolean isDisplayableInSecondaryFrame()
public Icons getIcons()
public boolean isProOnly()
public List<GeneiousAction> getPossibleExternalActions()
GeneiousActions for viewer actions that should be displayed in the main menu
or other location outside the viewer's toolbar. This is required because any actions that wish to be in the menu
must be added to the menu on start up, before the viewer is displayed.
The actual GeneiousActions (return matching values from GeneiousActionOptions.getIdentifier()) must be returned from
DocumentViewer.getActionProvider().getExternalActions(). The menu will then
link in to the action returned from the currently visible DocumentViewer instance.GeneiousActions for viewer actions that should be displayed in the main menu
or other location outside the viewer's toolbar