Skip to content

Commit 0774843

Browse files
committed
Merge pull request #3 from AliShug/tweaks
Tweaks
2 parents 8683a38 + d1741d0 commit 0774843

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+2401
-1626
lines changed

src/JNLP-INF/APPLICATION.JNLP

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<jnlp spec="7.0+" version="0.2.0.1" codebase="file:///F:/Documents/GitHub/ModuleSim"
3+
href="src/JNLP-INF/APPLICATION.jnlp">
4+
<information>
5+
<title>ModuleSim</title>
6+
<vendor>ModuleSim deployment test</vendor>
7+
<offline-allowed/>
8+
<association extensions="modsim" mime-type="application/modsim+xml"/>
9+
<shortcut online="false" install="true">
10+
<desktop/>
11+
<menu sub-menu="ModuleSim"/>
12+
</shortcut>
13+
</information>
14+
<resources>
15+
<!-- Application Resources -->
16+
<java version="1.8+" href=
17+
"http://java.sun.com/products/autodl/j2se"/>
18+
<jar href="out/artifacts/ModuleSim_jar/ModuleSim.jar"
19+
main="true" />
20+
21+
</resources>
22+
<security>
23+
<all-permissions/>
24+
</security>
25+
<application-desc
26+
name="ModuleSim v0.2.0"
27+
main-class="com.modsim.Main">
28+
</application-desc>
29+
<update check="background"/>
30+
</jnlp>

src/META-INF/MANIFEST.MF

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Manifest-Version: 1.0
2+
Main-Class: com.modsim.Main
3+

src/simulator/Main.java renamed to src/com/modsim/Main.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
package simulator;
2-
3-
import gui.GUI;
4-
import gui.Ticker;
5-
import tools.OperationStack;
6-
import util.ModuleClipboard;
7-
import util.Selection;
1+
package com.modsim;
2+
3+
import com.modsim.gui.GUI;
4+
import com.modsim.gui.view.Ticker;
5+
import com.modsim.simulator.Sim;
6+
import com.modsim.operations.OperationStack;
7+
import com.modsim.util.ModuleClipboard;
8+
import com.modsim.util.Selection;
89

910
import javax.swing.*;
1011

src/gui/ComponentPane.java renamed to src/com/modsim/gui/ComponentPane.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package gui;
1+
package com.modsim.gui;
22

33
import java.awt.*;
44
import javax.swing.JPanel;
5-
import static modules.BaseModule.AvailableModules;
5+
import static com.modsim.modules.BaseModule.AvailableModules;
66

