import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import javax.swing.JColorChooser;
import javax.swing.JComboBox;
AlignmentPanel ap;
+ /*
+ * the colour scheme selected by the user for the current feature type
+ * when amending features
+ */
+ FeatureColourI fcol;
+
+ int featureIndex = 0;
+
/**
* Creates a new FeatureRenderer object
*
}
}
- FeatureColourI oldcol, fcol;
-
- int featureIndex = 0;
-
/**
* Presents a dialog allowing the user to add new features, or amend or delete
* existing features. Currently this can be on
final List<SequenceFeature> features, boolean create,
final AlignmentPanel alignPanel)
{
+ /*
+ * save original colours, for reset on Cancel
+ */
+ Map<String, FeatureColourI> oldColours = new HashMap<>();
+ for (SequenceFeature sf : features)
+ {
+ String type = sf.getType();
+ if (type != null)
+ {
+ oldColours.put(type, getFeatureStyle(type));
+ }
+ }
+
featureIndex = 0;
final JPanel mainPanel = new JPanel(new BorderLayout());
@Override
public void mousePressed(MouseEvent evt)
{
+ final String ft = features.get(featureIndex).getType();
+ final String type = ft == null ? lastFeatureAdded : ft;
if (fcol.isSimpleColour())
{
Color col = JColorChooser.showDialog(Desktop.desktop,
if (col != null)
{
fcol = new FeatureColour(col);
+ setColour(type, fcol);
+ alignPanel.paintAlignment(true, true);
updateColourButton(mainPanel, colour, fcol);
}
}
{
if (fcc == null)
{
- final String ft = features.get(featureIndex).getType();
- final String type = ft == null ? lastFeatureAdded : ft;
fcc = new FeatureColourChooser(me, type);
fcc.setRequestFocusEnabled(true);
fcc.requestFocus();
col = new FeatureColour(
ColorUtils.createColourFromName(name.getText()));
}
- oldcol = fcol = col;
+ fcol = col;
updateColourButton(mainPanel, colour, col);
}
});
start.setValue(new Integer(firstFeature.getBegin()));
end.setValue(new Integer(firstFeature.getEnd()));
description.setText(firstFeature.getDescription());
- updateColourButton(mainPanel, colour,
- (oldcol = fcol = getFeatureStyle(featureType)));
+ fcol = getFeatureStyle(featureType);
+ oldColours.put(featureType, fcol);
+ updateColourButton(mainPanel, colour, fcol);
Object[] options;
if (!create)
{
*/
boolean refreshSettings = (!featureType.equals(enteredType) || !featureGroup
.equals(enteredGroup));
- refreshSettings |= (fcol != oldcol);
+ refreshSettings |= (fcol != oldColours.get(featureType));
setColour(enteredType, fcol);
int newBegin = sf.begin;
int newEnd = sf.end;
featuresAdded();
}
}
+ else
+ {
+ // Cancel: reset any colour changes applied
+ resetColours(oldColours);
+ }
}
else
// NEW FEATURES ADDED
}
else
{
+ // Cancel: reset any colour changes applied
+ resetColours(oldColours);
return false;
}
}
}
/**
+ * Reset features to their original colours (on Cancel)
+ *
+ * @param colours
+ */
+ private void resetColours(Map<String, FeatureColourI> colours)
+ {
+ for (Entry<String, FeatureColourI> entry : colours.entrySet())
+ {
+ setColour(entry.getKey(), entry.getValue());
+ }
+ }
+
+ /**
* Show a warning message if the entered type is one that is currently hidden
*
* @param panel