private Annotation findAnnotationOfFeature(Feature f) {
   List<Annotation> annotations = plasmid.getAnnotations();
   for (int i = 0; i < annotations.size(); i++) {
     org.autogene.core.bio.entities.Feature o = annotations.get(i).getFeature();
     if (f.getLabel().equals(o.getDisplayName())) return annotations.get(i);
   }
   return null;
 }
  /* Searches for the "SELECTED" feature and removes it if it exists */
  void removeSelectedFeature() {
    boolean found = true;
    ArrayList<FeatureSlot> slots = cgview.getFeatureSlots();
    for (int i = 0; i < slots.size(); i++) {
      FeatureSlot fs = slots.get(i);
      ArrayList<Feature> features = fs.getFeatures();
      for (int j = 0; j < features.size(); j++) {
        Feature f = features.get(j);
        if (f.getLabel().equals("SELECTED")) {
          found = true;
          features.remove(j);
          break;
        }
      }

      if (found) break;
    }

    repaint();
  }
  @Override
  public void mousePressed(MouseEvent me) {

    /* Check to see if we clicked a label */

    int x = me.getX(), y = me.getY();

    Feature selectedFeature = null;
    ArrayList<OuterLabel> outerLabels = cgview.getOuterLabels();
    OuterLabel ol = null;
    for (int o = 0; o < outerLabels.size(); o++) {

      ol = outerLabels.get(o);
      Rectangle2D rect = ol.getBounds();

      double rectX = rect.getX(),
          rectY = rect.getY(),
          rectW = rect.getWidth(),
          rectH = rect.getHeight();

      if (x > rectX && x < (rectX + rectW) && y > rectY && y < (rectY + rectH)) {
        ArrayList<FeatureSlot> featureSlots = cgview.getFeatureSlots();

        for (int i = 0; i < featureSlots.size(); i++) {
          FeatureSlot fs = featureSlots.get(i);
          ArrayList<Feature> features = fs.getFeatures();
          for (int j = 0; j < features.size(); j++) {
            Feature f = features.get(j);
            String featureLabel = f.getLabel();

            if (featureLabel.equals(ol.getLabelText())) {
              selectedFeature = f;
              break;
            }

            if (selectedFeature != null) break;
          }

          if (selectedFeature != null) break;
        }
      }

      if (selectedFeature != null) break;
    }

    /* If we have selected a feature, either make it appear selected or
     * deselected. */
    if (selectedFeature != null) {

      // paint the feature on the cgview
      Annotation a = findAnnotationOfFeature(selectedFeature);

      Color toUse =
          (a.getScore() == 1.0)
              ? ColorConstants.NEUTRAL_COLOR_PERFECT_MATCH
              : ColorConstants.NEUTRAL_COLOR_IMPERFECT_MATCH;
      Color fColor = selectedFeature.getColor();
      Color blue =
          (a.getScore() == 1.0)
              ? ColorConstants.NEUTRAL_COLOR_PERFECT_MATCH
              : ColorConstants.NEUTRAL_COLOR_IMPERFECT_MATCH;
      Color orange = ColorConstants.ROW_SELECTED_COLOR;
      boolean isBlue =
          fColor.getRed() == blue.getRed()
              && fColor.getGreen() == blue.getGreen()
              && fColor.getBlue() == blue.getBlue();
      boolean isOrange =
          fColor.getRed() == orange.getRed()
              && fColor.getGreen() == orange.getGreen()
              && fColor.getBlue() == orange.getBlue();
      Color turq = ColorConstants.CUSTOM_ANNOTATION_COLOR;
      boolean isTurquoise =
          fColor.getRed() == turq.getRed()
              && fColor.getGreen() == turq.getGreen()
              && fColor.getBlue() == turq.getBlue();
      Color ye = ColorConstants.VIEW_FEATURE_FROM_PRIVATE_REGISTRY_COLOR;
      boolean isYellow =
          fColor.getRed() == ye.getRed()
              && fColor.getGreen() == ye.getGreen()
              && fColor.getBlue() == ye.getBlue();
      if (isBlue || isOrange || isTurquoise || isYellow) {
        toUse = ColorConstants.SELECTED_COLOR;
        selectedFeatures.add(selectedFeature.getLabel());
      } else if (((MyTableModel) home.getTable().getModel())
          .isFeatureSelected(selectedFeature.getLabel())) {
        toUse = ColorConstants.ROW_SELECTED_COLOR;
        selectedFeatures.remove(selectedFeature.getLabel());
      } else {
        toUse =
            (a.getScore() == 1.0)
                ? ColorConstants.NEUTRAL_COLOR_PERFECT_MATCH
                : ColorConstants.NEUTRAL_COLOR_IMPERFECT_MATCH;
        selectedFeatures.remove(selectedFeature.getLabel());
      }

      selectedFeature.setColor(toUse);

      ArrayList<FeatureRange> f = selectedFeature.getRanges();
      for (int n = 0; n < f.size(); n++) {
        f.get(n).setColor(toUse);
      }

      // ol.setColor(Color.red);

      repaint();

      // highlight text in the textpane
      FeatureRange fr = (FeatureRange) selectedFeature.getRanges().get(0);

      if (home != null) home.highlightDNA(fr);

    } else {
      System.out.println("selected feature is null");
    }
  }