+ protected void sortByDens(String[] typ)
+ {
+ sortBy(typ, "Sort by Density", AlignmentSorter.FEATURE_DENSITY);
+ }
+
+ protected void sortBy(String[] typ, String methodText, final String method)
+ {
+ if (typ == null)
+ {
+ typ = getDisplayedFeatureTypes();
+ }
+ String gps[] = null;
+ gps = getDisplayedFeatureGroups();
+ if (typ != null)
+ {
+ for (int i = 0; i < typ.length; i++)
+ {
+ System.err.println("Sorting on Types:" + typ[i]);
+ }
+ }
+ if (gps != null)
+ {
+
+ for (int i = 0; i < gps.length; i++)
+ {
+ System.err.println("Sorting on groups:" + gps[i]);
+ }
+ }
+ AlignmentPanel alignPanel = af.alignPanel;
+ AlignmentI al = alignPanel.av.getAlignment();
+
+ int start, stop;
+ SequenceGroup sg = alignPanel.av.getSelectionGroup();
+ if (sg != null)
+ {
+ start = sg.getStartRes();
+ stop = sg.getEndRes();
+ }
+ else
+ {
+ start = 0;
+ stop = al.getWidth();
+ }
+ SequenceI[] oldOrder = al.getSequencesArray();
+ AlignmentSorter.sortByFeature(typ, gps, start, stop, al, method);
+ af.addHistoryItem(new OrderCommand(methodText, oldOrder, alignPanel.av
+ .getAlignment()));
+ alignPanel.paintAlignment(true);
+
+ }
+
+ protected void sortByScore(String[] typ)
+ {
+ sortBy(typ, "Sort by Feature Score", AlignmentSorter.FEATURE_SCORE);
+ }
+
+ private String[] getDisplayedFeatureTypes()
+ {
+ String[] typ = null;
+ if (fr != null)
+ {
+ synchronized (fr.renderOrder)
+ {
+ typ = new String[fr.renderOrder.length];
+ System.arraycopy(fr.renderOrder, 0, typ, 0, typ.length);
+ for (int i = 0; i < typ.length; i++)
+ {
+ if (af.viewport.featuresDisplayed.get(typ[i]) == null)
+ {
+ typ[i] = null;
+ }
+ }
+ }
+ }
+ return typ;
+ }
+
+ private String[] getDisplayedFeatureGroups()
+ {
+ String[] gps = null;
+ if (fr != null)
+ {
+
+ if (fr.featureGroups != null)
+ {
+ Enumeration en = fr.featureGroups.keys();
+ gps = new String[fr.featureColours.size()];
+ int g = 0;
+ boolean valid = false;
+ while (en.hasMoreElements())
+ {
+ String gp = (String) en.nextElement();
+ Boolean on = (Boolean) fr.featureGroups.get(gp);
+ if (on != null && on.booleanValue())
+ {
+ valid = true;
+ gps[g++] = gp;
+ }
+ }
+ while (g < gps.length)
+ {
+ gps[g++] = null;
+ }
+ if (!valid)
+ {
+ return null;
+ }
+ }
+ }
+ return gps;
+ }
+