-
- String title = create
- ? MessageManager.getString("label.create_new_sequence_features")
- : MessageManager.formatMessage("label.amend_delete_features",
- new String[]
- { sequences.get(0).getName() });
-
- /*
- * register responses and show the dialog
- */
- JvOptionPane.newOptionDialog(Desktop.desktop).response(
-
- new RunResponse(JvOptionPane.OK_OPTION)
- {
- public void run()
- {
- final String enteredType = name.getText().trim();
- final String enteredGroup = group.getText().trim();
- final String enteredDescription = description.getText()
- .replaceAll("\n", " ");
- if (enteredType.length() > 0)
-
- {
- /*
- * update default values only if creating using default values
- */
- if (useLastDefaults)
- {
- lastFeatureAdded = enteredType;
- lastFeatureGroupAdded = enteredGroup;
- // TODO: determine if the null feature group is valid
- if (lastFeatureGroupAdded.length() < 1)
- {
- lastFeatureGroupAdded = null;
- }
- }
- }
-
- if (create)
- {
- // NEW FEATURES ADDED
- if (enteredType.length() > 0)
- {
- for (int i = 0; i < sequences.size(); i++)
- {
- SequenceFeature sf = features.get(i);
- SequenceFeature sf2 = new SequenceFeature(enteredType,
- enteredDescription, sf.getBegin(),
- sf.getEnd(), enteredGroup);
- new FeaturesFile().parseDescriptionHTML(sf2, false);
- sequences.get(i).addSequenceFeature(sf2);
- }
-
- fr.setColour(enteredType, featureColour);
-
- fr.featuresAdded();
-
- responseHandler.run();
- }
- } else {
- SequenceFeature sf = features.get(featureIndex);
- /*
- * Feature amended - YES_OPTION corresponds to the Amend button
- * need to refresh Feature Settings if type, group or colour changed;
- * note we don't force the feature to be visible - the user has been
- * warned if a hidden feature type or group was entered
- */
- boolean refreshSettings = (!featureType.equals(enteredType)
- || !featureGroup.equals(enteredGroup));
- refreshSettings |= (featureColour != oldColour);
- fr.setColour(enteredType, featureColour);
- int newBegin = sf.begin;
- int newEnd = sf.end;
- try
- {
- newBegin = ((Integer) start.getValue()).intValue();
- newEnd = ((Integer) end.getValue()).intValue();
- } catch (NumberFormatException ex)
- {
- // JSpinner doesn't accept invalid format data :-)
- }
-
- /*
- * replace the feature by deleting it and adding a new one
- * (to ensure integrity of SequenceFeatures data store)
- */
- sequences.get(0).deleteFeature(sf);
- SequenceFeature newSf = new SequenceFeature(sf, enteredType,
- newBegin, newEnd, enteredGroup, sf.getScore());
- newSf.setDescription(enteredDescription);
- new FeaturesFile().parseDescriptionHTML(newSf, false);
- // amend features dialog only updates one sequence at a time
- sequences.get(0).addSequenceFeature(newSf);
-
- if (refreshSettings)
- {
- fr.featuresAdded();
- }
- }
- ap.getSeqPanel().seqCanvas.highlightSearchResults(null,
- false);
- ap.paintAlignment(true, true);
- }
- }).response(new RunResponse(JvOptionPane.NO_OPTION)
- {
- public void run()
- {
- SequenceFeature sf = features.get(featureIndex);
- /*
- * NO_OPTION corresponds to the Delete button
- */
- sequences.get(0).getDatasetSequence().deleteFeature(sf);
- // update Feature Settings for removal of feature / group
- fr.featuresAdded();
- ap.getSeqPanel().seqCanvas.highlightSearchResults(null,
- false);
- ap.paintAlignment(true, true);
- }
- }).defaultResponse(new Runnable()
+
+ dialog.showInternalDialog(mainPanel, title,
+ JvOptionPane.YES_NO_CANCEL_OPTION, JvOptionPane.PLAIN_MESSAGE,
+ null, options, MessageManager.getString("action.ok"));
+ }
+
+ /**
+ * Answers an action to run on Cancel in the dialog. This is just to remove
+ * any feature highlighting from the display. Changes in the dialog are not
+ * applied until it is dismissed with OK, Amend or Delete, so there are no
+ * updates to reset on Cancel.
+ *
+ * @return
+ */
+ protected Runnable getCancelAction()
+ {
+ Runnable okAction = () -> {
+ ap.highlightSearchResults(null);
+ ap.paintAlignment(false, false);
+ };
+ return okAction;
+ }
+
+ /**
+ * Returns the action to be run on OK in the dialog when creating one or more
+ * sequence features. Note these may have a pre-supplied feature type (such as
+ * a Find pattern), or none, in which case the feature type and group default
+ * to those last added through this dialog. The action includes refreshing the
+ * Feature Settings panel (if it is open), to show any new feature type, or
+ * amended colour for an existing type.
+ *
+ * @return
+ */
+ protected Runnable getCreateAction()
+ {
+ Runnable okAction = new Runnable()
+ {
+ boolean useLastDefaults = features.get(0).getType() == null;
+
+ @Override
+ public void run()
+ {
+ final String enteredType = name.getText().trim();
+ final String enteredGroup = group.getText().trim();
+ final String enteredDescription = description.getText()
+ .replaceAll("\n", " ");
+ if (enteredType.length() > 0)
+ {
+ /*
+ * update default values only if creating using default values
+ */
+ if (useLastDefaults)
+ {
+ lastFeatureAdded = enteredType;
+ lastFeatureGroupAdded = enteredGroup;
+ // TODO: determine if the null feature group is valid
+ if (lastFeatureGroupAdded.length() < 1)