Monday October 05, 2009
Multiple Selection in Small Visual Bean Editor
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.
Oct 05 2009, 01:08:24 PM PDT Permalink


