Commit b17121e7 authored by ludwig's avatar ludwig

> Improved Editor2 behaviour

> added Native Look and Feel option in TTT's main menu
> Tackled Linux camera bugs (restart recording)



git-svn-id: https://www2.in.tum.de/repos/ttt/trunk@81 0463f305-d864-43cb-8a47-61cf597d4139
parent eaf1fcae
......@@ -102,6 +102,11 @@ public class Recorder implements MessageConsumer, Closeable {
audioVideoRecorder.close();
audioVideoRecorder = null;
if(VideoRecorder != null) {
VideoRecorder.close();
}
VideoRecorder = null;
if (protocol != null)
protocol.close();
protocol = null;
......@@ -450,10 +455,13 @@ public class Recorder implements MessageConsumer, Closeable {
if (VideoRecorder != null) {
if (closing) {
VideoRecorder.close();
VideoRecorder = null;
if (closing) {
VideoRecorder.close();
VideoRecorder = null;
} else{
VideoRecorder.stop();
}
}
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -7,8 +7,6 @@ import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
......@@ -19,7 +17,6 @@ import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDesktopPane;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
......@@ -36,6 +33,8 @@ import javax.swing.SwingUtilities;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;
import javax.swing.plaf.DimensionUIResource;
import ttt.TTT;
......@@ -50,7 +49,7 @@ import ttt.record.Recording;
* Main class for TTTEditor.
*/
@SuppressWarnings("serial")
public class editor2 extends JFrame {
public class Editor2 extends JInternalFrame {
static final String version = "18.08.2010";
......@@ -59,7 +58,7 @@ public class editor2 extends JFrame {
// user preferences
static Preferences userPrefs = Preferences.userRoot().node("/TTTEditor");
private static editor2 instance;
private static Editor2 instance;
// markers for trimming the recording
private int startMarker;
......@@ -132,7 +131,7 @@ public class editor2 extends JFrame {
/**
* Class Constructor.
*/
public editor2() {
public Editor2() {
super("TTTEditor, Version: " + version);
desktopPane = new JDesktopPane();
......@@ -153,14 +152,40 @@ public class editor2 extends JFrame {
// attempt to close all open files before closing
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
tryExit();
setResizable(true);
setIconifiable(true);
setMaximizable(true);
addInternalFrameListener(new InternalFrameListener() {
@Override
public void internalFrameClosing(InternalFrameEvent arg0) {
tryExit();
}
});
@Override
public void internalFrameOpened(InternalFrameEvent arg0) {}
@Override
public void internalFrameIconified(InternalFrameEvent arg0) {}
@Override
public void internalFrameDeiconified(InternalFrameEvent arg0) {}
@Override
public void internalFrameDeactivated(InternalFrameEvent arg0) {}
@Override
public void internalFrameClosed(InternalFrameEvent arg0) {}
@Override
public void internalFrameActivated(InternalFrameEvent arg0) {}
});
setEnabled(true);
setVisible(true);
setExtendedState(MAXIMIZED_BOTH);
}
/**
......@@ -169,7 +194,7 @@ public class editor2 extends JFrame {
* @param args
*/
public static void main(final String[] args) {
editor2.getInstance();
Editor2.getInstance();
}
/**
......@@ -226,7 +251,7 @@ public class editor2 extends JFrame {
if (desktopFiles.length < 2) {
JOptionPane
.showInternalMessageDialog(
editor2.getInstance().getDesktopPane(),
Editor2.getInstance().getDesktopPane(),
"You need to choose more than one file to concatenate",
"Invalid selection",
JOptionPane.ERROR_MESSAGE);
......@@ -298,16 +323,16 @@ public class editor2 extends JFrame {
}
// use last opened path as start location for the filechooser
String lastUsedPath = editor2.userPrefs.get("last used path", null);
String lastUsedPath = Editor2.userPrefs.get("last used path", null);
JFileChooser fileChooser = lastUsedPath != null ? new JFileChooser(
lastUsedPath) : new JFileChooser();
int returnValue = fileChooser.showOpenDialog(editor2.getInstance());
int returnValue = fileChooser.showOpenDialog(Editor2.getInstance());
if (returnValue == JFileChooser.APPROVE_OPTION) {
// save used path
editor2.userPrefs.put("last used path", fileChooser
Editor2.userPrefs.put("last used path", fileChooser
.getSelectedFile().getAbsoluteFile().getParent());
// Open file and create edit Panel
......@@ -327,7 +352,7 @@ public class editor2 extends JFrame {
public boolean open(File file) {
// ensure max space available before trying to open a new file
System.gc();
IOProgressDisplayFrame progress = new IOProgressDisplayFrame(editor2
IOProgressDisplayFrame progress = new IOProgressDisplayFrame(Editor2
.getInstance().getOutputDisplayPanel());
try {
// look for audio, desktop and video
......@@ -391,15 +416,15 @@ public class editor2 extends JFrame {
graphicsContext.refresh();
JScrollPane scrollPane = new JScrollPane(graphicsContext);
JScrollPane videoPane = new JScrollPane(graphicsContext);
graphicsContext.setScaleFactor(0.7f);
graphicsContext.setScaleFactor(0.5f);
playerPane.setLayout(new GridBagLayout());
playerPane.add(playbackControls, c);
playerPane.add(videoPane, c);
c.gridy = 1;
playerPane.add(scrollPane, c);
playerPane.add(playbackControls, c);
c.gridy = 2;
playerPane.add(MarkerPanel, c);
......@@ -423,9 +448,9 @@ public class editor2 extends JFrame {
*
* @return returns the active instance of the editor2
*/
public static editor2 getInstance() {
public static Editor2 getInstance() {
if (instance == null) {
instance = new editor2();
instance = new Editor2();
}
return instance;
}
......@@ -479,7 +504,7 @@ public class editor2 extends JFrame {
SelectionPanel selectionPanel = new SelectionPanel(file);
result = editor2.showInternalConfirmDialog(selectionPanel, "Confirm",
result = Editor2.showInternalConfirmDialog(selectionPanel, "Confirm",
JOptionPane.OK_CANCEL_OPTION);
if (result == JOptionPane.OK_OPTION) {
......@@ -490,7 +515,7 @@ public class editor2 extends JFrame {
// indicate that file connection has been
// unsuccessful
if (!desktopPresent && !audioPresent && !videoPresent) {
JOptionPane.showInternalMessageDialog(editor2.getInstance()
JOptionPane.showInternalMessageDialog(Editor2.getInstance()
.getDesktopPane(), "No files have been selected.");
return false;
}
......@@ -506,7 +531,7 @@ public class editor2 extends JFrame {
// If the user wishes to continue, return true to indicate that
// the file connection has been successful
// (although not all 3 files have been selected)
if (editor2.showInternalConfirmDialog(warningString, "Confirm",
if (Editor2.showInternalConfirmDialog(warningString, "Confirm",
JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION) {
// ensure files are ignored if not selected
if (!videoCheckBox.isSelected())
......@@ -568,7 +593,7 @@ public class editor2 extends JFrame {
*/
public boolean closeFile() {
int confirm = JOptionPane
.showInternalConfirmDialog(editor2.getInstance()
.showInternalConfirmDialog(Editor2.getInstance()
.getDesktopPane(), "Do you want to save changes to "
+ desktopFile.getName() + "?", "Close file",
JOptionPane.YES_NO_CANCEL_OPTION);
......@@ -832,13 +857,13 @@ public class editor2 extends JFrame {
// dispatching thread
try {
if (SwingUtilities.isEventDispatchThread()) {
result = JOptionPane.showInternalConfirmDialog(editor2
result = JOptionPane.showInternalConfirmDialog(Editor2
.getInstance().getDesktopPane(), message, title,
optionType, messageType);
} else
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
result = JOptionPane.showInternalConfirmDialog(editor2
result = JOptionPane.showInternalConfirmDialog(Editor2
.getInstance().getDesktopPane(), message,
title, optionType, messageType);
}
......
......@@ -44,7 +44,7 @@ public class OutputDisplayPanel extends JPanel {
super(new BorderLayout());
// modified 19.01.2006 by Peter Ziewer
if (!editor2.consoleOutput) {
if (!Editor2.consoleOutput) {
System.setOut(printStream);
System.setErr(printStream);
}
......
......@@ -33,7 +33,7 @@ public final class Parameters {
// + "TeleTeachingTool, and created by Pete Bankhead as part of a\n"
// + "student project at the TUM.\n"
// + "--------------------------------------------\n"+
" TeleTeachingTool Editor - Version " + editor2.version + "\n\n"+
" TeleTeachingTool Editor - Version " + Editor2.version + "\n\n"+
" Author: \tPete Bankhead\n\n"
+ " Author: \tPeter Ziewer\n" + " Technical University of Munich\n" + " Germany\n"
......
......@@ -180,7 +180,7 @@ public class TTTFileUtilities {
*/
private static void createFileChooser() {
// added 19.01.2006 by Peter Ziewer
String lastUsedPath = editor2.userPrefs.get("last used path", null);
String lastUsedPath = Editor2.userPrefs.get("last used path", null);
fileChooser = lastUsedPath != null ? new JFileChooser(lastUsedPath) : new JFileChooser();
fileChooser.setFileFilter(new TTTDefaultFileFilter());
......@@ -223,12 +223,12 @@ public class TTTFileUtilities {
}
}
int returnValue = fileChooser.showOpenDialog(editor2.getInstance());
int returnValue = fileChooser.showOpenDialog(Editor2.getInstance());
if (returnValue == JFileChooser.APPROVE_OPTION) {
// added 22.03.2006 by Peter Ziewer
// use same path after restart
editor2.userPrefs.put("last used path", fileChooser.getSelectedFile().getAbsoluteFile().getParent());
Editor2.userPrefs.put("last used path", fileChooser.getSelectedFile().getAbsoluteFile().getParent());
return fileChooser.getSelectedFile();
}
......@@ -267,7 +267,7 @@ public class TTTFileUtilities {
if (suggestedFile != null)
fileChooser.setSelectedFile(suggestedFile);
int returnValue = fileChooser.showSaveDialog(editor2.getInstance());
int returnValue = fileChooser.showSaveDialog(Editor2.getInstance());
if (returnValue == JFileChooser.APPROVE_OPTION)
return fileChooser.getSelectedFile();
......
......@@ -118,8 +118,8 @@ public class TTTProcessor {
return false;
System.out.println("Beginning trim...");
System.out.println("Start time:\t" + editor2.getStringFromTime(startTimeMS, true));
System.out.println("End time:\t" + editor2.getStringFromTime(endTimeMS, true));
System.out.println("Start time:\t" + Editor2.getStringFromTime(startTimeMS, true));
System.out.println("End time:\t" + Editor2.getStringFromTime(endTimeMS, true));
System.out.println();
System.out.println("Saving video...");
......@@ -146,11 +146,11 @@ public class TTTProcessor {
// use real video cutting timestamps (better sync)
if (videoSuccessful) {
System.out.println("\nAdjusting to video frames:");
System.out.println("start:\t" + editor2.getStringFromTime(cuttedStart, true) + "\t("
+ editor2.getStringFromTime(cuttedStart - startTimeMS * 1000000l, true) + ")");
System.out.println("end:\t" + editor2.getStringFromTime(cuttedEnd, true) + "\t("
+ editor2.getStringFromTime(cuttedEnd - endTimeMS * 1000000l, true) + ")");
System.out.println("diff:\t" + editor2.getStringFromTime(cuttedEnd - cuttedStart, true));
System.out.println("start:\t" + Editor2.getStringFromTime(cuttedStart, true) + "\t("
+ Editor2.getStringFromTime(cuttedStart - startTimeMS * 1000000l, true) + ")");
System.out.println("end:\t" + Editor2.getStringFromTime(cuttedEnd, true) + "\t("
+ Editor2.getStringFromTime(cuttedEnd - endTimeMS * 1000000l, true) + ")");
System.out.println("diff:\t" + Editor2.getStringFromTime(cuttedEnd - cuttedStart, true));
System.out.println();
} else {
cuttedStart = startTimeMS;
......@@ -285,7 +285,7 @@ public class TTTProcessor {
recording.setMessages(messages);
for(Message m : messages){
System.out.println("what's going on? " + editor2.getStringFromTime( m.getTimestamp()) + " . damn " + m.toString());
System.out.println("what's going on? " + Editor2.getStringFromTime( m.getTimestamp()) + " . damn " + m.toString());
}
......@@ -438,7 +438,7 @@ public class TTTProcessor {
public static File[] getFilesForConcat() {
ConcatSelector selector = new ConcatSelector();
int selection = JOptionPane.showInternalOptionDialog(editor2.getInstance().getDesktopPane(), selector,
int selection = JOptionPane.showInternalOptionDialog(Editor2.getInstance().getDesktopPane(), selector,
"Choose files to concatenate", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null,
null);
......
......@@ -54,6 +54,7 @@ import javax.swing.ButtonGroup;
import javax.swing.Icon;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
......@@ -85,6 +86,25 @@ public class Player extends JInternalFrame {
ArrayList<Closeable> closeables = new ArrayList<Closeable>();;
private RfbProtocol protocol = null;
//used for testing
public static void main(String[] args){
try {
JFrame jay = new JFrame("Player");
Player play = new Player("/home/ludwig/testLecture/Theoretische_Informatik_2010_05_03.ttt");
jay.add(play);
// jay.setSize(300,300);
jay.pack();
jay.setVisible(true);
jay.setEnabled(true);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// simple player
public Player(MessageProducer producer) throws IOException {
......@@ -574,7 +594,7 @@ public class Player extends JInternalFrame {
public void actionPerformed(ActionEvent event) {
// popup is not visible in fullscreen mode
// hence return to wiondowed mode first
TTT.leaveFfullscreen();
TTT.leaveFullscreen();
if (JOptionPane.showInternalConfirmDialog(TTT.getInstance().getContentPane(), "Reconnect?", "TTT",
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
......
......@@ -107,7 +107,7 @@ public class LectureProfile {
profile.showRecordPlayRecordWarning = preferences.getBoolean("show_record_play_record_warning", true);
profile.RecordingCamera = preferences.get("RecordingCamera", "");
profile.Format = new ttt.video.TTTVideoFormat(preferences.getInt("FormatWidth", 160), preferences.getInt("FormatHeight", 120));
profile.VideoQuality = preferences.getFloat("VideoQuality", 0.1f);
profile.VideoQuality = preferences.getFloat("VideoQuality", 1.0f);
return profile;
}
} catch (Exception e) {
......
......@@ -81,13 +81,18 @@ public class LinuxCam implements WebCamControl, Runnable {
else return new Object[0];
}
private void initFrameGrabber(int std, int channel)
throws V4L4JException {
fg = system.get(selectedCameraID).getJPEGFrameGrabber(w, h, channel, std, V4L4JConstants.MAX_JPEG_QUALITY);
private void initFrameGrabber(int std, int channel) {
try {
fg = system.get(selectedCameraID).getJPEGFrameGrabber(w, h, channel, std, V4L4JConstants.MAX_JPEG_QUALITY);
} catch (V4L4JException e) {
System.out.println("Couldn't initiate Camera. fg broke.");
e.printStackTrace();
}
}
@Override
public void release() {//all initialized systems have to be released.
close();
for (VideoDevice x : system) {
x.releaseFrameGrabber();
x.release();
......@@ -96,19 +101,21 @@ public class LinuxCam implements WebCamControl, Runnable {
@Override
public boolean start() {
boolean check = false;
boolean checkForCamera = false;
if (CamFound)
try {
//checking if camera (still) exists
for(Object i: listV4LDeviceFiles()){
if( i.toString().equals(system.get(selectedCameraID).getDevicefile())) {
check = true;
checkForCamera = true;
}
}
if(check){
if(checkForCamera){
if(fg == null) {
initFrameGrabber(0, 0);
}
if (!isRecording) {
fg.startCapture();
captureThread = new Thread(this, "Capture Thread");
......@@ -118,6 +125,7 @@ public class LinuxCam implements WebCamControl, Runnable {
}
}
} catch (V4L4JException e) {
e.printStackTrace();
}
return false;
......@@ -129,13 +137,28 @@ public class LinuxCam implements WebCamControl, Runnable {
captureThread = null;
isRecording = false;
fg.stopCapture();
fg = null;
system.get(selectedCameraID).releaseFrameGrabber();
// fg = null;
//system.get(selectedCameraID).releaseFrameGrabber();
return true;
}
return false;
}
@Override
public boolean close() {
if(isRecording) {
fg.stopCapture();
}
captureThread = null;
isRecording = false;
fg = null;
system.get(selectedCameraID).releaseFrameGrabber();
return true;
}
@Override
public String getDeviceName(int DeviceID) {
if (CamFound)
......
......@@ -124,10 +124,10 @@ public class VideoRecorderPanel implements WindowListener{
} catch (CameraStopException e) {
e.printStackTrace();
}
WBC.release();
isRecording = false;
saveelapsedTime();
this.frame.dispose();
}
}
......@@ -146,7 +146,20 @@ public class VideoRecorderPanel implements WindowListener{
}
public void close() {
stop();
try {
stop();
WBC.close();
WBC.release();
this.frame.dispose();
} catch (CameraStopException e) {
this.frame.dispose();
e.printStackTrace();
}
frame.dispose();
}
......
......@@ -213,8 +213,8 @@ public class VideoSettingPanel implements ActionListener {
WBC.setQuality(AppliedQuality);
int index = (int) (Quality * 10) - 1;
if(1 <= index && index <= 10 ){
boxQuality.setSelectedIndex(index);}
boxQuality.setSelectedIndex(index);
}
}
public void setRecordingFormat(TTTVideoFormat format) {
......@@ -292,7 +292,7 @@ public class VideoSettingPanel implements ActionListener {
show(false);
setEnabled(true);
try {
WBC.stop();
WBC.close();
} catch (CameraStopException e1) {
e1.printStackTrace();
}
......@@ -301,7 +301,7 @@ public class VideoSettingPanel implements ActionListener {
if (e.getSource() == butApply) {
setEnabled(true);
try {
WBC.stop();
WBC.close();
} catch (CameraStopException e1) {
e1.printStackTrace();
}
......
......@@ -50,6 +50,9 @@ public interface WebCamControl {
public boolean stop() throws CameraStopException; //Ends Capturing images
public boolean close() throws CameraStopException;
/**
* needed under Linux
*/
......
......@@ -147,7 +147,7 @@ public class WindowsCam implements WebCamControl {
if (isRecording) {
StartcaptureStream.stop();
StartcaptureStream.dispose();
System.out.println("aufnahmestopp");
isRecording = false;
}
} catch (CaptureException e1) {
......@@ -244,4 +244,19 @@ public class WindowsCam implements WebCamControl {
}
}
}
@Override
public boolean close() throws CameraStopException {
try {
StartcaptureStream.stop();
StartcaptureStream.dispose();
isRecording = false;
} catch (CaptureException e) {
System.out.println("Something went wrong closing the Camerastream!");
e.printStackTrace();
}
return true;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment