From 1f0abb015ca85ecef5ef86a3dc395151437f1b28 Mon Sep 17 00:00:00 2001 From: Sebastien Bordes Date: Fri, 17 Oct 2014 20:44:11 +0200 Subject: [PATCH] Fix #126 Allow to get a ne w fresh instance of FXMLComponent --- .../af/core/resource/fxml/FXMLItem.java | 11 +++ .../af/core/resource/fxml/EnumFxmls.java | 37 ++++++++++ .../af/core/resource/fxml/FxmlTest.java | 68 +++++++++++++++++++ .../af/core/resource/fxml/TestFxmls.java | 39 +++++++++++ .../core/src/test/resources/fxml/first.fxml | 39 +++++++++++ .../src/test/resources/fxml/first.properties | 0 .../core/src/test/resources/fxml/second.fxml | 18 +++++ .../src/test/resources/fxml/second.properties | 0 .../fxml/ui/embedded/EmbeddedView.java | 18 ++++- 9 files changed, 229 insertions(+), 1 deletion(-) create mode 100644 org.jrebirth.af/core/src/test/java/org/jrebirth/af/core/resource/fxml/EnumFxmls.java create mode 100644 org.jrebirth.af/core/src/test/java/org/jrebirth/af/core/resource/fxml/FxmlTest.java create mode 100644 org.jrebirth.af/core/src/test/java/org/jrebirth/af/core/resource/fxml/TestFxmls.java create mode 100644 org.jrebirth.af/core/src/test/resources/fxml/first.fxml create mode 100644 org.jrebirth.af/core/src/test/resources/fxml/first.properties create mode 100644 org.jrebirth.af/core/src/test/resources/fxml/second.fxml create mode 100644 org.jrebirth.af/core/src/test/resources/fxml/second.properties diff --git a/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/resource/fxml/FXMLItem.java b/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/resource/fxml/FXMLItem.java index 0b9f5917b..526c45da3 100644 --- a/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/resource/fxml/FXMLItem.java +++ b/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/resource/fxml/FXMLItem.java @@ -53,4 +53,15 @@ default FXMLBuilder builder() { return ResourceBuilders.FXML_BUILDER; } + /** + * Build a new FXMLComponent without storing it. + * + * If you call 'n' times this method you will obtain 'n' {@link FXMLComponent} instances. + * + * @return a new {@link FXMLComponent} instance + */ + default FXMLComponent getNew(){ + return builder().buildResource(this, builder().getParam(this)); + } + } diff --git a/org.jrebirth.af/core/src/test/java/org/jrebirth/af/core/resource/fxml/EnumFxmls.java b/org.jrebirth.af/core/src/test/java/org/jrebirth/af/core/resource/fxml/EnumFxmls.java new file mode 100644 index 000000000..1236cc612 --- /dev/null +++ b/org.jrebirth.af/core/src/test/java/org/jrebirth/af/core/resource/fxml/EnumFxmls.java @@ -0,0 +1,37 @@ +/** + * Get more info at : www.jrebirth.org . + * Copyright JRebirth.org © 2011-2013 + * Contact : sebastien.bordes@jrebirth.org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jrebirth.af.core.resource.fxml; + + +/** + * The class EnumColors. + * + * @author Sébastien Bordes + * + */ +public enum EnumFxmls implements FXMLEnum { + + // @formatter:off + + /** . */ + FIRST_FXML {{ fxml("fxml", "first"); }}, + + /** Color for inner shadow, white. */ + SECOND_FXML{{ fxml("fxml", "second"); }}; + +} diff --git a/org.jrebirth.af/core/src/test/java/org/jrebirth/af/core/resource/fxml/FxmlTest.java b/org.jrebirth.af/core/src/test/java/org/jrebirth/af/core/resource/fxml/FxmlTest.java new file mode 100644 index 000000000..b17b38c44 --- /dev/null +++ b/org.jrebirth.af/core/src/test/java/org/jrebirth/af/core/resource/fxml/FxmlTest.java @@ -0,0 +1,68 @@ +package org.jrebirth.af.core.resource.fxml; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +import org.jrebirth.af.core.ui.fxml.FXMLComponent; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +/** + * The class ColorTest. + * + * @author Sébastien Bordes + */ +@Ignore("Must launch the Toolkit before") +public class FxmlTest { + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + + } + + @Before + public void setUp() throws Exception { + + } + + @Test + public void fxmlClone() { + + checkFXML(EnumFxmls.FIRST_FXML); + checkFXML(EnumFxmls.SECOND_FXML); + + checkFXML(TestFxmls.FIRST_FXML); + checkFXML(TestFxmls.SECOND_FXML); + + } + + private void checkFXML(final FXMLItem fxmlItem) { + + FXMLComponent fx1 = fxmlItem.get(); + FXMLComponent fx2 = fxmlItem.get(); + + FXMLComponent fx3 = fxmlItem.getNew(); + FXMLComponent fx4 = fxmlItem.getNew(); + + assertEquals(fx1, fx2); + assertNotEquals(fx1, fx3); + assertNotEquals(fx1, fx4); + assertNotEquals(fx3, fx4); + + + } + + + @After + public void tearDown() throws Exception { + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + } + +} diff --git a/org.jrebirth.af/core/src/test/java/org/jrebirth/af/core/resource/fxml/TestFxmls.java b/org.jrebirth.af/core/src/test/java/org/jrebirth/af/core/resource/fxml/TestFxmls.java new file mode 100644 index 000000000..4c3fe4e43 --- /dev/null +++ b/org.jrebirth.af/core/src/test/java/org/jrebirth/af/core/resource/fxml/TestFxmls.java @@ -0,0 +1,39 @@ +/** + * Get more info at : www.jrebirth.org . + * Copyright JRebirth.org © 2011-2013 + * Contact : sebastien.bordes@jrebirth.org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jrebirth.af.core.resource.fxml; + +import static org.jrebirth.af.core.resource.Resources.create; + +/** + * The class TestColors. + * + * @author Sébastien Bordes + */ +public interface TestFxmls { + + /**************************************************************************************/ + /** ___________________________________FXML Files.___________________________________ */ + /**************************************************************************************/ + + /** The first fxml file. */ + FXMLItem FIRST_FXML = create(new FXML("fxml", "first")); + + /** The second fxml file. */ + FXMLItem SECOND_FXML = create(new FXML("fxml", "second")); + +} diff --git a/org.jrebirth.af/core/src/test/resources/fxml/first.fxml b/org.jrebirth.af/core/src/test/resources/fxml/first.fxml new file mode 100644 index 000000000..4c8d65e9c --- /dev/null +++ b/org.jrebirth.af/core/src/test/resources/fxml/first.fxml @@ -0,0 +1,39 @@ + + + + + + + + + + +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
diff --git a/org.jrebirth.af/core/src/test/resources/fxml/first.properties b/org.jrebirth.af/core/src/test/resources/fxml/first.properties new file mode 100644 index 000000000..e69de29bb diff --git a/org.jrebirth.af/core/src/test/resources/fxml/second.fxml b/org.jrebirth.af/core/src/test/resources/fxml/second.fxml new file mode 100644 index 000000000..b586b1249 --- /dev/null +++ b/org.jrebirth.af/core/src/test/resources/fxml/second.fxml @@ -0,0 +1,18 @@ + + + + + + + + + +