I am hoping to create a mind-mapping like application and it needs to have a central workspace that will hold the map. Users should be able to drag items (like rectangles, texts, etc.) from a container to the workspace. The important thing is when a user is dragging an element to the workspace, the element should move with the mouse, not just the text.

What I'm looking for is something like the web apps LucidChart, Cacoo, MindMeister, etc. So is this possible to do in Java without too much hassle? And if yes, what is the application design (algorithm)?

I have searched many resources but have only found ways to drag only the text, images or the like. Not the entire element itself. It would be even better if I could make it to drag an entire JButton, so the users can create a map of JButtons.

Sorry if this is not the place to post this (should I post it in StackOverflow or here?).

FreeMind is an excellent floss mind-mapping app written in Java. So, yes it's possible :) Look at their code for inspiration... PS: I'm making this for Linux (Ubuntu). Since you'd be writing this in Java, that's largely irrelevant.
–
Yannis Rizos♦Dec 21 '11 at 13:05

@YannisRizos Saw FreeMind. Yes it would be something like that but simpler. I'm looking for an algorithm and the best flow to develop it. And I added that "I'm making this for Linux" part because I thought that I would have to use native Windows libraries or something like that. :)
–
RoshnalDec 21 '11 at 13:10

Well answers on application design / workflow shouldn't be around implementation specifics anyway. I think the possibility of someone suggesting a native windows library (within a good answer) is extremely small. If you are looking for implementation specifics, ask that question on StackOverflow and just keep the application design / workflow aspects of it here. Of course feel free to add the ps. back to the question, if you disagree with my edit.
–
Yannis Rizos♦Dec 21 '11 at 13:15

@YannisRizos So if I ask the same question on SO, I wouldn't be voted down right? And yeah I agree with you on that native-library thing.
–
RoshnalDec 21 '11 at 13:22

Well I can't really predict votes, but generally speaking the SO people prefer to see some code in questions. Typical questions there are of the "I tried this and that, it failed here and there, please help" style, where this and that are usually code samples.
–
Yannis Rizos♦Dec 21 '11 at 13:25

1 Answer
1

// Your framework probably provides this
class Point {
private int x, y; // x,y coordinates of top left of View
}
// Your framework probably provides something like this
/** Container class for all other types */
abstract class MindMapView {
public MindMapView(int width, int height, Point position) {
// Initialize fields
}
/** Top-Left */
private Point mPosition;
/** Width, Height */
private int mWidth, mHeight; // Width and height of view
/** Implement this to fulfill a request to draw the view on the screen */
abstract void onDraw();
/** Implement this to fulfill a request to move the view across the screen */
abstract void onMove(Point delta);
/** Implement this to fulfill a request to resize the view */
abstract void onResize(int width, int height);
/**
Implement this to fulfill a request to drag this view. Can be similar
to onMove, except you will want to hook the point where the view is
"dropped", which would be the last point in the drag.
We'd consider a drag to be a left mouse click, mouse movement, and mouse
un-click.
*/
abstract void onDrag(Point delta);
/** Called by other classes that desire to draw this View */
public final void draw() {
onDraw();
}
/** Called by other classes that desire to move this view */
public final void move(Point delta) {
onMove(delta);
}
/** Called by other classes that desire to resize this view */
public final void resize() {
onResize();
}
public final void drag(Point delta) {
onDrag(delta);
}
/** Implement this to
public Point getPosition() {
return mPosition;
}
}

You will hook your framework to funnel the various events into this view, but more than likely, your framework has a similar class ready for you.. Once you have that, you can extend it to make your other elements