//
// NudgePanel.java
// VideoAnnotate
//
// Created by Michael D. Fischer on 27/07/2006.
// Copyright (c) 2006, Centre for Social Anthropology and Computing,
// University of Kent. All rights reserved.
//
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// Neither the name of the Centre for Social Anthropology and Computing,
// University of Kent nor the names of its contributors may be used
// to endorse or promote products derived from this software without
// specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE
// COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
// BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
// OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import quicktime.qd.*;
import quicktime.*;
import quicktime.io.*;
import quicktime.std.*;
import quicktime.std.movies.*;
import quicktime.std.image.*;
// import quicktime.app.QTFactory;
// import quicktime.app.display.*;
// import quicktime.app.players.*;
// import quicktime.app.image.*;
// import quicktime.app.actions.*;
// import quicktime.app.anim.*;
// import quicktime.app.time.*;
import quicktime.std.clocks.TimeRecord;
public class MovieNudgePanel extends Panel{
public MovieNudgePanel (MediaPresenter mp) {
myPresenter = mp;
timeControl = new Canvas() {
public boolean mouseDown(Event e, int x, int y) {
try {
long t = myPresenter.getTime();
int s = myPresenter.getScale();
float r = (float) s / (float) 25;
int xp = getWidth()-x;
// xp = (int) (Math.pow((double)xp,1.414214) * r);
xp = (int) (Math.pow((double)xp,1.414214) * r);
if (t-xp < 0) xp= (int) t;
MovieController mc = getMovieController();
if (mc != null) {
TimeRecord ts = new TimeRecord(mc.getTimeScale(),t-xp);
TimeRecord te = new TimeRecord(mc.getTimeScale(),mc.getCurrentTime()-(t-xp));
mc.setSelectionBegin(ts);
mc.setSelectionDuration(te);
mc.setPlaySelection(true);
}
myPresenter.setTime(t-xp);
if (myPresenter.getRate() == 0) myPresenter.setRate(1.0);
currentPos = x;
repaint();
timeMonitor.repaint();
} catch(Exception ex) {
}
return true;
}
public void paint(Graphics g) {
g.setColor(Color.black);
g.drawRect(0,0,255,31);
g.setColor(Color.red);
if (currentPos > 0) g.fillOval(currentPos-6,10,12,12);
}
int currentPos = -1;
};
timeControl.setSize(256,32);
add (timeControl);
timeMonitor = new Canvas() {
public void paint(Graphics g) {
if (myPresenter.hasDrawer()) {
long t; int s;
try {
t = myPresenter.getTime();
s = myPresenter.getScale();
} catch (Exception e) {
t = 0;
s = 1;
}
g.drawString(new Long(t).toString(),5,16);
}
}
};
timeMonitor.setSize(64,32);
add (timeMonitor);
enableControl();
}
public void showTime() {
if (timeMonitor != null) {
timeMonitor.repaint();
}
}
void enableControl () {
timeControl.setEnabled (myPresenter.hasDrawer());
}
public void mediaSet() {
/* if (myPresenter != null && myPresenter.getMovieController() != null) {
// myQTCanvas.removeClient();
if (timer != null)
try {
timer.setActive (false);
} catch (Exception e) {
}
try {
timer = new Timer (3, 1, this, ((QTPlayer) myPresenter.getDrawable()).getMovieController().getMovie()) ;
timer.setActive(true);
} catch (Exception e) {
System.out.println("Timer not set");
}
}
*/
}
public MovieController getMovieController() {
if (myPresenter != null) {
return myPresenter.getMovieController();
} else
return null;
}
public boolean tickle (float er, int time) throws QTException {
timeMonitor.repaint();
return true;
}
public void timeChanged (int time) throws QTException {
// timeMonitor.repaint();
}
public Dimension getPreferredSize () {
return new Dimension (320, 38);
}
MediaPresenter myPresenter;
Canvas timeMonitor;
Canvas timeControl;
// private Timer timer;
}