symbolAddButton = new Button(getString("sidebar.insertSymbol"));
symbolAddButton.onClicked(new Callback<ActionEvent>() { public void call(ActionEvent event) {
if(listView.getSelectedIndex() < 0) return;
SNode node = listView.getModel().get(listView.getSelectedIndex());
SketchDocument sd = context.getDocument();
sd.getCurrentPage().add(node.duplicate(null));
context.redraw();
}});
EventBus.getSystem().addListener(listView, MouseEvent.MouseAll, new Callback<MouseEvent>() {
public double prevx;
public boolean created;
public SNode dupe;
public void call(MouseEvent event) {
if(event.getType() == MouseEvent.MousePressed) {
ContextMenu.hideAll();
if(event.getButton() == 3) { // check for right clicks to open the context menu
showContextMenu(event);
return;
}
}
if(event.getType() == MouseEvent.MouseDragged) {
if(created && dupe != null) {
Point2D pt = event.getPointInNodeCoords(context.getCanvas());
pt = context.getSketchCanvas().transformToCanvas(pt);
Bounds b = dupe.getBounds();
dupe.setTranslateX(pt.getX()-b.getWidth()/2);
dupe.setTranslateY(pt.getY()-b.getHeight()/2);
context.redraw();
}
if(event.getX() < 0 && prevx >= 0 && !created) {
created = true;
if(listView.getSelectedIndex() < 0) return;
SNode node = listView.getModel().get(listView.getSelectedIndex());
SketchDocument sd = context.getDocument();
dupe = node.duplicate(null);
Bounds b = dupe.getBounds();
sd.getCurrentPage().add(dupe);
Point2D pt = event.getPointInNodeCoords(context.getCanvas());
pt = context.getSketchCanvas().transformToCanvas(pt);
dupe.setTranslateX(pt.getX()-b.getWidth()/2);
dupe.setTranslateY(pt.getY()-b.getHeight()/2);
context.redraw();