/** * Front end for creating movies from JPEG images * Created for the Jython Environment for Students (JES) * @author Keith McDermottt, gte047w@cc.gatech.edu */ import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.Vector; public class MovieMaker implements ActionListener { private JpegImagesToMovie movie = new JpegImagesToMovie(); private JFrame frame; private JLabel startLabel; private JTextField startingFile; private JLabel endLabel; private JTextField endingFile; private JButton startingBrowse; private JButton endingBrowse; private JButton makeMovie; private JPanel middle; private JPanel bottom; private JPanel top; String startFilePath; String endFilePath; Vector fileVec; public MovieMaker() { createWindow(); } private void createWindow() { frame = new JFrame(); frame.setTitle("Movie Maker"); frame.setSize(450,300); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(new BorderLayout()); middle = new JPanel(); middle.setLayout(new GridLayout(7,1)); startLabel = new JLabel("Starting Frame:"); startingFile = new JTextField(); startingBrowse = new JButton("Browse For Starting File..."); endLabel = new JLabel("Ending Frame:"); endingFile = new JTextField(); endingBrowse = new JButton("Browse For Ending File..."); makeMovie = new JButton("Create Movie"); startingFile.setEditable(true); endingFile.setEditable(true); middle.add(startLabel); middle.add(startingFile); middle.add(new JPanel().add(startingBrowse)); middle.add(endLabel); middle.add(endingFile); middle.add(endingBrowse); middle.add(new JPanel()); bottom = new JPanel(); bottom.add(makeMovie); makeMovie.addActionListener(this); startingBrowse.addActionListener(this); endingBrowse.addActionListener(this); frame.getContentPane().add(bottom, BorderLayout.SOUTH); frame.getContentPane().add(middle, BorderLayout.CENTER); frame.setVisible(true); } private int createVector() { fileVec = new Vector(); String filename = ""; Integer startNumber = new Integer(0); Integer endNumber = new Integer(0); String extension = ".jpg"; startFilePath = startingFile.getText(); endFilePath = endingFile.getText(); if(startFilePath.length()!=endFilePath.length()) { JOptionPane.showMessageDialog(null, "Starting and ending filenames do not match. Please choose again.", "Warning", JOptionPane.ERROR_MESSAGE); return 0; } if(startFilePath.length()<7 || endFilePath.length()<7) { JOptionPane.showMessageDialog(null, "Please enter a starting and ending filename in the form name### or name##", "Warning", JOptionPane.ERROR_MESSAGE); return 0; } //Get the extension of the file: extension = getExtension(startFilePath); //Get the first and last indexes of the file: String startNumberString = getFileIndex(startFilePath); String endNumberString = getFileIndex(endFilePath); if (startNumberString.length() != endNumberString.length()) { JOptionPane.showMessageDialog(null, "Please enter a starting and ending filename in the form name### or name##", "Warning", JOptionPane.ERROR_MESSAGE); return 0; } //Convert the strings to numbers: startNumber = new Integer(startNumberString); endNumber = new Integer(endNumberString); //Get the filename part of the path filename = getPath(startFilePath); for (int i = startNumber.intValue(); i <= endNumber.intValue(); i++) { String number = getNumStringOfLength(i, startNumberString.length()); fileVec.addElement(filename + number + extension); } return 1; } private String getNumStringOfLength(int num, int length) { char[] number = new char[length]; String numberString = (new Integer(num)).toString(); int numberStringIndex = numberString.length() - 1; for (int i = length - 1; i >= 0; i--) { if (numberStringIndex < 0) number[i] = '0'; else number[i] = numberString.charAt(numberStringIndex); numberStringIndex--; } return new String(number); } private String getPath(String path) { int period = path.lastIndexOf('.'); int i = period - 1; while (i > 0 & new Integer(path.charAt(i)).intValue()<58 & new Integer(path.charAt(i)).intValue()>47) { i--; } return path.substring(0, i + 1); } private String getExtension(String path) { int period = path.lastIndexOf('.'); return path.substring(period, path.length()); } private String getFileIndex(String path) { int period = path.lastIndexOf('.'); int i = period - 1; while (i > 0 & (new Integer(path.charAt(i))).intValue()<58 & (new Integer(path.charAt(i))).intValue()>47) { i--; } return path.substring(i + 1, period); } private int createVectorOld() { fileVec = new Vector(); int location; int endLocation; int fileType; startFilePath = startingFile.getText(); endFilePath = endingFile.getText(); if(startFilePath.length()!=endFilePath.length()) { JOptionPane.showMessageDialog(null, "Starting and ending filenames do not match. Please choose again.", "Warning", JOptionPane.ERROR_MESSAGE); return 0; } if(startFilePath.length()<7 || endFilePath.length()<7) { JOptionPane.showMessageDialog(null, "Please enter a starting and ending filename in the form name### or name##", "Warning", JOptionPane.ERROR_MESSAGE); return 0; } int length = startFilePath.length(); if(new Integer(startFilePath.charAt(length-7)).intValue()<58 && new Integer(startFilePath.charAt(length-7)).intValue()>47) { location = length - 7; endLocation = location + 3; fileType=1; } else { System.out.println("Two digits"); location = length - 6; endLocation = location + 2; fileType=0; } fileVec.addElement(startFilePath); while(startFilePath.compareTo(endFilePath)!=0) { System.out.println(endFilePath); System.out.println(location + " " + endLocation); String stNum = startFilePath.substring(location, endLocation); Integer intNum = new Integer(stNum); int num = intNum.intValue(); num++; String tempString=""; if(fileType==1) { if(num<10) { tempString = "00" + num; } else if(num<100) { tempString = "0" + num; } else { tempString = "" + num; } } else { if(num<10) { tempString = "0" + num; } else if(num<100) { tempString = "" + num; } } startFilePath = startFilePath.replaceAll(stNum, tempString); System.out.println(startFilePath); fileVec.addElement(startFilePath); } return 1; } public void actionPerformed(ActionEvent e) { if(e.getActionCommand().equals(makeMovie.getText())) { Integer frameRate = new Integer("0"); if(createVector()==1) { int check=0; while(check==0) { check = 1; try { String frameRateTemp = JOptionPane.showInputDialog("Please input a frame rate:"); frameRate = new Integer(frameRateTemp); } catch(Exception exc) { check=0; } } String movieName = JOptionPane.showInputDialog("Please input the name of the movie including .mov at the end:"); //movieName = startFilePath.substring(0, startFilePath.lastIndexOf("\\")+1) + movieName; //try //{ JavaPicture forSize = new JavaPicture(); forSize.loadImage(startFilePath); movie.doItPath(forSize.getWidth(), forSize.getHeight(), frameRate.intValue(), fileVec, movieName); //} //catch(Exception exc) //{ // JOptionPane.showMessageDialog(null, "Unable to open images", // "Warning" + exc.getMessage(), JOptionPane.ERROR_MESSAGE); // return; //} } } if(e.getActionCommand().equals(startingBrowse.getText())) { JFileChooser chooser = new JFileChooser(); int returnVal = chooser.showOpenDialog(frame); if(returnVal == JFileChooser.APPROVE_OPTION) { startingFile.setText(chooser.getSelectedFile().getAbsolutePath()); } } if(e.getActionCommand().equals(endingBrowse.getText())) { JFileChooser chooser = new JFileChooser(); int returnVal = chooser.showOpenDialog(frame); if(returnVal == JFileChooser.APPROVE_OPTION) { endingFile.setText(chooser.getSelectedFile().getAbsolutePath()); } } } public static void main(String args[]) { MovieMaker test = new MovieMaker(); } }