use of com.cburch.logisim.comp.Component in project logisim-evolution by reds-heig.
the class XmlWriter method fromCircuit.
Element fromCircuit(Circuit circuit) {
Element ret = doc.createElement("circuit");
ret.setAttribute("name", circuit.getName());
addAttributeSetContent(ret, circuit.getStaticAttributes(), null);
if (!circuit.getAppearance().isDefaultAppearance()) {
Element appear = doc.createElement("appear");
for (Object o : circuit.getAppearance().getObjectsFromBottom()) {
if (o instanceof AbstractCanvasObject) {
Element elt = ((AbstractCanvasObject) o).toSvgElement(doc);
if (elt != null) {
appear.appendChild(elt);
}
}
}
ret.appendChild(appear);
}
for (Wire w : circuit.getWires()) {
ret.appendChild(fromWire(w));
}
for (Component comp : circuit.getNonWires()) {
Element elt = fromComponent(comp);
if (elt != null)
ret.appendChild(elt);
}
return ret;
}
use of com.cburch.logisim.comp.Component in project logisim-evolution by reds-heig.
the class AttrTableSelectionModel method setValueRequested.
@Override
public void setValueRequested(Attribute<Object> attr, Object value) throws AttrTableSetException {
Selection selection = frame.getCanvas().getSelection();
Circuit circuit = frame.getCanvas().getCircuit();
if (selection.isEmpty() && circuit != null) {
AttrTableCircuitModel circuitModel = new AttrTableCircuitModel(project, circuit);
circuitModel.setValueRequested(attr, value);
} else {
SetAttributeAction act = new SetAttributeAction(circuit, Strings.getter("selectionAttributeAction"));
AutoLabel labler = null;
if (attr.equals(StdAttr.LABEL)) {
labler = new AutoLabel((String) value, circuit);
}
SortedSet<Component> comps = new TreeSet<Component>(new PositionComparator());
comps.addAll(selection.getComponents());
for (Component comp : comps) {
if (!(comp instanceof Wire)) {
if (comp.getFactory() instanceof SubcircuitFactory) {
SubcircuitFactory fac = (SubcircuitFactory) comp.getFactory();
if (attr.equals(CircuitAttributes.NAMED_CIRCUIT_BOX) || attr.equals(CircuitAttributes.NAME_ATTR)) {
try {
CircuitMutation mutation = new CircuitMutation(fac.getSubcircuit());
mutation.setForCircuit(attr, value);
Action action = mutation.toAction(null);
project.doAction(action);
} catch (CircuitException ex) {
JOptionPane.showMessageDialog(project.getFrame(), ex.getMessage());
}
return;
}
}
if (attr.equals(StdAttr.LABEL)) {
if (labler.hasNext(circuit)) {
if (comps.size() > 1) {
act.set(comp, attr, labler.GetNext(circuit, comp.getFactory()));
} else {
if (getAttributeSet().getValue(StdAttr.LABEL).equals((String) value))
return;
else
act.set(comp, attr, labler.GetCurrent(circuit, comp.getFactory()));
}
} else
act.set(comp, attr, "");
} else
act.set(comp, attr, value);
}
}
project.doAction(act);
}
}
use of com.cburch.logisim.comp.Component in project logisim-evolution by reds-heig.
the class AttrTableSelectionModel method getTitle.
@Override
public String getTitle() {
ComponentFactory wireFactory = null;
ComponentFactory factory = null;
int factoryCount = 0;
int totalCount = 0;
boolean variousFound = false;
Selection selection = frame.getCanvas().getSelection();
for (Component comp : selection.getComponents()) {
ComponentFactory fact = comp.getFactory();
if (fact.equals(factory)) {
factoryCount++;
} else if (comp instanceof Wire) {
wireFactory = fact;
if (factory == null) {
factoryCount++;
}
} else if (factory == null) {
factory = fact;
factoryCount = 1;
} else {
variousFound = true;
}
if (!(comp instanceof Wire)) {
totalCount++;
}
}
if (factory == null) {
factory = wireFactory;
}
if (variousFound) {
SetInstance(factory);
return Strings.get("selectionVarious", "" + totalCount);
} else if (factoryCount == 0) {
String circName = frame.getCanvas().getCircuit().getName();
SetInstance(frame.getCanvas().getCircuit().getSubcircuitFactory());
return Strings.get("circuitAttrTitle", circName);
} else if (factoryCount == 1) {
SetInstance(factory);
return Strings.get("selectionOne", factory.getDisplayName());
} else {
SetInstance(factory);
return Strings.get("selectionMultiple", factory.getDisplayName(), "" + factoryCount);
}
}
use of com.cburch.logisim.comp.Component in project logisim-evolution by reds-heig.
the class Canvas method getToolTipText.
@Override
public String getToolTipText(MouseEvent event) {
boolean showTips = AppPreferences.COMPONENT_TIPS.getBoolean();
if (showTips) {
Canvas.snapToGrid(event);
Location loc = Location.create(event.getX(), event.getY());
ComponentUserEvent e = null;
for (Component comp : getCircuit().getAllContaining(loc)) {
Object makerObj = comp.getFeature(ToolTipMaker.class);
if (makerObj != null && makerObj instanceof ToolTipMaker) {
ToolTipMaker maker = (ToolTipMaker) makerObj;
if (e == null) {
e = new ComponentUserEvent(this, loc.getX(), loc.getY());
}
String ret = maker.getToolTip(e);
if (ret != null) {
unrepairMouseEvent(event);
return ret;
}
}
}
}
return null;
}
use of com.cburch.logisim.comp.Component in project logisim-evolution by reds-heig.
the class RegTabContent method fillArray.
/**
* This function will clear and fill the registers tab and refresh their
* value. It will start by iterate over all circuits of the current project
* to register all the "Register" components (providing their attributes are
* correctly set). It will then fill the panel with each register found,
* including their current value.
*/
private void fillArray() {
int y = 0;
MyLabel col1 = new MyLabel("Circuit", Font.ITALIC | Font.BOLD);
MyLabel col2 = new MyLabel("Reg name", Font.BOLD);
MyLabel col3 = new MyLabel("Value", Font.BOLD);
registers.clear();
panel.removeAll();
for (Circuit circ : proj.getLogisimFile().getCircuits()) {
getAllRegisters(circ);
}
if (proj.getLogisimFile().getLibrary("prodis_v1.3") instanceof LoadedLibrary) {
if (((LoadedLibrary) proj.getLogisimFile().getLibrary("prodis_v1.3")).getBase() instanceof LogisimFile) {
for (Circuit circ : ((LogisimFile) ((LoadedLibrary) proj.getLogisimFile().getLibrary("prodis_v1.3")).getBase()).getCircuits()) {
getAllRegisters(circ);
}
}
}
col1.setColor(Color.LIGHT_GRAY);
col2.setColor(Color.LIGHT_GRAY);
col3.setColor(Color.LIGHT_GRAY);
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.FIRST_LINE_START;
c.ipady = 2;
c.weighty = 0;
c.gridy = y;
c.gridx = 0;
c.weightx = 0.3;
panel.add(col1, c);
c.gridx++;
c.weightx = 0.5;
panel.add(col2, c);
c.gridx++;
c.weightx = 0.2;
panel.add(col3, c);
y++;
if (!registers.isEmpty()) {
Object[] objArr = registers.keySet().toArray();
Arrays.sort(objArr);
for (Object name : objArr) {
c.gridy = y;
c.gridx = 0;
String circuitName = name.toString().split("/")[0];
panel.add(new MyLabel(circuitName, Font.ITALIC, true), c);
c.gridx++;
String registerName = name.toString().split("/")[1];
panel.add(new MyLabel(registerName), c);
c.gridx++;
Component selReg = registers.get(name.toString());
CircuitState mainCircState = proj.getCircuitState();
while (mainCircState.getParentState() != null) {
// Get the main
// circuit
mainCircState = mainCircState.getParentState();
}
Value val = findVal(mainCircState, circuitName, selReg.getEnd(0).getLocation());
if (val != null) {
panel.add(new MyLabel(val.toHexString()), c);
} else {
panel.add(new MyLabel("-"), c);
}
y++;
}
}
c.weighty = 1;
c.gridy++;
c.gridx = 0;
c.weightx = 1;
panel.add(new MyLabel(""), c);
panel.validate();
}
Aggregations