Search in sources :

Example 46 with Circuit

use of com.cburch.logisim.circuit.Circuit in project logisim-evolution by reds-heig.

the class ExportImage method doExport.

static void doExport(Project proj) {
    // First display circuit/parameter selection dialog
    Frame frame = proj.getFrame();
    CircuitJList list = new CircuitJList(proj, true);
    if (list.getModel().getSize() == 0) {
        JOptionPane.showMessageDialog(proj.getFrame(), Strings.get("exportEmptyCircuitsMessage"), Strings.get("exportEmptyCircuitsTitle"), JOptionPane.YES_NO_OPTION);
        return;
    }
    OptionsPanel options = new OptionsPanel(list);
    int action = JOptionPane.showConfirmDialog(frame, options, Strings.get("exportImageSelect"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
    if (action != JOptionPane.OK_OPTION)
        return;
    List<Circuit> circuits = list.getSelectedCircuits();
    double scale = options.getScale();
    boolean printerView = options.getPrinterView();
    if (circuits.isEmpty())
        return;
    ImageFileFilter filter;
    int fmt = options.getImageFormat();
    switch(options.getImageFormat()) {
        case FORMAT_GIF:
            filter = new ImageFileFilter(fmt, Strings.getter("exportGifFilter"), new String[] { "gif" });
            break;
        case FORMAT_PNG:
            filter = new ImageFileFilter(fmt, Strings.getter("exportPngFilter"), new String[] { "png" });
            break;
        case FORMAT_JPG:
            filter = new ImageFileFilter(fmt, Strings.getter("exportJpgFilter"), new String[] { "jpg", "jpeg", "jpe", "jfi", "jfif", "jfi" });
            break;
        default:
            logger.error("Unexpected image format; aborted!");
            return;
    }
    // Then display file chooser
    Loader loader = proj.getLogisimFile().getLoader();
    JFileChooser chooser = loader.createChooser();
    if (circuits.size() > 1) {
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setDialogTitle(Strings.get("exportImageDirectorySelect"));
    } else {
        chooser.setFileFilter(filter);
        chooser.setDialogTitle(Strings.get("exportImageFileSelect"));
    }
    int returnVal = chooser.showDialog(frame, Strings.get("exportImageButton"));
    if (returnVal != JFileChooser.APPROVE_OPTION)
        return;
    // Determine whether destination is valid
    File dest = chooser.getSelectedFile();
    chooser.setCurrentDirectory(dest.isDirectory() ? dest : dest.getParentFile());
    if (dest.exists()) {
        if (!dest.isDirectory()) {
            int confirm = JOptionPane.showConfirmDialog(proj.getFrame(), Strings.get("confirmOverwriteMessage"), Strings.get("confirmOverwriteTitle"), JOptionPane.YES_NO_OPTION);
            if (confirm != JOptionPane.YES_OPTION)
                return;
        }
    } else {
        if (circuits.size() > 1) {
            boolean created = dest.mkdir();
            if (!created) {
                JOptionPane.showMessageDialog(proj.getFrame(), Strings.get("exportNewDirectoryErrorMessage"), Strings.get("exportNewDirectoryErrorTitle"), JOptionPane.YES_NO_OPTION);
                return;
            }
        }
    }
    // Create the progress monitor
    ProgressMonitor monitor = new ProgressMonitor(frame, Strings.get("exportImageProgress"), null, 0, 10000);
    monitor.setMillisToDecideToPopup(100);
    monitor.setMillisToPopup(200);
    monitor.setProgress(0);
    // And start a thread to actually perform the operation
    // (This is run in a thread so that Swing will update the
    // monitor.)
    new ExportThread(frame, frame.getCanvas(), dest, filter, circuits, scale, printerView, monitor).start();
}
Also used : Loader(com.cburch.logisim.file.Loader) Circuit(com.cburch.logisim.circuit.Circuit) ProgressMonitor(javax.swing.ProgressMonitor) JFileChooser(javax.swing.JFileChooser) File(java.io.File)

Example 47 with Circuit

use of com.cburch.logisim.circuit.Circuit in project logisim-evolution by reds-heig.

the class Frame method viewAttributes.

private void viewAttributes(Tool oldTool, Tool newTool, boolean force) {
    AttributeSet newAttrs;
    if (newTool == null) {
        newAttrs = null;
        if (!force) {
            return;
        }
    } else {
        newAttrs = newTool.getAttributeSet(layoutCanvas);
    }
    if (newAttrs == null) {
        AttrTableModel oldModel = attrTable.getAttrTableModel();
        boolean same = oldModel instanceof AttrTableToolModel && ((AttrTableToolModel) oldModel).getTool() == oldTool;
        if (!force && !same && !(oldModel instanceof AttrTableCircuitModel)) {
            return;
        }
    }
    if (newAttrs == null) {
        Circuit circ = proj.getCurrentCircuit();
        if (circ != null) {
            setAttrTableModel(new AttrTableCircuitModel(proj, circ));
        } else if (force) {
            setAttrTableModel(null);
        }
    } else if (newAttrs instanceof SelectionAttributes) {
        setAttrTableModel(attrTableSelectionModel);
    } else {
        setAttrTableModel(new AttrTableToolModel(proj, newTool));
    }
}
Also used : AttributeSet(com.cburch.logisim.data.AttributeSet) AttrTableModel(com.cburch.logisim.gui.generic.AttrTableModel) Circuit(com.cburch.logisim.circuit.Circuit)

Example 48 with Circuit

use of com.cburch.logisim.circuit.Circuit in project logisim-evolution by reds-heig.

the class XmlCircuitReader method buildCircuit.

private void buildCircuit(XmlReader.CircuitData circData, CircuitMutator mutator) {
    Element elt = circData.circuitElement;
    Circuit dest = circData.circuit;
    Map<Element, Component> knownComponents = circData.knownComponents;
    if (knownComponents == null)
        knownComponents = Collections.emptyMap();
    try {
        /* Here we check the attribute circuitnamedbox for backwards compatibility */
        boolean HasNamedBox = false;
        for (Element attrElt : XmlIterator.forChildElements(circData.circuitElement, "a")) {
            if (attrElt.hasAttribute("name")) {
                String Name = attrElt.getAttribute("name");
                if (Name.equals("circuitnamedbox")) {
                    HasNamedBox = true;
                }
            }
        }
        reader.initAttributeSet(circData.circuitElement, dest.getStaticAttributes(), null);
        if ((!HasNamedBox) && circData.circuitElement.hasChildNodes()) {
            dest.getStaticAttributes().setValue(CircuitAttributes.NAMED_CIRCUIT_BOX, false);
        }
    } catch (XmlReaderException e) {
        reader.addErrors(e, circData.circuit.getName() + ".static");
    }
    for (Element sub_elt : XmlIterator.forChildElements(elt)) {
        String sub_elt_name = sub_elt.getTagName();
        if (sub_elt_name.equals("comp")) {
            try {
                Component comp = knownComponents.get(sub_elt);
                if (comp == null) {
                    comp = getComponent(sub_elt, reader);
                }
                if (comp != null) {
                    mutator.add(dest, comp);
                }
            } catch (XmlReaderException e) {
                reader.addErrors(e, circData.circuit.getName() + "." + toComponentString(sub_elt));
            }
        } else if (sub_elt_name.equals("wire")) {
            try {
                addWire(dest, mutator, sub_elt);
            } catch (XmlReaderException e) {
                reader.addErrors(e, circData.circuit.getName() + "." + toWireString(sub_elt));
            }
        }
    }
    List<AbstractCanvasObject> appearance = circData.appearance;
    if (appearance != null && !appearance.isEmpty()) {
        dest.getAppearance().setObjectsForce(appearance);
        dest.getAppearance().setDefaultAppearance(false);
    }
}
Also used : Element(org.w3c.dom.Element) AbstractCanvasObject(com.cburch.draw.model.AbstractCanvasObject) Circuit(com.cburch.logisim.circuit.Circuit) Component(com.cburch.logisim.comp.Component)

Example 49 with Circuit

use of com.cburch.logisim.circuit.Circuit in project logisim-evolution by reds-heig.

the class XmlReader method readLibrary.

LogisimFile readLibrary(InputStream is, Project proj) throws IOException, SAXException {
    Document doc = loadXmlFrom(is);
    Element elt = doc.getDocumentElement();
    elt = ensureLogisimCompatibility(elt);
    considerRepairs(doc, elt);
    LogisimFile file = new LogisimFile((Loader) loader);
    ReadContext context = new ReadContext(file);
    context.toLogisimFile(elt, proj);
    if (file.getCircuitCount() == 0) {
        file.addCircuit(new Circuit("main", file, proj));
    }
    if (context.messages.size() > 0) {
        StringBuilder all = new StringBuilder();
        for (String msg : context.messages) {
            all.append(msg);
            all.append("\n");
        }
        loader.showError(all.substring(0, all.length() - 1));
    }
    return file;
}
Also used : Element(org.w3c.dom.Element) Circuit(com.cburch.logisim.circuit.Circuit) Document(org.w3c.dom.Document)

Example 50 with Circuit

use of com.cburch.logisim.circuit.Circuit in project logisim-evolution by reds-heig.

the class SelectionItem method circuitChanged.

public void circuitChanged(CircuitEvent event) {
    int action = event.getAction();
    if (action == CircuitEvent.ACTION_CLEAR || action == CircuitEvent.ACTION_REMOVE) {
        Circuit circ = event.getCircuit();
        Component circComp = null;
        if (circ == model.getCircuitState().getCircuit()) {
            circComp = path != null && path.length > 0 ? path[0] : comp;
        } else if (path != null) {
            for (int i = 0; i < path.length; i++) {
                SubcircuitFactory circFact = (SubcircuitFactory) path[i].getFactory();
                if (circ == circFact.getSubcircuit()) {
                    circComp = i + 1 < path.length ? path[i + 1] : comp;
                }
            }
        }
        if (circComp == null)
            return;
        if (action == CircuitEvent.ACTION_REMOVE && event.getData() != circComp) {
            return;
        }
        int index = model.getSelection().indexOf(this);
        if (index < 0)
            return;
        model.getSelection().remove(index);
    }
}
Also used : SubcircuitFactory(com.cburch.logisim.circuit.SubcircuitFactory) Circuit(com.cburch.logisim.circuit.Circuit) Component(com.cburch.logisim.comp.Component)

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