6161 * Ben Fry 2011-09-06, updated 2013-10-09
6262 */
6363public class MovieMaker extends JFrame implements Tool {
64- // private JFileChooser imageFolderChooser;
65- // private JFileChooser soundFileChooser;
66- // private JFileChooser movieFileChooser;
6764 private Preferences prefs ;
6865
69- // private Editor editor;
70-
71- //MovieMaker m = new MovieMaker();
72- //m.setVisible(true);
73- //m.pack();
7466
7567 public String getMenuTitle () {
7668 return Language .text ("movie_maker" );
7769 }
7870
7971
8072 public void run () {
81- // System.out.println("calling run() for MovieMaker " + EventQueue.isDispatchThread());
8273 setVisible (true );
8374 }
8475
8576
86- // public void run() {
87- // String classPath =
88- // getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
89- // System.out.println("cp is " + classPath);
90- // try {
91- // String[] cmd = new String[] {
92- // "java", "-cp", classPath, "processing.app.tools.MovieMaker"
93- // };
94- // Runtime.getRuntime().exec(cmd);
95- // } catch (IOException e) {
96- // e.printStackTrace();
97- // }
98- // }
99-
100-
10177 public void init (Editor editor ) {
102- // System.out.println("calling init for MovieMaker " + EventQueue.isDispatchThread());
103- // this.editor = editor;
10478 initComponents (editor == null );
10579
106- // String version = getClass().getPackage().getImplementationVersion();
107- // if (version != null) {
108- // setTitle(getTitle() + " " + version);
109- // }
110-
11180 ((JComponent ) getContentPane ()).setBorder (new EmptyBorder (12 , 18 , 18 , 18 ));
11281 imageFolderField .setTransferHandler (new FileTextFieldTransferHandler (JFileChooser .DIRECTORIES_ONLY ));
11382 soundFileField .setTransferHandler (new FileTextFieldTransferHandler ());
@@ -122,9 +91,6 @@ public void init(Editor editor) {
12291 heightField ,
12392 heightLabel ,
12493 originalSizeCheckBox ,
125- // noPreparationRadio,
126- // fastStartCompressedRadio,
127- // fastStartRadio
12894 };
12995 for (JComponent c : smallComponents ) {
13096 c .putClientProperty ("JComponent.sizeVariant" , "small" );
@@ -561,34 +527,6 @@ private void createMovie(final File movieFile) {
561527 prefs .putInt ("movie.compression" , compressionBox .getSelectedIndex ());
562528 prefs .putBoolean ("movie.originalSize" , originalSizeCheckBox .isSelected ());
563529
564-
565- // ---------------------------------
566- // Choose an output file
567- // ---------------------------------
568- /*
569- if (movieFileChooser == null) {
570- movieFileChooser = new JFileChooser();
571- if (prefs.get("movie.outputFile", null) != null) {
572- movieFileChooser.setSelectedFile(new File(prefs.get("movie.outputFile", null)));
573- } else {
574- if (imageFolderField.getText().length() > 0) {
575- movieFileChooser.setCurrentDirectory(new File(imageFolderField.getText()).getParentFile());
576- } else if (soundFileField.getText().length() > 0) {
577- movieFileChooser.setCurrentDirectory(new File(soundFileField.getText()).getParentFile());
578- }
579- }
580- }
581- if (JFileChooser.APPROVE_OPTION != movieFileChooser.showSaveDialog(this)) {
582- return;
583- }
584-
585- final File movieFile = movieFileChooser.getSelectedFile().getPath().toLowerCase().endsWith(".mov")//
586- ? movieFileChooser.getSelectedFile()
587- : new File(movieFileChooser.getSelectedFile().getPath() + ".mov");
588- prefs.put("movie.outputFile", movieFile.getPath());
589- createMovieButton.setEnabled(false);
590- */
591-
592530 final boolean originalSize = originalSizeCheckBox .isSelected ();
593531
594532 // ---------------------------------
@@ -599,15 +537,15 @@ private void createMovie(final File movieFile) {
599537 @ Override
600538 protected Object doInBackground () {
601539 try {
602-
603540 // Read image files
604541 File [] imgFiles = null ;
605542 if (imageFolder != null ) {
606543 imgFiles = imageFolder .listFiles (new FileFilter () {
607544 FileSystemView fsv = FileSystemView .getFileSystemView ();
608545
609546 public boolean accept (File f ) {
610- return f .isFile () && !fsv .isHiddenFile (f ) && !f .getName ().equals ("Thumbs.db" );
547+ return f .isFile () && !fsv .isHiddenFile (f ) &&
548+ !f .getName ().equals ("Thumbs.db" );
611549 }
612550 });
613551 if (imgFiles == null || imgFiles .length == 0 ) {
@@ -617,23 +555,14 @@ public boolean accept(File f) {
617555 }
618556
619557 // Get the width and height if we're preserving size.
620- // Nullify bad Files so we don't get errors twice.
621558 if (originalSize ) {
622- for (int i = 0 ; true ; ++i ) {
559+ Dimension d = findSize (imgFiles );
560+ if (d == null ) {
623561 // No images at all? No video then.
624- if (i >= imgFiles .length ) {
625- throw new RuntimeException (Language .text ("movie_maker.error.no_images_found" ));
626- }
627-
628- BufferedImage temp = readImage (imgFiles [i ]);
629- if (temp == null ) {
630- imgFiles [i ] = null ;
631- } else {
632- width = temp .getWidth ();
633- height = temp .getHeight ();
634- break ;
635- }
562+ throw new RuntimeException (Language .text ("movie_maker.error.no_images_found" ));
636563 }
564+ width = d .width ;
565+ height = d .height ;
637566 }
638567
639568 // Delete movie file if it already exists.
@@ -655,6 +584,19 @@ public boolean accept(File f) {
655584 }
656585 }
657586
587+ Dimension findSize (File [] imgFiles ) {
588+ for (int i = 0 ; i < imgFiles .length ; i ++) {
589+ BufferedImage temp = readImage (imgFiles [i ]);
590+ if (temp != null ) {
591+ return new Dimension (temp .getWidth (), temp .getHeight ());
592+ } else {
593+ // Nullify bad Files so we don't get errors twice.
594+ imgFiles [i ] = null ;
595+ }
596+ }
597+ return null ;
598+ }
599+
658600 @ Override
659601 protected void done () {
660602 Object o ;
@@ -681,18 +623,14 @@ protected void done() {
681623
682624
683625 /**
684- * Read an image from a file. ImageIcon doesn't don't do well with some file
685- * types, so we use ImageIO. ImageIO doesn't handle TGA files created by
686- * Processing, so this calls our own loadImageTGA().
626+ * Read an image from a file. ImageIcon doesn't don't do well with some
627+ * file types, so we use ImageIO. ImageIO doesn't handle TGA files
628+ * created by Processing, so this calls our own loadImageTGA().
687629 * <br> Prints errors itself.
688630 * @return null on error; image only if okay.
689631 */
690632 private BufferedImage readImage (File file ) {
691633 try {
692- // Make sure that we're using a ClassLoader that's aware of the ImageIO jar
693- //Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
694- //BufferedImage image = ImageIO.read(file);
695- // rewritten to switch back to the default loader
696634 Thread current = Thread .currentThread ();
697635 ClassLoader origLoader = Thread .currentThread ().getContextClassLoader ();
698636 current .setContextClassLoader (getClass ().getClassLoader ());
@@ -701,7 +639,7 @@ private BufferedImage readImage(File file) {
701639 try {
702640 image = ImageIO .read (file );
703641 } catch (IOException e ) {
704- System .err .println (Language .interpolate ("movie_maker.error.cant_read " ,
642+ System .err .println (Language .interpolate ("movie_maker.error.cannot_read " ,
705643 file .getAbsolutePath ()));
706644 return null ;
707645 }
@@ -725,40 +663,43 @@ private BufferedImage readImage(File file) {
725663 try {
726664 return loadImageTGA (file );
727665 } catch (IOException e ) {
728- System .err .println (Language .interpolate ("movie_maker.error.cant_read" ,
729- file .getAbsolutePath ()));
666+ cannotRead (file );
730667 return null ;
731668 }
732669
733670 } else if (pathLower .endsWith (".tif" ) || pathLower .endsWith (".tiff" )) {
734- System .err .println (Language .interpolate ("movie_maker.error.cant_read" ,
735- file .getAbsolutePath ()) + " " +
736- Language .text ("movie_maker.error.avoid_tiff" ));
671+ cannotRead (file );
672+ System .err .println (Language .text ("movie_maker.error.avoid_tiff" ));
737673 return null ;
738674
739675 } else {
740- System .err .println (Language .interpolate ("movie_maker.error.cant_read" ,
741- file .getAbsolutePath ()));
676+ cannotRead (file );
742677 return null ;
743678 }
744679
745680 } else {
746681 if (image .getWidth () <= 0 || image .getHeight () <= 0 ) {
747- System .err .println (Language .interpolate ("movie_maker.error.cant_read_maybe_bad" ,
748- file .getAbsolutePath ()));
682+ System .err .println (Language .interpolate ("movie_maker.error.cannot_read_maybe_bad" , file .getAbsolutePath ()));
749683 return null ;
750684 }
751685 }
752686 return image ;
753687
754688 // Catch-all is sometimes needed.
755689 } catch (RuntimeException e ) {
756- System . err . println ( Language . interpolate ( "movie_maker.error.cant_read" , file . getAbsolutePath ()) );
690+ cannotRead ( file );
757691 return null ;
758692 }
759693 }
760694
761695
696+ private void cannotRead (File file ) {
697+ String path = file .getAbsolutePath ();
698+ String msg = Language .interpolate ("movie_maker.error.cannot_read" , path );
699+ System .err .println (msg );
700+ }
701+
702+
762703 /** variable frame rate. */
763704 private void writeVideoOnlyVFR (File movieFile , File [] imgFiles , int width , int height , double fps , QuickTimeWriter .VideoFormat videoFormat , /*boolean passThrough,*/ String streaming ) throws IOException {
764705 File tmpFile = streaming .equals ("none" ) ? movieFile : new File (movieFile .getPath () + ".tmp" );
0 commit comments