コード例 #1
0
  /*  Start AnnotationChangeListenter interface */
  public boolean handleAnnotationChangeEvent(AnnotationChangeEvent evt) {
    if (this.isVisible() && evt.getSource() != this) {
      if (evt.isCompound()) {
        for (int i = 0; i < evt.getNumberOfChildren(); ++i) {
          handleAnnotationChangeEvent(evt.getChildChangeEvent(i));
        }
        reformatAnnotationPanel();
        return true;
      }

      // can probably be done better, this will reformat the panel a lot
      reformatAnnotationPanel();

      if (evt.isEndOfEditSession()) {

        getOverview().updateState();
        setSelection(getSelection());
        updateEditRegion();

        repaint();
        updateTitle();
      }

      if (evt.isAdd()) {
        AnnotatedFeatureI annotToDisplay = null;
        AnnotatedFeatureI gene = evt.getChangedAnnot();
        int trans_count = gene.size();
        for (int i = 0; i < trans_count; ++i) {
          Transcript t = (Transcript) gene.getFeatureAt(i);
          if (evt.isUndo()) {
            // System.out.printf("Attaching %s(%d)\n", t, t.hashCode());
            // addFeatureToPanel(t, getAnnotationPanel());
            if (getSelection() != null && t.getName().equals(getSelection().getName())) {
              annotToDisplay = t;
            }
          }
        }

        if (annotToDisplay == null) {
          annotToDisplay = (AnnotatedFeatureI) evt.getChangedAnnot().getFeatureAt(0);
        } else {
          setSelection(annotToDisplay);
        }

        getOverview().updateState();
      }

      if (evt.isDelete()) {}
    }

    repaint();
    return true;
  }