77
/**
88
* The module selection pane
@@ -21,7 +21,7 @@ public ComponentPane() {
2121
}
2222

2323
/**
24-
* Adds the modules to the listing
24+
* Adds the com.modsim.modules to the listing
2525
*/
2626
private void addModules() {
2727
GridBagConstraints gb = new GridBagConstraints();
@@ -51,7 +51,7 @@ private void addModules() {
5151
public void paintComponent(Graphics oldG) {
5252
Graphics2D g = (Graphics2D) oldG;
5353

54-
g.setColor(new Color(255, 255, 255));
54+
g.setColor(Color.WHITE);
5555
g.fillRect(0, 0, getWidth(), getHeight());
5656
}
5757

src/gui/GUI.java renamed to src/com/modsim/gui/GUI.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
package gui;
1+
package com.modsim.gui;
22

3-
import res.ResourceLoader;
4-
import simulator.Main;
5-
import sun.awt.WindowClosingListener;
3+
import com.modsim.operations.Ops;
4+
import com.modsim.gui.view.ContextMenu;
5+
import com.modsim.gui.view.View;
6+
import com.modsim.res.ResourceLoader;
7+
import com.modsim.Main;
68

79
import java.awt.event.WindowAdapter;
810
import java.awt.event.WindowEvent;
@@ -39,7 +41,7 @@ public boolean checkSave() {
3941

4042
switch (res) {
4143
case JOptionPane.YES_OPTION:
42-
return Main.ui.menu.save();
44+
return Ops.FileIO.save();
4345
case JOptionPane.NO_OPTION:
4446
return true;
4547

src/gui/MemEdit.java renamed to src/com/modsim/gui/MemEdit.java

Lines changed: 76 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package gui;
1+
package com.modsim.gui;
22

3-
import java.awt.BorderLayout;
3+
import java.awt.*;
44
import java.awt.event.ActionEvent;
55
import java.awt.event.ActionListener;
66
import java.awt.event.AdjustmentEvent;
@@ -11,36 +11,33 @@
1111
import java.awt.event.MouseAdapter;
1212
import java.awt.event.MouseWheelEvent;
1313
import java.io.File;
14+
import java.io.FilenameFilter;
15+
import java.util.prefs.Preferences;
1416

15-
import javax.swing.BoxLayout;
16-
import javax.swing.JButton;
17-
import javax.swing.JDialog;
18-
import javax.swing.JFileChooser;
19-
import javax.swing.JLabel;
20-
import javax.swing.JMenu;
21-
import javax.swing.JMenuBar;
22-
import javax.swing.JMenuItem;
23-
import javax.swing.JPanel;
24-
import javax.swing.JScrollBar;
25-
import javax.swing.JTextField;
17+
import javax.swing.*;
2618
import javax.swing.filechooser.FileNameExtensionFilter;
2719

28-
import simulator.Main;
29-
import util.BinData;
30-
import util.HexReader;
31-
import util.HexWriter;
32-
import modules.NRAM;
20+
import com.modsim.Main;
21+
import com.modsim.util.BinData;
22+
import com.modsim.util.HexReader;
23+
import com.modsim.util.HexWriter;
24+
import com.modsim.modules.NRAM;
25+
import com.modsim.util.XMLReader;
3326

3427
public class MemEdit {
3528

36-
private NRAM targ = null;
29+
private NRAM nram = null;
3730

3831
public final JDialog frame = new JDialog(Main.ui.frame, "Memory Viewer");
3932
private final JMenuBar menu = new JMenuBar();
40-
private final JFileChooser filePick = new JFileChooser();
41-
private final FileNameExtensionFilter hexFilter = new FileNameExtensionFilter("Hex files", "hex");
33+
private final FilenameFilter hexFilter = new FilenameFilter() {
34+
@Override
35+
public boolean accept(File dir, String name) {
36+
return name.endsWith(".hex");
37+
}
38+
};
4239
private final JScrollBar scroll = new JScrollBar(JScrollBar.VERTICAL);
43-
private final JTextField jumpadr = new JTextField();
40+
private final JTextField jumpAdr = new JTextField();
4441

4542
private final MemView memView;
4643

@@ -56,7 +53,7 @@ public MemEdit() {
5653
JPanel adrStrip = new JPanel();
5754
adrStrip.setLayout(new BoxLayout(adrStrip, BoxLayout.LINE_AXIS));
5855
adrStrip.add(new JLabel(" Jump to: "));
59-
adrStrip.add(jumpadr);
56+
adrStrip.add(jumpAdr);
6057

6158
JButton goBtn = new JButton("Go");
6259
JButton lastBtn = new JButton("Last Changed");
@@ -87,7 +84,7 @@ public void actionPerformed(ActionEvent e) {
8784
int adr;
8885

8986
try {
90-
adr = Integer.parseInt(jumpadr.getText(), 16);
87+
adr = Integer.parseInt(jumpAdr.getText(), 16);
9188
}
9289
catch (NumberFormatException nfe) {
9390
return; // Fail silently.
@@ -99,7 +96,7 @@ public void actionPerformed(ActionEvent e) {
9996
}
10097
};
10198

102-
jumpadr.addActionListener(jumpListener);
99+
jumpAdr.addActionListener(jumpListener);
103100
goBtn.addActionListener(jumpListener);
104101

105102
lastBtn.addActionListener(new ActionListener() {
@@ -119,7 +116,7 @@ public void show(NRAM nram) {
119116
frame.setSize(300, 700);
120117
frame.setLocation(800, 100);
121118
frame.setVisible(true);
122-
targ = nram;
119+
this.nram = nram;
123120

124121
update();
125122
}
@@ -135,6 +132,7 @@ public void close() {
135132
* Updates the view of the memory contents
136133
*/
137134
public void update() {
135+
frame.setTitle("NRAM " + nram.label);
138136
memView.setUpdated(updAdr);
139137
memView.repaint();
140138
}
@@ -145,7 +143,7 @@ public void update() {
145143
* @return The stored byte
146144
*/
147145
public int getByte(int adr) {
148-
BinData[] bits = targ.read(adr);
146+
BinData[] bits = nram.read(adr);
149147
return (bits[1].getUInt() << 4) | (bits[0].getUInt());
150148
}
151149

@@ -169,12 +167,40 @@ private void addFileMenu() {
169167
menuItem.setToolTipText("Load a hex data file into the module (replaces the current contents)");
170168
menuItem.addActionListener(new ActionListener() {
171169
public void actionPerformed(ActionEvent e) {
172-
filePick.setFileFilter(hexFilter);
173-
int r = filePick.showOpenDialog(frame);
170+
Preferences prefs = Preferences.userNodeForPackage(MemEdit.class);
171+
FileDialog fd = new FileDialog(frame, "Load Hex-encoded data", FileDialog.LOAD);
172+
173+
fd.setFilenameFilter(hexFilter);
174+
fd.setFile("*.hex"); // FilenameFilter doesn't work on Windows
175+
176+
fd.setDirectory(prefs.get("hex_fileDir", ""));
177+
fd.setVisible(true);
178+
179+
if (fd.getFile() != null) {
180+
String path = fd.getDirectory() + fd.getFile();
174181

175-
if (r == JFileChooser.APPROVE_OPTION) {
176-
File file = filePick.getSelectedFile();
177-
HexReader.readFile(file, targ);
182+
// Loop till we get a valid input
183+
while (!path.endsWith(".hex")) {
184+
int res = JOptionPane.showConfirmDialog(frame, "Data load: Warning",
185+
"That doesn't appear to be a hex file. Try and open anyway?",
186+
JOptionPane.YES_NO_CANCEL_OPTION);
187+
188+
if (res == JOptionPane.YES_OPTION) break;
189+
else if (res == JOptionPane.NO_OPTION) {
190+
fd.setFile("*.hex");
191+
fd.setVisible(true);
192+
193+
if (fd.getFile() == null) return;
194+
path = fd.getDirectory() + fd.getFile();
195+
}
196+
else {
197+
return;
198+
}
199+
}
200+
201+
prefs.put("hex_fileDir", fd.getDirectory());
202+
File file = new File(path);
203+
HexReader.readFile(file, nram);
178204
updAdr = -1;
179205
update();
180206
}
@@ -187,22 +213,29 @@ public void actionPerformed(ActionEvent e) {
187213
menuItem.setToolTipText("Saves the current NRAM contents to a hex data file");
188214
menuItem.addActionListener(new ActionListener() {
189215
public void actionPerformed(ActionEvent e) {
190-
filePick.setFileFilter(hexFilter);
191-
int r = filePick.showSaveDialog(frame);
216+
Preferences prefs = Preferences.userNodeForPackage(MemEdit.class);
217+
FileDialog fd = new FileDialog(frame, "Save Hex-encoded data", FileDialog.SAVE);
218+
fd.setFilenameFilter(hexFilter);
219+
// can just append .hex if the user doesn't
220+
if (Main.sim.filePath.isEmpty()) {
221+
fd.setFile("*.hex");
222+
} else {
223+
int ind = Main.sim.filePath.lastIndexOf('/');
224+
fd.setFile(Main.sim.filePath.substring(ind + 1));
225+
}
226+
227+
fd.setDirectory(prefs.get("hex_fileDir", ""));
228+
fd.setVisible(true);
192229

193-
if (r == JFileChooser.APPROVE_OPTION) {
194-
File file = filePick.getSelectedFile();
230+
if (fd.getFile() != null) {
231+
String path = fd.getDirectory() + fd.getFile();
195232

196233
// Is the file being created with the correct extension?
197-
if (!file.getName().endsWith(".hex")) {
198-
File extFile = new File(file.getPath() + ".hex");
199-
if (! extFile.exists()) {
200-
// Rename the destination file if it doesn't exist.
201-
file = extFile;
202-
}
234+
if (!path.endsWith(".hex")) {
235+
path = path + ".hex";
203236
}
204237

205-
HexWriter.writeFile(file, targ);
238+
HexWriter.writeFile(new File(path), nram);
206239
}
207240
}
208241
});

src/gui/MemView.java renamed to src/com/modsim/gui/MemView.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package gui;
1+
package com.modsim.gui;
22

33
import java.awt.Color;
44
import java.awt.Graphics;
@@ -7,7 +7,8 @@
77

88
import javax.swing.JPanel;
99

10-
import modules.NRAM;
10+
import com.modsim.modules.NRAM;
11+
import com.modsim.res.Colors;
1112

1213
public class MemView extends JPanel {
1314

@@ -98,7 +99,7 @@ private void drawRow(Graphics2D g, int row, int startAdr) {
9899
g.setTransform(xForm);
99100

100101
// Divider line
101-
g.setColor(new Color(200, 200, 200));
102+
g.setColor(Colors.moduleLabel);
102103
g.drawLine(0, rowH-1, getWidth(), rowH-1);
103104
}
104105
else {

0 commit comments

Comments
 (0)