- // If beginning and end are 0, the feature is for the whole sequence
- // and we don't want to render the feature in the normal way
-
- if (newMadeVisible && !oldfeatures.contains(features[index].getType())) {
- // this is a new feature type on the alignment. Mark it for
- // display.
- av.featuresDisplayed.put(features[index].getType(),
- new Integer(getColour(features[index].
- getType()).getRGB()));
- setOrder(features[index].getType(),0);
- }
- }
- }
- if (!allfeatures.contains(features[index].getType()))
- {
- allfeatures.addElement(features[index].getType());
- }
- index++;
- }
- }
- updateRenderOrder(allfeatures);
- findingFeatures = false;
- }
- protected boolean firing=false;
- /**
- * replaces the current renderOrder with the unordered features in allfeatures.
- * The ordering of any types in both renderOrder and allfeatures is preserved,
- * and all new feature types are rendered on top of the existing types, in
- * the order given by getOrder or the order given in allFeatures.
- * Note. this operates directly on the featureOrder hash for efficiency. TODO:
- * eliminate the float storage for computing/recalling the persistent ordering
- *
- * @param allFeatures
- */
- private void updateRenderOrder(Vector allFeatures) {
- Vector allfeatures = new Vector(allFeatures);
- String[] oldRender = renderOrder;
- renderOrder = new String[allfeatures.size()];
- boolean initOrders=(featureOrder==null);
- int opos=0;
- if (oldRender!=null && oldRender.length>0)
- {
- for (int j=0; j<oldRender.length; j++)
- {
- if (oldRender[j]!=null)
- {
- if (initOrders)
- {
- setOrder(oldRender[j], (1-(1+(float)j)/(float) oldRender.length));
- }
- if (allfeatures.contains(oldRender[j])) {
- renderOrder[opos++] = oldRender[j]; // existing features always
- // appear below new features
- allfeatures.removeElement(oldRender[j]);
- }
- }
- }
- }
- 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)
- {
- if (featureColours.get(featureType) == null)
- {
- jalview.schemes.UserColourScheme ucs = new
- jalview.schemes.UserColourScheme();
- Color col = ucs.createColourFromName(featureType);
- featureColours.put(featureType, col);
- return col;
- }
- else
- return (Color) featureColours.get(featureType);
- }