{
// Text descriptions surface in the Preferences Sort by... options
SEQUENCE_AND_LABEL("Sequence"), LABEL_AND_SEQUENCE("Label"),
- NONE("No sort");
+ NONE("No sort"),
+
+ /**
+ * custom is set if user drags to reorder annotations
+ */
+ CUSTOM("Customised");
private String description;
private boolean showAutocalcAbove;
// working map of sequence index in alignment
- private final Map<SequenceI, Integer> sequenceIndices = new HashMap<SequenceI, Integer>();
+ private final Map<SequenceI, Integer> sequenceIndices = new HashMap<>();
/**
* Constructor given an alignment and the location (top or bottom) of
public void sort(AlignmentAnnotation[] alignmentAnnotations,
SequenceAnnotationOrder order)
{
- if (alignmentAnnotations == null)
+ if (alignmentAnnotations == null
+ || order == SequenceAnnotationOrder.CUSTOM)
{
return;
}
import jalview.analysis.AlignmentSorter;
import jalview.analysis.AlignmentUtils;
+import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
import jalview.analysis.CrossRef;
import jalview.analysis.Dna;
import jalview.analysis.GeneticCodeI;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
+import javax.swing.event.MenuEvent;
+import javax.swing.event.MenuListener;
/**
* DOCUMENT ME!
sortPairwiseMenuItem_actionPerformed(null);
}
- this.alignPanel.av
- .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
-
setMenusFromViewport(viewport);
buildSortByAnnotationScoresMenu();
calculateTree.addActionListener(new ActionListener()
}
});
+ /*
+ * ensure By Label/Sequence are not selected if annotations
+ * have been reordered manually to CUSTOM order
+ */
+ annotationsMenu.addMenuListener(new MenuListener()
+ {
+ @Override
+ public void menuSelected(MenuEvent e)
+ {
+ SequenceAnnotationOrder sortAnnotationsBy = viewport
+ .getSortAnnotationsBy();
+ sortAnnByLabel.setSelected(
+ sortAnnotationsBy == SequenceAnnotationOrder.LABEL_AND_SEQUENCE);
+ sortAnnBySequence.setSelected(
+ sortAnnotationsBy == SequenceAnnotationOrder.SEQUENCE_AND_LABEL);
+ }
+
+ @Override
+ public void menuDeselected(MenuEvent e)
+ {
+ }
+
+ @Override
+ public void menuCanceled(MenuEvent e)
+ {
+ }
+ });
}
/**
}
/**
- * Store selected annotation sort order for the view and repaint.
+ * Sorts annotations and repaints the alignment
*/
@Override
- protected void sortAnnotations_actionPerformed()
+ protected void sortAnnotations()
{
- this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
- this.alignPanel.av
- .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
+ alignPanel.sortAnnotations();
alignPanel.paintAlignment(false, false);
}
}
}
+
+ @Override
+ protected boolean setShowAutoCalculatedAbove(
+ boolean showAutoCalculatedAbove)
+ {
+ if (viewport.isShowAutocalculatedAbove() != showAutoCalculatedAbove)
+ {
+ viewport.setShowAutocalculatedAbove(showAutoCalculatedAbove);
+
+ /*
+ * change CUSTOM annotation ordering to NONE
+ * so that sorting actually does something
+ */
+ if (viewport.getSortAnnotationsBy() == SequenceAnnotationOrder.CUSTOM)
+ {
+ viewport.setSortAnnotationsBy(SequenceAnnotationOrder.NONE);
+ }
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public void setAnnotationSortOrder(
+ SequenceAnnotationOrder annotationSortOrder)
+ {
+ viewport.setSortAnnotationsBy(annotationSortOrder);
+ }
}
class PrintThread extends Thread
public void paintAlignment(boolean updateOverview,
boolean updateStructures)
{
- final AnnotationSorter sorter = new AnnotationSorter(getAlignment(),
- av.isShowAutocalculatedAbove());
- sorter.sort(getAlignment().getAlignmentAnnotation(),
- av.getSortAnnotationsBy());
repaint();
if (updateStructures)
}
/**
+ * Sorts annotations according to currently selected preference
+ */
+ void sortAnnotations()
+ {
+ final AnnotationSorter sorter = new AnnotationSorter(getAlignment(),
+ av.isShowAutocalculatedAbove());
+ sorter.sort(getAlignment().getAlignmentAnnotation(),
+ av.getSortAnnotationsBy());
+ }
+
+ /**
* DOCUMENT ME!
*
* @param g
import jalview.analysis.AlignSeq;
import jalview.analysis.AlignmentUtils;
+import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.Annotation;
ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
+ av.setSortAnnotationsBy(SequenceAnnotationOrder.CUSTOM);
}
resizePanel = false;
protected JCheckBoxMenuItem applyAutoAnnotationSettings = new JCheckBoxMenuItem();
- private SequenceAnnotationOrder annotationSortOrder;
-
- private boolean showAutoCalculatedAbove = false;
-
private Map<KeyStroke, JMenuItem> accelerators = new HashMap<>();
private SplitContainerI splitFrame;
+ protected JCheckBoxMenuItem sortAnnBySequence;
+
+ protected JCheckBoxMenuItem sortAnnByLabel;
+
+ protected JMenu annotationsMenu;
+
public GAlignFrame()
{
try
JMenu editMenu = new JMenu(MessageManager.getString("action.edit"));
JMenu viewMenu = new JMenu(MessageManager.getString("action.view"));
- JMenu annotationsMenu = new JMenu(
+ annotationsMenu = new JMenu(
MessageManager.getString("action.annotations"));
JMenu showMenu = new JMenu(MessageManager.getString("action.show"));
colourMenu.setText(MessageManager.getString("action.colour"));
SequenceAnnotationOrder sortAnnotationsBy = SequenceAnnotationOrder
.valueOf(Cache.getDefault(Preferences.SORT_ANNOTATIONS,
SequenceAnnotationOrder.NONE.name()));
- final JCheckBoxMenuItem sortAnnBySequence = new JCheckBoxMenuItem(
+ sortAnnBySequence = new JCheckBoxMenuItem(
MessageManager.getString("label.sort_annotations_by_sequence"));
- final JCheckBoxMenuItem sortAnnByLabel = new JCheckBoxMenuItem(
+ sortAnnByLabel = new JCheckBoxMenuItem(
MessageManager.getString("label.sort_annotations_by_label"));
sortAnnBySequence.setSelected(
setAnnotationSortOrder(
newState ? SequenceAnnotationOrder.SEQUENCE_AND_LABEL
: SequenceAnnotationOrder.NONE);
- sortAnnotations_actionPerformed();
+ sortAnnotations();
}
});
sortAnnByLabel.setSelected(
setAnnotationSortOrder(
newState ? SequenceAnnotationOrder.LABEL_AND_SEQUENCE
: SequenceAnnotationOrder.NONE);
- sortAnnotations_actionPerformed();
+ sortAnnotations();
}
});
colourTextMenuItem = new JCheckBoxMenuItem(
final boolean autoFirst = Cache
.getDefault(Preferences.SHOW_AUTOCALC_ABOVE, false);
showAutoFirst.setSelected(autoFirst);
- setShowAutoCalculatedAbove(autoFirst);
showAutoFirst.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
- setShowAutoCalculatedAbove(showAutoFirst.isSelected());
- sortAnnotations_actionPerformed();
+ if (setShowAutoCalculatedAbove(showAutoFirst.isSelected()))
+ {
+ sortAnnotations();
+ }
}
});
showAutoLast.setSelected(!showAutoFirst.isSelected());
@Override
public void actionPerformed(ActionEvent e)
{
- setShowAutoCalculatedAbove(!showAutoLast.isSelected());
- sortAnnotations_actionPerformed();
+ if (setShowAutoCalculatedAbove(!showAutoLast.isSelected()))
+ {
+ sortAnnotations();
+ }
}
});
*
* @param sortOrder
*/
- protected void sortAnnotations_actionPerformed()
+ protected void sortAnnotations()
{
}
}
- protected boolean isShowAutoCalculatedAbove()
- {
- return showAutoCalculatedAbove;
- }
-
- protected void setShowAutoCalculatedAbove(boolean showAutoCalculatedAbove)
- {
- this.showAutoCalculatedAbove = showAutoCalculatedAbove;
- }
-
- protected SequenceAnnotationOrder getAnnotationSortOrder()
+ /**
+ * Sets the value of the flag for 'show autocalculated annotations above other
+ * annotations'. Answers true if the value changed, else false.
+ *
+ * @param showAutoCalculatedAbove
+ * @return
+ */
+ protected boolean setShowAutoCalculatedAbove(
+ boolean showAutoCalculatedAbove)
{
- return annotationSortOrder;
+ return false;
}
- protected void setAnnotationSortOrder(
+ public void setAnnotationSortOrder(
SequenceAnnotationOrder annotationSortOrder)
{
- this.annotationSortOrder = annotationSortOrder;
}
public Map<KeyStroke, JMenuItem> getAccelerators()