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();
    }
  }
Beispiel #2
0
        CircuitPopup(Project proj, Tool tool, Circuit circuit) {
            super(_("circuitMenu"));
            this.proj = proj;
            this.circuit = circuit;

            add(editLayout); editLayout.addActionListener(this);
            add(editAppearance); editAppearance.addActionListener(this);
            add(analyze); analyze.addActionListener(this);
            add(stats); stats.addActionListener(this);
            addSeparator();
            add(main); main.addActionListener(this);
            add(remove); remove.addActionListener(this);

            boolean canChange = proj.getLogisimFile().contains(circuit);
            LogisimFile file = proj.getLogisimFile();
            if (circuit == proj.getCurrentCircuit()) {
                if (proj.getFrame().getEditorView().equals(Frame.EDIT_APPEARANCE)) {
                    editAppearance.setEnabled(false);
                } else {
                    editLayout.setEnabled(false);
                }
            }
            main.setEnabled(canChange && file.getMainCircuit() != circuit);
            remove.setEnabled(canChange && file.getCircuitCount() > 1
                    && proj.getDependencies().canRemove(circuit));
        }
Beispiel #3
0
 @Override
 public void actionPerformed(ActionEvent e) {
     Object source = e.getSource();
     if (source == editLayout) {
         proj.setCurrentCircuit(circuit);
         proj.getFrame().setEditorView(Frame.EDIT_LAYOUT);
     } else if (source == editAppearance) {
         proj.setCurrentCircuit(circuit);
         proj.getFrame().setEditorView(Frame.EDIT_APPEARANCE);
     } else if (source == analyze) {
         ProjectCircuitActions.doAnalyze(proj, circuit);
     } else if (source == stats) {
         JFrame frame = (JFrame) SwingUtilities.getRoot(this);
         StatisticsDialog.show(frame, proj.getLogisimFile(), circuit);
     } else if (source == main) {
         ProjectCircuitActions.doSetAsMainCircuit(proj, circuit);
     } else if (source == remove) {
         ProjectCircuitActions.doRemoveCircuit(proj, circuit);
     }
 }
Beispiel #4
0
 public void actionPerformed(ActionEvent e) {
   Object src = e.getSource();
   Project proj = menubar.getProject();
   if (src == newi) {
     ProjectActions.doNew(proj);
   } else if (src == open) {
     ProjectActions.doOpen(proj == null ? null : proj.getFrame().getCanvas(), proj);
   } else if (src == close) {
     Frame frame = proj.getFrame();
     if (frame.confirmClose()) {
       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();
   }
 }
Beispiel #5
0
	public void configureMenu(JPopupMenu menu, Project proj) {
		this.proj = proj;
		this.frame = proj.getFrame();
		this.circState = proj.getCircuitState();    
		
		Object attrs = instance.getAttributeSet();
		if (attrs instanceof RomAttributes) {
			((RomAttributes) attrs).setProject(proj);
		}

		boolean enabled = circState != null;
		edit = createItem(enabled, _("ramEditMenuItem"));
		clear = createItem(enabled, _("ramClearMenuItem"));
		load = createItem(enabled, _("ramLoadMenuItem"));
		save = createItem(enabled, _("ramSaveMenuItem"));

		menu.addSeparator();
		menu.add(edit);
		menu.add(clear);
		menu.add(load);
		menu.add(save);
	}
Beispiel #6
0
  private void setState(Project proj, int new_state) {
    if (state == new_state) return; // do nothing if state not new

    state = new_state;
    proj.getFrame().getCanvas().setCursor(getCursor());
  }
Beispiel #7
0
  @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();
  }