SpringLayout.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  1. /* SpringLayout.java --
  2. Copyright (C) 2004, 2006, Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package javax.swing;
  32. import java.awt.Component;
  33. import java.awt.Container;
  34. import java.awt.Dimension;
  35. import java.awt.LayoutManager2;
  36. import java.util.HashMap;
  37. import java.util.Map;
  38. /**
  39. * A very flexible layout manager. Components are laid out by defining the
  40. * relationships between them. The relationships are expressed as
  41. * {@link Spring}s. You can attach a Spring for each edge of a component and
  42. * link it to an edge of a different component. For example, you can say,
  43. * the northern edge of component A should be attached to the southern edge
  44. * of component B, and the space between them should be something between
  45. * x and y pixels, and preferably z pixels.
  46. * <p>While quite simple, this layout manager can be used to emulate most other
  47. * layout managers, and can also be used to solve some layout problems, which
  48. * would be hard to solve with other layout managers.</p>
  49. *
  50. * @author Roman Kennke (roman@ontographics.com)
  51. */
  52. public class SpringLayout implements LayoutManager2
  53. {
  54. /** The right edge of a component. */
  55. public static final String EAST = "East";
  56. /** The top edge of a component. */
  57. public static final String NORTH = "North";
  58. /** The bottom edge of a component. */
  59. public static final String SOUTH = "South";
  60. /** The left edge of a component. */
  61. public static final String WEST = "West";
  62. /** maps components to their constraints. */
  63. private Map constraintsMap;
  64. /**
  65. * The constraints that define the relationships between components.
  66. * Each Constraints object can hold 4 Springs: one for each edge of the
  67. * component. Additionally it can hold Springs for the components width
  68. * and the components height. Since the height and width constraints are
  69. * dependend on the other constraints, a component can be over-constraint.
  70. * In this case (like when all of NORTH, SOUTH and HEIGHT are constraint),
  71. * the values are adjusted, so that the mathematics still hold true.
  72. *
  73. * @author Roman Kennke (roman@ontographics.com)
  74. */
  75. public static class Constraints
  76. {
  77. // The constraints for each edge, and width and height.
  78. /** The Spring for the left edge. */
  79. private Spring x;
  80. /** The Spring for the upper edge. */
  81. private Spring y;
  82. /** The Spring for the height. */
  83. private Spring height;
  84. /** The Spring for the width. */
  85. private Spring width;
  86. /** The Spring for the right edge. */
  87. private Spring east;
  88. /** The Spring for the bottom edge. */
  89. private Spring south;
  90. /**
  91. In each axis the user can set three values, i.e. x, width, east, if all
  92. three are set, then there's no room for manoeuvre so in those cases the
  93. third will be described by the below spring which is calculated in terms
  94. of the other two
  95. */
  96. private Spring v;
  97. private Spring h;
  98. /**
  99. * Creates a new Constraints object.
  100. * There is no constraint set.
  101. */
  102. public Constraints()
  103. {
  104. x = y = height = width = east = south = v = h = null;
  105. }
  106. /**
  107. * Creates a new Constraints object.
  108. *
  109. * @param x the constraint for the left edge of the component.
  110. * @param y the constraint for the upper edge of the component.
  111. */
  112. public Constraints(Spring x, Spring y)
  113. {
  114. this.x = x;
  115. this.y = y;
  116. width = height = east = south = v = h = null;
  117. }
  118. /**
  119. * Creates a new Constraints object.
  120. *
  121. * @param x the constraint for the left edge of the component.
  122. * @param y the constraint for the upper edge of the component.
  123. * @param width the constraint for the width of the component.
  124. * @param height the constraint for the height of the component.
  125. */
  126. public Constraints(Spring x, Spring y, Spring width, Spring height)
  127. {
  128. this.x = x;
  129. this.y = y;
  130. this.width = width;
  131. this.height = height;
  132. east = south = v = h = null;
  133. }
  134. /**
  135. * Create a new Constraints object which tracks the indicated
  136. * component. The x and y positions for this Constraints object
  137. * are constant Springs created with the component's location at
  138. * the time this constructor is called. The width and height
  139. * of this Constraints are Springs created using
  140. * {@link Spring#width(Component)} and {@link Spring#height(Component)},
  141. * respectively.
  142. * @param component the component to track
  143. * @since 1.5
  144. */
  145. public Constraints(Component component)
  146. {
  147. this(Spring.constant(component.getX()),
  148. Spring.constant(component.getY()),
  149. Spring.width(component),
  150. Spring.height(component));
  151. }
  152. /**
  153. * Returns the constraint for the edge with the <code>edgeName</code>.
  154. * This is expected to be one of
  155. * {@link #EAST}, {@link #WEST}, {@link #NORTH} or {@link #SOUTH}.
  156. *
  157. * @param edgeName the name of the edge.
  158. * @return the constraint for the specified edge.
  159. */
  160. public Spring getConstraint(String edgeName)
  161. {
  162. Spring retVal = null;
  163. if (edgeName.equals(SpringLayout.NORTH))
  164. retVal = getY();
  165. else if (edgeName.equals(SpringLayout.WEST))
  166. retVal = getX();
  167. else if (edgeName.equals(SpringLayout.SOUTH))
  168. retVal = getSouth();
  169. else if (edgeName.equals(SpringLayout.EAST))
  170. retVal = getEast();
  171. return retVal;
  172. }
  173. /**
  174. * Returns the constraint for the height of the component.
  175. *
  176. * @return the height constraint.
  177. */
  178. public Spring getHeight()
  179. {
  180. if (height != null)
  181. return height;
  182. else if ((v == null) && (y != null) && (south != null))
  183. v = Spring.sum(south, Spring.minus(y));
  184. return v;
  185. }
  186. /**
  187. * Returns the constraint for the width of the component.
  188. *
  189. * @return the width constraint.
  190. */
  191. public Spring getWidth()
  192. {
  193. if (width != null)
  194. return width;
  195. else if ((h == null) && (x != null) && (east != null))
  196. h = Spring.sum(east, Spring.minus(x));
  197. return h;
  198. }
  199. /**
  200. * Returns the constraint for the left edge of the component.
  201. *
  202. * @return the left-edge constraint (== WEST).
  203. */
  204. public Spring getX()
  205. {
  206. if (x != null)
  207. return x;
  208. else if ((h == null) && (width != null) && (east != null))
  209. h = Spring.sum(east, Spring.minus(width));
  210. return h;
  211. }
  212. /**
  213. * Returns the constraint for the upper edge of the component.
  214. *
  215. * @return the upper-edge constraint (== NORTH).
  216. */
  217. public Spring getY()
  218. {
  219. if (y != null)
  220. return y;
  221. else if ((v == null) && (height != null) && (south != null))
  222. v = Spring.sum(south, Spring.minus(height));
  223. return v;
  224. }
  225. /**
  226. * Returns the constraint for the lower edge of the component.
  227. *
  228. * @return the lower-edge constraint (== SOUTH).
  229. */
  230. public Spring getSouth()
  231. {
  232. if (south != null)
  233. return south;
  234. else if ((v == null) && (height != null) && (y != null))
  235. v = Spring.sum(y, height);
  236. return v;
  237. }
  238. /**
  239. * Returns the constraint for the right edge of the component.
  240. *
  241. * @return the right-edge constraint (== EAST).
  242. */
  243. public Spring getEast()
  244. {
  245. if (east != null)
  246. return east;
  247. else if ((h == null) && (width != null) && (x != null))
  248. h = Spring.sum(x, width);
  249. return h;
  250. }
  251. /**
  252. * Sets a constraint for the specified edge. If this leads to an
  253. * over-constrained situation, the constraints get adjusted, so that
  254. * the mathematics still hold true.
  255. *
  256. * @param edgeName the name of the edge, one of {@link #EAST},
  257. * {@link #WEST}, {@link #NORTH} or {@link #SOUTH}.
  258. * @param s the constraint to be set.
  259. */
  260. public void setConstraint(String edgeName, Spring s)
  261. {
  262. if (edgeName.equals(SpringLayout.WEST))
  263. setX(s);
  264. else if (edgeName.equals(SpringLayout.NORTH))
  265. setY(s);
  266. else if (edgeName.equals(SpringLayout.EAST))
  267. setEast(s);
  268. else if (edgeName.equals(SpringLayout.SOUTH))
  269. setSouth(s);
  270. }
  271. /**
  272. * Sets the height-constraint.
  273. *
  274. * @param s the constraint to be set.
  275. */
  276. public void setHeight(Spring s)
  277. {
  278. height = s;
  279. v = null;
  280. if ((south != null) && (y != null) && (height != null))
  281. south = null;
  282. }
  283. /**
  284. * Sets the width-constraint.
  285. *
  286. * @param s the constraint to be set.
  287. */
  288. public void setWidth(Spring s)
  289. {
  290. width = s;
  291. h = null;
  292. if ((east != null) && (x != null) && (width != null))
  293. east = null;
  294. }
  295. /**
  296. * Sets the WEST-constraint.
  297. *
  298. * @param s the constraint to be set.
  299. */
  300. public void setX(Spring s)
  301. {
  302. x = s;
  303. h = null;
  304. if ((width != null) && (east != null) && (x != null))
  305. width = null;
  306. }
  307. /**
  308. * Sets the NORTH-constraint.
  309. *
  310. * @param s the constraint to be set.
  311. */
  312. public void setY(Spring s)
  313. {
  314. y = s;
  315. v = null;
  316. if ((height != null) && (south != null) && (y != null))
  317. height = null;
  318. }
  319. /**
  320. * Sets the SOUTH-constraint.
  321. *
  322. * @param s the constraint to be set.
  323. */
  324. public void setSouth(Spring s)
  325. {
  326. south = s;
  327. v = null;
  328. if ((height != null) && (south != null) && (y != null))
  329. y = null;
  330. }
  331. /**
  332. * Sets the EAST-constraint.
  333. *
  334. * @param s the constraint to be set.
  335. */
  336. public void setEast(Spring s)
  337. {
  338. east = s;
  339. h = null;
  340. if ((width != null) && (east != null) && (x != null))
  341. x = null;
  342. }
  343. public void dropCalcResult()
  344. {
  345. if (x != null)
  346. x.setValue(Spring.UNSET);
  347. if (y != null)
  348. y.setValue(Spring.UNSET);
  349. if (width != null)
  350. width.setValue(Spring.UNSET);
  351. if (height != null)
  352. height.setValue(Spring.UNSET);
  353. if (east != null)
  354. east.setValue(Spring.UNSET);
  355. if (south != null)
  356. south.setValue(Spring.UNSET);
  357. if (h != null)
  358. h.setValue(Spring.UNSET);
  359. if (v != null)
  360. v.setValue(Spring.UNSET);
  361. }
  362. }
  363. /**
  364. * Creates a new SpringLayout.
  365. */
  366. public SpringLayout()
  367. {
  368. constraintsMap = new HashMap();
  369. }
  370. /**
  371. * Adds a layout component and a constraint object to this layout.
  372. * This method is usually only called by a {@link java.awt.Container}s add
  373. * method.
  374. *
  375. * @param component the component to be added.
  376. * @param constraint the constraint to be set.
  377. */
  378. public void addLayoutComponent(Component component, Object constraint)
  379. {
  380. constraintsMap.put(component, constraint);
  381. }
  382. /**
  383. * Adds a layout component and a constraint object to this layout.
  384. * This method is usually only called by a {@link java.awt.Container}s add
  385. * method. This method does nothing, since SpringLayout does not manage
  386. * String-indexed components.
  387. *
  388. * @param name the name.
  389. * @param c the component to be added.
  390. */
  391. public void addLayoutComponent(String name, Component c)
  392. {
  393. // do nothing here.
  394. }
  395. /**
  396. * The trick to SpringLayout is that the network of Springs needs to
  397. * completely created before the positioning results are generated.
  398. *
  399. * Using the springs directly during network creation will set their values
  400. * before the network is completed, Using Deferred Springs during creation of
  401. * the network allows all the edges to be connected together and the network
  402. * to be created without resolving the Springs until their results need to be
  403. * known, at which point the network is complete and the spring addition and
  404. * and substitution calculations will work on a complete and valid network.
  405. *
  406. * @author Caolan McNamara (caolanm@redhat.com)
  407. */
  408. private static class DeferredSpring extends Spring
  409. {
  410. private SpringLayout sl;
  411. private String edgeName;
  412. private Component c;
  413. public String toString()
  414. {
  415. return "DeferredSpring of edge" + edgeName + " of " + "something";
  416. }
  417. public DeferredSpring(SpringLayout s, String edge, Component component)
  418. {
  419. sl = s;
  420. edgeName = edge;
  421. c = component;
  422. }
  423. private Spring resolveSpring()
  424. {
  425. return sl.getConstraints(c).getConstraint(edgeName);
  426. }
  427. public int getMaximumValue()
  428. {
  429. return resolveSpring().getMaximumValue();
  430. }
  431. public int getMinimumValue()
  432. {
  433. return resolveSpring().getMinimumValue();
  434. }
  435. public int getPreferredValue()
  436. {
  437. return resolveSpring().getPreferredValue();
  438. }
  439. public int getValue()
  440. {
  441. int nRet = resolveSpring().getValue();
  442. if (nRet == Spring.UNSET)
  443. nRet = getPreferredValue();
  444. return nRet;
  445. }
  446. public void setValue(int size)
  447. {
  448. resolveSpring().setValue(size);
  449. }
  450. }
  451. private abstract static class DeferredDimension extends Spring
  452. {
  453. private int value;
  454. public DeferredDimension()
  455. {
  456. value = Spring.UNSET;
  457. }
  458. public void setValue(int val)
  459. {
  460. value = val;
  461. }
  462. public int getValue()
  463. {
  464. if (value == Spring.UNSET)
  465. return getPreferredValue();
  466. return value;
  467. }
  468. }
  469. private static class DeferredWidth extends DeferredDimension
  470. {
  471. private Component c;
  472. public DeferredWidth(Component component)
  473. {
  474. c = component;
  475. }
  476. public String toString()
  477. {
  478. return "DeferredWidth of " + "something";
  479. }
  480. //clip max to a value we can do meaningful calculation with
  481. public int getMaximumValue()
  482. {
  483. int widget_width = c.getMaximumSize().width;
  484. return Math.min(Short.MAX_VALUE, widget_width);
  485. }
  486. public int getMinimumValue()
  487. {
  488. return c.getMinimumSize().width;
  489. }
  490. public int getPreferredValue()
  491. {
  492. return c.getPreferredSize().width;
  493. }
  494. }
  495. private static class DeferredHeight extends DeferredDimension
  496. {
  497. private Component c;
  498. public String toString()
  499. {
  500. return "DeferredHeight of " + "something";
  501. }
  502. public DeferredHeight(Component component)
  503. {
  504. c = component;
  505. }
  506. //clip max to a value we can do meaningful calculations with it
  507. public int getMaximumValue()
  508. {
  509. int widget_height = c.getMaximumSize().height;
  510. return Math.min(Short.MAX_VALUE, widget_height);
  511. }
  512. public int getMinimumValue()
  513. {
  514. return c.getMinimumSize().height;
  515. }
  516. public int getPreferredValue()
  517. {
  518. return c.getPreferredSize().height;
  519. }
  520. }
  521. /**
  522. * Returns the constraint of the edge named by <code>edgeName</code>.
  523. *
  524. * @param c the component from which to get the constraint.
  525. * @param edgeName the name of the edge, one of {@link #EAST},
  526. * {@link #WEST}, {@link #NORTH} or {@link #SOUTH}.
  527. * @return the constraint of the edge <code>edgeName</code> of the
  528. * component c.
  529. */
  530. public Spring getConstraint(String edgeName, Component c)
  531. {
  532. return new DeferredSpring(this, edgeName, c);
  533. }
  534. /**
  535. * Returns the {@link Constraints} object associated with the specified
  536. * component.
  537. *
  538. * @param c the component for which to determine the constraint.
  539. * @return the {@link Constraints} object associated with the specified
  540. * component.
  541. */
  542. public SpringLayout.Constraints getConstraints(Component c)
  543. {
  544. Constraints constraints = (Constraints) constraintsMap.get(c);
  545. if (constraints == null)
  546. {
  547. constraints = new Constraints();
  548. constraints.setWidth(new DeferredWidth(c));
  549. constraints.setHeight(new DeferredHeight(c));
  550. constraints.setX(Spring.constant(0));
  551. constraints.setY(Spring.constant(0));
  552. constraintsMap.put(c, constraints);
  553. }
  554. return constraints;
  555. }
  556. /**
  557. * Returns the X alignment of the Container <code>p</code>.
  558. *
  559. * @param p
  560. * the {@link java.awt.Container} for which to determine the X
  561. * alignment.
  562. * @return always 0.0
  563. */
  564. public float getLayoutAlignmentX(Container p)
  565. {
  566. return 0.0F;
  567. }
  568. /**
  569. * Returns the Y alignment of the Container <code>p</code>.
  570. *
  571. * @param p the {@link java.awt.Container} for which to determine the Y
  572. * alignment.
  573. * @return always 0.0
  574. */
  575. public float getLayoutAlignmentY(Container p)
  576. {
  577. return 0.0F;
  578. }
  579. /**
  580. * Recalculate a possibly cached layout.
  581. */
  582. public void invalidateLayout(Container p)
  583. {
  584. // nothing to do here yet
  585. }
  586. private Constraints initContainer(Container p)
  587. {
  588. Constraints c = getConstraints(p);
  589. c.setX(Spring.constant(0));
  590. c.setY(Spring.constant(0));
  591. c.setWidth(null);
  592. c.setHeight(null);
  593. if (c.getEast() == null)
  594. c.setEast(Spring.constant(0, 0, Integer.MAX_VALUE));
  595. if (c.getSouth() == null)
  596. c.setSouth(Spring.constant(0, 0, Integer.MAX_VALUE));
  597. return c;
  598. }
  599. /**
  600. * Lays out the container <code>p</code>.
  601. *
  602. * @param p the container to be laid out.
  603. */
  604. public void layoutContainer(Container p)
  605. {
  606. java.awt.Insets insets = p.getInsets();
  607. Component[] components = p.getComponents();
  608. Constraints cs = initContainer(p);
  609. cs.dropCalcResult();
  610. for (int index = 0 ; index < components.length; index++)
  611. {
  612. Component c = components[index];
  613. getConstraints(c).dropCalcResult();
  614. }
  615. int offsetX = p.getInsets().left;
  616. int offsetY = p.getInsets().right;
  617. cs.getX().setValue(0);
  618. cs.getY().setValue(0);
  619. cs.getWidth().setValue(p.getWidth() - offsetX - insets.right);
  620. cs.getHeight().setValue(p.getHeight() - offsetY - insets.bottom);
  621. for (int index = 0; index < components.length; index++)
  622. {
  623. Component c = components[index];
  624. Constraints constraints = getConstraints(c);
  625. int x = constraints.getX().getValue();
  626. int y = constraints.getY().getValue();
  627. int width = constraints.getWidth().getValue();
  628. int height = constraints.getHeight().getValue();
  629. c.setBounds(x + offsetX, y + offsetY, width, height);
  630. }
  631. }
  632. /**
  633. * Calculates the maximum size of the layed out container. This
  634. * respects the maximum sizes of all contained components.
  635. *
  636. * @param p the container to be laid out.
  637. * @return the maximum size of the container.
  638. */
  639. public Dimension maximumLayoutSize(Container p)
  640. {
  641. java.awt.Insets insets = p.getInsets();
  642. Constraints cs = initContainer(p);
  643. int maxX = cs.getWidth().getMaximumValue() + insets.left + insets.right;
  644. int maxY = cs.getHeight().getMaximumValue() + insets.top + insets.bottom;
  645. return new Dimension(maxX, maxY);
  646. }
  647. /**
  648. * Calculates the minimum size of the layed out container. This
  649. * respects the minimum sizes of all contained components.
  650. *
  651. * @param p the container to be laid out.
  652. * @return the minimum size of the container.
  653. */
  654. public Dimension minimumLayoutSize(Container p)
  655. {
  656. java.awt.Insets insets = p.getInsets();
  657. Constraints cs = initContainer(p);
  658. int maxX = cs.getWidth().getMinimumValue() + insets.left + insets.right;
  659. int maxY = cs.getHeight().getMinimumValue() + insets.top + insets.bottom;
  660. return new Dimension(maxX, maxY);
  661. }
  662. /**
  663. * Calculates the preferred size of the layed out container. This
  664. * respects the preferred sizes of all contained components.
  665. *
  666. * @param p the container to be laid out.
  667. * @return the preferred size of the container.
  668. */
  669. public Dimension preferredLayoutSize(Container p)
  670. {
  671. java.awt.Insets insets = p.getInsets();
  672. Constraints cs = initContainer(p);
  673. int maxX = cs.getWidth().getPreferredValue() + insets.left + insets.right;
  674. int maxY = cs.getHeight().getPreferredValue() + insets.top + insets.bottom;
  675. return new Dimension(maxX, maxY);
  676. }
  677. /**
  678. * Attaches the edge <code>e1</code> of component <code>c1</code> to
  679. * the edge <code>e2</code> of component <code>c2</code> width the
  680. * fixed strut <code>pad</code>.
  681. *
  682. * @param e1 the edge of component 1.
  683. * @param c1 the component 1.
  684. * @param pad the space between the components in pixels.
  685. * @param e2 the edge of component 2.
  686. * @param c2 the component 2.
  687. */
  688. public void putConstraint(String e1, Component c1, int pad, String e2,
  689. Component c2)
  690. {
  691. putConstraint(e1, c1, Spring.constant(pad), e2, c2);
  692. }
  693. /**
  694. * Attaches the edge <code>e1</code> of component <code>c1</code> to
  695. * the edge <code>e2</code> of component <code>c2</code> width the
  696. * {@link Spring} <code>s</code>.
  697. *
  698. * @param e1 the edge of component 1.
  699. * @param c1 the component 1.
  700. * @param s the space between the components as a {@link Spring} object.
  701. * @param e2 the edge of component 2.
  702. * @param c2 the component 2.
  703. */
  704. public void putConstraint(String e1, Component c1, Spring s, String e2,
  705. Component c2)
  706. {
  707. Constraints constraints1 = getConstraints(c1);
  708. Spring otherEdge = getConstraint(e2, c2);
  709. constraints1.setConstraint(e1, Spring.sum(s, otherEdge));
  710. }
  711. /**
  712. * Removes a layout component.
  713. * @param c the layout component to remove.
  714. */
  715. public void removeLayoutComponent(Component c)
  716. {
  717. // do nothing here
  718. }
  719. }