From: gmungoc Date: Wed, 17 May 2017 12:07:13 +0000 (+0100) Subject: JAL-2504 use (and update) defaults for new feature only if not supplied X-Git-Tag: Release_2_10_2~3^2~79^2^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=268dfe33ea14bbcdfb0671a1ec8acc5e9c423426;p=jalview.git JAL-2504 use (and update) defaults for new feature only if not supplied --- diff --git a/src/jalview/appletgui/APopupMenu.java b/src/jalview/appletgui/APopupMenu.java index cd49f63..8fd317a 100644 --- a/src/jalview/appletgui/APopupMenu.java +++ b/src/jalview/appletgui/APopupMenu.java @@ -843,7 +843,7 @@ public class APopupMenu extends java.awt.PopupMenu implements seqs = rseqs; if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs, - features, true, ap, null)) + features, true, ap)) { ap.alignFrame.sequenceFeatures.setState(true); ap.av.setShowSequenceFeatures(true); diff --git a/src/jalview/appletgui/FeatureRenderer.java b/src/jalview/appletgui/FeatureRenderer.java index 2db2cab..a6d0d99 100644 --- a/src/jalview/appletgui/FeatureRenderer.java +++ b/src/jalview/appletgui/FeatureRenderer.java @@ -63,6 +63,13 @@ import java.util.Hashtable; public class FeatureRenderer extends jalview.renderer.seqfeatures.FeatureRenderer { + /* + * creating a new feature defaults to the type and group as + * the last one created + */ + static String lastFeatureAdded = "feature_1"; + + static String lastFeatureGroupAdded = "Jalview"; // Holds web links for feature groups and feature types // in the form label|link @@ -79,12 +86,6 @@ public class FeatureRenderer extends } - static String lastFeatureAdded; - - static String lastFeatureGroupAdded; - - static String lastDescriptionAdded; - int featureIndex = 0; boolean deleteFeature = false; @@ -171,18 +172,19 @@ public class FeatureRenderer extends /** * Shows a dialog allowing the user to create, or amend or delete, sequence - * features. + * features. If null in the supplied feature(s), feature type and group + * default to those for the last feature created (with initial defaults of + * "feature_1" and "Jalview"). * * @param sequences * @param features * @param create * @param ap - * @param featureType * @return */ boolean amendFeatures(final SequenceI[] sequences, final SequenceFeature[] features, boolean create, - final AlignmentPanel ap, String featureType) + final AlignmentPanel ap) { final Panel bigPanel = new Panel(new BorderLayout()); final TextField name = new TextField(16); @@ -321,36 +323,16 @@ public class FeatureRenderer extends bigPanel.add(panel, BorderLayout.CENTER); } - if (featureType != null) - { - lastFeatureAdded = featureType; - } - else - { - if (lastFeatureAdded == null) - { - if (features[0].type != null) - { - lastFeatureAdded = features[0].type; - } - else - { - lastFeatureAdded = "feature_1"; - } - } - } - - if (lastFeatureGroupAdded == null) - { - if (features[0].featureGroup != null) - { - lastFeatureGroupAdded = features[0].featureGroup; - } - else - { - lastFeatureAdded = "Jalview"; - } - } + /* + * use defaults for type and group (and update them on Confirm) only + * if feature type has not been supplied by the caller + * (e.g. for Amend, or create features from Find) + */ + boolean useLastDefaults = features[0].getType() == null; + String featureType = useLastDefaults ? lastFeatureAdded : features[0] + .getType(); + String featureGroup = useLastDefaults ? lastFeatureGroupAdded + : features[0].getFeatureGroup(); String title = create ? MessageManager .getString("label.create_new_sequence_features") @@ -362,12 +344,10 @@ public class FeatureRenderer extends dialog.setMainPanel(bigPanel); - if (create) - { - name.setText(lastFeatureAdded); - group.setText(lastFeatureGroupAdded); - } - else + name.setText(featureType); + group.setText(featureGroup); + + if (!create) { dialog.ok.setLabel(MessageManager.getString("label.amend")); dialog.buttonPanel.add(deleteButton, 1); @@ -380,8 +360,6 @@ public class FeatureRenderer extends dialog.setVisible(false); } }); - name.setText(features[0].getType()); - group.setText(features[0].getFeatureGroup()); } start.setText(features[0].getBegin() + ""); @@ -413,29 +391,27 @@ public class FeatureRenderer extends FeaturesFile ffile = new FeaturesFile(); - if (dialog.accept) + /* + * only update default type and group if we used defaults + */ + if (dialog.accept && useLastDefaults) { lastFeatureAdded = name.getText().trim(); lastFeatureGroupAdded = group.getText().trim(); - lastDescriptionAdded = description.getText().replace('\n', ' '); - } - - if (lastFeatureGroupAdded != null && lastFeatureGroupAdded.length() < 1) - { - lastFeatureGroupAdded = null; } if (!create) { - SequenceFeature sf = features[featureIndex]; if (dialog.accept) { - boolean typeOrGroupChanged = (!lastFeatureAdded.equals(sf.type) || !lastFeatureGroupAdded - .equals(sf.featureGroup)); - sf.type = lastFeatureAdded; - sf.featureGroup = lastFeatureGroupAdded; - sf.description = lastDescriptionAdded; + sf.type = name.getText().trim(); + sf.featureGroup = group.getText().trim(); + if (sf.featureGroup != null && sf.featureGroup.length() < 1) + { + sf.featureGroup = null; + } + sf.description = description.getText().replace('\n', ' '); if (!colourPanel.isGcol) { // update colour - otherwise its already done. @@ -447,7 +423,10 @@ public class FeatureRenderer extends sf.end = Integer.parseInt(end.getText()); } catch (NumberFormatException ex) { + // } + boolean typeOrGroupChanged = (!featureType.equals(sf.type) || !featureGroup + .equals(sf.featureGroup)); ffile.parseDescriptionHTML(sf, false); if (typeOrGroupChanged) @@ -461,7 +440,6 @@ public class FeatureRenderer extends // ensure Feature Settings reflects removal of feature / group featuresAdded(); } - } else { @@ -472,9 +450,10 @@ public class FeatureRenderer extends { for (int i = 0; i < sequences.length; i++) { - features[i].type = lastFeatureAdded; - features[i].featureGroup = lastFeatureGroupAdded; - features[i].description = lastDescriptionAdded; + features[i].type = name.getText().trim(); + features[i].featureGroup = group.getText().trim(); + features[i].description = description.getText() + .replace('\n', ' '); sequences[i].addSequenceFeature(features[i]); ffile.parseDescriptionHTML(features[i], false); } diff --git a/src/jalview/appletgui/Finder.java b/src/jalview/appletgui/Finder.java index 2579d91..a342736 100644 --- a/src/jalview/appletgui/Finder.java +++ b/src/jalview/appletgui/Finder.java @@ -130,7 +130,7 @@ public class Finder extends Panel implements ActionListener } if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs, - features, true, ap, searchString)) + features, true, ap)) { ap.alignFrame.sequenceFeatures.setState(true); av.setShowSequenceFeatures(true); diff --git a/src/jalview/appletgui/SeqPanel.java b/src/jalview/appletgui/SeqPanel.java index 708bc6b..d46cc34 100644 --- a/src/jalview/appletgui/SeqPanel.java +++ b/src/jalview/appletgui/SeqPanel.java @@ -575,7 +575,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, if (features != null && features.length > 0) { seqCanvas.getFeatureRenderer().amendFeatures( - new SequenceI[] { sequence }, features, false, ap, null); + new SequenceI[] { sequence }, features, false, ap); seqCanvas.highlightSearchResults(null); } diff --git a/src/jalview/gui/FeatureRenderer.java b/src/jalview/gui/FeatureRenderer.java index 0921a48..2f12eef 100644 --- a/src/jalview/gui/FeatureRenderer.java +++ b/src/jalview/gui/FeatureRenderer.java @@ -66,6 +66,14 @@ import javax.swing.event.DocumentListener; public class FeatureRenderer extends jalview.renderer.seqfeatures.FeatureRenderer { + /* + * defaults for creating a new feature are the last created + * feature type and group + */ + static String lastFeatureAdded = "feature_1"; + + static String lastFeatureGroupAdded = "Jalview"; + Color resBoxColour; AlignmentPanel ap; @@ -87,16 +95,6 @@ public class FeatureRenderer extends } } - // // ///////////// - // // Feature Editing Dialog - // // Will be refactored in next release. - - static String lastFeatureAdded; - - static String lastFeatureGroupAdded; - - static String lastDescriptionAdded; - FeatureColourI oldcol, fcol; int featureIndex = 0; @@ -109,27 +107,25 @@ public class FeatureRenderer extends *
  • Create sequence feature from pop-up menu on selected region
  • *
  • Create features for pattern matches from Find
  • * + * If the supplied feature type is null, show (and update on confirm) the type + * and group of the last new feature created (with initial defaults of + * "feature_1" and "Jalview"). * * @param sequences * the sequences features are to be created on (if creating * features), or a single sequence (if amending features) * @param features * the current features at the position (if amending), or template - * new features with start/end position set (if creating) + * new feature(s) with start/end position set (if creating) * @param create * true to create features, false to amend or delete - * @param featureType - * the feature type to set on new features; if null, defaults to the - * type of the last new feature created if any, failing that to - * "feature_1" * @param alignPanel * @return */ protected boolean amendFeatures(final List sequences, final List features, boolean create, - final AlignmentPanel alignPanel, String featureType) + final AlignmentPanel alignPanel) { - featureIndex = 0; final JPanel mainPanel = new JPanel(new BorderLayout()); @@ -344,48 +340,18 @@ public class FeatureRenderer extends mainPanel.add(descriptionPanel, BorderLayout.CENTER); } + /* + * default feature type and group to that of the first feature supplied, + * or to the last feature created if not supplied (null value) + */ SequenceFeature firstFeature = features.get(0); - if (featureType != null) - { - lastFeatureAdded = featureType; - } - else - { - if (lastFeatureAdded == null) - { - if (firstFeature.type != null) - { - lastFeatureAdded = firstFeature.type; - } - else - { - lastFeatureAdded = "feature_1"; - } - } - } - - if (lastFeatureGroupAdded == null) - { - if (firstFeature.featureGroup != null) - { - lastFeatureGroupAdded = firstFeature.featureGroup; - } - else - { - lastFeatureGroupAdded = "Jalview"; - } - } - - if (create) - { - name.setText(lastFeatureAdded); - group.setText(lastFeatureGroupAdded); - } - else - { - name.setText(firstFeature.getType()); - group.setText(firstFeature.getFeatureGroup()); - } + boolean useLastDefaults = firstFeature.getType() == null; + final String featureType = useLastDefaults ? lastFeatureAdded + : firstFeature.getType(); + final String featureGroup = useLastDefaults ? lastFeatureGroupAdded + : firstFeature.getFeatureGroup(); + name.setText(featureType); + group.setText(featureGroup); start.setValue(new Integer(firstFeature.getBegin())); end.setValue(new Integer(firstFeature.getEnd())); @@ -422,13 +388,18 @@ public class FeatureRenderer extends if (reply == JvOptionPane.OK_OPTION && name.getText().length() > 0) { - lastFeatureAdded = name.getText().trim(); - lastFeatureGroupAdded = group.getText().trim(); - lastDescriptionAdded = description.getText().replaceAll("\n", " "); - // TODO: determine if the null feature group is valid - if (lastFeatureGroupAdded.length() < 1) + /* + * update default values only if creating using default values + */ + if (useLastDefaults) { - lastFeatureGroupAdded = null; + lastFeatureAdded = name.getText().trim(); + lastFeatureGroupAdded = group.getText().trim(); + // TODO: determine if the null feature group is valid + if (lastFeatureGroupAdded.length() < 1) + { + lastFeatureGroupAdded = null; + } } } @@ -449,13 +420,14 @@ public class FeatureRenderer extends { /* * YES_OPTION corresponds to the Amend button + * need to refresh Feature Settings if type, group or colour changed */ - boolean refreshSettings = (!lastFeatureAdded.equals(sf.type) || !lastFeatureGroupAdded + sf.type = name.getText().trim(); + sf.featureGroup = group.getText().trim(); + sf.description = description.getText().replaceAll("\n", " "); + boolean refreshSettings = (!featureType.equals(sf.type) || !featureGroup .equals(sf.featureGroup)); refreshSettings |= (fcol != oldcol); - sf.type = lastFeatureAdded; - sf.featureGroup = lastFeatureGroupAdded; - sf.description = lastDescriptionAdded; setColour(sf.type, fcol); @@ -482,10 +454,10 @@ public class FeatureRenderer extends for (int i = 0; i < sequences.size(); i++) { SequenceFeature sf = features.get(i); - sf.type = lastFeatureAdded; + sf.type = name.getText().trim(); // fix for JAL-1538 - always set feature group here - sf.featureGroup = lastFeatureGroupAdded; - sf.description = lastDescriptionAdded; + sf.featureGroup = group.getText().trim(); + sf.description = description.getText().replaceAll("\n", " "); sequences.get(i).addSequenceFeature(sf); ffile.parseDescriptionHTML(sf, false); } diff --git a/src/jalview/gui/Finder.java b/src/jalview/gui/Finder.java index 21c6c8a..625fc27 100755 --- a/src/jalview/gui/Finder.java +++ b/src/jalview/gui/Finder.java @@ -227,7 +227,7 @@ public class Finder extends GFinder } if (ap.getSeqPanel().seqCanvas.getFeatureRenderer().amendFeatures(seqs, - features, true, ap, searchString)) + features, true, ap)) { /* * ensure feature display is turned on to show the new features, diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 09e3263..3de7c3c 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -1904,13 +1904,12 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener if (start <= end) { seqs.add(sg.getSequenceAt(i).getDatasetSequence()); - features.add(new SequenceFeature(null, null, null, start, end, - "Jalview")); + features.add(new SequenceFeature(null, null, null, start, end, null)); } } if (ap.getSeqPanel().seqCanvas.getFeatureRenderer().amendFeatures(seqs, - features, true, ap, null)) + features, true, ap)) { ap.alignFrame.setShowSeqFeatures(true); ap.highlightSearchResults(null); diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index a2c2bd9..de44aa0 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -1570,7 +1570,7 @@ public class SeqPanel extends JPanel implements MouseListener, */ List seqs = Collections.singletonList(sequence); seqCanvas.getFeatureRenderer().amendFeatures(seqs, features, false, - ap, null); + ap); seqCanvas.highlightSearchResults(null); } }