Bluej keeps rounding my double... How do I get it to stop? - interface

I am doing a project, I have a test file and interface and I am told to make a "line" file that successfully implements the interface and checks out successful on all the tests.
It implements and is successful on 3 of the 4 tests but fails on the last because it rounds the slope to 1.0...
Here is the code for the tester:
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* The test class LineTest.
*
* #author (your name)
* #version (a version number or a date)
*/
public class LineTest
{
/**
* Default constructor for test class LineTest
*/
public LineTest()
{
}
/**
* Sets up the test fixture.
*
* Called before every test case method.
*/
#Before
public void setUp()
{
}
/**
* Tears down the test fixture.
*
* Called after every test case method.
*/
#After
public void tearDown()
{
}
#Test
public void testConstructor()
{
Line line1 = new Line(10, 10, 25, 25);
assertEquals(10, line1.getXOne());
assertEquals(25, line1.getXTwo());
assertEquals(10, line1.getYOne());
assertEquals(25, line1.getYTwo());
}
#Test
public void testGetSlope()
{
Line line1 = new Line(10, 10, -25, -25);
assertEquals(0.0, line1.getSlope(), 0.1);
line1.print();
}
#Test
public void testCalcSlope()
{
Line line1 = new Line(10, 10, -25, -25);
line1.calculateSlope();
assertEquals(1.0, line1.getSlope(), 0.1);
line1.print();
}
#Test
public void testSetCoords()
{
Line line1 = new Line(10, 10, -25, -35);
line1.calculateSlope();
assertEquals(1.285, line1.getSlope(), 0.003);
line1.print();
line1.setCoordinates(10, 10, 25, 35);
line1.calculateSlope();
assertEquals(1.667, line1.getSlope(), 0.001);
line1.print();
}
}
Here is the line class:
public class Line
{
private int xOne,yOne, xTwo, yTwo;
private double slope;
public Line(int x1, int y1, int x2, int y2)
{
xOne=x1;
yOne=y1;
xTwo=x2;
yTwo=y2;
}
public void setCoordinates(int x1, int y1, int x2, int y2)
{
x1=xOne;
y1=yOne;
x2=xTwo;
y2=yTwo;
}
public void calculateSlope( )
{
slope = (((yTwo)-(yOne))/((xTwo)-(xOne)));
}
public void print( )
{
System.out.println("The slope of the line created by the points ("+xOne+","+yOne+"), and ("+xTwo+","+yTwo+") is "+slope+".");
}
public int getXOne(){
return xOne;
}
public int getXTwo(){
return xTwo;
}
public int getYOne(){
return yOne;
}
public int getYTwo(){
return yTwo;
}
public double getSlope(){
return slope;
}
}
Here is the interface:
public interface TestableLine
{
public void setCoordinates(int x1, int y1, int x2, int y2);
public void calculateSlope( );
public void print( );
public int getXOne();
public int getYOne();
public int getXTwo();
public int getYTwo();
public double getSlope();
}
What is wrong here? I have tried specifying the number of decimals to round to, it just makes test 3 fail as well.

You are calculating the slope only with int values. In the method which calculates the slope you can create double variables out of the int values and use those to make the calculation.

Related

can't find method java

So I run the following program and my cmd prompt gives me an error saying that the getDescriptions() method is not found in the DataElements class. I'm sure there's a simple solution but I'm just stuck. Here's the DataElements class:
import java.io.*;
public class DataElements
{
File file;
private int columns;
private int row;
private int length;
private String name;
private String type;
private int position;
private String[] descriptions;
public File getFile(){
return file;
}
public void setFile(File f){
file = f;
}
public int getColumns(){
return columns;
}
public void setColumns(int c){
columns = c;
}
public int getRow(){
return row;
}
public void setRow(int r){
row = r;
}
public int getLength(){
return length;
}
public void setLength(int l){
length = l;
}
public String getName(){
return name;
}
public void setName(String n){
name = n;
}
public String getType(){
return type;
}
public void setType(String t){
type = t;
}
public int getPosition(){
return position;
}
public void setPosition(int p){
position = p;
}
public String[] getDescriptions(){
return description;
}
public void setDescriptions(String[] d){
description = d;
}
}
And here's the main method. If you need the CMSReader class let me know, but the problem seems to be stuck in these two classes
import java.util.Scanner;
import java.io.*;
public class Project2{
public static void main(String[] args) throws FileNotFoundException{
Scanner keyboard = new Scanner(System.in);
boolean fileParsed = false;
String inFile;
String outFile;
if(args.length != 1){
System.out.println("Error. Enter one argument: the file that needs to be parsed.");
System.exit(0);
}
Scanner scan = new Scanner(new File(args[0]));
DataElements storage = new DataElements();
CMSReader reader = new CMSReader(scan,storage);
reader.scanTopData();
System.out.println("Input File - " + storage.getName());
System.out.println("Output File - ");//*************Look at this*********************
System.out.println("Number of Variables - " + storage.getColumns());
System.out.println("Number of Records - " + storage.getRow());
System.out.println("Record Length - " + storage.getLength());
System.out.println("Variable information:");
reader.scanVariableData();
String[] variableData = storage.getDescriptions();
for(int i = 0; i < variableData.length ; i++){
System.out.println(variableData[i]);
}
}
}
I appreciate any help. Like I said, I'm sure it's something dumb but I've been looking at this for too long.
The variable description is not declared in your DataElements class, which is why DataElements file cannot compile, and my guess is that you have an older compiled version (.class file) of DataElements which does not contain that method.
Recommendation:
Start working with a good IDE (IntelliJ is my personal favorite, but Eclipse and Netbeans are also good options). A good IDE, on top of all other goodies it provides, will highlight such issues in a way you won't miss.

