Skip to content
Permalink
Browse files

Merge pull request #6004 from DanielBoudreau/master

Improve initialization time by eliminating the confirmation of icon
  • Loading branch information...
DanielBoudreau committed Oct 15, 2018
2 parents 08bfeee + 21d1271 commit d4ea4254cf86bb81cee87b60f7b3396884b05f70
@@ -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.
@@ -49,6 +49,9 @@ boolean filter(String ext) {
}
return false;
}

int count = 0;
int leafcount = 0;

/**
* Recursively add nodes to the tree
@@ -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);
@@ -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);
@@ -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.
@@ -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));
}

@@ -109,7 +112,7 @@ public CatalogTreeLeaf getLeaf(String name, String path) {

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

@@ -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 d4ea425

Please sign in to comment.
You can’t perform that action at this time.