Search in sources :

Example 11 with Project

use of com.cburch.logisim.proj.Project in project logisim-evolution by reds-heig.

the class AddTool method keyPressed.

@Override
public void keyPressed(Canvas canvas, KeyEvent event) {
    processKeyEvent(canvas, event, KeyConfigurationEvent.KEY_PRESSED);
    if (!event.isConsumed() && event.getModifiersEx() == 0) {
        int KeybEvent = event.getKeyCode();
        String Component = getFactory().getDisplayName();
        if (!GateKeyboardModifier.TookKeyboardStrokes(KeybEvent, null, attrs, canvas, null, false))
            if (AutoLabler.LabelKeyboardHandler(KeybEvent, getAttributeSet(), Component, null, getFactory(), canvas.getCircuit(), null, false)) {
                canvas.repaint();
            } else
                switch(KeybEvent) {
                    case KeyEvent.VK_UP:
                        setFacing(canvas, Direction.NORTH);
                        break;
                    case KeyEvent.VK_DOWN:
                        setFacing(canvas, Direction.SOUTH);
                        break;
                    case KeyEvent.VK_LEFT:
                        setFacing(canvas, Direction.WEST);
                        break;
                    case KeyEvent.VK_RIGHT:
                        setFacing(canvas, Direction.EAST);
                        break;
                    case KeyEvent.VK_R:
                        Direction current = getFacing();
                        if (current == Direction.NORTH)
                            setFacing(canvas, Direction.EAST);
                        else if (current == Direction.EAST)
                            setFacing(canvas, Direction.SOUTH);
                        else if (current == Direction.SOUTH)
                            setFacing(canvas, Direction.WEST);
                        else
                            setFacing(canvas, Direction.NORTH);
                        break;
                    case KeyEvent.VK_ESCAPE:
                        Project proj = canvas.getProject();
                        Library base = proj.getLogisimFile().getLibrary("Base");
                        Tool next = (base == null) ? null : base.getTool("Edit Tool");
                        if (next != null) {
                            proj.setTool(next);
                            Action act = SelectionActions.dropAll(canvas.getSelection());
                            if (act != null) {
                                proj.doAction(act);
                            }
                        }
                        break;
                    case KeyEvent.VK_BACK_SPACE:
                        if (lastAddition != null && canvas.getProject().getLastAction() == lastAddition) {
                            canvas.getProject().undoAction();
                            lastAddition = null;
                        }
                }
    }
}
Also used : Project(com.cburch.logisim.proj.Project) Action(com.cburch.logisim.proj.Action) ToolAttributeAction(com.cburch.logisim.gui.main.ToolAttributeAction) Direction(com.cburch.logisim.data.Direction)

Example 12 with Project

use of com.cburch.logisim.proj.Project in project logisim-evolution by reds-heig.

the class SelectTool method mouseDragged.

@Override
public void mouseDragged(Canvas canvas, Graphics g, MouseEvent e) {
    if (state == MOVING) {
        Project proj = canvas.getProject();
        computeDxDy(proj, e, g);
        handleMoveDrag(canvas, curDx, curDy, e.getModifiersEx());
    } else if (state == RECT_SELECT) {
        Project proj = canvas.getProject();
        curDx = e.getX() - start.getX();
        curDy = e.getY() - start.getY();
        proj.repaintCanvas();
    }
}
Also used : Project(com.cburch.logisim.proj.Project)

Example 13 with Project

use of com.cburch.logisim.proj.Project in project logisim-evolution by reds-heig.

the class TextTool method mousePressed.

