コード例 #1
0
ファイル: Baseline.java プロジェクト: benbac20/jrdesktop
 private static Method getBaselineMethod(JComponent component) {
   if (COMPONENT_BASELINE_METHOD != null) {
     return COMPONENT_BASELINE_METHOD;
   }
   Class klass = component.getClass();
   while (klass != null) {
     if (BASELINE_MAP.containsKey(klass)) {
       Method method = (Method) BASELINE_MAP.get(klass);
       return method;
     }
     klass = klass.getSuperclass();
   }
   klass = component.getClass();
   Method[] methods = klass.getMethods();
   for (int i = methods.length - 1; i >= 0; i--) {
     Method method = methods[i];
     if ("getBaseline".equals(method.getName())) {
       Class[] params = method.getParameterTypes();
       if (params.length == 2 && params[0] == int.class && params[1] == int.class) {
         BASELINE_MAP.put(klass, method);
         return method;
       }
     }
   }
   BASELINE_MAP.put(klass, null);
   return null;
 }
コード例 #2
0
  /**
   * Creates an <code>ComponentUI</code> implementation for the specified component. In other words
   * create the look and feel specific delegate object for <code>target</code>. This is done in two
   * steps:
   *
   * <ul>
   *   <li>Look up the name of the <code>ComponentUI</code> implementation class under the value
   *       returned by <code>target.getUIClassID()</code>.
   *   <li>Use the implementation classes static <code>createUI()</code> method to construct a look
   *       and feel delegate.
   * </ul>
   *
   * @param target the <code>JComponent</code> which needs a UI
   * @return the <code>ComponentUI</code> object
   */
  public ComponentUI getUI(JComponent target) {

    Object cl = get("ClassLoader");
    ClassLoader uiClassLoader =
        (cl != null) ? (ClassLoader) cl : target.getClass().getClassLoader();
    Class<? extends ComponentUI> uiClass = getUIClass(target.getUIClassID(), uiClassLoader);
    Object uiObject = null;

    if (uiClass == null) {
      getUIError("no ComponentUI class for: " + target);
    } else {
      try {
        Method m = (Method) get(uiClass);
        if (m == null) {
          m = uiClass.getMethod("createUI", new Class[] {JComponent.class});
          put(uiClass, m);
        }
        uiObject = MethodUtil.invoke(m, null, new Object[] {target});
      } catch (NoSuchMethodException e) {
        getUIError("static createUI() method not found in " + uiClass);
      } catch (Exception e) {
        getUIError("createUI() failed for " + target + " " + e);
      }
    }

    return (ComponentUI) uiObject;
  }
コード例 #3
0
  /**
   * Method to use when we are needing to see if two sets of components are equal when we are
   * considering them as JavaBeans. If all the properties of each component are equal, then the two
   * sets are equal. 'all the properties' is determined by recursing down to the child components
   *
   * @param components first array of components
   * @param components2 second array of components
   * @param widgetClassifier Provides this method with a definition of a component
   */
  public static boolean equalsByProperties(
      JComponent[] components, JComponent[] components2, WidgetClassifierI widgetClassifier) {
    ReasonNotEquals.addClassVisiting("pUtils.equalsByProperties([])");

    boolean result = true;
    if (components.length != components2.length) {
      ReasonNotEquals.addReason(
          "got lists of components of different sizes: "
              + components.length
              + " and "
              + components2.length);
      result = false;
    } else {
      for (int i = 0; i < components.length; i++) {
        JComponent comp1 = components[i];
        JComponent comp2 = components2[i];
        // not work due to diff classloaders having been used
        // if(comp1.getClass() != comp2.getClass())
        if (!comp1.getClass().getName().equals(comp2.getClass().getName())) {
          ReasonNotEquals.addReason(
              "two components were not of the same class: "
                  + comp1.getClass()
                  + " and "
                  + comp2.getClass());
          result = false;
          break;
        } else {
          result = equalsByProperties(comp1, comp2, widgetClassifier);
          if (!result) {
            ReasonNotEquals.addReason(
                "equalsByProperties() failed for 2 classes of type: " + comp1.getClass().getName());
            break;
          }
        }
      }
    }
    return result;
  }
コード例 #4
0
 public static void installProperty(
     final JComponent c, final String propertyName, final Object propertyValue) {
   if (c.installablePropertiesExcluded.contains(propertyName)) {
     return;
   }
   Method setter = getSetter(propertyName, c.getClass());
   if (setter == null) {
     throw new IllegalArgumentException(
         Messages.getString("swing.51") + propertyName); // $NON-NLS-1$
   }
   try {
     setter.invoke(c, new Object[] {propertyValue});
   } catch (IllegalArgumentException e) {
     throw new ClassCastException();
   } catch (IllegalAccessException e) {
     throw new IllegalArgumentException(
         Messages.getString("swing.51") + propertyName); // $NON-NLS-1$
   } catch (InvocationTargetException e) {
     throw new IllegalArgumentException(
         Messages.getString("swing.51") + propertyName); // $NON-NLS-1$
   }
   c.installablePropertiesExcluded.remove(propertyName);
 }