Back to index

moin  1.9.0~rc2
PaletteLayout.java
Go to the documentation of this file.
00001 /*
00002  * @(#)PaletteLayout.java 5.1
00003  *
00004  */
00005 
00006 package CH.ifa.draw.util;
00007 
00008 import java.awt.*;
00009 
00015 public  class PaletteLayout
00016         implements LayoutManager {
00017 
00018     private int         fGap;
00019     private Point       fBorder;
00020     private boolean     fVerticalLayout;
00021 
00026     public PaletteLayout(int gap) {
00027         this(gap, new Point(0,0), true);
00028     }
00029 
00030     public PaletteLayout(int gap, Point border) {
00031         this(gap, border, true);
00032     }
00033 
00034     public PaletteLayout(int gap, Point border, boolean vertical) {
00035         fGap = gap;
00036         fBorder = border;
00037         fVerticalLayout = vertical;
00038     }
00039 
00040     public void addLayoutComponent(String name, Component comp) {
00041     }
00042 
00043     public void removeLayoutComponent(Component comp) {
00044     }
00045 
00046     public Dimension preferredLayoutSize(Container target) {
00047         return minimumLayoutSize(target);
00048     }
00049 
00050     public Dimension minimumLayoutSize(Container target) {
00051            Dimension dim = new Dimension(0, 0);
00052            int nmembers = target.getComponentCount();
00053 
00054            for (int i = 0 ; i < nmembers ; i++) {
00055                Component m = target.getComponent(i);
00056                if (m.isVisible()) {
00057                       Dimension d = m.getMinimumSize();
00058                       if (fVerticalLayout) {
00059                           dim.width = Math.max(dim.width, d.width);
00060                           if (i > 0)
00061                               dim.height += fGap;
00062                           dim.height += d.height;
00063                       } else {
00064                           dim.height = Math.max(dim.height, d.height);
00065                           if (i > 0)
00066                               dim.width += fGap;
00067                           dim.width += d.width;
00068                    }
00069                }
00070            }
00071 
00072            Insets insets = target.getInsets();
00073            dim.width += insets.left + insets.right;
00074            dim.width += 2 * fBorder.x;
00075            dim.height += insets.top + insets.bottom;
00076            dim.height += 2 * fBorder.y;
00077            return dim;
00078     }
00079 
00080     public void layoutContainer(Container target) {
00081            Insets insets = target.getInsets();
00082            int nmembers = target.getComponentCount();
00083            int x = insets.left + fBorder.x;
00084            int y = insets.top + fBorder.y;
00085 
00086            for (int i = 0 ; i < nmembers ; i++) {
00087                Component m = target.getComponent(i);
00088                if (m.isVisible()) {
00089                       Dimension d = m.getMinimumSize();
00090                       m.setBounds(x, y, d.width, d.height);
00091                       if (fVerticalLayout) {
00092                           y += d.height;
00093                           y += fGap;
00094                       } else {
00095                           x += d.width;
00096                           x += fGap;
00097                       }
00098                   }
00099            }
00100     }
00101 }