< prev index next >

src/java.desktop/share/classes/javax/swing/TransferHandler.java

Print this page


   1 /*
   2  * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


1050     protected void exportDone(JComponent source, Transferable data, int action) {
1051     }
1052 
1053     /**
1054      * Fetches the property descriptor for the property assigned to this transfer
1055      * handler on the given component (transfer handler may be shared).  This
1056      * returns <code>null</code> if the property descriptor can't be found
1057      * or there is an error attempting to fetch the property descriptor.
1058      */
1059     private PropertyDescriptor getPropertyDescriptor(JComponent comp) {
1060         if (propertyName == null) {
1061             return null;
1062         }
1063         Class<?> k = comp.getClass();
1064         BeanInfo bi;
1065         try {
1066             bi = Introspector.getBeanInfo(k);
1067         } catch (IntrospectionException ex) {
1068             return null;
1069         }
1070         PropertyDescriptor props[] = bi.getPropertyDescriptors();
1071         for (int i=0; i < props.length; i++) {
1072             if (propertyName.equals(props[i].getName())) {
1073                 Method reader = props[i].getReadMethod();
1074 
1075                 if (reader != null) {
1076                     Class<?>[] params = reader.getParameterTypes();
1077 
1078                     if (params == null || params.length == 0) {
1079                         // found the desired descriptor
1080                         return props[i];
1081                     }
1082                 }
1083             }
1084         }
1085         return null;
1086     }
1087 
1088     /**
1089      * Fetches the data flavor from the array of possible flavors that
1090      * has data of the type represented by property type.  Null is


   1 /*
   2  * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


1050     protected void exportDone(JComponent source, Transferable data, int action) {
1051     }
1052 
1053     /**
1054      * Fetches the property descriptor for the property assigned to this transfer
1055      * handler on the given component (transfer handler may be shared).  This
1056      * returns <code>null</code> if the property descriptor can't be found
1057      * or there is an error attempting to fetch the property descriptor.
1058      */
1059     private PropertyDescriptor getPropertyDescriptor(JComponent comp) {
1060         if (propertyName == null) {
1061             return null;
1062         }
1063         Class<?> k = comp.getClass();
1064         BeanInfo bi;
1065         try {
1066             bi = Introspector.getBeanInfo(k);
1067         } catch (IntrospectionException ex) {
1068             return null;
1069         }
1070         PropertyDescriptor[] props = bi.getPropertyDescriptors();
1071         for (int i=0; i < props.length; i++) {
1072             if (propertyName.equals(props[i].getName())) {
1073                 Method reader = props[i].getReadMethod();
1074 
1075                 if (reader != null) {
1076                     Class<?>[] params = reader.getParameterTypes();
1077 
1078                     if (params == null || params.length == 0) {
1079                         // found the desired descriptor
1080                         return props[i];
1081                     }
1082                 }
1083             }
1084         }
1085         return null;
1086     }
1087 
1088     /**
1089      * Fetches the data flavor from the array of possible flavors that
1090      * has data of the type represented by property type.  Null is


< prev index next >