Disable repainting after modifying graph in Jung - java

I've a graph in Jung shown using a JFrame.
After I remove a vertex from the graph,
the shown graph automatically redrawn and presented without the removed vertex.
How can I disable it, so that only when I call the repaint method
the graph would be redrawn ?
Thank you

The simple way to do this is extend your graph by some class and add toRemove() method, where you can signify your vertex to delete in boolean array. And the second method deleteNow() which will use your boolean array and delete your vertexes - it will be alike repaint() now. The second way is add boolean value to your vertex instead of array in your extended class. I can't find any other way. Sorry if it's not helpful.

You haven't really given enough information to be able to advise you precisely, but here are some general observations.
The answer to your question is going to depend in part on how you're removing the vertex: interactively or programmatically.
If it's programmatically, then you'll need to look at the code that calls VisualizationViewer.repaint(). It's been a while since I've looked at that part of the code, but the gist is that something is listening to changes to the graph model and triggering repaints (because this is what users generally want).
If it's interactively, then it's probably on the same thread as your visualization, and you should have a fair amount of control over when repaint() gets called (see the calls in the sample code to VV.repaint()).

Related

Apache Batik: How to force JSVGComponent view to update when SVG Dom modified

Using Apache Batik,
Trying to get the JSVGComponent to update (repaint) after adding a new svg element to the DOM. I know about ALWAYS_DYNAMIC, and that is set. The new element(s) are successfully added to the document, but the only way I can get the component to repaint is to resize the view. Upon resize, the new elements pop (appear) into place. I have also tried to add the elements via a Runnable using the UpdateManager and the RunnableQueue. Again, the elements are successfully added, but don't appear until the component is resized (by resizing the housing frame). I have also tried invoking the repaint via a RunQ Runnable, but that also does not work (tho the repaint is actually called).
I think I may have to actually go into the GVT bridge, but I'd sure rather not.
Help extraordinarily appreciated. Thx.
Almost same problem for me : I had to dynamically modifiy the background of boxes (polygon node).
According to MelodyBibi, it works with setSVGDocument(doc); but the SVG flashes during refresh. It's not very appreciable.
My (better) solution is to call
svgCanvas.getCanvasGraphicsNode().fireGraphicsNodeChangeCompleted();
after modifying the DOM model using polygonElement.setAttribute("fill", "red"); on the appropriate Node.
I also added JSVGCanvas.ALWAYS_DYNAMIC before the first loading of the document.
Now my SVG refreshes in realtime, without blinking.
Hoping this will help you.
You can do
svgCanvas.setDocument(doc);
It's works for an JSVGCanvas, may be it will works for you.
You can also try method :
setSVGDocument(doc);
I found this :
There are two common causes for this. The first is that the JSVGCanvas doesn’t know it’s a dynamic document. Normally Batik detects this by looking for script elements but when you modify the document from Java it can’t tell. So call myJSVGCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC); before loading the document (with setURI, setDocument, setSVGDocument, etc.).
The second common reason is that the changes aren’t made in the UpdateManager ’s thread. You can run code in the UpdateManager ’s thread with the following: UpdateManager um = JSVGCanvas.getUpdateManager(); um.getUpdateRunnableQueue().invokeLater(Runnable); NOTE: The update manager only becomes available after the first rendering completes. You can be notified when this happens by registering a GVTTreeRendererListener.
But i don't try this yet.

How to create programmatically and execute custom animation in jME3?

There is a hello animation example, where, apparently, predefined character with predefined animations is used.
But what if I want to create some animation on-the-fly, programmatically? Suppose I want just cube perform some movements and rotations?
I found a class Animation which allows adding a tracks. One of the tracks type is SpatialTrack which has obvious structure: it apparently consists of a series of transformations and rotations over time.
But what to do with such an object, once it was created? How to "apply" or "execute" it on some geometry?
UPDATE
I found another pattern: first create MotionPath, then wrap it into MotionEvent and then add resulting object to the object you want to behave with addControl() method. Probably object will follow the path. Unfortunately, I can't find, how to set the orientation. Despite the fact that MotionEvent class has getRotation() method, which is documented as returning rotation of target object, I can't see any methods to set rotations in MotionPath, which constitues the MotionEvent.
I recommend using Cinematics for what you are attempting to do. All you have to do is create a cinematic object, add the appropriate events to it, and then use objectName.play().
The best part is that you are able to use both your original idea of animation objects as well as through your edited idea of using MotionPaths. You just have to use AnimationEvents and MotionEvents respectively.
You can also implement looping through a simple function that the wikipedia page gives you as well as being able to set direction for the movement.

JTree sometimes not expanding

