public static void fillLines(
      List<ViewDefinition> views, List<LineDefinition> lines, ConfigDefinition config) {
    LineDefinition currentLine = new LineDefinition(config);
    lines.add(currentLine);
    final int count = views.size();
    for (int i = 0; i < count; i++) {
      final ViewDefinition child = views.get(i);

      boolean newLine = child.isNewLine() || (config.isCheckCanFit() && !currentLine.canFit(child));
      if (newLine) {
        currentLine = new LineDefinition(config);
        if (config.getOrientation() == CommonLogic.VERTICAL
            && config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
          lines.add(0, currentLine);
        } else {
          lines.add(currentLine);
        }
      }

      if (config.getOrientation() == CommonLogic.HORIZONTAL
          && config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
        currentLine.addView(0, child);
      } else {
        currentLine.addView(child);
      }
    }
  }
  public static int getGravityFromRelative(int childGravity, ConfigDefinition config) {
    // swap directions for vertical non relative view
    // if it is relative, then START is TOP, and we do not need to switch it here.
    // it will be switched later on onMeasure stage when calculations will be with length and
    // thickness
    if (config.getOrientation() == CommonLogic.VERTICAL
        && (childGravity & Gravity.RELATIVE_LAYOUT_DIRECTION) == 0) {
      int horizontalGravity = childGravity;
      childGravity = 0;
      childGravity |=
          (horizontalGravity & Gravity.HORIZONTAL_GRAVITY_MASK)
              >> Gravity.AXIS_X_SHIFT
              << Gravity.AXIS_Y_SHIFT;
      childGravity |=
          (horizontalGravity & Gravity.VERTICAL_GRAVITY_MASK)
              >> Gravity.AXIS_Y_SHIFT
              << Gravity.AXIS_X_SHIFT;
    }

    // for relative layout and RTL direction swap left and right gravity
    if (config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL
        && (childGravity & Gravity.RELATIVE_LAYOUT_DIRECTION) != 0) {
      int ltrGravity = childGravity;
      childGravity = 0;
      childGravity |= (ltrGravity & Gravity.LEFT) == Gravity.LEFT ? Gravity.RIGHT : 0;
      childGravity |= (ltrGravity & Gravity.RIGHT) == Gravity.RIGHT ? Gravity.LEFT : 0;
    }

    return childGravity;
  }
Exemple #3
0
  /** Gets the GUI component for this pane. */
  public JComponent getGUI() {
    if (cwp == null) {
      Object object = mWhiteBoard.get("device_definition");
      Object ctx_obj = mWhiteBoard.get("context");

      if (null != object
          && object instanceof ConfigDefinition
          && null != ctx_obj
          && ctx_obj instanceof ConfigContext) {
        mConfigContext = (ConfigContext) ctx_obj;

        ConfigDefinition def = (ConfigDefinition) object;
        String token = def.getToken();

        // Create a temporary list of ConfigDefinitions to pass to factory.
        java.util.List def_list = new ArrayList();
        def_list.add(def);

        // Initialize a ConfigElementFactory with the needed
        // ConfigDefinition. And create a new ConfigElement.
        ConfigElementFactory temp_factory = new ConfigElementFactory(def_list);
        mConfigElement = temp_factory.create("New " + token, def);

        List list = CustomEditorRegistry.findEditors(token);

        Color start_color = new Color(160, 160, 180);

        Object color = UIManager.get("window");
        if (null != color && color instanceof Color) {
          start_color = (Color) color;
        } else {
          System.out.println("Could not get the desktop color from the  UIManager.");
        }

        // XXX:This will be used after making findEditors -> findEditor
        // if(null != editor)
        if (null == list || list.size() == 0) {
          System.out.println("No CustomEditors registered for token: " + token);

          JScrollPane scroll_pane = new JScrollPane();
          PropertySheet element_prop_sheet =
              PropertySheetFactory.instance()
                  .makeSheet(mConfigContext, mConfigElement, start_color);

          scroll_pane.getViewport().removeAll();
          scroll_pane.getViewport().add(element_prop_sheet, null);
          cwp = scroll_pane;
        } else if (null != list && list.size() > 0) {
          CustomEditor editor = (CustomEditor) list.get(0);
          cwp = (JComponent) editor.getPanel();
          editor.setConfig(mConfigContext, mConfigElement);
        }
      }
    }
    // cwp.init(mWhiteBoard);
    return cwp;
  }
  private static int getGravity(ViewDefinition child, ConfigDefinition config) {
    int parentGravity = config.getGravity();

    int childGravity;
    // get childGravity of child view (if exists)
    if (child != null && child.gravitySpecified()) {
      childGravity = child.getGravity();
    } else {
      childGravity = parentGravity;
    }

    childGravity = getGravityFromRelative(childGravity, config);
    parentGravity = getGravityFromRelative(parentGravity, config);

    // add parent gravity to child gravity if child gravity is not specified
    if ((childGravity & Gravity.HORIZONTAL_GRAVITY_MASK) == 0) {
      childGravity |= parentGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
    }
    if ((childGravity & Gravity.VERTICAL_GRAVITY_MASK) == 0) {
      childGravity |= parentGravity & Gravity.VERTICAL_GRAVITY_MASK;
    }

    // if childGravity is still not specified - set default top - left gravity
    if ((childGravity & Gravity.HORIZONTAL_GRAVITY_MASK) == 0) {
      childGravity |= Gravity.LEFT;
    }
    if ((childGravity & Gravity.VERTICAL_GRAVITY_MASK) == 0) {
      childGravity |= Gravity.TOP;
    }

    return childGravity;
  }
 private static float getWeight(ViewDefinition child, ConfigDefinition config) {
   return child.weightSpecified() ? child.getWeight() : config.getWeightDefault();
 }