protected float getMaxHeight() { float max = 0; for (int i = 0; i < items.size(); i++) { MenuItem item = (MenuItem) items.get(i); float curHeight = item.getHeight(); if (curHeight > max) max = curHeight; } return max; }
public synchronized void layout() { if (menu == null) return; float px = getPadX(); float py = getPadY(); float curX = 0, curY = 0; switch (layoutMode) { case (LAYOUT_BELOW): curX = x - py; curY = y + height; break; case (LAYOUT_RIGHT): default: curX = x + width; curY = y - px; break; } subItemRect.x = curX; subItemRect.y = curY; curX += px; curY += py; for (int i = 0; i < items.size(); i++) { MenuItem item = (MenuItem) items.get(i); item.calcPreferredSize(); } float maxWidth = getMaxWidth(); float maxHeight = getMaxHeight(); for (int i = 0; i < items.size(); i++) { MenuItem item = (MenuItem) items.get(i); if (item.isHidden()) continue; item.setPosition(curX, curY); // if (layoutMode == LAYOUT_BELOW) // item.setWidth(maxWidth); // else // item.setHeight(maxHeight); item.setSize(maxWidth, maxHeight); curY += item.getHeight(); } curY += py; subItemRect.width = maxWidth + px * 2; subItemRect.height = curY - subItemRect.y; /* * Trigger the recursive layout. */ super.layout(); }