Commit c671f1dd authored by ludwig's avatar ludwig
Browse files

this it the old unused postprocessor


git-svn-id: https://www2.in.tum.de/repos/ttt/trunk@117 0463f305-d864-43cb-8a47-61cf597d4139
parent cf90f973
// TeleTeachingTool - Presentation Recording With Automated Indexing
//
// Copyright (C) 2003-2008 Peter Ziewer - Technische Universitt Mnchen
//
// This file is part of TeleTeachingTool.
//
// TeleTeachingTool is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// TeleTeachingTool is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with TeleTeachingTool. If not, see <http://www.gnu.org/licenses/>.
/*
* Created on 28.04.2006
*
* Author: Peter Ziewer, TU Munich, Germany - ziewer@in.tum.de
*/
package ttt.postprocessing;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.SpringLayout;
import javax.swing.SwingConstants;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;
import ttt.Constants;
import ttt.TTT;
import ttt.gui.GradientPanel;
import ttt.gui.Index;
import ttt.gui.MyTitledBorder;
import ttt.gui.SpringUtilities;
import ttt.record.LectureProfile;
import ttt.record.Recording;
//
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// NOTE: This class is outdated - it contains the old post processing dialog
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//
public class PostProcessor extends JPanel {
// recording
private Recording recording;
private boolean modified;
private int script_creator_mode;
// GUI
private JTabbedPane tabbedPane;
private PostProcessor() {
tabbedPane = new JTabbedPane();
tabbedPane.addTab("Open", null, createOpenTab(), "select recording for post processing");
tabbedPane.addTab("Info", null, createInfoTab(), "see and modify metadata");
tabbedPane.setEnabledAt(1, false);
tabbedPane.addTab("Script", null, createScriptTab(), "create HTML Script");
tabbedPane.setEnabledAt(2, false);
tabbedPane.addTab("Full Text Search", null, createSearchbaseTab(),
"read and integrate searchbase for full text search");
tabbedPane.setEnabledAt(3, false);
tabbedPane.addTab("Finish", null, createFinishTab(), "process and store modified recording");
tabbedPane.setEnabledAt(4, false);
// TODO: remove nasty hack - used to get focus on open file text field
tabbedPane.setFocusable(false);
add(tabbedPane);
}
private void close() {
if (modified
&& JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(null, "Store modified recording?",
"Closing Post Processing", JOptionPane.YES_NO_OPTION)) {
store();
}
// close frame
Container parent = getParent();
while (parent != null) {
if (parent instanceof JInternalFrame) {
((JInternalFrame) parent).dispose();
break;
} else if (parent instanceof JFrame) {
((JFrame) parent).dispose();
break;
} else {
parent = parent.getParent();
}
}
}
private void store() {
// ensure thumbnails are available
if (!recording.thumbnailsAvailable())
try {
recording.createThumbnails();
modified = true;
} catch (IOException e) {
TTT.showMessage("Thumbnail creation failed:\nError: " + e, "Thumbnail Creator Failure",
JOptionPane.ERROR_MESSAGE);
}
// store
if (modified)
recording.store();
modified = false;
}
private void doScriptCreation() {
// generate whatever was selected
try {
if (script_creator_mode != 0) {
recording.createScript(script_creator_mode);
// remember to store thumbs
if ((script_creator_mode & ScriptCreator.THUMBNAILS) != 0)
modified = true;
script_creator_mode = 0;
}
} catch (IOException e) {
TTT
.showMessage("Script creation failed:\nError: " + e, "Script Creator Failure",
JOptionPane.ERROR_MESSAGE);
}
}
public static void main(String[] args) {
createStandalonePostProcessor();
}
// ////////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 1: load recording
// ////////////////////////////////////////////////////////////////////////////////////////////////////
private JComponent createOpenTab() {
// select file for postprocessing
final JTextField fileTextField = new JTextField(TTT.userPrefs.get("last_opened_recording", "."), 40);
// button for show file dialog
JButton selectFileButton = new JButton("...");
selectFileButton.setToolTipText("open file browser");
// file input and file browser button
JPanel filePanel = new JPanel();
filePanel.setLayout(new BoxLayout(filePanel, BoxLayout.X_AXIS));
filePanel.setAlignmentX(Component.LEFT_ALIGNMENT);
filePanel.add(fileTextField);
filePanel.add(Box.createRigidArea(new Dimension(10, 0)));
filePanel.add(selectFileButton);
// packing GUI together
JPanel panel = new JPanel();
panel.setOpaque(false);
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.add(Box.createRigidArea(new Dimension(0, 9)));
panel.add(new JLabel("Open TTT Recording:"));
panel.add(Box.createRigidArea(new Dimension(0, 20)));
panel.add(filePanel);
panel.add(Box.createRigidArea(new Dimension(0, 100)));
JLabel label = new JLabel("Reads file for post processing.");
label.setEnabled(false);
panel.add(label);
// action listener
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (arg0.getActionCommand().equals("cancel")) {
close();
} else
try {
recording = new Recording(fileTextField.getText());
modified = false;
// // create Thumbnails
// if (!recording.thumbnailsAvailable()) {
// recording.createThumbnails();
// modified = true;
// }
updateTabData();
// enable others
tabbedPane.setEnabledAt(1, true);
tabbedPane.setEnabledAt(2, true);
tabbedPane.setEnabledAt(3, true);
tabbedPane.setEnabledAt(4, true);
// goto next
tabbedPane.setSelectedIndex(1);
} catch (IOException e) {
TTT
.showMessage("Cannot open recording:\nError: " + e, "Open failed",
JOptionPane.ERROR_MESSAGE);
tabbedPane.setEnabledAt(1, false);
tabbedPane.setEnabledAt(2, false);
tabbedPane.setEnabledAt(3, false);
tabbedPane.setEnabledAt(4, false);
}
}
};
fileTextField.addActionListener(actionListener);
// fileTextField.requestFocus(true);
// action buttons
final JButton[] buttons = new JButton[2];
buttons[0] = new JButton("open");
buttons[0].addActionListener(actionListener);
buttons[1] = new JButton("cancel");
buttons[1].addActionListener(actionListener);
JComponent component = createTab(panel, buttons);
selectFileButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
File file = TTT.showFileDialog();
if (file != null)
try {
TTT.userPrefs.put("last_opened_recording", file.getCanonicalPath());
fileTextField.setText(file.getCanonicalPath());
buttons[0].doClick();
} catch (IOException e) {
System.out.println("File selection failed: " + e);
}
}
});
return component;
}
// ////////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 2: show metadata and check name
// ////////////////////////////////////////////////////////////////////////////////////////////////////
private JLabel titleLabel = new JLabel();
private JTextField titleTextField = new JTextField(25);
private JLabel timeLabel = new JLabel();
private JLabel resolutionLabel = new JLabel();
private JLabel versionLabel = new JLabel();
private JLabel thumbnailsLabel = new JLabel("Thumbnails:");
private JLabel fullTextSearchLabel = new JLabel("Full Text Search:");
private JCheckBox thumbsCheckBox;
private JComponent createInfoTab() {
JPanel panel = new JPanel(new SpringLayout());
panel.setOpaque(false);
panel.add(new JLabel("Title:"));
panel.add(titleLabel);
panel.add(new JLabel("change Title:"));
panel.add(titleTextField);
panel.add(new JLabel(" "));
panel.add(new JLabel(" "));
panel.add(new JLabel("Version:"));
panel.add(versionLabel);
panel.add(new JLabel("Resolution:"));
panel.add(resolutionLabel);
panel.add(new JLabel("Date:"));
panel.add(timeLabel);
panel.add(new JLabel(" "));
panel.add(new JLabel(" "));
// thumbnail generation
thumbsCheckBox = new JCheckBox();
thumbsCheckBox.setToolTipText("create and store thumbnails for this recording.");
thumbsCheckBox.setOpaque(false);
panel.add(new JLabel("Thumbnails:"));
panel.add(thumbnailsLabel);
thumbsCheckBox.setHorizontalAlignment(SwingConstants.RIGHT);
panel.add(thumbsCheckBox);
JLabel label = new JLabel("create thumbnails");
label.setToolTipText("create and store thumbnails for this recording.");
// label.setEnabled(false);
panel.add(label);
// Lay out the panel.
SpringUtilities.makeCompactGrid(panel, panel.getComponentCount() / 2, 2, // rows, cols
8, 8, // initX, initY
12, 8); // xPad, yPad
// action listener
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (arg0.getActionCommand().equals("skip"))
// reset
updateTabData();
else {
// set new title
if (!titleTextField.getText().equals(recording.prefs.name)) {
recording.prefs.name = titleTextField.getText();
modified = true;
}
// create thumbnails
if (thumbsCheckBox.isSelected())
script_creator_mode |= ScriptCreator.THUMBNAILS;
else
script_creator_mode &= (ScriptCreator.HTML_SCRIPT | ScriptCreator.OCR_OPTIMIZED);
}
// goto next
tabbedPane.setSelectedIndex(2);
}
};
titleTextField.addActionListener(actionListener);
// action buttons
JButton[] buttons = new JButton[2];
buttons[0] = new JButton("apply");
buttons[0].addActionListener(actionListener);
buttons[1] = new JButton("skip");
buttons[1].addActionListener(actionListener);
return createTab(panel, buttons);
}
// ////////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 3: create script & ocr input (& thumbnails)
// ////////////////////////////////////////////////////////////////////////////////////////////////////
private JComponent createScriptTab() {
// HTML script generation
final JCheckBox htmlScriptCheckBox = new JCheckBox(" create HTML Script ", TTT.userPrefs.getBoolean(
"post_process_html", true));
htmlScriptCheckBox
.setToolTipText("Creates a folder containing linked HTML pages incl. thumbnails and screenshots.");
htmlScriptCheckBox.setOpaque(false);
htmlScriptCheckBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
TTT.userPrefs.putBoolean("post_process_html", ((JCheckBox) event.getSource()).isSelected());
}
});
// packing GUI together
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setOpaque(false);
panel.add(Box.createRigidArea(new Dimension(0, 9)));
panel.add(new JLabel("HTML Script:"));
panel.add(Box.createRigidArea(new Dimension(0, 20)));
panel.add(htmlScriptCheckBox);
panel.add(Box.createRigidArea(new Dimension(0, 100)));
JLabel label = new JLabel("Creates a folder containing linked HTML pages");
label.setEnabled(false);
panel.add(label);
label = new JLabel("incl. thumbnails and screenshots.");
label.setEnabled(false);
panel.add(label);
// action buttons
JButton[] buttons = new JButton[2];
buttons[0] = new JButton("apply");
buttons[0].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (htmlScriptCheckBox.isSelected())
script_creator_mode |= ScriptCreator.HTML_SCRIPT;
else
script_creator_mode &= (ScriptCreator.THUMBNAILS | ScriptCreator.OCR_OPTIMIZED);
tabbedPane.setSelectedIndex(3);
}
});
buttons[1] = new JButton("skip");
buttons[1].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
tabbedPane.setSelectedIndex(3);
}
});
JComponent component = createTab(panel, buttons);
htmlScriptCheckBox.setFocusable(false);
return component;
}
// ////////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 4: read search base
// ////////////////////////////////////////////////////////////////////////////////////////////////////
private JTextField searchbaseTextField;
private JCheckBox ocrCheckBox;
private JComponent createSearchbaseTab() {
// OCR input generation
ocrCheckBox = new JCheckBox(" prepare full text search ", TTT.userPrefs.getBoolean("post_process_ocr", true));
ocrCheckBox
.setToolTipText("Create a folder containing screenshots without annotations optimized for Optical Character Recognition (OCR)");
ocrCheckBox.setOpaque(false);
ocrCheckBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
TTT.userPrefs.putBoolean("post_process_ocr", ((JCheckBox) event.getSource()).isSelected());
}
});
JButton ocrButton = new JButton("create OCR input");
ocrButton
.setToolTipText("Create a folder containing screenshots without annotations optimized for Optical Character Recognition (OCR)");
ocrButton.setOpaque(false);
ocrButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
script_creator_mode |= ScriptCreator.OCR_OPTIMIZED;
doScriptCreation();
}
});
// select searchbase file
searchbaseTextField = new JTextField("", 40);
// button for show file dialog
JButton selectFileButton = new JButton("...");
selectFileButton.setToolTipText("open file browser");
selectFileButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
try {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
public boolean accept(File f) {
String fname = f.getName().toLowerCase();
// TODO; use Constant Endings Field
return fname.endsWith(".xml") || fname.endsWith(".txt") || f.isDirectory();
}
public String getDescription() {
return "XML or TXT searchbase";
}
});
// ask user
int returnVal = fileChooser.showOpenDialog(TTT.getInstance());
if (returnVal == JFileChooser.APPROVE_OPTION) {
searchbaseTextField.setText(fileChooser.getSelectedFile().getCanonicalPath());
}
} catch (IOException e) {
System.out.println("File selection failed: " + e);
}
}
});
// file input and file browser button
JPanel filePanel = new JPanel();
filePanel.setLayout(new BoxLayout(filePanel, BoxLayout.X_AXIS));
filePanel.setAlignmentX(Component.LEFT_ALIGNMENT);
filePanel.add(searchbaseTextField);
filePanel.add(Box.createRigidArea(new Dimension(10, 0)));
filePanel.add(selectFileButton);
// packing GUI together
JPanel panel = new JPanel();
panel.setOpaque(false);
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
JPanel subPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
subPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
subPanel.setOpaque(false);
subPanel.add(new JLabel("Status: "));
subPanel.add(fullTextSearchLabel);
fullTextSearchLabel.setForeground(Color.BLUE);
panel.add(new JLabel("Full Text Search: "));
panel.add(Box.createRigidArea(new Dimension(0, 10)));
panel.add(indentation(subPanel));
panel.add(Box.createRigidArea(new Dimension(0, 50)));
final JPanel stepsPanel = new JPanel();
stepsPanel.setOpaque(false);
stepsPanel.setLayout(new BoxLayout(stepsPanel, BoxLayout.Y_AXIS));
// STEP 1
stepsPanel.add(new JLabel("Step 1: Create input for Optical Character Recognition:"));
stepsPanel.add(Box.createRigidArea(new Dimension(0, 10)));
stepsPanel.add(indentation(ocrButton));
stepsPanel.add(Box.createRigidArea(new Dimension(0, 30)));
// STEP 3
stepsPanel.add(new JLabel("Step 2: Optical Character Recognition ( OCR ):"));
stepsPanel.add(Box.createRigidArea(new Dimension(0, 10)));
JLabel label = new JLabel("1. run external OCR Software ( e.g. Omnipage )");
// label.setEnabled(false);
stepsPanel.add(indentation(label));
label = new JLabel("2. apply OCR to screenshots created in [Step 1]");
// label.setEnabled(false);
stepsPanel.add(indentation(label));
label = new JLabel("3. store recognized text as XML or TXT");
// label.setEnabled(false);
stepsPanel.add(indentation(label));
stepsPanel.add(Box.createRigidArea(new Dimension(0, 30)));
// STEP 3
stepsPanel.add(new JLabel("Step 3: Read searchbase created in [Step 2]:"));
stepsPanel.add(Box.createRigidArea(new Dimension(0, 10)));
stepsPanel.add(indentation(filePanel));
panel.add(stepsPanel);
// action listener
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (arg0.getActionCommand().equals("skip")) {
tabbedPane.setSelectedIndex(4);
} else
try {
String filename = searchbaseTextField.getText();
if (!new File(filename).exists()) {
TTT.showMessage("File Not Found: " + filename, "Loading Searchbase failed",
JOptionPane.ERROR_MESSAGE);
} else if (recording.readSearchbaseFromFile(filename)) {
modified = true;
tabbedPane.setSelectedIndex(4);
} else {
TTT.showMessage("Loading Searchbase failed: " + filename, "Loading Searchbase failed",
JOptionPane.ERROR_MESSAGE);
}
} catch (Exception e) {
TTT.showMessage("Loading Searchbase failed:\nError: " + e, "Loading Searchbase failed",
JOptionPane.ERROR_MESSAGE);
}
}
};
searchbaseTextField.addActionListener(actionListener);
// action buttons
JButton[] buttons = new JButton[2];
buttons[0] = new JButton("import searchbase");
buttons[0].addActionListener(actionListener);
buttons[1] = new JButton("skip");
buttons[1].addActionListener(actionListener);
ocrButton.setFocusable(false);
selectFileButton.setFocusable(false);
return createTab(panel, buttons);
}
// ////////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 5: store
// ////////////////////////////////////////////////////////////////////////////////////////////////////
private JComponent createFinishTab() {
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setOpaque(false);
panel.add(Box.createRigidArea(new Dimension(0, 9)));
panel.add(new JLabel("Process uncompleted tasks and store modified data."));
JButton[] buttons = new JButton[2];
buttons[0] = new JButton("finish");