nunit/mbunit parameterized SetUp

I'd like to provide parameterized data for the setup of a test. Something like this:
[TestCase("1", "2")
[TestCase("a", "b")
public class TestFixture
{
[SetUp]
public void SetUp(string x, string y)
{
Console.WriteLine("Setup with {0}, {1}", x, y);
}
[Test]
public void Test() {...}
}
But I can only manage to get parameters passed to the testcase itself.
I prefer solutions for either nunit or mbunit but open for alternatives (yet to settle on which test framework to use). This is ultimately for a set of Selenium system-tests where the setup creates a browser session.
[edit]
Using NUnit I can get this working:
[TestFixture("1", "2")]
[TestFixture("a", "b")]
public class Tests
{
private string _x;
private string _y;
public Tests(string x, string y)
{
_x = x;
_y = y;
}
[SetUp]
public void SetUp()
{
Console.WriteLine("Setup with {0}, {1}", _x, _y);
}
[Test]
public void Test()
{
}
}
[/edit]
That seems to suit my needs, but I'll leave the question open for a few days to see if alternatives are suggested.
Using NUnit I can get this working:
[TestFixture("1", "2")]
[TestFixture("a", "b")]
public class Tests
{
private string _x;
private string _y;
public Tests(string x, string y)
{
_x = x;
_y = y;
}
[SetUp]
public void SetUp()
{
Console.WriteLine("Setup with {0}, {1}", _x, _y);
}
[Test]
public void Test()
{
}
}

Vector3 not serializable Unity3D

Ok so I followed the Unity3D data persistence tutorial, everything is going smoothly until I tried to save a Vector3 type of data. The tutorial only shows how to save int and strings.
When I used the function Save() , the consoles shows me that says: "SerializationException: Type UnityEngine.Vector3 is not marked as Serializable.
But as you can see from my code, I included it under the Serializable part. I am trying to save my playerPosition. Thanks
using UnityEngine;
using System.Collections;
using System;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System.Collections.Generic;
public class GameManager : MonoBehaviour
{
public static GameManager control;
public float health;
public float mana;
public float experience;
public Vector3 playerPosition;
public List<Item> inventory = new List<Item>();
void Awake()
{
if(control == null)
{
DontDestroyOnLoad(gameObject);
control = this;
}
else if(control != this)
{
Destroy(gameObject);
}
}
// Use this for initialization
void Start (){}
// Update is called once per frame
void Update () {}
void OnGUI()
{
GUI.Box(new Rect(10, 10, 100, 30), "Health: " + health);
GUI.Box(new Rect(10, 30, 100, 30), "Mana: " + mana);
GUI.Box(new Rect(10, 50, 100, 30), "Experience: " + experience);
}
public void SaveSlot1()
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Create(Application.persistentDataPath +
"/saveData1.dat");
PlayerData data = new PlayerData();
data.health = health;
data.mana = mana;
data.experience = experience;
data.playerPosition = playerPosition;
for(int i = 0; i <inventory.Count; i++)
{
//data.inventory[i] = inventory[i];
}
bf.Serialize(file, data);
file.Close();
}
public void LoadSlot1()
{
if(File.Exists(Application.persistentDataPath +
"/saveData1.dat") )
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath +
"/saveData1.dat", FileMode.Open);
PlayerData data = (PlayerData)bf.Deserialize(file);
file.Close();
health = data.health;
mana = data.mana;
experience = data.experience;
playerPosition = data.playerPosition;
for(int i = 0; i <inventory.Count; i++)
{
//inventory[i] = data.inventory[i];
}
}
}
[Serializable]
class PlayerData
{
public float health;
public float mana;
public float experience;
public Vector3 playerPosition;
public List<Item> inventory = new List<Item>();
//position
//spells
//
}
}
Marking something as Serializable just let's .NET to know that you are going to be using serialization. At that point every property all the way down the data model must also be serializable, either by being inherently serializable like ints and strings, or being a type that is also marked as serializable. There's a couple of options
[Serializable]
class PlayerData
{
public PlayerData()
{
playerPosition = Vector3.zero;
}
public float health;
public float mana;
public float experience;
[NonSerialized]
public Vector3 playerPosition;
public double playerPositionX
{
get
{
return playerPosition.x;
}
set
{
playerPosition.x = value;
}
}
public double playerPositionY
{
get
{
return playerPosition.y;
}
set
{
playerPosition.y = value;
}
}
public double playerPositionZ
{
get
{
return playerPosition.z;
}
set
{
playerPosition.z = value;
}
}
public List<Item> inventory = new List<Item>();
}
This first option will not serialize the vector field, and instead use the properties. Having a vector to start with is important.
The other option is to implement the ISerializable interface on your class and then specifically control what fields are being written. The interface is somewhat tricky to implement, here is a MSDN link that explains some good and bad examples

how to generate html report if my Junit is not run by Ant but by JunitCore.run

