use of com.cburch.draw.canvas.Selection in project logisim-evolution by reds-heig.
the class AppearanceEditHandler method duplicate.
@Override
public void duplicate() {
Selection sel = canvas.getSelection();
int n = sel.getSelected().size();
List<CanvasObject> select = new ArrayList<CanvasObject>(n);
List<CanvasObject> clones = new ArrayList<CanvasObject>(n);
for (CanvasObject o : sel.getSelected()) {
if (o.canRemove()) {
CanvasObject copy = o.clone();
copy.translate(10, 10);
clones.add(copy);
select.add(copy);
} else {
select.add(o);
}
}
if (!clones.isEmpty()) {
canvas.getProject().doAction(new SelectionAction(canvas, Strings.getter("duplicateSelectionAction"), null, clones, select, null, null));
}
}
use of com.cburch.draw.canvas.Selection in project logisim-evolution by reds-heig.
the class AppearanceEditHandler method computeEnabled.
@Override
public void computeEnabled() {
Project proj = canvas.getProject();
Circuit circ = canvas.getCircuit();
Selection sel = canvas.getSelection();
boolean selEmpty = sel.isEmpty();
boolean canChange = proj.getLogisimFile().contains(circ);
boolean clipExists = !Clipboard.isEmpty();
boolean selHasRemovable = false;
for (CanvasObject o : sel.getSelected()) {
if (!(o instanceof AppearanceElement)) {
selHasRemovable = true;
}
}
boolean canRaise;
boolean canLower;
if (!selEmpty && canChange) {
Map<CanvasObject, Integer> zs = ZOrder.getZIndex(sel.getSelected(), canvas.getModel());
int zmin = Integer.MAX_VALUE;
int zmax = Integer.MIN_VALUE;
int count = 0;
for (Map.Entry<CanvasObject, Integer> entry : zs.entrySet()) {
if (!(entry.getKey() instanceof AppearanceElement)) {
count++;
int z = entry.getValue().intValue();
if (z < zmin)
zmin = z;
if (z > zmax)
zmax = z;
}
}
int maxPoss = AppearanceCanvas.getMaxIndex(canvas.getModel());
if (count > 0 && count <= maxPoss) {
canRaise = zmin <= maxPoss - count;
canLower = zmax >= count;
} else {
canRaise = false;
canLower = false;
}
} else {
canRaise = false;
canLower = false;
}
boolean canAddCtrl = false;
boolean canRemCtrl = false;
Handle handle = sel.getSelectedHandle();
if (handle != null && canChange) {
CanvasObject o = handle.getObject();
canAddCtrl = o.canInsertHandle(handle.getLocation()) != null;
canRemCtrl = o.canDeleteHandle(handle.getLocation()) != null;
}
setEnabled(LogisimMenuBar.CUT, selHasRemovable && canChange);
setEnabled(LogisimMenuBar.COPY, !selEmpty);
setEnabled(LogisimMenuBar.PASTE, canChange && clipExists);
setEnabled(LogisimMenuBar.DELETE, selHasRemovable && canChange);
setEnabled(LogisimMenuBar.DUPLICATE, !selEmpty && canChange);
setEnabled(LogisimMenuBar.SELECT_ALL, true);
setEnabled(LogisimMenuBar.RAISE, canRaise);
setEnabled(LogisimMenuBar.LOWER, canLower);
setEnabled(LogisimMenuBar.RAISE_TOP, canRaise);
setEnabled(LogisimMenuBar.LOWER_BOTTOM, canLower);
setEnabled(LogisimMenuBar.ADD_CONTROL, canAddCtrl);
setEnabled(LogisimMenuBar.REMOVE_CONTROL, canRemCtrl);
}
use of com.cburch.draw.canvas.Selection in project logisim-evolution by reds-heig.
the class SelectionAction method doIt.
@Override
public void doIt(Project proj) {
Selection sel = canvas.getSelection();
sel.clearSelected();
if (toRemove != null)
canvasModel.removeObjects(toRemove.keySet());
int dest = AppearanceCanvas.getMaxIndex(canvasModel) + 1;
if (toAdd != null)
canvasModel.addObjects(dest, toAdd);
AppearanceAnchor anchor = findAnchor(canvasModel);
if (anchor != null && anchorNewLocation != null) {
anchorOldLocation = anchor.getLocation();
anchor.translate(anchorNewLocation.getX() - anchorOldLocation.getX(), anchorNewLocation.getY() - anchorOldLocation.getY());
}
if (anchor != null && anchorNewFacing != null) {
anchorOldFacing = anchor.getFacing();
anchor.setValue(AppearanceAnchor.FACING, anchorNewFacing);
}
sel.setSelected(newSelection, true);
canvas.repaint();
}
use of com.cburch.draw.canvas.Selection in project logisim-evolution by reds-heig.
the class SelectTool method keyTyped.
@Override
public void keyTyped(Canvas canvas, KeyEvent e) {
char ch = e.getKeyChar();
Selection selected = canvas.getSelection();
if ((ch == '\u0008' || ch == '\u007F') && !selected.isEmpty()) {
ArrayList<CanvasObject> toRemove = new ArrayList<CanvasObject>();
for (CanvasObject shape : selected.getSelected()) {
if (shape.canRemove()) {
toRemove.add(shape);
}
}
if (!toRemove.isEmpty()) {
e.consume();
CanvasModel model = canvas.getModel();
canvas.doAction(new ModelRemoveAction(model, toRemove));
selected.clearSelected();
repaintArea(canvas);
}
} else if (ch == '\u001b' && !selected.isEmpty()) {
selected.clearSelected();
repaintArea(canvas);
}
}
use of com.cburch.draw.canvas.Selection in project logisim-evolution by reds-heig.
the class AttrTableSelectionModel method getTitle.
@Override
public String getTitle() {
Selection sel = canvas.getSelection();
Class<? extends CanvasObject> commonClass = null;
int commonCount = 0;
CanvasObject firstObject = null;
int totalCount = 0;
for (CanvasObject obj : sel.getSelected()) {
if (firstObject == null) {
firstObject = obj;
commonClass = obj.getClass();
commonCount = 1;
} else if (obj.getClass() == commonClass) {
commonCount++;
} else {
commonClass = null;
}
totalCount++;
}
if (firstObject == null) {
return null;
} else if (commonClass == null) {
return Strings.get("selectionVarious", "" + totalCount);
} else if (commonCount == 1) {
return Strings.get("selectionOne", firstObject.getDisplayName());
} else {
return Strings.get("selectionMultiple", firstObject.getDisplayName(), "" + commonCount);
}
}
Aggregations