|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| ObjectWrapper.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.util;
|
|
| 8 |
|
|
| 9 |
import java.awt.Component;
|
|
| 10 |
import java.beans.BeanInfo;
|
|
| 11 |
import java.beans.Introspector;
|
|
| 12 |
import java.beans.beancontext.BeanContextChildComponentProxy;
|
|
| 13 |
import java.beans.beancontext.BeanContextContainerProxy;
|
|
| 14 |
import java.lang.reflect.Method;
|
|
| 15 |
|
|
| 16 |
import javax.swing.Icon;
|
|
| 17 |
import javax.swing.ImageIcon;
|
|
| 18 |
import javax.swing.JLabel;
|
|
| 19 |
|
|
| 20 |
/**
|
|
| 21 |
* @author Laurent Etiemble
|
|
| 22 |
* @version $Revision: 1.3 $
|
|
| 23 |
*/
|
|
| 24 |
public class ObjectWrapper implements BeanContextChildComponentProxy |
|
| 25 |
{
|
|
| 26 |
/** Description of the Field */
|
|
| 27 |
private Icon icon;
|
|
| 28 |
/** Description of the Field */
|
|
| 29 |
private Object object;
|
|
| 30 |
/** Description of the Field */
|
|
| 31 |
private String text;
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
/**
|
|
| 35 |
* Constructor for the ContextNode object
|
|
| 36 |
*
|
|
| 37 |
* @param object Description of the Parameter
|
|
| 38 |
*/
|
|
| 39 | 0 |
public ObjectWrapper(Object object)
|
| 40 |
{
|
|
| 41 | 0 |
this.object = object;
|
| 42 | 0 |
try
|
| 43 |
{
|
|
| 44 | 0 |
BeanInfo beaninfo = Introspector.getBeanInfo(this.object.getClass());
|
| 45 | 0 |
if (beaninfo.getIcon(BeanInfo.ICON_COLOR_16x16) != null) |
| 46 |
{
|
|
| 47 | 0 |
this.icon = new ImageIcon(beaninfo.getIcon(BeanInfo.ICON_COLOR_16x16)); |
| 48 |
} |
|
| 49 |
|
|
| 50 | 0 |
Method method = this.object.getClass().getMethod("toString", new Class[0]); |
| 51 | 0 |
if (method.getDeclaringClass().equals(Object.class)) |
| 52 |
{
|
|
| 53 | 0 |
this.text = beaninfo.getBeanDescriptor().getDisplayName();
|
| 54 |
} |
|
| 55 |
} |
|
| 56 |
catch (Exception exception)
|
|
| 57 |
{
|
|
| 58 | 0 |
exception.printStackTrace(); |
| 59 |
} |
|
| 60 |
} |
|
| 61 |
|
|
| 62 |
|
|
| 63 |
/**
|
|
| 64 |
* Gets the Component attribute of the ContextNode object
|
|
| 65 |
*
|
|
| 66 |
* @return The Component value
|
|
| 67 |
*/
|
|
| 68 | 0 |
public Component getComponent()
|
| 69 |
{
|
|
| 70 | 0 |
if (this.object instanceof Component) |
| 71 |
{
|
|
| 72 | 0 |
return (Component) this.object; |
| 73 |
} |
|
| 74 | 0 |
if (this.object instanceof BeanContextContainerProxy) |
| 75 |
{
|
|
| 76 | 0 |
return ((BeanContextContainerProxy) this.object).getContainer(); |
| 77 |
} |
|
| 78 | 0 |
if (this.object instanceof BeanContextChildComponentProxy) |
| 79 |
{
|
|
| 80 | 0 |
return ((BeanContextChildComponentProxy) this.object).getComponent(); |
| 81 |
} |
|
| 82 |
else
|
|
| 83 |
{
|
|
| 84 | 0 |
return new JLabel("No GUI available for this service", 0); |
| 85 |
} |
|
| 86 |
} |
|
| 87 |
|
|
| 88 |
|
|
| 89 |
/**
|
|
| 90 |
* Returns the icon.
|
|
| 91 |
*
|
|
| 92 |
* @return Icon
|
|
| 93 |
*/
|
|
| 94 | 0 |
public Icon getIcon()
|
| 95 |
{
|
|
| 96 | 0 |
return this.icon; |
| 97 |
} |
|
| 98 |
|
|
| 99 |
|
|
| 100 |
/**
|
|
| 101 |
* Gets the UserObject attribute of the ContextNode object
|
|
| 102 |
*
|
|
| 103 |
* @return The UserObject value
|
|
| 104 |
*/
|
|
| 105 | 0 |
public Object getUserObject()
|
| 106 |
{
|
|
| 107 | 0 |
return this.object; |
| 108 |
} |
|
| 109 |
|
|
| 110 |
|
|
| 111 |
/**
|
|
| 112 |
* Description of the Method
|
|
| 113 |
*
|
|
| 114 |
* @return Description of the Returned Value
|
|
| 115 |
*/
|
|
| 116 | 0 |
public String toString()
|
| 117 |
{
|
|
| 118 | 0 |
return this.text != null ? this.text : this.object.toString(); |
| 119 |
} |
|
| 120 |
} |
|
| 121 |
|
|
||||||||||