Draggable rectangles in Java 2D [duplicate] - java

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
how to drag object
I need to draw some UML components (classes, packages etc) using Java 2D and then be able to drag them around. Is there a way to do this? I mean, to make a shape "draggable"?

JHotDraw was designed as "a Java GUI framework for technical and structured Graphics." The linked JHotDraw Pattern Language: JHotDraw Domain Overview illustrates how to customize drawing editors. The sample org.jhotdraw.samples.draw.Main is a reasonable starting point, and JModeller is a simple UML editor built using the framework.

Are you forced to swing?
If not you might have look at draw2d which is a java library that works on a SWT canvas. You can find some examples of draw2d here.

You can only add MouseListener to a (J)Component. All Java2D stuff is painted on the component. If you manage all shapes in a List you can search for the correct shape under the mouse courser, move it and repaint the component.

Related

Convert Shape from awt to Shape in javafx

I want to display Shape on Pane in JavaFx. I am using oracle JGeometry object selected from spatial database, it has a method createShape() but it returns java.awt.Shape.
Is it possible to create JavaFx object also so easily? Maybe I am just blind but I haven't found anything and don't want to program too much stuff on top. Thank you
Java only supports a handful of shapes, so it is not very difficult to write a little converter but if all you want to do is to draw the AWT shapes on a JavaFX canvas, then maybe this library can be helpful: http://www.jfree.org/fxgraphics2d/

Manipulating Pixels(Drawing) in Java

This is not a typical "what library do i use?" or "is there an API for that". Using lines of code I create not implementing them through a library of sorts. Is there any documentation on how to actually create a window, and within that window draw a line from pixels?
I just want to understand how its done, and not learn through a library which does it for me.
Previously tried:
JavaFx
Swing
If you want to draw a line in a window, you'll ultimately have to create a BufferedImage, set pixels in that BufferedImage according to some drawing algorithm (like Bresenham's), then put the BufferedImage in the window.

Java 2d graphic library

Hi I am trying to create simple 2d graphic editor. I need some library which will create shape from given points(draw lines between these points) and then user can move this shape with mouse or scale this shape with mouse. I need points, because I have Oracle Jgeometry shape saved in database and I need to visualize it. Could you please help me?
I found jGraph but I don't know, how to create shape from points, or get these points from shape
Instead of reinventing the wheel I would suggest using svg. There is a pretty nice implementation from Apache: https://xmlgraphics.apache.org/batik/
You could generate svg from your data (which is pretty easy) and pass it on to batik to show in a component or you can use their bindings to Java2D to draw.
As a bonus you can use existing tools like Inkscape to edit you drawings further.
There are existing projects which use this to do simmilar things like you want: https://xmlgraphics.apache.org/batik/uses.html

3d Way Finding Mapping

Hello there guys and gals
I'm just little bit confused about creating simple way finding using the java programming language?
Or is it possible in java? I want to create a simple way finding just like these
Do you have any suggestions for this particular matter?
You need to use a shortest-path algorithm and a matrix-builder from the way-points of your map. Java 3D has built-in primitive shapes such as cylinders, spheres and cubes. But you can make your own geometry from points, triangles and quads. See some of the java3D tagged questions in SO.
In java3D, mouse and keyboard interaction is very easy implemented.
Collision detection is also a good pro of java3D while not having a shadow lib being a con.
You can try 3D Wayfinder. They have a public API and fully featured 3d wayfinding. Its not in Java but uses HTML5, WebGL and JavaScript. Yiu have to upload just a floor plan model and are good to go.

How should I proceed to do a interactive program with drag feature and graph arrows

I'm doing a college project which I must finish in 3 months. And I have 8 hours a week to spend in that project.
The project consists in doing a graphical interface that shows many rectangles next to each other which should be movable. It should be very similar to the tabs in the chrome browser, where you can drag them to which ever position you want.
In addition to that there should be arrows connecting one rectangle to the other. And these arrows should still connect the same rectangles even when I change the order of the rectangles. The image below illustrates what I'm saying.
The image shows before and after one of the rectangles being dragged.
Since Java is my first language, I would like to use it.
My question is: What framework, APIs should I use to do this project. What will be the easiest and fastest way to do it? Should I use Swing? or JavaFX? or GWT? or other alternative?
Is there an API for handling arrows connecting objects? Maybe one used for representing graphs may be ok.
Edit: I don't know anything about Swing and neither about JavaFX. So which one would be more worthwhile learning given that I don’t have too much time this semester because I’m very busy?
This shouldn't be too hard to write from scratch.
Use this site : http://www.codeproject.com/Articles/116088/Draggable-Components-in-Java-Swing for the drag-able components
Draw arrows with some kind of parameterization (math formula) for half of an oval. Pass the draw path into a java.awt.Graphics2D pen object.
You might want to check Java Universal Network/Graph Framework.
It has some extensive support for making editable graphs while maintaining relationship among nodes and edges.
What you can do is change the icon of node to a squared rectagnle, while add logic to plot them in a straight axis so that it would look the way you want, plus it would be editable while linked arrows will remain where they should be.
But incase you don't have experience with Swing, better start learning the basis of SWING first, as JUNG framework pretty much requires some good basic knowledge of swing itself.

Categories

Resources