Search in sources :

Example 1 with IconTreeListItem

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;
}
Also used : Enumeration(java.util.Enumeration) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath) IEntity(de.gurkenlabs.litiengine.entities.IEntity) IconTreeListItem(de.gurkenlabs.utiliti.swing.IconTreeListItem) Rectangle(java.awt.Rectangle)

Example 2 with IconTreeListItem

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();
}
Also used : Emitter(de.gurkenlabs.litiengine.graphics.particles.Emitter) Creature(de.gurkenlabs.litiengine.entities.Creature) Trigger(de.gurkenlabs.litiengine.entities.Trigger) StaticShadow(de.gurkenlabs.litiengine.graphics.StaticShadow) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Prop(de.gurkenlabs.litiengine.entities.Prop) MapArea(de.gurkenlabs.litiengine.environment.tilemap.MapArea) IconTreeListItem(de.gurkenlabs.utiliti.swing.IconTreeListItem) LightSource(de.gurkenlabs.litiengine.graphics.LightSource) Spawnpoint(de.gurkenlabs.litiengine.environment.tilemap.Spawnpoint) CollisionBox(de.gurkenlabs.litiengine.entities.CollisionBox)

Aggregations

IconTreeListItem (de.gurkenlabs.utiliti.swing.IconTreeListItem)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 CollisionBox (de.gurkenlabs.litiengine.entities.CollisionBox)1 Creature (de.gurkenlabs.litiengine.entities.Creature)1 IEntity (de.gurkenlabs.litiengine.entities.IEntity)1 Prop (de.gurkenlabs.litiengine.entities.Prop)1 Trigger (de.gurkenlabs.litiengine.entities.Trigger)1 MapArea (de.gurkenlabs.litiengine.environment.tilemap.MapArea)1 Spawnpoint (de.gurkenlabs.litiengine.environment.tilemap.Spawnpoint)1 LightSource (de.gurkenlabs.litiengine.graphics.LightSource)1 StaticShadow (de.gurkenlabs.litiengine.graphics.StaticShadow)1 Emitter (de.gurkenlabs.litiengine.graphics.particles.Emitter)1 Rectangle (java.awt.Rectangle)1 Enumeration (java.util.Enumeration)1 TreePath (javax.swing.tree.TreePath)1