summaryrefslogtreecommitdiff
path: root/prototypes/miglayout/net/miginfocom/layout/ComponentWrapper.java
blob: af96ca6be76319f61fb625c7e82dec809cd137b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
package net.miginfocom.layout;
/*
 * License (BSD):
 * ==============
 *
 * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 * Redistributions of source code must retain the above copyright notice, this list
 * of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this
 * list of conditions and the following disclaimer in the documentation and/or other
 * materials provided with the distribution.
 * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
 * used to endorse or promote products derived from this software without specific
 * prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 * OF SUCH DAMAGE.
 *
 * @version 1.0
 * @author Mikael Grev, MiG InfoCom AB
 *         Date: 2006-sep-08
 */

/** A class that wraps the important parts of a Component.
 * <p>
 * <b>NOTE!</b>.equals() and .hashcode() should be shunted to the wrapped component. E.g.
 * <pre>
 * 	public int hashCode()
	{
		return getComponent().hashCode();
	}

	public final boolean equals(Object o)
	{
		 if (o == null || o instanceof ComponentWrapper == false)
			 return false;

		 return getComponent().equals(((ComponentWrapper) o).getComponent());
	}
 * </pre>
 */
public interface ComponentWrapper
{
	static final int TYPE_UNSET = -1;
	public static final int TYPE_UNKNOWN = 0;
	public static final int TYPE_CONTAINER = 1;
	public static final int TYPE_LABEL = 2;
	public static final int TYPE_TEXT_FIELD = 3;
	public static final int TYPE_TEXT_AREA = 4;
	public static final int TYPE_BUTTON = 5;
	public static final int TYPE_LIST = 6;
	public static final int TYPE_TABLE = 7;
	public static final int TYPE_SCROLL_PANE = 8;
	public static final int TYPE_IMAGE = 9;
	public static final int TYPE_PANEL = 10;
	public static final int TYPE_COMBO_BOX = 11;
	public static final int TYPE_SLIDER = 12;
	public static final int TYPE_SPINNER = 13;
	public static final int TYPE_PROGRESS_BAR = 14;
	public static final int TYPE_TREE = 15;
	public static final int TYPE_CHECK_BOX = 16;
	public static final int TYPE_SCROLL_BAR = 17;
	public static final int TYPE_SEPARATOR = 18;

	/** Returns the actual object that this wrapper is aggregating. This might be needed for getting
	 * information about the object that the wrapper interface does not provide.
	 * <p>
	 * If this is a container the container should be returned instead.
	 * @return The actual object that this wrapper is aggregating. Not <code>null</code>.
	 */
	public abstract Object getComponent();

	/** Returns the current x coordinate for this component.
	 * @return The current x coordinate for this component.
	 */
	public abstract int getX();

	/** Returns the current y coordinate for this component.
	 * @return The current y coordinate for this component.
	 */
	public abstract int getY();

	/** Returns the current width for this component.
	 * @return The current width for this component.
	 */
	public abstract int getWidth();

	/** Returns the current height for this component.
	 * @return The current height for this component.
	 */
	public abstract int getHeight();

	/** Returns the screen x-coordinate for the upper left coordinate of the component layoutable bounds.
	 * @return The screen x-coordinate for the upper left coordinate of the component layoutable bounds.
	 */
	public abstract int getScreenLocationX();

	/** Returns the screen y-coordinate for the upper left coordinate of the component layoutable bounds.
	 * @return The screen y-coordinate for the upper left coordinate of the component layoutable bounds.
	 */
	public abstract int getScreenLocationY();

	/** Returns the minimum width of the component.
	 * @return The minimum width of the component.
	 */
	public abstract int getMinimumWidth();

	/** Returns the minimum height of the component.
	 * @return The minimum height of the component.
	 */
	public abstract int getMinimumHeight();

	/** Returns the preferred width of the component.
	 * @return The preferred width of the component.
	 */
	public abstract int getPreferredWidth();

	/** Returns the preferred height of the component.
	 * @return The preferred height of the component.
	 */
	public abstract int getPreferredHeight();

	/** Returns the maximum width of the component.
	 * @return The maximum width of the component.
	 */
	public abstract int getMaximumWidth();

	/** Returns the maximum height of the component.
	 * @return The maximum height of the component.
	 */
	public abstract int getMaximumHeight();

	/** Sets the component's bounds.
	 * @param x The x coordinate.
	 * @param y The y coordinate.
	 * @param width The width.
	 * @param height The height.
	 */
	public abstract void setBounds(int x, int y, int width, int height);