@Override
public void mousePressed(Canvas canvas, Graphics g, MouseEvent e) {
    Project proj = canvas.getProject();
    Circuit circ = canvas.getCircuit();
    if (!proj.getLogisimFile().contains(circ)) {
        if (caret != null)
            caret.cancelEditing();
        canvas.setErrorMessage(Strings.getter("cannotModifyError"));
        return;
    }
    // Maybe user is clicking within the current caret.
    if (caret != null) {
        if (caret.getBounds(g).contains(e.getX(), e.getY())) {
            // Yes
            caret.mousePressed(e);
            proj.repaintCanvas();
            return;
        } else {
            // No. End the current caret.
            caret.stopEditing();
        }
    }
    // caret will be null at this point
    // Otherwise search for a new caret.
    int x = e.getX();
    int y = e.getY();
    Location loc = Location.create(x, y);
    ComponentUserEvent event = new ComponentUserEvent(canvas, x, y);
    // First search in selection.
    for (Component comp : proj.getSelection().getComponentsContaining(loc, g)) {
        TextEditable editable = (TextEditable) comp.getFeature(TextEditable.class);
        if (editable != null) {
            caret = editable.getTextCaret(event);
            if (caret != null) {
                proj.getFrame().viewComponentAttributes(circ, comp);
                caretComponent = comp;
                caretCreatingText = false;
                break;
            }
        }
    }
    // Then search in circuit
    if (caret == null) {
        for (Component comp : circ.getAllContaining(loc, g)) {
            TextEditable editable = (TextEditable) comp.getFeature(TextEditable.class);
            if (editable != null) {
                caret = editable.getTextCaret(event);
                if (caret != null) {
                    proj.getFrame().viewComponentAttributes(circ, comp);
                    caretComponent = comp;
                    caretCreatingText = false;
                    break;
                }
            }
        }
    }
    // if nothing found, create a new label
    if (caret == null) {
        if (loc.getX() < 0 || loc.getY() < 0)
            return;
        AttributeSet copy = (AttributeSet) attrs.clone();
        caretComponent = Text.FACTORY.createComponent(loc, copy);
        caretCreatingText = true;
        TextEditable editable = (TextEditable) caretComponent.getFeature(TextEditable.class);
        if (editable != null) {
            caret = editable.getTextCaret(event);
            proj.getFrame().viewComponentAttributes(circ, caretComponent);
        }
    }
    if (caret != null) {
        caretCanvas = canvas;
        caretCircuit = canvas.getCircuit();
        caret.addCaretListener(listener);
        caretCircuit.addCircuitListener(listener);
    }
    proj.repaintCanvas();
}
Also used : Project(com.cburch.logisim.proj.Project) AttributeSet(com.cburch.logisim.data.AttributeSet) ComponentUserEvent(com.cburch.logisim.comp.ComponentUserEvent) Circuit(com.cburch.logisim.circuit.Circuit) Component(com.cburch.logisim.comp.Component) Location(com.cburch.logisim.data.Location)

Example 14 with Project

use of com.cburch.logisim.proj.Project in project logisim-evolution by reds-heig.

the class Startup method run.

public void run() {
    if (isTty) {
        try {
            TtyInterface.run(this);
            return;
        } catch (Exception t) {
            t.printStackTrace();
            System.exit(-1);
            return;
        }
    }
    // I loaded a large file.)
    if (showSplash) {
        try {
            monitor = new SplashScreen();
            monitor.setVisible(true);
        } catch (Exception t) {
            monitor = null;
            showSplash = false;
        }
    }
    Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.COMPONENT_EVENT_MASK | AWTEvent.CONTAINER_EVENT_MASK);
    // taken is shown separately in the progress bar.
    if (showSplash) {
        monitor.setProgress(SplashScreen.LIBRARIES);
    }
    Loader templLoader = new Loader(monitor);
    int count = templLoader.getBuiltin().getLibrary("Base").getTools().size() + templLoader.getBuiltin().getLibrary("Gates").getTools().size();
    if (count < 0) {
        // this will never happen, but the optimizer doesn't know that...
        // OK
        logger.error("FATAL ERROR - no components");
        System.exit(-1);
    }
    // load in template
    loadTemplate(templLoader, templFile, templEmpty);
    // interface initialization
    if (showSplash) {
        monitor.setProgress(SplashScreen.GUI_INIT);
    }
    WindowManagers.initialize();
    if (MacCompatibility.isSwingUsingScreenMenuBar()) {
        MacCompatibility.setFramelessJMenuBar(new LogisimMenuBar(null, null));
    } else {
        new LogisimMenuBar(null, null);
    // most of the time occupied here will be in loading menus, which
    // will occur eventually anyway; we might as well do it when the
    // monitor says we are
    }
    // if user has double-clicked a file to open, we'll
    // use that as the file to open now.
    initialized = true;
    // load file
    if (filesToOpen.isEmpty()) {
        Project proj = ProjectActions.doNew(monitor);
        proj.setStartupScreen(true);
        if (showSplash) {
            monitor.close();
        }
    } else {
        int numOpened = 0;
        boolean first = true;
        for (File fileToOpen : filesToOpen) {
            try {
                if (testVector != null) {
                    Project proj = ProjectActions.doOpenNoWindow(monitor, fileToOpen);
                    proj.doTestVector(testVector, circuitToTest);
                } else {
                    ProjectActions.doOpen(monitor, fileToOpen, substitutions);
                }
                numOpened++;
            } catch (LoadFailedException ex) {
                logger.error("{} : {}", fileToOpen.getName(), ex.getMessage());
            }
            if (first) {
                first = false;
                if (showSplash) {
                    monitor.close();
                }
                monitor = null;
            }
        }
        if (numOpened == 0)
            System.exit(-1);
    }
    for (File fileToPrint : filesToPrint) {
        doPrintFile(fileToPrint);
    }
    if (exitAfterStartup) {
        System.exit(0);
    }
}
Also used : Project(com.cburch.logisim.proj.Project) Loader(com.cburch.logisim.file.Loader) LogisimMenuBar(com.cburch.logisim.gui.menu.LogisimMenuBar) File(java.io.File) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) LoadFailedException(com.cburch.logisim.file.LoadFailedException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) Print(com.cburch.logisim.gui.main.Print) LoadFailedException(com.cburch.logisim.file.LoadFailedException)

