added an additional library path

This commit is contained in:
hneemann 2017-07-17 12:44:53 +02:00
parent 9baf1a5b82
commit 1a045d9ba4
68 changed files with 81 additions and 15 deletions

View File

@ -35,6 +35,13 @@
<fileSet>
<directory>${basedir}/src/main/dig/74xx</directory>
<outputDirectory>/examples/74xx/</outputDirectory>
<includes>
<include>*.dig</include>
</includes>
</fileSet>
<fileSet>
<directory>${basedir}/src/main/dig/lib</directory>
<outputDirectory>/examples/lib/</outputDirectory>
<includes>
<include>**/*.dig</include>
<include>**/*.txt</include>

View File

@ -23,7 +23,7 @@ public class StartATF1502Fitter implements ExpressionToFileExporter.PostProcess
private static File getFitterExe(String fitterName) {
File fitter = Settings.getInstance().get(Keys.SETTINGS_ATF1502_FITTER);
return new File(fitter.getParentFile(), fitterName);
return new File(fitter, fitterName);
}
/**

View File

@ -2,6 +2,8 @@ package de.neemann.digital.core.element;
import de.neemann.digital.lang.Lang;
import java.io.File;
/**
* Class is used to define the keys used to access the models attributes
*
@ -147,6 +149,38 @@ public class Key<VALUE> {
}
}
/**
* Stores a file
*/
public static final class KeyFile extends Key<File> {
private boolean directoryOnly;
KeyFile(String key, File def) {
super(key, def);
setDirectoryOnly(false);
}
/**
* Set the directory only mode
*
* @param directoryOnly if true you can select only directories
* @return this for chained calls
*/
public KeyFile setDirectoryOnly(boolean directoryOnly) {
this.directoryOnly = directoryOnly;
return this;
}
/**
* @return true if you can select only directories
*/
public boolean isDirectoryOnly() {
return directoryOnly;
}
}
/**
* Used to store enum values
*

View File

@ -6,6 +6,7 @@ import de.neemann.digital.core.arithmetic.LeftRightFormat;
import de.neemann.digital.core.io.InValue;
import de.neemann.digital.core.io.IntFormat;
import de.neemann.digital.core.memory.DataField;
import de.neemann.digital.draw.library.ElementLibrary;
import de.neemann.digital.draw.model.InverterConfig;
import de.neemann.gui.Screen;
import de.neemann.gui.language.Language;
@ -336,7 +337,7 @@ public final class Keys {
* Fitter for the atf1502
*/
public static final Key<File> SETTINGS_ATF1502_FITTER
= new Key<>("atf1502Fitter", new File("c:/Wincupl/WinCupl/Fitters/fit1502.exe"));
= new Key.KeyFile("atf1502Fitter", new File("c:/Wincupl/WinCupl/Fitters")).setDirectoryOnly(true);
/**
* A pin number, empty means no pin assigned
@ -416,4 +417,9 @@ public final class Keys {
public static final Key<Boolean> ACTIVE_LOW
= new Key<>("activeLow", false);
/**
* Fitter for the atf1502
*/
public static final Key<File> SETTINGS_LIBRARY_PATH
= new Key.KeyFile("libraryPath", ElementLibrary.getLibPath()).setDirectoryOnly(true);
}

View File

