package gve.calc.logic; import java.awt.*; public class TableauPartLayout implements LayoutManager { public TableauPartLayout() {} public void addLayoutComponent(String name,Component target) {} public void removeLayoutComponent(Component target) {} public Dimension preferredLayoutSize(Container target) { // Oops! In JDK1.1.5, the value returned by Component.getPreferredSize() // must be considered read only! If we would change it, following // calls to getPreferredSize() will return this changed value! Dimension tdim = target.getComponent(0).getPreferredSize(); Dimension ldim = target.getComponent(1).getPreferredSize(); Dimension result = new Dimension(ldim); if (target.getComponentCount() > 2) { Dimension rdim = target.getComponent(2).getPreferredSize(); result.width += 10+rdim.width; if (rdim.height > ldim.height) result.height = rdim.height; } // result is now the reauired size for the bottom parts if (tdim.width > result.width) result.width = tdim.width; result.height += 10 + tdim.height; return result; } public Dimension minimumLayoutSize(Container target) { return preferredLayoutSize(target); } public void layoutContainer(Container target) { Component top = target.getComponent(0); Component left = target.getComponent(1); top.validate(); left.validate(); Dimension topdim = top.getPreferredSize(); Dimension leftdim = left.getPreferredSize(); Component right = null; if (target.getComponentCount() > 2) { right = target.getComponent(2); right.validate(); } Dimension siz = target.getSize(); //System.out.println("Total height "+siz.height+" top height "+topdim.height); top.setBounds((siz.width-topdim.width)/2,0,topdim.width,topdim.height); //System.out.println("\ttop is now "+top); top.list(); int y = topdim.height+10; if (right == null) { left.setBounds((siz.width-leftdim.width)/2,y,leftdim.width,leftdim.height); } else { Dimension rightdim = right.getPreferredSize(); left.setBounds(0,y,leftdim.width,leftdim.height); right.setBounds(siz.width-rightdim.width,y,rightdim.width,rightdim.height); } } }