Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

38
LINES

< > BotCompany Repo | #1035072 // FormLayout1 - successor of formLayouter1 - splits available height among text areas

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (7651L) is out of date.

1  
sclass FormLayout1 extends AbstractLayoutManager {
2  
  public void layoutContainer(Container parent) {
3  
    L<Component> l = getComponents(parent);
4  
    
5  
    new BitSet bigOnes;
6  
    for i over l:
7  
      if (containsATextArea(l.get(i))) add(bigOnes, i);
8  
      
9  
    int nBigOnes = bigOnes.cardinality();
10  
    int mandatoryHeight = totalPreferredHeight(listWithoutIndicesInBitSet(l, bigOnes));
11  
    int gap = 4, outerSpacing = 5;
12  
    Dimension size = parent.getSize();
13  
    int gapsAndMargins = outerSpacing*2+(l(l)-1)*gap;
14  
    int totalSpace = size.height-gapsAndMargins;
15  
    int liberalSpace = totalSpace-mandatoryHeight;
16  
    double perBigOne = doubleRatio(liberalSpace, nBigOnes);
17  
    printVars ifdef FormLayout1_debug(height := size.height, +gapsAndMargins, +totalSpace, +liberalSpace, +nBigOnes, +perBigOne);
18  
    double y = outerSpacing;
19  
    for i over l: {
20  
      Component c = l.get(i);
21  
      bool big = contains(bigOnes, i);
22  
      double h = big ? perBigOne : c.getPreferredSize().height;
23  
      int actualY = iround(y);
24  
      c.setBounds(outerSpacing, actualY, size.width-outerSpacing*2, iround(y+h)-actualY);
25  
      printVars ifdef FormLayout1_debug(+i, +big, cBounds := c.getBounds());
26  
      y += h+gap;
27  
    }
28  
    printVars ifdef FormLayout1_debug(+y);
29  
30  
    // set preferred size
31  
    Dimension pref = componentsBoundingSize(parent, outerSpacing);
32  
    if (parent.getHeight() <= 0) { // pre-showing - maybe we should always do this
33  
      int tph = totalPreferredHeight(l);
34  
      pref.height = tph+gapsAndMargins;
35  
    }
36  
    preferredSize(pref);
37  
  }
38  
}

Author comment

Began life as a copy of #1014730

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035072
Snippet name: FormLayout1 - successor of formLayouter1 - splits available height among text areas
Eternal ID of this version: #1035072/8
Text MD5: 88cd943c08587ecf75bd242d2e20d785
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-03-29 15:51:16
Source code size: 1581 bytes / 38 lines
Pitched / IR pitched: No / No
Views / Downloads: 141 / 218
Version history: 7 change(s)
Referenced in: [show references]