	/** Returns if the component's visibility is set to <code>true</code>. This should not return if the component is
	 * actually visibile, but if the visibility is set to true or not.
	 * @return <code>true</code> means visible.
	 */
	public abstract boolean isVisible();

	/** Returns the baseline for the component given the suggested height.
	 * @param width The width to calculate for if other than the current. If <code>-1</code> the current size should be used.
	 * @param height The height to calculate for if other than the current. If <code>-1</code> the current size should be used.
	 * @return The baseline from the top or -1 if not applicable.
	 */
	public abstract int getBaseline(int width, int height);

	/** Returns if the component has a baseline and if it can be retrieved. Should for instance return
	 * <code>false</code> for Swing before mustang.
	 * @return If the component has a baseline and if it can be retrieved.
	 */
	public abstract boolean hasBaseline();

	/** Returns the container for this component.
	 * @return The container for this component. Should never be <code>null</code>.
	 */
	public abstract ContainerWrapper getParent();

	/** Returns the pixel unit factor for the horizontal or vertical dimension.
	 * <p>
	 * The factor is 1 for both dimensions on the normal font in a JPanel on Windows. The factor should increase with a bigger "X".
	 * <p>
	 * This is the Swing version:
	 * <pre>
	 * Rectangle2D r = fm.getStringBounds("X", parent.getGraphics());
	 * wFactor = r.getWidth() / 6;
	 * hFactor = r.getHeight() / 13.27734375f;
	 * </pre>
	 * @param isHor If it is the horizontal factor that should be returned.
	 * @return The factor.
	 */
	public abstract float getPixelUnitFactor(boolean isHor);

	/** Returns the DPI (Dots Per Inch) of the screen the component is currently in or for the default
	 * screen if the component is not visible.
	 * @return The DPI.
	 */
	public abstract int getHorizontalScreenDPI();

	/** Returns the DPI (Dots Per Inch) of the screen the component is currently in or for the default
	 * screen if the component is not visible.
	 * @return The DPI.
	 */
	public abstract int getVerticalScreenDPI();

	/** Returns the pixel size of the screen that the component is currently in or for the default
	 * screen if the component is not visible or <code>null</code>.
	 * @return The screen size. E.g. <code>1280</code>.
	 */
	public abstract int getScreenWidth();

	/** Returns the pixel size of the screen that the component is currently in or for the default
	 * screen if the component is not visible or <code>null</code>.
	 * @return The screen size. E.g. <code>1024</code>.
	 */
	public abstract int getScreenHeight();

	/** Returns a String id that can be used to reference the component in link constraints. This value should
	 * return the default id for the component. The id can be set for a component in the constraints and if
	 * so the value returned by this method will never be used. If there are no sensible id for the component
	 * <code>null</code> should be returned.
	 * <p>
	 * For instance the Swing implementation returns the string returned from <code>Component.getName()</code>.
	 * @return The string link id or <code>null</code>.
	 */
	public abstract String getLinkId();

	/** Returns a hash code that should be resonably different for anything that might change the layout. This value is used to
	 *  know if the component layout needs to clear any caches.
	 * @return A hash code that should be resonably different for anything that might change the layout. Returns -1 if the widget is
	 * disposed.
	 */
	public abstract int getLayoutHashCode();

	/** Returns the padding on a component by component basis. This method can be overridden to return padding to compensate for example for
	 * borders that have shadows or where the outer most pixel is not the visual "edge" to align to.
	 * <p>
	 * Default implementation returnes <code>null</code> for all components except for Windows XP's JTabbedPane which will return new Insets(0, 0, 2, 2).
	 * <p>
	 * <b>NOTE!</B> To reduce cenerated garbage the returned padding should never be changed so that the same insets can be returned many times.
	 * @return <code>null</code> if no padding. <b>NOTE!</B> To reduce cenerated garbage the returned padding should never be changed so that
	 * the same insets can be returned many times. [top, left, bottom, right]
	 */
	public int[] getVisualPadding();

	/** Paints component outline to indicate where it is.
	 */
	public abstract void paintDebugOutline();

	/** Returns the type of component that this wrapper is wrapping.
	 * <p>
	 * This method can be invoked often so the result should be cached.
	 * @param disregardScrollPane Is <code>true</code> any wrapping scroll pane should be disregarded and the type
	 * of the scrolled component should be returned.
	 * @return The type of component that this wrapper is wrapping. E.g. {@link #TYPE_LABEL}.
	 */
	public abstract int getComponetType(boolean disregardScrollPane);

			;
}