Package com.cburch.logisim.proj

Examples of com.cburch.logisim.proj.Project


            addActionListener(this);
        }

        @Override
        public void actionPerformed(ActionEvent event) {
            Project proj = menubar.getProject();
            Component par = proj == null ? null : proj.getFrame().getCanvas();
            ProjectActions.doOpen(par, proj, file);
        }
View Full Code Here


        int x = e.getX();
        int y = e.getY();
        Location pt = Location.create(x, y);

        JPopupMenu menu;
        Project proj = canvas.getProject();
        Selection sel = proj.getSelection();
        Collection<Component> in_sel = sel.getComponentsContaining(pt, g);
        if (!in_sel.isEmpty()) {
            Component comp = in_sel.iterator().next();
            if (sel.getComponents().size() > 1) {
                menu = new MenuSelection(proj);
View Full Code Here

        computeEnabled();
    }
   
    public void tick() {
      Project proj = menubar.getProject();
        Simulator sim = proj == null ? null : proj.getSimulator();
        if (sim != null)
          sim.tick();
    }
View Full Code Here

                remove.setEnabled(false);
                attrTable.setAttrTableModel(null);
            } else {
                remove.setEnabled(true);
                Tool tool = model.getTool(row);
                Project proj = getProject();
                AttrTableModel model;
                if (tool.getAttributeSet() == null) {
                    model = null;
                } else {
                    model = new AttrTableToolModel(proj, tool);
View Full Code Here

        }

        @Override
        public void actionPerformed(ActionEvent e) {
            Object src = e.getSource();
            Project proj = menubar.getProject();
      if( src == undo )
      {
        if( proj != null )
          proj.undoAction();
      }
      else if( src == redo )
      {
        if (proj != null )
          proj.redoAction();
            }
        }
View Full Code Here

    }

    @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();
        }
    }
View Full Code Here

        }
    }

    @Override
    public void mouseReleased(Canvas canvas, Graphics g, MouseEvent e) {
        Project proj = canvas.getProject();
        if (state == MOVING) {
            setState(proj, IDLE);
            computeDxDy(proj, e, g);
            int dx = curDx;
            int dy = curDy;
            if (dx != 0 || dy != 0) {
                if (!proj.getLogisimFile().contains(canvas.getCircuit())) {
                    canvas.setErrorMessage(getFromLocale("cannotModifyError"), dx, dy);
                } else if (proj.getSelection().hasConflictWhenMoved(dx, dy)) {
                    canvas.setErrorMessage(getFromLocale("exclusiveError"), dx, dy);
                } else {
                    boolean connect = shouldConnect(canvas, e.getModifiersEx());
                    drawConnections = false;
                    ReplacementMap repl;
                    if (connect) {
                        MoveGesture gesture = moveGesture;
                        if (gesture == null) {
                            gesture = new MoveGesture(new MoveRequestHandler(canvas),
                                    canvas.getCircuit(), canvas.getSelection().getAnchoredComponents());
                        }
                        canvas.setErrorMessage(getFromLocale("moveWorkingMsg"), dx, dy, COLOR_COMPUTING);
                        MoveResult result = gesture.forceRequest(dx, dy);
                        clearCanvasMessage(canvas, dx, dy);
                        repl = result.getReplacementMap();
                    } else {
                        repl = null;
                    }
                    Selection sel = proj.getSelection();
                    proj.doAction(SelectionActions.translate(sel, dx, dy, repl));
                }
            }
            moveGesture = null;
            proj.repaintCanvas();
        } else if (state == RECT_SELECT) {
            Bounds bds = Bounds.create(start).add(start.getX() + curDx,
                start.getY() + curDy);
            Circuit circuit = canvas.getCircuit();
            Selection sel = proj.getSelection();
            Collection<Component> in_sel = sel.getComponentsWithin(bds, g);
            for (Component comp : circuit.getAllWithin(bds, g)) {
                if (!in_sel.contains(comp)) sel.add(comp);
            }
            Action act = SelectionActions.drop(sel, in_sel);
            if (act != null) {
                proj.doAction(act);
            }
            setState(proj, IDLE);
            proj.repaintCanvas();
        }
    }
View Full Code Here

        }
    }

    @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(getFromLocale("cannotModifyError"), 0, 0);
            return;
        }

        // Maybe user is clicking within the current caret.
        if (caret != null) {
            // Yes
            if (caret.getBounds(g).contains(e.getX(), e.getY())) {
                caret.mousePressed(e);
                proj.repaintCanvas();
                return;
            // No. End the current caret.
            } else {
                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();
    }
View Full Code Here

            caretCircuit.removeCircuitListener(this);

            String val = caret.getText();
            boolean isEmpty = (val == null || val.equals(""));
            Action a;
            Project proj = caretCanvas.getProject();
            if (caretCreatingText) {
                if (!isEmpty) {
                    CircuitMutation xn = new CircuitMutation(caretCircuit);
                    xn.add(caretComponent);
                    a = xn.toAction(getFromLocale("addComponentAction",
                            Text.FACTORY.getDisplayGetter()));
                } else {
                    // don't add the blank text field
                    a = null;
                }
            } else {
                if (isEmpty && caretComponent.getFactory() instanceof Text) {
                    CircuitMutation xn = new CircuitMutation(caretCircuit);
                    xn.add(caretComponent);
                    a = xn.toAction(getFromLocale("removeComponentAction",
                            Text.FACTORY.getDisplayGetter()));
                } else {
                    Object obj = caretComponent.getFeature(TextEditable.class);
                    // should never happen
                    if (obj == null) {
                        a = null;
                    } else {
                        TextEditable editable = (TextEditable) obj;
                        a = editable.getCommitAction(caretCircuit, e.getOldText(), e.getText());
                    }
                }
            }

            caretCircuit = null;
            caretComponent = null;
            caretCreatingText = false;
            caret = null;

            if (a != null) {
                proj.doAction(a);
            }

        }
View Full Code Here

        canvas.addPropertyChangeListener(Canvas.MODEL_PROPERTY, this);
    }

    @Override
    public void computeEnabled() {
        Project proj = canvas.getProject();
        Circuit circ = canvas.getCircuit();
        Selection sel = canvas.getSelection();
        boolean selEmpty = sel.isEmpty();
        boolean canChange = proj.getLogisimFile().contains(circ);
        boolean clipExists = !Clipboard.isEmpty();
        boolean selHasRemovable = false;
        for (CanvasObject o : sel.getSelected()) {
            if (!(o instanceof AppearanceElement)) {
                selHasRemovable = true;
View Full Code Here

TOP

Related Classes of com.cburch.logisim.proj.Project

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.