Skip to content
This repository has been archived by the owner on Jun 24, 2021. It is now read-only.

Commit

Permalink
Merge from master
Browse files Browse the repository at this point in the history
  • Loading branch information
javafxports-github-bot committed Aug 3, 2018
2 parents 8f5ab1d + e39cb6f commit 1ba0255
Show file tree
Hide file tree
Showing 7 changed files with 648 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ public ColorPickerSkin(final ColorPicker control) {

pickerColorBox.getChildren().add(colorRect);
displayNode.setGraphic(pickerColorBox);

if (control.isShowing()) {
show();
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import javafx.beans.WeakInvalidationListener;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
Expand Down Expand Up @@ -190,6 +191,11 @@ public ComboBoxListViewSkin(final ComboBox<T> control) {
if (comboBox.isShowing()) {
show();
}
comboBox.sceneProperty().addListener(o -> {
if (((ObservableValue)o).getValue() == null) {
comboBox.hide();
}
});
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,8 @@ private void createPopup() {
getSkinnable().sceneProperty().addListener(o -> {
if (((ObservableValue)o).getValue() == null) {
hide();
} else if (getSkinnable().isShowing()) {
show();
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -147,6 +147,10 @@ public DatePickerSkin(final DatePicker control) {
hide();
}
});

if (control.isShowing()) {
show();
}
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package test.robot.javafx.scene;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.control.ColorPicker;
import javafx.scene.input.MouseButton;
import javafx.scene.layout.VBox;
import javafx.scene.robot.Robot;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.stage.WindowEvent;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.fail;

import test.util.Util;

public class ColorPickerTest {

static CountDownLatch startupLatch = new CountDownLatch(1);
static Robot robot;
static volatile Stage stage;
static volatile Scene scene;
static final int SCENE_WIDTH = 250;
static final int SCENE_HEIGHT = SCENE_WIDTH;
static VBox root;
int onShownCount = 0;
int onActionCount = 0;
ColorPicker colorPicker;
CountDownLatch onShownLatch;
CountDownLatch onActionLatch;

private void mouseClick(double x, double y) {
Util.runAndWait(() -> {
robot.mouseMove((int) (scene.getWindow().getX() + scene.getX() + x),
(int) (scene.getWindow().getY() + scene.getY() + y));
robot.mousePress(MouseButton.PRIMARY);
robot.mouseRelease(MouseButton.PRIMARY);
});
}

private void showColorPickerPalette() throws Exception {
onShownLatch = new CountDownLatch(1);
mouseClick(colorPicker.getLayoutX() + colorPicker.getWidth() - 15,
colorPicker.getLayoutY() + colorPicker.getHeight() / 2);
Thread.sleep(400); // ColorPicker takes some time to display the color palette.
waitForLatch(onShownLatch, 10, "Failed to show color palette.");
}

private void clickColorPickerPalette(int yFactor) throws Exception {
onActionLatch = new CountDownLatch(1);
mouseClick(colorPicker.getLayoutX() + colorPicker.getWidth() / 2,
colorPicker.getLayoutY() + colorPicker.getHeight() * yFactor);
Thread.sleep(400);
waitForLatch(onActionLatch, 10, "Failed to receive onAction callback.");
}

// This test is for verifying a specific behavior.
// 1. Remove ColorPicker, call ColorPicker.show() & add back ColorPicker.
// 2. Verify that the ColorPicker palette is shown using onShown,
// 2.1 Confirm that color palette is shown, using listener onAction.
// 3. Click on ColorPicker, color palette should get shown.
// 4. Repeat step 2.
// 4.1 Repeat step 2.1
// 5. Click on ColorPicker, color palette should get shown.
// 6. Remove & add back ColorPicker, color palette should get shown.
// 7. Confirm that color palette is shown, using listener onAction.

@Test
public void testColorPickerSceneChange() throws Exception {
Thread.sleep(1000); // Wait for stage to layout

// 1.
onShownLatch = new CountDownLatch(1);
Util.runAndWait(() -> {
root.getChildren().clear();
colorPicker.show();
root.getChildren().add(colorPicker);
});
waitForLatch(onShownLatch, 10, "Failed to show color palette.");
Thread.sleep(400); // ColorPicker takes some time to display the color palette.
// 2.
Assert.assertEquals("ColorPicker palette should be shown once.", 1, onShownCount);

// 2.1
clickColorPickerPalette(5);
Assert.assertEquals("ColorPicker palette should be clicked once.", 1, onActionCount);

// 3.
showColorPickerPalette();
// 4.
Assert.assertEquals("ColorPicker palette should have been shown two times.", 2, onShownCount);

// 4.1
clickColorPickerPalette(6);
Assert.assertEquals("ColorPicker palette have been clicked two times.", 2, onActionCount);

// 5.
showColorPickerPalette();
Assert.assertEquals("ColorPicker palette should have been shown three times.", 3, onShownCount);

// 6.
Util.runAndWait(() -> {
root.getChildren().clear();
root.getChildren().add(colorPicker);
});
Thread.sleep(400); // ColorPicker takes some time to display the color palette.

// 7.
clickColorPickerPalette(5);
Assert.assertEquals("ColorPicker palette should have been clicked three times.", 3, onActionCount);
}

@After
public void resetUI() {
Platform.runLater(() -> {
colorPicker.setOnShown(null);
colorPicker.setOnAction(null);
root.getChildren().clear();
});
}

@Before
public void setupUI() {
Platform.runLater(() -> {
colorPicker = new ColorPicker();
colorPicker.setOnShown(event -> {
onShownCount++;
onShownLatch.countDown();
});
colorPicker.setOnAction(event -> {
onActionCount++;
onActionLatch.countDown();
});
root.getChildren().add(colorPicker);
});
}

@BeforeClass
public static void initFX() throws Exception {
new Thread(() -> Application.launch(TestApp.class, (String[])null)).start();
waitForLatch(startupLatch, 10, "FX runtime failed to start.");
}

@AfterClass
public static void exit() {
Platform.runLater(() -> {
stage.hide();
});
Platform.exit();
}

public static class TestApp extends Application {
@Override
public void start(Stage primaryStage) {
robot = new Robot();
stage = primaryStage;
root = new VBox();
scene = new Scene(root, SCENE_WIDTH, SCENE_HEIGHT);
stage.setScene(scene);
stage.initStyle(StageStyle.UNDECORATED);
stage.addEventHandler(WindowEvent.WINDOW_SHOWN, e ->
Platform.runLater(startupLatch::countDown));
stage.setAlwaysOnTop(true);
stage.show();
}
}

public static void waitForLatch(CountDownLatch latch, int seconds, String msg) throws Exception {
Assert.assertTrue("Timeout: " + msg, latch.await(seconds, TimeUnit.SECONDS));
}
}
Loading

0 comments on commit 1ba0255

Please sign in to comment.