/** * 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(); int location; int endLocation; 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; } else { location = length - 6; endLocation = location + 2; } while(startFilePath.compareTo(endFilePath)!=0) { fileVec.addElement(startFilePath); String stNum = startFilePath.substring(location, endLocation); Integer intNum = new Integer(stNum); int num = intNum.intValue(); num++; String tempString; if(num<10) { tempString = "00" + num; } else if(num<100) { tempString = "0" + num; } else { tempString = "" + num; } startFilePath = startFilePath.replaceAll(stNum, tempString); } 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", 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(); } }