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();
}
}
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;
}
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);
}
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"));
}
}
}
}
}
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;
}
Aggregations