I worked on a project in which testclasses are run via JunitCore.run(testClasses) not via Ant because I have to run the project even with no ANT framework (so no Testng for the same reason). But I still need to create html and xml reports same as JUNIT/ANT. How to generate them in my case?
Right now I found https://github.com/barrypitman/JUnitXmlFormatter/blob/master/src/main/java/barrypitman/junitXmlFormatter/AntXmlRunListener.java may be used to generate xml report. How do I generate html similar to junit-noframes.html? Are there existing methods to convert the TESTS-TestSuites.xml to junit-noframes.html and how? if not, how to generate the html? I do not even find the standard of the html format.
1) Write a test class
import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class MyTest{
#Test
public void test(){
int i=5;
int j=5;
assertTrue(i==j);
}
#Test
public void test2(){
int i=5;
int j=15;
assertTrue(i!=j);
}
}
2)Create a class which extends RunListner:
import org.junit.runner.Description;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunListener;
public class MyRunListner extends RunListener{
private int numberOfTestClass;
private int testExecuted;
private int testFailed;
private long begin;
public MyRunListner(int numberOfTestClass){
this.setBegin(System.currentTimeMillis());
this.numberOfTestClass = numberOfTestClass;
}
public void testStarted(Description description) throws Exception{
this.testExecuted += 1;
}
public void testFailure(Failure failure) throws Exception{
this.testFailed += 1;
}
/**
* #return the numberOfTestClass
*/
public int getNumberOfTestClass(){
return numberOfTestClass;
}
/**
* #param numberOfTestClass the numberOfTestClass to set
*/
public void setNumberOfTestClass(int numberOfTestClass){
this.numberOfTestClass = numberOfTestClass;
}
/**
* #return the testExecuted
*/
public int getTestExecuted(){
return testExecuted;
}
/**
* #param testExecuted the testExecuted to set
*/
public void setTestExecuted(int testExecuted){
this.testExecuted = testExecuted;
}
/**
* #return the testFailed
*/
public int getTestFailed(){
return testFailed;
}
/**
* #param testFailed the testFailed to set
*/
public void setTestFailed(int testFailed){
this.testFailed = testFailed;
}
/**
* #return the begin
*/
public long getBegin(){
return begin;
}
/**
* #param begin the begin to set
*/
public void setBegin(long begin){
this.begin = begin;
}
}
3) Generate the report.
import java.io.FileWriter;
import java.io.IOException;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
public class JUnitTest{
public static void main(String[] args){
JUnitTest junit = new JUnitTest();
junit.runTest();
}
public void runTest(){
try {
String filePath = "C:/temp";
String reportFileName = "myReport.htm";
Class[] myTestToRunTab = {MyTest.class};
int size = myTestToRunTab.length;
JUnitCore jUnitCore = new JUnitCore();
jUnitCore.addListener(new MyRunListner(myTestToRunTab.length));
Result result = jUnitCore.run(myTestToRunTab);
StringBuffer myContent = getResultContent(result,size);
writeReportFile(filePath+"/"+reportFileName,myContent);
}
catch (Exception e) {
}
}
private StringBuffer getResultContent(Result result,int numberOfTestFiles){
int numberOfTest = result.getRunCount();
int numberOfTestFail = result.getFailureCount();
int numberOfTestIgnore = result.getIgnoreCount();
int numberOfTestSuccess = numberOfTest-numberOfTestFail-numberOfTestIgnore;
int successPercent = (numberOfTest!=0) ? numberOfTestSuccess*100/numberOfTest : 0;
double time = result.getRunTime();
StringBuffer myContent = new StringBuffer("<h1>Junit Report</h1><h2>Result</h2><table border=\"1\"><tr><th>Test Files</th><th>Tests</th><th>Success</th>");
if ((numberOfTestFail>0)||(numberOfTestIgnore>0)) {
myContent.append("<th>Failure</th><th>Ignore</th>");
}
myContent.append("<th>Test Time (seconds)</th></tr><tr");
if ((numberOfTestFail>0)||(numberOfTestIgnore>0)) {
myContent.append(" style=\"color:red\" ");
}
myContent.append("><td>");
myContent.append(numberOfTestFiles);
myContent.append("</td><td>");
myContent.append(numberOfTest);
myContent.append("</td><td>");
myContent.append(successPercent);
myContent.append("%</td><td>");
if ((numberOfTestFail>0)||(numberOfTestIgnore>0)) {
myContent.append(numberOfTestFail);
myContent.append("</td><td>");
myContent.append(numberOfTestIgnore);
myContent.append("</td><td>");
}
myContent.append(Double.valueOf(time/1000.0D));
myContent.append("</td></tr></table>");
return myContent;
}
private void writeReportFile(String fileName,StringBuffer reportContent){
FileWriter myFileWriter = null;
try {
myFileWriter = new FileWriter(fileName);
myFileWriter.write(reportContent.toString());
}
catch (IOException e) {
}
finally {
if (myFileWriter!=null) {
try {
myFileWriter.close();
}
catch (IOException e) {
}
}
}
}
}
4) Finally our report is ready
I hope it helps you!
In fact I solved the problem myself in this way:
First I use https://code.google.com/p/reporting-junit-runner/source/browse/trunk/src/junitrunner/XmlWritingListener.java?spec=svn2&r=2
to create TESTS-*.xml
Then I write the following code myself to create TEST-SUITE.xml and junit-noframes.html. The idea is make use of API of ANT to create reports without really running test. so far the solution works for me.
Project project = new Project();
//a fake project feeding to ANT API so that latter not complain
project.setName("dummy");
project.init();
FileSet fs = new FileSet();
fs.setDir(new File(reportToDir));
fs.createInclude().setName("TEST-*.xml");
XMLResultAggregator aggregator = new XMLResultAggregator();
aggregator.setProject(project);
aggregator.addFileSet(fs);
aggregator.setTodir(new File(reportToDir));
//create TESTS-TestSuites.xml
AggregateTransformer transformer = aggregator.createReport();
transformer.setTodir(new File(reportToDir));
Format format = new Format();
format.setValue(AggregateTransformer.NOFRAMES);
transformer.setFormat(format);
//create junit-noframe.html
aggregator.execute();

