X

Geertjan's Blog

  • October 5, 2009

Multiple Selection in Small Visual Bean Editor

Geertjan Wielenga
Product Manager
I used the code in Toni's blog today (also similar code here) to add multi-select support for the small Visual Editor I've been working on. Below, the widgets with green borders are selected (via Ctrl+click), while the widgets with blue borders are not selected:

The next step is to figure out how to MOVE the selected widgets together, rather than just one on its own.

Update. Now the multiple-move is working too. First, add to the widget:

MyMoveStrategyProvider provider = new MyMoveStrategyProvider(scene);
getActions().addAction(ActionFactory.createMoveAction(provider, provider));

Then, the class, copied/tweaked from the Visual Library:

public final class MyMoveStrategyProvider implements MoveStrategy, MoveProvider {
private HashMap<Widget,Point> originalLocations = new HashMap<Widget, Point> ();
private final EditorComponentGraphScene scene;
public MyMoveStrategyProvider (EditorComponentGraphScene scene) {
this.scene = scene;
}
@Override
public Point locationSuggested (Widget widget, Point originalLocation, Point suggestedLocation) {
return suggestedLocation;
}
@Override
public void movementStarted (Widget widget) {
}
@Override
public void movementFinished (Widget widget) {
originalLocations.clear();
}
@Override
public Point getOriginalLocation (Widget widget) {
for (Object o : scene.getSelectedObjects()) {
Widget w = scene.findWidget (o);
originalLocations.put (w, ActionFactory.createDefaultMoveProvider ().getOriginalLocation (w));
}
return ActionFactory.createDefaultMoveProvider ().getOriginalLocation (widget);
}
@Override
public void setNewLocation (Widget widget, Point location) {
ActionFactory.createDefaultMoveProvider ().setNewLocation (widget, location);
Point originalLocation = originalLocations.get(widget);
if (originalLocation == null)
return;
int dx = location.x - originalLocation.x;
int dy = location.y - originalLocation.y;
for (Entry<Widget, Point> entry : originalLocations.entrySet()) {
Widget w = entry.getKey();
if (w == widget)
continue;
Point l = new Point (entry.getValue());
l.translate(dx, dy);
ActionFactory.createDefaultMoveProvider().setNewLocation(w, l);
}
}
}

And now selected widgets move together.

Join the discussion

Comments ( 1 )
  • Gonzalo Medina Saturday, September 7, 2013

    Hi Geertjan. I'm using the visual library from Netbeans and i need to use a MoveStrategy ("Snap to Grid" , specifically) in wich the widget that is moving doesn't intersects with other objects in the scene. Do you know if it exist some piece of code or do i need to write it entirely by myself? Thanks in advance!


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.