I am working through the examples in 'The Eclipse Graphical Framework (GEF)' book and the included Genealogy example(Draw2d chapters) seems to have the z order of figures messed up. When a figure is dragged or selected its z order remains unchanged which causes strange/unnatural behavior where the dragged figure can be dragged under other figures.
I would like to be able to change figures' z order when the figures are selected so they are moved to the top of the children list and appear at the top of the z dimension of the chart. What is the best way to do that?
The z-order of the figures in draw2d is defined either by order of addition (last figure on top) or can be set in Figure.add.
I guess the easiest (but probably not very efficient) way of doing what you want is removing the figure from the parent and adding it again. This will make it the last figure added, therefore also the top figure
I have found that removing the figure and adding back will screw up the event system such that if your intent, for example, is, when a figure is dragged to another location, you want to bring that figure to the front, the dragging is interrupted and you will no longer get any events for that figure. To bring a figure to the top, use the following code:
final IFigure child = <figure you want to bring to the front>;
final IFigure parent = child.getParent();
final List children = child.getParent().getChildren();
children.remove( child );
children.add( child );
child.repaint();
This is manipulate the raw list of children, moving the particular child to the fron of the z-order. Then, a repaint of the child is issued to show this change. This solution is specific to Draw2d, and has nothing to do with GEF.
Related
NOTE: This is not homework. My Swing application was homework, but it's already completed. I'm doing this for my own knowledge to get a better understanding of JavaFX and Scenebuilder.
I created a Swing application that contained a 27x27 grid. Upon clicking "Normal Setup", only the center square is visible.
I am attemtping to translate everything into JavaFx, and I am using Scenebuilder. I'm still learning how to use this, and I'm unsure if I have my GridPane placed correctly (Notice how creating a 27 x 27 grid makes it go beyond the bounds of the parent). I can work on that later.
What I would like to know is if you can set all of the attributes for each node across the board. I had to go into my FXML file and manually change each node size in the 27x27 grid. This will get exhausting eventually. Surely there is a way to do this?
As you can see each node will have a Label template, and it will only be visible when a certain ant accesses it.
In my Swing version, an example of setting everything for all nodes looks like so:
setPreferredSize(new Dimension(ColonyView.NODE_SIZE, ColonyView.NODE_SIZE));
where the "NODE_SIZE" is:
public final static int NODE_SIZE = 96
Any help would be appreciated.
Select a node in your GridPane and press STRG + A
You can use CSS to set the yellow background. See https://docs.oracle.com/javafx/2/api/javafx/scene/doc-files/cssref.html for details.
I have a graphical editor written with GEF. In this editor it's possible to drag and drop elements around and create connection by dragging and dropping on specific anchor points.
Everything works fine, except that the diagram does not automatically scroll when the user drags stuff around.
I would expect the diagram to scroll automatically when the user reaches the side of it while dragging something.
Is such a feature supported by GEF? Which class/setter should be called to enable it?
If it's not directly supported, how to proceed to achieve it?
It's been a while since I last fiddled with GEF.
Does drag and drop not work at all or just in the direction of negative coordinates?
What Layout are you using?
IIRC, there were different layouts with one of them (FreeForm?) supporting negative coordinates, so if you just have trouble with negative coords, you could try to change the Layout.
Here is an example of a Scrolling Graphical editor (the author says ;)) which might give you a good hint.
And there is a class named org.eclipse.gef.ui.parts.ScrollingGraphicalViewer that might help, too.
Only hints, though, since I don't know your code.
First step is to make your canvas scrollable. This is explained in this book, pages 96 - 101.
Assuming you are already drawing your figures on a FigureCanvas and you're using FreeformFigures and FreeformLayer, you can do the following:
Add a MouseMoveListener on your Figure in its EditPart. Each time a drag is detected, in the mouseDragEvent method, reveal your figure with getViewer().reveal(EditPart.this).
This will cause your Figure to always be constantly revealed when it's being dragged.
I'm working on Java, SmartGWT 2.5 & Mozilla FF 3.6.x. I'm using Tree, TreeGrid & TreeNode in my application. I need to drag a node and while dragging I have to see the other nodes on which mouse will pass with changed background color. I tried with dragStart, dragStop, onCellOver, onCellOut and dragMove, but maybe I don't make a good combination of them. So, how can be these events combinated to get what I need?
Add a DropOverHandler on the target widget (a TreeGrid in this case).
You'll then need to use one of the many available styling APIs (probably getCellCSSText()) so that it returns different results while the mouse remains over the target grid, and call markForRedraw() on the grid from DropOver so that your new styling is applied.
Overriding willAcceptDrop() is how you tell the system whether dropping on a particular row is allowed (affects the mouse cursor).
Detect the mouse exiting the grid via the DropOut event, and call markForRedraw() again there.
I have a screen in my LibGDX game that will be essentially two columns, the first being 75% of the real estate and containing labels/buttons, and the next being 25% that will contain text and images. It is pretty complicated to include all of the code directly in the screen itself for this.
What I would like to do is to have one object contain the logic for the left side of the screen, and one for the right. This would be similar to ASP.NET, where I have a page, with one user control for the left content, and one for the right.
How can this be setup in a LibGDX screen?
I recommend you use scene2D and create new class for each element.
For example, you can create one class that extends Group for each side. Then you can add a ClickListener to group or to each Actor of the group with your logic.
Actually there are alot of ways you could do this. You can handle the events yourself by checking the if something is touched and if so, you do handle it yourself by the position.
On the other side you can use the scene2D system by creating Actors inside of a Stage and set the inputprocessor to the stage. In that case every event is given to the actors and if its inside of his bounds he does handle it depending on the implemented way (Take a look at this: ActionListenes).
So in your case you could create 2 Actors which are invisible
and everyone of it has its side.
You could also use the Button
from libgdx and use this without a background/foreground or such. Simply set the right sizes and make it invisible by the alpha or no background.
or you do check in every cycle of the gameloop if something is touched and if so you do handle the event as you whish. Take a look at this: input polling and creating an input processor
Here's my problem. I want the pop up dialog to be triggered when a use clicks on the icon and icon only of a jtree tree node. I did some research and did not find any existing way to add mouse listeners on the icon (if there is please let me know!). Therefore, I decided to hack my way into it and use the Point object which I can get form mouseevent.getPoint() to figure out whether the mouse is on the icon. However, when I call Jtree.getCellRenct(row, col, includespacing) the location I get seem to be relative to the indentation of children node.
For example,
Parent
-Child1
-Child2
I get the same x coordinate by calling getCellRect() on all three nodes although what I really want is the x plus the indentation caused by "-" because mouseevent.getpoint() is not relative to the indentation.
Any idea how I can do this?
Edit:
I figured out a way. I call tree.getUI to get a BasicTreeUI object and call BasicTreeUI.getLeftChildIndent() and BasicTreeUI.getRightChildIndent(). Summing up these two integers will be the total indentation per level of the tree (or it seems to be so far). So I calculate the indentation by
(path.getPathCount() - 1) * (leftindent + rightindent).
It works for me so far although I am not entirely sure if this is good. For example I don't really know what left and right indent mean. Also in the source of BasicTreeUI it actually has a protected method
protected int getRowX(int row, int depth)
{
return totalChildIndent * (depth + depthOffset);
}
This method seems to get called by another protected method used to check if a location is within the area of tree expansion or collapse icon. I couldn't figure out much about what depthOffset is for. I guess it has something to do with whether root gets displayed or things of similar nature.
But still I am not feeling very comfortable doing it this way.. could somebody either tell me I'm good or that there is a better way to do this? :-)