Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 57 additions & 24 deletions src/com/modsim/gui/MemEdit.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class MemEdit {

private NRAM nram = null;

public final JDialog frame = new JDialog(Main.ui.frame, "Memory Viewer");
public final JDialog frame = new JDialog(Main.ui.frame, "Memory Viewer", Dialog.ModalityType.MODELESS);
private final JMenuBar menu = new JMenuBar();
private final FilenameFilter hexFilter = new FilenameFilter() {
@Override
Expand Down Expand Up @@ -155,6 +155,42 @@ public void jumpTo(int adr) {
scroll.setValue(adr / memView.getCellsPerRow());
}

/**
* Handles a save action to save the data
* @param e The event that triggered the action
* @param shouldClose Whether the window should close after a successful save
*/
private void saveActionPerformed(ActionEvent e, boolean shouldClose) {
Preferences prefs = Preferences.userNodeForPackage(MemEdit.class);
FileDialog fd = new FileDialog(frame, "Save Hex-encoded data", FileDialog.SAVE);
fd.setFilenameFilter(hexFilter);
// can just append .hex if the user doesn't
if (Main.sim.filePath.isEmpty()) {
fd.setFile("*.hex");
} else {
int ind = Main.sim.filePath.lastIndexOf('/');
fd.setFile(Main.sim.filePath.substring(ind + 1));
}

fd.setDirectory(prefs.get("hex_fileDir", ""));
fd.setVisible(true);

if (fd.getFile() != null) {
String path = fd.getDirectory() + fd.getFile();

// Is the file being created with the correct extension?
if (!path.endsWith(".hex")) {
path = path + ".hex";
}

HexWriter.writeFile(new File(path), nram);

if (shouldClose) {
close();
}
}
}

/**
* Fills the file menu
*/
Expand Down Expand Up @@ -209,34 +245,31 @@ else if (res == JOptionPane.NO_OPTION) {
file.add(menuItem);

menuItem = new JMenuItem("Save Data");
menuItem.setMnemonic(KeyEvent.VK_O);
menuItem.setMnemonic(KeyEvent.VK_S);
menuItem.setToolTipText("Saves the current NRAM contents to a hex data file");
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Preferences prefs = Preferences.userNodeForPackage(MemEdit.class);
FileDialog fd = new FileDialog(frame, "Save Hex-encoded data", FileDialog.SAVE);
fd.setFilenameFilter(hexFilter);
// can just append .hex if the user doesn't
if (Main.sim.filePath.isEmpty()) {
fd.setFile("*.hex");
} else {
int ind = Main.sim.filePath.lastIndexOf('/');
fd.setFile(Main.sim.filePath.substring(ind + 1));
}

fd.setDirectory(prefs.get("hex_fileDir", ""));
fd.setVisible(true);

if (fd.getFile() != null) {
String path = fd.getDirectory() + fd.getFile();
saveActionPerformed(e, false);
}
});
file.add(menuItem);

// Is the file being created with the correct extension?
if (!path.endsWith(".hex")) {
path = path + ".hex";
}
menuItem = new JMenuItem("Close without save");
menuItem.setMnemonic(KeyEvent.VK_X);
menuItem.setToolTipText("Closes the window without saving NRAM contents");
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
close();
}
});
file.add(menuItem);

HexWriter.writeFile(new File(path), nram);
}
menuItem = new JMenuItem("Close with save");
menuItem.setMnemonic(KeyEvent.VK_D);
menuItem.setToolTipText("Saves the current NRAM contents to a hex data file and closes the window");
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
saveActionPerformed(e, true);
}
});
file.add(menuItem);
Expand Down
9 changes: 7 additions & 2 deletions src/com/modsim/gui/view/ViewUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ public void mousePressed(MouseEvent e) {
else {
Port p = screenSpace_portAt(e.getX(), e.getY());

Main.selection.clear();

//Link behaviour
if (p != null) {
tool = new MakeLinkTool();
Expand Down Expand Up @@ -401,14 +403,17 @@ public void keyPressed(KeyEvent e) {
View v = Main.ui.view;

// Cancel tool usage on escape press
if (e.getKeyChar() == KeyEvent.VK_ESCAPE) {
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
if (v.curTool != null) {
v.curTool.cancel();
v.curTool = null;
}
}
// Delete selection
else if (e.getKeyChar() == KeyEvent.VK_DELETE) {
else if (( e.getKeyCode() == KeyEvent.VK_DELETE
|| e.getKeyCode() == KeyEvent.VK_BACK_SPACE
|| e.getKeyCode() == KeyEvent.VK_X)
&& !Main.selection.isEmpty()) {
Main.selection.deleteAll();
}
// Pass to tool
Expand Down
2 changes: 2 additions & 0 deletions src/com/modsim/tools/EditLinkTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ public BaseTool lbUp(int x, int y) {
public BaseTool keyDown(int key) {
switch (key) {
case KeyEvent.VK_X:
case KeyEvent.VK_DELETE:
case KeyEvent.VK_BACK_SPACE:
Main.opStack.cancelCompoundOp();
link.highlight = false;
link.delete();
Expand Down
8 changes: 6 additions & 2 deletions src/com/modsim/tools/MakeLinkTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ public BaseTool mouseDrag(int x, int y) {

@Override
public BaseTool keyDown(int key) {
if (key == KeyEvent.VK_BACK_SPACE) {
if ( key == KeyEvent.VK_BACK_SPACE
|| key == KeyEvent.VK_DELETE
|| key == KeyEvent.VK_X) {
if (curve.removePt()) return this;
else return null;
}
Expand All @@ -94,7 +96,9 @@ public void paintWorld(Graphics2D g) {
public boolean startLink(int x, int y) {
source = ViewUtil.screenSpace_portAt(x, y);
if (source != null) {
working = true;
Main.selection.clear();

working = true;
start = new Vec2(x, y);
curve = new BezierPath();

Expand Down