Search in sources :

Example 6 with Circuit

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);
    }
}
Also used : PageFormat(java.awt.print.PageFormat) Circuit(com.cburch.logisim.circuit.Circuit) Printable(java.awt.print.Printable) PrinterException(java.awt.print.PrinterException) PrinterJob(java.awt.print.PrinterJob)

Example 7 with Circuit

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;
    }
}
Also used : Circuit(com.cburch.logisim.circuit.Circuit)

Example 8 with Circuit

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;
    }
}
Also used : Project(com.cburch.logisim.proj.Project) Circuit(com.cburch.logisim.circuit.Circuit)

Example 9 with Circuit

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;
}
Also used : Element(org.w3c.dom.Element) Circuit(com.cburch.logisim.circuit.Circuit) Library(com.cburch.logisim.tools.Library)

Example 10 with Circuit

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));
}
Also used : ReorderRequest(com.cburch.draw.model.ReorderRequest) CanvasObject(com.cburch.draw.model.CanvasObject) ModelReorderAction(com.cburch.draw.actions.ModelReorderAction) ModelAddAction(com.cburch.draw.actions.ModelAddAction) ArrayList(java.util.ArrayList) Circuit(com.cburch.logisim.circuit.Circuit) AppearanceElement(com.cburch.logisim.circuit.appear.AppearanceElement)

Aggregations

Circuit (com.cburch.logisim.circuit.Circuit)62 Component (com.cburch.logisim.comp.Component)19 SubcircuitFactory (com.cburch.logisim.circuit.SubcircuitFactory)12 Project (com.cburch.logisim.proj.Project)11 ArrayList (java.util.ArrayList)9 Wire (com.cburch.logisim.circuit.Wire)8 ComponentFactory (com.cburch.logisim.comp.ComponentFactory)8 Location (com.cburch.logisim.data.Location)8 Bounds (com.cburch.logisim.data.Bounds)6 LogisimFile (com.cburch.logisim.file.LogisimFile)6 AddTool (com.cburch.logisim.tools.AddTool)6 Tool (com.cburch.logisim.tools.Tool)6 CircuitState (com.cburch.logisim.circuit.CircuitState)5 AttributeSet (com.cburch.logisim.data.AttributeSet)5 Selection (com.cburch.logisim.gui.main.Selection)5 Action (com.cburch.logisim.proj.Action)4 CircuitMutation (com.cburch.logisim.circuit.CircuitMutation)3 ComponentDrawContext (com.cburch.logisim.comp.ComponentDrawContext)3 Graphics (java.awt.Graphics)3 CanvasObject (com.cburch.draw.model.CanvasObject)2