mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-14 15:26:52 -04:00
adds the FileLocator to the DataFieldEditor load button, closes #566
This commit is contained in:
parent
632eb16459
commit
b292ebdb53
@ -31,7 +31,7 @@ public class FileLocator {
|
|||||||
/**
|
/**
|
||||||
* Creates a new instance
|
* Creates a new instance
|
||||||
*
|
*
|
||||||
* @param file the file to serach for
|
* @param file the file to search for
|
||||||
*/
|
*/
|
||||||
public FileLocator(File file) {
|
public FileLocator(File file) {
|
||||||
this(file == null ? null : file.getName());
|
this(file == null ? null : file.getName());
|
||||||
@ -90,8 +90,10 @@ public class FileLocator {
|
|||||||
* @return this for chained calls
|
* @return this for chained calls
|
||||||
*/
|
*/
|
||||||
public FileLocator setupWithMain(Main main) {
|
public FileLocator setupWithMain(Main main) {
|
||||||
setBaseFile(main.getBaseFileName());
|
if (main != null) {
|
||||||
setLibrary(main.getLibrary());
|
setBaseFile(main.getBaseFileName());
|
||||||
|
setLibrary(main.getLibrary());
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +107,7 @@ public class FileLocator {
|
|||||||
return file;
|
return file;
|
||||||
|
|
||||||
if (filename == null)
|
if (filename == null)
|
||||||
return file;
|
return null;
|
||||||
|
|
||||||
if (baseFile != null) {
|
if (baseFile != null) {
|
||||||
File f = new File(baseFile.getParentFile(), filename);
|
File f = new File(baseFile.getParentFile(), filename);
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
package de.neemann.digital.gui.components;
|
package de.neemann.digital.gui.components;
|
||||||
|
|
||||||
|
import de.neemann.digital.FileLocator;
|
||||||
import de.neemann.digital.analyse.expression.format.FormatToExpression;
|
import de.neemann.digital.analyse.expression.format.FormatToExpression;
|
||||||
import de.neemann.digital.core.*;
|
import de.neemann.digital.core.*;
|
||||||
import de.neemann.digital.core.element.*;
|
import de.neemann.digital.core.element.*;
|
||||||
@ -640,7 +641,9 @@ public final class EditorFactory {
|
|||||||
int dataBits = attr.get(Keys.BITS);
|
int dataBits = attr.get(Keys.BITS);
|
||||||
int addrBits = getAddrBits(attr);
|
int addrBits = getAddrBits(attr);
|
||||||
DataEditor de = new DataEditor(panel, data, dataBits, addrBits, false, SyncAccess.NOSYNC, attr.get(Keys.INT_FORMAT));
|
DataEditor de = new DataEditor(panel, data, dataBits, addrBits, false, SyncAccess.NOSYNC, attr.get(Keys.INT_FORMAT));
|
||||||
de.setFileName(attr.getFile(ROM.LAST_DATA_FILE_KEY));
|
de.setFileName(new FileLocator(attr.getFile(ROM.LAST_DATA_FILE_KEY))
|
||||||
|
.setupWithMain(getAttributeDialog().getMain())
|
||||||
|
.locate());
|
||||||
if (de.showDialog()) {
|
if (de.showDialog()) {
|
||||||
DataField mod = de.getModifiedDataField();
|
DataField mod = de.getModifiedDataField();
|
||||||
if (!data.equals(mod))
|
if (!data.equals(mod))
|
||||||
@ -659,7 +662,9 @@ public final class EditorFactory {
|
|||||||
try {
|
try {
|
||||||
getAttributeDialog().storeEditedValues();
|
getAttributeDialog().storeEditedValues();
|
||||||
int dataBits = attr.get(Keys.BITS);
|
int dataBits = attr.get(Keys.BITS);
|
||||||
data = Importer.read(attr.getFile(ROM.LAST_DATA_FILE_KEY), dataBits)
|
data = Importer.read(new FileLocator(attr.getFile(ROM.LAST_DATA_FILE_KEY))
|
||||||
|
.setupWithMain(getAttributeDialog().getMain())
|
||||||
|
.locate(), dataBits)
|
||||||
.trimValues(getAddrBits(attr), dataBits);
|
.trimValues(getAddrBits(attr), dataBits);
|
||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
new ErrorMessage(Lang.get("msg_errorReadingFile")).addCause(e1).show(panel);
|
new ErrorMessage(Lang.get("msg_errorReadingFile")).addCause(e1).show(panel);
|
||||||
@ -677,7 +682,9 @@ public final class EditorFactory {
|
|||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
try {
|
try {
|
||||||
getAttributeDialog().storeEditedValues();
|
getAttributeDialog().storeEditedValues();
|
||||||
final File file = attr.getFile(ROM.LAST_DATA_FILE_KEY);
|
final File file = new FileLocator(attr.getFile(ROM.LAST_DATA_FILE_KEY))
|
||||||
|
.setupWithMain(getAttributeDialog().getMain())
|
||||||
|
.locate();
|
||||||
data.saveTo(SaveAsHelper.checkSuffix(file, "hex"));
|
data.saveTo(SaveAsHelper.checkSuffix(file, "hex"));
|
||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
new ErrorMessage(Lang.get("msg_errorWritingFile")).addCause(e1).show(panel);
|
new ErrorMessage(Lang.get("msg_errorWritingFile")).addCause(e1).show(panel);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user