Пример #1
0
 /**
  * Print Oarent of Component
  *
  * @param c component
  */
 static void printParents(JComponent c) {
   if (c.getName() == null) c.setName("C" + String.valueOf(s_no++));
   System.out.print(c.getName());
   System.out.print(" - " + c.getClass().getName());
   System.out.println(
       " ** "
           + c.isOpaque()
           + " bg="
           + (c.getClientProperty(CompiereLookAndFeel.BACKGROUND) != null));
   //
   Container container = c.getParent();
   while (container != null) {
     System.out.print(
         " - "
             + container.getName()
             + " "
             + container.getClass().getName()
             + " ** "
             + container.isOpaque());
     if (container instanceof JComponent)
       System.out.print(
           " bg="
               + (((JComponent) container).getClientProperty(CompiereLookAndFeel.BACKGROUND)
                   != null));
     System.out.println();
     container = container.getParent();
   }
 } //  printParents
Пример #2
0
 private static void setComponentName(JComponent component, String name) {
   if (component != null) {
     Container parent = component.getParent();
     if (parent != null) {
       component.setName(parent.getName() + "." + name);
     } else {
       component.setName(name);
     }
   }
 }
Пример #3
0
  public static boolean equalsByProperties(
      JComponent component1, JComponent component2, WidgetClassifierI widgetClassifier) {
    ReasonNotEquals.addClassVisiting("pUtils.equalsByProperties()");

    boolean result = true;
    List oneControls = getAllControls(component1);
    oneControls.add(0, component1);

    List twoControls = getAllControls(component2);
    twoControls.add(0, component2);
    if (oneControls.size() != twoControls.size()) {
      ReasonNotEquals.addReason(
          "got lists of controls of different sizes: "
              + oneControls.size()
              + " and "
              + twoControls.size());
      Print.prList(oneControls, "oneControls");
      Print.prList(twoControls, "twoControls");
      result = false;
    } else {
      for (int i = 0; i < oneControls.size(); i++) {
        Container comp1 = (Container) oneControls.get(i);
        // Err.pr( "Observing a " + comp1.getClass());
        Container comp2 = (Container) twoControls.get(i);
        if (comp1.getClass() != comp2.getClass()) {
          ReasonNotEquals.addReason(
              "first component is of type "
                  + comp1.getClass()
                  + " while second is of type "
                  + comp2.getClass());
          result = false;
          break;
        } else if (!Utils.equals(comp1.getName(), comp2.getName())) {
          ReasonNotEquals.addReason(
              "first component has name "
                  + comp1.getName()
                  + " while second has name "
                  + comp2.getName());
          result = false;
          break;
        } else if (widgetClassifier != null
            && !widgetClassifier.isAWidget(
                comp1.getClass())) { // If a comp1/comp2 is not a widget then end up here and we
          // won't examine
          // its properties
          // Err.pr( comp1.getClass() + " is not a widget: " + widgetClassifier.getReason());
        } else {
          List propertyNamesOne = new ArrayList();
          List propertyNamesTwo = new ArrayList();
          List propertyValuesOne = new ArrayList();
          List propertyValuesTwo = new ArrayList();
          loadPropertyNamesValues(comp1.getClass(), comp1, propertyNamesOne, propertyValuesOne);
          loadPropertyNamesValues(comp2.getClass(), comp2, propertyNamesTwo, propertyValuesTwo);
          if (propertyNamesOne.size() != propertyValuesOne.size()) {
            Err.error("expect names and properties to be same size for " + comp1.getClass());
          } else if (propertyNamesTwo.size() != propertyValuesTwo.size()) {
            Err.error("expect names and properties to be same size for " + comp2.getClass());
          } else if (propertyNamesOne.size() != propertyNamesTwo.size()) {
            ReasonNotEquals.addReason(
                "there should be an equal number of properties in "
                    + comp1.getClass()
                    + " and "
                    + comp2.getClass());
            result = false;
            break;
          } else {
            // Err.pr( "Will be examining properties from a " + comp1.getClass() + " against " +
            // comp2.getClass());
            for (int j = 0; j < propertyNamesOne.size(); j++) {
              String onePropName = (String) propertyNamesOne.get(j);
              String twoPropName = (String) propertyNamesTwo.get(j);
              if (!onePropName.equals(twoPropName)) {
                // If they are of thge same type, how could they possibly have
                // different property names, thus make this an error
                String txt =
                    "expect property names to be equal, got " + onePropName + " and " + twoPropName;
                // ReasonNotEquals.addReason( txt);
                Err.error(txt);
                result = false;
                break;
              } else {
                Object onePropValue = propertyValuesOne.get(j);
                Object twoPropValue = propertyValuesTwo.get(j);
                boolean debug = false;
                /*
                if(onePropName.equals( "text"))
                {
                Err.debug();
                debug = true;
                }
                */
                if (onePropValue.getClass() != twoPropValue.getClass()) {
                  Err.error(
                      "Property values to be examining should be of the same type, got "
                          + onePropValue.getClass().getName()
                          + " and "
                          + twoPropValue.getClass().getName());
                  result = false;
                  break;
                } else if (!Utils.isSimple(onePropValue.getClass())) {
                  // We only want to do value comparisons for simple types
                  // Err.pr( "Not simple: <" + onePropValue + ">");
                  if (debug) {
                    Err.error("Only supposed to be debugging on a simple property value");
                  }
                } else {
                  if (debug) {
                    Err.pr(
                        "Doing cf between <"
                            + onePropValue
                            + "> and <"
                            + twoPropValue
                            + "> for "
                            + onePropName
                            + " in a "
                            + comp1.getClass());
                    debug = false;
                  }
                  if (!onePropValue.equals(twoPropValue)) {
                    ReasonNotEquals.addReason(
                        "expect property values to be equal, got <"
                            + onePropValue
                            + "> and <"
                            + twoPropValue
                            + ">");
                    result = false;
                    break;
                  } else { // Err.pr( "\tconcordance, prop name " + onePropName + ", prop value " +
                    // onePropValue);
                  }
                }
              }
            }
            if (result == false) {
              break; // so break out of outer loop too
            }
          }
        }
      }
    }
    return result;
  }