@ -17,6 +17,7 @@ import de.neemann.digital.draw.elements.Circuit;
import de.neemann.digital.draw.elements.PinException;
import de.neemann.digital.draw.elements.Tunnel;
import de.neemann.digital.draw.shapes.ShapeFactory;
import de.neemann.digital.gui.Settings;
import de.neemann.digital.gui.components.data.DummyElement;
import de.neemann.digital.gui.components.graphics.GraphicCard;
import de.neemann.digital.gui.components.graphics.LedMatrix;
@ -48,16 +49,16 @@ public class ElementLibrary implements Iterable<ElementLibrary.ElementContainer>
/**
* @return the additional library path
*/
public static String getLibPath() {
public static File getLibPath() {
String path = ElementLibrary.class.getProtectionDomain().getCodeSource().getLocation().getPath().replace('\\', '/');
if (path.endsWith("/target/classes/"))
return path.substring(0, path.length() - 16) + "/src/main/dig/lib";
return new File(path.substring(0, path.length() - 16) + "/src/main/dig/lib");
if (path.endsWith("/target/Digital.jar"))
return path.substring(0, path.length() - 19) + "/src/main/dig/lib";
return new File(path.substring(0, path.length() - 19) + "/src/main/dig/lib");
if (path.endsWith("Digital.jar"))
return path.substring(0, path.length() - 12) + "/examples/lib";
return new File(path.substring(0, path.length() - 12) + "/examples/lib");
return null;
return new File("noLibFound");
}
private final HashMap<String, LibraryNode> map = new HashMap<>();
@ -291,9 +292,11 @@ public class ElementLibrary implements Iterable<ElementLibrary.ElementContainer>
private void rescanFolder() throws IOException {
LOGGER.debug("rescan folder");
LOGGER.info("library " + getLibPath());
File libPath = Settings.getInstance().get(Keys.SETTINGS_LIBRARY_PATH);
if (libPath != null && !libPath.exists()) libPath = null;
LibraryNode changedNode = null;
if (rootLibraryPath != null) {
if (rootLibraryPath != null || libPath != null) {
if (customNode == null) {
customNode = new LibraryNode(Lang.get("menu_custom"));
root.add(customNode);
@ -302,8 +305,11 @@ public class ElementLibrary implements Iterable<ElementLibrary.ElementContainer>
customNode.removeAll();
changedNode = customNode;
}
int num = scanFolder(rootLibraryPath, customNode);
int num = 0;
if (libPath != null)
num += scanFolder(libPath, customNode);
if (rootLibraryPath != null)
num += scanFolder(rootLibraryPath, customNode);
LOGGER.debug("found " + num + " files");
} else if (customNode != null) {
root.remove(customNode);

View File

@ -44,6 +44,7 @@ public final class Settings implements AttributeListener {
intList.add(Keys.SETTINGS_EXPRESSION_FORMAT);
intList.add(Keys.SETTINGS_DEFAULT_TREESELECT);
intList.add(Keys.SETTINGS_ATF1502_FITTER);
intList.add(Keys.SETTINGS_LIBRARY_PATH);
intList.add(Keys.SETTINGS_FONT_SCALING);
settingsKeys = Collections.unmodifiableList(intList);

View File

@ -300,14 +300,22 @@ public final class EditorFactory {
private final JPanel panel;
private final JTextField textField;
private final boolean directoryOnly;
public FileEditor(File value, Key<File> key) {
if (key instanceof Key.KeyFile)
directoryOnly = ((Key.KeyFile) key).isDirectoryOnly();
else
directoryOnly = false;
panel = new JPanel(new BorderLayout());
textField = new JTextField(value.getPath(), 20);
JButton button = new JButton(new AbstractAction("...") {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fc = new MyFileChooser(FileEditor.this.getValue());
if (directoryOnly)
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
if (fc.showOpenDialog(panel) == JFileChooser.APPROVE_OPTION)
textField.setText(fc.getSelectedFile().getPath());
}

View File

@ -676,8 +676,8 @@ Sind evtl. die Namen der Variablen nicht eindeutig?</string>
<string name="key_ledPersistence_tt">Die Schaltfrequenz in der Simulation kann nicht so hoch werden,
dass das menschliche Auge kein Flimmern mehr wahrnimmt. Um dennoch das Flackern zu unterdrücken, kann
bei den LEDs mit dieser Option ein "nachleuchten" eingeschaltet werden.</string>
<string name="key_atf1502Fitter">ATF1502 Fitter</string>
<string name="key_atf1502Fitter_tt">Pfad zum Fitter für den ATF1502. Geben Sie hier den vollen Pfad zur Datei fit1502.exe an. Diese Datei wird von ATMEL zu Verfügung gestellt.</string>
<string name="key_atf1502Fitter">ATF15xx Fitter</string>
<string name="key_atf1502Fitter_tt">Pfad zum Fitter für den ATF15xx. Geben Sie hier das Verzeichnis an, welches die Dateien fit15xx.exe enthält. Diese Datei wird von ATMEL zu Verfügung gestellt.</string>
<string name="key_pin">Pinnummer</string>
<string name="key_pin_tt">Ist das Feld leer bedeutet das, dass dieses Signal keinem Pin zugewiesen ist.</string>
<string name="key_rowDataBits">Zeilen</string>
@ -710,6 +710,8 @@ Sind evtl. die Namen der Variablen nicht eindeutig?</string>
Modus in manchen CMOS-Schaltungen erforderlich sein.</string>
<string name="key_activeLow">Active Low</string>
<string name="key_activeLow_tt">Wenn gesetzt, ist der Ausgang im aktiven Zustand Low.</string>
<string name="key_libraryPath">Bibliothek</string>
<string name="key_libraryPath_tt">Bibliothek mit vordefinierten Schaltungen. Enthält z.B. die ICs der 74xx Reihe.</string>
<string name="mod_insertWire">Leitung eingefügt.</string>
<string name="mod_insertCopied">Aus Zwischenablage eingefügt.</string>

View File

@ -664,8 +664,8 @@ The names of the variables may not be unique.</string>
<string name="key_ledPersistence_tt">It is not possible to increase the frequency so much that the flickering disappears.
With this option you can stabilize the display by keeping the LEDs on until the common cathode goes down again.
This simulates a frequency above the critical flicker fusion frequency.</string>
<string name="key_atf1502Fitter">ATF1502 Fitter</string>
<string name="key_atf1502Fitter_tt">Path to the fitter for the ATF1502. Enter the full path to the file fit1502.exe provided by ATMEL.</string>
<string name="key_atf1502Fitter">ATF15xx Fitter</string>
<string name="key_atf1502Fitter_tt">Path to the fitter for the ATF15xx. Enter the directory which countains the fit15xx.exe files provided by ATMEL.</string>
<string name="key_pin">Pin number</string>
<string name="key_pin_tt">An empty field means this signal is not assigned to a pin.</string>
<string name="key_rowDataBits">Rows</string>
@ -697,6 +697,8 @@ The names of the variables may not be unique.</string>
simulate certain CMOS circuits.</string>
<string name="key_activeLow">Active Low</string>
<string name="key_activeLow_tt">If selected the output is low if the component is active.</string>
<string name="key_libraryPath">Library</string>
<string name="key_libraryPath_tt">Library with predefined subcircuits. Contains, for example, the components of the 74xx series.</string>
<string name="mod_insertWire">Inserted wire.</string>
<string name="mod_insertCopied">Insert from clipboard.</string>