Exemplo n.º 1
0
 public static void registerWidgetByName(String name, View widget) {
   utilSys.objectSacPut("javaj." + name, widget);
   getListOfWidgetNames().add(name);
   if (log_widgetRegister.isDebugging(2)) {
     log_widgetRegister.dbg(
         2, "register", "add", new String[] {name, widget.getClass().toString()});
   }
 }
Exemplo n.º 2
0
  /**
   * Lays out the container in the specified container.
   *
   * @param parent the component which needs to be laid out
   */
  public void layoutContainer(int posX0, int posY0, int posX1, int posY1) {
    // isPrecalculated = false;
    if (log.isDebugging(4)) log.dbg(4, "layoutContainer", lay.getName());

    precalculateAll();

    // synchronized (parent.getTreeLock())
    {
      // if (log.isDebugging(4))
      //   log.dbg (4, "layoutContainer", "insets left right =" + insets.left + ", " + insets.right
      // + " top bottom " + insets.top + ", " + insets.bottom);

      // Total parent dimensions
      int parDx = posX1 - posX0;
      int parDy = posY1 - posY0;

      if (log.isDebugging(4)) log.dbg(4, "layoutContainer", "parent size =" + parDx + ", " + parDy);

      int repartH = parDx - fijoH;
      int repartV = parDy - fijoV;

      int[] HextraPos = new int[HdimPref.length];
      int[] VextraPos = new int[VdimPref.length];

      if (log.isDebugging(4))
        log.dbg(4, "layoutContainer", "repartH=" + repartH + " repartV=" + repartV);

      // repartir H
      if (columnsReparto.size() > 0) {
        repartH /= columnsReparto.size();
        for (int ii = 0; ii < columnsReparto.size(); ii++) {
          int indx = ((int[]) columnsReparto.get(ii))[0];
          HdimPref[indx] = repartH;
          for (int res = indx + 1; res < nColumns(); res++) HextraPos[res] += repartH;
        }
      }

      // repartir V
      if (rowsReparto.size() > 0) {
        repartV /= rowsReparto.size();
        for (int ii = 0; ii < rowsReparto.size(); ii++) {
          int indx = ((int[]) rowsReparto.get(ii))[0];
          VdimPref[indx] = repartV;
          for (int res = indx + 1; res < nRows(); res++) VextraPos[res] += repartV;
        }
      }

      for (int co = 0; co < getChildCount(); co++) {
        View vi = getChildAt(co);
        LayoutParams lp = (EvaLayout.LayoutParams) vi.getLayoutParams();

        if (log.isDebugging(4)) log.dbg(4, "layoutContainer", "element [" + lp.name + "]");
        // System.out.println ("componente " + lp.name);

        if (!lp.isLaidOut) continue;

        // System.out.println ("   indices " + lp.posCol0 + " (" + Hpos[lp.posCol0] + " extras " +
        // HextraPos[lp.posCol0] + ")");

        int x = Hpos[lp.posCol0] + HextraPos[lp.posCol0];
        int y = Vpos[lp.posRow0] + VextraPos[lp.posRow0];
        int dx = 0;
        int dy = 0;

        // if (log.isDebugging(4))
        //    log.dbg (4, "SIGUEY", "1) y = " + y + " Vpos[lp.posRow0] = " + Vpos[lp.posRow0] + "
        // VextraPos[lp.posRow0] = " + VextraPos[lp.posRow0]);

        for (int mm = lp.posCol0; mm <= lp.posCol1; mm++) {
          if (mm != lp.posCol0) dx += Hgap;
          dx += HdimPref[mm];
        }
        for (int mm = lp.posRow0; mm <= lp.posRow1; mm++) {
          if (mm != lp.posRow0) dy += Vgap;
          dy += VdimPref[mm];
        }

        if (x < 0 || y < 0 || dx < 0 || dy < 0) {
          // Disable this warning because it happens very often when minimizing the window etc
          // log.warn ("layoutContainer", "component not laid out! [" + lp.name + "] (" + x + ", " +
          // y + ") (" + dx + ", " + dy + ")");
          continue;
        }

        // vi.setWidth (dx);
        // vi.setHeight (dy);
        setMeasuredDimension(dx, dy);
        vi.layout(x, y, x + dx, y + dy);
        if (log.isDebugging(4))
          log.dbg(
              4,
              "layoutContainer",
              "vi.name [" + lp.name + "] (" + x + ", " + y + ") (" + dx + ", " + dy + ")");
      }
    } // end synchronized
  }
