Search in sources :

Example 1 with WidthIncompatibilityData

use of com.cburch.logisim.circuit.WidthIncompatibilityData in project logisim-evolution by reds-heig.

the class CanvasPainter method drawWidthIncompatibilityData.

private void drawWidthIncompatibilityData(Graphics base, Graphics g, Project proj) {
    Set<WidthIncompatibilityData> exceptions;
    exceptions = proj.getCurrentCircuit().getWidthIncompatibilityData();
    if (exceptions == null || exceptions.size() == 0)
        return;
    g.setColor(Value.WIDTH_ERROR_COLOR);
    GraphicsUtil.switchToWidth(g, 2);
    FontMetrics fm = base.getFontMetrics(g.getFont());
    for (WidthIncompatibilityData ex : exceptions) {
        for (int i = 0; i < ex.size(); i++) {
            Location p = ex.getPoint(i);
            BitWidth w = ex.getBitWidth(i);
            // ensure it hasn't already been drawn
            boolean drawn = false;
            for (int j = 0; j < i; j++) {
                if (ex.getPoint(j).equals(p)) {
                    drawn = true;
                    break;
                }
            }
            if (drawn)
                continue;
            // compute the caption combining all similar points
            String caption = "" + w.getWidth();
            for (int j = i + 1; j < ex.size(); j++) {
                if (ex.getPoint(j).equals(p)) {
                    caption += "/" + ex.getBitWidth(j);
                    break;
                }
            }
            g.drawOval(p.getX() - 4, p.getY() - 4, 8, 8);
            g.drawString(caption, p.getX() + 5, p.getY() + 2 + fm.getAscent());
        }
    }
    g.setColor(Color.BLACK);
    GraphicsUtil.switchToWidth(g, 1);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) WidthIncompatibilityData(com.cburch.logisim.circuit.WidthIncompatibilityData) FontMetrics(java.awt.FontMetrics) Location(com.cburch.logisim.data.Location)

Example 2 with WidthIncompatibilityData

use of com.cburch.logisim.circuit.WidthIncompatibilityData in project logisim-evolution by reds-heig.

the class Canvas method computeViewportContents.

private void computeViewportContents() {
    Set<WidthIncompatibilityData> exceptions = proj.getCurrentCircuit().getWidthIncompatibilityData();
    if (exceptions == null || exceptions.isEmpty()) {
        viewport.setWidthMessage(null);
        return;
    }
    Rectangle viewableBase;
    Rectangle viewable;
    if (canvasPane != null) {
        viewableBase = canvasPane.getViewport().getViewRect();
    } else {
        Bounds bds = proj.getCurrentCircuit().getBounds();
        viewableBase = new Rectangle(0, 0, bds.getWidth(), bds.getHeight());
    }
    double zoom = getZoomFactor();
    if (zoom == 1.0) {
        viewable = viewableBase;
    } else {
        viewable = new Rectangle((int) (viewableBase.x / zoom), (int) (viewableBase.y / zoom), (int) (viewableBase.width / zoom), (int) (viewableBase.height / zoom));
    }
    viewport.setWidthMessage(Strings.get("canvasWidthError") + (exceptions.size() == 1 ? "" : " (" + exceptions.size() + ")"));
    for (WidthIncompatibilityData ex : exceptions) {
        // See whether any of the points are on the canvas.
        boolean isWithin = false;
        for (int i = 0; i < ex.size(); i++) {
            Location p = ex.getPoint(i);
            int x = p.getX();
            int y = p.getY();
            if (x >= viewable.x && x < viewable.x + viewable.width && y >= viewable.y && y < viewable.y + viewable.height) {
                isWithin = true;
                break;
            }
        }
        // If none are, insert an arrow.
        if (!isWithin) {
            Location p = ex.getPoint(0);
            int x = p.getX();
            int y = p.getY();
            boolean isWest = x < viewable.x;
            boolean isEast = x >= viewable.x + viewable.width;
            boolean isNorth = y < viewable.y;
            boolean isSouth = y >= viewable.y + viewable.height;
            if (isNorth) {
                if (isEast) {
                    viewport.setNortheast(true);
                } else if (isWest) {
                    viewport.setNorthwest(true);
                } else {
                    viewport.setNorth(true);
                }
            } else if (isSouth) {
                if (isEast) {
                    viewport.setSoutheast(true);
                } else if (isWest) {
                    viewport.setSouthwest(true);
                } else {
                    viewport.setSouth(true);
                }
            } else {
                if (isEast) {
                    viewport.setEast(true);
                } else if (isWest) {
                    viewport.setWest(true);
                }
            }
        }
    }
}
Also used : WidthIncompatibilityData(com.cburch.logisim.circuit.WidthIncompatibilityData) Bounds(com.cburch.logisim.data.Bounds) Rectangle(java.awt.Rectangle) Location(com.cburch.logisim.data.Location)

Aggregations

WidthIncompatibilityData (com.cburch.logisim.circuit.WidthIncompatibilityData)2 Location (com.cburch.logisim.data.Location)2 BitWidth (com.cburch.logisim.data.BitWidth)1 Bounds (com.cburch.logisim.data.Bounds)1 FontMetrics (java.awt.FontMetrics)1 Rectangle (java.awt.Rectangle)1