コード例 #2
0
  public boolean handleAnnotationChangeEvent(AnnotationChangeEvent evt) {
    if (this.isVisible() && evt.getSource() != this) {
      if (evt.isCompound()) {
        for (int i = 0; i < evt.getNumberOfChildren(); ++i) {
          handleAnnotationChangeEvent(evt.getChildChangeEvent(i));
        }
        return true;
      }

      if (evt.isEndOfEditSession()) {
        // Dont want scrolling on ann change, also sf for redraw is the
        // gene, so it just goes to 1st trans which is problematic.
        displayAnnot(currentAnnot);
        repaint(); // this is the needed repaint after the changes
        return true;
      }

      /*
      AnnotatedFeatureI gene = evt.getChangedAnnot();
      for (Object o : szap.getAnnotations().getFeatures()) {
        AnnotatedFeatureI feat = (AnnotatedFeatureI)o;
        if (feat.getId().equals(gene.getId())) {
          //gene = feat;
          break;
        }
      }
      */

      if (evt.isAdd()) {
        AnnotatedFeatureI annotToDisplay = null;
        AnnotatedFeatureI gene = evt.getChangedAnnot();
        int trans_count = gene.size();
        for (int i = 0; i < trans_count; ++i) {
          Transcript t = (Transcript) gene.getFeatureAt(i);
          if (evt.isUndo()) {
            // System.out.printf("Attaching %s(%d)\n", t, t.hashCode());
            editorPanel.attachAnnot(t);
            if (currentAnnot != null && t.getName().equals(currentAnnot.getName())) {
              annotToDisplay = t;
            }
          }
        }
        if (annotToDisplay == null) {
          annotToDisplay = (AnnotatedFeatureI) evt.getChangedAnnot().getFeatureAt(0);
        }
        displayAnnot(annotToDisplay);
        return true;
      }

      if (evt.isDelete()) {
        AnnotatedFeatureI gene = evt.getChangedAnnot();
        int trans_count = gene.size();
        for (int i = 0; i < trans_count; ++i) {
          if (evt.isUndo()) {
            Transcript t = (Transcript) gene.getFeatureAt(i);
            // System.out.printf("Detaching %s(%d)\n", t, t.hashCode());
            editorPanel.detachTranscript(t);
          }
        }
        return true;
      }

      /*
            // getAnnotation() can be null after a delete - return if null?
            SeqFeatureI sf = evt.getAnnotTop();

            // If the annotation event is not for the editors strand then return
            boolean is_reverse = (sf.getStrand() == -1);
            if (editorPanel.getReverseStrand() != is_reverse)
              return false;

            if (evt.isDelete() && evt.isRootAnnotChange()) {
              AnnotatedFeatureI gene = evt.getChangedAnnot();
              int trans_count = gene.size();
              for (int i = 0; i < trans_count; i++) {
                Transcript t = (Transcript) gene.getFeatureAt (i);
                editorPanel.detachTranscript (t);
                if (t == currentAnnot)
                  currentAnnot = null;
              }
            } else if (evt.isDelete() && evt.isTranscriptChange()) {
              Transcript t = (Transcript) evt.getChangedAnnot();
              editorPanel.detachTranscript (t);
              if (t == currentAnnot)
                currentAnnot = null;
            } else if ((evt.isAdd() || evt.isSplit() || evt.isMerge()) &&
                       evt.isRootAnnotChange()) {
              AnnotatedFeatureI gene = evt.getChangedAnnot();
              int trans_count = gene.size();
              for (int i = 0; i < trans_count; i++) {
                Transcript t = (Transcript) gene.getFeatureAt (i);
                int tier = editorPanel.attachAnnot (t);
              }
            } else if (evt.isAdd() && evt.isTranscriptChange()) {
              Transcript t = (Transcript) evt.getChangedAnnot();
              int tier = editorPanel.attachAnnot (t);
            }
            // Exon split or intron made - same thing isnt it?
            else if (evt.isAdd() && evt.isExonChange()) {
              Transcript t = (Transcript) evt.getParentFeature();
              // removing and adding transcript will force editorPanel
              // to pick up new exon
              editorPanel.detachTranscript(t);
              editorPanel.attachAnnot(t);
            }
            else if (evt.isDelete() && evt.isExonChange()) {
              Transcript t = (Transcript) evt.getParentFeature();
              // removing and adding transcript will force editorPanel to remove exon
              editorPanel.detachTranscript(t);
              editorPanel.attachAnnot(t);
              // or editorPanel.removeFeature((Exon)evt.getSecondFeature());
            }
      //       else if (evt.isReplace()) { //&&evt.isTopAnnotChange - always true of replace
      //         AnnotatedFeatureI old_gene = evt.getReplacedFeature();
      //         AnnotatedFeatureI new_gene = (AnnotatedFeatureI)evt.getChangedFeature();
      //         int trans_count = old_gene.size();
      //         /* This does assume that there are no changes in the number
      //            of transcripts between the old and the new. Might be safer
      //            to separate the 2 loops */
      //         for (int i = 0; i < trans_count; i++) {
      //           Transcript t;
      //           t = (Transcript) old_gene.getFeatureAt (i);
      //           editorPanel.detachTranscript (t);
      //           t = (Transcript) new_gene.getFeatureAt (i);
      //           int tier = editorPanel.attachTranscript (t);
      //         }
      //         // This is so that we don't select a different transcript
      //         AnnotatedFeatureI current_gene = (current_transcript != null ?
      //                                           current_transcript.getGene() : null);
      //         if (current_gene != null && current_gene == old_gene) {
      //           int index = current_gene.getFeatureIndex(current_transcript);
      //           current_transcript = (Transcript) new_gene.getFeatureAt(index);
      //         }
      //       }
      // this isnt possible - all replaces are for top annots
      //       else if (evt.isReplace() && evt.isTranscriptChange()) {
      //         Transcript old_trans = (Transcript)evt.getReplacedFeature();
      //         Transcript new_trans = (Transcript)evt.getChangedFeature();
      //         editorPanel.detachTranscript (old_trans);
      //         int tier = editorPanel.attachTranscript (new_trans);
      //         // This is so that we don't select a different transcript
      //         if (current_transcript != null && current_transcript == old_trans) {
      //           current_transcript = new_trans;
      //         }
      //       }
    }

    return true;
  }