JavaFX, adding images in StackPane - javafx

I stuck at this stage, how add that 3 towers in to the StackPane and how to move the bricks inside that pane (from 1-2-3 for example) using only JavaFX code without Scene Builder? I would be grateful for any answers!
Image:

My suggestion:
You create a class "Tower" which extends the class Pane and contains a list of disks. The class has a method "accept" which returns boolean depending on whether you can put a disk there or not.
Create 3 instances of the class Tower.
Then you create a class "Disk" which extends the class Rectangle. Create 8 instances with varying width and add them to the first tower, ie the list of the class Tower.
Each Disk will use a mouselistener as described in Drag nodes like in a patience/Klondike card game. The mechanism is very similar to what you need.
In the mousepressed handler of the mouse listener you check whether the disk is on top of the tower or not and hence whether you can drag it or not.
In the mousereleased handler of the mouse listener you simply check whether a disk intersects (see boundsInParent and intersects) with a given tower. If it does and the accept method returns true, you drop it there. If the accept method returns false, you let it fly back to where it came from.
You're finished when a Tower has all of the disks.
That's basically it.
Oh, and don't use a StackPane, use a Pane instead. And you don't need images. The picture you show can be created solely of rectangles.

Related

How to create a dialog using JFXDialog of JFoenix in JavaFX

i search for an example for jfoenix jfxdialog anybody has working demo of this
JFXDialog dialog = new JFXDialog();
JFXDialog has three different constructors:
JFXDialog(),
JFXDialog(StackPane dialogContainer, Region content, DialogTransition transitionType) and
JFXDialog(StackPane dialogContainer, Region content, DialogTransition transitionType, boolean overlayClose)
The first one just sets the animationType to Center.
The second one sets the Parent(dialogContainer), the content(content) and the animationType(transitionType).
The third one sets the same as the second one + if the dialog should close if you click on the overlay(overlayClose).
For the parent of the Dialog you need a StackPane.
For the content you can use anything which is a child, grandchild, ... of Region. I would suggest you to use a JFXDialogLayout as it extends StackPane and makes it easier to style you dialog.
For the transitionType you have five different ones:
DialogTransition.TOP
DialogTransition.RIGHT
DialogTransition.BOTTOM
DialogTransition.LEFT
DialogTransition.CENTER
If you want to close it by clicking on the overlay set overlayClose to true, else set it to false
Some usefull methods which JFXDialog has:
setDialogContainer(StackPane dialogContainer) sets the Parent.
setContent(Region content) sets the Content of your Dialog.
setOverlayClose(final boolean overlayClose) you set wheter you want to close the Dialog by clicking on the overlay or not.
show(StackPane dialogContainer) shows the JFXDialog in the given StackPane
show() shows the JFXDialog in its parent
close() closes the JFXDialog
setTransitionType(DialogTransition transition) sets the DialogTransition to one of those mentioned before
setOnDialogClosed(EventHandler<? super JFXDialogEvent> handler) Defines a function to be called when the dialog is closed. It will be triggered after the close animation is finished.
setOnDialogOpened(EventHandler<? super JFXDialogEvent> handler) Defines a function to be called when the dialog is opened. It will be triggered after the show animation is finished.
JFXDialogLayout has just an empty constructor but contains out of a heading, body and actions.
The JFXDialogLayout class provides a setter for all those parts. Those are:
setHeading(Node... titleContent
setBody(Node... body)
setActions(Node... actions)
If you don't know, because of the three dots after Node you can add unlimited Nodes to all three parts. This is a feature called Varargs
For further information take a look at the demo on github at the Java controller JFoenix/Dialog Container and at the FXML file JFoenix/JFXDialog.fxml
Also here is the source code of the controls containing JFXDialog and JFXDialogLayout JFoenix/controls
I would suggest you to write your JavaFX applications seperated in Java, FXML and CSS files. Why Use FXML

Make ControlFx NotificationPane accept Node

ControlsFX has an awesome control called NotificationPane, which can easily be use like so
NotificationPane np = new NotificationPane();
np.setText("What to be displayed here");
What I am wondering, is it possible to extends it in such a way that, instead of it displaying text to display a Node.
You don't need to extends it. Just use the constructor that accepts a node.
http://controlsfx.bitbucket.org/org/controlsfx/control/NotificationPane.html#NotificationPane-javafx.scene.Node-
The Node that NotificationPane accepts in the constructor is actually the content pane OVER which the notification appears, not the content of the notification itself.
There is however a way to achieve what you asked. From the JavaDocs:
The graphic property represents the Node to show within the popup
notification bar that appears on top of the content that is within the
NotificationPane. Despite the term 'graphic', this can be an
arbitrarily complex scenegraph in its own right.
This means that you can indeed put complex Nodes (even whole trees) inside the notification. As long as the Text/Action properties are null, it will occupy all available space (or up to the preferred/max sizes of the node itself), leaving space for the closing button.

Unity canvas overlap using networking

I am using the new unity networking using unity 5.3.1 , my player prefab is a UI canvas , so when another client joins the canvas's overlap and I cannot press any button on host or client .
What i want is to disable other canvase's on each players game and just leave the local players canvase active , I have tried islocalplayer , isclient ,isserver but nothing works .
Is there a way around this please do tell.
Here are some options I can think of:
1) Instead of making canvas a player object, make panel a player object, so that all your players are different panels under same canvas. Now, when object are under same canvas, they ray casting order is determined by the order in hierarchy.
The objects that are lower in the hierarchy occlude those that are higher. So, what you can do is moving your player object to the lowest position in objects hierarchy, so that it will occlude all other players. This can be done using Transform methods SetSiblingIndex and GetSiblingIndex, like
transform.SetSiblingIndex(100000/*some big number*/);
2) Disable raycasting on all other players - what if you can click some component on canvas or not is whether it is a raycast target. Images and Text components can be raycast targets, or more generally any component that inherits from Graphics. You can iterate over all components of type Graphics in all players except the local player and mark raycastTarget = false.
I figured it out and as #NikaKasradze said use only one canvas and put all gui listeners in the islocalplayer bool check .