I have this pretty big project that I'm working on, graphic editor, and I've had some big problems working with swing components. However, now I have a programmers worst nightmare, a bug that is happening only some of the times.
If I try to select the elements in my JTree, whether when adding elements, or when selecting them when they are selected in diagram (JInternalFrame), some of them don't get expanded.
My structure is something like this, I have a workspace, containing projects and projects that contain diagrams. Diagrams hold all the elements I have, let's say circles, rectangles and so on, in folders (if they are circles, they are put in circles folder...).
Another thing to know is that I select my elements via setSelectedPath/Paths method of my JTree.
Some of the things that may help understanding what I do and what I tried:
I made sure my nodes know how to get to root. (getTreeModel.getPathToRoot returns good path)
I tried adding paths to trees selection model and to tree directly
I have set the trees expandsSelectedPaths to true
Nodes are selected when I expand my tree manually (they even expand afterwards), until I add new elements of type that caused problems
This happens about once when switching through 5 types of elements, and some stranger things happen when I try to add other type of element after I added one that made problems
I hope someone will know what to do, although I think this is very complicated problem. Please ask anything that may help you help me.
OK, thanks everyone for answering, but I have found a very simple workaround for this problem.
The thing was expanding has no effect if the last path component is leaf, for some reason.
What I did was simply making my leaf nodes return false for isLeaf method, and all my problems went away.
if addWhatever() to JTree firing the correct TreeModelEvent (fireChildAdded(), firePathChanged(), fireChildrenLoaded(), treeStructureChanged())
all changes for GUI would be moved to the BackGround Task(s), please look at SwingWorker or Runnable#Thread (most clear and easiest way), but Runnable#Thread required wrapping all output (Swing methods) to the invokeLater

Slick2D Movement Issue

So, I converted a game to Slick2D. The movement is broke, and I am at a loss. Before, we used KeyPressed and keyReleased methods, but now with Slick2D movement isn't working right.
Yea, nothing has gone right with converting to Slick2D. First the launcher, which I had a help topic on before, and now this. Though, the other topic was an issue with WebStart hating code.
You can only move right, using A. And you can't stop moving. Am I using the right methods? How can I fix it? Any help is greatly appreciated!
Here is a PasteBin link to the code, if it helps! http://pastebin.com/GRH86Yuw
I'm a fan of Slick, and I'd be happy to help.
The fundamental difference is that Slick is a polling model, not an event-driven model when it comes to input. Basically, in your logic update method you loop through the keys bound to your events, and check to see if any of the keys are currently pressed, and then trigger those events. For a number of reasons that I can go into if you like, polling tends to work better for games, especially with a large number of keys. It's just a different way of doing things, an not that complicated. The biggest upside is that you get centralized input processing a single method, instead of having it spread across multiple KeyListener instance objects.
If you want to look at Pedestrians - a simple pedestrian sim implemented in Slick - you can see an example of how to handle input in Slick.
Specifically, I handle input in this file (lines 192-295), inside the processInput method. Basically, you pass in a reference to the GameContainer object (the Slick object that contains your game), and from that you can get an instance to the Input instance that will allow you to check which keys are pressed, what mouse buttons are clicked, etc.

Modifying graphics context in Java

I have a form that tries to modify a JComponent's graphics context. I use, for example,
((Graphics2D) target.getGraphics()).setStroke(new BasicStroke(5));
Now, immediately after I set the value and close the form, the change is not visible. Am I not allowed to modify a JComponent's graphics context? How else would I modify the stroke, color and transformations?
Thanks,
Vlad
There are several problems with that approach. The first is that most components will set these things themselves when ever they are asked to repaint themselves. This means that your change will be lost every time the component gets to the point where it would actually use it. But, on an even more fundamental level than that, Graphics2D objects are not persistant. They are typically instantiated every time the component is redrawn, meaning that the Graphics2D object you got won't be the same the component will be using when redrawing.
What you need to do, to achieve this kind of thing is either to reimplement the specific component yourself, or implement a new look and feel that will affect the entire set of swing components. Have a look at the following link for further details about this:
http://today.java.net/pub/a/today/2006/09/12/how-to-write-custom-look-and-feel.html
Nobody to answer? I have let some time to see if there is any good answer before mine: I am not a specialist of such question...
First, I don't fully understand your question: you change a setting then close the form?
Anyway, I am not too sure, but somewhere in the process, the graphics context might be recomputed or taken from default. Perhaps if you do this operation in the paint() method, you can get some result, although I am not sure.
For a number of changes, you usually use a decorator. I explored a bit this topic when answering a question on SO: How do I add a separator to a JComboBox in Java?. I had to paint my own border there (asymmetrical), but often you just take an existing one, so it is quite simple.
I hope I provided some information, if it didn't helped, perhaps you should give more details on what you want to do (and perhaps a simple, minimal program illustrating your problem).
OK, I've worked around the problem like this: The custom JComponent now holds a Stroke object, which is set by the "Choose stroke" form when the user clicks OK. Then, in the paint method of the JComponent, I set the stroke of the graphics context passed as parameter to paint to the one contained in the object.
I have experimented and found out that, for some reason, JComponent.getGraphics().set* doesn't work.

Categories

Resources