Example 15 with Project

use of com.cburch.logisim.proj.Project in project logisim-evolution by reds-heig.

the class MenuFile method actionPerformed.

public void actionPerformed(ActionEvent e) {
    Object src = e.getSource();
    Project proj = menubar.getProject();
    if (src == newi) {
        ProjectActions.doNew(proj);
    } else if (src == merge) {
        ProjectActions.doMerge(proj == null ? null : proj.getFrame().getCanvas(), proj);
    } else if (src == open) {
        ProjectActions.doOpen(proj == null ? null : proj.getFrame().getCanvas(), proj);
    } else if (src == close) {
        int result = 0;
        Frame frame = proj.getFrame();
        if (proj.isFileDirty()) {
            /* Must use hardcoded strings here, because the string management is rotten */
            String message = "What should happen to your unsaved changes to " + proj.getLogisimFile().getName();
            String[] options = { "Save", "Discard", "Cancel" };
            result = JOptionPane.showOptionDialog(JOptionPane.getFrameForComponent(this), message, "Confirm Close", 0, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
            if (result == 0) {
                ProjectActions.doSave(proj);
            }
        }
        /* If "cancel" pressed do nothing, otherwise dispose the window, opening one if this was the last opened window */
        if (result != 2) {
            // Get the list of open projects
            List<Project> pl = Projects.getOpenProjects();
            if (pl.size() == 1) {
                // Since we have a single window open, before closing the
                // current
                // project open a new empty one
                ProjectActions.doNew(proj);
            }
            // Close the current project
            frame.dispose();
            OptionsFrame f = proj.getOptionsFrame(false);
            if (f != null)
                f.dispose();
        }
    } else if (src == save) {
        ProjectActions.doSave(proj);
    } else if (src == saveAs) {
        ProjectActions.doSaveAs(proj);
    } else if (src == prefs) {
        PreferencesFrame.showPreferences();
    } else if (src == quit) {
        ProjectActions.doQuit();
    }
}
Also used : Project(com.cburch.logisim.proj.Project) OptionsFrame(com.cburch.logisim.gui.opts.OptionsFrame) Frame(com.cburch.logisim.gui.main.Frame) PreferencesFrame(com.cburch.logisim.gui.prefs.PreferencesFrame) List(java.util.List) OptionsFrame(com.cburch.logisim.gui.opts.OptionsFrame)

Aggregations

Project (com.cburch.logisim.proj.Project)26 Circuit (com.cburch.logisim.circuit.Circuit)11 Component (com.cburch.logisim.comp.Component)7 Location (com.cburch.logisim.data.Location)5 Action (com.cburch.logisim.proj.Action)5 AttributeSet (com.cburch.logisim.data.AttributeSet)3 Bounds (com.cburch.logisim.data.Bounds)3 Selection (com.cburch.logisim.gui.main.Selection)3 Wire (com.cburch.logisim.circuit.Wire)2 ComponentUserEvent (com.cburch.logisim.comp.ComponentUserEvent)2 LoadFailedException (com.cburch.logisim.file.LoadFailedException)2 Loader (com.cburch.logisim.file.Loader)2 ToolAttributeAction (com.cburch.logisim.gui.main.ToolAttributeAction)2 MoveGesture (com.cburch.logisim.tools.move.MoveGesture)2 MoveResult (com.cburch.logisim.tools.move.MoveResult)2 File (java.io.File)2 IOException (java.io.IOException)2 Map (java.util.Map)2 Selection (com.cburch.draw.canvas.Selection)1 CanvasObject (com.cburch.draw.model.CanvasObject)1