Skip to content

Commit 55f88fd

Browse files
authored
Merge pull request #42 from EdNutting/master
Clipboard
2 parents 605cdc8 + c7def69 commit 55f88fd

File tree

11 files changed

+504
-271
lines changed

11 files changed

+504
-271
lines changed

src/com/modsim/modules/BaseModule.java

+20-2
Original file line numberDiff line numberDiff line change
@@ -704,15 +704,33 @@ public void propagateDirectionality(BidirPort root) {
704704
* Called by XMLReader and copy routines. Default behaviour is no-op.
705705
* @param data Structure containing state to load (module-defined elements)
706706
*/
707-
public void dataIn(HashMap<String, String> data) {}
707+
public void dataIn(HashMap<String, String> data) {
708+
if (data.containsKey("label")) {
709+
label = data.get("label");
710+
}
711+
if (data.containsKey("label_size")) {
712+
String sizeStr = data.get("label_size");
713+
try {
714+
labelSize = Integer.parseInt(sizeStr);
715+
} catch (NumberFormatException e) {
716+
System.err.println("Warning: unable to parse label_size:");
717+
e.printStackTrace();
718+
}
719+
}
720+
}
708721

709722
/**
710723
* Fill a string-string hash map with module-specific data for retrieval with dataIn.
711724
* Called by XMLWriter and the copy routines. Default behaviour is to return null, indicating that no relevant
712725
* data is contained in the module.
713726
* @return A filled hash map structure, or null if no state is stored
714727
*/
715-
public HashMap<String, String> dataOut() { return null; }
728+
public HashMap<String, String> dataOut() {
729+
HashMap<String, String> dataMap = new HashMap<>();
730+
dataMap.put("label", label);
731+
dataMap.put("label_size", Integer.toString(labelSize));
732+
return dataMap;
733+
}
716734

717735
public enum AvailableModules {
718736
// Enum members should not be renamed!

src/com/modsim/modules/Clock.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ public void propagate() {
118118

119119
@Override
120120
public void dataIn(HashMap<String, String> data) {
121+
super.dataIn(data);
122+
121123
if (data.containsKey("clock_phase")) {
122124
String phaseStr = data.get("clock_phase");
123125
try {
@@ -131,7 +133,7 @@ public void dataIn(HashMap<String, String> data) {
131133

132134
@Override
133135
public HashMap<String, String> dataOut() {
134-
HashMap<String, String> dataMap = new HashMap<>();
136+
HashMap<String, String> dataMap = super.dataOut();
135137
dataMap.put("clock_phase", String.valueOf(step));
136138
return dataMap;
137139
}

src/com/modsim/modules/LEDMatrix.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,18 @@ public boolean isPersistEnabled(){
124124

125125
@Override
126126
public HashMap<String, String> dataOut() {
127-
if (!isPersistEnabled()) return null;
127+
if (!isPersistEnabled()) return super.dataOut();
128128

129-
HashMap<String, String> data = new HashMap<>();
129+
HashMap<String, String> data = super.dataOut();
130130
data.put("persist", "1");
131131

132132
return data;
133133
}
134134

135135
@Override
136136
public void dataIn(HashMap<String, String> data) {
137+
super.dataIn(data);
138+
137139
if (data.containsKey("persist")) {
138140
String storeStr = data.get("persist");
139141
try{

src/com/modsim/modules/NRAM.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ public void clear() {
175175

176176
@Override
177177
public void dataIn(HashMap<String, String> data) {
178+
super.dataIn(data);
179+
178180
if (data.containsKey("memory_store")) {
179181
String storeStr = data.get("memory_store");
180182
HexReader.readString(storeStr, this);
@@ -192,9 +194,9 @@ public void dataIn(HashMap<String, String> data) {
192194
@Override
193195
public HashMap<String, String> dataOut() {
194196
String storeStr = HexWriter.hexString(this, false);
195-
if (storeStr.isEmpty()) return null;
197+
if (storeStr.isEmpty()) return super.dataOut();
196198

197-
HashMap<String, String> data = new HashMap<>();
199+
HashMap<String, String> data = super.dataOut();
198200
data.put("memory_store", storeStr);
199201
data.put("write_jumper", (writeJumper.getEnabled()) ? "1" : "0");
200202

src/com/modsim/modules/Register.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,16 @@ public void clear() {
109109

110110
@Override
111111
public HashMap<String, String> dataOut() {
112-
HashMap<String, String> dataMap = new HashMap<>();
112+
HashMap<String, String> dataMap = super.dataOut();
113113
String latched = myData.toString();
114114
dataMap.put("latched_value", latched);
115115
return dataMap;
116116
}
117117

118118
@Override
119119
public void dataIn(HashMap<String, String> data) {
120+
super.dataIn(data);
121+
120122
if (data.containsKey("latched_value")) {
121123
// Parse latched value
122124
String str = data.get("latched_value");

src/com/modsim/modules/SwitchInput.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ public void propagate() {
9898

9999
@Override
100100
public void dataIn(HashMap<String, String> data) {
101+
super.dataIn(data);
102+
101103
if (data.containsKey("switch_set")) {
102104
// Parse switch setting
103105
String str = data.get("switch_set");
@@ -121,7 +123,7 @@ public void dataIn(HashMap<String, String> data) {
121123

122124
@Override
123125
public HashMap<String, String> dataOut() {
124-
HashMap<String, String> data = new HashMap<>();
126+
HashMap<String, String> data = super.dataOut();
125127
String setting;
126128
setting = s1.getEnabled() ? "1" : "0";
127129
setting += s2.getEnabled() ? "1" : "0";

src/com/modsim/operations/Ops.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,13 @@ public static void fileNew() {
187187
Main.ui.view.cancelTool();
188188

189189
if (!Main.clipboard.isEmpty()) {
190-
Main.ui.view.setTool(new PlaceTool(Main.clipboard));
190+
try {
191+
Main.ui.view.setTool(new PlaceTool(Main.clipboard));
192+
}
193+
catch (Exception e) {
194+
// Clipboard contents may not be valid
195+
System.out.println(e.getMessage());
196+
}
191197
}
192198
else {
193199
System.out.println("Nothing to paste");

src/com/modsim/tools/PlaceTool.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ public PlaceTool(PickableEntity e) {
3434

3535
/**
3636
* Acts as a 'pasteInto' tool for the given clipboard
37+
*
3738
* @param clipboard Clipboard containing com.modsim.modules to 'pasteInto'
39+
* @throws Exception
3840
*/
39-
public PlaceTool(ModuleClipboard clipboard) {
41+
public PlaceTool(ModuleClipboard clipboard) throws Exception {
4042
Main.opStack.beginCompoundOp();
4143
entities = clipboard.paste();
4244

0 commit comments

Comments
 (0)