/*
This file is part of the software framework JStatCom,
a library for building applications for data based analysis.
Copyright (C) 2000-2005 Markus Kraetzig
This library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
*/
package com.jstatcom.project;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.tree.DefaultMutableTreeNode;
/**
* A tree node that represents a loaded JStatCom module. It is used by the
* project tree component.
*
* @author Markus Kraetzig
*/
public final class ModuleTreeNode extends DefaultMutableTreeNode {
private final AbstractAction action;
/**
* Creates a module tree node with an action that is invoked from the
* project tree it belongs to. All information about the represented module
* is retrieved from the parameter action.
*
* @param action
* the action to be invoked in the doAction method
* @throws IllegalArgumentException
* if (action == null)
*/
public ModuleTreeNode(AbstractAction action) {
if (action == null)
throw new IllegalArgumentException("Argument was null.");
this.action = action;
setAllowsChildren(false);
}
/**
* Gets the module name. It is retrieved from the underlying action.
*
* @return module name
*/
public String getName() {
return (String) action.getValue(Action.NAME);
}
/**
* Gets the string representation of this.
*
* @return descriptive string, used by display
*/
public String toString() {
return action.getValue(Action.NAME) + "";
}
/**
* Gets the module icon. It is retrieved from the underlying action.
*
* @return module icon
*/
Icon getIcon() {
Object o = action.getValue(Action.SMALL_ICON);
if (o instanceof Icon)
return (Icon) o;
return null;
}
/**
* Invokes the underlying action. Used by project tree on a mouse click over
* this node.
*
*/
public void doAction() {
action.actionPerformed(null);
}
}
Ads help maintain this website.