1 4 package org.ozoneDB.core.monitor; 5 6 import java.awt.*; 7 8 17 public class AbsoluteLayout implements LayoutManager2, java.io.Serializable { 18 19 20 protected java.util.Hashtable constraints = new java.util.Hashtable (); 21 22 23 public Dimension bounds; 24 25 26 final static long serialVersionUID = -1919857869177070440L; 27 28 29 35 public void addLayoutComponent( String name, Component comp ) { 36 throw new IllegalArgumentException (); 37 } 38 39 40 44 public void removeLayoutComponent( Component comp ) { 45 constraints.remove( comp ); 46 } 47 48 49 56 public Dimension preferredLayoutSize( Container parent ) { 57 int maxWidth = 0; 58 int maxHeight = 0; 59 for (java.util.Enumeration e = constraints.keys(); e.hasMoreElements();) { 60 Component comp = (Component)e.nextElement(); 61 AbsoluteConstraints ac = (AbsoluteConstraints)constraints.get( comp ); 62 Dimension size = comp.getPreferredSize(); 63 64 int width = ac.getWidth() == -1 ? size.width : ac.getWidth(); 65 int height = ac.getHeight() == -1 ? size.height : ac.getHeight(); 66 67 if (ac.x + width > maxWidth) { 68 maxWidth = ac.x + width; 69 } 70 if (ac.y + height > maxHeight) { 71 maxHeight = ac.y + height; 72 } 73 } 74 return new Dimension( maxWidth, maxHeight ); 75 } 76 77 78 84 public Dimension minimumLayoutSize( Container parent ) { 85 int maxWidth = 0; 86 int maxHeight = 0; 87 for (java.util.Enumeration e = constraints.keys(); e.hasMoreElements();) { 88 Component comp = (Component)e.nextElement(); 89 AbsoluteConstraints ac = (AbsoluteConstraints)constraints.get( comp ); 90 91 Dimension size = comp.getMinimumSize(); 92 93 int width = ac.getWidth() == -1 ? size.width : ac.getWidth(); 94 int height = ac.getHeight() == -1 ? size.height : ac.getHeight(); 95 96 if (ac.x + width > maxWidth) { 97 maxWidth = ac.x + width; 98 } 99 if (ac.y + height > maxHeight) { 100 maxHeight = ac.y + height; 101 } 102 } 103 return new Dimension( maxWidth, maxHeight ); 104 } 105 106 107 111 public void realizeSize( Dimension bounds ) { 112 bounds = new Dimension( bounds ); 113 } 114 115 116 120 public void layoutContainer( Container parent ) { 121 Dimension parentSize = parent.getSize(); 122 if (bounds == null) { 123 bounds = new Dimension( parentSize ); 124 } 125 126 for (java.util.Enumeration e = constraints.keys(); e.hasMoreElements();) { 127 Component comp = (Component)e.nextElement(); 128 AbsoluteConstraints ac = (AbsoluteConstraints)constraints.get( comp ); 129 Dimension size = comp.getPreferredSize(); 130 131 int x = ac.x; 132 int y = ac.y; 133 int width = ac.getWidth() == -1 ? size.width : ac.getWidth(); 134 int height = ac.getHeight() == -1 ? size.height : ac.getHeight(); 135 136 if ((ac.policy & AbsoluteConstraints.X_PROP) != 0) { 137 x = (int)((double)ac.x / (double)bounds.width * (double)parentSize.width); 138 } 139 if ((ac.policy & AbsoluteConstraints.Y_PROP) != 0) { 140 y = (int)((double)ac.y / (double)bounds.height * (double)parentSize.height); 141 } 142 if ((ac.policy & AbsoluteConstraints.X_ABS) != 0) { 143 x = (parentSize.width - (bounds.width - ac.x)); 144 } 145 if ((ac.policy & AbsoluteConstraints.Y_ABS) != 0) { 146 y = (parentSize.height - (bounds.height - ac.y)); 147 } 148 149 if ((ac.policy & AbsoluteConstraints.X2_PROP) != 0) { 150 width = ((int)((double)(ac.x + width) / (double)bounds.width * (double)parentSize.width) - x); 151 } 152 if ((ac.policy & AbsoluteConstraints.Y2_PROP) != 0) { 153 height = ((int)((double)(ac.y + height) / (double)bounds.height * (double)parentSize.height) - y); 154 } 155 if ((ac.policy & AbsoluteConstraints.X2_ABS) != 0) { 156 int x2 = bounds.width - ac.x + width; 157 width = (parentSize.width - x - x2); 158 } 159 if ((ac.policy & AbsoluteConstraints.Y2_ABS) != 0) { 160 int y2 = bounds.height - ac.y + height; 161 height = (parentSize.height - y - y2); 162 } 163 164 comp.setBounds( x, y, width, height ); 165 } 166 } 167 168 169 175 public void addLayoutComponent( Component comp, Object constr ) { 176 if (!(constr instanceof AbsoluteConstraints)) { 177 throw new IllegalArgumentException (); 178 } 179 constraints.put( comp, constr ); 180 } 181 182 183 189 public Dimension maximumLayoutSize( Container target ) { 190 return new Dimension( Integer.MAX_VALUE, Integer.MAX_VALUE ); 191 } 192 193 194 201 public float getLayoutAlignmentX( Container target ) { 202 return 0; 203 } 204 205 206 213 public float getLayoutAlignmentY( Container target ) { 214 return 0; 215 } 216 217 218 222 public void invalidateLayout( Container target ) { 223 } 224 } 225 | Popular Tags |