use of de.gurkenlabs.utiliti.swing.IconTreeListItem in project litiengine by gurkenlabs.
the class MapSelectionPanel method select.
private boolean select(DefaultMutableTreeNode parent, Predicate<IEntity> selectionPredicate) {
if (parent.getChildCount() == 0) {
return false;
}
Enumeration en = parent.depthFirstEnumeration();
while (en.hasMoreElements()) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) en.nextElement();
IEntity ent = null;
if (node.getUserObject() instanceof IconTreeListItem) {
IconTreeListItem iconItem = (IconTreeListItem) node.getUserObject();
if (iconItem.getUserObject() instanceof IEntity) {
ent = (IEntity) iconItem.getUserObject();
}
} else if (node.getUserObject() instanceof IEntity) {
ent = (IEntity) node.getUserObject();
}
if (ent == null) {
continue;
}
if (selectionPredicate.test(ent)) {
final TreePath newSelection = new TreePath(node.getPath());
if (this.tree.getSelectionPath() != null && this.tree.getSelectionPath().equals(newSelection)) {
continue;
}
this.tree.setSelectionPath(newSelection);
TreePath path = this.tree.getSelectionPath();
if (path == null || !this.tree.isVisible()) {
return false;
}
Rectangle bounds = this.tree.getPathBounds(path);
if (bounds == null) {
return false;
}
// set the height to the visible height to force the node to top
bounds.height = this.tree.getVisibleRect().height;
this.tree.scrollRectToVisible(bounds);
return true;
}
}
return false;
}
use of de.gurkenlabs.utiliti.swing.IconTreeListItem in project litiengine by gurkenlabs.
the class MapSelectionPanel method populateMapObjectTree.
private void populateMapObjectTree() {
this.nodeRoot.setUserObject(new IconTreeListItem(Game.getEnvironment().getEntities().size() + " " + Resources.get("panel_mapselection_entities"), Icons.FOLDER));
for (DefaultMutableTreeNode node : this.entityNodes) {
node.removeAllChildren();
}
this.nodeLights.setUserObject(new IconTreeListItem(Game.getEnvironment().getLightSources().size() + " " + Resources.get("panel_mapselection_lights"), Icons.LIGHT));
this.nodeProps.setUserObject(new IconTreeListItem(Game.getEnvironment().getProps().size() + " " + Resources.get("panel_mapselection_props"), Icons.PROP));
this.nodeCreatures.setUserObject(new IconTreeListItem(Game.getEnvironment().getCreatures().size() + " " + Resources.get("panel_mapselection_creatures"), Icons.CREATURE));
this.nodeTriggers.setUserObject(new IconTreeListItem(Game.getEnvironment().getTriggers().size() + " " + Resources.get("panel_mapselection_triggers"), Icons.TRIGGER));
this.nodeSpawnpoints.setUserObject(new IconTreeListItem(Game.getEnvironment().getSpawnPoints().size() + " " + Resources.get("panel_mapselection_spawnpoints"), Icons.SPAWMPOINT));
this.nodeCollisionBoxes.setUserObject(new IconTreeListItem(Game.getEnvironment().getCollisionBoxes().size() + " " + Resources.get("panel_mapselection_collboxes"), Icons.COLLISIONBOX));
this.nodeMapAreas.setUserObject(new IconTreeListItem(Game.getEnvironment().getAreas().size() + " " + Resources.get("panel_mapselection_areas"), Icons.MAPAREA));
this.nodeStaticShadows.setUserObject(new IconTreeListItem(Game.getEnvironment().getStaticShadows().size() + " " + Resources.get("panel_mapselection_shadow"), Icons.SHADOWBOX));
this.nodeEmitter.setUserObject(new IconTreeListItem(Game.getEnvironment().getEmitters().size() + " " + Resources.get("panel_mapselection_emitter"), Icons.EMITTER));
for (LightSource light : Game.getEnvironment().getLightSources()) {
DefaultMutableTreeNode node = new DefaultMutableTreeNode(new IconTreeListItem(light));
this.nodeLights.add(node);
}
for (Prop prop : Game.getEnvironment().getProps()) {
DefaultMutableTreeNode node = new DefaultMutableTreeNode(new IconTreeListItem(prop));
this.nodeProps.add(node);
}
for (Creature creature : Game.getEnvironment().getCreatures()) {
DefaultMutableTreeNode node = new DefaultMutableTreeNode(new IconTreeListItem(creature));
this.nodeCreatures.add(node);
}
for (Trigger trigger : Game.getEnvironment().getTriggers()) {
DefaultMutableTreeNode node = new DefaultMutableTreeNode(new IconTreeListItem(trigger));
this.nodeTriggers.add(node);
}
for (Spawnpoint spawn : Game.getEnvironment().getSpawnPoints()) {
DefaultMutableTreeNode node = new DefaultMutableTreeNode(new IconTreeListItem(spawn));
this.nodeSpawnpoints.add(node);
}
for (CollisionBox coll : Game.getEnvironment().getCollisionBoxes()) {
DefaultMutableTreeNode node = new DefaultMutableTreeNode(new IconTreeListItem(coll));
this.nodeCollisionBoxes.add(node);
}
for (MapArea area : Game.getEnvironment().getAreas()) {
DefaultMutableTreeNode node = new DefaultMutableTreeNode(new IconTreeListItem(area));
this.nodeMapAreas.add(node);
}
for (StaticShadow shadow : Game.getEnvironment().getStaticShadows()) {
DefaultMutableTreeNode node = new DefaultMutableTreeNode(new IconTreeListItem(shadow));
this.nodeStaticShadows.add(node);
}
for (Emitter emitter : Game.getEnvironment().getEmitters()) {
DefaultMutableTreeNode node = new DefaultMutableTreeNode(new IconTreeListItem(emitter));
this.nodeEmitter.add(node);
}
this.entitiesTreeModel.reload();
}
Aggregations