1 package com.calipso.reportgenerator.common; 2 3 15 16 18 import com.calipso.reportgenerator.common.AbsoluteConstraints; 19 20 import java.awt.*; 21 22 28 public class AbsoluteLayout implements LayoutManager2, java.io.Serializable { 29 30 static final long serialVersionUID = -1919857869177070440L; 31 32 37 public void addLayoutComponent(String name, Component comp) { 38 throw new IllegalArgumentException (); 39 } 40 41 44 public void removeLayoutComponent(Component comp) { 45 constraints.remove(comp); 46 } 47 48 54 public Dimension preferredLayoutSize(Container parent) { 55 int maxWidth = 0; 56 int maxHeight = 0; 57 for (java.util.Enumeration e = constraints.keys(); e.hasMoreElements();) { 58 Component comp = (Component)e.nextElement(); 59 AbsoluteConstraints ac = (AbsoluteConstraints)constraints.get(comp); 60 Dimension size = comp.getPreferredSize(); 61 62 int width = ac.getWidth (); 63 if (width == -1) width = size.width; 64 int height = ac.getHeight (); 65 if (height == -1) height = size.height; 66 67 if (ac.x + width > maxWidth) 68 maxWidth = ac.x + width; 69 if (ac.y + height > maxHeight) 70 maxHeight = ac.y + height; 71 } 72 return new Dimension (maxWidth, maxHeight); 73 } 74 75 80 public Dimension minimumLayoutSize(Container parent) { 81 int maxWidth = 0; 82 int maxHeight = 0; 83 for (java.util.Enumeration e = constraints.keys(); e.hasMoreElements();) { 84 Component comp = (Component)e.nextElement(); 85 com.calipso.reportgenerator.common.AbsoluteConstraints ac = (AbsoluteConstraints)constraints.get(comp); 86 87 Dimension size = comp.getMinimumSize(); 88 89 int width = ac.getWidth (); 90 if (width == -1) width = size.width; 91 int height = ac.getHeight (); 92 if (height == -1) height = size.height; 93 94 if (ac.x + width > maxWidth) 95 maxWidth = ac.x + width; 96 if (ac.y + height > maxHeight) 97 maxHeight = ac.y + height; 98 } 99 return new Dimension (maxWidth, maxHeight); 100 } 101 102 105 public void layoutContainer(Container parent) { 106 for (java.util.Enumeration e = constraints.keys(); e.hasMoreElements();) { 107 Component comp = (Component)e.nextElement(); 108 AbsoluteConstraints ac = (AbsoluteConstraints)constraints.get(comp); 109 Dimension size = comp.getPreferredSize(); 110 int width = ac.getWidth (); 111 if (width == -1) width = size.width; 112 int height = ac.getHeight (); 113 if (height == -1) height = size.height; 114 115 comp.setBounds(ac.x, ac.y, width, height); 116 } 117 } 118 119 124 public void addLayoutComponent(Component comp, Object constr) { 125 if (!(constr instanceof AbsoluteConstraints)) 126 throw new IllegalArgumentException (); 127 constraints.put(comp, constr); 128 } 129 130 135 public Dimension maximumLayoutSize(Container target) { 136 return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE); 137 } 138 139 145 public float getLayoutAlignmentX(Container target) { 146 return 0; 147 } 148 149 155 public float getLayoutAlignmentY(Container target) { 156 return 0; 157 } 158 159 162 public void invalidateLayout(Container target) { 163 } 164 165 166 167 protected java.util.Hashtable constraints = new java.util.Hashtable (); 168 } 169 170 | Popular Tags |