X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FFeatureSettings.java;fp=src%2Fjalview%2Fgui%2FFeatureSettings.java;h=b87e4bf92c10de36e2a0b7cf827a5dd5341871f3;hb=de5086fce53cc943c046efe3e81a2022b2c3af7e;hp=3efc63ed3b7532045065ce4058b06146e0db4474;hpb=e00aedcdf1c30781339cd93e6e812c71f16b86d3;p=jalview.git diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index 3efc63e..b87e4bf 100644 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -82,7 +82,6 @@ import java.util.Map; import java.util.Set; import javax.help.HelpSetException; -import javax.swing.AbstractButton; import javax.swing.AbstractCellEditor; import javax.swing.BorderFactory; import javax.swing.Icon; @@ -165,6 +164,10 @@ public class FeatureSettings extends JPanel JSlider transparency = new JSlider(); + private JCheckBox showComplementOnTop; + + private JCheckBox showComplement; + /* * when true, constructor is still executing - so ignore UI events */ @@ -180,6 +183,12 @@ public class FeatureSettings extends JPanel 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 typeWidth = null; @@ -448,12 +457,10 @@ public class FeatureSettings extends JPanel 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()); @@ -484,32 +491,23 @@ public class FeatureSettings extends JPanel 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); @@ -566,6 +564,47 @@ public class FeatureSettings extends JPanel 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 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 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() { @@ -1267,26 +1306,32 @@ public class FeatureSettings extends JPanel } }); - 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); + } } }); @@ -1425,38 +1470,9 @@ public class FeatureSettings extends JPanel 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);