Search in sources :

Example 1 with Direction

use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.

the class Frame method placeToolbar.

private void placeToolbar() {
    String loc = AppPreferences.TOOLBAR_PLACEMENT.get();
    Container contents = getContentPane();
    contents.remove(toolbar);
    mainPanelSuper.remove(toolbar);
    if (AppPreferences.TOOLBAR_HIDDEN.equals(loc)) {
        // don't place value anywhere
        ;
    } else if (AppPreferences.TOOLBAR_DOWN_MIDDLE.equals(loc)) {
        toolbar.setOrientation(Toolbar.VERTICAL);
        mainPanelSuper.add(toolbar, BorderLayout.WEST);
    } else {
        // it is a BorderLayout constant
        Object value = BorderLayout.NORTH;
        for (Direction dir : Direction.cardinals) {
            if (dir.toString().equals(loc)) {
                if (dir == Direction.EAST) {
                    value = BorderLayout.EAST;
                } else if (dir == Direction.SOUTH) {
                    value = BorderLayout.SOUTH;
                } else if (dir == Direction.WEST) {
                    value = BorderLayout.WEST;
                } else {
                    value = BorderLayout.NORTH;
                }
            }
        }
        contents.add(toolbar, value);
        boolean vertical = value == BorderLayout.WEST || value == BorderLayout.EAST;
        toolbar.setOrientation(vertical ? Toolbar.VERTICAL : Toolbar.HORIZONTAL);
    }
    contents.validate();
}
Also used : Container(java.awt.Container) Direction(com.cburch.logisim.data.Direction)

Example 2 with Direction

use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.

the class AddTool method setFacing.

private void setFacing(Canvas canvas, Direction facing) {
    ComponentFactory source = getFactory();
    if (source == null)
        return;
    AttributeSet base = getBaseAttributes();
    Object feature = source.getFeature(ComponentFactory.FACING_ATTRIBUTE_KEY, base);
    @SuppressWarnings("unchecked") Attribute<Direction> attr = (Attribute<Direction>) feature;
    if (attr != null) {
        Action act = ToolAttributeAction.create(this, attr, facing);
        canvas.getProject().doAction(act);
    }
}
Also used : Action(com.cburch.logisim.proj.Action) ToolAttributeAction(com.cburch.logisim.gui.main.ToolAttributeAction) AttributeSet(com.cburch.logisim.data.AttributeSet) Attribute(com.cburch.logisim.data.Attribute) ComponentFactory(com.cburch.logisim.comp.ComponentFactory) Direction(com.cburch.logisim.data.Direction)

Example 3 with Direction

use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.

the class AddTool method keyPressed.

@Override
public void keyPressed(Canvas canvas, KeyEvent event) {
    processKeyEvent(canvas, event, KeyConfigurationEvent.KEY_PRESSED);
    if (!event.isConsumed() && event.getModifiersEx() == 0) {
        int KeybEvent = event.getKeyCode();
        String Component = getFactory().getDisplayName();
        if (!GateKeyboardModifier.TookKeyboardStrokes(KeybEvent, null, attrs, canvas, null, false))
            if (AutoLabler.LabelKeyboardHandler(KeybEvent, getAttributeSet(), Component, null, getFactory(), canvas.getCircuit(), null, false)) {
                canvas.repaint();
            } else
                switch(KeybEvent) {
                    case KeyEvent.VK_UP:
                        setFacing(canvas, Direction.NORTH);
                        break;
                    case KeyEvent.VK_DOWN:
                        setFacing(canvas, Direction.SOUTH);
                        break;
                    case KeyEvent.VK_LEFT:
                        setFacing(canvas, Direction.WEST);
                        break;
                    case KeyEvent.VK_RIGHT:
                        setFacing(canvas, Direction.EAST);
                        break;
                    case KeyEvent.VK_R:
                        Direction current = getFacing();
                        if (current == Direction.NORTH)
                            setFacing(canvas, Direction.EAST);
                        else if (current == Direction.EAST)
                            setFacing(canvas, Direction.SOUTH);
                        else if (current == Direction.SOUTH)
                            setFacing(canvas, Direction.WEST);
                        else
                            setFacing(canvas, Direction.NORTH);
                        break;
                    case KeyEvent.VK_ESCAPE:
                        Project proj = canvas.getProject();
                        Library base = proj.getLogisimFile().getLibrary("Base");
                        Tool next = (base == null) ? null : base.getTool("Edit Tool");
                        if (next != null) {
                            proj.setTool(next);
                            Action act = SelectionActions.dropAll(canvas.getSelection());
                            if (act != null) {
                                proj.doAction(act);
                            }
                        }
                        break;
                    case KeyEvent.VK_BACK_SPACE:
                        if (lastAddition != null && canvas.getProject().getLastAction() == lastAddition) {
                            canvas.getProject().undoAction();
                            lastAddition = null;
                        }
                }
    }
}
Also used : Project(com.cburch.logisim.proj.Project) Action(com.cburch.logisim.proj.Action) ToolAttributeAction(com.cburch.logisim.gui.main.ToolAttributeAction) Direction(com.cburch.logisim.data.Direction)

