Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/memoire/dnd/DndManageProperty.java


1   /**
2    * @modification $Date: 2002/12/16 18:56:25 $
3    * @statut       unstable
4    * @file         DndManageProperty.java
5    * @version      0.36
6    * @author       Guillaume Desnoix
7    * @email        guillaume@desnoix.com
8    * @license      GNU General Public License 2 (GPL2)
9    * @copyright    1998-2001 Guillaume Desnoix
10   */
11  
12  package com.memoire.dnd;
13  import com.memoire.dnd.*;
14  
15  
16  import java.awt.*;
17  import java.lang.reflect.*;
18  import javax.swing.*;
19  
20  public class DndManageProperty
21      implements DndManageData
22  {
23      public static final DndManageProperty SINGLETON=
24    new DndManageProperty();
25  
26      public boolean manage
27    (Object _data,JComponent _component,Point _location)
28      {
29    DndProperty data=(DndProperty)_data;
30    String name =data.getName ();
31    Object value=data.getValue();
32    System.err.println("set-property "+name+": "+value);
33    setProperty(_component,name,value);
34    _component.repaint();
35    return true;
36      }
37  
38      public static final void setProperty
39    (JComponent _comp, String _name, Object _value)
40      {
41    try
42    {
43        String n="set"+_name.substring(0,1).toUpperCase()+
44           _name.substring(1);
45        Class  z=_value.getClass();
46  
47        // System.err.println("$$$ N="+n);
48        
49        try
50        {
51      z=(Class)(z.getField("TYPE").get(z));
52        }
53        catch(Exception ey) { }
54  
55        Class[] c=null;
56        Method  m=null;
57  
58        do
59        {
60      // System.err.println("$$$ Z="+z);
61  
62      c=new Class[] { z };
63      try
64      {
65          m=_comp.getClass().getMethod(n,c);
66      }
67      catch(Exception ey) { m=null; }
68  
69      // System.err.println("$$$ M="+m);
70  
71      z=z.getSuperclass();
72        }
73        while((m==null)&&(z!=null));
74  
75        Object[] o=new Object[] { _value };
76  
77        // System.err.println("$$$ O="+o);
78  
79        m.invoke(_comp,o);
80    }
81    catch(Exception ex)
82    {
83        if(!_name.equals("ancestor"))
84      System.err.println("Property "+_name+
85             " is not writable in "+
86             _comp.getClass().getName()+".");
87    }
88      }
89  }