use of com.cburch.logisim.circuit.Circuit in project logisim-evolution by reds-heig.
the class Print method doPrint.
public static void doPrint(Project proj) {
CircuitJList list = new CircuitJList(proj, true);
Frame frame = proj.getFrame();
if (list.getModel().getSize() == 0) {
JOptionPane.showMessageDialog(proj.getFrame(), Strings.get("printEmptyCircuitsMessage"), Strings.get("printEmptyCircuitsTitle"), JOptionPane.YES_NO_OPTION);
return;
}
ParmsPanel parmsPanel = new ParmsPanel(list);
int action = JOptionPane.showConfirmDialog(frame, parmsPanel, Strings.get("printParmsTitle"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
if (action != JOptionPane.OK_OPTION)
return;
List<Circuit> circuits = list.getSelectedCircuits();
if (circuits.isEmpty())
return;
PageFormat format = new PageFormat();
Printable print = new MyPrintable(proj, circuits, parmsPanel.getHeader(), parmsPanel.getRotateToFit(), parmsPanel.getPrinterView());
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(print, format);
if (job.printDialog() == false)
return;
try {
job.print();
} catch (PrinterException e) {
JOptionPane.showMessageDialog(proj.getFrame(), StringUtil.format(Strings.get("printError"), e.toString()), Strings.get("printErrorTitle"), JOptionPane.ERROR_MESSAGE);
}
}
use of com.cburch.logisim.circuit.Circuit in project logisim-evolution by reds-heig.
the class SelectionAttributes method getValue.
@Override
public <V> V getValue(Attribute<V> attr) {
Circuit circ = canvas.getCircuit();
if (selected.isEmpty() && circ != null) {
return circ.getStaticAttributes().getValue(attr);
} else {
int i = findIndex(attr);
Object[] vs = values;
@SuppressWarnings("unchecked") V ret = (V) (i >= 0 && i < vs.length ? vs[i] : null);
return ret;
}
}
use of com.cburch.logisim.circuit.Circuit in project logisim-evolution by reds-heig.
the class SelectionAttributes method isReadOnly.
@Override
public boolean isReadOnly(Attribute<?> attr) {
Project proj = canvas.getProject();
Circuit circ = canvas.getCircuit();
if (!proj.getLogisimFile().contains(circ)) {
return true;
} else if (selected.isEmpty() && circ != null) {
return circ.getStaticAttributes().isReadOnly(attr);
} else {
int i = findIndex(attr);
boolean[] ro = readOnly;
return i >= 0 && i < ro.length ? ro[i] : true;
}
}
use of com.cburch.logisim.circuit.Circuit in project logisim-evolution by reds-heig.
the class XmlWriter method fromLogisimFile.
Element fromLogisimFile() {
Element ret = doc.createElement("project");
doc.appendChild(ret);
ret.appendChild(doc.createTextNode("\nThis file is intended to be " + "loaded by Logisim-evolution (https://github.com/reds-heig/logisim-evolution).\n"));
ret.setAttribute("version", "1.0");
ret.setAttribute("source", Main.VERSION_NAME);
for (Library lib : file.getLibraries()) {
Element elt = fromLibrary(lib);
if (elt != null)
ret.appendChild(elt);
}
if (file.getMainCircuit() != null) {
Element mainElt = doc.createElement("main");
mainElt.setAttribute("name", file.getMainCircuit().getName());
ret.appendChild(mainElt);
}
ret.appendChild(fromOptions());
ret.appendChild(fromMouseMappings());
ret.appendChild(fromToolbarData());
for (Circuit circ : file.getCircuits()) {
ret.appendChild(fromCircuit(circ));
}
return ret;
}
use of com.cburch.logisim.circuit.Circuit in project logisim-evolution by reds-heig.
the class AppearanceCanvas method doAction.
@Override
public void doAction(Action canvasAction) {
Circuit circuit = circuitState.getCircuit();
if (!proj.getLogisimFile().contains(circuit)) {
return;
}
if (canvasAction instanceof ModelReorderAction) {
int max = getMaxIndex(getModel());
ModelReorderAction reorder = (ModelReorderAction) canvasAction;
List<ReorderRequest> rs = reorder.getReorderRequests();
List<ReorderRequest> mod = new ArrayList<ReorderRequest>(rs.size());
boolean changed = false;
boolean movedToMax = false;
for (ReorderRequest r : rs) {
CanvasObject o = r.getObject();
if (o instanceof AppearanceElement) {
changed = true;
} else {
if (r.getToIndex() > max) {
int from = r.getFromIndex();
changed = true;
movedToMax = true;
if (from == max && !movedToMax) {
// this change is ineffective - don't add it
;
} else {
mod.add(new ReorderRequest(o, from, max));
}
} else {
if (r.getToIndex() == max)
movedToMax = true;
mod.add(r);
}
}
}
if (changed) {
if (mod.isEmpty()) {
return;
}
canvasAction = new ModelReorderAction(getModel(), mod);
}
}
if (canvasAction instanceof ModelAddAction) {
ModelAddAction addAction = (ModelAddAction) canvasAction;
int cur = addAction.getDestinationIndex();
int max = getMaxIndex(getModel());
if (cur > max) {
canvasAction = new ModelAddAction(getModel(), addAction.getObjects(), max + 1);
}
}
proj.doAction(new CanvasActionAdapter(circuit, canvasAction));
}
Aggregations