final int standard_toolset = 0;
final int wrapper_toolset = 1;
int toolBarType = standard_toolset;
DefaultMutableTreeNode jtreeRoot = new DefaultMutableTreeNode("Weka");
// set up wrapper toolsets
for (int i = 0; i < TOOLBARS.size(); i++) {
Vector tempBarSpecs = (Vector) TOOLBARS.elementAt(i);
// name for the tool bar
String tempToolSetName = (String) tempBarSpecs.elementAt(0);
DefaultMutableTreeNode subTreeNode = new DefaultMutableTreeNode(tempToolSetName);
jtreeRoot.add(subTreeNode);
// Used for weka leaf packages
// Box singletonHolderPanel = null;
// name of the bean component to handle this class of weka algorithms
String tempBeanCompName = (String) tempBarSpecs.elementAt(1);
// a JPanel holding an instantiated bean + label ready to be added
// to the current toolbar
JPanel tempBean;
// the root package for weka algorithms
String rootPackage = "";
weka.gui.HierarchyPropertyParser hpp = null;
Hashtable hpps = null;
// Is this a wrapper toolbar?
if (tempBeanCompName.compareTo("null") != 0) {
tempBean = null;
toolBarType = wrapper_toolset;
rootPackage = (String) tempBarSpecs.elementAt(2);
// hpp = (weka.gui.HierarchyPropertyParser)tempBarSpecs.elementAt(3);
hpps = (Hashtable) tempBarSpecs.elementAt(3);
try {
// modifications by Zerbetto
// Beans.instantiate(null, tempBeanCompName);
Beans.instantiate(this.getClass().getClassLoader(), tempBeanCompName);
// end modifications by Zerbetto
} catch (Exception ex) {
// ignore
System.err.println("[KnowledgeFlow] Failed to instantiate: " + tempBeanCompName);
break;
}
} else {
toolBarType = standard_toolset;
}
// a toolbar to hold buttons---one for each algorithm
// JToolBar tempToolBar = new JToolBar();
// System.err.println(tempToolBar.getLayout());
// tempToolBar.setLayout(new FlowLayout());
int z = 2;
if (toolBarType == wrapper_toolset) {
Enumeration enm = hpps.keys();
while (enm.hasMoreElements()) {
String root = (String) enm.nextElement();
String userPrefix = "";
hpp = (HierarchyPropertyParser) hpps.get(root);
if (!hpp.goTo(rootPackage)) {
System.out.println("[KnowledgeFlow] Processing user package... ");
// System.exit(1);
userPrefix = root + ".";
}
String[] primaryPackages = hpp.childrenValues();
for (int kk = 0; kk < primaryPackages.length; kk++) {
hpp.goToChild(primaryPackages[kk]);
// check to see if this is a leaf - if so then there are no
// sub packages
if (hpp.isLeafReached()) {
/* if (singletonHolderPanel == null) {
singletonHolderPanel = Box.createHorizontalBox();
singletonHolderPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(
tempToolSetName));
} */
String algName = hpp.fullValue();
// -- tempBean = instantiateToolBarBean(true, tempBeanCompName, algName);
Object visibleCheck = instantiateBean((toolBarType == wrapper_toolset),
tempBeanCompName, algName);
//if (tempBean != null) {
if (visibleCheck != null) {
// tempToolBar.add(tempBean);
// singletonHolderPanel.add(tempBean);
/*Object visibleCheck = instantiateBean((toolBarType == wrapper_toolset),
tempBeanCompName, algName); */
if (visibleCheck instanceof BeanContextChild) {
m_bcSupport.add(visibleCheck);
}
ImageIcon scaledForTree = null;
if (visibleCheck instanceof Visible) {
BeanVisual bv = ((Visible)visibleCheck).getVisual();
if (bv != null) {
scaledForTree = new ImageIcon(bv.scale(0.33));
// m_iconLookup.put(algName, scaledForTree);
}
}
JTreeLeafDetails leafData = new JTreeLeafDetails(tempBeanCompName, algName,
scaledForTree);
DefaultMutableTreeNode leafAlgo =
new DefaultMutableTreeNode(leafData);
subTreeNode.add(leafAlgo);
}
hpp.goToParent();
} else {
// make a titledborder JPanel to hold all the schemes in this
// package
// JPanel holderPanel = new JPanel();
/* Box holderPanel = Box.createHorizontalBox();
holderPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(userPrefix +
primaryPackages[kk])); */
DefaultMutableTreeNode firstLevelOfMainAlgoType =
new DefaultMutableTreeNode(primaryPackages[kk]);
subTreeNode.add(firstLevelOfMainAlgoType);
//processPackage(holderPanel, tempBeanCompName, hpp, firstLevelOfMainAlgoType);
processPackage(tempBeanCompName, hpp, firstLevelOfMainAlgoType);
// tempToolBar.add(holderPanel);
}
}
/* if (singletonHolderPanel != null) {
tempToolBar.add(singletonHolderPanel);
singletonHolderPanel = null;
} */
}
} else {
/* Box holderPanel = Box.createHorizontalBox();
holderPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(
tempToolSetName)); */
for (int j = z; j < tempBarSpecs.size(); j++) {
tempBean = null;
tempBeanCompName = (String) tempBarSpecs.elementAt(j);
Object visibleCheck = instantiateBean((toolBarType == wrapper_toolset),
tempBeanCompName, "");
/* -- tempBean = instantiateToolBarBean((toolBarType == wrapper_toolset),
tempBeanCompName, ""); */
//if (tempBean != null) {
if (visibleCheck != null) {
// set tool tip text (if any)
// setToolTipText(tempBean)
// holderPanel.add(tempBean);
String treeName = tempBeanCompName;
if (treeName.lastIndexOf('.') > 0) {
treeName = treeName.substring(treeName.lastIndexOf('.') + 1,
treeName.length());
}
/*Object visibleCheck = instantiateBean((toolBarType == wrapper_toolset),
tempBeanCompName, ""); */
if (visibleCheck instanceof BeanContextChild) {
m_bcSupport.add(visibleCheck);
}
ImageIcon scaledForTree = null;
if (visibleCheck instanceof Visible) {
BeanVisual bv = ((Visible)visibleCheck).getVisual();
if (bv != null) {
scaledForTree = new ImageIcon(bv.scale(0.33));
//m_iconLookup.put(treeName, scaledForTree);
}
}
JTreeLeafDetails leafData = new JTreeLeafDetails(tempBeanCompName, "",
scaledForTree);
DefaultMutableTreeNode fixedLeafNode = new DefaultMutableTreeNode(leafData);
subTreeNode.add(fixedLeafNode);
}
}
// tempToolBar.add(holderPanel);
}
// JScrollPane tempJScrollPane = createScrollPaneForToolBar(tempToolBar);
// ok, now create tabbed pane to hold this toolbar
// m_toolBars.addTab(tempToolSetName, null, tempJScrollPane, tempToolSetName);
}
/// ----
// TODO Prescan for bean plugins and only create user tree node if there
// are actually some beans (rather than just all perspectives)
// Any plugin components to process?
if (BEAN_PLUGINS_PROPERTIES != null &&
BEAN_PLUGINS_PROPERTIES.size() > 0) {
boolean pluginBeans = false;
DefaultMutableTreeNode userSubTree = null;
for (int i = 0; i < BEAN_PLUGINS_PROPERTIES.size(); i++) {
Properties tempP = BEAN_PLUGINS_PROPERTIES.get(i);
JPanel tempBean = null;
String components =
tempP.getProperty("weka.gui.beans.KnowledgeFlow.Plugins");
if (components != null && components.length() > 0) {
if (!pluginBeans) {
// make the Plugins tree node entry
userSubTree = new DefaultMutableTreeNode("Plugins");
jtreeRoot.add(userSubTree);
pluginBeans = true;
}
StringTokenizer st2 = new StringTokenizer(components, ", ");
while (st2.hasMoreTokens()) {
String tempBeanCompName = st2.nextToken().trim();
String treeName = tempBeanCompName;
if (treeName.lastIndexOf('.') > 0) {
treeName = treeName.substring(treeName.lastIndexOf('.') + 1,
treeName.length());
}
// tempBean = instantiateToolBarBean(false, tempBeanCompName, "");
/* if (m_pluginsToolBar == null) {
// need to create the plugins tab and toolbar
setUpPluginsToolBar();
}
m_pluginsBoxPanel.add(tempBean); */
Object visibleCheck = instantiateBean((toolBarType == wrapper_toolset),
tempBeanCompName, "");
if (visibleCheck instanceof BeanContextChild) {
m_bcSupport.add(visibleCheck);
}
ImageIcon scaledForTree = null;
if (visibleCheck instanceof Visible) {
BeanVisual bv = ((Visible)visibleCheck).getVisual();
if (bv != null) {
scaledForTree = new ImageIcon(bv.scale(0.33));
//m_iconLookup.put(tempBeanCompName, scaledForTree);
}
}
JTreeLeafDetails leafData = new JTreeLeafDetails(tempBeanCompName, "",
scaledForTree);
DefaultMutableTreeNode pluginLeaf = new DefaultMutableTreeNode(leafData);
userSubTree.add(pluginLeaf);
}
}
// check for perspectives
String perspectives =
tempP.getProperty(("weka.gui.beans.KnowledgeFlow.Perspectives"));
if (perspectives != null && perspectives.length() > 0) {
StringTokenizer st2 = new StringTokenizer(perspectives, ",");
while (st2.hasMoreTokens()) {
String className = st2.nextToken();
try {
Object p = Class.forName(className).newInstance();
if (p instanceof KFPerspective &&
p instanceof JPanel) {
String title = ((KFPerspective)p).getPerspectiveTitle();
System.out.println("[KnowledgeFlow] loaded perspective: " + title);
PLUGIN_PERSPECTIVES.put(className, title);
// not selected as part of the users set of perspectives yet...
((KFPerspective)p).setLoaded(false);
// check to see if user has selected to use this perspective
if (VISIBLE_PERSPECTIVES.contains(className)) {
// add to the perspective cache. After processing
// all plugins we will iterate over the sorted
// VISIBLE_PERSPECTIVES in order to add them
// to the toolbar in consistent sorted order
//((KFPerspective)p).setMainKFPerspective(m_mainKFPerspective);
PERSPECTIVE_CACHE.put(className, (KFPerspective)p);
}
}
} catch (Exception ex) {
if (m_logPanel != null) {
m_logPanel.logMessage("[KnowledgeFlow] WARNING: " +
"unable to instantiate perspective \""
+ className + "\"");
} else {
System.err.println("[KnowledgeFlow] WARNING: " +
"unable to instantiate perspective \""
+ className + "\"");
}
}
}
}
}
}
m_togglePerspectivesB.setEnabled(PLUGIN_PERSPECTIVES.keySet().size() > 0);
// toolBarPanel.add(m_toolBars, BorderLayout.CENTER);
// add(m_toolBars, BorderLayout.NORTH);
add(toolBarPanel, BorderLayout.NORTH);
DefaultTreeModel model = new DefaultTreeModel(jtreeRoot);
// subclass JTree so that tool tips can be displayed for leaves (if necessary)
m_componentTree = new JTree(model) {
public String getToolTipText(MouseEvent e) {
if ((getRowForLocation(e.getX(), e.getY())) == -1) {
return null;
}
TreePath currPath = getPathForLocation(e.getX(), e.getY());
if (currPath.getLastPathComponent() instanceof DefaultMutableTreeNode) {
DefaultMutableTreeNode node =
(DefaultMutableTreeNode)currPath.getLastPathComponent();
if (node.isLeaf()) {
JTreeLeafDetails leaf = (JTreeLeafDetails)node.getUserObject();
return leaf.getToolTipText();
}
}
return null;
}
};
m_componentTree.setEnabled(true);
m_componentTree.setToolTipText("");
m_componentTree.setRootVisible(false);
m_componentTree.setShowsRootHandles(true);
m_componentTree.setCellRenderer(new BeanIconRenderer());
DefaultTreeSelectionModel selectionModel = new DefaultTreeSelectionModel();
selectionModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
m_componentTree.setSelectionModel(selectionModel);
m_componentTree.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (((e.getModifiers() & InputEvent.BUTTON1_MASK)
!= InputEvent.BUTTON1_MASK) || e.isAltDown()) {
boolean clearSelection = true;
/*TreePath path =
m_componentTree.getPathForLocation(e.getX(), e.getY());
if (path != null) {
DefaultMutableTreeNode tNode =
(DefaultMutableTreeNode)path.getLastPathComponent();
if (tNode.isLeaf()) {
System.out.println("Rick click selection");
// m_componentTree.setSelectionPath(path);
}
}*/
if (clearSelection) {
// right click cancels selected component
m_toolBarBean = null;
m_mode = NONE;
KnowledgeFlowApp.this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
m_componentTree.clearSelection();
}
}
TreePath p = m_componentTree.getSelectionPath();
if (p != null) {
if (p.getLastPathComponent() instanceof DefaultMutableTreeNode) {
DefaultMutableTreeNode tNode = (DefaultMutableTreeNode)p.getLastPathComponent();
if (tNode.isLeaf()) {
// System.err.println("Selected : " + tNode.getUserObject().toString());
Object userObject = tNode.getUserObject();
if (userObject instanceof JTreeLeafDetails) {
if ((e.getModifiers() & InputEvent.SHIFT_MASK) != 0 &&
((JTreeLeafDetails)userObject).isMetaBean()) {
if (m_firstUserComponentOpp) {
installWindowListenerForSavingUserStuff();
m_firstUserComponentOpp = false;
}
Vector toRemove = ((JTreeLeafDetails)userObject).getMetaBean();
DefaultTreeModel model = (DefaultTreeModel) m_componentTree.getModel();
MutableTreeNode userRoot = (MutableTreeNode)tNode.getParent(); // The "User" folder
model.removeNodeFromParent(tNode);
m_userComponents.remove(toRemove);
if (m_userComponents.size() == 0) {
model.removeNodeFromParent(userRoot);