Skip to content

Commit

Permalink
Fix #126 Allow to get a ne w fresh instance of FXMLComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
sbordes committed Oct 17, 2014
1 parent 65047b3 commit 1f0abb0
Show file tree
Hide file tree
Showing 9 changed files with 229 additions and 1 deletion.
Expand Up @@ -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));
}

}
@@ -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 <strong>EnumColors</strong>.
*
* @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"); }};

}
@@ -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 <strong>ColorTest</strong>.
*
* @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 {
}

}
@@ -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 <strong>TestColors</strong>.
*
* @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"));

}
39 changes: 39 additions & 0 deletions org.jrebirth.af/core/src/test/resources/fxml/first.fxml
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.chart.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>


<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<center>
<ScrollPane prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<content>
<PieChart />
</content>
</ScrollPane>
</center>
<right>
<Accordion BorderPane.alignment="CENTER">
<panes>
<TitledPane animated="false" text="untitled 1">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
</content>
</TitledPane>
<TitledPane animated="false" text="untitled 2">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
</content>
</TitledPane>
<TitledPane animated="false" text="untitled 3">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
</content>
</TitledPane>
</panes>
</Accordion>
</right>
</BorderPane>
Empty file.
18 changes: 18 additions & 0 deletions org.jrebirth.af/core/src/test/resources/fxml/second.fxml
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>


<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="175.0" prefWidth="53.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Button mnemonicParsing="false" text="Button" />
<Button mnemonicParsing="false" text="Button" />
<Button mnemonicParsing="false" text="Button" />
<Button mnemonicParsing="false" text="Button" />
<Button mnemonicParsing="false" text="Button" />
<Button mnemonicParsing="false" text="Button" />
<Button mnemonicParsing="false" text="Button" />
</children>
</VBox>
Empty file.
@@ -1,9 +1,11 @@
package org.jrebirth.af.showcase.fxml.ui.embedded;

import javafx.scene.Node;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;

import org.jrebirth.af.core.resource.Resources;
import org.jrebirth.af.core.resource.fxml.FXML;
Expand All @@ -16,6 +18,8 @@ public class EmbeddedView extends DefaultView<EmbeddedModel, AnchorPane, Embedde

private BorderPane borderPane;

private VBox box;

public EmbeddedView(final EmbeddedModel model) {
super(model);
}
Expand All @@ -35,16 +39,28 @@ protected void initView() {
getRootNode().setPrefHeight(400);
getRootNode().setPrefWidth(600);

box = new VBox();

ScrollPane scrollPane = new ScrollPane();
scrollPane.setPrefSize(600, 600);
scrollPane.setContent(box);

this.borderPane = new BorderPane();
this.borderPane.setCenter(scrollPane);

getRootNode().getChildren().add(this.borderPane);

addNode(EmbeddedView.ROOT_EMBEDDED_FXML.get().getNode());

// Load 2 more instance
addNode(EmbeddedView.ROOT_EMBEDDED_FXML.getNew().getNode());
addNode(EmbeddedView.ROOT_EMBEDDED_FXML.getNew().getNode());

}

public void addNode(final Node node) {

this.borderPane.setCenter(node);
this.box.getChildren().add(node);

}

Expand Down

0 comments on commit 1f0abb0

Please sign in to comment.