public void replaceFlameFromEditorBtn_clicked(Flame pFlame) {
    if (pFlame != null) {
      Flame flame = poolFlameHolder.getFlame();
      if (flame != null) {
        int idx = flamePropertiesTree.getSelectionRows()[0];
        // cant remove the flame by object reference because its a clone
        Flame newFlame = validateDancingFlame(pFlame.makeCopy());
        Flame oldFlame = project.getFlames().get(idx);
        for (Motion motion : project.getMotions()) {
          for (MotionLink link : motion.getMotionLinks()) {
            if (link.getProperyPath().getFlame().isEqual(oldFlame)) {
              link.getProperyPath().setFlame(newFlame);
            }
          }
        }

        project.getFlames().set(idx, newFlame);
        refreshProjectFlames();
        if (project.getFlames().size() == 0) {
          flamePropertiesTree_changed(null);
        } else {
          try {
            flamePropertiesTree.setSelectionRow(idx);
          } catch (Exception ex) {

          }
        }
        enableControls();
      }
    }
  }
 public void linkMotionBtn_clicked() {
   Motion currMotion = getSelectedMotion();
   if (currMotion != null
       && flamePropertiesTreeService.isPlainPropertySelected(flamePropertiesTree)) {
     FlamePropertyPath propertyPath =
         flamePropertiesTreeService.getSelectedPropertyPath(flamePropertiesTree);
     currMotion.getMotionLinks().add(new MotionLink(propertyPath));
     refreshMotionLinksTable();
     int selectRow = currMotion.getMotionLinks().size() - 1;
     motionLinksTable.getSelectionModel().setSelectionInterval(selectRow, selectRow);
     enableControls();
   }
 }
  private void enableControls() {
    loadSoundBtn.setEnabled(!running);
    addFromClipboardBtn.setEnabled(!running);
    addFromEditorBtn.setEnabled(!running);
    addFromDiscBtn.setEnabled(!running);
    randomCountIEd.setEnabled(!running);
    genRandFlamesBtn.setEnabled(!running);
    randomGenCmb.setEnabled(!running);
    boolean flameSelected = poolFlameHolder.getFlame() != null;
    flameToEditorBtn.setEnabled(flameSelected);
    deleteFlameBtn.setEnabled(flameSelected);
    renameFlameBtn.setEnabled(flameSelected);
    replaceFlameFromEditorBtn.setEnabled(flameSelected);

    framesPerSecondIEd.setEnabled(!running);
    borderSizeSlider.setEnabled(true);
    morphFrameCountIEd.setEnabled(true);
    startShowButton.setEnabled(!running && project.getFlames().size() > 0);
    stopShowButton.setEnabled(running);
    doRecordCBx.setEnabled(!running);

    motionTable.setEnabled(!running);
    addMotionCmb.setEnabled(!running);
    addMotionBtn.setEnabled(!running);
    Motion selMotion = getSelectedMotion();

    deleteMotionBtn.setEnabled(!running && selMotion != null);
    renameMotionBtn.setEnabled(deleteMotionBtn.isEnabled());
    boolean plainPropertySelected =
        flamePropertiesTreeService.isPlainPropertySelected(flamePropertiesTree);
    {
      boolean linkMotionEnabled = false;
      if (!running && selMotion != null && selMotion.getParent() == null) {
        if (plainPropertySelected) {
          FlamePropertyPath selPath =
              flamePropertiesTreeService.getSelectedPropertyPath(flamePropertiesTree);
          linkMotionEnabled = !selMotion.hasLink(selPath);
        }
      }
      linkMotionBtn.setEnabled(linkMotionEnabled);
      unlinkMotionBtn.setEnabled(
          selMotion != null
              && motionLinksTable.getSelectedRow() >= 0
              && motionLinksTable.getSelectedRow() < selMotion.getMotionLinks().size());
    }

    createMotionsCmb.setEnabled(!running);
    clearMotionsBtn.setEnabled(!running && project.getMotions().size() > 0);
    loadProjectBtn.setEnabled(!running);
    saveProjectBtn.setEnabled(!running);
  }
 public void unlinkMotionBtn_clicked() {
   Motion selMotion = getSelectedMotion();
   int row = motionLinksTable.getSelectedRow();
   if (selMotion != null && row >= 0 && row <= selMotion.getMotionLinks().size()) {
     int selRow = motionLinksTable.getSelectedRow();
     selMotion.getMotionLinks().remove(row);
     motionTableClicked();
     if (selRow >= selMotion.getMotionLinks().size()) {
       selRow--;
     }
     motionLinksTable.getSelectionModel().setSelectionInterval(selRow, selRow);
     enableControls();
   }
 }
 public void renameMotionBtn_clicked() {
   int row = motionTable.getSelectedRow();
   if (row >= 0 && row < project.getMotions().size()) {
     Motion motion = project.getMotions().get(row);
     String s =
         StandardDialogs.promptForText(
             rootTabbedPane, "Please enter the new title:", motion.getDisplayLabel());
     if (s != null) {
       motion.setCaption(s);
       refreshMotionTable();
       if (row >= project.getMotions().size()) {
         row--;
       }
       if (row >= 0) {
         motionTable.getSelectionModel().setSelectionInterval(row, row);
       }
       motionTableClicked();
       enableControls();
     }
   }
 }