JavaFX nodes - How to make them resizable by the end user?

I am developing a JavaFX application where a class I have developed (extended from javafx.scene.Parent) is created on-the-fly based on what entry the user has clicked in a ListView control.
Just to be clear about this node, it is not created using a layout tool like SceneBuilder, it is created at runtime based on the user's actions.
The constructor for my custom node class creates a VBox and a Label and uses passed coordinates (X,Y) in the constructor method to set its own Layout coords. I then use a custom utility class to make the node draggable. This new node is then added to the main application Pane.
However, I have failed to find out how I can make these nodes resizable by the user. That is, allow the user to mouse over the corner of the node, hold and drag to resize. An operation that all users are used to, no matter what the OS.
Has anyone done anything like this in JavaFX? (My searches on the subject only seem to pull up subjects on the automatic resizing that a parent node does with its child nodes.)
Many thanks,
Ian.
As you can see on the documentation of VBox you can only define minimum, prefered and maximum range, there's not really a way to make it manually resizable.
The only proper solution to solve your problem is to develop your own class to do it, because what you want seems very specific, with your problem description, I don't think use some layouts or panels will do what you exactly want.
I found something that you can use : Dragging to resize a JavaFX Region
This allows you to resize a region, all you have to do after is to put you VBox in this region, but notice in this article that :
Only height resizing is currently implemented.
This code won't work in JavaFX8, you'll have to check the comment to see how it worls in JavaFX8
Hope this helps.

Make a custom component or extend the List component for a 2D top down view MAP in flex 4?

Hy!
I'm building a top view 2D map, that it's objects are stored on the server.
The kind of objects are 10 and might be a photo, label, button, lists, mix of them or labels with tooltips.
The component must request the "areas" that are missing on screen.
An area is 1000x1000 px and is cached in flex.
To move in the map, will be like in google maps (drag-and-drop)
I should be able to have another list and move objects from one to another using drag-an-drop on objects. Ex.: I grab an objects from a list and I move it on this map, I release the mouse button and the item is placed there.
Now the problem is: I build a custom component for this trying to emulate the item renderer for performance and recyclage, implement drag-and-drop on objects and request the areas that are missing?
or
I extend the List component from spark and I add some features as multiple kind of itemrenderers and use recycle on them. Of course it must be able to request the missing areas on the screen and cache it's data.
Maybe create a custom layout is needed too.
What I need is something that must be really fluid, so the lighter this component is, the better!
Thanks for your help! (:
UPDATE:
*There will be not any object over another.
*I will not use hitTest on bitmaps because all bitmaps are wrapped in another component,as they,for now are itemrenderers.
Anyway I already begin to do this using a class that extends the SkinnableDataContainer and a custom layout. As the layout is not like a grid, is sparse, random items at diferent points(x, y).
Now I have this problem: https://stackoverflow.com/questions/4192934/how-to-get-the-localx-and-localy-relative-to-item-renderer-and-not-to-the-spark
Maybe you could use a combination of some of the following:
A canvas background (for layered components), looks fluid if using hitTest. Split up the canvas using constraintColumn/constraintRow for a grid layout.
Use hitTest (on items bitmapdata) for collision detection, and move the items to a new position (if items are dropped on top of one another).
Use a combo of mouseDown, mouseMove, mouseUP (example here) for drag n drop.
Use a 2D/3D indexed array to track the position of items (example here)

Resources