001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.dialogs; 003 004import javax.swing.JLabel; 005import javax.swing.tree.DefaultMutableTreeNode; 006 007import org.openstreetmap.josm.command.PseudoCommand; 008 009/** 010 * MutableTreeNode implementation for Command list JTree 011 */ 012public class CommandListMutableTreeNode extends DefaultMutableTreeNode { 013 014 protected final transient PseudoCommand cmd; 015 016 /** 017 * Constructs a new {@code CommandListMutableTreeNode}. 018 * @param cmd command 019 */ 020 public CommandListMutableTreeNode(PseudoCommand cmd) { 021 super(new JLabel(cmd.getDescriptionText(), cmd.getDescriptionIcon(), JLabel.HORIZONTAL)); 022 this.cmd = cmd; 023 } 024 025 /** 026 * Returns the command. 027 * @return the command 028 */ 029 public PseudoCommand getCommand() { 030 return cmd; 031 } 032 033 /** 034 * Returns the index. 035 * @return the index 036 */ 037 public int getIndex() { 038 return getParent().getIndex(this); 039 } 040 041 @Override 042 public String toString() { 043 return cmd.getDescriptionText(); 044 } 045}