Exemplo n.º 3
0
  private void precalculateAll() {
    if (isPrecalculated) return;
    if (!checkLayoutInfo()) {
      log.err("checkLayoutInfo", "layout [" + lay.getName() + "] is not of type EVA");
      // do not return! some variables has to be initialized anyway
    }

    log.dbg(2, "precalculateAll", "layout " + lay.getName() + " perform precalculation.");

    Hmargin = Math.max(0, stdlib.atoi(lay.getValue(0, 1)));
    Vmargin = Math.max(0, stdlib.atoi(lay.getValue(0, 2)));
    Hgap = Math.max(0, stdlib.atoi(lay.getValue(0, 3)));
    Vgap = Math.max(0, stdlib.atoi(lay.getValue(0, 4)));

    log.dbg(4, "precalculateAll", nColumns() + " columns x " + nRows() + " rows");
    log.dbg(
        4,
        "precalculateAll",
        "margins xm=" + Hmargin + ", ym=" + Vmargin + ", yg=" + Hgap + ", yg=" + Vgap);

    mnCols = -1; // reset cached number of cols
    mnRows = -1; // reset cached number of rows

    HdimMin = new int[nColumns()];
    HdimPref = new int[nColumns()];
    Hpos = new int[nColumns()];
    VdimMin = new int[nRows()];
    VdimPref = new int[nRows()];
    Vpos = new int[nRows()];

    columnsReparto = new Vector();
    rowsReparto = new Vector();

    // for all components ...
    int count = getChildCount();
    for (int i = 0; i < count; i++) {
      View child = getChildAt(i);
      // if (child.getVisibility() != GONE)
      EvaLayout.LayoutParams lp = (EvaLayout.LayoutParams) child.getLayoutParams();
      lp.isLaidOut = false;
    }

    // compute Vdim (Note: it might be precalculated if needed)
    fijoV = Vmargin;
    for (int rr = 0; rr < nRows(); rr++) {
      String heaRow = rowHeader(rr);
      int typ = headType(heaRow);
      int gap = (rr == 0) ? 0 : Vgap;

      if (typ == HEADER_ORIGINAL) {
        // maximum-minimum of the row
        VdimPref[rr] = minHeightOfRow(rr, true);
        VdimMin[rr] = minHeightOfRow(rr, false);
        log.dbg(2, "precalculateAll", "Adaption... VdimPref[rr] = " + VdimPref[rr]);
      } else if (typ == HEADER_EXPAND) {
        rowsReparto.add(new int[] {rr}); // compute later
        log.dbg(2, "precalculateAll", "Expand... VdimPref[rr] = " + VdimPref[rr]);
      } else {
        // indicated size
        VdimPref[rr] = VdimMin[rr] = stdlib.atoi(heaRow);
        log.dbg(2, "precalculateAll", "Explicit... VdimPref[rr] = " + VdimPref[rr]);
      }

      Vpos[rr] = fijoV + gap;
      fijoV += VdimPref[rr];
      fijoV += gap;
    }
    fijoV += Vmargin;
    log.dbg(2, "precalculateAll", "fijoV = " + fijoV + " Vmargin = " + Vmargin + " Vgap = " + Vgap);

    // DEBUG ....
    if (log.isDebugging(2)) {
      String vertical = "Vertical array (posY/prefHeight/minHeight)";
      for (int rr = 0; rr < Vpos.length; rr++)
        vertical += "  " + rr + ") " + Vpos[rr] + "/" + VdimPref[rr] + "/" + VdimMin[rr];

      log.dbg(2, "precalculateAll", vertical);
    }

    // compute Hdim (Note: it might be precalculated if needed)
    fijoH = Hmargin;
    for (int cc = 0; cc < nColumns(); cc++) {
      String heaCol = columnHeader(cc);
      int typ = headType(heaCol);
      int gap = (cc == 0) ? 0 : Hgap;

      if (typ == HEADER_ORIGINAL) {
        // maximum-minimum of the column
        HdimPref[cc] = minWidthOfColumn(cc, true);
        HdimMin[cc] = minWidthOfColumn(cc, false);
      } else if (typ == HEADER_EXPAND) columnsReparto.add(new int[] {cc}); // compute later
      else HdimPref[cc] = HdimMin[cc] = stdlib.atoi(heaCol); // indicated size

      Hpos[cc] = fijoH + gap;
      fijoH += HdimPref[cc];
      fijoH += gap;
    }
    fijoH += Hmargin;
    log.dbg(2, "precalculateAll", "fijoH = " + fijoH);

    // DEBUG ....
    if (log.isDebugging(2)) {
      String horizontal = "Horizontal array (posX/prefWidth/minWidth)";
      for (int cc = 0; cc < Hpos.length; cc++)
        horizontal += "  " + cc + ") " + Hpos[cc] + "/" + HdimPref[cc] + "/" + HdimMin[cc];

      log.dbg(2, "precalculateAll", horizontal);
    }

    // finding all components in the layout array
    for (int cc = 0; cc < nColumns(); cc++) {
      for (int rr = 0; rr < nRows(); rr++) {
        String name = widgetAt(rr, cc);

        LayoutParams wid = theComponent(name);
        if (wid == null) continue;

        // set position x,y
        wid.posCol0 = cc;
        wid.posRow0 = rr;

        // set position x2,y2
        int ava = cc;
        while (ava + 1 < nColumns() && widgetAt(rr, ava + 1).equals(EXPAND_HORIZONTAL)) ava++;
        wid.posCol1 = ava;

        ava = rr;
        while (ava + 1 < nRows() && widgetAt(ava + 1, cc).equals(EXPAND_VERTICAL)) ava++;
        wid.posRow1 = ava;

        wid.isLaidOut = true;

        // DEBUG ....
        if (log.isDebugging(2)) {
          log.dbg(
              2,
              "precalculateAll",
              wid.name
                  + " leftTop ("
                  + wid.posCol0
                  + ", "
                  + wid.posRow0
                  + ") rightBottom ("
                  + wid.posCol1
                  + ", "
                  + wid.posRow1
                  + ")");
        }
      }
    }

    isPrecalculated = true;
  }