Search in sources :

Example 11 with ComponentFactory

use of com.cburch.logisim.comp.ComponentFactory in project logisim-evolution by reds-heig.

the class LoadedLibrary method replaceAll.

private static void replaceAll(Circuit circuit, Map<ComponentFactory, ComponentFactory> compMap) {
    ArrayList<Component> toReplace = null;
    for (Component comp : circuit.getNonWires()) {
        if (compMap.containsKey(comp.getFactory())) {
            if (toReplace == null)
                toReplace = new ArrayList<Component>();
            toReplace.add(comp);
        }
    }
    if (toReplace != null) {
        CircuitMutation xn = new CircuitMutation(circuit);
        for (Component comp : toReplace) {
            xn.remove(comp);
            ComponentFactory factory = compMap.get(comp.getFactory());
            if (factory != null) {
                AttributeSet newAttrs = createAttributes(factory, comp.getAttributeSet());
                xn.add(factory.createComponent(comp.getLocation(), newAttrs));
            }
        }
        xn.execute();
    }
}
Also used : AttributeSet(com.cburch.logisim.data.AttributeSet) ComponentFactory(com.cburch.logisim.comp.ComponentFactory) ArrayList(java.util.ArrayList) CircuitMutation(com.cburch.logisim.circuit.CircuitMutation) Component(com.cburch.logisim.comp.Component)

Example 12 with ComponentFactory

use of com.cburch.logisim.comp.ComponentFactory in project logisim-evolution by reds-heig.

the class LogisimFile method getUnloadLibraryMessage.

public String getUnloadLibraryMessage(Library lib) {
    HashSet<ComponentFactory> factories = new HashSet<ComponentFactory>();
    for (Tool tool : lib.getTools()) {
        if (tool instanceof AddTool) {
            factories.add(((AddTool) tool).getFactory());
        }
    }
    for (Circuit circuit : getCircuits()) {
        for (Component comp : circuit.getNonWires()) {
            if (factories.contains(comp.getFactory())) {
                return StringUtil.format(Strings.get("unloadUsedError"), circuit.getName());
            }
        }
    }
    ToolbarData tb = options.getToolbarData();
    MouseMappings mm = options.getMouseMappings();
    for (Tool t : lib.getTools()) {
        if (tb.usesToolFromSource(t)) {
            return Strings.get("unloadToolbarError");
        }
        if (mm.usesToolFromSource(t)) {
            return Strings.get("unloadMappingError");
        }
    }
    return null;
}
Also used : ComponentFactory(com.cburch.logisim.comp.ComponentFactory) Circuit(com.cburch.logisim.circuit.Circuit) AddTool(com.cburch.logisim.tools.AddTool) Component(com.cburch.logisim.comp.Component) HashSet(java.util.HashSet) Tool(com.cburch.logisim.tools.Tool) AddTool(com.cburch.logisim.tools.AddTool)

Example 13 with ComponentFactory

use of com.cburch.logisim.comp.ComponentFactory in project logisim-evolution by reds-heig.

the class Circuit method mutatorRemove.

void mutatorRemove(Component c) {
    // logger.debug("mutatorRemove: {}", c);
    locker.checkForWritePermission("remove");
    Annotated = false;
    MyNetList.clear();
    if (c instanceof Wire) {
        wires.remove(c);
    } else {
        wires.remove(c);
        comps.remove(c);
        ComponentFactory factory = c.getFactory();
        if (factory instanceof Clock) {
            clocks.remove(c);
        } else if (factory instanceof SubcircuitFactory) {
            SubcircuitFactory subcirc = (SubcircuitFactory) factory;
            subcirc.getSubcircuit().circuitsUsingThis.remove(c);
        }
        c.removeComponentListener(myComponentListener);
    }
    fireEvent(CircuitEvent.ACTION_REMOVE, c);
}
Also used : ComponentFactory(com.cburch.logisim.comp.ComponentFactory) Clock(com.cburch.logisim.std.wiring.Clock)

Example 14 with ComponentFactory

use of com.cburch.logisim.comp.ComponentFactory in project logisim-evolution by reds-heig.

the class ToolboxManip method doubleClicked.

public void doubleClicked(ProjectExplorerEvent event) {
    Object clicked = event.getTarget();
    if (clicked instanceof ProjectExplorerToolNode) {
        Tool baseTool = ((ProjectExplorerToolNode) clicked).getValue();
        if (baseTool instanceof AddTool) {
            AddTool tool = (AddTool) baseTool;
            ComponentFactory source = tool.getFactory();
            if (source instanceof SubcircuitFactory) {
                SubcircuitFactory circFact = (SubcircuitFactory) source;
                proj.setCurrentCircuit(circFact.getSubcircuit());
                proj.getFrame().setEditorView(Frame.EDIT_LAYOUT);
                if (lastSelected != null) {
                    proj.setTool(lastSelected);
                } else {
                    Library base = proj.getLogisimFile().getLibrary("Base");
                    if (base != null)
                        proj.setTool(base.getTool("Edit Tool"));
                }
            }
        }
    }
}
Also used : ProjectExplorerToolNode(com.cburch.logisim.gui.generic.ProjectExplorerToolNode) ComponentFactory(com.cburch.logisim.comp.ComponentFactory) SubcircuitFactory(com.cburch.logisim.circuit.SubcircuitFactory) AddTool(com.cburch.logisim.tools.AddTool) Library(com.cburch.logisim.tools.Library) Tool(com.cburch.logisim.tools.Tool) AddTool(com.cburch.logisim.tools.AddTool)

Example 15 with ComponentFactory

use of com.cburch.logisim.comp.ComponentFactory in project logisim-evolution by reds-heig.

the class SimulationTreeRenderer method getTreeCellRendererComponent.

@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    Component ret = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
    SimulationTreeModel model = (SimulationTreeModel) tree.getModel();
    if (ret instanceof JLabel) {
        JLabel label = (JLabel) ret;
        if (value instanceof SimulationTreeNode) {
            SimulationTreeNode node = (SimulationTreeNode) value;
            ComponentFactory factory = node.getComponentFactory();
            if (factory != null) {
                label.setIcon(new RendererIcon(factory, node.isCurrentView(model)));
            }
        }
    }
    return ret;
}
Also used : ComponentFactory(com.cburch.logisim.comp.ComponentFactory) JLabel(javax.swing.JLabel) Component(java.awt.Component)

Aggregations

ComponentFactory (com.cburch.logisim.comp.ComponentFactory)37 AttributeSet (com.cburch.logisim.data.AttributeSet)16 AddTool (com.cburch.logisim.tools.AddTool)9 Tool (com.cburch.logisim.tools.Tool)9 Circuit (com.cburch.logisim.circuit.Circuit)8 SubcircuitFactory (com.cburch.logisim.circuit.SubcircuitFactory)8 Component (com.cburch.logisim.comp.Component)8 Library (com.cburch.logisim.tools.Library)8 ArrayList (java.util.ArrayList)6 Wire (com.cburch.logisim.circuit.Wire)4 Location (com.cburch.logisim.data.Location)4 ProjectExplorerToolNode (com.cburch.logisim.gui.generic.ProjectExplorerToolNode)4 HashSet (java.util.HashSet)4 Attribute (com.cburch.logisim.data.Attribute)3 Bounds (com.cburch.logisim.data.Bounds)3 ToolAttributeAction (com.cburch.logisim.gui.main.ToolAttributeAction)3 Action (com.cburch.logisim.proj.Action)3 HashMap (java.util.HashMap)3 CircuitMutation (com.cburch.logisim.circuit.CircuitMutation)2 Direction (com.cburch.logisim.data.Direction)2