Methods Summary |
---|
public void | addNotify()
super.addNotify();
if ( /*securityPrivelege && */ (jmfSecurity != null) ) {
String permission = null;
try {
if (jmfSecurity.getName().startsWith("jmf-security")) {
permission = "thread";
jmfSecurity.requestPermission(m, cl, args, JMFSecurity.THREAD);
m[0].invoke(cl[0], args[0]);
permission = "thread group";
jmfSecurity.requestPermission(m, cl, args, JMFSecurity.THREAD_GROUP);
m[0].invoke(cl[0], args[0]);
} else if (jmfSecurity.getName().startsWith("internet")) {
PolicyEngine.checkPermission(PermissionID.THREAD);
PolicyEngine.assertPermission(PermissionID.THREAD);
}
} catch (Throwable e) {
if (JMFSecurityManager.DEBUG) {
System.err.println("Unable to get " + permission +
" privilege " + e);
}
securityPrivelege = false;
// TODO: Do the right thing if permissions cannot be obtained.
// User should be notified via an event
}
}
if ( (jmfSecurity != null) && (jmfSecurity.getName().startsWith("jdk12"))) {
try {
final ProgressSlider slider = this;
Constructor cons = jdk12CreateThreadRunnableAction.cons;
timer = (MediaThread) jdk12.doPrivM.invoke(
jdk12.ac,
new Object[] {
cons.newInstance(
new Object[] {
MediaThread.class,
this
})});
timer.setName("Progress Slider thread");
// timer.useControlPriority();
cons = jdk12PriorityAction.cons;
jdk12.doPrivM.invoke(
jdk12.ac,
new Object[] {
cons.newInstance(
new Object[] {
timer,
new Integer(timer.getControlPriority())
})});
stopTimer = false;
timer.start();
} catch (Exception e) {
}
} else {
timer = new MediaThread(this);
timer.setName("Progress Slider thread");
timer.useControlPriority();
stopTimer = false;
timer.start();
}
|
public void | componentHidden(java.awt.event.ComponentEvent event)
|
public void | componentMoved(java.awt.event.ComponentEvent event)
|
public void | componentResized(java.awt.event.ComponentEvent event)
Dimension dim;
dim = this.getSize ();
if ( dim.width - leftBorder - rightBorder < 1 )
return;
grabberPosition = (int) (grabberPosition * ((float)(dim.width-leftBorder-rightBorder) / (this.width - leftBorder - rightBorder)));
this.width = dim.width;
sliderWidth = this.width - leftBorder - rightBorder;
|
public void | componentShown(java.awt.event.ComponentEvent event)
|
public synchronized void | controllerUpdate(javax.media.ControllerEvent event)
CachingControl cachingControl;
long length;
long progress;
if ( event instanceof CachingControlEvent ) {
cachingControl = ((CachingControlEvent)event).getCachingControl();
length = cachingControl.getContentLength ();
progress = cachingControl.getContentProgress ();
progressCaching = (double)progress / length;
repaint ();
} else if ( event instanceof MediaTimeSetEvent) {
resetMediaTime = true;
}
|
public synchronized void | dispose()
synchronized (syncStop) {
if (timer != null) {
stopTimer = true;
}
}
removeMouseListener( this );
removeMouseMotionListener( this );
removeComponentListener ( this );
synchronized (disposeLock) {
if (toolTip != null) {
toolTip.dispose();
toolTip = null;
}
}
timer = null;
player = null;
|
private java.lang.String | formatTime(javax.media.Time time)
long nano;
String strTime = new String ( "<unknown>" );
if ( time == null || time == Time.TIME_UNKNOWN || time == javax.media.Duration.DURATION_UNKNOWN )
return ( strTime );
nano = time.getNanoseconds();
strTime = formatTime ( nano );
return ( strTime );
|
private java.lang.String | formatTime(long nanoSeconds)
int hours;
int minutes;
int seconds;
int hours10;
int minutes10;
int seconds10;
long nano10;
String strTime;
seconds = (int) (nanoSeconds / Time.ONE_SECOND);
hours = seconds / 3600;
minutes = ( seconds - hours * 3600 ) / 60;
seconds = seconds - hours * 3600 - minutes * 60;
nanoSeconds = (long) ((nanoSeconds % Time.ONE_SECOND) / (Time.ONE_SECOND/100));
hours10 = hours / 10;
hours = hours % 10;
minutes10 = minutes / 10;
minutes = minutes % 10;
seconds10 = seconds / 10;
seconds = seconds % 10;
nano10 = nanoSeconds / 10;
nanoSeconds = nanoSeconds % 10;
strTime = new String ( "" + hours10 + hours + ":" + minutes10 + minutes + ":" + seconds10 + seconds + "." + nano10 + nanoSeconds );
return ( strTime );
|
public java.awt.Dimension | getPreferredSize()
return new Dimension(20, this.height);
|
public void | mouseClicked(java.awt.event.MouseEvent me)
|
public synchronized void | mouseDragged(java.awt.event.MouseEvent me)
float seek;
long value;
if (!isEnabled() || player == null)
return;
int newPosition = mouseToSlider(me.getX());
if (newPosition != grabberPosition) {
grabberPosition = newPosition;
seek = sliderToSeek(grabberPosition);
if (player.getState() != Controller.Started)
sliderSeek(seek);
value = (long) (seek * player.getDuration().getNanoseconds());
updateToolTip ( value );
repaint();
}
|
public synchronized void | mouseEntered(java.awt.event.MouseEvent me)
// Dimension dim;
Point pointScreen;
entered = true;
if ( toolTip == null && isEnabled() && player != null) {
toolTip = new ToolTip ( "time/duration" );
updateToolTip ( player.getMediaNanoseconds() );
if ( this.isShowing() ) {
pointScreen = this.getLocationOnScreen ();
// dim = toolTip.getSize ();
// pointScreen.x += me.getX() - dim.width - 2;
// pointScreen.y += me.getY();
// dim = this.getSize ();
pointScreen.y += this.height + 4;
toolTip.setLocation ( pointScreen );
toolTip.show ();
}
}
repaint();
|
public synchronized void | mouseExited(java.awt.event.MouseEvent me)
if ( toolTip != null && grabbed == false ) {
toolTip.dispose ();
toolTip = null;
}
if (!isEnabled())
return;
entered = false;
repaint();
|
public synchronized void | mouseMoved(java.awt.event.MouseEvent me)
Dimension dim;
Point pointScreen;
if ( toolTip != null && this.isShowing() ) {
dim = toolTip.getSize ();
pointScreen = this.getLocationOnScreen ();
pointScreen.x += me.getX() - dim.width - 2;
pointScreen.y += me.getY();
// toolTip.setLocation ( pointScreen );
}
|
public void | mousePressed(java.awt.event.MouseEvent me)
if (!isEnabled())
return;
grabbed = true;
grabberPosition = mouseToSlider(me.getX());
repaint();
|
public synchronized void | mouseReleased(java.awt.event.MouseEvent me)
if (!isEnabled())
return;
grabbed = false;
grabberPosition = mouseToSlider(me.getX());
float seek = sliderToSeek(grabberPosition);
sliderSeek(seek);
if ( toolTip != null && entered == false ) {
toolTip.dispose ();
toolTip = null;
}
repaint();
|
public int | mouseToSlider(int x)
if (x < leftBorder)
x = leftBorder;
if (x > this.width - rightBorder)
x = this.width - rightBorder;
x -= leftBorder;
return x;
|
public void | paint(java.awt.Graphics g)
// Draw the rod
int x;
int y;
int grabberY;
int downloadCredit;
String strTime;
Font font;
FontMetrics fontMetrics;
if (isEnabled()) {
y = (this.height / 2) - 2;
grabberY = (this.height / 2) - (grabberHeight / 2);
g.setColor( getBackground().darker() );
g.drawRect (leftBorder, y, sliderWidth, 3);
g.setColor(getBackground());
downloadCredit = grabberWidth;
g.draw3DRect(leftBorder, y, (int)((sliderWidth - downloadCredit) * progressCaching + downloadCredit), 3, false);
// Paint the download display
/*
if ((displayControl != null) && displayControl.isEnable()) {
int percent = (int) displayControl.getMaxValue();
if (percent < 100) {
g.setColor(Color.yellow); // Loading zone
x = sliderWidth * percent / 100 + 3;
y += 2;
g.drawLine(x, y, this.width - 4, y);
g.setColor(Color.green);
g.drawLine(0, y, x, y);
} else {
g.setColor(Color.green);
y += 2;
g.drawLine(0, y, this.width - 4, y);
}
}
*/
// Paint the grabber
if (grabbed || entered)
g.drawImage(imageGrabberDown,
grabberPosition + leftBorder - grabberWidth / 2, grabberY,
this);
else
g.drawImage(imageGrabber,
grabberPosition + leftBorder - grabberWidth / 2, grabberY,
this);
}
else if (player != null) {
strTime = formatTime ( player.getMediaNanoseconds() );
font = this. getFont ();
g.setFont ( font );
fontMetrics = this.getFontMetrics ( font );
g.drawString ( strTime, 2, 2 + fontMetrics.getAscent() );
}
|
public void | removeNotify()
if (timer != null) {
synchronized (syncStop) {
stopTimer = true;
timer = null;
}
}
synchronized (disposeLock) {
if ( toolTip != null ) {
toolTip.setVisible ( false );
//toolTip = null;
}
}
super.removeNotify();
|
public void | run()
int counter = 0;
int pausecnt = -1;
int sleepTime;
boolean doUpdate = true;
while (!stopTimer) {
try {
if ( player != null && player.getState() == Controller.Started) {
doUpdate = true;
pausecnt = -1;
} else if (player != null && pausecnt < 5) {
pausecnt ++;
doUpdate = true;
} else if ( resetMediaTime ) {
doUpdate = true;
resetMediaTime = false;
} else {
doUpdate = false;
}
try {
if (doUpdate) {
long nanoDuration = player.getDuration().getNanoseconds();
if (nanoDuration > 0) {
long nanoTime = player.getMediaNanoseconds();
// Update the time less often if the slider is not
// present.
seek((float)nanoTime / nanoDuration);
if ( grabbed == false )
updateToolTip ( nanoTime );
}
}
} catch (Exception e) { }
sleepTime = (isEnabled() ? 200 : 1000);
try { Thread.sleep(sleepTime); } catch (Exception e) {}
counter++;
if (counter == 1000/sleepTime) {
counter = 0;
controlPanel.update();
}
if (justSeeked) {
justSeeked = false;
try { Thread.sleep(1000); } catch (Exception e) {}
}
} catch (Exception e) {
}
}
|
public void | seek(float fraction)
if (justSeeked)
return;
if (!grabbed) {
int newPosition = (int) (fraction * sliderWidth);
if (newPosition > sliderWidth)
newPosition = sliderWidth;
if (newPosition < 0)
newPosition = 0;
if (grabberPosition != newPosition || !isEnabled()) {
grabberPosition = newPosition;
repaint();
}
}
|
private void | sliderSeek(float fraction)
if (player == null)
return;
long value = (long) (fraction * player.getDuration().getNanoseconds());
justSeeked = true;
if (value >= 0) {
player.setMediaTime(new Time(value));
controlPanel.resetPauseCount();
controlPanel.update();
}
|
public float | sliderToSeek(int x)
float s = (float)(x) / (float)(sliderWidth);
return s;
|
public void | updateToolTip(long nanoMedia)
String strTool;
Time timeDuration;
if ( toolTip == null || player == null )
return;
timeDuration = player.getDuration ();
strTool = new String ( formatTime(nanoMedia) + " / " + formatTime(timeDuration) );
toolTip.setText ( strTool );
|