/* * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * */ import javafx.application.Application; import javafx.embed.swing.SwingNode; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.input.MouseEvent; import javafx.scene.layout.BorderPane; import javafx.scene.layout.FlowPane; import javafx.stage.Stage; import javax.swing.JComponent; import javax.swing.JInternalFrame; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.SwingUtilities; /** * Create tests for RT-31957. * Test checks that cursor changes corresponding to SwingNode content. * @author andrei-eremeev */ public class CursorCorrespondsContentTest extends Application { private String[] components = new String[]{ "javax.swing.JTextField", "javax.swing.JTextArea", "javax.swing.JInternalFrame" }; private int count = 0; private SwingNode swingNode; private Button pass; private Button fail; private String[] description = new String[]{ "Check that mouse cursor changes when it moves on text field", "Check that mouse cursor changes\nwhen it moves on text area", "Check that mouse cursor changes\nwhen it moves on text area and\nalong border of internal frame" }; @Override public void start(Stage stage) throws Exception { stage.setTitle("CursorCorrespondsContentTest dialog"); final BorderPane pane = new BorderPane(); final FlowPane childPane = new FlowPane(); childPane.setAlignment(Pos.CENTER); childPane.setVgap(10); childPane.setHgap(10); childPane.setPadding(new Insets(10, 10, 10, 10)); pane.setPadding(new Insets(10, 10, 0, 10)); swingNode = new SwingNode(); init(swingNode, count); ButtonEventHandler handler = new ButtonEventHandler(); pass = new Button("Pass"); pass.setOnMouseClicked(handler); fail = new Button("Fail"); fail.setOnMouseClicked(handler); childPane.getChildren().addAll(pass, fail); pane.setCenter(swingNode); pane.setBottom(childPane); Scene scene = new Scene(pane, 500, 200); stage.setScene(scene); stage.show(); stage.centerOnScreen(); } private void init(final SwingNode swingNode, final int counter) { SwingUtilities.invokeLater(new Runnable() { public void run() { try { JComponent c = (JComponent) Class.forName(components[counter]).newInstance(); switch (counter) { case 0: ((JTextField) c).setText(description[counter]); break; case 1: ((JTextArea) c).setText(description[counter]); break; case 2: JPanel panel = new JPanel(); panel.setLayout(null); JInternalFrame frame = ((JInternalFrame) c); frame.setResizable(true); frame.setBounds(25, 25, 300, 100); JTextArea area = new JTextArea(description[counter]); frame.getContentPane().add(area); panel.add(frame); c = panel; frame.show(); break; default: throw new RuntimeException("Unexpected number : " + counter); } swingNode.setContent(c); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } }); } private class ButtonEventHandler implements EventHandler { private int failCount = 0; @Override public void handle(MouseEvent t) { if (t.getSource() == pass) { System.out.println("Testcase passed : " + (count + 1)); } if (t.getSource() == fail) { ++failCount; System.err.println("Testcase failed : " + (count + 1)); } if (++count == components.length) { if (failCount > 0) { System.exit(1); } else { System.exit(0); } } init(swingNode, count); } } public static void main(String[] args) { launch(args); } }