mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-21 02:55:28 -04:00
limits the menu size in the component menu. Closes #152
This commit is contained in:
parent
aa207fb8ce
commit
ac063e2bd6
@ -5,6 +5,7 @@
|
||||
*/
|
||||
package de.neemann.digital.draw.library;
|
||||
|
||||
import de.neemann.digital.lang.Lang;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -18,14 +19,14 @@ import java.util.Arrays;
|
||||
public class ElementLibraryFolder {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ElementLibraryFolder.class);
|
||||
private static final int MAX_FILES_TO_SCAN = 5000;
|
||||
private static final int MAX_MENU_SIZE = 12;
|
||||
|
||||
private final LibraryNode root;
|
||||
private final String menuTitle;
|
||||
private LibraryNode node;
|
||||
private File lastPath;
|
||||
|
||||
/**
|
||||
* create a new folder manager
|
||||
* Create a new folder manager.
|
||||
*
|
||||
* @param root the root node
|
||||
* @param menuTitle string to show in menu
|
||||
@ -43,7 +44,7 @@ public class ElementLibraryFolder {
|
||||
}
|
||||
|
||||
/**
|
||||
* scans the given folder
|
||||
* Scans the given folder
|
||||
*
|
||||
* @param path the path to scan
|
||||
* @param isLibrary true if this is the library
|
||||
@ -84,17 +85,58 @@ public class ElementLibraryFolder {
|
||||
node.add(n);
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList<File> fileList = new ArrayList<>();
|
||||
for (File f : orderedList) {
|
||||
scanCounter.incFile();
|
||||
final String name = f.getName();
|
||||
if (f.isFile() && name.endsWith(".dig")) {
|
||||
node.add(new LibraryNode(f, isLibrary));
|
||||
fileList.add(f);
|
||||
scanCounter.incCircuit();
|
||||
}
|
||||
}
|
||||
|
||||
if (fileList.size() <= MAX_MENU_SIZE + 1) {
|
||||
for (File f : fileList)
|
||||
node.add(new LibraryNode(f, isLibrary));
|
||||
} else {
|
||||
for (int i = 0; i < MAX_MENU_SIZE; i++)
|
||||
node.add(new LibraryNode(fileList.get(i), isLibrary));
|
||||
|
||||
final int size = fileList.size() - MAX_MENU_SIZE;
|
||||
int subMenus = (size - 1) / MAX_MENU_SIZE + 1;
|
||||
int delta = (size - 1) / subMenus + 1;
|
||||
|
||||
int pos = MAX_MENU_SIZE;
|
||||
while (pos < fileList.size()) {
|
||||
int pos2 = pos + delta;
|
||||
if (pos2 > fileList.size())
|
||||
pos2 = fileList.size();
|
||||
|
||||
String name;
|
||||
if (subMenus > 1)
|
||||
name = clean(fileList.get(pos)) + " - " + clean(fileList.get(pos2 - 1));
|
||||
else
|
||||
name = Lang.get("lib_more");
|
||||
|
||||
LibraryNode n = new LibraryNode(name);
|
||||
node.add(n);
|
||||
for (int p = pos; p < pos2; p++)
|
||||
n.add(new LibraryNode(fileList.get(p), isLibrary));
|
||||
|
||||
pos = pos2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String clean(File file) {
|
||||
String s = file.getName();
|
||||
if (s.endsWith(".dig"))
|
||||
s = s.substring(0, s.length() - 4);
|
||||
return s;
|
||||
}
|
||||
|
||||
private static final class ScanCounter {
|
||||
private int fileCounter;
|
||||
private int circuitCounter;
|
||||
|
Loading…
x
Reference in New Issue
Block a user