public void sky(Node node, double xDest, double yDest) {
TranslateTransition tTrans = new TranslateTransition(
Duration.seconds(4), node);
// tTrans.setFromX(xPlec);
tTrans.setToX(xDest);
tTrans.setRate(2);
tTrans.setInterpolator(Interpolator.LINEAR);
// tTrans.setFromY(yPlec);
tTrans.setToY(yDest);
tTrans.setRate(2);
tTrans.setInterpolator(Interpolator.LINEAR);
node.setLayoutX(node.getLayoutX() + xDest);
node.setLayoutY(node.getLayoutY() + yDest);
tTrans.play();
}
And here is my method for when the button is pressed
public void setDateFwd(MouseEvent event) {
bFwd.setOnMouseClicked(e -> {
if (data.getValue().equals(LocalDate.of(2014, 8, 15))) {
sky(Sirius, 35.5, 4.5);
sky(Procyon, 35.5, 4.5);
sky(Beetlegeuse, 35.5, 4.5);
sky(Polux, 35.5, 4.5);
sky(Capella, 35.5, 4.5);
sky(Regulus, 35.5, 4.5);
sky(Rigel, 35.5, 4.5);
sky(Aldebaran, 35.5, 4.5);
sky(Castor, 35.5, 4.5);
sky(Mirphak, 35.5, 4.5);
}
});
}
if i click it the first time it works fine(it moves my object from point A to point B using animation) but if i click it the second time it just relocates the object(it makes it dissapear from point A and appear in point B) and i want it to move it from point A to point B so i can see it move along the distance, can anyone help please?
You need to specify fromXProperty and fromYProperty properties and should not change the layout values
public void sky(Node node, double xDest, double yDest) {
TranslateTransition tTrans = new TranslateTransition(Duration.seconds(4), node);
tTrans.setFromX(0);
tTrans.setFromY(0);
tTrans.setToX(xDest);
tTrans.setToY(yDest);
tTrans.setRate(2);
tTrans.setInterpolator(Interpolator.LINEAR);
tTrans.play();
}
Related
I'm at an impasse on this ever-present autocomplete widget in the Zoho app that I'm to test. It pops up on the CRM pages under test, and to handle it, I had the following util method:
public final class GeneralWebUIUtils {
// ... other utils
public static void HandleAutoComplete(TestObject textField, String input, TestObject loader, TestObject dropdownOption, boolean doScroll = false) {
WebUI.click(textField)
WebUI.setText(textField, input)
TimeLoggerUtil.LogAction({
WebUI.waitForElementVisible(loader, 3)
// TODO: somehow this is not working for state; // it ends up selecting the first dropdown value
return WebUI.waitForElementNotVisible(loader, 3)
},
"Loader",
"appear and disappear");
// TODO: do we really need if-condition here?
if (doScroll) {
this.ScrollDropdownOptionIntoView(dropdownOption)
}
WebUI.waitForElementVisible(dropdownOption, 3, FailureHandling.STOP_ON_FAILURE)
WebUI.click(dropdownOption)
}
public static void ScrollDropdownOptionIntoView(TestObject to) {
WebUI.executeJavaScript("arguments[0].scrollIntoView({block: 'center'})", [WebUiCommonHelper.findWebElement(to, 1)])
}
// ... other util methods
}
This seemed like the answer, until I have been dealing with, off and on for several month...
...it select "the wrong" dropdown option! For example, on a membership category autocomplete, we type in "Membership", and it would select [some other dropdown option with "Membership" in the name], before the first member category dropdown option became available.
Last night, I was up til 2am working on this and test cases that were using it. I ended up changing the code to:
public static void HandleAutoComplete(TestObject textField, String input, TestObject loader, TestObject dropdownOption, boolean doScroll = false) throws StepFailedException {
WebUI.click(textField)
WebUI.setText(textField, input)
TimeLoggerUtil.LogAction({
return WebUI.waitForElementNotVisible(loader, 3)
},
"Loader",
"disappear");
// TODO: do we really need if-condition here?
if (doScroll) {
this.ScrollDropdownOptionIntoView(dropdownOption)
}
TimeLoggerUtil.LogAction({
WebUI.waitForElementVisible(dropdownOption, 3);
return this.WaitForElementHasText(dropdownOption, input, 5, FailureHandling.STOP_ON_FAILURE);
},
"Dropdown option",
"become visible")
WebUI.verifyElementText(dropdownOption, input)
WebUI.click(dropdownOption)
}
public static boolean WaitForElementCondition(Closure<Boolean> onCheckCondition, TestObject to, int timeOut, FailureHandling failureHandling = FailureHandling.STOP_ON_FAILURE) {
final long startTime = System.currentTimeMillis()
boolean isConditionSatisfied = false;
while ((System.currentTimeMillis() < startTime + timeOut * 1000) && (!isConditionSatisfied)) {
isConditionSatisfied = onCheckCondition(to);
}
if ((!isConditionSatisfied) && (failureHandling.equals(FailureHandling.STOP_ON_FAILURE))) {
KeywordUtil.markFailedAndStop("Condition for TestObject '${to.getObjectId()}' not met after ${(System.currentTimeMillis() - startTime) / 1000} seconds");
}
return isConditionSatisfied;
}
public static boolean WaitForElementHasText(TestObject to, String expectedText, int timeOut, FailureHandling failureHandling = FailureHandling.STOP_ON_FAILURE) {
return this.WaitForElementCondition({ TestObject testObj ->
return WebUI.getText(testObj).contains(expectedText);
},
to,
timeOut,
failureHandling);
}
This is way the hell faster, and instead of silently doing incorrect behavior (i.e. selecting the wrong dropdown option), it will throw exception. It should just work!!! (It seems like the actual dropdown option isn't ready to be checked by the time we go to check it...)
I tried remedying it by tweaking WaitForElementHasText():
public static boolean WaitForElementHasText(TestObject to, String expectedText, int timeOut, FailureHandling failureHandling = FailureHandling.STOP_ON_FAILURE) {
return this.WaitForElementCondition({ TestObject testObj ->
return WebUI.verifyElementPresent(testObj, 1) && WebUI.getText(testObj).contains(expectedText);
},
to,
timeOut,
failureHandling);
}
No dice. It will still sometimes fail, and there doesn't seem to be a damn thing I can do about it....
....or is there?
How, outside of switching to modal view, which is more complicated to handle, can we handle the autocomplete once and for all?
No matter how hard I tried, I couldn't solve this the traditional way: using strategy patterns.
Why? Because, when I went to log the initial states of dropdownOption and loader, they were the exact same, regardless of whether the autocomplete handler was going to end up succeeding, or failing.
It looks like I have no control over the dropdownOption "flickers" even after we wait on it to exist!
So, I had to get creative:
public static boolean WaitForElementCondition(Closure<Boolean> onCheckCondition, Closure onContinue, TestObject to, int timeOut, FailureHandling failureHandling = FailureHandling.STOP_ON_FAILURE) {
final long startTime = System.currentTimeMillis()
boolean isConditionSatisfied = false;
while ((System.currentTimeMillis() < startTime + timeOut * 1000) && (!isConditionSatisfied)) {
isConditionSatisfied = onCheckCondition(to);
onContinue(isConditionSatisfied, to);
}
if ((!isConditionSatisfied) && (failureHandling.equals(FailureHandling.STOP_ON_FAILURE))) {
KeywordUtil.markFailedAndStop("Condition for TestObject '${to.getObjectId()}' not met after ${(System.currentTimeMillis() - startTime) / 1000} seconds");
}
return isConditionSatisfied;
}
public static boolean WaitForElementHasText(TestObject to, String expectedText, int timeOut, FailureHandling failureHandling = FailureHandling.STOP_ON_FAILURE) {
return this.WaitForElementCondition({ TestObject testObj ->
return WebUI.getText(testObj).contains(expectedText);
},
{ boolean success, TestObject tObj ->
if (!success) {
WebUI.waitForElementNotPresent(tObj, 1);
WebUI.waitForElementPresent(tObj, timeOut);
}
},
to,
timeOut,
failureHandling);
}
re-ran the test several times, and all was well!
I have work with Magento 1.8.1.0 Version, for my requirement i create a custom pagination.here the pagination link is not showing. in phtml file i added the line $this->getPagerHtml()
// model intiate
private function getModel() {
return Mage::getModel('retailers/retailersmodel');
}
// set the collection
public function __construct() {
parent::__construct();
$model = $this->getModel();
$collection = $model->getCollection();
$this->setCollection($collection);
}
//custom pagination code
protected function _prepareLayout() {
parent::_prepareLayout();
$pager = $this->getLayout()->createBlock('page/html_pager', 'custom.pager');
$pager->setAvailableLimit(array(5 => 5, 10 => 10, 20 => 20, 'all' => 'all'));
$pager->setCollection($this->getCollection());
$this->setChild('pager', $pager);
$this->getCollection()->load();
return $this;
}
public function getPagerHtml() {
return $this->getChildHtml('pager');
}
thanks for you idea and suggestion.
i have a problem with my Pager adapter timer , when user touches to adapter,and if user slides the image ,its working fine. but ,if he doesn't slide the image , my timer is getting faster and sometimes goes to next image.
here is my pager adapter which i am using in the activity
pagerAdapter.setTimer(myPager, 7, pagerAdapter.getCount(), pagerAdapter.currentPage);
myPager.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN://starts with down
//Log.e("TOUCH", "DOWN");
break;
case MotionEvent.ACTION_MOVE://moves finger
//todo check ifts working
if(pagerAdapter.timerworking){
Log.d("ACTION_MOVE", "currentPage"+pagerAdapter.currentPage);
pagerAdapter.stopTimer();
}
//Log.e("TOUCH", "MOVE");
break;
case MotionEvent.ACTION_UP://ends with up
//current +1 e kayitli oldugu icin bir onceki olmali
Log.d("ACTION_UP", "currentPage"+pagerAdapter.currentPage);
pagerAdapter.setTimer(myPager, 7, pagerAdapter.getCount(), pagerAdapter.currentPage);
//Log.e("TOUCH", "UP");
break;
case MotionEvent.ACTION_CANCEL:
//Log.e("TOUCH", "CANCEL");
break;
default:
break;
}
return false;
}
});
here is timer functions of my pager adapter(ImagePager)
/**
* this function swipes pages left to right for every 7 seconds
* #param myPager
* #param time
* #param numPages we recommend that it should be as much as much objects.size()
* #param curPage we recommend that it should start from 0
*
*/
public void setTimer(final ViewPager myPager, int time, final int numPages, final int curPage){
currentPage = curPage;
final Runnable Update = new Runnable() {
int NUM_PAGES =numPages;
public void run() {
if(timerworking){
Log.d("PagerTimer", "currentPage"+currentPage);
myPager.setCurrentItem(currentPage, true);
currentPage=(currentPage+1)%NUM_PAGES;
}
}
};
swipeTimer = new Timer();
swipeTimer.schedule(new TimerTask() {
#Override
public void run() {
handler.post(Update);
}
}, 1000, time*1000);//1000 =1 saniyede gecis suresi , 7000 kac saniyede bir degisecek
timerworking=true;
Log.d("PagerTimer", "timerRUN");
}
/**
* its kills runnable
*/
public void stopTimer(){
//handler.removeCallbacks(null);
swipeTimer.cancel();
timerworking=false;
Log.d("PagerTimer", "timerSTOP");
/*
clearTimer();
swipeTimer=null;
handler.removeCallbacksAndMessages(null);
handler.removeCallbacks(null);
*/
}
my intent to make this slider automatically slide for every 7 seconds, if user touches to screen, i want it to stop the counter and when user release touch and goes back to automatically slide (countdown of 7 seconds starts again ).
my problem is when user touches and doesn't slide , it goes to next slide, and its counter gets faster.
EDIT: i have realized that , my timer is controlling 3 threads which changes my adapter quickly.i guess i am creating more threads every time user interrupt
by changing
pagerAdapter.setTimer(myPager, 7, pagerAdapter.getCount(), pagerAdapter.currentPage);
in the case MotionEvent.ACTION_UP to this
if(!pagerAdapter.timerworking){
pagerAdapter.setTimer(myPager, 7, pagerAdapter.getCount(), pagerAdapter.currentPage);
}
i have prevented multiple threads
and also added function below to do image pager to get the current item to stay on it.
public void setOnPageChangeListener(ViewPager myPager){
myPager.setOnPageChangeListener(new OnPageChangeListener() {
#Override
public void onPageSelected(int arg0) {
//new page is selected , by the user or automatically
nextPage=(arg0)%NUM_PAGES;
Log.d("OnPageChange", "Selected Page is "+arg0);
Log.d("OnPageChange", "currentPage "+currentPage);
}
#Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
#Override
public void onPageScrollStateChanged(int arg0) {
}
});
}
and calling line below , before the myPager.setOnTouchListener , in th activity
pagerAdapter.setOnPageChangeListener(myPager);
b1.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent e) {
try {
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager
.getConnection("jdbc:mysql://localhost:3306/project?"
+ "user=root&password=virus");
statement = connect.createStatement();
preparedStatement = connect
.prepareStatement("select * from mark where clsnum = " + txt1.getText() + "");
rs = preparedStatement.executeQuery();
if (rs.next()) {
delete();
} else {
msg.setText("Student Not Found...!");
}
} catch (ClassNotFoundException | SQLException ex) {
Logger.getLogger(DeleteMark.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
This is my code to display a message if the query not worked(I mean if no row is returned to ResultSet rs). msg is an object of Text and its declaration and other details are -
Text msg = new Text();
msg.setFont(Font.font("Calibri", FontWeight.THIN, 18));
msg.setFill(Color.RED);
I want to make the Text disappear after sometime, like 3 or 4 seconds. Is it possible to do it in JavaFX (with the help of timer or something else you know) ? If yes, how ?
Use Timelines and/or Transitions.
This answer is for a previous iteration of the question.
Sample solution code
import javafx.animation.*;
import javafx.application.Application;
import javafx.scene.*;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.util.Duration;
public class BlinkingAndFading extends Application {
#Override
public void start(Stage stage) {
Label label = new Label("Blinking");
label.setStyle("-fx-text-fill: red; -fx-padding: 10px;");
Timeline blinker = createBlinker(label);
blinker.setOnFinished(event -> label.setText("Fading"));
FadeTransition fader = createFader(label);
SequentialTransition blinkThenFade = new SequentialTransition(
label,
blinker,
fader
);
stage.setScene(new Scene(new StackPane(label), 100, 50));
stage.show();
blinkThenFade.play();
}
private Timeline createBlinker(Node node) {
Timeline blink = new Timeline(
new KeyFrame(
Duration.seconds(0),
new KeyValue(
node.opacityProperty(),
1,
Interpolator.DISCRETE
)
),
new KeyFrame(
Duration.seconds(0.5),
new KeyValue(
node.opacityProperty(),
0,
Interpolator.DISCRETE
)
),
new KeyFrame(
Duration.seconds(1),
new KeyValue(
node.opacityProperty(),
1,
Interpolator.DISCRETE
)
)
);
blink.setCycleCount(3);
return blink;
}
private FadeTransition createFader(Node node) {
FadeTransition fade = new FadeTransition(Duration.seconds(2), node);
fade.setFromValue(1);
fade.setToValue(0);
return fade;
}
public static void main(String[] args) {
launch(args);
}
}
Answers to additional questions
lambda expression not expected here lambda expressions are not supported in -source 1.7 (use -source 8 or higher to enable lambda expressions)
You should use Java 8 and not set -source 1.7. If you wish to stick with Java 7 (which I don't advise for JavaFX work), you can replace the Lambda:
blinker.setOnFinished(event -> label.setText("Fading"));
with:
blinker.setOnFinished(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
label.setText("Fading");
}
});
actual and formal argument lists differ in length
Again, you should use Java 8. But if you wish to use Java 7, replace:
stage.setScene(new Scene(new StackPane(label), 100, 50));
with:
StackPane layout = new StackPane();
layout.getChildren().add(label);
stage.setScene(new Scene(layout, 100, 50));
Further recommendations
Good call on not having the text both blink and fade. Blinking text makes for pretty distracting UI, but just fading is fine.
I don't think I'd recommend fading an error message, at least until the user clicks on it or something like that. What if the user didn't see the error message before it faded away?
I am creating a game similar to Glider PRO. In the game, you control a paper airplane and you use air vents to keep you from falling on the floor. When the airplane collides with the air vent, (using collidesWith method) it pushes the airplane up. Now here is the problem, when I attach 2 air vents to the scene, only the first attached air vent works. The second one doesn't seem to collide with the airplane. I use the onManagedUpdate method in each air vent to check for the collision. This is my first time coding with AndEngine so any help on this will be greatly appreciated.
Here is the AirVent code:
public class AirVent extends Rectangle
{
private Sprite sprite;
private Glider glider;
public AirVent(float pX, float pY, float pWidth, float pHeight,
VertexBufferObjectManager pVertexBufferObjectManager,
ITextureRegion pITextureRegion)
{
super(pX, pY, pWidth, pHeight, pVertexBufferObjectManager);
sprite = new Sprite(0, 0, pITextureRegion, pVertexBufferObjectManager);
sprite.setSize(pWidth, pWidth / 2);
sprite.setPosition((pWidth / 2) - (sprite.getWidth() / 2), pHeight
- sprite.getHeight());
this.attachChild(sprite);
this.setAlpha(0);
}
public Sprite getSprite()
{
return sprite;
}
public void checkCollision()
{
if (glider.collidesWith(this))
{
glider.setGravity(glider.getConstantGravity() * -1f);
}
else
{
glider.setGravity(glider.getConstantGravity());
}
}
public void applyGliderInteraction(Glider glider)
{
this.glider = glider;
}
#Override
public void onManagedUpdate(float secondsElapsed)
{
this.checkCollision();
super.onManagedUpdate(secondsElapsed);
}
}
And the MainActivity code part:
#Override
protected Scene onCreateScene()
{
// TODO Auto-generated method stub
// 1 - Create new scene
final Scene scene = new Scene();
Sprite backgroundSprite = new Sprite(0, 0, this.mBackground, getVertexBufferObjectManager());
scene.attachChild(backgroundSprite);
roomChanger = new RoomChanger(0, 0, screenWidth, screenHeight, getVertexBufferObjectManager(), scene);
// 2 - Create the player
player1 = new Glider(339, 174, this.mPlayerGlider1, getVertexBufferObjectManager())
{
#Override
public void onManagedUpdate(float secondsElapsed)
{
if (player1.getLife() == 0)
{
// Execute your actions.
finish();
}
super.onManagedUpdate(secondsElapsed);
}
};
scene.attachChild(player1);
airVent = new AirVent(200, 100, 100, 400, getVertexBufferObjectManager(), this.mAirVent);
airVent.applyGliderInteraction(player1);
airVent2 = new AirVent(500, 100, 100, 400, getVertexBufferObjectManager(), this.mAirVent);
airVent2.applyGliderInteraction(player1);
scene.attachChild(airVent);
scene.attachChild(airVent2);
createControllers();
return scene;
}
I found the problem. The checkCollison() method works, but when I add a second AirVent, the if/else statements battle each other. Removing the else statement from the checkCollision() method fixed the issue but right now, that is not the way I want my game to behave.