Is there an event in JavaFX8 when a stage gets disabled by a modal stage?

I am trying to create a status bar for our project. What I would like to happen is to change the status bar message whenever the primary stage got disabled by a modal stage (e.g. dialog).
It is currently implemented by changing the status message manually before and after showing the modal stage. Is there a better way to do this?
There is a very simple way to do this, assuming that you only have one dialog:
statusLabel.textProperty().bind(Bindings.when(dialog.showingProperty())
.then("Modal Dialog is showing").otherwise("Main window is showing"));
Alternatively, if you have multiple dialogs, you can do:
List<Stage> dialogs = ...
statusLabel.textProperty().bind(new StringBinding() {
{
for (Stage dialog : dialogs)
bind(dialog.showingProperty());
}
protected String computeValue() {
for (Stage dialog : dialogs)
if (dialog.isShowing())
return "A modal dialog is showing";
return "Main window is showing";
}
});
EDIT: Currently, there is no simple way to determine whether or not a given window is blocked by another modal window, assuming you have no knowledge of (or don't want to keep track of) all of the child windows you've created. Also, if you are using a FileChooser or a DirectoryChooser, the above method completely falls apart.
However, by inserting a custom Toolkit into javafx, you can obtain the desired behavior. A word of caution: using classes in com.sun.* directly in your code is usually not a good idea. But in the spirit of adventure, I have implemented one such Toolkit which (I believe) is working correctly. It should work with both WINDOW_MODAL and APPLICATION_MODAL windows. Use at your own risk! Here goes:
public class Test extends Application {
public static final StringProperty readyLabelProperty = new SimpleStringProperty("Ready");
public static final StringProperty blockedLabelProperty = new SimpleStringProperty("Blocked");
public static void main(String[] args) {
Tk.register();
Application.launch(args);
}
private static StringBinding statusBinding(Window window) {
return Bindings.when(Tk.blockedProperty(window)).then(blockedLabelProperty).otherwise(readyLabelProperty);
}
#Override
public void start(Stage s) throws Exception {
s.show();
s.titleProperty().bind(statusBinding(s));
Stage stage = new Stage();
stage.initOwner(s);
stage.initModality(Modality.WINDOW_MODAL);
stage.titleProperty().bind(statusBinding(stage));
stage.show();
new FileChooser().showOpenDialog(stage);
}
}
public class Tk extends Toolkit {
public static final BooleanBinding blockedProperty(final Window window) {
Objects.requireNonNull(window);
return new BooleanBinding() {
{
bind(stageImpls, owners);
}
#Override
protected boolean computeValue() {
try {
return StageImpl.get(window).isBlocked();
} catch (NullPointerException e) {
return false;
}
}
};
}
private static final Field TOOLKIT = getField(Toolkit.class, "TOOLKIT");
private static Field getField(Class<?> clazz, String name) {
try {
Field f = clazz.getDeclaredField(name);
f.setAccessible(true);
return f;
} catch (NoSuchFieldException e) {
return getField(clazz.getSuperclass(), name);
}
}
private static Method getMethod(Class<?> clazz, String name, Class<?>...parameterTypes) {
try {
Method m = clazz.getDeclaredMethod(name, parameterTypes);
m.setAccessible(true);
return m;
} catch (NoSuchMethodException e) {
return getMethod(clazz.getSuperclass(), name);
}
}
private static final Object invoke(Method method, Object obj, Object...args) {
try {
return method.invoke(obj, args);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
private final Toolkit qt = Toolkit.getToolkit();
private static Tk current;
public static void register() {
current = new Tk();
rewrap();
}
private static void unwrap() {
current = (Tk)Toolkit.getToolkit();
try {
TOOLKIT.set(null, current.qt);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
private static void rewrap() {
try {
TOOLKIT.set(null, Objects.requireNonNull(current));
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
private static final ObservableList<StageImpl> owners = FXCollections.observableArrayList();
private static final ObservableList<StageImpl> stageImpls = new ModifiableObservableListBase<StageImpl>() {
final ArrayList<StageImpl> list = new ArrayList<>();
final InvalidationListener l = new InvalidationListener() {
public void invalidated(Observable obs) {
beginChange();
nextUpdate(indexOf(StageImpl.get((Window)((ReadOnlyBooleanProperty)obs).getBean())));
endChange();
}
};
public StageImpl get(int index) {
return list.get(index);
}
public int size() {
return list.size();
}
protected void doAdd(int index, StageImpl element) {
list.add(index, element);
element.peer.showingProperty().addListener(l);
}
protected StageImpl doSet(int index, StageImpl element) {
StageImpl replaced = list.set(index, element);
replaced.peer.showingProperty().removeListener(l);
element.peer.showingProperty().addListener(l);
return replaced;
}
protected StageImpl doRemove(int index) {
StageImpl removed = list.remove(index);
removed.peer.showingProperty().removeListener(l);
return removed;
}
};
public TKStage createTKStage(Window w, StageStyle s, boolean primary, Modality m, TKStage owner, boolean rtl, AccessControlContext acc) {
return new StageImpl(qt.createTKStage(w, s, primary, m, owner == null ? null : StageImpl.get(owner).qs, rtl, acc), w, owner, m);
}
public FileChooserResult showFileChooser(TKStage owner, String title, File dir, String name, FileChooserType type,
List<ExtensionFilter> filters, ExtensionFilter selected) {
if (owner == null)
return qt.showFileChooser(null, title, dir, name, type, filters, selected);
StageImpl ownerImpl = StageImpl.get(owner);
owners.add(ownerImpl);
FileChooserResult result = qt.showFileChooser(ownerImpl.qs, title, dir, name, type, filters, selected);
owners.remove(ownerImpl);
return result;
}
public File showDirectoryChooser(TKStage owner, String title, File dir) {
if (owner == null)
return qt.showDirectoryChooser(null, title, dir);
StageImpl ownerImpl = StageImpl.get(owner);
owners.add(ownerImpl);
File file = qt.showDirectoryChooser(ownerImpl.qs, title, dir);
owners.remove(ownerImpl);
return file;
}
public boolean init() {
return qt.init();
}
public void startup(Runnable userStartupRunnable) {
qt.startup(userStartupRunnable);
}
public void checkFxUserThread() {
qt.checkFxUserThread();
}
public Future<?> addRenderJob(RenderJob r) {
return qt.addRenderJob(r);
}
public AppletWindow createAppletWindow(long parent, String serverName) {
return qt.createAppletWindow(parent, serverName);
}
public void closeAppletWindow() {
qt.closeAppletWindow();
}
public Object enterNestedEventLoop(Object key) {
return qt.enterNestedEventLoop(key);
}
public void exitNestedEventLoop(Object key, Object rval) {
qt.exitNestedEventLoop(key, rval);
}
public TKStage createTKPopupStage(Window peerWindow, StageStyle popupStyle,
TKStage owner, AccessControlContext acc) {
return qt.createTKPopupStage(peerWindow, popupStyle, owner, acc);
}
public TKStage createTKEmbeddedStage(HostInterface host,
AccessControlContext acc) {
return qt.createTKEmbeddedStage(host, acc);
}
public ScreenConfigurationAccessor setScreenConfigurationListener(
TKScreenConfigurationListener listener) {
return qt.setScreenConfigurationListener(listener);
}
public Object getPrimaryScreen() {
return qt.getPrimaryScreen();
}
public List<?> getScreens() {
return qt.getScreens();
}
public PerformanceTracker getPerformanceTracker() {
return qt.getPerformanceTracker();
}
public PerformanceTracker createPerformanceTracker() {
return qt.createPerformanceTracker();
}
public ImageLoader loadImage(String url, int width, int height,
boolean preserveRatio, boolean smooth) {
return qt.loadImage(url, width, height, preserveRatio, smooth);
}
public ImageLoader loadImage(InputStream stream, int width, int height,
boolean preserveRatio, boolean smooth) {
return qt.loadImage(stream, width, height, preserveRatio, smooth);
}
public AbstractRemoteResource loadImageAsync(
AsyncOperationListener l, String url, int width, int height,
boolean preserveRatio, boolean smooth) {
return (AbstractRemoteResource) qt.loadImageAsync(l, url, width, height,
preserveRatio, smooth);
}
public void defer(Runnable runnable) {
qt.defer(runnable);
}
public void exit() {
qt.exit();
}
public boolean isForwardTraversalKey(KeyEvent e) {
return qt.isForwardTraversalKey(e);
}
public boolean isBackwardTraversalKey(KeyEvent e) {
return qt.isBackwardTraversalKey(e);
}
public Map<Object, Object> getContextMap() {
return qt.getContextMap();
}
public int getRefreshRate() {
return qt.getRefreshRate();
}
public void setAnimationRunnable(DelayedRunnable animationRunnable) {
qt.setAnimationRunnable(animationRunnable);
}
public void requestNextPulse() {
qt.requestNextPulse();
}
public void waitFor(Task t) {
qt.waitFor(t);
}
public void accumulateStrokeBounds(Shape s, float[] b, StrokeType t, double w, StrokeLineCap c, StrokeLineJoin j, float m, BaseTransform tx) {
qt.accumulateStrokeBounds(s, b, t, w, c, j, m, tx);
}
public boolean strokeContains(Shape s, double x, double y, StrokeType t, double w, StrokeLineCap c, StrokeLineJoin j, float m) {
return qt.strokeContains(s, x, y, t, w, c, j, m);
}
public Shape createStrokedShape(Shape s, StrokeType p, double w, StrokeLineCap c, StrokeLineJoin j, float l, float[] d, float o) {
return qt.createStrokedShape(s, p, w, c, j, l, d, o);
}
public Dimension2D getBestCursorSize(int w, int h) {
return qt.getBestCursorSize(w, h);
}
public int getMaximumCursorColors() {
return qt.getMaximumCursorColors();
}
public int getKeyCodeForChar(String c) {
return qt.getKeyCodeForChar(c);
}
public PathElement[] convertShapeToFXPath(Object s) {
return qt.convertShapeToFXPath(s);
}
public HitInfo convertHitInfoToFX(Object hit) {
return qt.convertHitInfoToFX(hit);
}
public Filterable toFilterable(Image img) {
return qt.toFilterable(img);
}
public FilterContext getFilterContext(Object c) {
return qt.getFilterContext(c);
}
public AbstractMasterTimer getMasterTimer() {
return qt.getMasterTimer();
}
public FontLoader getFontLoader() {
return qt.getFontLoader();
}
public TextLayoutFactory getTextLayoutFactory() {
return qt.getTextLayoutFactory();
}
public Object createSVGPathObject(SVGPath s) {
return qt.createSVGPathObject(s);
}
public Path2D createSVGPath2D(SVGPath s) {
return qt.createSVGPath2D(s);
}
public boolean imageContains(Object image, float x, float y) {
return qt.imageContains(image, x, y);
}
public boolean isNestedLoopRunning() {
return qt.isNestedLoopRunning();
}
public boolean isSupported(ConditionalFeature f) {
return qt.isSupported(f);
}
public boolean isAntiAliasingSupported() {
return qt.isAntiAliasingSupported();
}
public TKClipboard getSystemClipboard() {
return qt.getSystemClipboard();
}
public TKSystemMenu getSystemMenu() {
return qt.getSystemMenu();
}
public TKClipboard getNamedClipboard(String name) {
return qt.getNamedClipboard(name);
}
public void startDrag(TKScene s, Set<TransferMode> tm, TKDragSourceListener l, Dragboard d) {
qt.startDrag(SceneImpl.get(s).qs, tm, l, d);
}
public void enableDrop(TKScene s, TKDropTargetListener l) {
qt.enableDrop(SceneImpl.get(s).qs, l);
}
public void registerDragGestureListener(TKScene s, Set<TransferMode> tm, TKDragGestureListener l) {
qt.registerDragGestureListener(SceneImpl.get(s).qs, tm, l);
}
public void installInputMethodRequests(TKScene s, InputMethodRequests requests) {
qt.installInputMethodRequests(SceneImpl.get(s).qs, requests);
}
public ImageLoader loadPlatformImage(Object platformImage) {
return qt.loadPlatformImage(platformImage);
}
public PlatformImage createPlatformImage(int w, int h) {
return qt.createPlatformImage(w, h);
}
public Object renderToImage(ImageRenderingContext p) {
return qt.renderToImage(p);
}
public long getMultiClickTime() {
return qt.getMultiClickTime();
}
public int getMultiClickMaxX() {
return qt.getMultiClickMaxX();
}
public int getMultiClickMaxY() {
return qt.getMultiClickMaxY();
}
protected Object createColorPaint(Color paint) {
throw new UnsupportedOperationException();
}
protected Object createLinearGradientPaint(LinearGradient paint) {
throw new UnsupportedOperationException();
}
protected Object createRadialGradientPaint(RadialGradient paint) {
throw new UnsupportedOperationException();
}
protected Object createImagePatternPaint(ImagePattern paint) {
throw new UnsupportedOperationException();
}
public boolean isFxUserThread() {
return qt.isFxUserThread();
}
public String toString() {
return qt.toString();
}
public void firePulse() {
qt.firePulse();
}
public void addStageTkPulseListener(TKPulseListener l) {
qt.addStageTkPulseListener(l);
}
public void removeStageTkPulseListener(TKPulseListener l) {
qt.removeStageTkPulseListener(l);
}
public void addSceneTkPulseListener(TKPulseListener l) {
qt.addSceneTkPulseListener(l);
}
public void removeSceneTkPulseListener(TKPulseListener l) {
qt.removeSceneTkPulseListener(l);
}
public void addPostSceneTkPulseListener(TKPulseListener l) {
qt.addPostSceneTkPulseListener(l);
}
public void removePostSceneTkPulseListener(TKPulseListener l) {
qt.removePostSceneTkPulseListener(l);
}
public void addTkListener(TKListener l) {
qt.addTkListener(l);
}
public void removeTkListener(TKListener l) {
qt.removeTkListener(l);
}
public void setLastTkPulseListener(TKPulseListener l) {
qt.setLastTkPulseListener(l);
}
public void addShutdownHook(Runnable hook) {
qt.addShutdownHook(hook);
}
public void removeShutdownHook(Runnable hook) {
qt.removeShutdownHook(hook);
}
public void notifyWindowListeners(List<TKStage> windows) {
qt.notifyWindowListeners(windows);
}
public void notifyLastNestedLoopExited() {
qt.notifyLastNestedLoopExited();
}
public InputStream getInputStream(String url, Class base) throws IOException {
return qt.getInputStream(url, base);
}
public boolean getDefaultImageSmooth() {
return qt.getDefaultImageSmooth();
}
public Object getPaint(Paint paint) {
return qt.getPaint(paint);
}
public TKClipboard createLocalClipboard() {
return qt.createLocalClipboard();
}
public void stopDrag(Dragboard dragboard) {
qt.stopDrag(dragboard);
}
public Color4f toColor4f(Color color) {
return qt.toColor4f(color);
}
public ShadowMode toShadowMode(BlurType blurType) {
return qt.toShadowMode(blurType);
}
public KeyCode getPlatformShortcutKey() {
return qt.getPlatformShortcutKey();
}
public void pauseScenes() {
qt.pauseScenes();
}
public void resumeScenes() {
qt.resumeScenes();
}
public void pauseCurrentThread() {
qt.pauseCurrentThread();
}
public Set<HighlightRegion> getHighlightedRegions() {
return qt.getHighlightedRegions();
}
static final class StageImpl implements TKStage {
final TKStage qs;
final Window peer;
final StageImpl owner;
final Modality modality;
boolean isBlocked() {
for (StageImpl w : owners)
if (w == this || w.isDescendantOf(this))
return true;
for (StageImpl w : stageImpls) {
if (w.peer.isShowing()) {
switch (w.modality) {
case APPLICATION_MODAL:
if (w != this && !this.isDescendantOf(w))
return true;
case WINDOW_MODAL:
if (w.isDescendantOf(this))
return true;
default:
}
}
}
return false;
}
StageImpl(TKStage quantumStage, Window peer, TKStage owner, Modality modality) {
if (quantumStage instanceof StageImpl || map.containsKey(quantumStage))
throw new IllegalArgumentException();
this.owner = owner == null ? null : get(owner);
this.modality = modality == null ? Modality.NONE : modality;
map.put(this.qs = Objects.requireNonNull(quantumStage), this);
if (peers.containsKey(peer))
peers.get(peer).dispose();
peers.put(this.peer = Objects.requireNonNull(peer), this);
stageImpls.add(this);
}
boolean isDescendantOf(StageImpl possibleAncestor) {
for (StageImpl stage = owner; stage != null; stage = stage.owner)
if (stage == possibleAncestor)
return true;
return false;
}
private static final HashMap<TKStage, StageImpl> map = new HashMap<>();
private static final HashMap<Window, StageImpl> peers = new HashMap<>();
static final StageImpl get(TKStage stage) {
if (Objects.requireNonNull(stage) instanceof StageImpl)
return (StageImpl) stage;
return Objects.requireNonNull(map.get(stage));
}
static final StageImpl get(Window peer) {
return peers.get(Objects.requireNonNull(peer));
}
public void dispose() {
map.remove(qs);
peers.remove(peer);
stageImpls.remove(this);
}
public void setTKStageListener(TKStageListener listener) {
qs.setTKStageListener(listener);
}
public TKScene createTKScene(boolean depthBuffer, boolean antiAliasing, AccessControlContext acc) {
return new SceneImpl(qs.createTKScene(depthBuffer, antiAliasing, acc));
}
public void setScene(TKScene scene) {
qs.setScene(scene == null ? null : SceneImpl.get(scene).qs);
}
public void setBounds(float x, float y, boolean xSet, boolean ySet, float w, float h, float cw, float ch, float xGravity, float yGravity) {
qs.setBounds(x, y, xSet, ySet, w, h, cw, ch, xGravity, yGravity);
}
public void setIcons(List icons) {
qs.setIcons(icons);
}
public void setTitle(String title) {
qs.setTitle(title);
}
public void setVisible(boolean visible) {
qs.setVisible(visible);
}
public void setOpacity(float opacity) {
qs.setOpacity(opacity);
}
public void setIconified(boolean iconified) {
qs.setIconified(iconified);
}
public void setMaximized(boolean maximized) {
qs.setMaximized(maximized);
}
public void setResizable(boolean resizable) {
qs.setResizable(resizable);
}
public void setImportant(boolean important) {
qs.setImportant(important);
}
public void setMinimumSize(int w, int h) {
qs.setMinimumSize(w, h);
}
public void setMaximumSize(int w, int h) {
qs.setMaximumSize(w, h);
}
public void setFullScreen(boolean f) {
qs.setFullScreen(f);
}
public void requestFocus() {
qs.requestFocus();
}
public void toBack() {
qs.toBack();
}
public void toFront() {
qs.toFront();
}
public void close() {
qs.close();
}
public void requestFocus(FocusCause cause) {
qs.requestFocus(cause);
}
public boolean grabFocus() {
return qs.grabFocus();
}
public void ungrabFocus() {
qs.ungrabFocus();
}
public void requestInput(String text, int type, double width,
double height, double Mxx, double Mxy, double Mxz, double Mxt,
double Myx, double Myy, double Myz, double Myt, double Mzx,
double Mzy, double Mzz, double Mzt) {
qs.requestInput(text, type, width, height, Mxx, Mxy, Mxz,
Mxt, Myx, Myy, Myz, Myt, Mzx, Mzy, Mzz, Mzt);
}
public void releaseInput() {
qs.releaseInput();
}
public void setRTL(boolean b) {
qs.setRTL(b);
}
public void setAccessibilityInitIsComplete(Object ac) {
qs.setAccessibilityInitIsComplete(ac);
}
public Object accessibleCreateStageProvider(AccessibleStageProvider ac) {
return qs.accessibleCreateStageProvider(ac);
}
public Object accessibleCreateBasicProvider(AccessibleProvider ac) {
return qs.accessibleCreateBasicProvider(ac);
}
public void accessibleDestroyBasicProvider(Object a) {
qs.accessibleDestroyBasicProvider(a);
}
public void accessibleFireEvent(Object a, int eventID) {
qs.accessibleFireEvent(a, eventID);
}
public void accessibleFirePropertyChange(Object a, int p, int o, int n) {
qs.accessibleFirePropertyChange(a, p, o, n);
}
public void accessibleFirePropertyChange(Object a, int p, boolean o, boolean n) {
qs.accessibleFirePropertyChange(a, p, o, n);
}
}
static final class SceneImpl implements TKScene {
public final TKScene qs;
public SceneImpl(TKScene quantumScene) {
if (quantumScene instanceof SceneImpl || map.containsKey(quantumScene))
throw new IllegalArgumentException();
map.put(this.qs = Objects.requireNonNull(quantumScene), this);
Method getPlatformView = getMethod(quantumScene.getClass(), "getPlatformView");
View view = (View)invoke(getPlatformView, quantumScene);
view.setEventHandler(new VEHImpl(view.getEventHandler()));
}
private static final HashMap<TKScene, SceneImpl> map = new HashMap<>();
public static final SceneImpl get(TKScene scene) {
if (Objects.requireNonNull(scene) instanceof SceneImpl)
return (SceneImpl) scene;
return Objects.requireNonNull(map.get(scene));
}
public void dispose() {
map.remove(qs);
qs.dispose();
}
public void waitForRenderingToComplete() {
qs.waitForRenderingToComplete();
}
public void waitForSynchronization() {
qs.waitForSynchronization();
}
public void releaseSynchronization(boolean u) {
qs.releaseSynchronization(u);
}
public void setTKSceneListener(TKSceneListener l) {
qs.setTKSceneListener(l);
}
public void setTKScenePaintListener(TKScenePaintListener l) {
qs.setTKScenePaintListener(l);
}
public void setRoot(NGNode root) {
qs.setRoot(root);
}
public void markDirty() {
qs.markDirty();
}
public void setCamera(NGCamera camera) {
qs.setCamera(camera);
}
public NGLightBase[] getLights() {
return qs.getLights();
}
public void setLights(NGLightBase[] lights) {
qs.setLights(lights);
}
public void setFillPaint(Object f) {
qs.setFillPaint(f);
}
public void setCursor(Object cursor) {
qs.setCursor(cursor);
}
public void enableInputMethodEvents(boolean enable) {
qs.enableInputMethodEvents(enable);
}
public void finishInputMethodComposition() {
qs.finishInputMethodComposition();
}
public void entireSceneNeedsRepaint() {
qs.entireSceneNeedsRepaint();
}
public TKClipboard createDragboard(boolean d) {
return qs.createDragboard(d);
}
}
static final class VEHImpl extends EventHandler {
private final EventHandler qh;
public VEHImpl(EventHandler quantumHandler) {
this.qh = quantumHandler;
}
public void handleViewEvent(View view, long time, int type) {
unwrap();
qh.handleViewEvent(view, time, type);
rewrap();
}
public void handleKeyEvent(View view, long time, int action, int keyCode,char[] keyChars, int m) {
qh.handleKeyEvent(view, time, action, keyCode, keyChars, m);
}
public void handleMenuEvent(View view, int x, int y, int xAbs, int yAbs,boolean k) {
qh.handleMenuEvent(view, x, y, xAbs, yAbs,k);
}
public void handleMouseEvent(View view, long time, int type, int button,int x, int y, int xAbs, int yAbs, int m,boolean p, boolean s) {
qh.handleMouseEvent(view, time, type, button, x, y, xAbs,yAbs, m, p, s);
}
public void handleScrollEvent(View view, long time, int x, int y, int xAbs,int yAbs, double deltaX, double deltaY, int m, int lines,int chars, int l, int c, double xm,double ym) {
qh.handleScrollEvent(view, time, x, y, xAbs, yAbs, deltaX, deltaY, m, lines, chars, l, c,xm, ym);
}
public void handleInputMethodEvent(long time, String text, int[] c, int[] a, byte[] v, int cc, int p) {
qh.handleInputMethodEvent(time, text, c, a, v, cc, p);
}
public double[] getInputMethodCandidatePos(int offset) {
return qh.getInputMethodCandidatePos(offset);
}
public void handleDragStart(View view, int button, int x, int y, int xAbs, int yAbs, ClipboardAssistance d) {
qh.handleDragStart(view, button, x, y, xAbs, yAbs, d);
}
public void handleDragEnd(View view, int p) {
qh.handleDragEnd(view, p);
}
public int handleDragEnter(View view, int x, int y, int xAbs, int yAbs, int r, ClipboardAssistance d) {
return qh.handleDragEnter(view, x, y, xAbs, yAbs, r, d);
}
public int handleDragOver(View view, int x, int y, int xAbs, int yAbs, int r, ClipboardAssistance d) {
return qh.handleDragOver(view, x, y, xAbs, yAbs, r, d);
}
public void handleDragLeave(View view, ClipboardAssistance d) {
qh.handleDragLeave(view, d);
}
public int handleDragDrop(View view, int x, int y, int xAbs, int yAbs, int r, ClipboardAssistance d) {
return qh.handleDragDrop(view, x, y, xAbs, yAbs, r, d);
}
public void handleBeginTouchEvent(View view, long time, int m, boolean isDirect, int tc) {
qh.handleBeginTouchEvent(view, time, m, isDirect, tc);
}
public void handleNextTouchEvent(View view, long time, int type, long touchId, int x, int y, int xAbs, int yAbs) {
qh.handleNextTouchEvent(view, time, type, touchId, x, y, xAbs, yAbs);
}
public void handleEndTouchEvent(View view, long time) {
qh.handleEndTouchEvent(view, time);
}
public void handleScrollGestureEvent(View v, long t, int type, int m, boolean d, boolean i, int c, int x, int y, int xAbs, int yAbs, double dx, double dy, double tdx, double tdy, double mx, double my) {
qh.handleScrollGestureEvent(v, t, type, m, d, i, c, x, y, xAbs, yAbs, dx, dy, tdx, tdy, mx, my);
}
public void handleZoomGestureEvent(View v, long t, int type, int m, boolean d, boolean i, int x, int y, int xAbs, int yAbs, double scale, double e, double s, double te) {
qh.handleZoomGestureEvent(v, t, type, m, d, i, x, y, xAbs, yAbs, scale, e, s, te);
}
public void handleRotateGestureEvent(View v, long t, int type, int m, boolean d, boolean i, int x, int y, int xAbs, int yAbs, double dangle, double a) {
qh.handleRotateGestureEvent(v, t, type, m, d, i, x, y, xAbs, yAbs, dangle, a);
}
public void handleSwipeGestureEvent(View v, long t, int type, int m, boolean d, boolean i, int c, int dir, int x, int y, int xAbs, int yAbs) {
qh.handleSwipeGestureEvent(v, t, type, m, d, i, c, dir, x, y, xAbs, yAbs);
}
}
}