| AbstractLayout.java |
1 /**
2 * Distribution License:
3 * JSword is free software; you can redistribute it and/or modify it under
4 * the terms of the GNU Lesser General Public License, version 2.1 as published by
5 * the Free Software Foundation. This program is distributed in the hope
6 * that it will be useful, but WITHOUT ANY WARRANTY; without even the
7 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8 * See the GNU Lesser General Public License for more details.
9 *
10 * The License is available on the internet at:
11 * http://www.gnu.org/copyleft/lgpl.html
12 * or by writing to:
13 * Free Software Foundation, Inc.
14 * 59 Temple Place - Suite 330
15 * Boston, MA 02111-1307, USA
16 *
17 * Copyright: 2005
18 * The copyright to this program is held by it's authors.
19 *
20 * ID: $Id: AbstractLayout.java 2050 2010-12-09 15:31:45Z dmsmith $
21 */
22 package org.crosswire.common.swing;
23
24 import java.awt.Component;
25 import java.awt.Container;
26 import java.awt.Dimension;
27 import java.awt.LayoutManager2;
28 import java.io.Serializable;
29
30 /**
31 * AbstractLayout - support for DeckLayout.
32 *
33 * @see gnu.lgpl.License for license details.<br>
34 * The copyright to this program is held by it's authors.
35 * @author Joe Walker [joe at eireneh dot com]
36 * @author Claude Duguay (Idea in JDJ article)
37 */
38 public abstract class AbstractLayout implements LayoutManager2, Serializable {
39 /**
40 * Defaults the horizontal and vertical gaps to 0
41 */
42 protected AbstractLayout() {
43 this(0, 0);
44 }
45
46 /**
47 * Constructor that specifies the horizontal and vertical gaps
48 */
49 protected AbstractLayout(int hgap, int vgap) {
50 setHgap(hgap);
51 setVgap(vgap);
52 }
53
54 /**
55 * Get the horizontal gap between components.
56 */
57 public final int getHgap() {
58 return hgap;
59 }
60
61 /**
62 * Get the vertical gap between components.
63 */
64 public final int getVgap() {
65 return vgap;
66 }
67
68 /**
69 * Set the horizontal gap between components.
70 *
71 * @param gap
72 * The horizontal gap to be set
73 */
74 public final void setHgap(int gap) {
75 hgap = gap;
76 }
77
78 /**
79 * Set the vertical gap between components.
80 *
81 * @param gap
82 * The vertical gap to be set
83 */
84 public final void setVgap(int gap) {
85 vgap = gap;
86 }
87
88 /**
89 * Returns the maximum dimensions for this layout given the component in the
90 * specified target container.
91 *
92 * @param target
93 * The component which needs to be laid out
94 */
95 public Dimension maximumLayoutSize(Container target) {
96 return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
97 }
98
99 /**
100 * Returns the alignment along the x axis. This specifies how the component
101 * would like to be aligned relative to other components. The value should
102 * be a number between 0 and 1 where 0 represents alignment along the
103 * origin, 1 is aligned the furthest away from the origin, 0.5 is centered,
104 * etc.
105 */
106 public float getLayoutAlignmentX(Container parent) {
107 return 0.5f;
108 }
109
110 /**
111 * Returns the alignment along the y axis. This specifies how the component
112 * would like to be aligned relative to other components. The value should
113 * be a number between 0 and 1 where 0 represents alignment along the
114 * origin, 1 is aligned the furthest away from the origin, 0.5 is centered,
115 * etc.
116 */
117 public float getLayoutAlignmentY(Container parent) {
118 return 0.5f;
119 }
120
121 /**
122 * Invalidates the layout, indicating that if the layout manager has cached
123 * information it should be discarded.
124 */
125 public void invalidateLayout(Container target) {
126 }
127
128 /**
129 * Adds the specified component with the specified name to the layout. By
130 * default, we call the more recent addLayoutComponent method with an object
131 * constraint argument. The name is passed through directly.
132 *
133 * @param name
134 * The name of the component
135 * @param comp
136 * The component to be added
137 */
138 public void addLayoutComponent(String name, Component comp) {
139 addLayoutComponent(comp, name);
140 }
141
142 /**
143 * Add the specified component from the layout. By default, we let the
144 * Container handle this directly.
145 *
146 * @param comp
147 * The component to be added
148 * @param constraints
149 * The constraints to apply when laying out.
150 */
151 public void addLayoutComponent(Component comp, Object constraints) {
152 }
153
154 /**
155 * Removes the specified component from the layout. By default, we let the
156 * Container handle this directly.
157 *
158 * @param comp
159 * the component to be removed
160 */
161 public void removeLayoutComponent(Component comp) {
162 }
163
164 /**
165 * Return a string representation of the layout manager
166 */
167 @Override
168 public String toString() {
169 return getClass().getName() + "[hgap=" + hgap + ",vgap=" + vgap + ']';
170 }
171
172 /**
173 * horizontal gap
174 */
175 protected int hgap;
176
177 /**
178 * vertical gap
179 */
180 protected int vgap;
181
182 /**
183 * Serialization ID
184 */
185 private static final long serialVersionUID = -1275138133354908272L;
186 }
187