|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| BeanContextTree.java | 0% | 0% | 0% | 0% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* EJTools, the Enterprise Java Tools
|
|
| 3 |
*
|
|
| 4 |
* Distributable under LGPL license.
|
|
| 5 |
* See terms of license at www.gnu.org.
|
|
| 6 |
*/
|
|
| 7 |
package org.ejtools.adwt;
|
|
| 8 |
|
|
| 9 |
import java.awt.Component;
|
|
| 10 |
|
|
| 11 |
import javax.swing.Icon;
|
|
| 12 |
import javax.swing.JTree;
|
|
| 13 |
import javax.swing.tree.DefaultTreeCellRenderer;
|
|
| 14 |
import javax.swing.tree.TreePath;
|
|
| 15 |
|
|
| 16 |
import org.ejtools.adwt.util.DefaultObjectRenderer;
|
|
| 17 |
import org.ejtools.adwt.util.ObjectIndexer;
|
|
| 18 |
import org.ejtools.adwt.util.ObjectRenderer;
|
|
| 19 |
import org.ejtools.adwt.util.ObjectSearcher;
|
|
| 20 |
import org.ejtools.adwt.util.SearchableTreeModel;
|
|
| 21 |
|
|
| 22 |
/**
|
|
| 23 |
* Description of the Class
|
|
| 24 |
*
|
|
| 25 |
* @author Laurent Etiemble
|
|
| 26 |
* @version $Revision: 1.2 $
|
|
| 27 |
*/
|
|
| 28 |
public class BeanContextTree extends JTree implements ObjectSearcher |
|
| 29 |
{
|
|
| 30 |
/** Description of the Field */
|
|
| 31 |
protected ObjectRenderer renderer = new DefaultObjectRenderer(); |
|
| 32 |
|
|
| 33 |
|
|
| 34 |
/**
|
|
| 35 |
* Constructor for the BeanContextTree object
|
|
| 36 |
*
|
|
| 37 |
* @param newModel Description of the Parameter
|
|
| 38 |
*/
|
|
| 39 | 0 |
public BeanContextTree(SearchableTreeModel newModel)
|
| 40 |
{
|
|
| 41 | 0 |
super(newModel);
|
| 42 |
|
|
| 43 | 0 |
this.setShowsRootHandles(true); |
| 44 | 0 |
this.setExpandsSelectedPaths(true); |
| 45 | 0 |
this.putClientProperty("JTree.lineStyle", "Angled"); |
| 46 |
|
|
| 47 | 0 |
this.setCellRenderer(
|
| 48 |
new DefaultTreeCellRenderer()
|
|
| 49 |
{
|
|
| 50 | 0 |
public Component getTreeCellRendererComponent(JTree jtree, Object obj, boolean flag, boolean flag1, boolean flag2, int i, boolean flag3) |
| 51 |
{
|
|
| 52 | 0 |
try
|
| 53 |
{
|
|
| 54 | 0 |
Icon leafIcon = null;
|
| 55 | 0 |
Icon openIcon = null;
|
| 56 | 0 |
Icon closedIcon = null;
|
| 57 |
|
|
| 58 | 0 |
Icon newIcon = BeanContextTree.this.renderer.getIcon(obj);
|
| 59 |
|
|
| 60 | 0 |
if (newIcon != null) |
| 61 |
{
|
|
| 62 | 0 |
leafIcon = this.getLeafIcon();
|
| 63 | 0 |
openIcon = this.getOpenIcon();
|
| 64 | 0 |
closedIcon = this.getClosedIcon();
|
| 65 | 0 |
this.setLeafIcon(newIcon);
|
| 66 | 0 |
this.setOpenIcon(newIcon);
|
| 67 | 0 |
this.setClosedIcon(newIcon);
|
| 68 |
} |
|
| 69 |
|
|
| 70 | 0 |
super.getTreeCellRendererComponent(jtree, obj, flag, flag1, flag2, i, flag3);
|
| 71 |
|
|
| 72 | 0 |
if (newIcon != null) |
| 73 |
{
|
|
| 74 | 0 |
this.setLeafIcon(leafIcon);
|
| 75 | 0 |
this.setOpenIcon(openIcon);
|
| 76 | 0 |
this.setClosedIcon(closedIcon);
|
| 77 |
} |
|
| 78 |
|
|
| 79 | 0 |
return this; |
| 80 |
} |
|
| 81 |
catch (Exception e)
|
|
| 82 |
{
|
|
| 83 | 0 |
return super.getTreeCellRendererComponent(jtree, obj, flag, flag1, flag2, i, flag3); |
| 84 |
} |
|
| 85 |
} |
|
| 86 |
}); |
|
| 87 |
} |
|
| 88 |
|
|
| 89 |
|
|
| 90 |
/**
|
|
| 91 |
* Description of the Method
|
|
| 92 |
*
|
|
| 93 |
* @param o Description of the Parameter
|
|
| 94 |
* @return Description of the Return Value
|
|
| 95 |
*/
|
|
| 96 | 0 |
public Object find(Object o)
|
| 97 |
{
|
|
| 98 | 0 |
Object r = ((SearchableTreeModel) this.getModel()).find(o);
|
| 99 | 0 |
if (r != null) |
| 100 |
{
|
|
| 101 | 0 |
Object[] paths = (Object[]) r; |
| 102 | 0 |
TreePath path = new TreePath(paths);
|
| 103 | 0 |
this.setSelectionPath(path);
|
| 104 |
} |
|
| 105 | 0 |
return null; |
| 106 |
} |
|
| 107 |
|
|
| 108 |
|
|
| 109 |
/** Description of the Method */
|
|
| 110 | 0 |
public void selectRoot() |
| 111 |
{
|
|
| 112 | 0 |
TreePath path = new TreePath(this.getModel().getRoot()); |
| 113 | 0 |
this.setSelectionPath(path);
|
| 114 |
} |
|
| 115 |
|
|
| 116 |
|
|
| 117 |
/**
|
|
| 118 |
* Sets the indexer attribute of the BeanContextTree object
|
|
| 119 |
*
|
|
| 120 |
* @param indexer The new indexer value
|
|
| 121 |
*/
|
|
| 122 | 0 |
public void setIndexer(ObjectIndexer indexer) |
| 123 |
{
|
|
| 124 | 0 |
((SearchableTreeModel) this.getModel()).setIndexer(indexer);
|
| 125 |
} |
|
| 126 |
|
|
| 127 |
|
|
| 128 |
/**
|
|
| 129 |
* Sets the renderer attribute of the BeanContextTree object
|
|
| 130 |
*
|
|
| 131 |
* @param renderer The new renderer value
|
|
| 132 |
*/
|
|
| 133 | 0 |
public void setRenderer(ObjectRenderer renderer) |
| 134 |
{
|
|
| 135 | 0 |
this.renderer = renderer;
|
| 136 |
} |
|
| 137 |
} |
|
| 138 |
|
|
||||||||||