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 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 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);
    }
  }
 protected void runScript() {
   try {
     collectFieldValues();
     if (scriptRunner != null) {
       scriptRunner.run(this);
     }
   } catch (Exception ex) {
     errorHandler.handleError(ex);
   }
 }
 public void stopShow() {
   try {
     if (jLayer != null) {
       jLayer.stop();
     }
     stopRender();
     running = false;
     enableControls();
   } catch (Throwable ex) {
     errorHandler.handleError(ex);
   }
 }
 public void createMotionsBtn_clicked() {
   try {
     MotionCreatorType creatorType = (MotionCreatorType) createMotionsCmb.getSelectedItem();
     if (creatorType != null) {
       MotionCreator creator = creatorType.getMotionCreatorClass().newInstance();
       creator.createMotions(project);
       refreshMotionTable();
     }
   } catch (Throwable ex) {
     errorHandler.handleError(ex);
   }
 }
 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 dancingFlamesSaveProjectBtn_clicked() {
   try {
     JFileChooser chooser = new JWFDanceFileChooser(prefs);
     if (prefs.getOutputJWFMoviePath() != null) {
       try {
         chooser.setCurrentDirectory(new File(prefs.getOutputJWFMoviePath()));
       } catch (Exception ex) {
         ex.printStackTrace();
       }
     }
     if (chooser.showSaveDialog(poolFlamePreviewPnl) == JFileChooser.APPROVE_OPTION) {
       File file = chooser.getSelectedFile();
       new JWFDanceWriter().writeProject(project, file.getAbsolutePath());
       prefs.setLastOutputJWFMovieFile(file);
     }
   } catch (Throwable ex) {
     errorHandler.handleError(ex);
   }
 }
 public void loadSoundButton_clicked() {
   try {
     JFileChooser chooser = new SoundFileChooser(prefs);
     if (prefs.getInputSoundFilePath() != null) {
       try {
         chooser.setCurrentDirectory(new File(prefs.getInputSoundFilePath()));
       } catch (Exception ex) {
         ex.printStackTrace();
       }
     }
     if (chooser.showOpenDialog(flameRootPanel) == JFileChooser.APPROVE_OPTION) {
       File file = chooser.getSelectedFile();
       prefs.setLastInputSoundFile(file);
       project.setSoundFilename(jLayer, file.getAbsolutePath());
       enableControls();
     }
   } catch (Throwable ex) {
     errorHandler.handleError(ex);
   }
 }
 public void dancingFlamesLoadProjectBtn_clicked() {
   try {
     JFileChooser chooser = new JWFDanceFileChooser(prefs);
     if (prefs.getInputJWFMoviePath() != null) {
       try {
         chooser.setCurrentDirectory(new File(prefs.getInputJWFMoviePath()));
       } catch (Exception ex) {
         ex.printStackTrace();
       }
     }
     if (chooser.showOpenDialog(poolFlamePreviewPnl) == JFileChooser.APPROVE_OPTION) {
       File file = chooser.getSelectedFile();
       project = new JWFDanceReader().readProject(file.getAbsolutePath());
       refreshProjectFlames();
       enableControls();
     }
   } catch (Throwable ex) {
     errorHandler.handleError(ex);
   }
 }
  public void addMotionBtn_clicked() {
    try {
      MotionType motionType = (MotionType) addMotionCmb.getSelectedItem();
      if (motionType != null) {
        Motion newMotion = motionType.getMotionClass().newInstance();
        project.getMotions().add(newMotion);

        boolean oldRefreshing = refreshing;
        refreshing = true;
        try {
          refreshMotionTable();
        } finally {
          refreshing = oldRefreshing;
        }

        int selectRow = project.getMotions().size() - 1;
        motionTable.getSelectionModel().setSelectionInterval(selectRow, selectRow);
      }
    } 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);
   }
 }