Skip to main content

Incomplete Triggers

2 replies [Last post]
mortennobel
Offline
Joined: 2004-11-03
Points: 0

One thing I like about like about animation part of scenegraph is the Trigger classes that acts as glue between event listeners and Clip.

My favorite example is the mouse over effect like in the following code:
Clip clip = Clip.create(5000,contentPane,"background",bgColorSrc,bgColorDest);
clip.setInterpolator(Interpolators.getLinearInstance());
clip.setAutoReverse(true);
MouseTrigger mouseTrigger = new MouseTrigger(clip, MouseTriggerEvent.ENTER);
contentPane.addMouseListener(mouseTrigger);

This work perfect on any AWT or Swing component, but I miss a SGMouseTrigger, that allows developers to add the same functionality on any SGNode.

A related question: Does Triggers exist in JavaFX Script language/API?

Kind regards,
Morten Nobel-Joergensen

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Chris Campbell

Hi Morten,

It's a perfectly good suggestion, but as I mentioned in a previous
email to this list [1], the team is currently focused on getting the
JavaFX APIs ready for the 1.0 release. So at this time we're not
making any API changes to Scenario, other than those required to
fulfill its role as the scene graph implementation layer for JavaFX.

The Trigger classes in Scenario are not completely vetted and exist
mainly as a bridge between the animation package and various graphical
packages. They're not needed in the JavaFX runtime API because the
JavaFX language makes it trivial to connect a scene graph node with
some behavior (such as toggling an animation) thanks to binding and
function pointers. Here's some simple code that demonstrates how easy
it is to provide a hover animation in JavaFX (works with the JavaFX
Preview SDK):

----
var fill = Color.RED;
var t = Timeline {
toggle: true
keyFrames: [
KeyFrame { time: 0s values: fill => Color.RED },
KeyFrame { time: 1s values: fill => Color.BLUE tween
Interpolator.LINEAR }
]
}
Frame {
stage: Stage {
content: [
Circle {
centerX: 100
centerY: 100
radius: 50
fill: bind fill
onMouseEntered: function(e) { t.start(); }
onMouseExited: function(e) { t.start(); }
}
]
}
visible: true
}
----

Most likely, the above will be even more straightforward by the time
1.0 ships. Even in its current form, it should help demonstrate why
explicit trigger classes aren't needed in the JavaFX runtime API.

Thanks,
Chris

[1] http://forums.java.net/jive/message.jspa?messageID=282828#282828

On Sep 8, 2008, at 1:08 PM, scenario@javadesktop.org wrote:
> One thing I like about like about animation part of scenegraph is
> the Trigger classes that acts as glue between event listeners and
> Clip.
>
> My favorite example is the mouse over effect like in the following
> code:
> Clip clip =
> Clip.create(5000,contentPane,"background",bgColorSrc,bgColorDest);
> clip.setInterpolator(Interpolators.getLinearInstance());
> clip.setAutoReverse(true);
> MouseTrigger mouseTrigger = new MouseTrigger(clip,
> MouseTriggerEvent.ENTER);
> contentPane.addMouseListener(mouseTrigger);
>
> This work perfect on any AWT or Swing component, but I miss a
> SGMouseTrigger, that allows developers to add the same functionality
> on any SGNode.
>
> A related question: Does Triggers exist in JavaFX Script language/API?
>
> Kind regards,
> Morten Nobel-Joergensen
> [Message sent by forum member 'mortennobel' (mortennobel)]
>
> http://forums.java.net/jive/thread.jspa?messageID=297890
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@scenegraph.dev.java.net
> For additional commands, e-mail: dev-help@scenegraph.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@scenegraph.dev.java.net
For additional commands, e-mail: dev-help@scenegraph.dev.java.net

mortennobel
Offline
Joined: 2004-11-03
Points: 0

Maybe I should add that a SGMouseListener could be implemented really simple, maybe something like:

import com.sun.scenario.animation.util.MouseTrigger;
import com.sun.scenario.animation.util.MouseTriggerEvent;
import com.sun.scenario.animation.Clip;
import com.sun.scenario.scenegraph.event.SGMouseListener;
import com.sun.scenario.scenegraph.SGNode;

import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;

/**
* @author Morten Nobel-Joergensen ( http://www.nobel-joergensen.com )
*/
public class SGMouseTrigger extends MouseTrigger implements SGMouseListener {
/**
* Creates a {@code MouseTrigger}, which should be added
* to a {@code Component} that will generate the mouse events of interest.
*/
public SGMouseTrigger(Clip clip, MouseTriggerEvent event) {
super(clip, event);
}

public void mouseClicked(MouseEvent e, SGNode node) {
mouseClicked(e);
}

public void mousePressed(MouseEvent e, SGNode node) {
mousePressed(e);
}

public void mouseReleased(MouseEvent e, SGNode node) {
mouseReleased(e);
}

public void mouseEntered(MouseEvent e, SGNode node) {
mouseEntered(e);
}

public void mouseExited(MouseEvent e, SGNode node) {
mouseExited(e);
}

public void mouseDragged(MouseEvent e, SGNode node) {
// ignore
}

public void mouseMoved(MouseEvent e, SGNode node) {
// ignore
}

public void mouseWheelMoved(MouseWheelEvent e, SGNode node) {
// ignore
}
}