@Override
public void sortAlignmentByFeatureDensity(List<String> typ)
{
- sortBy(typ, "Sort by Density", AlignmentSorter.FEATURE_DENSITY);
+ String methodText = MessageManager.getString("label.sort_by_density");
+ sortByFeatures(typ, methodText, AlignmentSorter.FEATURE_DENSITY);
}
- protected void sortBy(List<String> typ, String methodText,
+ /**
+ * Sorts the alignment (or current selection) by either average score or
+ * density of the specified feature types, and adds to the command history. If
+ * {@code types} is null, all visible feature types are used for the sort. If
+ * no feature types apply, does nothing.
+ *
+ * @param types
+ * @param methodText
+ * @param method
+ */
+ protected void sortByFeatures(List<String> types, String methodText,
final String method)
{
FeatureRenderer fr = alignPanel.getFeatureRenderer();
- if (typ == null && fr != null)
+ if (types == null && fr != null)
+ {
+ types = fr.getDisplayedFeatureTypes();
+ }
+ if (types.isEmpty())
{
- typ = fr.getDisplayedFeatureTypes();
+ return; // nothing to do
}
List<String> gps = null;
if (fr != null)
stop = al.getWidth();
}
SequenceI[] oldOrder = al.getSequencesArray();
- AlignmentSorter.sortByFeature(typ, gps, start, stop, al, method);
+ AlignmentSorter.sortByFeature(types, gps, start, stop, al, method);
avcg.addHistoryItem(new OrderCommand(methodText, oldOrder,
viewport.getAlignment()));
alignPanel.paintAlignment(true, false);
@Override
public void sortAlignmentByFeatureScore(List<String> typ)
{
- sortBy(typ, "Sort by Feature Score", AlignmentSorter.FEATURE_SCORE);
+ String methodText = MessageManager.getString("label.sort_by_score");
+ sortByFeatures(typ, methodText, AlignmentSorter.FEATURE_SCORE);
}
@Override
import java.util.Set;
import javax.help.HelpSetException;
-import javax.swing.AbstractButton;
import javax.swing.AbstractCellEditor;
import javax.swing.BorderFactory;
import javax.swing.Icon;
JSlider transparency = new JSlider();
+ private JCheckBox showComplementOnTop;
+
+ private JCheckBox showComplement;
+
/*
* when true, constructor is still executing - so ignore UI events
*/
private boolean handlingUpdate = false;
/*
+ * a change listener to ensure the dialog is updated if
+ * FeatureRenderer discovers new features
+ */
+ private PropertyChangeListener change;
+
+ /*
* holds {featureCount, totalExtent} for each feature type
*/
Map<String, float[]> typeWidth = null;
inConstruction = false;
}
- PropertyChangeListener change;
-
- private JCheckBox showComplementOnTop;
-
- private AbstractButton showComplement;
-
+ /**
+ * Sets the state of buttons to show complement features from viewport
+ * settings
+ */
private void updateComplementButtons()
{
showComplement.setSelected(af.getViewport().isShowComplementFeatures());
JMenuItem scr = new JMenuItem(
MessageManager.getString("label.sort_by_score"));
men.add(scr);
- final FeatureSettings me = this;
scr.addActionListener(new ActionListener()
{
-
@Override
public void actionPerformed(ActionEvent e)
{
- me.af.avc
- .sortAlignmentByFeatureScore(Arrays.asList(new String[]
- { type }));
+ sortByScore(Arrays.asList(new String[] { type }));
}
-
});
JMenuItem dens = new JMenuItem(
MessageManager.getString("label.sort_by_density"));
dens.addActionListener(new ActionListener()
{
-
@Override
public void actionPerformed(ActionEvent e)
{
- me.af.avc
- .sortAlignmentByFeatureDensity(Arrays.asList(new String[]
- { type }));
+ sortByDensity(Arrays.asList(new String[] { type }));
}
-
});
men.add(dens);
men.show(table, x, y);
}
+ /**
+ * Sort the sequences in the alignment by the number of features for the given
+ * feature types (or all features if null)
+ *
+ * @param featureTypes
+ */
+ protected void sortByDensity(List<String> featureTypes)
+ {
+ af.avc.sortAlignmentByFeatureDensity(featureTypes);
+ }
+
+ /**
+ * Sort the sequences in the alignment by average score for the given feature
+ * types (or all features if null)
+ *
+ * @param featureTypes
+ */
+ protected void sortByScore(List<String> featureTypes)
+ {
+ af.avc.sortAlignmentByFeatureScore(featureTypes);
+ }
+
+ /**
+ * Returns true if at least one feature type is visible. Else shows a warning
+ * dialog and returns false.
+ *
+ * @param title
+ * @return
+ */
+ private boolean canSortBy(String title)
+ {
+ if (fr.getDisplayedFeatureTypes().isEmpty())
+ {
+ JvOptionPane.showMessageDialog(this,
+ MessageManager.getString("label.no_features_to_sort_by"),
+ title, JvOptionPane.OK_OPTION);
+ return false;
+ }
+ return true;
+ }
+
@Override
synchronized public void discoverAllFeatureData()
{
}
});
- JButton sortByScore = new JButton(
- MessageManager.getString("label.seq_sort_by_score"));
+ final String byScoreLabel = MessageManager.getString("label.seq_sort_by_score");
+ JButton sortByScore = new JButton(byScoreLabel);
sortByScore.setFont(JvSwingUtils.getLabelFont());
sortByScore.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
- af.avc.sortAlignmentByFeatureScore(null);
+ if (canSortBy(byScoreLabel))
+ {
+ sortByScore(null);
+ }
}
});
- JButton sortByDens = new JButton(
- MessageManager.getString("label.sequence_sort_by_density"));
+ final String byDensityLabel = MessageManager.getString("label.sequence_sort_by_density");
+ JButton sortByDens = new JButton(byDensityLabel);
sortByDens.setFont(JvSwingUtils.getLabelFont());
sortByDens.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
- af.avc.sortAlignmentByFeatureDensity(null);
+ if (canSortBy(byDensityLabel))
+ {
+ sortByDensity(null);
+ }
}
});
refreshDisplay();
}
});
- // JButton viewComplementSettings = new JButton(MessageManager
- // .formatMessage("label.show_linked_feature_settings",
- // nucleotide
- // ? MessageManager.getString("label.protein")
- // .toLowerCase()
- // : "CDS"));
- // viewComplementSettings.addActionListener(new ActionListener()
- // {
- //
- // @Override
- // public void actionPerformed(ActionEvent e)
- // {
- // AlignViewControllerGuiI complAf = af.getSplitViewContainer()
- // .getComplementAlignFrame(af);
- // FeatureSettings complFeatureSettings = (FeatureSettings) complAf
- // .getFeatureSettingsUI();
- // if (complFeatureSettings != null)
- // {
- // complFeatureSettings.frame.setVisible(true);
- // try
- // {
- // complFeatureSettings.frame.setSelected(true);
- // return;
- // } catch (Exception q)
- // {
- // }
- // }
- // {
- // complAf.showFeatureSettingsUI();
- // }
- // }
- // });
+
+ updateComplementButtons();
+
JPanel lowerPanel = new JPanel(new GridLayout(1, 2));
bigPanel.add(lowerPanel, BorderLayout.SOUTH);