[virtualcommons-svn] SF.net SVN: virtualcommons:[213] foraging/trunk/src/main/java/edu/asu/ common
Status: Beta
Brought to you by:
alllee
From: <al...@us...> - 2009-08-04 06:05:29
|
Revision: 213 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=213&view=rev Author: alllee Date: 2009-08-04 06:05:21 +0000 (Tue, 04 Aug 2009) Log Message: ----------- quicktime movie creation appears to work. still need to tweak frame rate, should create a frame for each movement/token collection Modified Paths: -------------- foraging/trunk/src/main/java/edu/asu/commons/foraging/util/ForagingSaveFileConverter.java Modified: foraging/trunk/src/main/java/edu/asu/commons/foraging/util/ForagingSaveFileConverter.java =================================================================== --- foraging/trunk/src/main/java/edu/asu/commons/foraging/util/ForagingSaveFileConverter.java 2009-08-03 19:34:52 UTC (rev 212) +++ foraging/trunk/src/main/java/edu/asu/commons/foraging/util/ForagingSaveFileConverter.java 2009-08-04 06:05:21 UTC (rev 213) @@ -8,6 +8,7 @@ import java.io.IOException; import java.io.OutputStream; import java.io.PrintWriter; +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -19,8 +20,8 @@ import java.util.SortedSet; import java.util.TreeSet; -import javax.imageio.ImageIO; import javax.swing.JFrame; +import javax.swing.SwingUtilities; import edu.asu.commons.event.ChatRequest; import edu.asu.commons.event.PersistableEvent; @@ -95,69 +96,107 @@ public MovieCreatorProcessor(VideoFormat videoFormat) { this.videoFormat = videoFormat; } - + @Override public void process(SavedRoundData savedRoundData, OutputStream stream) { - try { - // hmm, there needs to be one output stream per group because we write 1 video per group. -// QuickTimeOutputStream quickTimeOutputStream = new QuickTimeOutputStream(stream, videoFormat); - ServerDataModel serverDataModel = (ServerDataModel) savedRoundData.getDataModel(); - RoundConfiguration roundConfiguration = (RoundConfiguration) savedRoundData.getRoundParameters(); - List<GroupView> groupViewList = new ArrayList<GroupView>(); - serverDataModel.reinitialize(); - List<JFrame> jframes = new ArrayList<JFrame>(); - Dimension dimension = new Dimension(800, 600); -// int i = 0; - for (GroupDataModel groupDataModel: serverDataModel.getGroups()) { - GroupView groupView = new GroupView(dimension, groupDataModel); - groupView.setup(roundConfiguration); - groupViewList.add(groupView); - JFrame jframe = new JFrame("Group: " + groupViewList.size()); - jframe.setPreferredSize(dimension); - jframe.add(groupView); - jframe.pack(); - jframe.setVisible(true); - jframes.add(jframe); - } - int secondHasPassedCheck = -1; - // grab out all add client events to initialize the state of the game properly. - for (PersistableEvent event: savedRoundData.getActions()) { - if (event instanceof AddClientEvent) { - serverDataModel.apply(event); - } - } - for (PersistableEvent event: savedRoundData.getActions()) { - int elapsedTimeInSeconds = savedRoundData.getElapsedTimeInSeconds(event); - System.err.println("elapsed time in seconds: " + elapsedTimeInSeconds); - serverDataModel.apply(event); - if (elapsedTimeInSeconds > secondHasPassedCheck) { - secondHasPassedCheck = elapsedTimeInSeconds; - // take a snapshot of each group... - for (GroupView groupView: groupViewList) { - Graphics2D graphics = (Graphics2D) groupView.getGraphics(); - BufferedImage bufferedImage = graphics.getDeviceConfiguration().createCompatibleImage(800, 600); -// write a frame to the quicktime movie... -// quickTimeOutputStream.writeFrame(bufferedImage, 40); - // write buffered image out to named sequentially. - ImageIO.write(bufferedImage, videoFormat.name(), new File(elapsedTimeInSeconds + "-group-" + groupViewList.indexOf(groupView) + "." + videoFormat.name())); - } - } - } - for (JFrame jframe : jframes) { - jframe.setVisible(false); - jframe.dispose(); - } - + // hmm, there needs to be one output stream per group because we write 1 video per group. + // QuickTimeOutputStream quickTimeOutputStream = new QuickTimeOutputStream(stream, videoFormat); + ServerDataModel serverDataModel = (ServerDataModel) savedRoundData.getDataModel(); + RoundConfiguration roundConfiguration = (RoundConfiguration) savedRoundData.getRoundParameters(); + final List<GroupView> groupViewList = new ArrayList<GroupView>(); + final Map<GroupView, QuickTimeOutputStream> groupViewMap = new HashMap<GroupView, QuickTimeOutputStream>(); + serverDataModel.reinitialize(); + List<JFrame> jframes = new ArrayList<JFrame>(); + Dimension dimension = new Dimension(800, 800); + File savedRoundDataFile = new File(savedRoundData.getSaveFilePath()); + String saveFilePath = savedRoundDataFile.getName(); + for (GroupDataModel groupDataModel: serverDataModel.getGroups()) { + GroupView groupView = new GroupView(dimension, groupDataModel); + groupView.setup(roundConfiguration); + groupViewList.add(groupView); + try { + File groupMovieFile = new File(savedRoundDataFile.getCanonicalPath() + "-group-" + groupViewList.size() + "-" + saveFilePath + ".mov"); + groupViewMap.put(groupView, new QuickTimeOutputStream(groupMovieFile, videoFormat)); + } + catch (IOException exception) { + exception.printStackTrace(); + } + JFrame jframe = new JFrame("Group: " + groupViewList.size()); + jframe.add(groupView); + jframe.pack(); + jframe.setVisible(true); + jframes.add(jframe); } - catch (IOException exception) { - exception.printStackTrace(); - throw new RuntimeException(exception); + int secondHasPassedCheck = -1; + // grab out all add client events to initialize the state of the game properly. + for (PersistableEvent event: savedRoundData.getActions()) { + if (event instanceof AddClientEvent) { + System.err.println("Adding client: " + event); + serverDataModel.apply(event); + } } - - + for (PersistableEvent event: savedRoundData.getActions()) { + final int elapsedTimeInSeconds = savedRoundData.getElapsedTimeInSeconds(event); + System.err.println("elapsed time in seconds: " + elapsedTimeInSeconds + ":" + event); + serverDataModel.apply(event); + if (elapsedTimeInSeconds > secondHasPassedCheck) { + secondHasPassedCheck = elapsedTimeInSeconds; + // take a snapshot of each group... + for (final GroupView groupView: groupViewList) { + try { +// groupView.repaint(); + final Dimension groupViewSize = groupView.getSize(); + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + Graphics2D graphics = (Graphics2D) groupView.getGraphics(); + + BufferedImage bufferedImage = graphics.getDeviceConfiguration().createCompatibleImage(groupViewSize.width, groupViewSize.height); + Graphics2D bufferedImageGraphics = bufferedImage.createGraphics(); + groupView.paint(bufferedImageGraphics); + try { + // currently each frame is 1 second.. maybe we can divvy this up so it's .5 seconds instead. + groupViewMap.get(groupView).writeFrame(bufferedImage, 600); + } + catch (IOException exception) { + exception.printStackTrace(); + throw new RuntimeException(exception); + } + + // write buffered image out to sequentially named file..? +// try { +// ImageIO.write(bufferedImage, videoFormat.name(), new File(elapsedTimeInSeconds + "-group-" + groupViewList.indexOf(groupView) + "." + videoFormat.name())); +// } +// catch (IOException e) { +// e.printStackTrace(); +// throw new RuntimeException(e); +// } + } + }); + } + catch (InterruptedException e) { + e.printStackTrace(); + } + catch (InvocationTargetException e) { + e.printStackTrace(); + } + } + } + } + for (QuickTimeOutputStream out : groupViewMap.values()) { + try { + out.close(); + } + catch (IOException exception) { + exception.printStackTrace(); + } + } + for (JFrame jframe : jframes) { + jframe.setVisible(false); + jframe.dispose(); + } - } + @Override public void process(SavedRoundData savedRoundData, PrintWriter writer) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |