public void renameFlameBtn_clicked() {
    try {
      Flame flame = poolFlameHolder.getFlame();
      if (flame != null) {
        int idx = flamePropertiesTree.getSelectionRows()[0];
        String s =
            StandardDialogs.promptForText(
                rootTabbedPane, "Please enter the new title:", flame.getName());
        if (s != null) {
          for (Flame tFlame : project.getFlames()) {
            if (!tFlame.isEqual(flame) && s.equals(tFlame.getName())) {
              throw new RuntimeException(
                  "A different flame with the name \"" + s + "\" alread exists");
            }
          }
          flame.setName(s);
          refreshProjectFlames();
          if (project.getFlames().size() == 0) {
            flamePropertiesTree_changed(null);
          } else {
            try {
              flamePropertiesTree.setSelectionRow(idx);
            } catch (Exception ex) {

            }
          }
          enableControls();
        }
      }
    } catch (Exception ex) {
      errorHandler.handleError(ex);
    }
  }
  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 deleteFlameBtn_clicked() {
   Flame flame = poolFlameHolder.getFlame();
   if (flame != null) {
     int idx = flamePropertiesTree.getSelectionRows()[0];
     // cant remove the flame by object reference because its a clone
     project.getFlames().remove(idx);
     refreshProjectFlames();
     if (project.getFlames().size() == 0) {
       flamePropertiesTree_changed(null);
     }
     enableControls();
   }
 }
 public void flameCmb_changed() {
   if (!refreshing && renderThread != null) {
     Flame selFlame =
         flamesCmb.getSelectedIndex() >= 0
                 && flamesCmb.getSelectedIndex() < project.getFlames().size()
             ? project.getFlames().get(flamesCmb.getSelectedIndex())
             : null;
     if (selFlame != null && renderThread != null) {
       int morphFrameCount = Integer.parseInt(morphFrameCountIEd.getText());
       renderThread
           .getFlameStack()
           .addFlame(selFlame, morphFrameCount, project.getMotions(selFlame));
       if (actionRecorder != null) actionRecorder.recordFlameChange(selFlame, morphFrameCount);
     }
   }
 }
 public void loadFlameButton_clicked() {
   try {
     JFileChooser chooser = new FlameFileChooser(prefs);
     if (prefs.getInputFlamePath() != null) {
       try {
         chooser.setCurrentDirectory(new File(prefs.getInputFlamePath()));
       } catch (Exception ex) {
         ex.printStackTrace();
       }
     }
     chooser.setMultiSelectionEnabled(true);
     if (chooser.showOpenDialog(poolFlamePreviewPnl) == JFileChooser.APPROVE_OPTION) {
       for (File file : chooser.getSelectedFiles()) {
         List<Flame> newFlames = new FlameReader(prefs).readFlames(file.getAbsolutePath());
         prefs.setLastInputFlameFile(file);
         if (newFlames != null && newFlames.size() > 0) {
           for (Flame newFlame : newFlames) {
             project.getFlames().add(validateDancingFlame(newFlame));
           }
         }
       }
       refreshProjectFlames();
       enableControls();
     }
   } catch (Throwable ex) {
     errorHandler.handleError(ex);
   }
 }
  public void genRandomFlames() {
    try {
      final int IMG_WIDTH = 80;
      final int IMG_HEIGHT = 60;
      int count = (int) ((Double) randomCountIEd.getValue() + 0.5);
      for (int i = 0; i < count; i++) {

        RandomFlameGenerator randGen =
            RandomFlameGeneratorList.getRandomFlameGeneratorInstance(
                (String) randomGenCmb.getSelectedItem(), true);
        int palettePoints = 3 + (int) (Math.random() * 68.0);
        boolean fadePaletteColors = Math.random() > 0.33;
        RandomFlameGeneratorSampler sampler =
            new RandomFlameGeneratorSampler(
                IMG_WIDTH,
                IMG_HEIGHT,
                prefs,
                randGen,
                RandomSymmetryGeneratorList.NONE,
                RandomGradientGeneratorList.DEFAULT,
                palettePoints,
                fadePaletteColors,
                RandomBatchQuality.NORMAL);
        project.getFlames().add(validateDancingFlame(sampler.createSample().getFlame()));
      }
      refreshProjectFlames();
      enableControls();
    } catch (Throwable ex) {
      errorHandler.handleError(ex);
    }
  }
 public void importFlame(Flame pFlame) {
   if (pFlame != null) {
     project.getFlames().add(validateDancingFlame(pFlame.makeCopy()));
     refreshProjectFlames();
     enableControls();
   }
 }
 private void refreshFlamesCmb() {
   Flame selFlame =
       flamesCmb.getSelectedIndex() >= 0
               && flamesCmb.getSelectedIndex() < project.getFlames().size()
           ? project.getFlames().get(flamesCmb.getSelectedIndex())
           : null;
   int newSelIdx = -1;
   flamesCmb.removeAllItems();
   for (int i = 0; i < project.getFlames().size(); i++) {
     Flame flame = project.getFlames().get(i);
     if (newSelIdx < 0 && flame.equals(selFlame)) {
       newSelIdx = i;
     }
     flamesCmb.addItem(flamePropertiesTreeService.getFlameCaption(flame));
   }
   flamesCmb.setSelectedIndex(
       newSelIdx >= 0 ? newSelIdx : project.getFlames().size() > 0 ? 0 : -1);
 }
 public void startRender() throws Exception {
   stopRender();
   Flame selFlame =
       flamesCmb.getSelectedIndex() >= 0
               && flamesCmb.getSelectedIndex() < project.getFlames().size()
           ? project.getFlames().get(flamesCmb.getSelectedIndex())
           : null;
   renderThread = new RealtimeAnimRenderThread(this, project);
   renderThread.getFlameStack().addFlame(selFlame, 0, project.getMotions(selFlame));
   actionRecorder = new ActionRecorder(renderThread);
   renderThread.setFFTData(project.getFFT());
   renderThread.setMusicPlayer(jLayer);
   renderThread.setFFTPanel(getGraph1Panel());
   renderThread.setFramesPerSecond(Integer.parseInt(framesPerSecondIEd.getText()));
   renderThread.setDrawTriangles(drawTrianglesCbx.isSelected());
   renderThread.setDrawFFT(drawFFTCbx.isSelected());
   renderThread.setDrawFPS(drawFPSCbx.isSelected());
   actionRecorder.recordStart(selFlame);
   new Thread(renderThread).start();
 }
  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 startShow() {
   try {
     if (project.getFlames().size() == 0) throw new Exception("No flames to animate");
     jLayer.stop();
     if (project.getSoundFilename() != null && project.getSoundFilename().length() > 0) {
       jLayer.play(project.getSoundFilename());
     }
     startRender();
     running = true;
     enableControls();
   } catch (Throwable ex) {
     errorHandler.handleError(ex);
   }
 }
 public void loadFlameFromClipboardButton_clicked() {
   List<Flame> newFlames = null;
   try {
     Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
     Transferable clipData = clipboard.getContents(clipboard);
     if (clipData != null) {
       if (clipData.isDataFlavorSupported(DataFlavor.stringFlavor)) {
         String xml = (String) (clipData.getTransferData(DataFlavor.stringFlavor));
         newFlames = new FlameReader(prefs).readFlamesfromXML(xml);
       }
     }
     if (newFlames == null || newFlames.size() < 1) {
       throw new Exception("There is currently no valid flame in the clipboard");
     } else {
       for (Flame newFlame : newFlames) {
         project.getFlames().add(validateDancingFlame(newFlame));
       }
       refreshProjectFlames();
       enableControls();
     }
   } catch (Throwable ex) {
     errorHandler.handleError(ex);
   }
 }