X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FFeatureSettings.java;h=b87e4bf92c10de36e2a0b7cf827a5dd5341871f3;hb=85283704c950febdca739d7dd857a1068cd73bbb;hp=dc7283bfed29df19729799de0a75a98b89994e3f;hpb=5dc249708303dd777f4570bb66335150a8beab07;p=jalview.git diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index dc7283b..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; @@ -188,12 +197,22 @@ public class FeatureSettings extends JPanel { // save transparency for restore on Cancel originalTransparency = fr.getTransparency(); - int originalTransparencyAsPercent = (int) (originalTransparency * 100); - transparency.setMaximum(100 - originalTransparencyAsPercent); + + updateTransparencySliderFromFR(); originalFilters = new HashMap<>(fr.getFeatureFilters()); // shallow copy originalViewStyle = new ViewStyle(af.viewport.getViewStyle()); } + + private void updateTransparencySliderFromFR() + { + boolean incon = inConstruction; + inConstruction = true; + + int transparencyAsPercent = (int) (fr.getTransparency() * 100); + transparency.setValue(100 - transparencyAsPercent); + inConstruction = incon; + } /** * Constructor * @@ -203,7 +222,9 @@ public class FeatureSettings extends JPanel { this.af = alignFrame; fr = af.getFeatureRenderer(); + storeOriginalSettings(); + try { jbInit(); @@ -436,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()); @@ -472,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); @@ -554,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() { @@ -1255,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); + } } }); @@ -1310,6 +1367,7 @@ public class FeatureSettings extends JPanel public void actionPerformed(ActionEvent e) { revert(); + refreshDisplay(); if (!hasComplement) { close(); @@ -1412,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); @@ -2052,6 +2081,7 @@ public class FeatureSettings extends JPanel fr.setFeatureFilters(originalFilters); updateFeatureRenderer(originalData); af.getViewport().setViewStyle(originalViewStyle); + updateTransparencySliderFromFR(); updateComplementButtons(); refreshDisplay(); }