/[classpath]/classpath/javax/swing/BoxLayout.java
ViewVC logotype

Diff of /classpath/javax/swing/BoxLayout.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7 by rabbit78, Thu Mar 3 10:34:27 2005 UTC revision 1.8 by rabbit78, Tue Apr 12 19:48:43 2005 UTC
# Line 243  public class BoxLayout implements Layout Line 243  public class BoxLayout implements Layout
243                                          - insets.right, size.height                                          - insets.right, size.height
244                                          - insets.bottom - insets.top);                                          - insets.bottom - insets.top);
245      Component[] children = parent.getComponents();      Component[] children = parent.getComponents();
246        boolean[] laidOut = new boolean[children.length];
247        for (int index = 0; index < laidOut.length; index++)
248          laidOut[index] = false;
249    
250      if (isHorizontalIn(parent))      if (isHorizontalIn(parent))
251        {        {
252          int x = insets.left;          // compute overall preferred width
253            int preferredWidthAll = 0;
254            for (int index = 0; index < children.length; index++)
255              {
256                preferredWidthAll += children[index].getPreferredSize().width;
257              }
258            double widthFactor = (double) innerSize.width /
259              (double) preferredWidthAll;
260    
261            // sort out components that are constrained by minimum or maximum size
262            int widthRemain = innerSize.width;
263          for (int index = 0; index < children.length; index++)          for (int index = 0; index < children.length; index++)
264            {            {
265              Component comp = children[index];              Component comp = children[index];
266              Dimension sz = comp.getPreferredSize();              Dimension sz = comp.getPreferredSize();
267              int width = sz.width;              Dimension minSize = comp.getMinimumSize();
268              int height = sz.height;              Dimension maxSize = comp.getMaximumSize();
269              int cy = insets.top;              int width = (int) (sz.width * widthFactor);
270              if (height > innerSize.height)              int height = Math.min(innerSize.height, maxSize.height);
271                // check min size
272                if (width < minSize.width)
273                {                {
274                  height = innerSize.height;                  width = minSize.width;
275                    comp.setSize(width, height);
276                    laidOut[index] = true;
277                    preferredWidthAll -= sz.width;
278                    widthRemain -= width;
279                    continue;
280                }                }
281              else              // check max size
282                if (width > maxSize.width)
283                {                {
284                  cy = (int) ((innerSize.height - height)                  width = maxSize.width;
285                              * comp.getAlignmentY());                  comp.setSize(width, height);
286                    laidOut[index] = true;
287                    preferredWidthAll -= sz.width;
288                    widthRemain -= width;
289                    continue;
290                }                }
291                
292              comp.setSize(width, height);            }
293    
294            // recompute widthFactor for remaining components
295            widthFactor = (double) widthRemain / (double) preferredWidthAll;
296    
297            int x = insets.left;
298    
299            // lay out remaining comonents
300            for (int index = 0; index < children.length; index++)
301              {
302                Component comp = children[index];
303                int width = 0;
304    
305                if (!laidOut[index])
306                  {
307                    Dimension sz = comp.getPreferredSize();
308                    Dimension maxSize = comp.getMaximumSize();
309                    width = (int) (sz.width * widthFactor);
310                    int height = Math.min(innerSize.height, maxSize.height);
311                    comp.setSize(width, height);
312                  }
313                else
314                    width = comp.getWidth();
315    
316                int cy = (int) ((innerSize.height - comp.getHeight())
317                  * comp.getAlignmentY() + insets.top);
318              comp.setLocation(x, cy);              comp.setLocation(x, cy);
319              x = x + width;                          x = x + width;            
320            }            }
321        }        }
322      else      else
323        {        {
324          int y = insets.top;                  // compute overall preferred height
325            int preferredHeightAll = 0;
326            for (int index = 0; index < children.length; index++)
327              {
328                preferredHeightAll += children[index].getPreferredSize().height;
329              }
330            double heightFactor = (double) innerSize.height /
331              (double) preferredHeightAll;
332    
333            // sort out components that are constrained by minimum or maximum size
334            int heightRemain = innerSize.height;
335          for (int index = 0; index < children.length; index++)          for (int index = 0; index < children.length; index++)
336            {            {
337              Component comp = children[index];              Component comp = children[index];
338              Dimension sz = comp.getPreferredSize();              Dimension sz = comp.getPreferredSize();
339              int width = sz.width;              Dimension minSize = comp.getMinimumSize();
340              int height = sz.height;              Dimension maxSize = comp.getMaximumSize();
341              int cx = insets.left;              int height = (int) (sz.height * heightFactor);
342              if (width > innerSize.width)              int width = Math.min(innerSize.width, maxSize.width);
343                // check min size
344                if (height < minSize.height)
345                {                {
346                  width = innerSize.width;                  height = minSize.height;
347                    comp.setSize(width, height);
348                    laidOut[index] = true;
349                    preferredHeightAll -= sz.height;
350                    heightRemain -= height;
351                    continue;
352                }                }
353              else              // check max size
354                if (height > maxSize.height)
355                {                {
356                  cx = (int) ((innerSize.width - width) * comp.getAlignmentX());                  height = maxSize.height;
357                    comp.setSize(width, height);
358                    laidOut[index] = true;
359                    preferredHeightAll -= sz.height;
360                    heightRemain -= height;
361                    continue;
362                }                }
363                
364              comp.setSize(width, height);            }
365    
366            // recompute heightFactor for remaining components
367            heightFactor = (double) heightRemain / (double) preferredHeightAll;
368    
369            int y = insets.top;
370    
371            // lay out remaining comonents
372            for (int index = 0; index < children.length; index++)
373              {
374                Component comp = children[index];
375                int height = 0;
376    
377                if (!laidOut[index])
378                  {
379                    Dimension sz = comp.getPreferredSize();
380                    Dimension maxSize = comp.getMaximumSize();
381                    height = (int) (sz.height * heightFactor);
382                    int width = Math.min(innerSize.width, maxSize.width);
383                    comp.setSize(width, height);
384                  }
385                else
386                  height = comp.getHeight();
387    
388                int cx = (int) ((innerSize.width - comp.getWidth())
389                  * comp.getAlignmentX() + insets.left);
390              comp.setLocation(cx, y);              comp.setLocation(cx, y);
391              y = y + height;                          y = y + height;            
392            }            }

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26