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);
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
}
- static String lastFeatureAdded;
-
- static String lastFeatureGroupAdded;
-
- static String lastDescriptionAdded;
-
int featureIndex = 0;
boolean deleteFeature = false;
/**
* 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);
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")
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);
dialog.setVisible(false);
}
});
- name.setText(features[0].getType());
- group.setText(features[0].getFeatureGroup());
}
start.setText(features[0].getBegin() + "");
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.
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)
// ensure Feature Settings reflects removal of feature / group
featuresAdded();
}
-
}
else
{
{
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);
}
}
if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
- features, true, ap, searchString))
+ features, true, ap))
{
ap.alignFrame.sequenceFeatures.setState(true);
av.setShowSequenceFeatures(true);
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);
}
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;
}
}
- // // /////////////
- // // Feature Editing Dialog
- // // Will be refactored in next release.
-
- static String lastFeatureAdded;
-
- static String lastFeatureGroupAdded;
-
- static String lastDescriptionAdded;
-
FeatureColourI oldcol, fcol;
int featureIndex = 0;
* <li>Create sequence feature from pop-up menu on selected region</li>
* <li>Create features for pattern matches from Find</li>
* </ul>
+ * 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<SequenceI> sequences,
final List<SequenceFeature> features, boolean create,
- final AlignmentPanel alignPanel, String featureType)
+ final AlignmentPanel alignPanel)
{
-
featureIndex = 0;
final JPanel mainPanel = new JPanel(new BorderLayout());
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()));
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;
+ }
}
}
{
/*
* 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);
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);
}
}
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,
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);
*/
List<SequenceI> seqs = Collections.singletonList(sequence);
seqCanvas.getFeatureRenderer().amendFeatures(seqs, features, false,
- ap, null);
+ ap);
seqCanvas.highlightSearchResults(null);
}
}