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;
}
}
}
}
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();
}
}
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();
}
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);
}
}
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();
}
}
Aggregations