use of com.cburch.logisim.data.AttributeSet in project logisim-evolution by reds-heig.
the class XmlWriter method fromLibrary.
Element fromLibrary(Library lib) {
Element ret = doc.createElement("lib");
if (libs.containsKey(lib))
return null;
String name = "" + libs.size();
String desc = loader.getDescriptor(lib);
if (desc == null) {
loader.showError("library location unknown: " + lib.getName());
return null;
}
libs.put(lib, name);
ret.setAttribute("name", name);
ret.setAttribute("desc", desc);
for (Tool t : lib.getTools()) {
AttributeSet attrs = t.getAttributeSet();
if (attrs != null) {
Element toAdd = doc.createElement("tool");
toAdd.setAttribute("name", t.getName());
addAttributeSetContent(toAdd, attrs, t);
if (toAdd.getChildNodes().getLength() > 0) {
ret.appendChild(toAdd);
}
}
}
return ret;
}
use of com.cburch.logisim.data.AttributeSet in project logisim-evolution by reds-heig.
the class XmlCircuitReader method getComponent.
/**
* Get a circuit's component from a read XML file. If the component has a
* non-null "trackercomp" field, it means that it is tracked, therefore it
* is skipped in the non-tracked version to avoid errors.
*
* @param elt
* XML element to parse
* @param reader
* XML file reader
* @return the component built from its XML description
* @throws XmlReaderException
*/
static Component getComponent(Element elt, XmlReader.ReadContext reader) throws XmlReaderException {
if (elt.getAttribute("trackercomp") != "" && !Main.VERSION.hasTracker()) {
return (null);
}
// Determine the factory that creates this element
String name = elt.getAttribute("name");
if (name == null || name.equals("")) {
throw new XmlReaderException(Strings.get("compNameMissingError"));
}
String libName = elt.getAttribute("lib");
Library lib = reader.findLibrary(libName);
if (lib == null) {
throw new XmlReaderException(Strings.get("compUnknownError", "no-lib"));
}
Tool tool = lib.getTool(name);
if (tool == null || !(tool instanceof AddTool)) {
if (libName == null || libName.equals("")) {
throw new XmlReaderException(Strings.get("compUnknownError", name));
} else {
throw new XmlReaderException(Strings.get("compAbsentError", name, libName));
}
}
ComponentFactory source = ((AddTool) tool).getFactory();
// Determine attributes
String loc_str = elt.getAttribute("loc");
AttributeSet attrs = source.createAttributeSet();
reader.initAttributeSet(elt, attrs, source);
// Create component if location known
if (loc_str == null || loc_str.equals("")) {
throw new XmlReaderException(Strings.get("compLocMissingError", source.getName()));
} else {
try {
Location loc = Location.parse(loc_str);
return source.createComponent(loc, attrs);
} catch (NumberFormatException e) {
throw new XmlReaderException(Strings.get("compLocInvalidError", source.getName(), loc_str));
}
}
}
use of com.cburch.logisim.data.AttributeSet in project logisim-evolution by reds-heig.
the class PokeTool method mousePressed.
@Override
public void mousePressed(Canvas canvas, Graphics g, MouseEvent e) {
int x = e.getX();
int y = e.getY();
Location loc = Location.create(x, y);
boolean dirty = false;
canvas.setHighlightedWires(WireSet.EMPTY);
if (pokeCaret != null && !pokeCaret.getBounds(g).contains(loc)) {
dirty = true;
removeCaret(true);
}
if (pokeCaret == null) {
ComponentUserEvent event = new ComponentUserEvent(canvas, x, y);
Circuit circ = canvas.getCircuit();
for (Component c : circ.getAllContaining(loc, g)) {
if (pokeCaret != null)
break;
if (c instanceof Wire) {
Caret caret = new WireCaret(canvas, (Wire) c, x, y, canvas.getProject().getOptions().getAttributeSet());
setPokedComponent(circ, c, caret);
canvas.setHighlightedWires(circ.getWireSet((Wire) c));
} else {
Pokable p = (Pokable) c.getFeature(Pokable.class);
if (p != null) {
Caret caret = p.getPokeCaret(event);
setPokedComponent(circ, c, caret);
AttributeSet attrs = c.getAttributeSet();
if (attrs != null && attrs.getAttributes().size() > 0) {
Project proj = canvas.getProject();
proj.getFrame().viewComponentAttributes(circ, c);
}
}
}
}
}
if (pokeCaret != null) {
dirty = true;
pokeCaret.mousePressed(e);
}
if (dirty)
canvas.getProject().repaintCanvas();
}
use of com.cburch.logisim.data.AttributeSet in project logisim-evolution by reds-heig.
the class SelectTool method processKeyEvent.
private void processKeyEvent(Canvas canvas, KeyEvent e, int type) {
HashMap<Component, KeyConfigurator> handlers = keyHandlers;
if (handlers == null) {
handlers = new HashMap<Component, KeyConfigurator>();
Selection sel = canvas.getSelection();
for (Component comp : sel.getComponents()) {
ComponentFactory factory = comp.getFactory();
AttributeSet attrs = comp.getAttributeSet();
Object handler = factory.getFeature(KeyConfigurator.class, attrs);
if (handler != null) {
KeyConfigurator base = (KeyConfigurator) handler;
handlers.put(comp, base.clone());
}
}
keyHandlers = handlers;
}
if (!handlers.isEmpty()) {
boolean consume = false;
ArrayList<KeyConfigurationResult> results;
results = new ArrayList<KeyConfigurationResult>();
for (Map.Entry<Component, KeyConfigurator> entry : handlers.entrySet()) {
Component comp = entry.getKey();
KeyConfigurator handler = entry.getValue();
KeyConfigurationEvent event = new KeyConfigurationEvent(type, comp.getAttributeSet(), e, comp);
KeyConfigurationResult result = handler.keyEventReceived(event);
consume |= event.isConsumed();
if (result != null) {
results.add(result);
}
}
if (consume) {
e.consume();
}
if (!results.isEmpty()) {
SetAttributeAction act = new SetAttributeAction(canvas.getCircuit(), Strings.getter("changeComponentAttributesAction"));
for (KeyConfigurationResult result : results) {
Component comp = (Component) result.getEvent().getData();
Map<Attribute<?>, Object> newValues = result.getAttributeValues();
for (Map.Entry<Attribute<?>, Object> entry : newValues.entrySet()) {
act.set(comp, entry.getKey(), entry.getValue());
}
}
if (!act.isEmpty()) {
canvas.getProject().doAction(act);
}
}
}
}
use of com.cburch.logisim.data.AttributeSet in project logisim-evolution by reds-heig.
the class SetAttributeAction method doIt.
@Override
public void doIt(Project proj) {
CircuitMutation xn = new CircuitMutation(circuit);
int len = values.size();
oldValues.clear();
for (int i = 0; i < len; i++) {
Component comp = comps.get(i);
Attribute<Object> attr = attrs.get(i);
Object value = values.get(i);
if (circuit.contains(comp)) {
oldValues.add(null);
xn.set(comp, attr, value);
} else {
AttributeSet compAttrs = comp.getAttributeSet();
oldValues.add(compAttrs.getValue(attr));
compAttrs.setValue(attr, value);
}
}
if (!xn.isEmpty()) {
CircuitTransactionResult result = xn.execute();
xnReverse = result.getReverseTransaction();
}
}
Aggregations