Example 4 with Direction

use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.

the class EditTool method attemptReface.

private void attemptReface(Canvas canvas, final Direction facing, KeyEvent e) {
    if (e.getModifiersEx() == 0) {
        final Circuit circuit = canvas.getCircuit();
        final Selection sel = canvas.getSelection();
        SetAttributeAction act = new SetAttributeAction(circuit, Strings.getter("selectionRefaceAction"));
        for (Component comp : sel.getComponents()) {
            if (!(comp instanceof Wire)) {
                Attribute<Direction> attr = getFacingAttribute(comp);
                if (attr != null) {
                    act.set(comp, attr, facing);
                }
            }
        }
        if (!act.isEmpty()) {
            canvas.getProject().doAction(act);
            e.consume();
        }
    }
}
Also used : Selection(com.cburch.logisim.gui.main.Selection) Circuit(com.cburch.logisim.circuit.Circuit) Component(com.cburch.logisim.comp.Component) Wire(com.cburch.logisim.circuit.Wire) Direction(com.cburch.logisim.data.Direction)

Example 5 with Direction

use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.

the class PullResistor method paintBase.

private void paintBase(InstancePainter painter, Value pullValue, Color inColor, Color outColor) {
    boolean color = painter.shouldDrawColor();
    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    Graphics g = painter.getGraphics();
    Color baseColor = g.getColor();
    GraphicsUtil.switchToWidth(g, 3);
    if (color && inColor != null)
        g.setColor(inColor);
    if (facing == Direction.EAST) {
        GraphicsUtil.drawText(g, pullValue.toDisplayString(), -32, 0, GraphicsUtil.H_RIGHT, GraphicsUtil.V_CENTER);
    } else if (facing == Direction.WEST) {
        GraphicsUtil.drawText(g, pullValue.toDisplayString(), 32, 0, GraphicsUtil.H_LEFT, GraphicsUtil.V_CENTER);
    } else if (facing == Direction.NORTH) {
        GraphicsUtil.drawText(g, pullValue.toDisplayString(), 0, 32, GraphicsUtil.H_CENTER, GraphicsUtil.V_TOP);
    } else {
        GraphicsUtil.drawText(g, pullValue.toDisplayString(), 0, -32, GraphicsUtil.H_CENTER, GraphicsUtil.V_BASELINE);
    }
    double rotate = 0.0;
    if (g instanceof Graphics2D) {
        rotate = Direction.SOUTH.toRadians() - facing.toRadians();
        if (rotate != 0.0)
            ((Graphics2D) g).rotate(rotate);
    }
    g.drawLine(0, -30, 0, -26);
    g.drawLine(-6, -30, 6, -30);
    if (color && outColor != null)
        g.setColor(outColor);
    g.drawLine(0, -4, 0, 0);
    g.setColor(baseColor);
    GraphicsUtil.switchToWidth(g, 2);
    if (painter.getGateShape() == AppPreferences.SHAPE_SHAPED) {
        int[] xp = { 0, -5, 5, -5, 5, -5, 0 };
        int[] yp = { -25, -23, -19, -15, -11, -7, -5 };
        g.drawPolyline(xp, yp, xp.length);
    } else {
        g.drawRect(-5, -25, 10, 20);
    }
    if (rotate != 0.0) {
        ((Graphics2D) g).rotate(-rotate);
    }
}
Also used : Graphics(java.awt.Graphics) Color(java.awt.Color) Direction(com.cburch.logisim.data.Direction) Graphics2D(java.awt.Graphics2D)

Aggregations

Direction (com.cburch.logisim.data.Direction)89 Location (com.cburch.logisim.data.Location)39 Bounds (com.cburch.logisim.data.Bounds)27 BitWidth (com.cburch.logisim.data.BitWidth)20 Graphics (java.awt.Graphics)20 Graphics2D (java.awt.Graphics2D)13 Port (com.cburch.logisim.instance.Port)10 Instance (com.cburch.logisim.instance.Instance)9 ArrayList (java.util.ArrayList)7 CanvasObject (com.cburch.draw.model.CanvasObject)5 Color (java.awt.Color)5 Font (java.awt.Font)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 AttributeSet (com.cburch.logisim.data.AttributeSet)4 FontMetrics (java.awt.FontMetrics)4 List (java.util.List)4 Wire (com.cburch.logisim.circuit.Wire)3 Attribute (com.cburch.logisim.data.Attribute)3 Value (com.cburch.logisim.data.Value)3