1 13 14 package org.netbeans.lib.awtextra; 15 16 import java.awt.*; 17 18 24 public class AbsoluteLayout implements LayoutManager2, java.io.Serializable { 25 26 static final long serialVersionUID = -1919857869177070440L; 27 28 33 public void addLayoutComponent(String name, Component comp) { 34 throw new IllegalArgumentException (); 35 } 36 37 40 public void removeLayoutComponent(Component comp) { 41 constraints.remove(comp); 42 } 43 44 50 public Dimension preferredLayoutSize(Container parent) { 51 int maxWidth = 0; 52 int maxHeight = 0; 53 for (java.util.Enumeration e = constraints.keys(); e.hasMoreElements();) { 54 Component comp = (Component)e.nextElement(); 55 AbsoluteConstraints ac = (AbsoluteConstraints)constraints.get(comp); 56 Dimension size = comp.getPreferredSize(); 57 58 int width = ac.getWidth (); 59 if (width == -1) width = size.width; 60 int height = ac.getHeight (); 61 if (height == -1) height = size.height; 62 63 if (ac.x + width > maxWidth) 64 maxWidth = ac.x + width; 65 if (ac.y + height > maxHeight) 66 maxHeight = ac.y + height; 67 } 68 return new Dimension (maxWidth, maxHeight); 69 } 70 71 76 public Dimension minimumLayoutSize(Container parent) { 77 int maxWidth = 0; 78 int maxHeight = 0; 79 for (java.util.Enumeration e = constraints.keys(); e.hasMoreElements();) { 80 Component comp = (Component)e.nextElement(); 81 AbsoluteConstraints ac = (AbsoluteConstraints)constraints.get(comp); 82 83 Dimension size = comp.getMinimumSize(); 84 85 int width = ac.getWidth (); 86 if (width == -1) width = size.width; 87 int height = ac.getHeight (); 88 if (height == -1) height = size.height; 89 90 if (ac.x + width > maxWidth) 91 maxWidth = ac.x + width; 92 if (ac.y + height > maxHeight) 93 maxHeight = ac.y + height; 94 } 95 return new Dimension (maxWidth, maxHeight); 96 } 97 98 101 public void layoutContainer(Container parent) { 102 for (java.util.Enumeration e = constraints.keys(); e.hasMoreElements();) { 103 Component comp = (Component)e.nextElement(); 104 AbsoluteConstraints ac = (AbsoluteConstraints)constraints.get(comp); 105 Dimension size = comp.getPreferredSize(); 106 int width = ac.getWidth (); 107 if (width == -1) width = size.width; 108 int height = ac.getHeight (); 109 if (height == -1) height = size.height; 110 111 comp.setBounds(ac.x, ac.y, width, height); 112 } 113 } 114 115 120 public void addLayoutComponent(Component comp, Object constr) { 121 if (!(constr instanceof AbsoluteConstraints)) 122 throw new IllegalArgumentException (); 123 constraints.put(comp, constr); 124 } 125 126 131 public Dimension maximumLayoutSize(Container target) { 132 return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE); 133 } 134 135 141 public float getLayoutAlignmentX(Container target) { 142 return 0; 143 } 144 145 151 public float getLayoutAlignmentY(Container target) { 152 return 0; 153 } 154 155 158 public void invalidateLayout(Container target) { 159 } 160 161 162 163 protected java.util.Hashtable constraints = new java.util.Hashtable (); 164 } 165 166 | Popular Tags |