Changeset 831 for vanHelsing/trunk/gui/src/de/dass_it/vanhelsing
- Timestamp:
- Mar 4, 2010, 5:43:09 PM (15 years ago)
- Location:
- vanHelsing/trunk/gui/src/de/dass_it/vanhelsing/gui
- Files:
-
- 4 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vanHelsing/trunk/gui/src/de/dass_it/vanhelsing/gui/TreeNavigation.java
r830 r831 1 1 2 package de.dass_it.vanhelsing.gui; 3 4 import javax.swing.tree.DefaultTreeModel; 5 import javax.swing.tree.DefaultMutableTreeNode; 6 import de.dass_it.vanhelsing.gui.items.*; 7 2 8 /* 3 * Helper class to encapsulate all procedures to work with the tree structure. 9 * Helper class to encapsulate all procedure 10 * s to work with the tree structure. 4 11 */ 5 12 public class TreeNavigation extends BeanUtil { 13 private DefaultTreeModel tree; 14 15 public DefaultTreeModel createTree(DefaultMutableTreeNode root, String[] nodes){ 16 17 tree = new DefaultTreeModel(root); 18 for(int i = 0; i< nodes.length; i++){ 19 addNode(root, nodes[i]); 20 } 21 22 23 return tree; 24 } 25 26 public DefaultMutableTreeNode addNode(DefaultMutableTreeNode parent, String type){ 27 DefaultMutableTreeNode node = new DefaultMutableTreeNode(); 28 node.setParent(parent); 29 UserObjectItemType userObject = new UserObjectItemType(node); 30 type = "de.dass_it.vanhelsing.gui.items." + type + "Item"; 31 try { 32 Class myClass = Class.forName(type); 33 UserObjectItem item = (UserObjectItem) myClass.newInstance(); 34 userObject.setUserObjectItem(item); 6 35 36 } catch (ClassNotFoundException e){ 37 System.err.println("Itemclass "+ type +" must be in the classpath"); 38 } catch (InstantiationException e){ 39 System.err.println("Class"+type+"must be a concrete class, not an interface or an abstract class"); 40 } catch (IllegalAccessException e){ 41 System.err.println("Class" + type + " lacks a no-argument constructor"); 42 } 43 return node; 44 45 } 7 46 }
Note:
See TracChangeset
for help on using the changeset viewer.