PageRenderTime 62ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/java-1.7.0-openjdk/openjdk/jdk/src/share/classes/java/awt/GridBagLayout.java

#
Java | 2228 lines | 1060 code | 158 blank | 1010 comment | 290 complexity | 01afadfc037ebcf45c372cbd58dca85b MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause-No-Nuclear-License-2014, LGPL-3.0, LGPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. * Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved.
  3. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4. *
  5. * This code is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 only, as
  7. * published by the Free Software Foundation. Oracle designates this
  8. * particular file as subject to the "Classpath" exception as provided
  9. * by Oracle in the LICENSE file that accompanied this code.
  10. *
  11. * This code is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  14. * version 2 for more details (a copy is included in the LICENSE file that
  15. * accompanied this code).
  16. *
  17. * You should have received a copy of the GNU General Public License version
  18. * 2 along with this work; if not, write to the Free Software Foundation,
  19. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20. *
  21. * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22. * or visit www.oracle.com if you need additional information or have any
  23. * questions.
  24. */
  25. package java.awt;
  26. import java.util.Hashtable;
  27. import java.util.Arrays;
  28. /**
  29. * The <code>GridBagLayout</code> class is a flexible layout
  30. * manager that aligns components vertically, horizontally or along their
  31. * baseline without requiring that the components be of the same size.
  32. * Each <code>GridBagLayout</code> object maintains a dynamic,
  33. * rectangular grid of cells, with each component occupying
  34. * one or more cells, called its <em>display area</em>.
  35. * <p>
  36. * Each component managed by a <code>GridBagLayout</code> is associated with
  37. * an instance of {@link GridBagConstraints}. The constraints object
  38. * specifies where a component's display area should be located on the grid
  39. * and how the component should be positioned within its display area. In
  40. * addition to its constraints object, the <code>GridBagLayout</code> also
  41. * considers each component's minimum and preferred sizes in order to
  42. * determine a component's size.
  43. * <p>
  44. * The overall orientation of the grid depends on the container's
  45. * {@link ComponentOrientation} property. For horizontal left-to-right
  46. * orientations, grid coordinate (0,0) is in the upper left corner of the
  47. * container with x increasing to the right and y increasing downward. For
  48. * horizontal right-to-left orientations, grid coordinate (0,0) is in the upper
  49. * right corner of the container with x increasing to the left and y
  50. * increasing downward.
  51. * <p>
  52. * To use a grid bag layout effectively, you must customize one or more
  53. * of the <code>GridBagConstraints</code> objects that are associated
  54. * with its components. You customize a <code>GridBagConstraints</code>
  55. * object by setting one or more of its instance variables:
  56. * <p>
  57. * <dl>
  58. * <dt>{@link GridBagConstraints#gridx},
  59. * {@link GridBagConstraints#gridy}
  60. * <dd>Specifies the cell containing the leading corner of the component's
  61. * display area, where the cell at the origin of the grid has address
  62. * <code>gridx&nbsp;=&nbsp;0</code>,
  63. * <code>gridy&nbsp;=&nbsp;0</code>. For horizontal left-to-right layout,
  64. * a component's leading corner is its upper left. For horizontal
  65. * right-to-left layout, a component's leading corner is its upper right.
  66. * Use <code>GridBagConstraints.RELATIVE</code> (the default value)
  67. * to specify that the component be placed immediately following
  68. * (along the x axis for <code>gridx</code> or the y axis for
  69. * <code>gridy</code>) the component that was added to the container
  70. * just before this component was added.
  71. * <dt>{@link GridBagConstraints#gridwidth},
  72. * {@link GridBagConstraints#gridheight}
  73. * <dd>Specifies the number of cells in a row (for <code>gridwidth</code>)
  74. * or column (for <code>gridheight</code>)
  75. * in the component's display area.
  76. * The default value is 1.
  77. * Use <code>GridBagConstraints.REMAINDER</code> to specify
  78. * that the component's display area will be from <code>gridx</code>
  79. * to the last cell in the row (for <code>gridwidth</code>)
  80. * or from <code>gridy</code> to the last cell in the column
  81. * (for <code>gridheight</code>).
  82. *
  83. * Use <code>GridBagConstraints.RELATIVE</code> to specify
  84. * that the component's display area will be from <code>gridx</code>
  85. * to the next to the last cell in its row (for <code>gridwidth</code>
  86. * or from <code>gridy</code> to the next to the last cell in its
  87. * column (for <code>gridheight</code>).
  88. *
  89. * <dt>{@link GridBagConstraints#fill}
  90. * <dd>Used when the component's display area
  91. * is larger than the component's requested size
  92. * to determine whether (and how) to resize the component.
  93. * Possible values are
  94. * <code>GridBagConstraints.NONE</code> (the default),
  95. * <code>GridBagConstraints.HORIZONTAL</code>
  96. * (make the component wide enough to fill its display area
  97. * horizontally, but don't change its height),
  98. * <code>GridBagConstraints.VERTICAL</code>
  99. * (make the component tall enough to fill its display area
  100. * vertically, but don't change its width), and
  101. * <code>GridBagConstraints.BOTH</code>
  102. * (make the component fill its display area entirely).
  103. * <dt>{@link GridBagConstraints#ipadx},
  104. * {@link GridBagConstraints#ipady}
  105. * <dd>Specifies the component's internal padding within the layout,
  106. * how much to add to the minimum size of the component.
  107. * The width of the component will be at least its minimum width
  108. * plus <code>ipadx</code> pixels. Similarly, the height of
  109. * the component will be at least the minimum height plus
  110. * <code>ipady</code> pixels.
  111. * <dt>{@link GridBagConstraints#insets}
  112. * <dd>Specifies the component's external padding, the minimum
  113. * amount of space between the component and the edges of its display area.
  114. * <dt>{@link GridBagConstraints#anchor}
  115. * <dd>Specifies where the component should be positioned in its display area.
  116. * There are three kinds of possible values: absolute, orientation-relative,
  117. * and baseline-relative
  118. * Orientation relative values are interpreted relative to the container's
  119. * <code>ComponentOrientation</code> property while absolute values
  120. * are not. Baseline relative values are calculated relative to the
  121. * baseline. Valid values are:</dd>
  122. * <p>
  123. * <center><table BORDER=0 COLS=3 WIDTH=800
  124. * SUMMARY="absolute, relative and baseline values as described above">
  125. * <tr>
  126. * <th><P ALIGN="LEFT">Absolute Values</th>
  127. * <th><P ALIGN="LEFT">Orientation Relative Values</th>
  128. * <th><P ALIGN="LEFT">Baseline Relative Values</th>
  129. * </tr>
  130. * <tr>
  131. * <td>
  132. * <li><code>GridBagConstraints.NORTH</code></li>
  133. * <li><code>GridBagConstraints.SOUTH</code></li>
  134. * <li><code>GridBagConstraints.WEST</code></li>
  135. * <li><code>GridBagConstraints.EAST</code></li>
  136. * <li><code>GridBagConstraints.NORTHWEST</code></li>
  137. * <li><code>GridBagConstraints.NORTHEAST</code></li>
  138. * <li><code>GridBagConstraints.SOUTHWEST</code></li>
  139. * <li><code>GridBagConstraints.SOUTHEAST</code></li>
  140. * <li><code>GridBagConstraints.CENTER</code> (the default)</li>
  141. * </td>
  142. * <td>
  143. * <li><code>GridBagConstraints.PAGE_START</code></li>
  144. * <li><code>GridBagConstraints.PAGE_END</code></li>
  145. * <li><code>GridBagConstraints.LINE_START</code></li>
  146. * <li><code>GridBagConstraints.LINE_END</code></li>
  147. * <li><code>GridBagConstraints.FIRST_LINE_START</code></li>
  148. * <li><code>GridBagConstraints.FIRST_LINE_END</code></li>
  149. * <li><code>GridBagConstraints.LAST_LINE_START</code></li>
  150. * <li><code>GridBagConstraints.LAST_LINE_END</code></li>
  151. * </td>
  152. * <td>
  153. * <li><code>GridBagConstraints.BASELINE</code></li>
  154. * <li><code>GridBagConstraints.BASELINE_LEADING</code></li>
  155. * <li><code>GridBagConstraints.BASELINE_TRAILING</code></li>
  156. * <li><code>GridBagConstraints.ABOVE_BASELINE</code></li>
  157. * <li><code>GridBagConstraints.ABOVE_BASELINE_LEADING</code></li>
  158. * <li><code>GridBagConstraints.ABOVE_BASELINE_TRAILING</code></li>
  159. * <li><code>GridBagConstraints.BELOW_BASELINE</code></li>
  160. * <li><code>GridBagConstraints.BELOW_BASELINE_LEADING</code></li>
  161. * <li><code>GridBagConstraints.BELOW_BASELINE_TRAILING</code></li>
  162. * </td>
  163. * </tr>
  164. * </table></center><p>
  165. * <dt>{@link GridBagConstraints#weightx},
  166. * {@link GridBagConstraints#weighty}
  167. * <dd>Used to determine how to distribute space, which is
  168. * important for specifying resizing behavior.
  169. * Unless you specify a weight for at least one component
  170. * in a row (<code>weightx</code>) and column (<code>weighty</code>),
  171. * all the components clump together in the center of their container.
  172. * This is because when the weight is zero (the default),
  173. * the <code>GridBagLayout</code> object puts any extra space
  174. * between its grid of cells and the edges of the container.
  175. * </dl>
  176. * <p>
  177. * Each row may have a baseline; the baseline is determined by the
  178. * components in that row that have a valid baseline and are aligned
  179. * along the baseline (the component's anchor value is one of {@code
  180. * BASELINE}, {@code BASELINE_LEADING} or {@code BASELINE_TRAILING}).
  181. * If none of the components in the row has a valid baseline, the row
  182. * does not have a baseline.
  183. * <p>
  184. * If a component spans rows it is aligned either to the baseline of
  185. * the start row (if the baseline-resize behavior is {@code
  186. * CONSTANT_ASCENT}) or the end row (if the baseline-resize behavior
  187. * is {@code CONSTANT_DESCENT}). The row that the component is
  188. * aligned to is called the <em>prevailing row</em>.
  189. * <p>
  190. * The following figure shows a baseline layout and includes a
  191. * component that spans rows:
  192. * <center><table summary="Baseline Layout">
  193. * <tr ALIGN=CENTER>
  194. * <td>
  195. * <img src="doc-files/GridBagLayout-baseline.png"
  196. * alt="The following text describes this graphic (Figure 1)." ALIGN=center>
  197. * </td>
  198. * </table></center>
  199. * This layout consists of three components:
  200. * <ul><li>A panel that starts in row 0 and ends in row 1. The panel
  201. * has a baseline-resize behavior of <code>CONSTANT_DESCENT</code> and has
  202. * an anchor of <code>BASELINE</code>. As the baseline-resize behavior
  203. * is <code>CONSTANT_DESCENT</code> the prevailing row for the panel is
  204. * row 1.
  205. * <li>Two buttons, each with a baseline-resize behavior of
  206. * <code>CENTER_OFFSET</code> and an anchor of <code>BASELINE</code>.
  207. * </ul>
  208. * Because the second button and the panel share the same prevailing row,
  209. * they are both aligned along their baseline.
  210. * <p>
  211. * Components positioned using one of the baseline-relative values resize
  212. * differently than when positioned using an absolute or orientation-relative
  213. * value. How components change is dictated by how the baseline of the
  214. * prevailing row changes. The baseline is anchored to the
  215. * bottom of the display area if any components with the same prevailing row
  216. * have a baseline-resize behavior of <code>CONSTANT_DESCENT</code>,
  217. * otherwise the baseline is anchored to the top of the display area.
  218. * The following rules dictate the resize behavior:
  219. * <ul>
  220. * <li>Resizable components positioned above the baseline can only
  221. * grow as tall as the baseline. For example, if the baseline is at 100
  222. * and anchored at the top, a resizable component positioned above the
  223. * baseline can never grow more than 100 units.
  224. * <li>Similarly, resizable components positioned below the baseline can
  225. * only grow as high as the difference between the display height and the
  226. * baseline.
  227. * <li>Resizable components positioned on the baseline with a
  228. * baseline-resize behavior of <code>OTHER</code> are only resized if
  229. * the baseline at the resized size fits within the display area. If
  230. * the baseline is such that it does not fit within the display area
  231. * the component is not resized.
  232. * <li>Components positioned on the baseline that do not have a
  233. * baseline-resize behavior of <code>OTHER</code>
  234. * can only grow as tall as {@code display height - baseline + baseline of component}.
  235. * </ul>
  236. * If you position a component along the baseline, but the
  237. * component does not have a valid baseline, it will be vertically centered
  238. * in its space. Similarly if you have positioned a component relative
  239. * to the baseline and none of the components in the row have a valid
  240. * baseline the component is vertically centered.
  241. * <p>
  242. * The following figures show ten components (all buttons)
  243. * managed by a grid bag layout. Figure 2 shows the layout for a horizontal,
  244. * left-to-right container and Figure 3 shows the layout for a horizontal,
  245. * right-to-left container.
  246. * <p>
  247. * <center><table COLS=2 WIDTH=600 summary="layout">
  248. * <tr ALIGN=CENTER>
  249. * <td>
  250. * <img src="doc-files/GridBagLayout-1.gif" alt="The preceeding text describes this graphic (Figure 1)." ALIGN=center HSPACE=10 VSPACE=7>
  251. * </td>
  252. * <td>
  253. * <img src="doc-files/GridBagLayout-2.gif" alt="The preceeding text describes this graphic (Figure 2)." ALIGN=center HSPACE=10 VSPACE=7>
  254. * </td>
  255. * <tr ALIGN=CENTER>
  256. * <td>Figure 2: Horizontal, Left-to-Right</td>
  257. * <td>Figure 3: Horizontal, Right-to-Left</td>
  258. * </tr>
  259. * </table></center>
  260. * <p>
  261. * Each of the ten components has the <code>fill</code> field
  262. * of its associated <code>GridBagConstraints</code> object
  263. * set to <code>GridBagConstraints.BOTH</code>.
  264. * In addition, the components have the following non-default constraints:
  265. * <p>
  266. * <ul>
  267. * <li>Button1, Button2, Button3: <code>weightx&nbsp;=&nbsp;1.0</code>
  268. * <li>Button4: <code>weightx&nbsp;=&nbsp;1.0</code>,
  269. * <code>gridwidth&nbsp;=&nbsp;GridBagConstraints.REMAINDER</code>
  270. * <li>Button5: <code>gridwidth&nbsp;=&nbsp;GridBagConstraints.REMAINDER</code>
  271. * <li>Button6: <code>gridwidth&nbsp;=&nbsp;GridBagConstraints.RELATIVE</code>
  272. * <li>Button7: <code>gridwidth&nbsp;=&nbsp;GridBagConstraints.REMAINDER</code>
  273. * <li>Button8: <code>gridheight&nbsp;=&nbsp;2</code>,
  274. * <code>weighty&nbsp;=&nbsp;1.0</code>
  275. * <li>Button9, Button 10:
  276. * <code>gridwidth&nbsp;=&nbsp;GridBagConstraints.REMAINDER</code>
  277. * </ul>
  278. * <p>
  279. * Here is the code that implements the example shown above:
  280. * <p>
  281. * <hr><blockquote><pre>
  282. * import java.awt.*;
  283. * import java.util.*;
  284. * import java.applet.Applet;
  285. *
  286. * public class GridBagEx1 extends Applet {
  287. *
  288. * protected void makebutton(String name,
  289. * GridBagLayout gridbag,
  290. * GridBagConstraints c) {
  291. * Button button = new Button(name);
  292. * gridbag.setConstraints(button, c);
  293. * add(button);
  294. * }
  295. *
  296. * public void init() {
  297. * GridBagLayout gridbag = new GridBagLayout();
  298. * GridBagConstraints c = new GridBagConstraints();
  299. *
  300. * setFont(new Font("SansSerif", Font.PLAIN, 14));
  301. * setLayout(gridbag);
  302. *
  303. * c.fill = GridBagConstraints.BOTH;
  304. * c.weightx = 1.0;
  305. * makebutton("Button1", gridbag, c);
  306. * makebutton("Button2", gridbag, c);
  307. * makebutton("Button3", gridbag, c);
  308. *
  309. * c.gridwidth = GridBagConstraints.REMAINDER; //end row
  310. * makebutton("Button4", gridbag, c);
  311. *
  312. * c.weightx = 0.0; //reset to the default
  313. * makebutton("Button5", gridbag, c); //another row
  314. *
  315. * c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last in row
  316. * makebutton("Button6", gridbag, c);
  317. *
  318. * c.gridwidth = GridBagConstraints.REMAINDER; //end row
  319. * makebutton("Button7", gridbag, c);
  320. *
  321. * c.gridwidth = 1; //reset to the default
  322. * c.gridheight = 2;
  323. * c.weighty = 1.0;
  324. * makebutton("Button8", gridbag, c);
  325. *
  326. * c.weighty = 0.0; //reset to the default
  327. * c.gridwidth = GridBagConstraints.REMAINDER; //end row
  328. * c.gridheight = 1; //reset to the default
  329. * makebutton("Button9", gridbag, c);
  330. * makebutton("Button10", gridbag, c);
  331. *
  332. * setSize(300, 100);
  333. * }
  334. *
  335. * public static void main(String args[]) {
  336. * Frame f = new Frame("GridBag Layout Example");
  337. * GridBagEx1 ex1 = new GridBagEx1();
  338. *
  339. * ex1.init();
  340. *
  341. * f.add("Center", ex1);
  342. * f.pack();
  343. * f.setSize(f.getPreferredSize());
  344. * f.show();
  345. * }
  346. * }
  347. * </pre></blockquote><hr>
  348. * <p>
  349. * @author Doug Stein
  350. * @author Bill Spitzak (orignial NeWS & OLIT implementation)
  351. * @see java.awt.GridBagConstraints
  352. * @see java.awt.GridBagLayoutInfo
  353. * @see java.awt.ComponentOrientation
  354. * @since JDK1.0
  355. */
  356. public class GridBagLayout implements LayoutManager2,
  357. java.io.Serializable {
  358. static final int EMPIRICMULTIPLIER = 2;
  359. /**
  360. * This field is no longer used to reserve arrays and keeped for backward
  361. * compatibility. Previously, this was
  362. * the maximum number of grid positions (both horizontal and
  363. * vertical) that could be laid out by the grid bag layout.
  364. * Current implementation doesn't impose any limits
  365. * on the size of a grid.
  366. */
  367. protected static final int MAXGRIDSIZE = 512;
  368. /**
  369. * The smallest grid that can be laid out by the grid bag layout.
  370. */
  371. protected static final int MINSIZE = 1;
  372. /**
  373. * The preferred grid size that can be laid out by the grid bag layout.
  374. */
  375. protected static final int PREFERREDSIZE = 2;
  376. /**
  377. * This hashtable maintains the association between
  378. * a component and its gridbag constraints.
  379. * The Keys in <code>comptable</code> are the components and the
  380. * values are the instances of <code>GridBagConstraints</code>.
  381. *
  382. * @serial
  383. * @see java.awt.GridBagConstraints
  384. */
  385. protected Hashtable<Component,GridBagConstraints> comptable;
  386. /**
  387. * This field holds a gridbag constraints instance
  388. * containing the default values, so if a component
  389. * does not have gridbag constraints associated with
  390. * it, then the component will be assigned a
  391. * copy of the <code>defaultConstraints</code>.
  392. *
  393. * @serial
  394. * @see #getConstraints(Component)
  395. * @see #setConstraints(Component, GridBagConstraints)
  396. * @see #lookupConstraints(Component)
  397. */
  398. protected GridBagConstraints defaultConstraints;
  399. /**
  400. * This field holds the layout information
  401. * for the gridbag. The information in this field
  402. * is based on the most recent validation of the
  403. * gridbag.
  404. * If <code>layoutInfo</code> is <code>null</code>
  405. * this indicates that there are no components in
  406. * the gridbag or if there are components, they have
  407. * not yet been validated.
  408. *
  409. * @serial
  410. * @see #getLayoutInfo(Container, int)
  411. */
  412. protected GridBagLayoutInfo layoutInfo;
  413. /**
  414. * This field holds the overrides to the column minimum
  415. * width. If this field is non-<code>null</code> the values are
  416. * applied to the gridbag after all of the minimum columns
  417. * widths have been calculated.
  418. * If columnWidths has more elements than the number of
  419. * columns, columns are added to the gridbag to match
  420. * the number of elements in columnWidth.
  421. *
  422. * @serial
  423. * @see #getLayoutDimensions()
  424. */
  425. public int columnWidths[];
  426. /**
  427. * This field holds the overrides to the row minimum
  428. * heights. If this field is non-<code>null</code> the values are
  429. * applied to the gridbag after all of the minimum row
  430. * heights have been calculated.
  431. * If <code>rowHeights</code> has more elements than the number of
  432. * rows, rowa are added to the gridbag to match
  433. * the number of elements in <code>rowHeights</code>.
  434. *
  435. * @serial
  436. * @see #getLayoutDimensions()
  437. */
  438. public int rowHeights[];
  439. /**
  440. * This field holds the overrides to the column weights.
  441. * If this field is non-<code>null</code> the values are
  442. * applied to the gridbag after all of the columns
  443. * weights have been calculated.
  444. * If <code>columnWeights[i]</code> &gt; weight for column i, then
  445. * column i is assigned the weight in <code>columnWeights[i]</code>.
  446. * If <code>columnWeights</code> has more elements than the number
  447. * of columns, the excess elements are ignored - they do
  448. * not cause more columns to be created.
  449. *
  450. * @serial
  451. */
  452. public double columnWeights[];
  453. /**
  454. * This field holds the overrides to the row weights.
  455. * If this field is non-<code>null</code> the values are
  456. * applied to the gridbag after all of the rows
  457. * weights have been calculated.
  458. * If <code>rowWeights[i]</code> &gt; weight for row i, then
  459. * row i is assigned the weight in <code>rowWeights[i]</code>.
  460. * If <code>rowWeights</code> has more elements than the number
  461. * of rows, the excess elements are ignored - they do
  462. * not cause more rows to be created.
  463. *
  464. * @serial
  465. */
  466. public double rowWeights[];
  467. /**
  468. * The component being positioned. This is set before calling into
  469. * <code>adjustForGravity</code>.
  470. */
  471. private Component componentAdjusting;
  472. /**
  473. * Creates a grid bag layout manager.
  474. */
  475. public GridBagLayout () {
  476. comptable = new Hashtable<Component,GridBagConstraints>();
  477. defaultConstraints = new GridBagConstraints();
  478. }
  479. /**
  480. * Sets the constraints for the specified component in this layout.
  481. * @param comp the component to be modified
  482. * @param constraints the constraints to be applied
  483. */
  484. public void setConstraints(Component comp, GridBagConstraints constraints) {
  485. comptable.put(comp, (GridBagConstraints)constraints.clone());
  486. }
  487. /**
  488. * Gets the constraints for the specified component. A copy of
  489. * the actual <code>GridBagConstraints</code> object is returned.
  490. * @param comp the component to be queried
  491. * @return the constraint for the specified component in this
  492. * grid bag layout; a copy of the actual constraint
  493. * object is returned
  494. */
  495. public GridBagConstraints getConstraints(Component comp) {
  496. GridBagConstraints constraints = comptable.get(comp);
  497. if (constraints == null) {
  498. setConstraints(comp, defaultConstraints);
  499. constraints = comptable.get(comp);
  500. }
  501. return (GridBagConstraints)constraints.clone();
  502. }
  503. /**
  504. * Retrieves the constraints for the specified component.
  505. * The return value is not a copy, but is the actual
  506. * <code>GridBagConstraints</code> object used by the layout mechanism.
  507. * <p>
  508. * If <code>comp</code> is not in the <code>GridBagLayout</code>,
  509. * a set of default <code>GridBagConstraints</code> are returned.
  510. * A <code>comp</code> value of <code>null</code> is invalid
  511. * and returns <code>null</code>.
  512. *
  513. * @param comp the component to be queried
  514. * @return the contraints for the specified component
  515. */
  516. protected GridBagConstraints lookupConstraints(Component comp) {
  517. GridBagConstraints constraints = comptable.get(comp);
  518. if (constraints == null) {
  519. setConstraints(comp, defaultConstraints);
  520. constraints = comptable.get(comp);
  521. }
  522. return constraints;
  523. }
  524. /**
  525. * Removes the constraints for the specified component in this layout
  526. * @param comp the component to be modified
  527. */
  528. private void removeConstraints(Component comp) {
  529. comptable.remove(comp);
  530. }
  531. /**
  532. * Determines the origin of the layout area, in the graphics coordinate
  533. * space of the target container. This value represents the pixel
  534. * coordinates of the top-left corner of the layout area regardless of
  535. * the <code>ComponentOrientation</code> value of the container. This
  536. * is distinct from the grid origin given by the cell coordinates (0,0).
  537. * Most applications do not call this method directly.
  538. * @return the graphics origin of the cell in the top-left
  539. * corner of the layout grid
  540. * @see java.awt.ComponentOrientation
  541. * @since JDK1.1
  542. */
  543. public Point getLayoutOrigin () {
  544. Point origin = new Point(0,0);
  545. if (layoutInfo != null) {
  546. origin.x = layoutInfo.startx;
  547. origin.y = layoutInfo.starty;
  548. }
  549. return origin;
  550. }
  551. /**
  552. * Determines column widths and row heights for the layout grid.
  553. * <p>
  554. * Most applications do not call this method directly.
  555. * @return an array of two arrays, containing the widths
  556. * of the layout columns and
  557. * the heights of the layout rows
  558. * @since JDK1.1
  559. */
  560. public int [][] getLayoutDimensions () {
  561. if (layoutInfo == null)
  562. return new int[2][0];
  563. int dim[][] = new int [2][];
  564. dim[0] = new int[layoutInfo.width];
  565. dim[1] = new int[layoutInfo.height];
  566. System.arraycopy(layoutInfo.minWidth, 0, dim[0], 0, layoutInfo.width);
  567. System.arraycopy(layoutInfo.minHeight, 0, dim[1], 0, layoutInfo.height);
  568. return dim;
  569. }
  570. /**
  571. * Determines the weights of the layout grid's columns and rows.
  572. * Weights are used to calculate how much a given column or row
  573. * stretches beyond its preferred size, if the layout has extra
  574. * room to fill.
  575. * <p>
  576. * Most applications do not call this method directly.
  577. * @return an array of two arrays, representing the
  578. * horizontal weights of the layout columns
  579. * and the vertical weights of the layout rows
  580. * @since JDK1.1
  581. */
  582. public double [][] getLayoutWeights () {
  583. if (layoutInfo == null)
  584. return new double[2][0];
  585. double weights[][] = new double [2][];
  586. weights[0] = new double[layoutInfo.width];
  587. weights[1] = new double[layoutInfo.height];
  588. System.arraycopy(layoutInfo.weightX, 0, weights[0], 0, layoutInfo.width);
  589. System.arraycopy(layoutInfo.weightY, 0, weights[1], 0, layoutInfo.height);
  590. return weights;
  591. }
  592. /**
  593. * Determines which cell in the layout grid contains the point
  594. * specified by <code>(x,&nbsp;y)</code>. Each cell is identified
  595. * by its column index (ranging from 0 to the number of columns
  596. * minus 1) and its row index (ranging from 0 to the number of
  597. * rows minus 1).
  598. * <p>
  599. * If the <code>(x,&nbsp;y)</code> point lies
  600. * outside the grid, the following rules are used.
  601. * The column index is returned as zero if <code>x</code> lies to the
  602. * left of the layout for a left-to-right container or to the right of
  603. * the layout for a right-to-left container. The column index is returned
  604. * as the number of columns if <code>x</code> lies
  605. * to the right of the layout in a left-to-right container or to the left
  606. * in a right-to-left container.
  607. * The row index is returned as zero if <code>y</code> lies above the
  608. * layout, and as the number of rows if <code>y</code> lies
  609. * below the layout. The orientation of a container is determined by its
  610. * <code>ComponentOrientation</code> property.
  611. * @param x the <i>x</i> coordinate of a point
  612. * @param y the <i>y</i> coordinate of a point
  613. * @return an ordered pair of indexes that indicate which cell
  614. * in the layout grid contains the point
  615. * (<i>x</i>,&nbsp;<i>y</i>).
  616. * @see java.awt.ComponentOrientation
  617. * @since JDK1.1
  618. */
  619. public Point location(int x, int y) {
  620. Point loc = new Point(0,0);
  621. int i, d;
  622. if (layoutInfo == null)
  623. return loc;
  624. d = layoutInfo.startx;
  625. if (!rightToLeft) {
  626. for (i=0; i<layoutInfo.width; i++) {
  627. d += layoutInfo.minWidth[i];
  628. if (d > x)
  629. break;
  630. }
  631. } else {
  632. for (i=layoutInfo.width-1; i>=0; i--) {
  633. if (d > x)
  634. break;
  635. d += layoutInfo.minWidth[i];
  636. }
  637. i++;
  638. }
  639. loc.x = i;
  640. d = layoutInfo.starty;
  641. for (i=0; i<layoutInfo.height; i++) {
  642. d += layoutInfo.minHeight[i];
  643. if (d > y)
  644. break;
  645. }
  646. loc.y = i;
  647. return loc;
  648. }
  649. /**
  650. * Has no effect, since this layout manager does not use a per-component string.
  651. */
  652. public void addLayoutComponent(String name, Component comp) {
  653. }
  654. /**
  655. * Adds the specified component to the layout, using the specified
  656. * <code>constraints</code> object. Note that constraints
  657. * are mutable and are, therefore, cloned when cached.
  658. *
  659. * @param comp the component to be added
  660. * @param constraints an object that determines how
  661. * the component is added to the layout
  662. * @exception IllegalArgumentException if <code>constraints</code>
  663. * is not a <code>GridBagConstraint</code>
  664. */
  665. public void addLayoutComponent(Component comp, Object constraints) {
  666. if (constraints instanceof GridBagConstraints) {
  667. setConstraints(comp, (GridBagConstraints)constraints);
  668. } else if (constraints != null) {
  669. throw new IllegalArgumentException("cannot add to layout: constraints must be a GridBagConstraint");
  670. }
  671. }
  672. /**
  673. * Removes the specified component from this layout.
  674. * <p>
  675. * Most applications do not call this method directly.
  676. * @param comp the component to be removed.
  677. * @see java.awt.Container#remove(java.awt.Component)
  678. * @see java.awt.Container#removeAll()
  679. */
  680. public void removeLayoutComponent(Component comp) {
  681. removeConstraints(comp);
  682. }
  683. /**
  684. * Determines the preferred size of the <code>parent</code>
  685. * container using this grid bag layout.
  686. * <p>
  687. * Most applications do not call this method directly.
  688. *
  689. * @param parent the container in which to do the layout
  690. * @see java.awt.Container#getPreferredSize
  691. * @return the preferred size of the <code>parent</code>
  692. * container
  693. */
  694. public Dimension preferredLayoutSize(Container parent) {
  695. GridBagLayoutInfo info = getLayoutInfo(parent, PREFERREDSIZE);
  696. return getMinSize(parent, info);
  697. }
  698. /**
  699. * Determines the minimum size of the <code>parent</code> container
  700. * using this grid bag layout.
  701. * <p>
  702. * Most applications do not call this method directly.
  703. * @param parent the container in which to do the layout
  704. * @see java.awt.Container#doLayout
  705. * @return the minimum size of the <code>parent</code> container
  706. */
  707. public Dimension minimumLayoutSize(Container parent) {
  708. GridBagLayoutInfo info = getLayoutInfo(parent, MINSIZE);
  709. return getMinSize(parent, info);
  710. }
  711. /**
  712. * Returns the maximum dimensions for this layout given the components
  713. * in the specified target container.
  714. * @param target the container which needs to be laid out
  715. * @see Container
  716. * @see #minimumLayoutSize(Container)
  717. * @see #preferredLayoutSize(Container)
  718. * @return the maximum dimensions for this layout
  719. */
  720. public Dimension maximumLayoutSize(Container target) {
  721. return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
  722. }
  723. /**
  724. * Returns the alignment along the x axis. This specifies how
  725. * the component would like to be aligned relative to other
  726. * components. The value should be a number between 0 and 1
  727. * where 0 represents alignment along the origin, 1 is aligned
  728. * the furthest away from the origin, 0.5 is centered, etc.
  729. * <p>
  730. * @return the value <code>0.5f</code> to indicate centered
  731. */
  732. public float getLayoutAlignmentX(Container parent) {
  733. return 0.5f;
  734. }
  735. /**
  736. * Returns the alignment along the y axis. This specifies how
  737. * the component would like to be aligned relative to other
  738. * components. The value should be a number between 0 and 1
  739. * where 0 represents alignment along the origin, 1 is aligned
  740. * the furthest away from the origin, 0.5 is centered, etc.
  741. * <p>
  742. * @return the value <code>0.5f</code> to indicate centered
  743. */
  744. public float getLayoutAlignmentY(Container parent) {
  745. return 0.5f;
  746. }
  747. /**
  748. * Invalidates the layout, indicating that if the layout manager
  749. * has cached information it should be discarded.
  750. */
  751. public void invalidateLayout(Container target) {
  752. }
  753. /**
  754. * Lays out the specified container using this grid bag layout.
  755. * This method reshapes components in the specified container in
  756. * order to satisfy the contraints of this <code>GridBagLayout</code>
  757. * object.
  758. * <p>
  759. * Most applications do not call this method directly.
  760. * @param parent the container in which to do the layout
  761. * @see java.awt.Container
  762. * @see java.awt.Container#doLayout
  763. */
  764. public void layoutContainer(Container parent) {
  765. arrangeGrid(parent);
  766. }
  767. /**
  768. * Returns a string representation of this grid bag layout's values.
  769. * @return a string representation of this grid bag layout.
  770. */
  771. public String toString() {
  772. return getClass().getName();
  773. }
  774. /**
  775. * Print the layout information. Useful for debugging.
  776. */
  777. /* DEBUG
  778. *
  779. * protected void dumpLayoutInfo(GridBagLayoutInfo s) {
  780. * int x;
  781. *
  782. * System.out.println("Col\tWidth\tWeight");
  783. * for (x=0; x<s.width; x++) {
  784. * System.out.println(x + "\t" +
  785. * s.minWidth[x] + "\t" +
  786. * s.weightX[x]);
  787. * }
  788. * System.out.println("Row\tHeight\tWeight");
  789. * for (x=0; x<s.height; x++) {
  790. * System.out.println(x + "\t" +
  791. * s.minHeight[x] + "\t" +
  792. * s.weightY[x]);
  793. * }
  794. * }
  795. */
  796. /**
  797. * Print the layout constraints. Useful for debugging.
  798. */
  799. /* DEBUG
  800. *
  801. * protected void dumpConstraints(GridBagConstraints constraints) {
  802. * System.out.println(
  803. * "wt " +
  804. * constraints.weightx +
  805. * " " +
  806. * constraints.weighty +
  807. * ", " +
  808. *
  809. * "box " +
  810. * constraints.gridx +
  811. * " " +
  812. * constraints.gridy +
  813. * " " +
  814. * constraints.gridwidth +
  815. * " " +
  816. * constraints.gridheight +
  817. * ", " +
  818. *
  819. * "min " +
  820. * constraints.minWidth +
  821. * " " +
  822. * constraints.minHeight +
  823. * ", " +
  824. *
  825. * "pad " +
  826. * constraints.insets.bottom +
  827. * " " +
  828. * constraints.insets.left +
  829. * " " +
  830. * constraints.insets.right +
  831. * " " +
  832. * constraints.insets.top +
  833. * " " +
  834. * constraints.ipadx +
  835. * " " +
  836. * constraints.ipady);
  837. * }
  838. */
  839. /**
  840. * Fills in an instance of <code>GridBagLayoutInfo</code> for the
  841. * current set of managed children. This requires three passes through the
  842. * set of children:
  843. *
  844. * <ol>
  845. * <li>Figure out the dimensions of the layout grid.
  846. * <li>Determine which cells the components occupy.
  847. * <li>Distribute the weights and min sizes amoung the rows/columns.
  848. * </ol>
  849. *
  850. * This also caches the minsizes for all the children when they are
  851. * first encountered (so subsequent loops don't need to ask again).
  852. * <p>
  853. * This method should only be used internally by
  854. * <code>GridBagLayout</code>.
  855. *
  856. * @param parent the layout container
  857. * @param sizeflag either <code>PREFERREDSIZE</code> or
  858. * <code>MINSIZE</code>
  859. * @return the <code>GridBagLayoutInfo</code> for the set of children
  860. * @since 1.4
  861. */
  862. protected GridBagLayoutInfo getLayoutInfo(Container parent, int sizeflag) {
  863. return GetLayoutInfo(parent, sizeflag);
  864. }
  865. /*
  866. * Calculate maximum array sizes to allocate arrays without ensureCapacity
  867. * we may use preCalculated sizes in whole class because of upper estimation of
  868. * maximumArrayXIndex and maximumArrayYIndex.
  869. */
  870. private long[] preInitMaximumArraySizes(Container parent){
  871. Component components[] = parent.getComponents();
  872. Component comp;
  873. GridBagConstraints constraints;
  874. int curX, curY;
  875. int curWidth, curHeight;
  876. int preMaximumArrayXIndex = 0;
  877. int preMaximumArrayYIndex = 0;
  878. long [] returnArray = new long[2];
  879. for (int compId = 0 ; compId < components.length ; compId++) {
  880. comp = components[compId];
  881. if (!comp.isVisible()) {
  882. continue;
  883. }
  884. constraints = lookupConstraints(comp);
  885. curX = constraints.gridx;
  886. curY = constraints.gridy;
  887. curWidth = constraints.gridwidth;
  888. curHeight = constraints.gridheight;
  889. // -1==RELATIVE, means that column|row equals to previously added component,
  890. // since each next Component with gridx|gridy == RELATIVE starts from
  891. // previous position, so we should start from previous component which
  892. // already used in maximumArray[X|Y]Index calculation. We could just increase
  893. // maximum by 1 to handle situation when component with gridx=-1 was added.
  894. if (curX < 0){
  895. curX = ++preMaximumArrayYIndex;
  896. }
  897. if (curY < 0){
  898. curY = ++preMaximumArrayXIndex;
  899. }
  900. // gridwidth|gridheight may be equal to RELATIVE (-1) or REMAINDER (0)
  901. // in any case using 1 instead of 0 or -1 should be sufficient to for
  902. // correct maximumArraySizes calculation
  903. if (curWidth <= 0){
  904. curWidth = 1;
  905. }
  906. if (curHeight <= 0){
  907. curHeight = 1;
  908. }
  909. preMaximumArrayXIndex = Math.max(curY + curHeight, preMaximumArrayXIndex);
  910. preMaximumArrayYIndex = Math.max(curX + curWidth, preMaximumArrayYIndex);
  911. } //for (components) loop
  912. // Must specify index++ to allocate well-working arrays.
  913. /* fix for 4623196.
  914. * now return long array instead of Point
  915. */
  916. returnArray[0] = preMaximumArrayXIndex;
  917. returnArray[1] = preMaximumArrayYIndex;
  918. return returnArray;
  919. } //PreInitMaximumSizes
  920. /**
  921. * This method is obsolete and supplied for backwards
  922. * compatability only; new code should call {@link
  923. * #getLayoutInfo(java.awt.Container, int) getLayoutInfo} instead.
  924. * This method is the same as <code>getLayoutInfo</code>;
  925. * refer to <code>getLayoutInfo</code> for details on parameters
  926. * and return value.
  927. */
  928. protected GridBagLayoutInfo GetLayoutInfo(Container parent, int sizeflag) {
  929. synchronized (parent.getTreeLock()) {
  930. GridBagLayoutInfo r;
  931. Component comp;
  932. GridBagConstraints constraints;
  933. Dimension d;
  934. Component components[] = parent.getComponents();
  935. // Code below will address index curX+curWidth in the case of yMaxArray, weightY
  936. // ( respectively curY+curHeight for xMaxArray, weightX ) where
  937. // curX in 0 to preInitMaximumArraySizes.y
  938. // Thus, the maximum index that could
  939. // be calculated in the following code is curX+curX.
  940. // EmpericMultier equals 2 because of this.
  941. int layoutWidth, layoutHeight;
  942. int []xMaxArray;
  943. int []yMaxArray;
  944. int compindex, i, k, px, py, pixels_diff, nextSize;
  945. int curX = 0; // constraints.gridx
  946. int curY = 0; // constraints.gridy
  947. int curWidth = 1; // constraints.gridwidth
  948. int curHeight = 1; // constraints.gridheight
  949. int curRow, curCol;
  950. double weight_diff, weight;
  951. int maximumArrayXIndex = 0;
  952. int maximumArrayYIndex = 0;
  953. int anchor;
  954. /*
  955. * Pass #1
  956. *
  957. * Figure out the dimensions of the layout grid (use a value of 1 for
  958. * zero or negative widths and heights).
  959. */
  960. layoutWidth = layoutHeight = 0;
  961. curRow = curCol = -1;
  962. long [] arraySizes = preInitMaximumArraySizes(parent);
  963. /* fix for 4623196.
  964. * If user try to create a very big grid we can
  965. * get NegativeArraySizeException because of integer value
  966. * overflow (EMPIRICMULTIPLIER*gridSize might be more then Integer.MAX_VALUE).
  967. * We need to detect this situation and try to create a
  968. * grid with Integer.MAX_VALUE size instead.
  969. */
  970. maximumArrayXIndex = (EMPIRICMULTIPLIER * arraySizes[0] > Integer.MAX_VALUE )? Integer.MAX_VALUE : EMPIRICMULTIPLIER*(int)arraySizes[0];
  971. maximumArrayYIndex = (EMPIRICMULTIPLIER * arraySizes[1] > Integer.MAX_VALUE )? Integer.MAX_VALUE : EMPIRICMULTIPLIER*(int)arraySizes[1];
  972. if (rowHeights != null){
  973. maximumArrayXIndex = Math.max(maximumArrayXIndex, rowHeights.length);
  974. }
  975. if (columnWidths != null){
  976. maximumArrayYIndex = Math.max(maximumArrayYIndex, columnWidths.length);
  977. }
  978. xMaxArray = new int[maximumArrayXIndex];
  979. yMaxArray = new int[maximumArrayYIndex];
  980. boolean hasBaseline = false;
  981. for (compindex = 0 ; compindex < components.length ; compindex++) {
  982. comp = components[compindex];
  983. if (!comp.isVisible())
  984. continue;
  985. constraints = lookupConstraints(comp);
  986. curX = constraints.gridx;
  987. curY = constraints.gridy;
  988. curWidth = constraints.gridwidth;
  989. if (curWidth <= 0)
  990. curWidth = 1;
  991. curHeight = constraints.gridheight;
  992. if (curHeight <= 0)
  993. curHeight = 1;
  994. /* If x or y is negative, then use relative positioning: */
  995. if (curX < 0 && curY < 0) {
  996. if (curRow >= 0)
  997. curY = curRow;
  998. else if (curCol >= 0)
  999. curX = curCol;
  1000. else
  1001. curY = 0;
  1002. }
  1003. if (curX < 0) {
  1004. px = 0;
  1005. for (i = curY; i < (curY + curHeight); i++) {
  1006. px = Math.max(px, xMaxArray[i]);
  1007. }
  1008. curX = px - curX - 1;
  1009. if(curX < 0)
  1010. curX = 0;
  1011. }
  1012. else if (curY < 0) {
  1013. py = 0;
  1014. for (i = curX; i < (curX + curWidth); i++) {
  1015. py = Math.max(py, yMaxArray[i]);
  1016. }
  1017. curY = py - curY - 1;
  1018. if(curY < 0)
  1019. curY = 0;
  1020. }
  1021. /* Adjust the grid width and height
  1022. * fix for 5005945: unneccessary loops removed
  1023. */
  1024. px = curX + curWidth;
  1025. if (layoutWidth < px) {
  1026. layoutWidth = px;
  1027. }
  1028. py = curY + curHeight;
  1029. if (layoutHeight < py) {
  1030. layoutHeight = py;
  1031. }
  1032. /* Adjust xMaxArray and yMaxArray */
  1033. for (i = curX; i < (curX + curWidth); i++) {
  1034. yMaxArray[i] =py;
  1035. }
  1036. for (i = curY; i < (curY + curHeight); i++) {
  1037. xMaxArray[i] = px;
  1038. }
  1039. /* Cache the current slave's size. */
  1040. if (sizeflag == PREFERREDSIZE)
  1041. d = comp.getPreferredSize();
  1042. else
  1043. d = comp.getMinimumSize();
  1044. constraints.minWidth = d.width;
  1045. constraints.minHeight = d.height;
  1046. if (calculateBaseline(comp, constraints, d)) {
  1047. hasBaseline = true;
  1048. }
  1049. /* Zero width and height must mean that this is the last item (or
  1050. * else something is wrong). */
  1051. if (constraints.gridheight == 0 && constraints.gridwidth == 0)
  1052. curRow = curCol = -1;
  1053. /* Zero width starts a new row */
  1054. if (constraints.gridheight == 0 && curRow < 0)
  1055. curCol = curX + curWidth;
  1056. /* Zero height starts a new column */
  1057. else if (constraints.gridwidth == 0 && curCol < 0)
  1058. curRow = curY + curHeight;
  1059. } //for (components) loop
  1060. /*
  1061. * Apply minimum row/column dimensions
  1062. */
  1063. if (columnWidths != null && layoutWidth < columnWidths.length)
  1064. layoutWidth = columnWidths.length;
  1065. if (rowHeights != null && layoutHeight < rowHeights.length)
  1066. layoutHeight = rowHeights.length;
  1067. r = new GridBagLayoutInfo(layoutWidth, layoutHeight);
  1068. /*
  1069. * Pass #2
  1070. *
  1071. * Negative values for gridX are filled in with the current x value.
  1072. * Negative values for gridY are filled in with the current y value.
  1073. * Negative or zero values for gridWidth and gridHeight end the current
  1074. * row or column, respectively.
  1075. */
  1076. curRow = curCol = -1;
  1077. Arrays.fill(xMaxArray, 0);
  1078. Arrays.fill(yMaxArray, 0);
  1079. int[] maxAscent = null;
  1080. int[] maxDescent = null;
  1081. short[] baselineType = null;
  1082. if (hasBaseline) {
  1083. r.maxAscent = maxAscent = new int[layoutHeight];
  1084. r.maxDescent = maxDescent = new int[layoutHeight];
  1085. r.baselineType = baselineType = new short[layoutHeight];
  1086. r.hasBaseline = true;
  1087. }
  1088. for (compindex = 0 ; compindex < components.length ; compindex++) {
  1089. comp = components[compindex];
  1090. if (!comp.isVisible())
  1091. continue;
  1092. constraints = lookupConstraints(comp);
  1093. curX = constraints.gridx;
  1094. curY = constraints.gridy;
  1095. curWidth = constraints.gridwidth;
  1096. curHeight = constraints.gridheight;
  1097. /* If x or y is negative, then use relative positioning: */
  1098. if (curX < 0 && curY < 0) {
  1099. if(curRow >= 0)
  1100. curY = curRow;
  1101. else if(curCol >= 0)
  1102. curX = curCol;
  1103. else
  1104. curY = 0;
  1105. }
  1106. if (curX < 0) {
  1107. if (curHeight <= 0) {
  1108. curHeight += r.height - curY;
  1109. if (curHeight < 1)
  1110. curHeight = 1;
  1111. }
  1112. px = 0;
  1113. for (i = curY; i < (curY + curHeight); i++)
  1114. px = Math.max(px, xMaxArray[i]);
  1115. curX = px - curX - 1;
  1116. if(curX < 0)
  1117. curX = 0;
  1118. }
  1119. else if (curY < 0) {
  1120. if (curWidth <= 0) {
  1121. curWidth += r.width - curX;
  1122. if (curWidth < 1)
  1123. curWidth = 1;
  1124. }
  1125. py = 0;
  1126. for (i = curX; i < (curX + curWidth); i++){
  1127. py = Math.max(py, yMaxArray[i]);
  1128. }
  1129. curY = py - curY - 1;
  1130. if(curY < 0)
  1131. curY = 0;
  1132. }
  1133. if (curWidth <= 0) {
  1134. curWidth += r.width - curX;
  1135. if (curWidth < 1)
  1136. curWidth = 1;
  1137. }
  1138. if (curHeight <= 0) {
  1139. curHeight += r.height - curY;
  1140. if (curHeight < 1)
  1141. curHeight = 1;
  1142. }
  1143. px = curX + curWidth;
  1144. py = curY + curHeight;
  1145. for (i = curX; i < (curX + curWidth); i++) { yMaxArray[i] = py; }
  1146. for (i = curY; i < (curY + curHeight); i++) { xMaxArray[i] = px; }
  1147. /* Make negative sizes start a new row/column */
  1148. if (constraints.gridheight == 0 && constraints.gridwidth == 0)
  1149. curRow = curCol = -1;
  1150. if (constraints.gridheight == 0 && curRow < 0)
  1151. curCol = curX + curWidth;
  1152. else if (constraints.gridwidth == 0 && curCol < 0)
  1153. curRow = curY + curHeight;
  1154. /* Assign the new values to the gridbag slave */
  1155. constraints.tempX = curX;
  1156. constraints.tempY = curY;
  1157. constraints.tempWidth = curWidth;
  1158. constraints.tempHeight = curHeight;
  1159. anchor = constraints.anchor;
  1160. if (hasBaseline) {
  1161. switch(anchor)

Large files files are truncated, but you can click here to view the full file