Skip to content

Commit

Permalink
Improve initialization time by eliminating the confirmation of icon
Browse files Browse the repository at this point in the history
images at startup.
  • Loading branch information
danielboudreau authored and danielboudreau committed Oct 15, 2018
1 parent 85dd88d commit 21d1271
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 26 deletions.
1 change: 0 additions & 1 deletion java/src/jmri/CatalogTreeManager.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package jmri;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.List;

/**
* Locate a CatalogTree object representing some specific information.
Expand Down
16 changes: 10 additions & 6 deletions java/src/jmri/jmrit/catalog/CatalogTreeFS.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ boolean filter(String ext) {
}
return false;
}

int count = 0;
int leafcount = 0;

/**
* Recursively add nodes to the tree
Expand Down Expand Up @@ -81,8 +84,8 @@ public void insertNodes(String pName, String pPath, CatalogTreeNode pParent) {
insertNodeInto(newElement, pParent, pParent.getChildCount());
String[] sp = fp.list();
for (int i = 0; i < sp.length; i++) {
log.debug("Descend into resource: {}",sp[i]);
insertNodes(sp[i], pPath + "/" + sp[i], newElement);
log.debug("Descend into resource: {} count {}",sp[i], count++);
insertNodes(sp[i], pPath + File.separator + sp[i], newElement);
}
} else /* leaf */ {
String ext = jmri.util.FileChooserFilter.getFileExtension(fp);
Expand All @@ -93,37 +96,38 @@ public void insertNodes(String pName, String pPath, CatalogTreeNode pParent) {
if (index > 0) {
filename = filename.substring(0, index);
}
log.debug("add leaf: {} count {}", filename, leafcount++);
pParent.addLeaf(filename, pPath);
}
}

@Override
public void setProperty(String key, Object value) {
if (parameters == null) {
parameters = new HashMap<String, Object>();
parameters = new HashMap<>();
}
parameters.put(key, value);
}

@Override
public Object getProperty(String key) {
if (parameters == null) {
parameters = new HashMap<String, Object>();
parameters = new HashMap<>();
}
return parameters.get(key);
}

@Override
public java.util.Set<String> getPropertyKeys() {
if (parameters == null) {
parameters = new HashMap<String, Object>();
parameters = new HashMap<>();
}
return parameters.keySet();
}

@Override
public void removeProperty(String key) {
if (parameters == null || key == null) {
if (parameters == null) {
return;
}
parameters.remove(key);
Expand Down
41 changes: 22 additions & 19 deletions java/src/jmri/jmrit/catalog/CatalogTreeNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import java.util.ArrayList;
import java.util.Enumeration;
import javax.swing.tree.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeNode;

/**
* Node of a CatalogTree.
Expand Down Expand Up @@ -32,26 +31,30 @@ public void addLeaf(CatalogTreeLeaf leaf) {
}

/**
* Insert leaf according to height.
* Insert leaf according to height. Dan Boudreau 10/15/2018 eliminated the
* check for valid icon and the sorting of the icons by height. Improves
* load time at initialization by an order of magnitude.
*
* @param name name of the new leaf
* @param path path to the new leaf
*/
public void addLeaf(String name, String path) {
// check path
NamedIcon icon = NamedIcon.getIconByName(path);
if (icon == null) {
log.warn("path \"" + path + "\" is not a NamedIcon.");
return;
}
int h = icon.getIconHeight();
for (int i = 0; i < _leafs.size(); i++) {
CatalogTreeLeaf leaf = _leafs.get(i);
if (h < leaf.getSize()) {
_leafs.add(i + 1, new CatalogTreeLeaf(name, path, h));
return;
}
}
// NamedIcon icon = NamedIcon.getIconByName(path);
// if (icon == null) {
// log.warn("path \" {} \" is not a NamedIcon.", path);
// return;
// }
// int h = icon.getIconHeight();
// log.debug("_leafs size {}", _leafs.size());
// for (int i = 0; i < _leafs.size(); i++) {
// CatalogTreeLeaf leaf = _leafs.get(i);
// if (h < leaf.getSize()) {
// _leafs.add(i + 1, new CatalogTreeLeaf(name, path, h));
// return;
// }
// }
int h = 0;
_leafs.add(new CatalogTreeLeaf(name, path, h));
}

Expand Down Expand Up @@ -109,7 +112,7 @@ public ArrayList<CatalogTreeLeaf> getLeaves(String name) {

@Override
@SuppressWarnings("unchecked")
public Enumeration<TreeNode> children() { // for JDK 9 typing
public Enumeration<TreeNode> children() { // for JDK 9 typing
return super.children();
}

Expand All @@ -125,5 +128,5 @@ public void setLeaves(ArrayList<CatalogTreeLeaf> leafs) {
_leafs = leafs;
}

private final static Logger log = LoggerFactory.getLogger(CatalogTreeNode.class);
// private final static Logger log = LoggerFactory.getLogger(CatalogTreeNode.class);
}

0 comments on commit 21d1271

Please sign in to comment.