Package net.alteiar.campaign.player.gui.centerViews.explorer.tree

Source Code of net.alteiar.campaign.player.gui.centerViews.explorer.tree.MyTreeCellRenderer

package net.alteiar.campaign.player.gui.centerViews.explorer.tree;

import java.awt.Component;

import javax.swing.Icon;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;

import net.alteiar.campaign.player.gui.centerViews.explorer.ExplorerIconUtils;
import net.alteiar.campaign.player.gui.centerViews.explorer.PanelDocument;
import net.alteiar.documents.BeanDocument;

public class MyTreeCellRenderer extends DefaultTreeCellRenderer {
  private static final long serialVersionUID = 1L;

  private final PanelDocument panel;

  public MyTreeCellRenderer() {
    panel = new PanelDocument();
  }

  @Override
  public Component getTreeCellRendererComponent(JTree tree, Object value,
      boolean sel, boolean expanded, boolean leaf, int row,
      boolean hasFocus) {

    DocumentNode node = (DocumentNode) value;

    Icon icon = ExplorerIconUtils.getDirClosedIcon(32, 32);
    if (expanded) {
      icon = ExplorerIconUtils.getDirOpenIcon(32, 32);
    }
    if (leaf && !node.getAllowsChildren()) {
      icon = ExplorerIconUtils.getFileIcon(
          (BeanDocument) node.getUserObject(), 32, 32);
    }
    panel.setIcon(icon);
    panel.setBean(node.getUserObject());

    if (sel) {
      panel.setOpaque(true);
    } else {
      panel.setOpaque(false);
    }

    return panel;
  }
}
TOP

Related Classes of net.alteiar.campaign.player.gui.centerViews.explorer.tree.MyTreeCellRenderer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.