@Override public void translate(int dx, int dy) { p0 = p0.translate(dx, dy); p1 = p1.translate(dx, dy); p2 = p2.translate(dx, dy); bounds = bounds.translate(dx, dy); }
public ALU(Location loc, AttributeSet attrs) { super(loc, attrs, 5); setEnd(0, loc.translate(-30, -30), BITWIDTH_32, 1); setEnd(1, loc.translate(-30, 30), BITWIDTH_32, 1); setEnd(2, loc.translate(-10, 40), BITWIDTH_4, 1); setEnd(3, loc.translate(30, -20), BITWIDTH_1, 2); setEnd(4, loc.translate(30, 0), BITWIDTH_32, 2); setEnd(5, loc.translate(30, 20), BITWIDTH_1, 2); }
public EndData toEnd(Location loc, AttributeSet attrs) { Location pt = loc.translate(dx, dy); if (widthFixed != null) { return new EndData(pt, widthFixed, type, exclude); } else { Object val = attrs.getValue(widthAttr); if (!(val instanceof BitWidth)) { throw new IllegalArgumentException("Width attribute not set"); } return new EndData(pt, (BitWidth) val, type, exclude); } }
@Override public void paste() { ClipboardContents clip = Clipboard.get(); Collection<CanvasObject> contents = clip.getElements(); List<CanvasObject> add = new ArrayList<CanvasObject>(contents.size()); for (CanvasObject o : contents) { add.add(o.clone()); } if (add.isEmpty()) return; // find how far we have to translate shapes so that at least one of the // pasted shapes doesn't match what's already in the model Collection<CanvasObject> raw = canvas.getModel().getObjectsFromBottom(); MatchingSet<CanvasObject> cur = new MatchingSet<CanvasObject>(raw); int dx = 0; while (true) { // if any shapes in "add" aren't in canvas, we are done boolean allMatch = true; for (CanvasObject o : add) { if (!cur.contains(o)) { allMatch = false; break; } } if (!allMatch) break; // otherwise translate everything by 10 pixels and repeat test for (CanvasObject o : add) { o.translate(10, 10); } dx += 10; } Location anchorLocation = clip.getAnchorLocation(); if (anchorLocation != null && dx != 0) { anchorLocation = anchorLocation.translate(dx, dx); } canvas .getProject() .doAction( new SelectionAction( canvas, Strings.getter("pasteClipboardAction"), null, add, add, anchorLocation, clip.getAnchorFacing())); }
private void paintBase(InstancePainter painter) { GateAttributes attrs = (GateAttributes) painter.getAttributeSet(); Direction facing = attrs.facing; int inputs = attrs.inputs; int negated = attrs.negated; Object shape = painter.getGateShape(); Location loc = painter.getLocation(); Bounds bds = painter.getOffsetBounds(); int width = bds.getWidth(); int height = bds.getHeight(); if (facing == Direction.NORTH || facing == Direction.SOUTH) { int t = width; width = height; height = t; } if (negated != 0) { width -= 10; } Graphics g = painter.getGraphics(); Color baseColor = g.getColor(); if (shape == AppPreferences.SHAPE_SHAPED && paintInputLines) { PainterShaped.paintInputLines(painter, this); } else if (negated != 0) { for (int i = 0; i < inputs; i++) { int negatedBit = (negated >> i) & 1; if (negatedBit == 1) { Location in = getInputOffset(attrs, i); Location cen = in.translate(facing, 5); painter.drawDongle(loc.getX() + cen.getX(), loc.getY() + cen.getY()); } } } g.setColor(baseColor); g.translate(loc.getX(), loc.getY()); double rotate = 0.0; if (facing != Direction.EAST && g instanceof Graphics2D) { rotate = -facing.toRadians(); Graphics2D g2 = (Graphics2D) g; g2.rotate(rotate); } if (shape == AppPreferences.SHAPE_RECTANGULAR) { paintRectangular(painter, width, height); } else if (shape == AppPreferences.SHAPE_DIN40700) { paintDinShape(painter, width, height, inputs); // SHAPE_SHAPED } else { if (negateOutput) { g.translate(-10, 0); paintShape(painter, width - 10, height); painter.drawDongle(5, 0); g.translate(10, 0); } else { paintShape(painter, width, height); } } if (rotate != 0.0) { ((Graphics2D) g).rotate(-rotate); } g.translate(-loc.getX(), -loc.getY()); painter.drawLabel(); }