- }
- if (allfeatures.size() == 0)
- {
- // no new features - leave order unchanged.
- return;
- }
- int i = allfeatures.size() - 1;
- int iSize = i;
- boolean sort = false;
- String[] newf = new String[allfeatures.size()];
- float[] sortOrder = new float[allfeatures.size()];
- Enumeration en = allfeatures.elements();
- // sort remaining elements
- while (en.hasMoreElements())
- {
- newf[i] = en.nextElement().toString();
- if (initOrders || !featureOrder.containsKey(newf[i]))
- {
- int denom = initOrders ? allfeatures.size() : featureOrder.size();
- // new unordered feature - compute persistent ordering at head of
- // existing features.
- setOrder(newf[i], i / (float) denom);
- }
- // set order from newly found feature from persisted ordering.
- sortOrder[i] = 2 - ((Float) featureOrder.get(newf[i])).floatValue();
- if (i < iSize)
- {
- // only sort if we need to
- sort = sort || sortOrder[i] > sortOrder[i + 1];
- }
- i--;
- }
- if (iSize > 1 && sort)
- jalview.util.QuickSort.sort(sortOrder, newf);
- sortOrder = null;
- System.arraycopy(newf, 0, renderOrder, opos, newf.length);
- }
-
- public Color getColour(String featureType)
- {
- Object fc = featureColours.get(featureType);
- if (fc == null)
- {
- jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme();
- Color col = ucs.createColourFromName(featureType);
- featureColours.put(featureType, col);
- return col;
- }
- else if (fc instanceof Color)
- {
- return (Color) fc;
- }
- else
- {
- if (fc instanceof GraduatedColor)
- {
- return ((GraduatedColor) fc).getMinColor();
- }
- // TODO: raise an implementation error here.
- return null; // Color.white;
- }
- }
-
- /**
- * implement graduated colouring for features with scores
- *
- * @param feature
- * @return render colour for the given feature
- */
- public Color getColour(SequenceFeature feature)
- {
- Object fc = featureColours.get(feature.type);
- if (fc == null)
- {
- jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme();
- Color col = ucs.createColourFromName(feature.type);
- featureColours.put(feature.type, col);
- return col;
- }
- else if (fc instanceof Color)
- {
- return (Color) fc;
- }
- else
- {
- if (fc instanceof GraduatedColor)
- {
- return ((GraduatedColor) fc).findColor(feature);
- }
- // TODO: raise an implementation error here.
- return null; // Color.white;
- }
- }
- private boolean showFeature(SequenceFeature sequenceFeature)
- {
- Object fc = featureColours.get(sequenceFeature.type);
- if (fc instanceof GraduatedColor)
- {
- return ((GraduatedColor) fc).isColored(sequenceFeature);
- } else { return true; }
- }
-
-
- static String lastFeatureAdded;
-
- static String lastFeatureGroupAdded;
-
- static String lastDescriptionAdded;
-
- int featureIndex = 0;
-
- boolean amendFeatures(final SequenceI[] sequences,
- final SequenceFeature[] features, boolean newFeatures,
- final AlignmentPanel ap)
- {
-
- featureIndex = 0;
-
- JPanel bigPanel = new JPanel(new BorderLayout());
- final JComboBox overlaps;
- final JTextField name = new JTextField(25);
- final JTextField source = new JTextField(25);
- final JTextArea description = new JTextArea(3, 25);
- final JSpinner start = new JSpinner();
- final JSpinner end = new JSpinner();
- start.setPreferredSize(new Dimension(80, 20));
- end.setPreferredSize(new Dimension(80, 20));
-
- final JPanel colour = new JPanel();
- colour.setBorder(BorderFactory.createEtchedBorder());
- colour.setMaximumSize(new Dimension(40, 10));
- colour.addMouseListener(new MouseAdapter()
- {
- public void mousePressed(MouseEvent evt)
- {
- // TODO: use featurecolourchooser here
- Color col = JColorChooser.showDialog(Desktop.desktop,
- "Select Feature Colour", colour.getBackground());
- if (col != null)
- colour.setBackground(col);
-
- }