Sfoglia il codice sorgente

Extract and update mig 3.6.3

tags/0.6.3m1rc1
Chris Smith 15 anni fa
parent
commit
ec2a08ac21

BIN
lib/miglayout-3.6.3.jar Vedi File


+ 2
- 1
nbproject/project.properties Vedi File

@@ -3,6 +3,7 @@ file.reference.fest-reflect-0.4.jar=lib/fest-reflect-0.4.jar
3 3
 file.reference.fest-swing-1.0b1.jar=lib/fest-swing-1.0b1.jar
4 4
 file.reference.fest-swing-junit-1.0b1.jar=lib/fest-swing-junit-1.0b1.jar
5 5
 file.reference.fest-util-0.4.jar=lib/fest-util-0.4.jar
6
+file.reference.miglayout.jar=lib/miglayout-3.6.3.jar
6 7
 file.reference.junit-4.jar=lib/junit-4.1.jar
7 8
 file.reference.junit-3.jar=lib/junit-3.8.1.jar
8 9
 
@@ -31,7 +32,7 @@ dist.jar.excludes=com/dmdirc/addons/**
31 32
 excludes=
32 33
 includes=**
33 34
 jar.compress=false
34
-javac.classpath=
35
+javac.classpath=${file.reference.miglayout.jar}
35 36
 # Space-separated list of extra javac options
36 37
 javac.compilerargs=-Xlint:all
37 38
 javac.deprecation=true

+ 0
- 63
src/net/miginfocom/examples/BugTestApp.java Vedi File

@@ -1,63 +0,0 @@
1
-package net.miginfocom.examples;
2
-
3
-import net.miginfocom.swing.MigLayout;
4
-
5
-import javax.swing.*;
6
-
7
-/**
8
- * @author Mikael Grev, MiG InfoCom AB
9
- *         Date: Dec 15, 2008
10
- *         Time: 7:04:50 PM
11
- */
12
-public class BugTestApp
13
-{
14
-	private static JPanel createPanel()
15
-	{
16
-		JPanel panel = new JPanel(new MigLayout("debug, wrap 2", "", "[]10[]20[]30[]"));
17
-
18
-		panel.add(new JButton("1"));
19
-		panel.add(new JButton("2"), "skip 3");
20
-		panel.add(new JButton("3"));
21
-		panel.add(new JButton("4"), "skip 0");
22
-//		panel.add("newline, span", new JButton());
23
-
24
-//		panel.add("newline 100", new JButton("Should have 40 pixels before"));
25
-//
26
-//		panel.add("newline", new JButton());
27
-//		panel.add("newline", new JButton());
28
-//		panel.add("newline", new JButton());
29
-
30
-		return panel;
31
-	}
32
-
33
-	private static JPanel createPanel2()
34
-	{
35
-		JPanel panel = new JPanel(new MigLayout("wrap 2"));
36
-
37
-		panel.add(new JTable(), "spany 2, w 100, h 100");
38
-		panel.add(new JButton("Button 1"));
39
-		panel.add(new JButton("Button 2"), "skip, span");
40
-
41
-		return panel;
42
-	}
43
-
44
-	public static void main(String[] args)
45
-	{
46
-		SwingUtilities.invokeLater(new Runnable() {
47
-			public void run() {
48
-				try {
49
-					UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
50
-				} catch (Exception ex) {
51
-					ex.printStackTrace();
52
-				}
53
-
54
-				JFrame frame = new JFrame("Bug Test App");
55
-				frame.getContentPane().add(createPanel2());
56
-				frame.pack();
57
-				frame.setLocationRelativeTo(null);
58
-				frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
59
-				frame.setVisible(true);
60
-			}
61
-		});
62
-	}
63
-}

+ 0
- 501
src/net/miginfocom/layout/AC.java Vedi File

@@ -1,501 +0,0 @@
1
-package net.miginfocom.layout;
2
-
3
-import java.io.*;
4
-import java.util.ArrayList;
5
-
6
-/*
7
- * License (BSD):
8
- * ==============
9
- *
10
- * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
11
- * All rights reserved.
12
- *
13
- * Redistribution and use in source and binary forms, with or without modification,
14
- * are permitted provided that the following conditions are met:
15
- * Redistributions of source code must retain the above copyright notice, this list
16
- * of conditions and the following disclaimer.
17
- * Redistributions in binary form must reproduce the above copyright notice, this
18
- * list of conditions and the following disclaimer in the documentation and/or other
19
- * materials provided with the distribution.
20
- * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
21
- * used to endorse or promote products derived from this software without specific
22
- * prior written permission.
23
- *
24
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27
- * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
30
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
33
- * OF SUCH DAMAGE.
34
- *
35
- * @version 1.0
36
- * @author Mikael Grev, MiG InfoCom AB
37
- *         Date: 2006-sep-08
38
- */
39
-
40
-/** A constraint that holds the column <b>or</b> row constraints for the grid. It also holds the gaps between the rows and columns.
41
- * <p>
42
- * This class is a holder and builder for a number of {@link net.miginfocom.layout.DimConstraint}s.
43
- * <p>
44
- * For a more thorough explanation of what these constraints do, and how to build the constriants, see the White Paper or Cheat Sheet at www.migcomponents.com.
45
- * <p>
46
- * Note that there are two way to build this constraint. Through String (e.g. <code>"[100]3[200,fill]"</code> or through API (E.g.
47
- * <code>new AxisConstraint().size("100").gap("3").size("200").fill()</code>.
48
- */
49
-public final class AC implements Externalizable
50
-{
51
-
52
-	/**
53
-	 * A version number for this class. It should be changed whenever the
54
-	 * class structure is changed (or anything else that would prevent
55
-	 * serialized objects being unserialized with the new class).
56
-	 */
57
-	private static final long serialVersionUID = 1;
58
-
59
-	private final ArrayList<DimConstraint> cList = new ArrayList<DimConstraint>(8);
60
-
61
-	private transient int curIx = 0;
62
-
63
-	/** Constructor. Creates an instance that can be configured manually. Will be initialized with a default
64
-	 * {@link net.miginfocom.layout.DimConstraint}.
65
-	 */
66
-	public AC()
67
-	{
68
-		cList.add(new DimConstraint());
69
-	}
70
-
71
-	/** Property. The different {@link net.miginfocom.layout.DimConstraint}s that this object consists of.
72
-	 * These <code><DimConstraints/code> contains all information in this class.
73
-	 * @return The different {@link net.miginfocom.layout.DimConstraint}s that this object consists of. A new list and
74
-	 * never <code>null</code>.
75
-	 */
76
-	public final DimConstraint[] getConstaints()
77
-	{
78
-		return cList.toArray(new DimConstraint[cList.size()]);
79
-	}
80
-
81
-	/** Sets the different {@link net.miginfocom.layout.DimConstraint}s that this object should consists of.
82
-	 * @param constr The different {@link net.miginfocom.layout.DimConstraint}s that this object consists of. The list
83
-	 * will be copied for storage. <code>null</code> or and emty array will reset the constaints to one <code>DimConstraint</code>
84
-	 * with default values.
85
-	 */
86
-	public final void setConstaints(DimConstraint[] constr)
87
-	{
88
-		if (constr == null || constr.length < 1 )
89
-			constr = new DimConstraint[] {new DimConstraint()};
90
-
91
-		cList.clear();
92
-		cList.ensureCapacity(constr.length);
93
-		for (int i = 0; i < constr.length; i++)
94
-			cList.add(constr[i]);
95
-	}
96
-
97
-	/** Returns the number of rows/columns that this constraints currently have.
98
-	 * @return The number of rows/columns that this constraints currently have. At least 1.
99
-	 */
100
-	public int getCount()
101
-	{
102
-		return cList.size();
103
-	}
104
-
105
-	/** Sets the total number of rows/columns to <code>size</code>. If the number of rows/columns is already more
106
-	 * than <code>size</code> nothing will happen.
107
-	 * @param size The total number of rows/columns
108
-	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
109
-	 */
110
-	public final AC count(int size)
111
-	{
112
-		makeSize(size);
113
-		return this;
114
-	}
115
-
116
-	/** Specifies that the current row/column should not be grid-like. The while row/colum will have its components layed out
117
-	 * in one single cell. It is the same as to say that the cells in this column/row will all be merged (a.k.a spanned).
118
-	 * <p>
119
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
120
-	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
121
-	 */
122
-	public final AC noGrid()
123
-	{
124
-		return noGrid(curIx);
125
-	}
126
-
127
-	/** Specifies that the indicated rows/columns should not be grid-like. The while row/colum will have its components layed out
128
-	 * in one single cell. It is the same as to say that the cells in this column/row will all be merged (a.k.a spanned).
129
-	 * <p>
130
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
131
-	 * @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint.
132
-	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
133
-	 */
134
-	public final AC noGrid(int... indexes)
135
-	{
136
-		for (int i = indexes.length - 1; i >= 0; i--) {
137
-			int ix = indexes[i];
138
-			makeSize(ix);
139
-			cList.get(ix).setNoGrid(true);
140
-		}
141
-		return this;
142
-	}
143
-
144
-	/** Sets the current row/column to <code>i</code>. If the current number of rows/columns is less than <code>i</code> a call
145
-	 * to {@link #count(int)} will set the size accoringly.
146
-	 * <p>
147
-	 * The next call to any of the constriant methods (e.g. {@link net.miginfocom.layout.AC#noGrid}) will be carried
148
-	 * out on this new row/column.
149
-	 * <p>
150
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
151
-	 * @param i The new current row/column.
152
-	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
153
-	 */
154
-	public final AC index(int i)
155
-	{
156
-		makeSize(i);
157
-		curIx = i;
158
-		return this;
159
-	}
160
-
161
-	/** Specifies that the current row/column's component should grow by default. It does not affect the size of the row/column.
162
-	 * <p>
163
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
164
-	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
165
-	 */
166
-	public final AC fill()
167
-	{
168
-		return fill(curIx);
169
-	}
170
-
171
-	/** Specifies that the indicated rows'/columns' component should grow by default. It does not affect the size of the row/column.
172
-	 * <p>
173
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
174
-	 * @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint.
175
-	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
176
-	 */
177
-	public final AC fill(int... indexes)
178
-	{
179
-		for (int i = indexes.length - 1; i >= 0; i--) {
180
-			int ix = indexes[i];
181
-			makeSize(ix);
182
-			cList.get(ix).setFill(true);
183
-		}
184
-		return this;
185
-	}
186
-
187
-//	/** Specifies that the current row/column should be put in the end group <code>s</code> and will thus share the same ending
188
-//	 * coordinate within the group.
189
-//	 * <p>
190
-//	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
191
-//	 * @param s A name to associate on the group that should be the same for other rows/columns in the same group.
192
-//	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
193
-//	 */
194
-//	public final AxisConstraint endGroup(String s)
195
-//	{
196
-//		return endGroup(s, curIx);
197
-//	}
198
-//
199
-//	/** Specifies that the indicated rows/columns should be put in the end group <code>s</code> and will thus share the same ending
200
-//	 * coordinate within the group.
201
-//	 * <p>
202
-//	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
203
-//	 * @param s A name to associate on the group that should be the same for other rows/columns in the same group.
204
-//	 * @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint.
205
-//	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
206
-//	 */
207
-//	public final AxisConstraint endGroup(String s, int... indexes)
208
-//	{
209
-//		for (int i = indexes.length - 1; i >= 0; i--) {
210
-//			int ix = indexes[i];
211
-//			makeSize(ix);
212
-//			cList.get(ix).setEndGroup(s);
213
-//		}
214
-//		return this;
215
-//	}
216
-
217
-	/** Specifies that the current row/column should be put in the size group <code>s</code> and will thus share the same size
218
-	 * constraints as the other components in the group.
219
-	 * <p>
220
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
221
-	 * @param s A name to associate on the group that should be the same for other rows/columns in the same group.
222
-	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
223
-	 */
224
-	public final AC sizeGroup(String s)
225
-	{
226
-		return sizeGroup(s, curIx);
227
-	}
228
-
229
-	/** Specifies that the indicated rows/columns should be put in the size group <code>s</code> and will thus share the same size
230
-	 * constraints as the other components in the group.
231
-	 * <p>
232
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
233
-	 * @param s A name to associate on the group that should be the same for other rows/columns in the same group.
234
-	 * @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint.
235
-	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
236
-	 */
237
-	public final AC sizeGroup(String s, int... indexes)
238
-	{
239
-		for (int i = indexes.length - 1; i >= 0; i--) {
240
-			int ix = indexes[i];
241
-			makeSize(ix);
242
-			cList.get(ix).setSizeGroup(s);
243
-		}
244
-		return this;
245
-	}
246
-
247
-	/** Specifies the current row/column's min and/or preferred and/or max size. E.g. <code>"10px"</code> or <code>"50:100:200"</code>.
248
-	 * <p>
249
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
250
-	 * @param s The minimum and/or preferred and/or maximum size of this row. The string will be interpreted
251
-	 * as a <b>BoundSize</b>. For more info on how <b>BoundSize</b> is formatted see the documentation.
252
-	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
253
-	 */
254
-	public final AC size(String s)
255
-	{
256
-		return size(s, curIx);
257
-	}
258
-
259
-	/** Specifies the indicated rows'/columns' min and/or preferred and/or max size. E.g. <code>"10px"</code> or <code>"50:100:200"</code>.
260
-	 * <p>
261
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
262
-	 * @param size The minimum and/or preferred and/or maximum size of this row. The string will be interpreted
263
-	 * as a <b>BoundSize</b>. For more info on how <b>BoundSize</b> is formatted see the documentation.
264
-	 * @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint.
265
-	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
266
-	 */
267
-	public final AC size(String size, int... indexes)
268
-	{
269
-		BoundSize bs = ConstraintParser.parseBoundSize(size, false, true);
270
-		for (int i = indexes.length - 1; i >= 0; i--) {
271
-			int ix = indexes[i];
272
-			makeSize(ix);
273
-			cList.get(ix).setSize(bs);
274
-		}
275
-		return this;
276
-	}
277
-
278
-	/** Specifies the gap size to be the default one <b>AND</b> moves to the next column/row. The method is called <code>.gap()</code>
279
-	 * rather the more natural <code>.next()</code> to indicate that it is very much related to the other <code>.gap(..)</code> methods.
280
-	 * <p>
281
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
282
-	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
283
-	 */
284
-	public final AC gap()
285
-	{
286
-		curIx++;
287
-		return this;
288
-	}
289
-
290
-	/** Specifies the gap size to <code>size</code> <b>AND</b> moves to the next column/row.
291
-	 * <p>
292
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
293
-	 * @param size minimum and/or preferred and/or maximum size of the gap between this and the next row/column.
294
-	 * The string will be interpreted as a <b>BoundSize</b>. For more info on how <b>BoundSize</b> is formatted see the documentation.
295
-	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
296
-	 */
297
-	public final AC gap(String size)
298
-	{
299
-		return gap(size, curIx++);
300
-	}
301
-
302
-	/** Specifies the indicated rows'/columns' gap size to <code>size</code>.
303
-	 * <p>
304
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
305
-	 * @param size minimum and/or preferred and/or maximum size of the gap between this and the next row/column.
306
-	 * The string will be interpreted as a <b>BoundSize</b>. For more info on how <b>BoundSize</b> is formatted see the documentation.
307
-	 * @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint.
308
-	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
309
-	 */
310
-	public final AC gap(String size, int... indexes)
311
-	{
312
-		BoundSize bsa = size != null ? ConstraintParser.parseBoundSize(size, true, true) : null;
313
-
314
-		for (int i = indexes.length - 1; i >= 0; i--) {
315
-			int ix = indexes[i];
316
-			makeSize(ix);
317
-			if (bsa != null)
318
-				cList.get(ix).setGapAfter(bsa);
319
-		}
320
-		return this;
321
-	}
322
-
323
-	/** Specifies the current row/column's columns default alignment <b>for its components</b>. It does not affect the positioning
324
-	 * or size of the columns/row itself. For columns it is the horizonal alignment (e.g. "left") and for rows it is the vertical
325
-	 * alignment (e.g. "top").
326
-	 * <p>
327
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
328
-	 * @param side The default side to align the components. E.g. "top" or "left", or "leading" or "trailing" or "bottom" or "right".
329
-	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
330
-	 */
331
-	public final AC align(String side)
332
-	{
333
-		return align(side, curIx);
334
-	}
335
-
336
-	/** Specifies the indicated rows'/columns' columns default alignment <b>for its components</b>. It does not affect the positioning
337
-	 * or size of the columns/row itself. For columns it is the horizonal alignment (e.g. "left") and for rows it is the vertical
338
-	 * alignment (e.g. "top").
339
-	 * <p>
340
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
341
-	 * @param side The default side to align the components. E.g. "top" or "left", or "before" or "after" or "bottom" or "right".
342
-	 * @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint.
343
-	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
344
-	 */
345
-	public final AC align(String side, int... indexes)
346
-	{
347
-		UnitValue al = ConstraintParser.parseAlignKeywords(side, true);
348
-		if (al == null)
349
-			al = ConstraintParser.parseAlignKeywords(side, false);
350
-
351
-		for (int i = indexes.length - 1; i >= 0; i--) {
352
-			int ix = indexes[i];
353
-			makeSize(ix);
354
-			cList.get(ix).setAlign(al);
355
-		}
356
-		return this;
357
-	}
358
-
359
-	/** Specifies the current row/column's grow priority.
360
-	 * <p>
361
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
362
-	 * @param p The new grow priority.
363
-	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
364
-	 */
365
-	public final AC growPrio(int p)
366
-	{
367
-		return growPrio(p, curIx);
368
-	}
369
-
370
-	/** Specifies the indicated rows'/columns' grow priority.
371
-	 * <p>
372
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
373
-	 * @param p The new grow priority.
374
-	 * @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint.
375
-	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
376
-	 */
377
-	public final AC growPrio(int p, int... indexes)
378
-	{
379
-		for (int i = indexes.length - 1; i >= 0; i--) {
380
-			int ix = indexes[i];
381
-			makeSize(ix);
382
-			cList.get(ix).setGrowPriority(p);
383
-		}
384
-		return this;
385
-	}
386
-
387
-	/** Specifies the current row/column's grow weight within columns/rows with the same <code>grow priority</code>.
388
-	 * <p>
389
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
390
-	 * @param w The new grow weight.
391
-	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
392
-	 */
393
-	public final AC grow(float w)
394
-	{
395
-		return grow(w, curIx);
396
-	}
397
-
398
-	/** Specifies the indicated rows'/columns' grow weight within columns/rows with the same <code>grow priority</code>.
399
-	 * <p>
400
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
401
-	 * @param w The new grow weight.
402
-	 * @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint.
403
-	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
404
-	 */
405
-	public final AC grow(float w, int... indexes)
406
-	{
407
-		Float gw = new Float(w);
408
-		for (int i = indexes.length - 1; i >= 0; i--) {
409
-			int ix = indexes[i];
410
-			makeSize(ix);
411
-			cList.get(ix).setGrow(gw);
412
-		}
413
-		return this;
414
-	}
415
-
416
-	/** Specifies the current row/column's shrink priority.
417
-	 * <p>
418
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
419
-	 * @param p The new shrink priority.
420
-	 	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
421
-	 */
422
-	public final AC shrinkPrio(int p)
423
-	{
424
-		return shrinkPrio(p, curIx);
425
-	}
426
-
427
-	/** Specifies the indicated rows'/columns' shrink priority.
428
-	 * <p>
429
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
430
-	 * @param p The new shrink priority.
431
-	 * @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint.
432
-	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
433
-	 */
434
-	public final AC shrinkPrio(int p, int... indexes)
435
-	{
436
-		for (int i = indexes.length - 1; i >= 0; i--) {
437
-			int ix = indexes[i];
438
-			makeSize(ix);
439
-			cList.get(ix).setShrinkPriority(p);
440
-		}
441
-		return this;
442
-	}
443
-
444
-	/** Specifies that the current row/column's shrink weight withing the columns/rows with the same <code>shrink priority</code>.
445
-	 * <p>
446
-	 * For a more thorough explanation of what this constraint does see the White Paper or Cheat Sheet at www.migcomponents.com.
447
-	 * @param w The shrink weight.
448
-	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
449
-	 */
450
-	public final AC shrinkWeight(float w)
451
-	{
452
-		return shrinkWeight(w, curIx);
453
-	}
454
-
455
-	/** Specifies the indicated rows'/columns' shrink weight withing the columns/rows with the same <code>shrink priority</code>.
456
-	 * <p>
457
-	 * For a more thorough explanation of what this constraint does see the White Paper or Cheat Sheet at www.migcomponents.com.
458
-	 * @param w The shrink weight.
459
-	 * @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint.
460
-	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
461
-	 */
462
-	public final AC shrinkWeight(float w, int... indexes)
463
-	{
464
-		Float sw = new Float(w);
465
-		for (int i = indexes.length - 1; i >= 0; i--) {
466
-			int ix = indexes[i];
467
-			makeSize(ix);
468
-			cList.get(ix).setShrink(sw);
469
-		}
470
-		return this;
471
-	}
472
-
473
-	private void makeSize(int sz)
474
-	{
475
-		if (cList.size() <= sz) {
476
-			cList.ensureCapacity(sz);
477
-			for (int i = cList.size(); i <= sz; i++)
478
-				cList.add(new DimConstraint());
479
-		}
480
-	}
481
-
482
-	// ************************************************
483
-	// Persistence Delegate and Serializable combined.
484
-	// ************************************************
485
-
486
-	private Object readResolve() throws ObjectStreamException
487
-	{
488
-		return LayoutUtil.getSerializedObject(this);
489
-	}
490
-
491
-	public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
492
-	{
493
-		LayoutUtil.setSerializedObject(this, LayoutUtil.readAsXML(in));
494
-	}
495
-
496
-	public void writeExternal(ObjectOutput out) throws IOException
497
-	{
498
-		if (getClass() == AC.class)
499
-			LayoutUtil.writeAsXML(out, this);
500
-	}
501
-}

+ 0
- 271
src/net/miginfocom/layout/BoundSize.java Vedi File

@@ -1,271 +0,0 @@
1
-package net.miginfocom.layout;
2
-
3
-import java.beans.Encoder;
4
-import java.beans.Expression;
5
-import java.beans.PersistenceDelegate;
6
-import java.io.*;
7
-/*
8
- * License (BSD):
9
- * ==============
10
- *
11
- * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
12
- * All rights reserved.
13
- *
14
- * Redistribution and use in source and binary forms, with or without modification,
15
- * are permitted provided that the following conditions are met:
16
- * Redistributions of source code must retain the above copyright notice, this list
17
- * of conditions and the following disclaimer.
18
- * Redistributions in binary form must reproduce the above copyright notice, this
19
- * list of conditions and the following disclaimer in the documentation and/or other
20
- * materials provided with the distribution.
21
- * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
22
- * used to endorse or promote products derived from this software without specific
23
- * prior written permission.
24
- *
25
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
26
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28
- * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
31
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
34
- * OF SUCH DAMAGE.
35
- *
36
- * @version 1.0
37
- * @author Mikael Grev, MiG InfoCom AB
38
- *         Date: 2006-sep-08
39
- */
40
-
41
-/** A size that contains minimum, preferred and maximum size of type {@link UnitValue}.
42
- * <p>
43
- * This class is a simple value container and it is immutable.
44
- * <p>
45
- * If a size is missing (i.e., <code>null</code>) that boundary should be considered "not in use".
46
- * <p>
47
- * You can create a BoundSize from a String with the use of {@link ConstraintParser#parseBoundSize(String, boolean, boolean)}
48
- */
49
-public class BoundSize implements Serializable
50
-{
51
-	public static final BoundSize NULL_SIZE = new BoundSize(null, null);
52
-	public static final BoundSize ZERO_PIXEL = new BoundSize(UnitValue.ZERO, "0px");
53
-
54
-	private final transient UnitValue min;
55
-	private final transient UnitValue pref;
56
-	private final transient UnitValue max;
57
-	private final transient boolean gapPush;
58
-
59
-	/** Constructor that use the same value for min/preferred/max size.
60
-	 * @param minMaxPref The value to use for min/preferred/max size.
61
-	 * @param createString The string used to create the BoundsSize.
62
-	 */
63
-	public BoundSize(UnitValue minMaxPref, String createString)
64
-	{
65
-		this(minMaxPref, minMaxPref, minMaxPref, createString);
66
-	}
67
-
68
-	/** Constructor. <b>This method is here for serilization only and should normally not be used. Use
69
-	 * {@link ConstraintParser#parseBoundSize(String, boolean, boolean)} instead.
70
-	 * @param min The minimum size. May be <code>null</code>.
71
-	 * @param preferred  The preferred size. May be <code>null</code>.
72
-	 * @param max  The maximum size. May be <code>null</code>.
73
-	 * @param createString The string used to create the BoundsSize.
74
-	 */
75
-	public BoundSize(UnitValue min, UnitValue preferred, UnitValue max, String createString)    // Bound to old delegate!!!!!
76
-	{
77
-		this(min, preferred, max, false, createString);
78
-	}
79
-
80
-	/** Constructor. <b>This method is here for serilization only and should normally not be used. Use
81
-	 * {@link ConstraintParser#parseBoundSize(String, boolean, boolean)} instead.
82
-	 * @param min The minimum size. May be <code>null</code>.
83
-	 * @param preferred  The preferred size. May be <code>null</code>.
84
-	 * @param max  The maximum size. May be <code>null</code>.
85
-	 * @param gapPush If the size should be hinted as "pushing" and thus want to occupy free space if no one else is claiming it.
86
-	 * @param createString The string used to create the BoundsSize.
87
-	 */
88
-	public BoundSize(UnitValue min, UnitValue preferred, UnitValue max, boolean gapPush, String createString)
89
-	{
90
-		this.min = min;
91
-		this.pref = preferred;
92
-		this.max = max;
93
-		this.gapPush = gapPush;
94
-
95
-		LayoutUtil.putCCString(this, createString);    // this escapes!!
96
-	}
97
-
98
-	/** Returns the minimum size as sent into the constructor.
99
-	 * @return The minimum size as sent into the constructor. May be <code>null</code>.
100
-	 */
101
-	public final UnitValue getMin()
102
-	{
103
-		return min;
104
-	}
105
-
106
-	/** Returns the preferred size as sent into the constructor.
107
-	 * @return The preferred size as sent into the constructor. May be <code>null</code>.
108
-	 */
109
-	public final UnitValue getPreferred()
110
-	{
111
-		return pref;
112
-	}
113
-
114
-	/** Returns the maximum size as sent into the constructor.
115
-	 * @return The maximum size as sent into the constructor. May be <code>null</code>.
116
-	 */
117
-	public final UnitValue getMax()
118
-	{
119
-		return max;
120
-	}
121
-
122
-	/** If the size should be hinted as "pushing" and thus want to occupy free space if noone else is claiming it.
123
-	 * @return The value.
124
-	 */
125
-	public boolean getGapPush()
126
-	{
127
-		return gapPush;
128
-	}
129
-
130
-	/** Returns if this bound size has no min, preferred and maximum size set (they are all <code>null</code>)
131
-	 * @return If unset.
132
-	 */
133
-	public boolean isUnset()
134
-	{
135
-		// Most common case by far is this == ZERO_PIXEL...
136
-		return this == ZERO_PIXEL || (pref == null && min == null && max == null && gapPush == false);
137
-	}
138
-
139
-	/** Makes sure that <code>size</code> is within min and max of this size.
140
-	 * @param size The size to constrain.
141
-	 * @param refValue The reference to use for relative sizes.
142
-	 * @param parent The parent container.
143
-	 * @return The size, constrained within min and max.
144
-	 */
145
-	public int constrain(int size, float refValue, ContainerWrapper parent)
146
-	{
147
-		if (max != null)
148
-			size = Math.min(size, max.getPixels(refValue, parent, parent));
149
-		if (min != null)
150
-			size = Math.max(size, min.getPixels(refValue, parent, parent));
151
-		return size;
152
-	}
153
-
154
-	/** Returns the minimum, preferred or maximum size for this bounded size.
155
-	 * @param sizeType The type. <code>LayoutUtil.MIN</code>, <code>LayoutUtil.PREF</code> or <code>LayoutUtil.MAX</code>.
156
-	 * @return
157
-	 */
158
-	final UnitValue getSize(int sizeType)
159
-	{
160
-		switch(sizeType) {
161
-			case LayoutUtil.MIN:
162
-				return min;
163
-			case LayoutUtil.PREF:
164
-				return pref;
165
-			case LayoutUtil.MAX:
166
-				return max;
167
-			default:
168
-				throw new IllegalArgumentException("Unknown size: " + sizeType);
169
-		}
170
-	}
171
-
172
-	/** Convert the bound sizes to pixels.
173
-	 * <p>
174
-	 * <code>null</code> bound sizes will be 0 for min and preferred and {@link net.miginfocom.layout.LayoutUtil#INF} for max.
175
-	 * @param refSize The reference size.
176
-	 * @param parent The parent. Not <code>null</code>.
177
-	 * @param comp The component, if applicable, can be <code>null</code>.
178
-	 * @return An array of lenth three (min,pref,max).
179
-	 */
180
-	final int[] getPixelSizes(float refSize, ContainerWrapper parent, ComponentWrapper comp)
181
-	{
182
-		return new int[] {
183
-				min != null ? min.getPixels(refSize, parent, comp) : 0,
184
-				pref != null ? pref.getPixels(refSize, parent, comp) : 0,
185
-				max != null ? max.getPixels(refSize, parent, comp) : LayoutUtil.INF
186
-		};
187
-	}
188
-
189
-	/** Returns the a constraint string that can be re-parsed to be the exact same UnitValue.
190
-	 * @return A String. Never <code>null</code>.
191
-	 */
192
-	String getConstraintString()
193
-	{
194
-		String cs = LayoutUtil.getCCString(this);
195
-		if (cs != null)
196
-			return cs;
197
-
198
-		if (min == pref && pref == max)
199
-			return min != null ? (min.getConstraintString() + "!") : "null";
200
-
201
-		StringBuilder sb = new StringBuilder(16);
202
-
203
-		if (min != null)
204
-			sb.append(min.getConstraintString()).append(':');
205
-
206
-		if (pref != null) {
207
-			if (min == null && max != null)
208
-				sb.append(":");
209
-			sb.append(pref.getConstraintString());
210
-		} else if (min != null) {
211
-			sb.append('n');
212
-		}
213
-
214
-		if (max != null)
215
-			sb.append(sb.length() == 0 ? "::" : ":").append(max.getConstraintString());
216
-
217
-		if (gapPush) {
218
-			if (sb.length() > 0)
219
-				sb.append(':');
220
-			sb.append("push");
221
-		}
222
-
223
-		return sb.toString();
224
-	}
225
-
226
-	void checkNotLinked()
227
-	{
228
-		if (min != null && min.isLinkedDeep() || pref != null && pref.isLinkedDeep() || max != null && max.isLinkedDeep())
229
-			throw new IllegalArgumentException("Size may not contain links");
230
-	}
231
-
232
-	static {
233
-		LayoutUtil.setDelegate(BoundSize.class, new PersistenceDelegate() {
234
-			protected Expression instantiate(Object oldInstance, Encoder out)
235
-			{
236
-				BoundSize bs = (BoundSize) oldInstance;
237
-				if (Grid.TEST_GAPS) {
238
-					return new Expression(oldInstance, BoundSize.class, "new", new Object[] {
239
-							bs.getMin(), bs.getPreferred(), bs.getMax(), bs.getGapPush(), bs.getConstraintString()
240
-					});
241
-				} else {
242
-					return new Expression(oldInstance, BoundSize.class, "new", new Object[] {
243
-							bs.getMin(), bs.getPreferred(), bs.getMax(), bs.getConstraintString()
244
-					});
245
-				}
246
-			}
247
-		});
248
-	}
249
-
250
-	// ************************************************
251
-	// Persistence Delegate and Serializable combined.
252
-	// ************************************************
253
-
254
-	private static final long serialVersionUID = 1L;
255
-
256
-	protected Object readResolve() throws ObjectStreamException
257
-	{
258
-		return LayoutUtil.getSerializedObject(this);
259
-	}
260
-
261
-	private void writeObject(ObjectOutputStream out) throws IOException
262
-	{
263
-		if (getClass() == BoundSize.class)
264
-			LayoutUtil.writeAsXML(out, this);
265
-	}
266
-
267
-	private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
268
-	{
269
-		LayoutUtil.setSerializedObject(this, LayoutUtil.readAsXML(in));
270
-	}
271
-}

+ 0
- 1599
src/net/miginfocom/layout/CC.java
File diff soppresso perché troppo grande
Vedi File


+ 0
- 294
src/net/miginfocom/layout/ComponentWrapper.java Vedi File

@@ -1,294 +0,0 @@
1
-package net.miginfocom.layout;
2
-/*
3
- * License (BSD):
4
- * ==============
5
- *
6
- * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
7
- * All rights reserved.
8
- *
9
- * Redistribution and use in source and binary forms, with or without modification,
10
- * are permitted provided that the following conditions are met:
11
- * Redistributions of source code must retain the above copyright notice, this list
12
- * of conditions and the following disclaimer.
13
- * Redistributions in binary form must reproduce the above copyright notice, this
14
- * list of conditions and the following disclaimer in the documentation and/or other
15
- * materials provided with the distribution.
16
- * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
17
- * used to endorse or promote products derived from this software without specific
18
- * prior written permission.
19
- *
20
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23
- * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
26
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
29
- * OF SUCH DAMAGE.
30
- *
31
- * @version 1.0
32
- * @author Mikael Grev, MiG InfoCom AB
33
- *         Date: 2006-sep-08
34
- */
35
-
36
-/** A class that wraps the important parts of a Component.
37
- * <p>
38
- * <b>NOTE!</b>.equals() and .hashcode() should be shunted to the wrapped component. E.g.
39
- * <pre>
40
- * 	public int hashCode()
41
-	{
42
-		return getComponent().hashCode();
43
-	}
44
-
45
-	public final boolean equals(Object o)
46
-	{
47
-		 if (o == null || o instanceof ComponentWrapper == false)
48
-			 return false;
49
-
50
-		 return getComponent().equals(((ComponentWrapper) o).getComponent());
51
-	}
52
- * </pre>
53
- */
54
-public interface ComponentWrapper
55
-{
56
-	static final int TYPE_UNSET = -1;
57
-	public static final int TYPE_UNKNOWN = 0;
58
-	public static final int TYPE_CONTAINER = 1;
59
-	public static final int TYPE_LABEL = 2;
60
-	public static final int TYPE_TEXT_FIELD = 3;
61
-	public static final int TYPE_TEXT_AREA = 4;
62
-	public static final int TYPE_BUTTON = 5;
63
-	public static final int TYPE_LIST = 6;
64
-	public static final int TYPE_TABLE = 7;
65
-	public static final int TYPE_SCROLL_PANE = 8;
66
-	public static final int TYPE_IMAGE = 9;
67
-	public static final int TYPE_PANEL = 10;
68
-	public static final int TYPE_COMBO_BOX = 11;
69
-	public static final int TYPE_SLIDER = 12;
70
-	public static final int TYPE_SPINNER = 13;
71
-	public static final int TYPE_PROGRESS_BAR = 14;
72
-	public static final int TYPE_TREE = 15;
73
-	public static final int TYPE_CHECK_BOX = 16;
74
-	public static final int TYPE_SCROLL_BAR = 17;
75
-	public static final int TYPE_SEPARATOR = 18;
76
-
77
-	/** Returns the actual object that this wrapper is aggregating. This might be needed for getting
78
-	 * information about the object that the wrapper interface does not provide.
79
-	 * <p>
80
-	 * If this is a container the container should be returned instead.
81
-	 * @return The actual object that this wrapper is aggregating. Not <code>null</code>.
82
-	 */
83
-	public abstract Object getComponent();
84
-
85
-	/** Returns the current x coordinate for this component.
86
-	 * @return The current x coordinate for this component.
87
-	 */
88
-	public abstract int getX();
89
-
90
-	/** Returns the current y coordinate for this component.
91
-	 * @return The current y coordinate for this component.
92
-	 */
93
-	public abstract int getY();
94
-
95
-	/** Returns the current width for this component.
96
-	 * @return The current width for this component.
97
-	 */
98
-	public abstract int getWidth();
99
-
100
-	/** Returns the current height for this component.
101
-	 * @return The current height for this component.
102
-	 */
103
-	public abstract int getHeight();
104
-
105
-	/** Returns the screen x-coordinate for the upper left coordinate of the component layoutable bounds.
106
-	 * @return The screen x-coordinate for the upper left coordinate of the component layoutable bounds.
107
-	 */
108
-	public abstract int getScreenLocationX();
109
-
110
-	/** Returns the screen y-coordinate for the upper left coordinate of the component layoutable bounds.
111
-	 * @return The screen y-coordinate for the upper left coordinate of the component layoutable bounds.
112
-	 */
113
-	public abstract int getScreenLocationY();
114
-
115
-	/** Returns the minimum width of the component.
116
-	 * @param hHint The Size hint for the other dimension. An implementation can use this value or the
117
-	 * current size for the widget in this dimension, or a combination of both, to calculate the correct size.<br>
118
-	 * Use -1 to denote that there is no hint. This corresponds with SWT.DEFAULT.
119
-	 * @return The minimum width of the component.
120
-	 * @since 3.5. Added the hint as a parameter knowing that a correction and recompilation is neccessary for
121
-	 * any implmenting classes. This change was worth it though.
122
-	 */
123
-	public abstract int getMinimumWidth(int hHint);
124
-
125
-	/** Returns the minimum height of the component.
126
-	 * @param wHint The Size hint for the other dimension. An implementation can use this value or the
127
-	 * current size for the widget in this dimension, or a combination of both, to calculate the correct size.<br>
128
-	 * Use -1 to denote that there is no hint. This corresponds with SWT.DEFAULT.
129
-	 * @return The minimum height of the component.
130
-	 * @since 3.5. Added the hint as a parameter knowing that a correction and recompilation is neccessary for
131
-	 * any implmenting classes. This change was worth it though.
132
-	 */
133
-	public abstract int getMinimumHeight(int wHint);
134
-
135
-	/** Returns the preferred width of the component.
136
-	 * @param hHint The Size hint for the other dimension. An implementation can use this value or the
137
-	 * current size for the widget in this dimension, or a combination of both, to calculate the correct size.<br>
138
-	 * Use -1 to denote that there is no hint. This corresponds with SWT.DEFAULT.
139
-	 * @return The preferred width of the component.
140
-	 * @since 3.5. Added the hint as a parameter knowing that a correction and recompilation is neccessary for
141
-	 * any implmenting classes. This change was worth it though.
142
-	 */
143
-	public abstract int getPreferredWidth(int hHint);
144
-
145
-	/** Returns the preferred height of the component.
146
-	 * @param wHint The Size hint for the other dimension. An implementation can use this value or the
147
-	 * current size for the widget in this dimension, or a combination of both, to calculate the correct size.<br>
148
-	 * Use -1 to denote that there is no hint. This corresponds with SWT.DEFAULT.
149
-	 * @return The preferred height of the component.
150
-	 * @since 3.5. Added the hint as a parameter knowing that a correction and recompilation is neccessary for
151
-	 * any implmenting classes. This change was worth it though.
152
-	 */
153
-	public abstract int getPreferredHeight(int wHint);
154
-
155
-	/** Returns the maximum width of the component.
156
-	 * @param hHint The Size hint for the other dimension. An implementation can use this value or the
157
-	 * current size for the widget in this dimension, or a combination of both, to calculate the correct size.<br>
158
-	 * Use -1 to denote that there is no hint. This corresponds with SWT.DEFAULT.
159
-	 * @return The maximum width of the component.
160
-	 * @since 3.5. Added the hint as a parameter knowing that a correction and recompilation is neccessary for
161
-	 * any implmenting classes. This change was worth it though.
162
-	 */
163
-	public abstract int getMaximumWidth(int hHint);
164
-
165
-	/** Returns the maximum height of the component.
166
-	 * @param wHint The Size hint for the other dimension. An implementation can use this value or the
167
-	 * current size for the widget in this dimension, or a combination of both, to calculate the correct size.<br>
168
-	 * Use -1 to denote that there is no hint. This corresponds with SWT.DEFAULT.
169
-	 * @return The maximum height of the component.
170
-	 * @since 3.5. Added the hint as a parameter knowing that a correction and recompilation is neccessary for
171
-	 * any implmenting classes. This change was worth it though.
172
-	 */
173
-	public abstract int getMaximumHeight(int wHint);
174
-
175
-	/** Sets the component's bounds.
176
-	 * @param x The x coordinate.
177
-	 * @param y The y coordinate.
178
-	 * @param width The width.
179
-	 * @param height The height.
180
-	 */
181
-	public abstract void setBounds(int x, int y, int width, int height);
182
-
183
-	/** Returns if the component's visibility is set to <code>true</code>. This should not return if the component is
184
-	 * actually visibile, but if the visibility is set to true or not.
185
-	 * @return <code>true</code> means visible.
186
-	 */
187
-	public abstract boolean isVisible();
188
-
189
-	/** Returns the baseline for the component given the suggested height.
190
-	 * @param width The width to calculate for if other than the current. If <code>-1</code> the current size should be used.
191
-	 * @param height The height to calculate for if other than the current. If <code>-1</code> the current size should be used.
192
-	 * @return The baseline from the top or -1 if not applicable.
193
-	 */
194
-	public abstract int getBaseline(int width, int height);
195
-
196
-	/** Returns if the component has a baseline and if it can be retrieved. Should for instance return
197
-	 * <code>false</code> for Swing before mustang.
198
-	 * @return If the component has a baseline and if it can be retrieved.
199
-	 */
200
-	public abstract boolean hasBaseline();
201
-
202
-	/** Returns the container for this component.
203
-	 * @return The container for this component. Should never be <code>null</code>.
204
-	 */
205
-	public abstract ContainerWrapper getParent();
206
-
207
-	/** Returns the pixel unit factor for the horizontal or vertical dimension.
208
-	 * <p>
209
-	 * The factor is 1 for both dimensions on the normal font in a JPanel on Windows. The factor should increase with a bigger "X".
210
-	 * <p>
211
-	 * This is the Swing version:
212
-	 * <pre>
213
-	 * Rectangle2D r = fm.getStringBounds("X", parent.getGraphics());
214
-	 * wFactor = r.getWidth() / 6;
215
-	 * hFactor = r.getHeight() / 13.27734375f;
216
-	 * </pre>
217
-	 * @param isHor If it is the horizontal factor that should be returned.
218
-	 * @return The factor.
219
-	 */
220
-	public abstract float getPixelUnitFactor(boolean isHor);
221
-
222
-	/** Returns the DPI (Dots Per Inch) of the screen the component is currently in or for the default
223
-	 * screen if the component is not visible.
224
-	 * <p>
225
-	 * If headless mode {@link net.miginfocom.layout.PlatformDefaults#getDefaultDPI} will be returned.
226
-	 * @return The DPI.
227
-	 */
228
-	public abstract int getHorizontalScreenDPI();
229
-
230
-	/** Returns the DPI (Dots Per Inch) of the screen the component is currently in or for the default
231
-	 * screen if the component is not visible.
232
-	 * <p>
233
-	 * If headless mode {@link net.miginfocom.layout.PlatformDefaults#getDefaultDPI} will be returned.
234
-	 * @return The DPI.
235
-	 */
236
-	public abstract int getVerticalScreenDPI();
237
-
238
-	/** Returns the pixel size of the screen that the component is currently in or for the default
239
-	 * screen if the component is not visible or <code>null</code>.
240
-	 * <p>
241
-	 * If in headless mode <code>1024</code> is returned.
242
-	 * @return The screen size. E.g. <code>1280</code>.
243
-	 */
244
-	public abstract int getScreenWidth();
245
-
246
-	/** Returns the pixel size of the screen that the component is currently in or for the default
247
-	 * screen if the component is not visible or <code>null</code>.
248
-	 * <p>
249
-	 * If in headless mode <code>768</code> is returned.
250
-	 * @return The screen size. E.g. <code>1024</code>.
251
-	 */
252
-	public abstract int getScreenHeight();
253
-
254
-	/** Returns a String id that can be used to reference the component in link constraints. This value should
255
-	 * return the default id for the component. The id can be set for a component in the constraints and if
256
-	 * so the value returned by this method will never be used. If there are no sensible id for the component
257
-	 * <code>null</code> should be returned.
258
-	 * <p>
259
-	 * For instance the Swing implementation returns the string returned from <code>Component.getName()</code>.
260
-	 * @return The string link id or <code>null</code>.
261
-	 */
262
-	public abstract String getLinkId();
263
-
264
-	/** Returns a hash code that should be resonably different for anything that might change the layout. This value is used to
265
-	 *  know if the component layout needs to clear any caches.
266
-	 * @return A hash code that should be resonably different for anything that might change the layout. Returns -1 if the widget is
267
-	 * disposed.
268
-	 */
269
-	public abstract int getLayoutHashCode();
270
-
271
-	/** Returns the padding on a component by component basis. This method can be overridden to return padding to compensate for example for
272
-	 * borders that have shadows or where the outer most pixel is not the visual "edge" to align to.
273
-	 * <p>
274
-	 * Default implementation returnes <code>null</code> for all components except for Windows XP's JTabbedPane which will return new Insets(0, 0, 2, 2).
275
-	 * <p>
276
-	 * <b>NOTE!</B> To reduce cenerated garbage the returned padding should never be changed so that the same insets can be returned many times.
277
-	 * @return <code>null</code> if no padding. <b>NOTE!</B> To reduce cenerated garbage the returned padding should never be changed so that
278
-	 * the same insets can be returned many times. [top, left, bottom, right]
279
-	 */
280
-	public int[] getVisualPadding();
281
-
282
-	/** Paints component outline to indicate where it is.
283
-	 */
284
-	public abstract void paintDebugOutline();
285
-
286
-	/** Returns the type of component that this wrapper is wrapping.
287
-	 * <p>
288
-	 * This method can be invoked often so the result should be cached.
289
-	 * @param disregardScrollPane Is <code>true</code> any wrapping scroll pane should be disregarded and the type
290
-	 * of the scrolled component should be returned.
291
-	 * @return The type of component that this wrapper is wrapping. E.g. {@link #TYPE_LABEL}.
292
-	 */
293
-	public abstract int getComponetType(boolean disregardScrollPane);
294
-}

+ 0
- 1455
src/net/miginfocom/layout/ConstraintParser.java
File diff soppresso perché troppo grande
Vedi File


+ 0
- 69
src/net/miginfocom/layout/ContainerWrapper.java Vedi File

@@ -1,69 +0,0 @@
1
-package net.miginfocom.layout;
2
-/*
3
- * License (BSD):
4
- * ==============
5
- *
6
- * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
7
- * All rights reserved.
8
- *
9
- * Redistribution and use in source and binary forms, with or without modification,
10
- * are permitted provided that the following conditions are met:
11
- * Redistributions of source code must retain the above copyright notice, this list
12
- * of conditions and the following disclaimer.
13
- * Redistributions in binary form must reproduce the above copyright notice, this
14
- * list of conditions and the following disclaimer in the documentation and/or other
15
- * materials provided with the distribution.
16
- * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
17
- * used to endorse or promote products derived from this software without specific
18
- * prior written permission.
19
- *
20
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23
- * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
26
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
29
- * OF SUCH DAMAGE.
30
- *
31
- * @version 1.0
32
- * @author Mikael Grev, MiG InfoCom AB
33
- *         Date: 2006-sep-08
34
- */
35
-
36
-/** A class that wraps a container that contains components.
37
- */
38
-public interface ContainerWrapper extends ComponentWrapper
39
-{
40
-	/** Returns the components of the container that wrapper is wrapping.
41
-	 * @return The components of the container that wrapper is wrapping. Never <code>null</code>.
42
-	 */
43
-	public abstract ComponentWrapper[] getComponents();
44
-
45
-	/** Returns the number of components that this parent has.
46
-	 * @return The number of components that this parent has.
47
-	 */
48
-	public abstract int getComponentCount();
49
-
50
-	/** Returns the <code>LayoutHandler</code> (in Swing terms) that is handling the layout of this container.
51
-	 * If there exist no such class the method should return the same as {@link #getComponent()}, which is the
52
-	 * container itself.
53
-	 * @return The layout handler instance. Never <code>null</code>.
54
-	 */
55
-	public abstract Object getLayout();
56
-
57
-	/** Returns if this container is using left-to-right component ordering.
58
-	 * @return If this container is using left-to-right component ordering.
59
-	 */
60
-	public abstract boolean isLeftToRight();
61
-
62
-	/** Paints a cell to indicate where it is.
63
-	 * @param x The x coordinate to start the drwaing.
64
-	 * @param y The x coordinate to start the drwaing.
65
-	 * @param width The width to draw/fill
66
-	 * @param height The height to draw/fill
67
-	 */
68
-	public abstract void paintDebugCell(int x, int y, int width, int height);
69
-}

+ 0
- 478
src/net/miginfocom/layout/DimConstraint.java Vedi File

@@ -1,478 +0,0 @@
1
-package net.miginfocom.layout;
2
-
3
-import java.io.*;
4
-/*
5
- * License (BSD):
6
- * ==============
7
- *
8
- * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
9
- * All rights reserved.
10
- *
11
- * Redistribution and use in source and binary forms, with or without modification,
12
- * are permitted provided that the following conditions are met:
13
- * Redistributions of source code must retain the above copyright notice, this list
14
- * of conditions and the following disclaimer.
15
- * Redistributions in binary form must reproduce the above copyright notice, this
16
- * list of conditions and the following disclaimer in the documentation and/or other
17
- * materials provided with the distribution.
18
- * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
19
- * used to endorse or promote products derived from this software without specific
20
- * prior written permission.
21
- *
22
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25
- * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
26
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
28
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
31
- * OF SUCH DAMAGE.
32
- *
33
- * @version 1.0
34
- * @author Mikael Grev, MiG InfoCom AB
35
- *         Date: 2006-sep-08
36
- */
37
-
38
-/** A simple value holder for a constraint for one dimension.
39
- */
40
-public final class DimConstraint implements Externalizable
41
-{
42
-
43
-	/**
44
-	 * A version number for this class. It should be changed whenever the
45
-	 * class structure is changed (or anything else that would prevent
46
-	 * serialized objects being unserialized with the new class).
47
-	 */
48
-	private static final long serialVersionUID = 1;
49
-
50
-	/** How this entity can be resized in the dimension that this constraint represents.
51
-	 */
52
-	final ResizeConstraint resize = new ResizeConstraint();
53
-
54
-	// Look at the properties' getter/setter methods for explanation
55
-
56
-	private String sizeGroup = null;            // A "context" compared with equals.
57
-
58
-	private BoundSize size = BoundSize.NULL_SIZE;     // Min, pref, max. Never null, but sizes can be null.
59
-
60
-	private BoundSize gapBefore = null, gapAfter = null;
61
-
62
-	private UnitValue align = null;
63
-
64
-
65
-	// **************  Only applicable on components! *******************
66
-
67
-	private String endGroup = null;            // A "context" compared with equals.
68
-
69
-
70
-	// **************  Only applicable on rows/columns! *******************
71
-
72
-	private boolean fill = false;
73
-
74
-	private boolean noGrid = false;
75
-
76
-	/** Empty constructor.
77
-	 */
78
-	public DimConstraint()
79
-	{
80
-	}
81
-
82
-	/** Returns the grow priority. Relative priority is used for determining which entities gets the extra space first.
83
-	 * <p>
84
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
85
-	 * @return The grow priority.
86
-	 */
87
-	public int getGrowPriority()
88
-	{
89
-		return resize.growPrio;
90
-	}
91
-
92
-	/** Sets the grow priority. Relative priority is used for determining which entities gets the extra space first.
93
-	 * <p>
94
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
95
-	 * @param p The new grow priority.
96
-	 */
97
-	public void setGrowPriority(int p)
98
-	{
99
-		resize.growPrio = p;
100
-	}
101
-
102
-	/** Returns the grow weight.<p>
103
-	 * Grow weight is how flexilble the entity should be, relative to other entities, when it comes to growing. <code>null</code> or
104
-	 * zero mean it will never grow. An entity that has twise the grow weight compared to another entity will get twice
105
-	 * as much of available space.
106
-	 * <p>
107
-	 * GrowWeight are only compared within the same GrowPrio.
108
-	 * <p>
109
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
110
-	 * @return The current grow weight.
111
-	 */
112
-	public Float getGrow()
113
-	{
114
-		return resize.grow;
115
-	}
116
-
117
-	/** Sets the grow weight.<p>
118
-	 * Grow weight is how flexilble the entity should be, relative to other entities, when it comes to growing. <code>null</code> or
119
-	 * zero mean it will never grow. An entity that has twise the grow weight compared to another entity will get twice
120
-	 * as much of available space.
121
-	 * <p>
122
-	 * GrowWeight are only compared within the same GrowPrio.
123
-	 * <p>
124
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
125
-	 * @param weight The new grow weight.
126
-	 */
127
-	public void setGrow(Float weight)
128
-	{
129
-		resize.grow = weight;
130
-	}
131
-
132
-	/** Returns the shrink priority. Relative priority is used for determining which entities gets smaller first when space is scarse.
133
-	 * <p>
134
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
135
-	 * @return The shrink priority.
136
-	 */
137
-	public int getShrinkPriority()
138
-	{
139
-		return resize.shrinkPrio;
140
-	}
141
-
142
-	/** Sets the shrink priority. Relative priority is used for determining which entities gets smaller first when space is scarse.
143
-	 * <p>
144
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
145
-	 * @param p The new shrink priority.
146
-	 */
147
-	public void setShrinkPriority(int p)
148
-	{
149
-		resize.shrinkPrio = p;
150
-	}
151
-
152
-	/** Returns the shrink priority. Relative priority is used for determining which entities gets smaller first when space is scarse.
153
-	 * Shrink weight is how flexilble the entity should be, relative to other entities, when it comes to shrinking. <code>null</code> or
154
-	 * zero mean it will never shrink (default). An entity that has twise the shrink weight compared to another entity will get twice
155
-	 * as much of available space.
156
-	 * <p>
157
-	 * Shrink(Weight) are only compared within the same ShrinkPrio.
158
-	 * <p>
159
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
160
-	 * @return The current shrink weight.
161
-	 */
162
-	public Float getShrink()
163
-	{
164
-		return resize.shrink;
165
-	}
166
-
167
-	/** Sets the shrink priority. Relative priority is used for determining which entities gets smaller first when space is scarse.
168
-	 * Shrink weight is how flexilble the entity should be, relative to other entities, when it comes to shrinking. <code>null</code> or
169
-	 * zero mean it will never shrink (default). An entity that has twise the shrink weight compared to another entity will get twice
170
-	 * as much of available space.
171
-	 * <p>
172
-	 * Shrink(Weight) are only compared within the same ShrinkPrio.
173
-	 * <p>
174
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
175
-	 * @param weight The new shrink weight.
176
-	 */
177
-	public void setShrink(Float weight)
178
-	{
179
-		resize.shrink = weight;
180
-	}
181
-
182
-	public UnitValue getAlignOrDefault(boolean isCols)
183
-	{
184
-		if (align != null)
185
-			return align;
186
-
187
-		if (isCols)
188
-			return UnitValue.LEADING;
189
-
190
-		return fill || PlatformDefaults.getDefaultRowAlignmentBaseline() == false ? UnitValue.CENTER : UnitValue.BASELINE_IDENTITY;
191
-	}
192
-
193
-	/** Returns the alignment used either as a default value for sub-entities or for this entity.
194
-	 * <p>
195
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
196
-	 * @return The alignment.
197
-	 */
198
-	public UnitValue getAlign()
199
-	{
200
-		return align;
201
-	}
202
-
203
-	/** Sets the alignment used wither as a default value for sub-entities or for this entity.
204
-	 * <p>
205
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
206
-	 * @param uv The new shrink priority. E.g. {@link UnitValue#CENTER} or {@link net.miginfocom.layout.UnitValue#LEADING}.
207
-	 */
208
-	public void setAlign(UnitValue uv)
209
-	{
210
-		this.align = uv;
211
-	}
212
-
213
-	/** Returns the gap after this entitiy. The gap is an empty space and can have a min/preferred/maximum size so that it can shrink and
214
-	 * grow depending on available space. Gaps are against other entities' edges and not against other entities' gaps.
215
-	 * <p>
216
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
217
-	 * @return The gap after this entitiy
218
-	 */
219
-	public BoundSize getGapAfter()
220
-	{
221
-		return gapAfter;
222
-	}
223
-
224
-	/** Sets the gap after this entitiy. The gap is an empty space and can have a min/preferred/maximum size so that it can shrink and
225
-	 * grow depending on available space. Gaps are against other entities' edges and not against other entities' gaps.
226
-	 * <p>
227
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
228
-	 * @param size The new gap.
229
-	 * @see net.miginfocom.layout.ConstraintParser#parseBoundSize(String, boolean, boolean).
230
-	 */
231
-	public void setGapAfter(BoundSize size)
232
-	{
233
-		this.gapAfter = size;
234
-	}
235
-
236
-	boolean hasGapAfter()
237
-	{
238
-		return gapAfter != null && gapAfter.isUnset() == false;
239
-	}
240
-
241
-	boolean isGapAfterPush()
242
-	{
243
-		return gapAfter != null && gapAfter.getGapPush();
244
-	}
245
-
246
-	/** Returns the gap before this entitiy. The gap is an empty space and can have a min/preferred/maximum size so that it can shrink and
247
-	 * grow depending on available space. Gaps are against other entities' edges and not against other entities' gaps.
248
-	 * <p>
249
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
250
-	 * @return The gap before this entitiy
251
-	 */
252
-	public BoundSize getGapBefore()
253
-	{
254
-		return gapBefore;
255
-	}
256
-
257
-	/** Sets the gap before this entitiy. The gap is an empty space and can have a min/preferred/maximum size so that it can shrink and
258
-	 * grow depending on available space. Gaps are against other entities' edges and not against other entities' gaps.
259
-	 * <p>
260
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
261
-	 * @param size The new gap.
262
-	 * @see net.miginfocom.layout.ConstraintParser#parseBoundSize(String, boolean, boolean).
263
-	 */
264
-	public void setGapBefore(BoundSize size)
265
-	{
266
-		this.gapBefore = size;
267
-	}
268
-
269
-	boolean hasGapBefore()
270
-	{
271
-		return gapBefore != null && gapBefore.isUnset() == false;
272
-	}
273
-
274
-	boolean isGapBeforePush()
275
-	{
276
-		return gapBefore != null && gapBefore.getGapPush();
277
-	}
278
-
279
-	/** Returns the min/preferred/max size for the entity in the dimension that this object describes.
280
-	 * <p>
281
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
282
-	 * @return The current size. Never <code>null</code> since v3.5.
283
-	 * @see net.miginfocom.layout.ConstraintParser#parseBoundSize(String, boolean, boolean).
284
-	 */
285
-	public BoundSize getSize()
286
-	{
287
-		return size;
288
-	}
289
-
290
-	/** Sets the min/preferred/max size for the enintity in the dimension that this object describes.
291
-	 * <p>
292
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
293
-	 * @param size The new size. May be <code>null</code>.
294
-	 */
295
-	public void setSize(BoundSize size)
296
-	{
297
-		size.checkNotLinked();
298
-		this.size = size;
299
-	}
300
-
301
-	/** Returns the size group that this entitiy should be in for the demension that this object is describing.
302
-	 * If this constraint is in a size group that is specified here. <code>null</code> means no size group
303
-	 * and all other values are legal. Comparison with .equals(). Components/columnss/rows in the same size group
304
-	 * will have the same min/preferred/max size; that of the largest in the group for the first two and the
305
-	 * smallest for max.
306
-	 * <p>
307
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
308
-	 * @return The current size group. May be <code>null</code>.
309
-	 */
310
-	public String getSizeGroup()
311
-	{
312
-		return sizeGroup;
313
-	}
314
-
315
-	/** Sets the size group that this entitiy should be in for the demension that this object is describing.
316
-	 * If this constraint is in a size group that is specified here. <code>null</code> means no size group
317
-	 * and all other values are legal. Comparison with .equals(). Components/columnss/rows in the same size group
318
-	 * will have the same min/preferred/max size; that of the largest in the group for the first two and the
319
-	 * smallest for max.
320
-	 * <p>
321
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
322
-	 * @param s The new size group. <code>null</code> disables size grouping.
323
-	 */
324
-	public void setSizeGroup(String s)
325
-	{
326
-		sizeGroup = s;
327
-	}
328
-
329
-	// **************  Only applicable on components ! *******************
330
-
331
-	/** Returns the end group that this entitiy should be in for the demension that this object is describing.
332
-	 * If this constraint is in an end group that is specified here. <code>null</code> means no end group
333
-	 * and all other values are legal. Comparison with .equals(). Components in the same end group
334
-	 * will have the same end coordinate.
335
-	 * <p>
336
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
337
-	 * @return The current end group. <code>null</code> may be returned.
338
-	 */
339
-	public String getEndGroup()
340
-	{
341
-		return endGroup;
342
-	}
343
-
344
-	/** Sets the end group that this entitiy should be in for the demension that this object is describing.
345
-	 * If this constraint is in an end group that is specified here. <code>null</code> means no end group
346
-	 * and all other values are legal. Comparison with .equals(). Components in the same end group
347
-	 * will have the same end coordinate.
348
-	 * <p>
349
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
350
-	 * @param s The new end group. <code>null</code> disables end grouping.
351
-	 */
352
-	public void setEndGroup(String s)
353
-	{
354
-		endGroup = s;
355
-	}
356
-
357
-	// **************  Not applicable on components below ! *******************
358
-
359
-	/** Returns if the component in the row/column that this constraint should default be grown in the same dimension that
360
-	 * this constraint represents (width for column and height for a row).
361
-	 * <p>
362
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
363
-	 * @return code>true</code> means that components should grow.
364
-	 */
365
-	public boolean isFill()
366
-	{
367
-		return fill;
368
-	}
369
-
370
-	/** Sets if the component in the row/column that this constraint should default be grown in the same dimension that
371
-	 * this constraint represents (width for column and height for a row).
372
-	 * <p>
373
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
374
-	 * @param b <code>true</code> means that components should grow.
375
-	 */
376
-	public void setFill(boolean b)
377
-	{
378
-		fill = b;
379
-	}
380
-
381
-	/** Returns if the row/column should default to flow and not to grid behaviour. This means that the whole row/column
382
-	 * will be one cell and all components will end up in that cell.
383
-	 * <p>
384
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
385
-	 * @return <code>true</code> means that the whole row/column should be one cell.
386
-	 */
387
-	public boolean isNoGrid()
388
-	{
389
-		return noGrid;
390
-	}
391
-
392
-	/** Sets if the row/column should default to flow and not to grid behaviour. This means that the whole row/column
393
-	 * will be one cell and all components will end up in that cell.
394
-	 * <p>
395
-	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
396
-	 * @param b <code>true</code> means that the whole row/column should be one cell.
397
-	 */
398
-	public void setNoGrid(boolean b)
399
-	{
400
-		this.noGrid = b;
401
-	}
402
-
403
-	/** Returns the gaps as pixel values.
404
-	 * @param parent The parent. Used to get the pixel values.
405
-	 * @param defGap The default gap to use if there is no gap set on this object (i.e. it is null).
406
-	 * @param refSize The reference size used to get the pixel sizes.
407
-	 * @param before IF it is the gap before rather than the gap after to return.
408
-	 * @return The [min,preferred,max] sizes for the specified gap. Uses {@link net.miginfocom.layout.LayoutUtil#NOT_SET}
409
-	 * for gap sizes that are <code>null</code>. Returns <code>null</code> if there was no gap specified. A new and free to use array.
410
-	 */
411
-	int[] getRowGaps(ContainerWrapper parent, BoundSize defGap, int refSize, boolean before)
412
-	{
413
-		BoundSize gap = before ? gapBefore : gapAfter;
414
-		if (gap == null || gap.isUnset())
415
-			gap = defGap;
416
-
417
-		if (gap == null || gap.isUnset())
418
-			return null;
419
-
420
-		int[] ret = new int[3];
421
-		for (int i = LayoutUtil.MIN; i <= LayoutUtil.MAX; i++) {
422
-			UnitValue uv = gap.getSize(i);
423
-			ret[i] = uv != null ? uv.getPixels(refSize, parent, null) : LayoutUtil.NOT_SET;
424
-		}
425
-		return ret;
426
-	}
427
-
428
-	/** Returns the gaps as pixel values.
429
-	 * @param parent The parent. Used to get the pixel values.
430
-	 * @param comp The component that the gap is for. If not for a component it is <code>null</code>.
431
-	 * @param adjGap The gap that the adjacent component, if any, has towards <code>comp</code>.
432
-	 * @param adjacentComp The adjacent component if any. May be <code>null</code>.
433
-	 * @param refSize The reference size used to get the pixel sizes.
434
-	 * @param adjacentSide Whan side the <code>adjacentComp</code> is on. 0 = top, 1 = left, 2 = bottom, 3 = right.
435
-	 * @param tag The tag string that the component might be tagged with in the component constraints. May be <code>null</code>.
436
-	 * @param isLTR If it is left-to-right.
437
-	 * @return The [min,preferred,max] sizes for the specified gap. Uses {@link net.miginfocom.layout.LayoutUtil#NOT_SET}
438
-	 * for gap sizes that are <code>null</code>. Returns <code>null</code> if there was no gap specified. A new and free to use array.
439
-	 */
440
-	int[] getComponentGaps(ContainerWrapper parent, ComponentWrapper comp, BoundSize adjGap, ComponentWrapper adjacentComp, String tag, int refSize, int adjacentSide, boolean isLTR)
441
-	{
442
-		BoundSize gap = adjacentSide < 2 ? gapBefore : gapAfter;
443
-
444
-		boolean hasGap = gap != null && gap.getGapPush();
445
-		if ((gap == null || gap.isUnset()) && (adjGap == null || adjGap.isUnset()) && comp != null)
446
-			gap = PlatformDefaults.getDefaultComponentGap(comp, adjacentComp, adjacentSide + 1, tag, isLTR);
447
-
448
-		if (gap == null)
449
-			return hasGap ? new int[] {0, 0, LayoutUtil.NOT_SET} : null;
450
-
451
-		int[] ret = new int[3];
452
-		for (int i = LayoutUtil.MIN; i <= LayoutUtil.MAX; i++) {
453
-			UnitValue uv = gap.getSize(i);
454
-			ret[i] = uv != null ? uv.getPixels(refSize, parent, null) : LayoutUtil.NOT_SET;
455
-		}
456
-		return ret;
457
-	}
458
-
459
-	// ************************************************
460
-	// Persistence Delegate and Serializable combined.
461
-	// ************************************************
462
-
463
-	private Object readResolve() throws ObjectStreamException
464
-	{
465
-		return LayoutUtil.getSerializedObject(this);
466
-	}
467
-
468
-	public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
469
-	{
470
-		LayoutUtil.setSerializedObject(this, LayoutUtil.readAsXML(in));
471
-	}
472
-
473
-	public void writeExternal(ObjectOutput out) throws IOException
474
-	{
475
-		if (getClass() == DimConstraint.class)
476
-			LayoutUtil.writeAsXML(out, this);
477
-	}
478
-}

+ 0
- 2343
src/net/miginfocom/layout/Grid.java
File diff soppresso perché troppo grande
Vedi File


+ 0
- 787
src/net/miginfocom/layout/IDEUtil.java Vedi File

@@ -1,787 +0,0 @@
1
-package net.miginfocom.layout;
2
-
3
-import java.util.HashMap;
4
-/*
5
- * License (BSD):
6
- * ==============
7
- *
8
- * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
9
- * All rights reserved.
10
- *
11
- * Redistribution and use in source and binary forms, with or without modification,
12
- * are permitted provided that the following conditions are met:
13
- * Redistributions of source code must retain the above copyright notice, this list
14
- * of conditions and the following disclaimer.
15
- * Redistributions in binary form must reproduce the above copyright notice, this
16
- * list of conditions and the following disclaimer in the documentation and/or other
17
- * materials provided with the distribution.
18
- * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
19
- * used to endorse or promote products derived from this software without specific
20
- * prior written permission.
21
- *
22
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25
- * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
26
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
28
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
31
- * OF SUCH DAMAGE.
32
- *
33
- * @version 1.0
34
- * @author Mikael Grev, MiG InfoCom AB
35
- *         Date: 2006-sep-08
36
- */
37
-
38
-/** This class contains static methods to be used by IDE vendors to convert to and from String/API constraints.
39
- * <p>
40
- * <b>Note that {@link LayoutUtil#setDesignTime(ContainerWrapper, boolean)} should be set to <code>true</code> for this class'
41
- * methods to work.</b>
42
- */
43
-public class IDEUtil
44
-{
45
-	/** A direct reference to the corresponding value for predefined UnitValues in {@link UnitValue}.
46
-	 */
47
-	public static final UnitValue ZERO = UnitValue.ZERO;
48
-
49
-	/** A direct reference to the corresponding value for predefined UnitValues in {@link UnitValue}.
50
-	 */
51
-	public static final UnitValue TOP = UnitValue.TOP;
52
-
53
-	/** A direct reference to the corresponding value for predefined UnitValues in {@link UnitValue}.
54
-	 */
55
-	public static final UnitValue LEADING = UnitValue.LEADING;
56
-
57
-	/** A direct reference to the corresponding value for predefined UnitValues in {@link UnitValue}.
58
-	 */
59
-	public static final UnitValue LEFT = UnitValue.LEFT;
60
-
61
-	/** A direct reference to the corresponding value for predefined UnitValues in {@link UnitValue}.
62
-	 */
63
-	public static final UnitValue CENTER = UnitValue.CENTER;
64
-
65
-	/** A direct reference to the corresponding value for predefined UnitValues in {@link UnitValue}.
66
-	 */
67
-	public static final UnitValue TRAILING = UnitValue.TRAILING;
68
-
69
-	/** A direct reference to the corresponding value for predefined UnitValues in {@link UnitValue}.
70
-	 */
71
-	public static final UnitValue RIGHT = UnitValue.RIGHT;
72
-
73
-	/** A direct reference to the corresponding value for predefined UnitValues in {@link UnitValue}.
74
-	 */
75
-	public static final UnitValue BOTTOM = UnitValue.BOTTOM;
76
-
77
-	/** A direct reference to the corresponding value for predefined UnitValues in {@link UnitValue}.
78
-	 */
79
-	public static final UnitValue LABEL = UnitValue.LABEL;
80
-
81
-	/** A direct reference to the corresponding value for predefined UnitValues in {@link UnitValue}.
82
-	 */
83
-	public static final UnitValue INF = UnitValue.INF;
84
-
85
-	/** A direct reference to the corresponding value for predefined UnitValues in {@link UnitValue}.
86
-	 */
87
-	public static final UnitValue BASELINE_IDENTITY = UnitValue.BASELINE_IDENTITY;
88
-
89
-	private final static String[] X_Y_STRINGS = new String[] {"x", "y", "x2", "y2"};
90
-
91
-	/** Returns the version of IDEUtil
92
-	 * @return The version.
93
-	 */
94
-	public String getIDEUtilVersion()
95
-	{
96
-		return "1.0";
97
-	}
98
-
99
-	/** Returns the grid cells that the components in <code>parentContainer</code> has.
100
-	 * @param parentContainer The parent container. It is an object since MigLayout is GUI toolkit
101
-	 * independent.
102
-	 * @return A new hashmap with the components mapped to an array [x, y, spanx, spany].
103
-	 * <p>
104
-	 * Dock components will always have x and y less than -30000 or more than 30000. This is since they
105
-	 * are actually part of the grid, but on the outer edges.
106
-	 * <p>
107
-	 * Components that span the "rest of the row/column" have really large span values. Actually 30000-x or
108
-	 * 30000-y.
109
-	 * <p>
110
-	 * Generally, the grid does not need to have the upper left at 0, 0. Though it normally does if you
111
-	 * don't set the cells explicitly to other values. Rows and columns that are completely empty and
112
-	 * that does not have an explicit row/column constraint will be totally disregarded.
113
-	 */
114
-	public static HashMap<Object, int[]> getGridPositions(Object parentContainer)
115
-	{
116
-		return Grid.getGridPositions(parentContainer);
117
-	}
118
-
119
-	/** Returns the sizes of the rows and gaps for a container.
120
-	 * There will be two arrays returned [0] and [1].
121
-	 * <p>
122
-	 * The first array will be the indexes of the rows where indexes that
123
-	 * are less than 30000 or larger than 30000 is docking rows. There might be extra docking rows that aren't
124
-	 * visible but they always have size 0. Non docking indexes will probably always be 0, 1, 2, 3, etc..
125
-	 * <p>
126
-	 * The second array is the sizes of the form:<br>
127
-	 * <code>[left inset][row size 1][gap 1][row size 2][gap 2][row size n][right inset]</code>.
128
-	 * <p>
129
-	 * The returned sizes will be the ones calculated in the last layout cycle.
130
-	 * @param parentContainer The container to retuern the row sizes and gaps for. In Swing it will be a {@link java.awt.Container} and
131
-	 * in SWT it will be a {@link org.eclipse.swt.widgets.Composite}.
132
-	 * @return The sizes or <code>null</code> if {@link LayoutUtil#isDesignTime(ContainerWrapper)} is <code>false</code> or
133
-	 * <code>parentContainer</code> does not have a MigLayout layout manager.
134
-	 * The returned sizes will be the ones calculated in the last layout cycle.
135
-	 * @see LayoutUtil#isDesignTime(ContainerWrapper)
136
-	 */
137
-	public static int[][] getRowSizes(Object parentContainer)
138
-	{
139
-		return Grid.getSizesAndIndexes(parentContainer, true);
140
-	}
141
-
142
-	/** Returns the sizes of the columns and gaps for a container.
143
-	 * There will be two arrays returned [0] and [1].
144
-	 * <p>
145
-	 * The first array will be the indexes of the columns where indexes that
146
-	 * are less than 30000 or larger than 30000 is docking columns. There might be extra docking columns that aren't
147
-	 * visible but they always have size 0. Non docking indexes will probably always be 0, 1, 2, 3, etc..
148
-	 * <p>
149
-	 * The second array is the sizes of the form:<br>
150
-	 * <code>[top inset][column size 1][gap 1][column size 2][gap 2][column size n][bottom inset]</code>.
151
-	 * <p>
152
-	 * The returned sizes will be the ones calculated in the last layout cycle.
153
-	 * @param parentContainer The container to retuern the column sizes and gaps for. In Swing it will be a {@link java.awt.Container} and
154
-	 * in SWT it will be a {@link org.eclipse.swt.widgets.Composite}.
155
-	 * @return The sizes and indexes or <code>null</code> if {@link LayoutUtil#isDesignTime(ContainerWrapper)} is <code>false</code> or
156
-	 * <code>parentContainer</code> does not have a MigLayout layout manager.
157
-	 * The returned sizes will be the ones calculated in the last layout cycle.
158
-	 * @see LayoutUtil#isDesignTime(ContainerWrapper)
159
-	 */
160
-	public static int[][] getColumnSizes(Object parentContainer)
161
-	{
162
-		return Grid.getSizesAndIndexes(parentContainer, false);
163
-	}
164
-
165
-	/** Returns the a constraint string that can be re-parsed to be the exact same AxisConstraint.
166
-	 * @param ac The axis constraint to return as a constraint string.
167
-	 * @param asAPI If the returned string should be of API type (e.g. .flowX().gap("rel").align("right")) or
168
-	 * as a String type (e.g. "flowx, gap rel, right").
169
-	 * @param isCols The the constraint should be returned for columns rather than rows.
170
-	 * @return A String. Never <code>null</code>.
171
-	 */
172
-	public static final String getConstraintString(AC ac, boolean asAPI, boolean isCols)
173
-	{
174
-		StringBuffer sb = new StringBuffer(32);
175
-
176
-		DimConstraint[] dims = ac.getConstaints();
177
-		BoundSize defGap = isCols ? PlatformDefaults.getGridGapX() : PlatformDefaults.getGridGapY();
178
-
179
-		for (int i = 0; i < dims.length; i++) {
180
-			DimConstraint dc = dims[i];
181
-
182
-			addRowDimConstraintString(dc, sb, asAPI);
183
-
184
-			if (i < dims.length - 1) {
185
-				BoundSize gap = dc.getGapAfter();
186
-
187
-				if (gap == defGap || gap == null)
188
-					gap = dims[i + 1].getGapBefore();
189
-
190
-				if (gap != null) {
191
-					String gapStr = getBS(gap);
192
-					if (asAPI) {
193
-						sb.append(".gap(\"").append(gapStr).append("\")");
194
-					} else {
195
-						sb.append(gapStr);
196
-					}
197
-				} else {
198
-					if (asAPI)
199
-						sb.append(".gap()");
200
-				}
201
-			}
202
-		}
203
-
204
-		return sb.toString();
205
-	}
206
-
207
-	/** Adds the a constraint string that can be re-parsed to be the exact same DimConstraint.
208
-	 * @param dc The layout constraint to return as a constraint string.
209
-	 * @param asAPI If the returned string should be of API type (e.g. .flowX().gap("rel").align("right")) or
210
-	 * as a String type (e.g. "flowx, gap rel, right").
211
-	 */
212
-	private static final void addRowDimConstraintString(DimConstraint dc, StringBuffer sb, boolean asAPI)
213
-	{
214
-		int gp = dc.getGrowPriority();
215
-
216
-		int firstComma = sb.length();
217
-
218
-		BoundSize size = dc.getSize();
219
-		if (size.isUnset() == false) {
220
-			if (asAPI) {
221
-				sb.append(".size(\"").append(getBS(size)).append("\")");
222
-			} else {
223
-				sb.append(',').append(getBS(size));
224
-			}
225
-		}
226
-
227
-		if (gp != 100) {
228
-			if (asAPI) {
229
-				sb.append(".growPrio(").append(gp).append("\")");
230
-			} else {
231
-				sb.append(",growprio ").append(gp);
232
-			}
233
-		}
234
-
235
-		Float gw = dc.getGrow();
236
-		if (gw != null) {
237
-			String g = gw.floatValue() != 100f ? floatToString(gw.floatValue(), asAPI) : "";
238
-			if (asAPI) {
239
-				if (g.length() == 0) {
240
-					sb.append(".grow()");
241
-				} else {
242
-					sb.append(".grow(\"").append(g).append("\")");
243
-				}
244
-			} else {
245
-				sb.append(",grow").append(g.length() > 0 ? (" " + g) : "");
246
-			}
247
-		}
248
-
249
-		int sp = dc.getShrinkPriority();
250
-		if (sp != 100) {
251
-			if (asAPI) {
252
-				sb.append(".shrinkPrio(").append(sp).append("\")");
253
-			} else {
254
-				sb.append(",shrinkprio ").append(sp);
255
-			}
256
-		}
257
-
258
-		Float sw = dc.getShrink();
259
-		if (sw != null && sw.intValue() != 100) {
260
-			String s = floatToString(sw.floatValue(), asAPI);
261
-			if (asAPI) {
262
-				sb.append(".shrink(\"").append(s).append("\")");
263
-			} else {
264
-				sb.append(",shrink ").append(s);
265
-			}
266
-		}
267
-
268
-		String eg = dc.getEndGroup();
269
-		if (eg != null) {
270
-			if (asAPI) {
271
-				sb.append(".endGroup(\"").append(eg).append("\")");
272
-			} else {
273
-				sb.append(",endgroup ").append(eg);
274
-			}
275
-		}
276
-
277
-		String sg = dc.getSizeGroup();
278
-		if (sg != null) {
279
-			if (asAPI) {
280
-				sb.append(".sizeGroup(\"").append(sg).append("\")");
281
-			} else {
282
-				sb.append(",sizegroup ").append(sg);
283
-			}
284
-		}
285
-
286
-		UnitValue al = dc.getAlign();
287
-		if (al != null) {
288
-			if (asAPI) {
289
-				sb.append(".align(\"").append(getUV(al)).append("\")");
290
-			} else {
291
-				String s = getUV(al);
292
-				String alKw = (s.equals("top") || s.equals("bottom") || s.equals("left") || s.equals("label") ||
293
-							   s.equals("leading") || s.equals("center") || s.equals("trailing") ||
294
-							   s.equals("right") || s.equals("baseline")) ? "" : "align ";
295
-				sb.append(',').append(alKw).append(s);
296
-			}
297
-		}
298
-
299
-		if (dc.isNoGrid()) {
300
-			if (asAPI) {
301
-				sb.append(".noGrid()");
302
-			} else {
303
-				sb.append(",nogrid");
304
-			}
305
-		}
306
-
307
-		if (dc.isFill()) {
308
-			if (asAPI) {
309
-				sb.append(".fill()");
310
-			} else {
311
-				sb.append(",fill");
312
-			}
313
-		}
314
-
315
-		if (asAPI == false) {
316
-			if (sb.length() > firstComma) {
317
-				sb.setCharAt(firstComma, '[');
318
-				sb.append(']');
319
-			} else {
320
-				sb.append("[]");
321
-			}
322
-		}
323
-	}
324
-
325
-	/** Returns the a constraint string that can be re-parsed to be the exact same DimConstraint.
326
-	 * @param dc The layout constraint to return as a constraint string.
327
-	 * @param asAPI If the returned string should be of API type (e.g. .flowX().gap("rel").align("right")) or
328
-	 * as a String type (e.g. "flowx, gap rel, right").
329
-	 * @param isHor The the DimConstraint is decoration something horizontal (column or x).
330
-	 * @param noGrowAdd If <code>true</code> no grow constraints will be added.
331
-	 * @return A constraint string. Never <code>null</code>.
332
-	 */
333
-	private static final void addComponentDimConstraintString(DimConstraint dc, StringBuffer sb, boolean asAPI, boolean isHor, boolean noGrowAdd)
334
-	{
335
-		int gp = dc.getGrowPriority();
336
-		if (gp != 100) {
337
-			if (asAPI) {
338
-				sb.append(isHor ? ".growPrioX(" : ".growPrioY(").append(gp).append(')');
339
-			} else {
340
-				sb.append(isHor ? ",growpriox " : ",growprioy ").append(gp);
341
-			}
342
-		}
343
-
344
-		if (noGrowAdd == false) {
345
-			Float gw = dc.getGrow();
346
-			if (gw != null) {
347
-				String g = gw.floatValue() != 100f ? floatToString(gw.floatValue(), asAPI) : "";
348
-				if (asAPI) {
349
-					sb.append(isHor ? ".growX(" : ".growY(").append(g).append(')');
350
-				} else {
351
-					sb.append(isHor ? ",growx" : ",growy").append(g.length() > 0 ? (" " + g) : "");
352
-				}
353
-			}
354
-		}
355
-
356
-		int sp = dc.getShrinkPriority();
357
-		if (sp != 100) {
358
-			if (asAPI) {
359
-				sb.append(isHor ? ".shrinkPrioX(" : ".shrinkPrioY(").append(sp).append(')');
360
-			} else {
361
-				sb.append(isHor ? ",shrinkpriox " : ",shrinkprioy ").append(sp);
362
-			}
363
-		}
364
-
365
-		Float sw = dc.getShrink();
366
-		if (sw != null && sw.intValue() != 100) {
367
-			String s = floatToString(sw.floatValue(), asAPI);
368
-			if (asAPI) {
369
-				sb.append(isHor ? ".shrinkX(" : ".shrinkY(").append(s).append(')');
370
-			} else {
371
-				sb.append(isHor ? ",shrinkx " : ",shrinky ").append(s);
372
-			}
373
-		}
374
-
375
-		String eg = dc.getEndGroup();
376
-		if (eg != null) {
377
-			if (asAPI) {
378
-				sb.append(isHor ? ".endGroupX(\"" : ".endGroupY(\"").append(eg).append("\")");
379
-			} else {
380
-				sb.append(isHor ? ",endgroupx " : ",endgroupy ").append(eg);
381
-			}
382
-		}
383
-
384
-		String sg = dc.getSizeGroup();
385
-		if (sg != null) {
386
-			if (asAPI) {
387
-				sb.append(isHor ? ".sizeGroupX(\"" : ".sizeGroupY(\"").append(sg).append("\")");
388
-			} else {
389
-				sb.append(isHor ? ",sizegroupx " : ",sizegroupy ").append(sg);
390
-			}
391
-		}
392
-
393
-		appendBoundSize(dc.getSize(), sb, isHor, asAPI);
394
-
395
-		UnitValue al = dc.getAlign();
396
-		if (al != null) {
397
-			if (asAPI) {
398
-				sb.append(isHor ? ".alignX(\"" : ".alignY(\"").append(getUV(al)).append("\")");
399
-			} else {
400
-				sb.append(isHor ? ",alignx " : ",aligny ").append(getUV(al));
401
-			}
402
-		}
403
-
404
-		BoundSize gapBef = dc.getGapBefore();
405
-		BoundSize gapAft= dc.getGapAfter();
406
-		if (gapBef != null || gapAft != null) {
407
-			if (asAPI) {
408
-				sb.append(isHor ? ".gapX(\"" : ".gapY(\"").append(getBS(gapBef)).append("\", \"").append(getBS(gapAft)).append("\")");
409
-			} else {
410
-				sb.append(isHor ? ",gapx " : ",gapy ").append(getBS(gapBef)).append(' ').append(getBS(gapAft));
411
-			}
412
-		}
413
-	}
414
-
415
-	private static void appendBoundSize(BoundSize size, StringBuffer sb, boolean isHor, boolean asAPI)
416
-	{
417
-		if (size.isUnset() == false) {
418
-			if (size.getPreferred() == null) {
419
-				if (size.getMin() == null) {
420
-					if (asAPI) {
421
-						sb.append(isHor ? ".maxWidth(\"" : ".maxHeight(\"").append(getUV(size.getMax())).append("\")");
422
-					} else {
423
-						sb.append(isHor ? ",wmax " : ",hmax ").append(getUV(size.getMax()));
424
-					}
425
-
426
-				} else if (size.getMax() == null) {
427
-					if (asAPI) {
428
-						sb.append(isHor ? ".minWidth(\"" : ".minHeight(\"").append(getUV(size.getMin())).append("\")");
429
-					} else {
430
-						sb.append(isHor ? ",wmin " : ",hmin ").append(getUV(size.getMin()));
431
-					}
432
-				} else { // None are null
433
-					if (asAPI) {
434
-						sb.append(isHor ? ".width(\"" : ".height(\"").append(getUV(size.getMin())).append("::").append(getUV(size.getMax())).append("\")");
435
-					} else {
436
-						sb.append(isHor ? ",width " : ",height ").append(getUV(size.getMin())).append("::").append(getUV(size.getMax()));
437
-					}
438
-				}
439
-			} else {
440
-				if (asAPI) {
441
-					sb.append(isHor ? ".width(\"" : ".height(\":").append(getBS(size)).append("\")");
442
-				} else {
443
-					sb.append(isHor ? ",width " : ",height :").append(getBS(size));
444
-				}
445
-			}
446
-		}
447
-	}
448
-
449
-	/** Returns the a constraint string that can be re-parsed to be the exact same LayoutConstraint.
450
-	 * @param cc The component constraint to return as a constraint string.
451
-	 * @param asAPI If the returned string should be of API type (e.g. .flowX().gap("rel").align("right")) or
452
-	 * as a String type (e.g. "flowx, gap rel, right").
453
-	 * @return A String. Never <code>null</code>.
454
-	 */
455
-	public static final String getConstraintString(CC cc, boolean asAPI)
456
-	{
457
-		StringBuffer sb = new StringBuffer(16);
458
-
459
-		if (cc.isNewline())
460
-			sb.append(asAPI ? ".newline()" : ",newline");
461
-
462
-		if (cc.isExternal())
463
-			sb.append(asAPI ? ".external()" : ",external");
464
-
465
-		Boolean flowX = cc.getFlowX();
466
-		if (flowX != null) {
467
-			if (asAPI) {
468
-				sb.append(flowX.booleanValue() ? ".flowX()" : ".flowY()");
469
-			} else {
470
-				sb.append(flowX.booleanValue() ? ",flowx" : ",flowy");
471
-			}
472
-		}
473
-
474
-		UnitValue[] pad = cc.getPadding();
475
-		if (pad != null) {
476
-			sb.append(asAPI ? ".pad(\"" : ",pad ");
477
-			for (int i = 0; i < pad.length; i++)
478
-				sb.append(getUV(pad[i])).append(i < pad.length - 1 ? " " : "");
479
-			if (asAPI)
480
-				sb.append("\")");
481
-		}
482
-
483
-		UnitValue[] pos = cc.getPos();
484
-		if (pos != null) {
485
-			if (cc.isBoundsInGrid()) {
486
-				for (int i = 0; i < 4; i++) {
487
-					if (pos[i] != null) {
488
-						if (asAPI) {
489
-							sb.append('.').append(X_Y_STRINGS[i]).append("(\"").append(getUV(pos[i])).append("\")");
490
-						} else {
491
-							sb.append(',').append(X_Y_STRINGS[i]).append(getUV(pos[i]));
492
-						}
493
-					}
494
-				}
495
-			} else {
496
-				sb.append(asAPI ? ".pos(\"" : ",pos ");
497
-				int iSz = (pos[2] != null || pos[3] != null) ? 4 : 2;  // "pos x y" vs "pos x1 y1 x2 y2".
498
-				for (int i = 0; i < iSz; i++)
499
-					sb.append(getUV(pos[i])).append(i < iSz - 1 ? " " : "");
500
-
501
-				if (asAPI)
502
-					sb.append("\")");
503
-			}
504
-		}
505
-
506
-		String id = cc.getId();
507
-		if (id != null) {
508
-			if (asAPI) {
509
-				sb.append(".id(\"").append(id).append("\")");
510
-			} else {
511
-				sb.append(",id ").append(id);
512
-			}
513
-		}
514
-
515
-		String tag = cc.getTag();
516
-		if (tag != null) {
517
-			if (asAPI) {
518
-				sb.append(".tag(\"").append(tag).append("\")");
519
-			} else {
520
-				sb.append(",tag ").append(tag);
521
-			}
522
-		}
523
-
524
-		int hideMode = cc.getHideMode();
525
-		if (hideMode >= 0) {
526
-			if (asAPI) {
527
-				sb.append(".hideMode(").append(hideMode).append(')');
528
-			} else {
529
-				sb.append(",hideMode ").append(hideMode);
530
-			}
531
-		}
532
-
533
-		int skip = cc.getSkip();
534
-		if (skip > 0) {
535
-			if (asAPI) {
536
-				sb.append(".skip(").append(skip).append(')');
537
-			} else {
538
-				sb.append(",skip ").append(skip);
539
-			}
540
-		}
541
-
542
-		int split = cc.getSplit();
543
-		if (split > 1) {
544
-			String s = split == LayoutUtil.INF ? "" : String.valueOf(split);
545
-			if (asAPI) {
546
-				sb.append(".split(").append(s).append(')');
547
-			} else {
548
-				sb.append(",split ").append(s);
549
-			}
550
-		}
551
-
552
-		int cx = cc.getCellX();
553
-		int cy = cc.getCellY();
554
-		int spanX = cc.getSpanX();
555
-		int spanY = cc.getSpanY();
556
-		if (cx >= 0 && cy >= 0) {
557
-			if (asAPI) {
558
-				sb.append(".cell(").append(cx).append(", ").append(cy);
559
-				if (spanX > 1 || spanY > 1)
560
-					sb.append(", ").append(spanX).append(", ").append(spanY);
561
-				sb.append(')');
562
-			} else {
563
-				sb.append(",cell ").append(cx).append(' ').append(cy);
564
-				if (spanX > 1 || spanY > 1)
565
-					sb.append(' ').append(spanX).append(' ').append(spanY);
566
-			}
567
-		} else if (spanX > 1 || spanY > 1) {
568
-			if (spanX > 1 && spanY > 1) {
569
-				sb.append(asAPI ? ".span(" : ",span ").append(spanX).append(asAPI ? ", " : " ").append(spanY);
570
-			} else if (spanX > 1) {
571
-				sb.append(asAPI ? ".spanX(" : ",spanx ").append(spanX == LayoutUtil.INF ? "" : (String.valueOf(spanX)));
572
-			} else if (spanY > 1) {
573
-				sb.append(asAPI ? ".spanY(" : ",spany ").append(spanY == LayoutUtil.INF ? "" : (String.valueOf(spanY)));
574
-			}
575
-			if (asAPI)
576
-				sb.append(')');
577
-		}
578
-
579
-		Float pushX = cc.getPushX();
580
-		Float pushY = cc.getPushY();
581
-		if (pushX != null || pushY != null) {
582
-			if (pushX != null && pushY != null) {
583
-				sb.append(asAPI ? ".push(" : ",push ");
584
-				if (pushX != 100.0 || pushY != 100.0)
585
-					sb.append(pushX).append(asAPI ? ", " : " ").append(pushY);
586
-			} else if (pushX != null) {
587
-				sb.append(asAPI ? ".pushX(" : ",pushx ").append(pushX == 100 ? "" : (String.valueOf(pushX)));
588
-			} else if (pushY != null) {
589
-				sb.append(asAPI ? ".pushY(" : ",pushy ").append(pushY == 100 ? "" : (String.valueOf(pushY)));
590
-			}
591
-			if (asAPI)
592
-				sb.append(')');
593
-		}
594
-
595
-		int dock = cc.getDockSide();
596
-		if (dock >= 0) {
597
-			String ds = CC.DOCK_SIDES[dock];
598
-			if (asAPI) {
599
-				sb.append(".dock").append(Character.toUpperCase(ds.charAt(0))).append(ds.substring(1)).append("()");
600
-			} else {
601
-				sb.append(",").append(ds);
602
-			}
603
-		}
604
-
605
-		boolean noGrowAdd = cc.getHorizontal().getGrow() != null && cc.getHorizontal().getGrow().intValue() == 100 &&
606
-		                    cc.getVertical().getGrow() != null && cc.getVertical().getGrow().intValue() == 100;
607
-
608
-		addComponentDimConstraintString(cc.getHorizontal(), sb, asAPI, true, noGrowAdd);
609
-		addComponentDimConstraintString(cc.getVertical(), sb, asAPI, false, noGrowAdd);
610
-		if (noGrowAdd)
611
-			sb.append(asAPI ? ".grow()" : ",grow");   // Combine ".growX().growY()" into ".grow()".
612
-
613
-		if (cc.isWrap())
614
-			sb.append(asAPI ? ".wrap()" : ",wrap");
615
-
616
-		String s = sb.toString();
617
-		return s.length() == 0 || s.charAt(0) != ',' ? s : s.substring(1);
618
-	}
619
-
620
-	/** Returns the a constraint string that can be re-parsed to be the exact same LayoutConstraint.
621
-	 * @param lc The layout constraint to return as a constraint string.
622
-	 * @param asAPI If the returned string should be of API type (e.g. .flowX().gap("rel").align("right")) or
623
-	 * as a String type (e.g. "flowx, gap rel, right").
624
-	 * @return A String. Never <code>null</code>.
625
-	 */
626
-	public static final String getConstraintString(LC lc, boolean asAPI)
627
-	{
628
-		StringBuffer sb = new StringBuffer(16);
629
-
630
-		if (lc.isFlowX() == false)
631
-			sb.append(asAPI ? ".flowY()" : ",flowy");
632
-
633
-		boolean fillX = lc.isFillX();
634
-		boolean fillY = lc.isFillY();
635
-		if (fillX || fillY) {
636
-			if (fillX == fillY) {
637
-				sb.append(asAPI ? ".fill()" : ",fill");
638
-			} else {
639
-				sb.append(asAPI ? (fillX ? ".fillX()" : ".fillY()") : (fillX ? ",fillx" : ",filly"));
640
-			}
641
-		}
642
-
643
-		Boolean leftToRight = lc.getLeftToRight();
644
-		if (leftToRight != null) {
645
-			if (asAPI) {
646
-				sb.append(".leftToRight(").append(leftToRight).append(')');
647
-			} else {
648
-				sb.append(leftToRight.booleanValue() ? ",ltr" : ",rtl");
649
-			}
650
-		}
651
-
652
-		if (!lc.getPackWidth().isUnset() || !lc.getPackHeight().isUnset()) {
653
-			if (asAPI) {
654
-				String w = getBS(lc.getPackWidth());
655
-				String h = getBS(lc.getPackHeight());
656
-				sb.append(".pack(");
657
-				if (w.equals("pref") && h.equals("pref")) {
658
-					sb.append(')');
659
-				} else {
660
-					sb.append('\"').append(w).append("\", \"").append(h).append("\")");
661
-				}
662
-			} else {
663
-				sb.append(",pack");
664
-				String size = getBS(lc.getPackWidth()) + " " + getBS(lc.getPackHeight());
665
-				if (size.equals("pref pref") == false)
666
-					sb.append(' ').append(size);
667
-			}
668
-		}
669
-
670
-		if (lc.getPackWidthAlign() != 0.5f || lc.getPackHeightAlign() != 1f) {
671
-			if (asAPI) {
672
-				sb.append(".packAlign(").append(floatToString(lc.getPackWidthAlign(), asAPI)).append(", ").append(floatToString(lc.getPackHeightAlign(), asAPI)).append(')');
673
-			} else {
674
-				sb.append(",packalign ").append(floatToString(lc.getPackWidthAlign(), asAPI)).append(' ').append(floatToString(lc.getPackHeightAlign(), asAPI));
675
-			}
676
-		}
677
-
678
-		if (lc.isTopToBottom() == false)
679
-			sb.append(asAPI ? ".bottomToTop()" : ",btt");
680
-
681
-		UnitValue[] insets = lc.getInsets();
682
-		if (insets != null) {
683
-			String cs = LayoutUtil.getCCString(insets);
684
-			if (cs != null) {
685
-				if (asAPI) {
686
-					sb.append(".insets(\"").append(cs).append("\")");
687
-				} else {
688
-					sb.append(",insets ").append(cs);
689
-				}
690
-			} else {
691
-				sb.append(asAPI ? ".insets(\"" : ",insets ");
692
-				for (int i = 0; i < insets.length; i++)
693
-					sb.append(getUV(insets[i])).append(i < insets.length - 1 ? " " : "");
694
-				if (asAPI)
695
-					sb.append("\")");
696
-			}
697
-		}
698
-
699
-		if (lc.isNoGrid())
700
-			sb.append(asAPI ? ".noGrid()" : ",nogrid");
701
-
702
-		if (lc.isVisualPadding() == false)
703
-			sb.append(asAPI ? ".noVisualPadding()" : ",novisualpadding");
704
-
705
-		int hideMode = lc.getHideMode();
706
-		if (hideMode > 0) {
707
-			if (asAPI) {
708
-				sb.append(".hideMode(").append(hideMode).append(')');
709
-			} else {
710
-				sb.append(",hideMode ").append(hideMode);
711
-			}
712
-		}
713
-
714
-		appendBoundSize(lc.getWidth(), sb, true, asAPI);
715
-		appendBoundSize(lc.getHeight(), sb, false, asAPI);
716
-
717
-		UnitValue alignX = lc.getAlignX();
718
-		UnitValue alignY = lc.getAlignY();
719
-		if (alignX != null || alignY != null) {
720
-			if (alignX != null && alignY != null) {
721
-				sb.append(asAPI ? ".align(\"" : ",align ").append(getUV(alignX)).append(' ').append(getUV(alignY));
722
-			} else if (alignX != null) {
723
-				sb.append(asAPI ? ".alignX(\"" : ",alignx ").append(getUV(alignX));
724
-			} else if (alignY != null) {
725
-				sb.append(asAPI ? ".alignY(\"" : ",aligny ").append(getUV(alignY));
726
-			}
727
-			if (asAPI)
728
-				sb.append("\")");
729
-		}
730
-
731
-		BoundSize gridGapX = lc.getGridGapX();
732
-		BoundSize gridGapY = lc.getGridGapY();
733
-		if (gridGapX != null || gridGapY != null) {
734
-			if (gridGapX != null && gridGapY != null) {
735
-				sb.append(asAPI ? ".gridGap(\"" : ",gap ").append(getBS(gridGapX)).append(' ').append(getBS(gridGapY));
736
-			} else if (gridGapX != null) {
737
-				sb.append(asAPI ? ".gridGapX(\"" : ",gapx ").append(getBS(gridGapX));
738
-			} else if (gridGapY != null) {
739
-				sb.append(asAPI ? ".gridGapY(\"" : ",gapy ").append(getBS(gridGapY));
740
-			}
741
-			if (asAPI)
742
-				sb.append("\")");
743
-		}
744
-
745
-		int wrapAfter = lc.getWrapAfter();
746
-		if (wrapAfter != LayoutUtil.INF) {
747
-			String ws = wrapAfter > 0 ? String.valueOf(wrapAfter) : "";
748
-			if (asAPI) {
749
-				sb.append(".wrap(").append(ws).append(')');
750
-			} else {
751
-				sb.append(",wrap ").append(ws);
752
-			}
753
-		}
754
-
755
-		int debugMillis = lc.getDebugMillis();
756
-		if (debugMillis > 0) {
757
-			if (asAPI) {
758
-				sb.append(".debug(").append(debugMillis).append(')');
759
-			} else {
760
-				sb.append(",debug ").append(debugMillis);
761
-			}
762
-		}
763
-
764
-		String s = sb.toString();
765
-		return s.length() == 0 || s.charAt(0) != ',' ? s : s.substring(1);
766
-	}
767
-
768
-	private static String getUV(UnitValue uv)
769
-	{
770
-		return uv != null ? uv.getConstraintString() : "null";
771
-	}
772
-
773
-	private static String getBS(BoundSize bs)
774
-	{
775
-		return bs != null ? bs.getConstraintString() : "null";
776
-	}
777
-
778
-	/** Converts a <code>float</code> to a string and is removing the ".0" if the float is an integer.
779
-	 * @param f the float.
780
-	 * @return <code>f</code> as a string. Never <code>null</code>.
781
-	 */
782
-	private static final String floatToString(float f, boolean asAPI)
783
-	{
784
-		String valS = String.valueOf(f);
785
-		return valS.endsWith(".0") ? valS.substring(0, valS.length() - 2) : (valS + (asAPI ? "f" : ""));
786
-	}
787
-}

+ 0
- 31
src/net/miginfocom/layout/InCellGapProvider.java Vedi File

@@ -1,31 +0,0 @@
1
-package net.miginfocom.layout;
2
-
3
-/** An interfance to implement if you want to decide the gaps between two types of components within the same cell.
4
- * <p>
5
- * E.g.:
6
- *
7
- * <pre>
8
- * if (adjacentComp == null || adjacentSide == SwingConstants.LEFT || adjacentSide == SwingConstants.TOP)
9
- *	  return null;
10
- *
11
- * boolean isHor = (adjacentSide == SwingConstants.LEFT || adjacentSide == SwingConstants.RIGHT);
12
- *
13
- * if (adjacentComp.getComponetType(false) == ComponentWrapper.TYPE_LABEL && comp.getComponetType(false) == ComponentWrapper.TYPE_TEXT_FIELD)
14
- *    return isHor ? UNRELATED_Y : UNRELATED_Y;
15
- *
16
- * return (adjacentSide == SwingConstants.LEFT || adjacentSide == SwingConstants.RIGHT) ? RELATED_X : RELATED_Y;
17
- * </pre
18
- */
19
-public interface InCellGapProvider
20
-{
21
-	/** Returns the default gap between two components that <b>are in the same cell</b>.
22
-	 * @param comp The component that the gap is for. Never <code>null</code>.
23
-	 * @param adjacentComp The adjacent component if any. May be <code>null</code>.
24
-	 * @param adjacentSide What side the <code>adjacentComp</code> is on. {@link javax.swing.SwingUtilities#TOP} or
25
-	 * {@link javax.swing.SwingUtilities#LEFT} or {@link javax.swing.SwingUtilities#BOTTOM} or {@link javax.swing.SwingUtilities#RIGHT}.
26
-	 * @param tag The tag string that the component might be tagged with in the component constraints. May be <code>null</code>.
27
-	 * @param isLTR If it is left-to-right.
28
-	 * @return The default gap between two components or <code>null</code> if there should be no gap.
29
-	 */
30
-	public abstract BoundSize getDefaultGap(ComponentWrapper comp, ComponentWrapper adjacentComp, int adjacentSide, String tag, boolean isLTR);
31
-}

+ 0
- 1016
src/net/miginfocom/layout/LC.java
File diff soppresso perché troppo grande
Vedi File


+ 0
- 44
src/net/miginfocom/layout/LayoutCallback.java Vedi File

@@ -1,44 +0,0 @@
1
-package net.miginfocom.layout;
2
-
3
-/** A class to extend if you want to provide more control over where a component is placed or the size of it.
4
- * <p>
5
- * Note! Returned arrays from this class will never be altered. This means that caching of arrays in these methods
6
- * is OK.
7
- */
8
-public abstract class LayoutCallback
9
-{
10
-	/** Returns a position similar to the "pos" the component constraint.
11
-	 * @param comp The component wrapper that holds the actual component (JComponent is Swing and Control in SWT).
12
-	 * <b>Should not be altered.</b>
13
-	 * @return The [x, y, x2, y2] as explained in the documentation for "pos". If <code>null</code>
14
-	 * is returned nothing is done and this is the default.
15
-	 * @see UnitValue
16
-	 * @see net.miginfocom.layout.ConstraintParser#parseUnitValue(String, boolean)
17
-	 */
18
-	public UnitValue[] getPosition(ComponentWrapper comp)
19
-	{
20
-		return null;
21
-	}
22
-
23
-	/** Returns a size similar to the "width" and "height" in the component constraint.
24
-	 * @param comp The component wrapper that holds the actual component (JComponent is Swing and Control in SWT).
25
-	 * <b>Should not be altered.</b>
26
-	 * @return The [width, height] as explained in the documentation for "width" and "height". If <code>null</code>
27
-	 * is returned nothing is done and this is the default.
28
-	 * @see net.miginfocom.layout.BoundSize
29
-	 * @see net.miginfocom.layout.ConstraintParser#parseBoundSize(String, boolean, boolean)
30
-	 */
31
-	public BoundSize[] getSize(ComponentWrapper comp)
32
-	{
33
-		return null;
34
-	}
35
-
36
-	/** A last minute change of the bounds. The bound for the layout cycle has been set and you can correct there
37
-	 * after any set of rules you like.
38
-	 * @param comp The component wrapper that holds the actual component (JComponent is Swing and Control in SWT).
39
-	 * <b>Should not be altered.</b>
40
-	 */
41
-	public void correctBounds(ComponentWrapper comp)
42
-	{
43
-	}
44
-}

+ 0
- 528
src/net/miginfocom/layout/LayoutUtil.java Vedi File

@@ -1,528 +0,0 @@
1
-package net.miginfocom.layout;
2
-
3
-import java.beans.*;
4
-import java.io.*;
5
-import java.util.IdentityHashMap;
6
-import java.util.TreeSet;
7
-import java.util.WeakHashMap;
8
-/*
9
- * License (BSD):
10
- * ==============
11
- *
12
- * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
13
- * All rights reserved.
14
- *
15
- * Redistribution and use in source and binary forms, with or without modification,
16
- * are permitted provided that the following conditions are met:
17
- * Redistributions of source code must retain the above copyright notice, this list
18
- * of conditions and the following disclaimer.
19
- * Redistributions in binary form must reproduce the above copyright notice, this
20
- * list of conditions and the following disclaimer in the documentation and/or other
21
- * materials provided with the distribution.
22
- * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
23
- * used to endorse or promote products derived from this software without specific
24
- * prior written permission.
25
- *
26
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
27
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29
- * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
30
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
32
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
33
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
35
- * OF SUCH DAMAGE.
36
- *
37
- * @version 1.0
38
- * @author Mikael Grev, MiG InfoCom AB
39
- *         Date: 2006-sep-08
40
- */
41
-
42
-/** A utility class that has only static helper methods.
43
- */
44
-public final class LayoutUtil
45
-{
46
-	/** A substitute value for aa really large value. Integer.MAX_VALUE is not used since that means a lot of defensive code
47
-	 * for potential overflow must exist in many places. This value is large enough for being unresonable yet it is hard to
48
-	 * overflow.
49
-	 */
50
-	static final int INF = (Integer.MAX_VALUE >> 10) - 100; // To reduce likelyhood of overflow errors when calculating.
51
-
52
-	/** Tag int for a value that in considered "not set". Used as "null" element in int arays.
53
-	 */
54
-	static final int NOT_SET = Integer.MIN_VALUE + 12346;   // Magic value...
55
-
56
-	// Index for the different sizes
57
-	public static final int MIN = 0;
58
-	public static final int PREF = 1;
59
-	public static final int MAX = 2;
60
-
61
-	private static WeakHashMap<Object, String> CR_MAP = null;
62
-	private static WeakHashMap<Object, Boolean> DT_MAP = null;      // The Containers that have design time. Value not used.
63
-	private static int eSz = 15;
64
-
65
-	private LayoutUtil()
66
-	{
67
-	}
68
-
69
-	/** Returns the current version of MiG Layout.
70
-	 * @return The current version of MiG Layout.
71
-	 */
72
-	public static String getVersion()
73
-	{
74
-		return "3.6.2";
75
-	}
76
-
77
-	/** Sets if design time is turned on for a Container in {@link ContainerWrapper}.
78
-	 * @param cw The container to set design time for. <code>null</code> is legal and can be used as
79
-	 * a key to turn on/off design time "in general". Note though that design time "in general" is
80
-	 * always on as long as there is at least one ContainerWrapper with design time.
81
-	 * <p>
82
-	 * <strong>If this method has not ever been called it will default to what
83
-	 * <code>Beans.isDesignTime()</code> returns.</strong> This means that if you call
84
-	 * this method you indicate that you will take responsibility for the design time value.
85
-	 * @param b <code>true</code> means design time on.
86
-	 */
87
-	public static void setDesignTime(ContainerWrapper cw, boolean b)
88
-	{
89
-		if (DT_MAP == null)
90
-			DT_MAP = new WeakHashMap<Object, Boolean>();
91
-
92
-		DT_MAP.put((cw != null ? cw.getComponent() : null), new Boolean(b));
93
-	}
94
-
95
-	/** Returns if design time is turned on for a Container in {@link ContainerWrapper}.
96
-	 * @param cw The container to set design time for. <code>null</code> is legal will return <code>true</code>
97
-	 * if there is at least one <code>ContainerWrapper</code> (or <code>null</code>) that have design time
98
-	 * turned on.
99
-	 * @return If design time is set for <code>cw</code>.
100
-	 */
101
-	public static boolean isDesignTime(ContainerWrapper cw)
102
-	{
103
-		if (DT_MAP == null)
104
-			return Beans.isDesignTime();
105
-
106
-		if (cw != null && DT_MAP.containsKey(cw.getComponent()) == false)
107
-			cw = null;
108
-
109
-		Boolean b = DT_MAP.get(cw != null ? cw.getComponent() : null);
110
-		return b != null && b.booleanValue();
111
-	}
112
-
113
-	/** The size of an empty row or columns in a grid during design time.
114
-	 * @return The number of pixels. Default is 15.
115
-	 */
116
-	public static int getDesignTimeEmptySize()
117
-	{
118
-		return eSz;
119
-	}
120
-
121
-	/** The size of an empty row or columns in a grid during design time.
122
-	 * @param pixels The number of pixels. Default is 15.
123
-	 */
124
-	public static void setDesignTimeEmptySize(int pixels)
125
-	{
126
-		eSz = pixels;
127
-	}
128
-
129
-	/** Associates <code>con</code> with the creation string <code>s</code>. The <code>con</code> object should
130
-	 * probably have an equals method that compares identities or <code>con</code> objects that .equals() will only
131
-	 * be able to have <b>one</b> creation string.
132
-	 * <p>
133
-	 * If {@link LayoutUtil#isDesignTime(ContainerWrapper)} returns <code>false</code> the method does nothing.
134
-	 * @param con The object. if <code>null</code> the method does nothing.
135
-	 * @param s The creation string. if <code>null</code> the method does nothing.
136
-	 */
137
-	static void putCCString(Object con, String s)
138
-	{
139
-		if (s != null && con != null && isDesignTime(null)) {
140
-			if (CR_MAP == null)
141
-				CR_MAP = new WeakHashMap<Object, String>(64);
142
-
143
-			CR_MAP.put(con, s);
144
-		}
145
-	}
146
-
147
-	/** Sets/add the persistence delagates to be used for a class.
148
-	 * @param c The class to set the registered deligate for.
149
-	 * @param del The new deligate or <code>null</code> to erase to old one.
150
-	 */
151
-	static synchronized void setDelegate(Class c, PersistenceDelegate del)
152
-	{
153
-		try {
154
-			Introspector.getBeanInfo(c).getBeanDescriptor().setValue("persistenceDelegate", del);
155
-		} catch (Exception e1) {
156
-		}
157
-	}
158
-
159
-	/** Returns strings set with {@link #putCCString(Object, String)} or <code>null</code> if nothing is associated or
160
-	 * {@link LayoutUtil#isDesignTime(ContainerWrapper)} returns <code>false</code>.
161
-	 * @param con The constraitn object.
162
-	 * @return The creation string or <code>null</code> if nothing is registered with the <code>con</code> object.
163
-	 */
164
-	static String getCCString(Object con)
165
-	{
166
-		return CR_MAP != null ? CR_MAP.get(con) : null;
167
-	}
168
-
169
-	static void throwCC()
170
-	{
171
-		throw new IllegalStateException("setStoreConstraintData(true) must be set for strings to be saved.");
172
-	}
173
-
174
-	/** Takes a number on min/preferred/max sizes and resize constraints and returns the calculated sizes which sum should add up to <code>bounds</code>. Whether the sum
175
-	 * will actually equal <code>bounds</code> is dependent om the pref/max sizes and resise constraints.
176
-	 * @param sizes [ix],[MIN][PREF][MAX]. Grid.CompWrap.NOT_SET will be treated as N/A or 0. A "[MIN][PREF][MAX]" array with null elements will be interpreted as very flexible (no bounds)
177
-	 * but if the array itself is null it will not get any size.
178
-	 * @param resConstr Elements can be <code>null</code> and the whole array can be <code>null</code>. <code>null</code> means that the size will not be flexible at all.
179
-	 * Can have length less than <code>sizes</code> in which case the last element should be used for the elements missing.
180
-	 * @param defGrowWeights If there is no grow weight for a resConstr the correspinding value of this array is used.
181
-	 * These forced resConstr will be grown last though and only if needed to fill to the bounds.
182
-	 * @param startSizeType The initial size to use. E.g. {@link net.miginfocom.layout.LayoutUtil#MIN}.
183
-	 * @param bounds To use for relative sizes.
184
-	 * @return The sizes. Array length will match <code>sizes</code>.
185
-	 */
186
-	static int[] calculateSerial(int[][] sizes, ResizeConstraint[] resConstr, Float[] defGrowWeights, int startSizeType, int bounds)
187
-	{
188
-		float[] lengths = new float[sizes.length];	// heights/widths that are set
189
-		float usedLength = 0.0f;
190
-
191
-		// Give all preferred size to start with
192
-		for (int i = 0; i < sizes.length; i++) {
193
-			if (sizes[i] != null) {
194
-				float len = sizes[i][startSizeType] != NOT_SET ? sizes[i][startSizeType] : 0;
195
-				int newSizeBounded = getBrokenBoundary(len, sizes[i][MIN], sizes[i][MAX]);
196
-				if (newSizeBounded != NOT_SET)
197
-					len = newSizeBounded;
198
-
199
-				usedLength += len;
200
-				lengths[i] = len;
201
-			}
202
-		}
203
-
204
-		int useLengthI = Math.round(usedLength);
205
-		if (useLengthI != bounds && resConstr != null) {
206
-			boolean isGrow = useLengthI < bounds;
207
-
208
-			// Create a Set with the available priorities
209
-			TreeSet<Integer> prioList = new TreeSet<Integer>();
210
-			for (int i = 0; i < sizes.length; i++) {
211
-				ResizeConstraint resC = (ResizeConstraint) getIndexSafe(resConstr, i);
212
-				if (resC != null)
213
-					prioList.add(new Integer(isGrow ? resC.growPrio : resC.shrinkPrio));
214
-			}
215
-			Integer[] prioIntegers = prioList.toArray(new Integer[prioList.size()]);
216
-
217
-			for (int force = 0; force <= ((isGrow && defGrowWeights != null) ? 1 : 0); force++) {    // Run twice if defGrow and the need for growing.
218
-				for (int pr = prioIntegers.length - 1; pr >= 0; pr--) {
219
-					int curPrio = prioIntegers[pr].intValue();
220
-
221
-					float totWeight = 0f;
222
-					Float[] resizeWeight = new Float[sizes.length];
223
-					for (int i = 0; i < sizes.length; i++) {
224
-						if (sizes[i] == null)   // if no min/pref/max size at all do not grow or shrink.
225
-							continue;
226
-
227
-						ResizeConstraint resC = (ResizeConstraint) getIndexSafe(resConstr, i);
228
-						if (resC != null) {
229
-							int prio = isGrow ? resC.growPrio : resC.shrinkPrio;
230
-
231
-							if (curPrio == prio) {
232
-								if (isGrow) {
233
-									resizeWeight[i] = (force == 0 || resC.grow != null) ? resC.grow : (defGrowWeights[i < defGrowWeights.length ? i : defGrowWeights.length - 1]);
234
-								} else {
235
-									resizeWeight[i] = resC.shrink;
236
-								}
237
-								if (resizeWeight[i] != null)
238
-									totWeight += resizeWeight[i].floatValue();
239
-							}
240
-						}
241
-					}
242
-
243
-					if (totWeight > 0f) {
244
-						boolean hit;
245
-						do {
246
-							float toChange = bounds - usedLength;
247
-							hit = false;
248
-							float changedWeight = 0f;
249
-							for (int i = 0; i < sizes.length && totWeight > 0.0001f; i++) {
250
-
251
-								Float weight = resizeWeight[i];
252
-								if (weight != null) {
253
-									float sizeDelta = toChange * weight.floatValue() / totWeight;
254
-									float newSize = lengths[i] + sizeDelta;
255
-
256
-									if (sizes[i] != null) {
257
-										int newSizeBounded = getBrokenBoundary(newSize, sizes[i][MIN], sizes[i][MAX]);
258
-										if (newSizeBounded != NOT_SET) {
259
-											resizeWeight[i] = null;
260
-											hit = true;
261
-											changedWeight += weight.floatValue();
262
-											newSize = newSizeBounded;
263
-											sizeDelta = newSize - lengths[i];
264
-										}
265
-									}
266
-
267
-									lengths[i] = newSize;
268
-									usedLength += sizeDelta;
269
-								}
270
-							}
271
-							totWeight -= changedWeight;
272
-						} while (hit);
273
-					}
274
-				}
275
-			}
276
-		}
277
-		return roundSizes(lengths);
278
-	}
279
-
280
-	static Object getIndexSafe(Object[] arr, int ix)
281
-	{
282
-		return arr != null ? arr[ix < arr.length ? ix : arr.length - 1] : null;
283
-	}
284
-
285
-	/** Returns the broken boundary if <code>sz</code> is outside the boundaries <code>lower</code> or <code>upper</code>. If both boundaries
286
-	 * are broken, the lower one is returned. If <code>sz</code> is &lt; 0 then <code>new Float(0f)</code> is returned so that no sizes can be
287
-	 * negative.
288
-	 * @param sz The size to check
289
-	 * @param lower The lower boundary (or <code>null</code> fo no boundary).
290
-	 * @param upper The upper boundary (or <code>null</code> fo no boundary).
291
-	 * @return The broken boundary or <code>null</code> if no boundary was broken.
292
-	 */
293
-	private static int getBrokenBoundary(float sz, int lower, int upper)
294
-	{
295
-		if (lower != NOT_SET) {
296
-			if (sz < lower)
297
-				return new Integer(lower);
298
-		} else if (sz < 0f) {
299
-			return new Integer(0);
300
-		}
301
-
302
-		if (upper != NOT_SET && sz > upper)
303
-			return new Integer(upper);
304
-
305
-		return NOT_SET;
306
-	}
307
-
308
-
309
-	static int sum(int[] terms, int start, int len)
310
-	{
311
-		int s = 0;
312
-		for (int i = start, iSz = start + len; i < iSz; i++)
313
-			s += terms[i];
314
-		return s;
315
-	}
316
-
317
-	static int sum(int[] terms)
318
-	{
319
-		return sum(terms, 0, terms.length);
320
-	}
321
-
322
-	public static int getSizeSafe(int[] sizes, int sizeType)
323
-	{
324
-		if (sizes == null || sizes[sizeType] == NOT_SET)
325
-			return sizeType == MAX ? LayoutUtil.INF : 0;
326
-		return sizes[sizeType];
327
-	}
328
-
329
-	static BoundSize derive(BoundSize bs, UnitValue min, UnitValue pref, UnitValue max)
330
-	{
331
-		if (bs == null || bs.isUnset())
332
-			return new BoundSize(min, pref, max, null);
333
-
334
-		return new BoundSize(
335
-				min != null ? min : bs.getMin(),
336
-				pref != null ? pref : bs.getPreferred(),
337
-				max != null ? max : bs.getMax(),
338
-				bs.getGapPush(),
339
-				null);
340
-	}
341
-
342
-	/** Returns if left-to-right orientation is used. If not set explicitly in the layout constraints the Locale
343
-	 * of the <code>parent</code> is used.
344
-	 * @param lc The constraint if there is one. Can be <code>null</code>.
345
-	 * @param container The parent that may be used to get the left-to-right if ffc does not specify this.
346
-	 * @return If left-to-right orientation is currently used.
347
-	 */
348
-	public final static boolean isLeftToRight(LC lc, ContainerWrapper container)
349
-	{
350
-		if (lc != null && lc.getLeftToRight() != null)
351
-			return lc.getLeftToRight().booleanValue();
352
-
353
-		return container == null || container.isLeftToRight();
354
-	}
355
-
356
-	/** Round a number of float sizes into int sizes so that the total length match up
357
-	 * @param sizes The sizes to round
358
-	 * @return An array of equal length as <code>sizes</code>.
359
-	 */
360
-	static int[] roundSizes(float[] sizes)
361
-	{
362
-		int[] retInts = new int[sizes.length];
363
-		float posD = 0;
364
-
365
-		for (int i = 0; i < retInts.length; i++) {
366
-			int posI = (int) (posD + 0.5f);
367
-
368
-			posD += sizes[i];
369
-
370
-			retInts[i] = (int) (posD + 0.5f) - posI;
371
-		}
372
-
373
-		return retInts;
374
-	}
375
-
376
-	/** Safe equals. null == null, but null never equals anything else.
377
-	 * @param o1 The first object. May be <code>null</code>.
378
-	 * @param o2 The second object. May be <code>null</code>.
379
-	 * @return Returns <code>true</code> if <code>o1</code> and <code>o2</code> are equal (using .equals()) or both are <code>null</code>.
380
-	 */
381
-	static final boolean equals(Object o1, Object o2)
382
-	{
383
-		return o1 == o2 || (o1 != null && o2 != null && o1.equals(o2));
384
-	}
385
-
386
-//	static int getBaselineCorrect(Component comp)
387
-//	{
388
-//		Dimension pSize = comp.getPreferredSize();
389
-//		int baseline = comp.getBaseline(pSize.width, pSize.height);
390
-//		int nextBaseline = comp.getBaseline(pSize.width, pSize.height + 1);
391
-//
392
-//		// Amount to add to height when calculating where baseline
393
-//		// lands for a particular height:
394
-//		int padding = 0;
395
-//
396
-//		// Where the baseline is relative to the mid point
397
-//		int baselineOffset = baseline - pSize.height / 2;
398
-//		if (pSize.height % 2 == 0 && baseline != nextBaseline) {
399
-//			padding = 1;
400
-//		} else if (pSize.height % 2 == 1 && baseline == nextBaseline) {
401
-//			baselineOffset--;
402
-//			padding = 1;
403
-//		}
404
-//
405
-//		// The following calculates where the baseline lands for
406
-//		// the height z:
407
-//		return (pSize.height + padding) / 2 + baselineOffset;
408
-//	}
409
-
410
-
411
-	/** Returns the inset for the side.
412
-	 * @param side top == 0, left == 1, bottom = 2, right = 3.
413
-	 * @param getDefault If <code>true</code> the default insets will get retrieved if <code>lc</code> has none set.
414
-	 * @return The inset for the side. Never <code>null</code>.
415
-	 */
416
-	static final UnitValue getInsets(LC lc, int side, boolean getDefault)
417
-	{
418
-		UnitValue[] i = lc.getInsets();
419
-		return (i != null && i[side] != null) ? i[side] : (getDefault ? PlatformDefaults.getPanelInsets(side) : UnitValue.ZERO);
420
-	}
421
-
422
-	/** Writes the objet and CLOSES the stream. Uses the persistence delegate registered in this class.
423
-	 * @param os The stream to write to. Will be closed.
424
-	 * @param o The object to be serialized.
425
-	 * @param listener The listener to recieve the exeptions if there are any. If <code>null</code> not used.
426
-	 */
427
-	static void writeXMLObject(OutputStream os, Object o, ExceptionListener listener)
428
-	{
429
-		ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
430
-		Thread.currentThread().setContextClassLoader(LayoutUtil.class.getClassLoader());
431
-
432
-		XMLEncoder encoder = new XMLEncoder(os);
433
-
434
-		if (listener != null)
435
-			encoder.setExceptionListener(listener);
436
-
437
-		encoder.writeObject(o);
438
-        encoder.close();    // Must be closed to write.
439
-
440
-		Thread.currentThread().setContextClassLoader(oldClassLoader);
441
-	}
442
-
443
-	private static ByteArrayOutputStream writeOutputStream = null;
444
-	/** Writes an object to XML.
445
-	 * @param out The boject out to write to. Will not be closed.
446
-	 * @param o The object to write.
447
-	 */
448
-	public static synchronized void writeAsXML(ObjectOutput out, Object o) throws IOException
449
-	{
450
-		if (writeOutputStream == null)
451
-			writeOutputStream = new ByteArrayOutputStream(16384);
452
-
453
-		writeOutputStream.reset();
454
-
455
-		writeXMLObject(writeOutputStream, o, new ExceptionListener() {
456
-			public void exceptionThrown(Exception e) {
457
-				e.printStackTrace();
458
-			}});
459
-
460
-		byte[] buf = writeOutputStream.toByteArray();
461
-
462
-		out.writeInt(buf.length);
463
-		out.write(buf);
464
-	}
465
-
466
-	private static byte[] readBuf = null;
467
-	/** Reads an object from <code>in</code> using the
468
-	 * @param in The object input to read from.
469
-	 * @return The object. Never <code>null</code>.
470
-	 * @throws IOException If there was a problem saving as XML
471
-	 */
472
-	public static synchronized Object readAsXML(ObjectInput in) throws IOException
473
-	{
474
-		if (readBuf == null)
475
-			readBuf = new byte[16384];
476
-
477
-		Thread cThread = Thread.currentThread();
478
-		ClassLoader oldCL = null;
479
-
480
-		try {
481
-			oldCL = cThread.getContextClassLoader();
482
-			cThread.setContextClassLoader(LayoutUtil.class.getClassLoader());
483
-		} catch(SecurityException e) {
484
-		}
485
-
486
-		Object o = null;
487
-		try {
488
-			int length = in.readInt();
489
-			if (length > readBuf.length)
490
-				readBuf = new byte[length];
491
-
492
-			in.readFully(readBuf, 0, length);
493
-
494
-			o = new XMLDecoder(new ByteArrayInputStream(readBuf, 0, length)).readObject();
495
-
496
-		} catch(EOFException e) {
497
-		}
498
-
499
-		if (oldCL != null)
500
-			cThread.setContextClassLoader(oldCL);
501
-
502
-		return o;
503
-	}
504
-
505
-	private static final IdentityHashMap<Object, Object> SER_MAP = new IdentityHashMap<Object, Object>(2);
506
-
507
-	/** Sets the serialized object and associates it with <code>caller</code>.
508
-	 * @param caller The objec created <code>o</code>
509
-	 * @param o The just serialized object.
510
-	 */
511
-	public static void setSerializedObject(Object caller, Object o)
512
-	{
513
-		synchronized(SER_MAP) {
514
-			SER_MAP.put(caller, o);
515
-		}
516
-	}
517
-
518
-	/** Returns the serialized object that are associated with <code>caller</code>. It also removes it from the list.
519
-	 * @param caller The original creator of the object.
520
-	 * @return The object.
521
-	 */
522
-	public static Object getSerializedObject(Object caller)
523
-	{
524
-		synchronized(SER_MAP) {
525
-			return SER_MAP.remove(caller);
526
-		}
527
-	}
528
-}

+ 0
- 191
src/net/miginfocom/layout/LinkHandler.java Vedi File

@@ -1,191 +0,0 @@
1
-package net.miginfocom.layout;
2
-
3
-import java.lang.ref.WeakReference;
4
-import java.util.ArrayList;
5
-import java.util.HashMap;
6
-/*
7
- * License (BSD):
8
- * ==============
9
- *
10
- * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
11
- * All rights reserved.
12
- *
13
- * Redistribution and use in source and binary forms, with or without modification,
14
- * are permitted provided that the following conditions are met:
15
- * Redistributions of source code must retain the above copyright notice, this list
16
- * of conditions and the following disclaimer.
17
- * Redistributions in binary form must reproduce the above copyright notice, this
18
- * list of conditions and the following disclaimer in the documentation and/or other
19
- * materials provided with the distribution.
20
- * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
21
- * used to endorse or promote products derived from this software without specific
22
- * prior written permission.
23
- *
24
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27
- * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
30
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
33
- * OF SUCH DAMAGE.
34
- *
35
- * @version 1.0
36
- * @author Mikael Grev, MiG InfoCom AB
37
- *         Date: 2006-sep-08
38
- */
39
-
40
-/**
41
- */
42
-public final class LinkHandler
43
-{
44
-	public static final int X = 0;
45
-	public static final int Y = 1;
46
-	public static final int WIDTH = 2;
47
-	public static final int HEIGHT = 3;
48
-	public static final int X2 = 4;
49
-	public static final int Y2 = 5;
50
-
51
-	private static final ArrayList<WeakReference<Object>> LAYOUTS = new ArrayList<WeakReference<Object>>(4);
52
-	private static final ArrayList<HashMap<String, int[]>> VALUES = new ArrayList<HashMap<String, int[]>>(4);
53
-	private static final ArrayList<HashMap<String, int[]>> VALUES_TEMP = new ArrayList<HashMap<String, int[]>>(4);
54
-
55
-	private LinkHandler()
56
-	{
57
-	}
58
-
59
-	public synchronized static Integer getValue(Object layout, String key, int type)
60
-	{
61
-		Integer ret = null;
62
-		boolean cont = true;
63
-
64
-		for (int i = LAYOUTS.size() - 1; i >= 0; i--) {
65
-			Object l = LAYOUTS.get(i).get();
66
-			if (ret == null && l == layout) {
67
-				int[] rect = VALUES_TEMP.get(i).get(key);
68
-				if (cont && rect != null && rect[type] != LayoutUtil.NOT_SET) {
69
-					ret = new Integer(rect[type]);
70
-				} else {
71
-					rect = VALUES.get(i).get(key);
72
-					ret = (rect != null && rect[type] != LayoutUtil.NOT_SET) ? new Integer(rect[type]) : null;
73
-				}
74
-				cont = false;
75
-			}
76
-
77
-			if (l == null) {
78
-				LAYOUTS.remove(i);
79
-				VALUES.remove(i);
80
-				VALUES_TEMP.remove(i);
81
-			}
82
-		}
83
-		return ret;
84
-	}
85
-
86
-	/** Sets a key that can be linked to from any component.
87
-	 * @param layout The MigLayout instance
88
-	 * @param key The key to link to. This is the same as the ID in a component constraint.
89
-	 * @param x x
90
-	 * @param y y
91
-	 * @param width Width
92
-	 * @param height Height
93
-	 * @return If the value was changed
94
-	 */
95
-	public synchronized static boolean setBounds(Object layout, String key, int x, int y, int width, int height)
96
-	{
97
-		return setBounds(layout, key, x, y, width, height, false, false);
98
-	}
99
-
100
-	synchronized static boolean setBounds(Object layout, String key, int x, int y, int width, int height, boolean temporary, boolean incCur)
101
-	{
102
-		for (int i = LAYOUTS.size() - 1; i >= 0; i--) {
103
-			Object l = LAYOUTS.get(i).get();
104
-			if (l == layout) {
105
-				HashMap<String, int[]> map = (temporary ? VALUES_TEMP : VALUES).get(i);
106
-				int[] old = map.get(key);
107
-
108
-				if (old == null || old[X] != x || old[Y] != y || old[WIDTH] != width || old[HEIGHT] != height) {
109
-					if (old == null || incCur == false) {
110
-						map.put(key, new int[] {x, y, width, height, x + width, y + height});
111
-						return true;
112
-					} else {
113
-						boolean changed = false;
114
-
115
-						if (x != LayoutUtil.NOT_SET) {
116
-							if (old[X] == LayoutUtil.NOT_SET || x < old[X]) {
117
-								old[X] = x;
118
-								old[WIDTH] = old[X2] - x;
119
-								changed = true;
120
-							}
121
-
122
-							if (width != LayoutUtil.NOT_SET) {
123
-								int x2 = x + width;
124
-								if (old[X2] == LayoutUtil.NOT_SET || x2 > old[X2]) {
125
-									old[X2] = x2;
126
-									old[WIDTH] = x2 - old[X];
127
-									changed = true;
128
-								}
129
-							}
130
-						}
131
-
132
-						if (y != LayoutUtil.NOT_SET) {
133
-							if (old[Y] == LayoutUtil.NOT_SET || y < old[Y]) {
134
-								old[Y] = y;
135
-								old[HEIGHT] = old[Y2] - y;
136
-								changed = true;
137
-							}
138
-
139
-							if (height != LayoutUtil.NOT_SET) {
140
-								int y2 = y + height;
141
-								if (old[Y2] == LayoutUtil.NOT_SET || y2 > old[Y2]) {
142
-									old[Y2] = y2;
143
-									old[HEIGHT] = y2 - old[Y];
144
-									changed = true;
145
-								}
146
-							}
147
-						}
148
-						return changed;
149
-					}
150
-				}
151
-				return false;
152
-			}
153
-		}
154
-
155
-		LAYOUTS.add(new WeakReference<Object>(layout));
156
-		int[] bounds = new int[] {x, y, width, height, x + width, y + height};
157
-
158
-		HashMap<String, int[]> values = new HashMap<String, int[]>(4);
159
-		if (temporary)
160
-			values.put(key, bounds);
161
-		VALUES_TEMP.add(values);
162
-
163
-		values = new HashMap<String, int[]>(4);
164
-		if (temporary == false)
165
-			values.put(key, bounds);
166
-		VALUES.add(values);
167
-
168
-		return true;
169
-	}
170
-
171
-	public synchronized static boolean clearBounds(Object layout, String key)
172
-	{
173
-		for (int i = LAYOUTS.size() - 1; i >= 0; i--) {
174
-			Object l = LAYOUTS.get(i).get();
175
-			if (l == layout)
176
-				return VALUES.get(i).remove(key) != null;
177
-		}
178
-		return false;
179
-	}
180
-
181
-	synchronized static void clearTemporaryBounds(Object layout)
182
-	{
183
-		for (int i = LAYOUTS.size() - 1; i >= 0; i--) {
184
-			Object l = LAYOUTS.get(i).get();
185
-			if (l == layout) {
186
-				VALUES_TEMP.get(i).clear();
187
-				return;
188
-			}
189
-		}
190
-	}
191
-}

+ 0
- 713
src/net/miginfocom/layout/PlatformDefaults.java Vedi File

@@ -1,713 +0,0 @@
1
-package net.miginfocom.layout;
2
-
3
-import javax.swing.*;
4
-import java.util.HashMap;
5
-/*
6
- * License (BSD):
7
- * ==============
8
- *
9
- * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
10
- * All rights reserved.
11
- *
12
- * Redistribution and use in source and binary forms, with or without modification,
13
- * are permitted provided that the following conditions are met:
14
- * Redistributions of source code must retain the above copyright notice, this list
15
- * of conditions and the following disclaimer.
16
- * Redistributions in binary form must reproduce the above copyright notice, this
17
- * list of conditions and the following disclaimer in the documentation and/or other
18
- * materials provided with the distribution.
19
- * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
20
- * used to endorse or promote products derived from this software without specific
21
- * prior written permission.
22
- *
23
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26
- * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
29
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32
- * OF SUCH DAMAGE.
33
- *
34
- * @version 1.0
35
- * @author Mikael Grev, MiG InfoCom AB
36
- *         Date: 2006-sep-08
37
- */
38
-
39
-/** Currently handles Windows and Mac OS X spacing.
40
- */
41
-public final class PlatformDefaults
42
-{
43
-	private static int DEF_H_UNIT = UnitValue.LPX;
44
-	private static int DEF_V_UNIT = UnitValue.LPY;
45
-
46
-	private static InCellGapProvider GAP_PROVIDER = null;
47
-
48
-	private static volatile int MOD_COUNT = 0;
49
-
50
-	private static final UnitValue LPX4 = new UnitValue(4, UnitValue.LPX, null);
51
-	private static final UnitValue LPX7 = new UnitValue(7, UnitValue.LPX, null);
52
-//	private static final UnitValue LPX8 = new UnitValue(8, UnitValue.LPX, null);
53
-	private static final UnitValue LPX9 = new UnitValue(9, UnitValue.LPX, null);
54
-	private static final UnitValue LPX10 = new UnitValue(10, UnitValue.LPX, null);
55
-	private static final UnitValue LPX11 = new UnitValue(11, UnitValue.LPX, null);
56
-//	private static final UnitValue LPX12 = new UnitValue(12, UnitValue.LPX, null);
57
-	private static final UnitValue LPX14 = new UnitValue(14, UnitValue.LPX, null);
58
-	private static final UnitValue LPX16 = new UnitValue(16, UnitValue.LPX, null);
59
-	private static final UnitValue LPX20 = new UnitValue(20, UnitValue.LPX, null);
60
-
61
-	private static final UnitValue LPY4 = new UnitValue(4, UnitValue.LPY, null);
62
-	private static final UnitValue LPY7 = new UnitValue(7, UnitValue.LPY, null);
63
-//	private static final UnitValue LPY8 = new UnitValue(8, UnitValue.LPY, null);
64
-	private static final UnitValue LPY9 = new UnitValue(9, UnitValue.LPY, null);
65
-	private static final UnitValue LPY10 = new UnitValue(10, UnitValue.LPY, null);
66
-	private static final UnitValue LPY11 = new UnitValue(11, UnitValue.LPY, null);
67
-//	private static final UnitValue LPY12 = new UnitValue(12, UnitValue.LPY, null);
68
-	private static final UnitValue LPY14 = new UnitValue(14, UnitValue.LPY, null);
69
-	private static final UnitValue LPY16 = new UnitValue(16, UnitValue.LPY, null);
70
-	private static final UnitValue LPY20 = new UnitValue(20, UnitValue.LPY, null);
71
-
72
-	public static final int WINDOWS_XP = 0;
73
-	public static final int MAC_OSX = 1;
74
-//	private static final int GNOME = 2;
75
-//	private static final int KDE = 3;
76
-
77
-	private static int CUR_PLAF = WINDOWS_XP;
78
-
79
-	// Used for holding values.
80
-	private final static UnitValue[] PANEL_INS = new UnitValue[4];
81
-	private final static UnitValue[] DIALOG_INS = new UnitValue[4];
82
-
83
-	private static String BUTTON_FORMAT = null;
84
-
85
-	private static final HashMap<String, UnitValue> HOR_DEFS = new HashMap<String, UnitValue>(32);
86
-	private static final HashMap<String, UnitValue> VER_DEFS = new HashMap<String, UnitValue>(32);
87
-	private static BoundSize DEF_VGAP = null, DEF_HGAP = null;
88
-	static BoundSize RELATED_X = null, RELATED_Y = null, UNRELATED_X = null, UNRELATED_Y = null;
89
-	private static UnitValue BUTT_WIDTH = null;
90
-
91
-	private static Float horScale = null, verScale = null;
92
-
93
-	/** I value indicating that the size of the font for the container of the component
94
-	 * will be used as a base for calculating the logical pixel size. This is much as how
95
-	 * Windows calculated DLU (dialog units).
96
-	 * @see net.miginfocom.layout.UnitValue#LPX
97
-	 * @see net.miginfocom.layout.UnitValue#LPY
98
-	 * @see #setLogicalPixelBase(int)
99
-	 */
100
-	public static final int BASE_FONT_SIZE = 100;
101
-
102
-	/** I value indicating that the screen DPI will be used as a base for calculating the
103
-	 * logical pixel size.
104
-	 * <p>
105
-	 * This is the default value.
106
-	 * @see net.miginfocom.layout.UnitValue#LPX
107
-	 * @see net.miginfocom.layout.UnitValue#LPY
108
-	 * @see #setLogicalPixelBase(int)
109
-	 * @see #setVerticalScaleFactor(Float)
110
-	 * @see #setHorizontalScaleFactor(Float)
111
-	 */
112
-	public static final int BASE_SCALE_FACTOR = 101;
113
-
114
-	/** I value indicating that the size of a logical pixel should always be a real pixel
115
-	 * and thus no compensation will be made.
116
-	 * @see net.miginfocom.layout.UnitValue#LPX
117
-	 * @see net.miginfocom.layout.UnitValue#LPY
118
-	 * @see #setLogicalPixelBase(int)
119
-	 */
120
-	public static final int BASE_REAL_PIXEL = 102;
121
-
122
-	private static int LP_BASE = BASE_SCALE_FACTOR;
123
-
124
-	private static int BASE_DPI = 96;
125
-
126
-	private static boolean dra = true;
127
-
128
-	static {
129
-		setPlatform(getCurrentPlatform());
130
-		MOD_COUNT = 0;
131
-	}
132
-
133
-	/** Returns the platform that the JRE is running on currently.
134
-	 * @return The platform that the JRE is running on currently. E.g. {@link #MAC_OSX} or {@link #WINDOWS_XP}.
135
-	 */
136
-	public static int getCurrentPlatform()
137
-	{
138
-		return System.getProperty("os.name").startsWith("Mac OS") ? MAC_OSX : WINDOWS_XP;
139
-	}
140
-
141
-	private PlatformDefaults()
142
-	{
143
-	}
144
-
145
-	/** Set the defaults to the default for the platform
146
-	 * @param plaf The platform. <code>PlatformDefaults.WINDOWS</code> or <code>PlatformDefaults.MAC_OSX</code>
147
-	 */
148
-	public static void setPlatform(int plaf)
149
-	{
150
-		if (plaf < WINDOWS_XP || plaf > MAC_OSX)
151
-			throw new IllegalArgumentException("Unknown platform: " + plaf);
152
-
153
-		CUR_PLAF = plaf;
154
-		if (plaf == WINDOWS_XP) {
155
-			setRelatedGap(LPX4, LPY4);
156
-			setUnrelatedGap(LPX7, LPY9);
157
-			setParagraphGap(LPX14, LPY14);
158
-			setIndentGap(LPX9, LPY9);
159
-			setGridCellGap(LPX4, LPY4);
160
-
161
-			setMinimumButtonWidth(new UnitValue(75, UnitValue.LPX, null));
162
-			setButtonOrder("L_E+U+YNBXOCAH_R");
163
-			setDialogInsets(LPY11, LPX11, LPY11, LPX11);
164
-			setPanelInsets(LPY7, LPX7, LPY7, LPX7);
165
-			BASE_DPI = 96;
166
-		} else {
167
-			setRelatedGap(LPX4, LPY4);
168
-			setUnrelatedGap(LPX7, LPY9);
169
-			setParagraphGap(LPX14, LPY14);
170
-			setIndentGap(LPX10, LPY10);
171
-			setGridCellGap(LPX4, LPY4);
172
-
173
-			setMinimumButtonWidth(new UnitValue(68, UnitValue.LPX, null));
174
-			setButtonOrder("L_HE+U+NYBXCOA_R");
175
-			setDialogInsets(LPY14, LPX20, LPY20, LPX20);
176
-			setPanelInsets(LPY16, LPX16, LPY16, LPX16);
177
-//			setRelatedGap(LPX8, LPY8);
178
-//			setUnrelatedGap(LPX12, LPY12);
179
-//			setParagraphGap(LPX16, LPY16);
180
-//			setIndentGap(LPX10, LPY10);
181
-//			setGridCellGap(LPX8, LPY8);
182
-//
183
-//			setMinimumButtonWidth(new UnitValue(68, UnitValue.LPX, null));
184
-//			setButtonOrder("L_HE+U+NYBXCOA_R");
185
-//			setDialogInsets(LPY14, LPX20, LPY20, LPX20);
186
-//			setPanelInsets(LPY16, LPX16, LPY16, LPX16);
187
-			try {
188
-				BASE_DPI = System.getProperty("java.version").compareTo("1.6") < 0 ? 72 : 96; // Default DPI was 72 prior to JSE 1.6
189
-			} catch (Throwable t) {
190
-				BASE_DPI = 72;
191
-			}
192
-		}
193
-	}
194
-
195
-	/** Returns the current platform
196
-	 * @return <code>PlatformDefaults.WINDOWS</code> or <code>PlatformDefaults.MAC_OSX</code>
197
-	 */
198
-	public static int getPlatform()
199
-	{
200
-		return CUR_PLAF;
201
-	}
202
-
203
-	public static int getDefaultDPI()
204
-	{
205
-		return BASE_DPI;
206
-	}
207
-
208
-	/** The forced scale factor that all screen relative units (e.g. millimeters, inches and logical pixels) will be multiplied
209
-	 * with. If <code>null</code> this will default to a scale that will scale the current screen to the default screen resolution
210
-	 * (72 DPI for Mac and 92 DPI for Windows).
211
-	 * @return The forced scale or <code>null</code> for default scaling.
212
-	 * @see #getHorizontalScaleFactor()
213
-	 * @see ComponentWrapper#getHorizontalScreenDPI()
214
-	 */
215
-	public static Float getHorizontalScaleFactor()
216
-	{
217
-		return horScale;
218
-	}
219
-
220
-	/** The forced scale factor that all screen relative units (e.g. millimeters, inches and logical pixels) will be multiplied
221
-	 * with. If <code>null</code> this will default to a scale that will scale the current screen to the default screen resolution
222
-	 * (72 DPI for Mac and 92 DPI for Windows).
223
-	 * @param f The forced scale or <code>null</code> for default scaling.
224
-	 * @see #getHorizontalScaleFactor()
225
-	 * @see ComponentWrapper#getHorizontalScreenDPI()
226
-	 */
227
-	public static void setHorizontalScaleFactor(Float f)
228
-	{
229
-		if (LayoutUtil.equals(horScale, f) == false) {
230
-			horScale = f;
231
-			MOD_COUNT++;
232
-		}
233
-	}
234
-
235
-	/** The forced scale factor that all screen relative units (e.g. millimeters, inches and logical pixels) will be multiplied
236
-	 * with. If <code>null</code> this will default to a scale that will scale the current screen to the default screen resolution
237
-	 * (72 DPI for Mac and 92 DPI for Windows).
238
-	 * @return The forced scale or <code>null</code> for default scaling.
239
-	 * @see #getHorizontalScaleFactor()
240
-	 * @see ComponentWrapper#getVerticalScreenDPI()
241
-	 */
242
-	public static Float getVerticalScaleFactor()
243
-	{
244
-		return verScale;
245
-	}
246
-
247
-	/** The forced scale factor that all screen relative units (e.g. millimeters, inches and logical pixels) will be multiplied
248
-	 * with. If <code>null</code> this will default to a scale that will scale the current screen to the default screen resolution
249
-	 * (72 DPI for Mac and 92 DPI for Windows).
250
-	 * @param f The forced scale or <code>null</code> for default scaling.
251
-	 * @see #getHorizontalScaleFactor()
252
-	 * @see ComponentWrapper#getVerticalScreenDPI()
253
-	 */
254
-	public static void setVerticalScaleFactor(Float f)
255
-	{
256
-		if (LayoutUtil.equals(verScale, f) == false) {
257
-			verScale = f;
258
-			MOD_COUNT++;
259
-		}
260
-	}
261
-
262
-	/** What base value should be used to calculate logical pixel sizes.
263
-	 * @return The current base. Default is {@link #BASE_SCALE_FACTOR}
264
-	 * @see #BASE_FONT_SIZE
265
-	 * @see # BASE_SCREEN_DPI_FACTOR
266
-	 * @see #BASE_REAL_PIXEL
267
-	 */
268
-	public static int getLogicalPixelBase()
269
-	{
270
-		return LP_BASE;
271
-	}
272
-
273
-	/** What base value should be used to calculate logical pixel sizes.
274
-	 * @param base The new base. Default is {@link #BASE_SCALE_FACTOR}
275
-	 * @see #BASE_FONT_SIZE
276
-	 * @see # BASE_SCREEN_DPI_FACTOR
277
-	 * @see #BASE_REAL_PIXEL
278
-	 */
279
-	public static void setLogicalPixelBase(int base)
280
-	{
281
-		if (LP_BASE != base) {
282
-			if (base < BASE_FONT_SIZE || base > BASE_SCALE_FACTOR)
283
-				throw new IllegalArgumentException("Unrecognized base: " + base);
284
-
285
-			LP_BASE = base;
286
-			MOD_COUNT++;
287
-		}
288
-	}
289
-
290
-	/** Sets gap value for components that are "related".
291
-	 * @param x The value that will be transformed to pixels. If <code>null</code> the current value will not change.
292
-	 * @param y The value that will be transformed to pixels. If <code>null</code> the current value will not change.
293
-	 */
294
-	public static void setRelatedGap(UnitValue x, UnitValue y)
295
-	{
296
-		setUnitValue(new String[] {"r", "rel", "related"}, x, y);
297
-
298
-		RELATED_X = new BoundSize(x, x, null, "rel:rel");
299
-		RELATED_Y = new BoundSize(y, y, null, "rel:rel");
300
-	}
301
-
302
-	/** Sets gap value for components that are "unrelated".
303
-	 * @param x The value that will be transformed to pixels. If <code>null</code> the current value will not change.
304
-	 * @param y The value that will be transformed to pixels. If <code>null</code> the current value will not change.
305
-	 */
306
-	public static void setUnrelatedGap(UnitValue x, UnitValue y)
307
-	{
308
-		setUnitValue(new String[] {"u", "unrel", "unrelated"}, x, y);
309
-
310
-		UNRELATED_X = new BoundSize(x, x, null, "unrel:unrel");
311
-		UNRELATED_Y = new BoundSize(y, y, null, "unrel:unrel");
312
-	}
313
-
314
-	/** Sets paragraph gap value for components.
315
-	 * @param x The value that will be transformed to pixels. If <code>null</code> the current value will not change.
316
-	 * @param y The value that will be transformed to pixels. If <code>null</code> the current value will not change.
317
-	 */
318
-	public static void setParagraphGap(UnitValue x, UnitValue y)
319
-	{
320
-		setUnitValue(new String[] {"p", "para", "paragraph"}, x, y);
321
-	}
322
-
323
-	/** Sets gap value for components that are "intended".
324
-	 * @param x The value that will be transformed to pixels. If <code>null</code> the current value will not change.
325
-	 * @param y The value that will be transformed to pixels. If <code>null</code> the current value will not change.
326
-	 */
327
-	public static void setIndentGap(UnitValue x, UnitValue y)
328
-	{
329
-		setUnitValue(new String[] {"i", "ind", "indent"}, x, y);
330
-	}
331
-
332
-	/** Sets gap between two cells in the grid. Note that this is not a gap between component IN a cell, that has to be set
333
-	 * on the component constraints. The value will be the min and preferred size of the gap.
334
-	 * @param x The value that will be transformed to pixels. If <code>null</code> the current value will not change.
335
-	 * @param y The value that will be transformed to pixels. If <code>null</code> the current value will not change.
336
-	 */
337
-	public static void setGridCellGap(UnitValue x, UnitValue y)
338
-	{
339
-		if (x != null)
340
-			DEF_HGAP = new BoundSize(x, x, null, null);
341
-
342
-		if (y != null)
343
-			DEF_VGAP = new BoundSize(y, y, null, null);
344
-
345
-		MOD_COUNT++;
346
-	}
347
-
348
-	/** Sets the recommended minimum button width.
349
-	 * @param width The recommended minimum button width.
350
-	 */
351
-	public static void setMinimumButtonWidth(UnitValue width)
352
-	{
353
-		BUTT_WIDTH = width;
354
-		MOD_COUNT++;
355
-	}
356
-
357
-	/** Returns the recommended minimum button width depending on the current set platform.
358
-	 * @return The recommended minimum button width depending on the current set platform.
359
-	 */
360
-	public static UnitValue getMinimumButtonWidth()
361
-	{
362
-		return BUTT_WIDTH;
363
-	}
364
-
365
-	/** Returns the unit value associated with the unit. (E.i. "related" or "indent"). Must be lower case.
366
-	 * @param unit The unit string.
367
-	 * @return Tthe unit value associated with the unit. <code>null</code> for unrecognized units.
368
-	 */
369
-	public static UnitValue getUnitValueX(String unit)
370
-	{
371
-		return HOR_DEFS.get(unit);
372
-	}
373
-
374
-	/** Returns the unit value associated with the unit. (E.i. "related" or "indent"). Must be lower case.
375
-	 * @param unit The unit string.
376
-	 * @return Tthe unit value associated with the unit. <code>null</code> for unrecognized units.
377
-	 */
378
-	public static UnitValue getUnitValueY(String unit)
379
-	{
380
-		return VER_DEFS.get(unit);
381
-	}
382
-
383
-	/** Sets the unit value assiciated with a unit string. This may be used to store values for new unit strings
384
-	 * or modify old. Note that if a built in unit (such as "related") is modified all versions of it must be
385
-	 * set (I.e. "r", "rel" and "related"). The build in values will be reset to the default ones if the platform
386
-	 * is re-set.
387
-	 * @param unitStrings The unit strings. E.g. "mu", "myunit". Will be converted to lower case and trimmed. Not <code>null</code>.
388
-	 * @param x The value for the horizontal dimension. If <code>null</code> the value is not changed.
389
-	 * @param y The value for the vertical dimension. Might be same object as for <code>x</code>. If <code>null</code> the value is not changed.
390
-	 */
391
-	public static final void setUnitValue(String[] unitStrings, UnitValue x, UnitValue y)
392
-	{
393
-		for (int i = 0; i < unitStrings.length; i++) {
394
-			String s = unitStrings[i].toLowerCase().trim();
395
-			if (x != null)
396
-				HOR_DEFS.put(s, x);
397
-			if (y != null)
398
-				VER_DEFS.put(s, y);
399
-		}
400
-		MOD_COUNT++;
401
-	}
402
-
403
-	/** Understands ("r", "rel", "related") OR ("u", "unrel", "unrelated") OR ("i", "ind", "indent") OR ("p", "para", "paragraph").
404
-	 */
405
-	static final int convertToPixels(float value, String unit, boolean isHor, float ref, ContainerWrapper parent, ComponentWrapper comp)
406
-	{
407
-		UnitValue uv = (isHor ? HOR_DEFS : VER_DEFS).get(unit);
408
-		return uv != null ? Math.round(value * uv.getPixels(ref, parent, comp)) : UnitConverter.UNABLE;
409
-	}
410
-
411
-	/** Returns the order for the typical buttons in a standard button bar. It is one letter per button type.
412
-	 * @return The button order.
413
-	 * @see #setButtonOrder(String)
414
-	 */
415
-	public static final String getButtonOrder()
416
-	{
417
-		return BUTTON_FORMAT;
418
-	}
419
-
420
-	/** Sets the order for the typical buttons in a standard button bar. It is one letter per button type.
421
-	 * <p>
422
-	 * Letter in upper case will get the minimum button width that the {@link #getMinimumButtonWidth()} specifies
423
-	 * and letters in lower case will get the width the corrent look&feel specifies.
424
-	 * <p>
425
-	 * Gaps will never be added to before the first component or after the last component. However, '+' (push) will be
426
-	 * applied before and after as well, but with a minimum size of 0 if first/last so there will not be a gap
427
-	 * before or after.
428
-	 * <p>
429
-	 * If gaps are explicitly set on buttons they will never be reduced, but they may be increased.
430
-	 * <p>
431
-	 * These are the characters that can be used:
432
-	 * <ul>
433
-	 * <li><code>'L'</code> - Buttons with this style tag will staticall end up on the left end of the bar.
434
-	 * <li><code>'R'</code> - Buttons with this style tag will staticall end up on the right end of the bar.
435
-	 * <li><code>'H'</code> - A tag for the "help" button that normally is supposed to be on the right.
436
-	 * <li><code>'E'</code> - A tag for the "help2" button that normally is supposed to be on the left.
437
-	 * <li><code>'Y'</code> - A tag for the "yes" button.
438
-	 * <li><code>'N'</code> - A tag for the "no" button.
439
-	 * <li><code>'X'</code> - A tag for the "next >" or "forward >" button.
440
-	 * <li><code>'B'</code> - A tag for the "< back>" or "< previous" button.
441
-	 * <li><code>'I'</code> - A tag for the "finish".
442
-	 * <li><code>'A'</code> - A tag for the "apply" button.
443
-	 * <li><code>'C'</code> - A tag for the "cancel" or "close" button.
444
-	 * <li><code>'O'</code> - A tag for the "ok" or "done" button.
445
-	 * <li><code>'U'</code> - All Uncategorized, Other, or "Unknown" buttons. Tag will be "other".
446
-	 * <li><code>'+'</code> - A glue push gap that will take as much space as it can and at least an "unrelated" gap. (Platform dependant)
447
-	 * <li><code>'_'</code> - (underscore) An "unrelated" gap. (Platform dependant)
448
-	 * </ul>
449
-	 * <p>
450
-	 * Even though the style tags are normally applied to buttons this works with all components.
451
-	 * <p>
452
-	 * The normal style for MAC OS X is <code>"L_HE+U+FBI_NYCOA_R"</code> and for Windows is <code>"L_E+U+FBI_YNOCAH_R"</code>
453
-	 * @param order The new button order for the current platform.
454
-	 */
455
-	public static final void setButtonOrder(String order)
456
-	{
457
-		BUTTON_FORMAT = order;
458
-		MOD_COUNT++;
459
-	}
460
-
461
-	/** Returns the tag (used in the {@link CC}) for a char. The char is same as used in {@link #getButtonOrder()}.
462
-	 * @param c The char. Must be lower case!
463
-	 * @return The tag that corresponds to the char or <code>null</code> if the char is unrecognized.
464
-	 */
465
-	static final String getTagForChar(char c)
466
-	{
467
-		switch (c) {
468
-			case 'o':
469
-				return "ok";
470
-			case 'c':
471
-				return "cancel";
472
-			case 'h':
473
-				return "help";
474
-			case 'e':
475
-				return "help2";
476
-			case 'y':
477
-				return "yes";
478
-			case 'n':
479
-				return "no";
480
-			case 'a':
481
-				return "apply";
482
-			case 'x':
483
-				return "next";  // a.k.a forward
484
-			case 'b':
485
-				return "back";  // a.k.a. previous
486
-			case 'i':
487
-				return "finish";
488
-			case 'l':
489
-				return "left";
490
-			case 'r':
491
-				return "right";
492
-			case 'u':
493
-				return "other";
494
-			default:
495
-				return null;
496
-		}
497
-	}
498
-
499
-	/** Returns the platform recommended inter-cell gap in the horizontal (x) dimension..
500
-	 * @return The platform recommended inter-cell gap in the horizontal (x) dimension..
501
-	 */
502
-	public static BoundSize getGridGapX()
503
-	{
504
-		return DEF_HGAP;
505
-	}
506
-
507
-	/** Returns the platform recommended inter-cell gap in the vertical (x) dimension..
508
-	 * @return The platform recommended inter-cell gap in the vertical (x) dimension..
509
-	 */
510
-	public static BoundSize getGridGapY()
511
-	{
512
-		return DEF_VGAP;
513
-	}
514
-
515
-	/** Returns the default dialog inset depending of the current platform.
516
-	 * @param side top == 0, left == 1, bottom = 2, right = 3.
517
-	 * @return The inset. Never <code>null</code>.
518
-	 */
519
-	public static UnitValue getDialogInsets(int side)
520
-	{
521
-		return DIALOG_INS[side];
522
-	}
523
-
524
-	/** Sets the default insets for a dialog. Values that are null will not be changed.
525
-	 * @param top The top inset. May be <code>null</code>.
526
-	 * @param left The left inset. May be <code>null</code>.
527
-	 * @param bottom The bottom inset. May be <code>null</code>.
528
-	 * @param right The right inset. May be <code>null</code>.
529
-	 */
530
-	public static void setDialogInsets(UnitValue top, UnitValue left, UnitValue bottom, UnitValue right)
531
-	{
532
-		if (top != null)
533
-			DIALOG_INS[0] = top;
534
-
535
-		if (left != null)
536
-			DIALOG_INS[1] = left;
537
-
538
-		if (bottom != null)
539
-			DIALOG_INS[2] = bottom;
540
-
541
-		if (right != null)
542
-			DIALOG_INS[3] = right;
543
-
544
-		MOD_COUNT++;
545
-	}
546
-
547
-	/** Returns the default panel inset depending of the current platform.
548
-	 * @param side top == 0, left == 1, bottom = 2, right = 3.
549
-	 * @return The inset. Never <code>null</code>.
550
-	 */
551
-	public static UnitValue getPanelInsets(int side)
552
-	{
553
-		return PANEL_INS[side];
554
-	}
555
-
556
-	/** Sets the default insets for a dialog. Values that are null will not be changed.
557
-	 * @param top The top inset. May be <code>null</code>.
558
-	 * @param left The left inset. May be <code>null</code>.
559
-	 * @param bottom The bottom inset. May be <code>null</code>.
560
-	 * @param right The right inset. May be <code>null</code>.
561
-	 */
562
-	public static void setPanelInsets(UnitValue top, UnitValue left, UnitValue bottom, UnitValue right)
563
-	{
564
-		if (top != null)
565
-			PANEL_INS[0] = top;
566
-
567
-		if (left != null)
568
-			PANEL_INS[1] = left;
569
-
570
-		if (bottom != null)
571
-			PANEL_INS[2] = bottom;
572
-
573
-		if (right != null)
574
-			PANEL_INS[3] = right;
575
-
576
-		MOD_COUNT++;
577
-	}
578
-
579
-	/** Returns the percentage used for alignment for labels (0 is left, 50 is center and 100 is right).
580
-	 * @return The percentage used for alignment for labels
581
-	 */
582
-	public static float getLabelAlignPercentage()
583
-	{
584
-		return CUR_PLAF == MAC_OSX ? 1f : 0f;
585
-	}
586
-
587
-	/** Returns the default gap between two components that <b>are in the same cell</b>.
588
-	 * @param comp The component that the gap is for. Never <code>null</code>.
589
-	 * @param adjacentComp The adjacent component if any. May be <code>null</code>.
590
-	 * @param adjacentSide What side the <code>adjacentComp</code> is on. {@link javax.swing.SwingUtilities#TOP} or
591
-	 * {@link javax.swing.SwingUtilities#LEFT} or {@link javax.swing.SwingUtilities#BOTTOM} or {@link javax.swing.SwingUtilities#RIGHT}.
592
-	 * @param tag The tag string that the component might be tagged with in the component constraints. May be <code>null</code>.
593
-	 * @param isLTR If it is left-to-right.
594
-	 * @return The default gap between two components or <code>null</code> if there should be no gap.
595
-	 */
596
-	static BoundSize getDefaultComponentGap(ComponentWrapper comp, ComponentWrapper adjacentComp, int adjacentSide, String tag, boolean isLTR)
597
-	{
598
-		if (GAP_PROVIDER != null)
599
-			return GAP_PROVIDER.getDefaultGap(comp, adjacentComp, adjacentSide, tag, isLTR);
600
-
601
-		if (adjacentComp == null)
602
-			return null;
603
-
604
-//		if (adjacentComp == null || adjacentSide == SwingConstants.LEFT || adjacentSide == SwingConstants.TOP)
605
-//			return null;
606
-
607
-		return (adjacentSide == SwingConstants.LEFT || adjacentSide == SwingConstants.RIGHT) ? RELATED_X : RELATED_Y;
608
-	}
609
-
610
-	/** Returns the current gap privider or <code>null</code> if none is set and "related" should always be used.
611
-	 * @return The current gap privider or <code>null</code> if none is set and "related" should always be used.
612
-	 */
613
-	public static InCellGapProvider getGapProvider()
614
-	{
615
-		return GAP_PROVIDER;
616
-	}
617
-
618
-	/** Sets the current gap privider or <code>null</code> if none is set and "related" should always be used.
619
-	 * @param provider The current gap privider or <code>null</code> if none is set and "related" should always be used.
620
-	 */
621
-	public static void setGapProvider(InCellGapProvider provider)
622
-	{
623
-		GAP_PROVIDER = provider;
624
-	}
625
-
626
-	/** Returns how many times the defaults has been changed. This can be used as a light weight check to
627
-	 * see if layout caches needs to be refreshed.
628
-	 * @return How many times the defaults has been changed.
629
-	 */
630
-	public static int getModCount()
631
-	{
632
-		return MOD_COUNT;
633
-	}
634
-
635
-	/** Tells all layout manager instances to revalidate and recalculated everything.
636
-	 */
637
-	public void invalidate()
638
-	{
639
-		MOD_COUNT++;
640
-	}
641
-
642
-	/** Returns the current default unit. The default unit is the unit used if no unit is set. E.g. "width 10".
643
-	 * @return The current default unit.
644
-	 * @see UnitValue#PIXEL
645
-	 * @see UnitValue#LPX
646
-	 */
647
-	public final static int getDefaultHorizontalUnit()
648
-	{
649
-		return DEF_H_UNIT;
650
-	}
651
-
652
-	/** Sets the default unit. The default unit is the unit used if no unit is set. E.g. "width 10".
653
-	 * @param unit The new default unit.
654
-	 * @see UnitValue#PIXEL
655
-	 * @see UnitValue#LPX
656
-	 */
657
-	public final static void setDefaultHorizontalUnit(int unit)
658
-	{
659
-		if (unit < UnitValue.PIXEL || unit > UnitValue.LABEL_ALIGN)
660
-			throw new IllegalArgumentException("Illegal Unit: " + unit);
661
-
662
-		if (DEF_H_UNIT != unit) {
663
-			DEF_H_UNIT = unit;
664
-			MOD_COUNT++;
665
-		}
666
-	}
667
-
668
-	/** Returns the current default unit. The default unit is the unit used if no unit is set. E.g. "width 10".
669
-	 * @return The current default unit.
670
-	 * @see UnitValue#PIXEL
671
-	 * @see UnitValue#LPY
672
-	 */
673
-	public final static int getDefaultVerticalUnit()
674
-	{
675
-		return DEF_V_UNIT;
676
-	}
677
-
678
-	/** Sets the default unit. The default unit is the unit used if no unit is set. E.g. "width 10".
679
-	 * @param unit The new default unit.
680
-	 * @see UnitValue#PIXEL
681
-	 * @see UnitValue#LPY
682
-	 */
683
-	public final static void setDefaultVerticalUnit(int unit)
684
-	{
685
-		if (unit < UnitValue.PIXEL || unit > UnitValue.LABEL_ALIGN)
686
-			throw new IllegalArgumentException("Illegal Unit: " + unit);
687
-
688
-		if (DEF_V_UNIT != unit) {
689
-			DEF_V_UNIT = unit;
690
-			MOD_COUNT++;
691
-		}
692
-	}
693
-
694
-	/** The default alignment for rows. Pre v3.5 this was <code>false</code> but now it is
695
-	 * <code>true</code>.
696
-	 * @return The current value. Default is <code>true</code>.
697
-	 * @since 3.5
698
-	 */
699
-	public static boolean getDefaultRowAlignmentBaseline()
700
-	{
701
-		return dra;
702
-	}
703
-
704
-	/** The default alignment for rows. Pre v3.5 this was <code>false</code> but now it is
705
-	 * <code>true</code>.
706
-	 * @param b The new value. Default is <code>true</code> from v3.5.
707
-	 * @since 3.5
708
-	 */
709
-	public static void setDefaultRowAlignmentBaseline(boolean b)
710
-	{
711
-		dra = b;
712
-	}
713
-}

+ 0
- 100
src/net/miginfocom/layout/ResizeConstraint.java Vedi File

@@ -1,100 +0,0 @@
1
-package net.miginfocom.layout;
2
-
3
-import java.io.*;
4
-/*
5
- * License (BSD):
6
- * ==============
7
- *
8
- * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
9
- * All rights reserved.
10
- *
11
- * Redistribution and use in source and binary forms, with or without modification,
12
- * are permitted provided that the following conditions are met:
13
- * Redistributions of source code must retain the above copyright notice, this list
14
- * of conditions and the following disclaimer.
15
- * Redistributions in binary form must reproduce the above copyright notice, this
16
- * list of conditions and the following disclaimer in the documentation and/or other
17
- * materials provided with the distribution.
18
- * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
19
- * used to endorse or promote products derived from this software without specific
20
- * prior written permission.
21
- *
22
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25
- * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
26
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
28
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
31
- * OF SUCH DAMAGE.
32
- *
33
- * @version 1.0
34
- * @author Mikael Grev, MiG InfoCom AB
35
- *         Date: 2006-sep-08
36
- */
37
-
38
-/** A parsed constraint that specifies how an entity (normally column/row or component) can shrink or
39
- * grow compared to other entities.
40
- */
41
-final class ResizeConstraint implements Externalizable
42
-{
43
-
44
-	/**
45
-	 * A version number for this class. It should be changed whenever the
46
-	 * class structure is changed (or anything else that would prevent
47
-	 * serialized objects being unserialized with the new class).
48
-	 */
49
-	private static final long serialVersionUID = 1;
50
-
51
-	static final Float WEIGHT_100 = new Float(100);
52
-
53
-	/** How flexilble the entity should be, relative to other entities, when it comes to growing. <code>null</code> or
54
-	 * zero mean it will never grow. An entity that has twise the growWeight compared to another entity will get twice
55
-	 * as much of available space.
56
-	 * <p>
57
-	 * "grow" are only compared within the same "growPrio".
58
-	 */
59
-	Float grow = null;
60
-
61
-	/** The relative priority used for determining which entities gets the extra space first.
62
-	 */
63
-	int growPrio = 100;
64
-
65
-	Float shrink = WEIGHT_100;
66
-
67
-	int shrinkPrio = 100;
68
-
69
-	public ResizeConstraint()   // For Externalizable
70
-	{
71
-	}
72
-
73
-	ResizeConstraint(int shrinkPrio, Float shrinkWeight, int growPrio, Float growWeight)
74
-	{
75
-		this.shrinkPrio = shrinkPrio;
76
-		this.shrink = shrinkWeight;
77
-		this.growPrio = growPrio;
78
-		this.grow = growWeight;
79
-	}
80
-
81
-	// ************************************************
82
-	// Persistence Delegate and Serializable combined.
83
-	// ************************************************
84
-
85
-	private Object readResolve() throws ObjectStreamException
86
-	{
87
-		return LayoutUtil.getSerializedObject(this);
88
-	}
89
-
90
-	public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
91
-	{
92
-		LayoutUtil.setSerializedObject(this, LayoutUtil.readAsXML(in));
93
-	}
94
-
95
-	public void writeExternal(ObjectOutput out) throws IOException
96
-	{
97
-		if (getClass() == ResizeConstraint.class)
98
-			LayoutUtil.writeAsXML(out, this);
99
-	}
100
-}

+ 0
- 59
src/net/miginfocom/layout/UnitConverter.java Vedi File

@@ -1,59 +0,0 @@
1
-package net.miginfocom.layout;
2
-/*
3
- * License (BSD):
4
- * ==============
5
- *
6
- * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
7
- * All rights reserved.
8
- *
9
- * Redistribution and use in source and binary forms, with or without modification,
10
- * are permitted provided that the following conditions are met:
11
- * Redistributions of source code must retain the above copyright notice, this list
12
- * of conditions and the following disclaimer.
13
- * Redistributions in binary form must reproduce the above copyright notice, this
14
- * list of conditions and the following disclaimer in the documentation and/or other
15
- * materials provided with the distribution.
16
- * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
17
- * used to endorse or promote products derived from this software without specific
18
- * prior written permission.
19
- *
20
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23
- * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
26
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
29
- * OF SUCH DAMAGE.
30
- *
31
- * @version 1.0
32
- * @author Mikael Grev, MiG InfoCom AB
33
- *         Date: 2006-sep-08
34
- */
35
-
36
-/**
37
- */
38
-public abstract class UnitConverter
39
-{
40
-	/** Value to return if this converter can not handle the <code>unit</code> sent in as an argument
41
-	 * to the convert method.
42
-	 */
43
-	public static final int UNABLE = -87654312;
44
-
45
-	/** Converts <code>value</code> to pixels.
46
-	 * @param value The value to be converted.
47
-	 * @param unit The unit of <code>value</code>. Never <code>null</code> and at least one character.
48
-	 * @param refValue Some reference value that may of may not be used. If the unit is percent for instance this value
49
-	 * is the value to take the percent from. Usually the size of the parent component in the appropriate dimension.
50
-	 * @param isHor If the value is horizontal (<code>true</code>) or vertical (<code>false</code>).
51
-	 * @param parent The parent of the target component that <code>value</code> is to be applied to.
52
-	 * Might for instance be needed to get the screen that the component is on in a multi screen environment.
53
-	 * <p>
54
-	 * May be <code>null</code> in which case a "best guess" value should be returned.
55
-	 * @param comp The component, if applicable, or <code>null</code> if none.
56
-	 * @return The number of pixels if <code>unit</code> is handled by this converter, <code>UnitConverter.UNABLE</code> if not.
57
-	 */
58
-	public abstract int convertToPixels(float value, String unit, boolean isHor, float refValue, ContainerWrapper parent, ComponentWrapper comp);
59
-}

+ 0
- 638
src/net/miginfocom/layout/UnitValue.java Vedi File

@@ -1,638 +0,0 @@
1
-package net.miginfocom.layout;
2
-/*
3
- * License (BSD):
4
- * ==============
5
- *
6
- * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
7
- * All rights reserved.
8
- *
9
- * Redistribution and use in source and binary forms, with or without modification,
10
- * are permitted provided that the following conditions are met:
11
- * Redistributions of source code must retain the above copyright notice, this list
12
- * of conditions and the following disclaimer.
13
- * Redistributions in binary form must reproduce the above copyright notice, this
14
- * list of conditions and the following disclaimer in the documentation and/or other
15
- * materials provided with the distribution.
16
- * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
17
- * used to endorse or promote products derived from this software without specific
18
- * prior written permission.
19
- *
20
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23
- * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
26
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
29
- * OF SUCH DAMAGE.
30
- *
31
- * @version 1.0
32
- * @author Mikael Grev, MiG InfoCom AB
33
- *         Date: 2006-sep-08
34
- */
35
-
36
-import java.beans.Encoder;
37
-import java.beans.Expression;
38
-import java.beans.PersistenceDelegate;
39
-import java.io.*;
40
-import java.util.ArrayList;
41
-import java.util.HashMap;
42
-
43
-public final class UnitValue implements Serializable
44
-{
45
-	private static final HashMap<String, Integer> UNIT_MAP = new HashMap<String, Integer>(32);
46
-
47
-	private static final ArrayList<UnitConverter> CONVERTERS = new ArrayList<UnitConverter>();
48
-
49
-	/** An operation indicating a static value.
50
-	 */
51
-	public static final int STATIC = 100;
52
-
53
-	/** An operation indicating a addition of two sub units.
54
-	 */
55
-	public static final int ADD = 101; // Must have "sub-unit values"
56
-
57
-	/** An operation indicating a subtraction of two sub units
58
-	 */
59
-	public static final int SUB = 102; // Must have "sub-unit values"
60
-
61
-	/** An operation indicating a multiplication of two sub units.
62
-	 */
63
-	public static final int MUL = 103; // Must have "sub-unit values"
64
-
65
-	/** An operation indicating a division of two sub units.
66
-	 */
67
-	public static final int DIV = 104; // Must have "sub-unit values"
68
-
69
-	/** An operation indicating the minimum of two sub units
70
-	 */
71
-	public static final int MIN = 105; // Must have "sub-unit values"
72
-
73
-	/** An operation indicating the maximum of two sub units
74
-	 */
75
-	public static final int MAX = 106; // Must have "sub-unit values"
76
-
77
-	/** An operation indicating the middle value of two sub units
78
-	 */
79
-	public static final int MID = 107; // Must have "sub-unit values"
80
-
81
-
82
-
83
-
84
-	/** A unit indicating pixels.
85
-	 */
86
-	public static final int PIXEL = 0;
87
-
88
-	/** A unit indicating logical horizontal pixels.
89
-	 */
90
-	public static final int LPX = 1;
91
-
92
-	/** A unit indicating logical vertical pixels.
93
-	 */
94
-	public static final int LPY = 2;
95
-
96
-	/** A unit indicating millimeters.
97
-	 */
98
-	public static final int MM = 3;
99
-
100
-	/** A unit indicating centimeters.
101
-	 */
102
-	public static final int CM = 4;
103
-
104
-	/** A unit indicating inches.
105
-	 */
106
-	public static final int INCH = 5;
107
-
108
-	/** A unit indicating percent.
109
-	 */
110
-	public static final int PERCENT = 6;
111
-
112
-	/** A unit indicating points.
113
-	 */
114
-	public static final int PT = 7;
115
-
116
-	/** A unit indicating screen percentage width.
117
-	 */
118
-	public static final int SPX = 8;
119
-
120
-	/** A unit indicating screen percentage height.
121
-	 */
122
-	public static final int SPY = 9;
123
-
124
-	/** A unit indicating alignment.
125
-	 */
126
-	public static final int ALIGN = 12;
127
-
128
-	/** A unit indicating minimum size.
129
-	 */
130
-	public static final int MIN_SIZE = 13;
131
-
132
-	/** A unit indicating preferred size.
133
-	 */
134
-	public static final int PREF_SIZE = 14;
135
-
136
-	/** A unit indicating maximum size.
137
-	 */
138
-	public static final int MAX_SIZE = 15;
139
-
140
-	/** A unit indicating botton size.
141
-	 */
142
-	public static final int BUTTON = 16;
143
-
144
-	/** A unit indicating linking to x.
145
-	 */
146
-	public static final int LINK_X = 18;   // First link
147
-
148
-	/** A unit indicating linking to y.
149
-	 */
150
-	public static final int LINK_Y = 19;
151
-
152
-	/** A unit indicating linking to width.
153
-	 */
154
-	public static final int LINK_W = 20;
155
-
156
-	/** A unit indicating linking to height.
157
-	 */
158
-	public static final int LINK_H = 21;
159
-
160
-	/** A unit indicating linking to x2.
161
-	 */
162
-	public static final int LINK_X2 = 22;
163
-
164
-	/** A unit indicating linking to y2.
165
-	 */
166
-	public static final int LINK_Y2 = 23;
167
-
168
-	/** A unit indicating linking to x position on screen.
169
-	 */
170
-	public static final int LINK_XPOS = 24;
171
-
172
-	/** A unit indicating linking to y position on screen.
173
-	 */
174
-	public static final int LINK_YPOS = 25;    // Last link
175
-
176
-	/** A unit indicating a lookup.
177
-	 */
178
-	public static final int LOOKUP = 26;
179
-
180
-	/** A unit indicating label alignment.
181
-	 */
182
-	public static final int LABEL_ALIGN = 27;
183
-
184
-	private static final int IDENTITY = -1;
185
-
186
-	static {
187
-		UNIT_MAP.put("px", new Integer(PIXEL));
188
-		UNIT_MAP.put("lpx", new Integer(LPX));
189
-		UNIT_MAP.put("lpy", new Integer(LPY));
190
-		UNIT_MAP.put("%", new Integer(PERCENT));
191
-		UNIT_MAP.put("cm", new Integer(CM));
192
-		UNIT_MAP.put("in", new Integer(INCH));
193
-		UNIT_MAP.put("spx", new Integer(SPX));
194
-		UNIT_MAP.put("spy", new Integer(SPY));
195
-		UNIT_MAP.put("al", new Integer(ALIGN));
196
-		UNIT_MAP.put("mm", new Integer(MM));
197
-		UNIT_MAP.put("pt", new Integer(PT));
198
-		UNIT_MAP.put("min", new Integer(MIN_SIZE));
199
-		UNIT_MAP.put("minimum", new Integer(MIN_SIZE));
200
-		UNIT_MAP.put("p", new Integer(PREF_SIZE));
201
-		UNIT_MAP.put("pref", new Integer(PREF_SIZE));
202
-		UNIT_MAP.put("max", new Integer(MAX_SIZE));
203
-		UNIT_MAP.put("maximum", new Integer(MAX_SIZE));
204
-		UNIT_MAP.put("button", new Integer(BUTTON));
205
-		UNIT_MAP.put("label", new Integer(LABEL_ALIGN));
206
-	}
207
-
208
-	static final UnitValue ZERO = new UnitValue(0, null, PIXEL, true, STATIC, null, null, "0px");
209
-	static final UnitValue TOP = new UnitValue(0, null, PERCENT, false, STATIC, null, null, "top");
210
-	static final UnitValue LEADING = new UnitValue(0, null, PERCENT, true, STATIC, null, null, "leading");
211
-	static final UnitValue LEFT = new UnitValue(0, null, PERCENT, true, STATIC, null, null, "left");
212
-	static final UnitValue CENTER = new UnitValue(50, null, PERCENT, true, STATIC, null, null, "center");
213
-	static final UnitValue TRAILING = new UnitValue(100, null, PERCENT, true, STATIC, null, null, "trailing");
214
-	static final UnitValue RIGHT = new UnitValue(100, null, PERCENT, true, STATIC, null, null, "right");
215
-	static final UnitValue BOTTOM = new UnitValue(100, null, PERCENT, false, STATIC, null, null, "bottom");
216
-	static final UnitValue LABEL = new UnitValue(0, null, LABEL_ALIGN, false, STATIC, null, null, "label");
217
-
218
-	static final UnitValue INF = new UnitValue(LayoutUtil.INF, null, PIXEL, true, STATIC, null, null, "inf");
219
-
220
-	static final UnitValue BASELINE_IDENTITY = new UnitValue(0, null, IDENTITY, false, STATIC, null, null, "baseline");
221
-
222
-	private final transient float value;
223
-	private final transient int unit;
224
-	private final transient int oper;
225
-	private final transient String unitStr;
226
-	private transient String linkId = null; // Should be final, but initializes in a sub method.
227
-	private final transient boolean isHor;
228
-	private final transient UnitValue[] subUnits;
229
-
230
-	// Pixel
231
-	public UnitValue(float value)  // If hor/ver does not matter.
232
-	{
233
-		this(value, null, PIXEL, true, STATIC, null, null, value + "px");
234
-	}
235
-
236
-	public UnitValue(float value, int unit, String createString)  // If hor/ver does not matter.
237
-	{
238
-		this(value, null, unit, true, STATIC, null, null, createString);
239
-	}
240
-
241
-	UnitValue(float value, String unitStr, boolean isHor, int oper, String createString)
242
-	{
243
-		this(value, unitStr, -1, isHor, oper, null, null, createString);
244
-	}
245
-
246
-	UnitValue(boolean isHor, int oper, UnitValue sub1, UnitValue sub2, String createString)
247
-	{
248
-		this(0, "", -1, isHor, oper, sub1, sub2, createString);
249
-		if (sub1 == null || sub2 == null)
250
-			throw new IllegalArgumentException("Sub units is null!");
251
-	}
252
-
253
-	private UnitValue(float value, String unitStr, int unit, boolean isHor, int oper, UnitValue sub1, UnitValue sub2, String createString)
254
-	{
255
-		if (oper < STATIC || oper > MID)
256
-			throw new IllegalArgumentException("Unknown Operation: " + oper);
257
-
258
-		if (oper >= ADD && oper <= MID && (sub1 == null || sub2 == null))
259
-			throw new IllegalArgumentException(oper + " Operation may not have null sub-UnitValues.");
260
-
261
-		this.value = value;
262
-		this.oper = oper;
263
-		this.isHor = isHor;
264
-		this.unitStr = unitStr;
265
-		this.unit = unitStr != null ? parseUnitString() : unit;
266
-		this.subUnits = sub1 != null && sub2 != null ? new UnitValue[] {sub1, sub2} : null;
267
-
268
-		LayoutUtil.putCCString(this, createString);    // "this" escapes!! Safe though.
269
-	}
270
-
271
-	/** Returns the size in pixels rounded.
272
-	 * @param refValue The reference value. Normally the size of the parent. For unit {@link #ALIGN} the current size of the component should be sent in.
273
-	 * @param parent The parent. May be <code>null</code> for testing the validity of the value, but should normally not and are not
274
-	 * required to return any usable value if <code>null</code>.
275
-	 * @param comp The component, if any, that the value is for. Might be <code>null</code> if the value is not
276
-	 * connected to any component.
277
-	 * @return The size in pixels.
278
-	 */
279
-	public final int getPixels(float refValue, ContainerWrapper parent, ComponentWrapper comp)
280
-	{
281
-		return Math.round(getPixelsExact(refValue, parent, comp));
282
-	}
283
-
284
-	private static final float[] SCALE = new float[] {25.4f, 2.54f, 1f, 0f, 72f};
285
-	/** Returns the size in pixels.
286
-	 * @param refValue The reference value. Normally the size of the parent. For unit {@link #ALIGN} the current size of the component should be sent in.
287
-	 * @param parent The parent. May be <code>null</code> for testing the validity of the value, but should normally not and are not
288
-	 * required to return any usable value if <code>null</code>.
289
-	 * @param comp The component, if any, that the value is for. Might be <code>null</code> if the value is not
290
-	 * connected to any component.
291
-	 * @return The size in pixels.
292
-	 */
293
-	@SuppressWarnings("fallthrough")
294
-	public final float getPixelsExact(float refValue, ContainerWrapper parent, ComponentWrapper comp)
295
-	{
296
-		if (parent == null)
297
-			return 1;
298
-
299
-		if (oper == STATIC) {
300
-			switch (unit) {
301
-				case PIXEL:
302
-					return value;
303
-
304
-				case LPX:
305
-				case LPY:
306
-					return parent.getPixelUnitFactor(unit == LPX) * value;
307
-
308
-				case MM:
309
-				case CM:
310
-				case INCH:
311
-				case PT:
312
-					float f = SCALE[unit - MM];
313
-					Float s = isHor ? PlatformDefaults.getHorizontalScaleFactor() : PlatformDefaults.getVerticalScaleFactor();
314
-					if (s != null)
315
-						f *= s.floatValue();
316
-					return (isHor ? parent.getHorizontalScreenDPI() : parent.getVerticalScreenDPI()) * value / f;
317
-
318
-				case PERCENT:
319
-					return value * refValue * 0.01f;
320
-
321
-				case SPX:
322
-				case SPY:
323
-					return (unit == SPX ? parent.getScreenWidth() : parent.getScreenHeight()) * value * 0.01f;
324
-
325
-				case ALIGN:
326
-					Integer st = LinkHandler.getValue(parent.getLayout(), "visual", isHor ? LinkHandler.X : LinkHandler.Y);
327
-					Integer sz = LinkHandler.getValue(parent.getLayout(), "visual", isHor ? LinkHandler.WIDTH : LinkHandler.HEIGHT);
328
-					if (st == null || sz == null)
329
-						return 0;
330
-					return value * (Math.max(0, sz.intValue()) - refValue) + st.intValue();
331
-
332
-				case MIN_SIZE:
333
-					if (comp == null)
334
-						return 0;
335
-					return isHor ? comp.getMinimumWidth(comp.getHeight()) : comp.getMinimumHeight(comp.getWidth());
336
-
337
-				case PREF_SIZE:
338
-					if (comp == null)
339
-						return 0;
340
-					return isHor ? comp.getPreferredWidth(comp.getHeight()) : comp.getPreferredHeight(comp.getWidth());
341
-
342
-				case MAX_SIZE:
343
-					if (comp == null)
344
-						return 0;
345
-					return isHor ? comp.getMaximumWidth(comp.getHeight()) : comp.getMaximumHeight(comp.getWidth());
346
-
347
-				case BUTTON:
348
-					return PlatformDefaults.getMinimumButtonWidth().getPixels(refValue, parent, comp);
349
-
350
-				case LINK_X:
351
-				case LINK_Y:
352
-				case LINK_W:
353
-				case LINK_H:
354
-				case LINK_X2:
355
-				case LINK_Y2:
356
-				case LINK_XPOS:
357
-				case LINK_YPOS:
358
-					Integer v = LinkHandler.getValue(parent.getLayout(), getLinkTargetId(), unit - (unit >= LINK_XPOS ? LINK_XPOS : LINK_X));
359
-					if (v == null)
360
-						return 0;
361
-
362
-					if (unit == LINK_XPOS)
363
-						return parent.getScreenLocationX() + v.intValue();
364
-					if (unit == LINK_YPOS)
365
-						return parent.getScreenLocationY() + v.intValue();
366
-
367
-					return v.intValue();
368
-
369
-				case LOOKUP:
370
-					float res = lookup(refValue, parent, comp);
371
-					if (res != UnitConverter.UNABLE)
372
-						return res;
373
-
374
-				case LABEL_ALIGN:
375
-					return PlatformDefaults.getLabelAlignPercentage() * refValue;
376
-
377
-				case IDENTITY:
378
-			}
379
-			throw new IllegalArgumentException("Unknown/illegal unit: " + unit + ", unitStr: " + unitStr);
380
-		}
381
-
382
-		if (subUnits != null && subUnits.length == 2) {
383
-			float r1 = subUnits[0].getPixelsExact(refValue, parent, comp);
384
-			float r2 = subUnits[1].getPixelsExact(refValue, parent, comp);
385
-			switch (oper) {
386
-				case ADD:
387
-					return r1 + r2;
388
-				case SUB:
389
-					return r1 - r2;
390
-				case MUL:
391
-					return r1 * r2;
392
-				case DIV:
393
-					return r1 / r2;
394
-				case MIN:
395
-					return r1 < r2 ? r1 : r2;
396
-				case MAX:
397
-					return r1 > r2 ? r1 : r2;
398
-				case MID:
399
-					return (r1 + r2) * 0.5f;
400
-			}
401
-		}
402
-
403
-		throw new IllegalArgumentException("Internal: Unknown Oper: " + oper);
404
-	}
405
-
406
-	private float lookup(float refValue, ContainerWrapper parent, ComponentWrapper comp)
407
-	{
408
-		float res = UnitConverter.UNABLE;
409
-		for (int i = CONVERTERS.size() - 1; i >= 0; i--) {
410
-			res = CONVERTERS.get(i).convertToPixels(value, unitStr, isHor, refValue, parent, comp);
411
-			if (res != UnitConverter.UNABLE)
412
-				return res;
413
-		}
414
-		return PlatformDefaults.convertToPixels(value, unitStr, isHor, refValue, parent, comp);
415
-	}
416
-
417
-	private int parseUnitString()
418
-	{
419
-		int len = unitStr.length();
420
-		if (len == 0)
421
-			return isHor ? PlatformDefaults.getDefaultHorizontalUnit() : PlatformDefaults.getDefaultVerticalUnit();
422
-
423
-		Integer u = UNIT_MAP.get(unitStr);
424
-		if (u != null)
425
-			return u.intValue();
426
-
427
-		if (unitStr.equals("lp"))
428
-			return isHor ? LPX : LPY;
429
-
430
-		if (unitStr.equals("sp"))
431
-			return isHor ? SPX : SPY;
432
-
433
-		if (lookup(0, null, null) != UnitConverter.UNABLE)    // To test so we can fail fast
434
-			return LOOKUP;
435
-
436
-		// Only link left. E.g. "otherID.width"
437
-
438
-		int pIx = unitStr.indexOf('.');
439
-		if (pIx != -1) {
440
-			linkId = unitStr.substring(0, pIx);
441
-			String e = unitStr.substring(pIx + 1);
442
-
443
-			if (e.equals("x"))
444
-				return LINK_X;
445
-			if (e.equals("y"))
446
-				return LINK_Y;
447
-			if (e.equals("w") || e.equals("width"))
448
-				return LINK_W;
449
-			if (e.equals("h") || e.equals("height"))
450
-				return LINK_H;
451
-			if (e.equals("x2"))
452
-				return LINK_X2;
453
-			if (e.equals("y2"))
454
-				return LINK_Y2;
455
-			if (e.equals("xpos"))
456
-				return LINK_XPOS;
457
-			if (e.equals("ypos"))
458
-				return LINK_YPOS;
459
-		}
460
-
461
-		throw new IllegalArgumentException("Unknown keyword: " + unitStr);
462
-	}
463
-
464
-	final boolean isLinked()
465
-	{
466
-		return linkId != null;
467
-	}
468
-
469
-	final boolean isLinkedDeep()
470
-	{
471
-		if (subUnits == null)
472
-			return linkId != null;
473
-
474
-		for (int i = 0; i < subUnits.length; i++) {
475
-			if (subUnits[i].isLinkedDeep())
476
-				return true;
477
-		}
478
-
479
-		return false;
480
-	}
481
-
482
-	final String getLinkTargetId()
483
-	{
484
-		return linkId;
485
-	}
486
-
487
-	final UnitValue getSubUnitValue(int i)
488
-	{
489
-		return subUnits[i];
490
-	}
491
-
492
-	final int getSubUnitCount()
493
-	{
494
-		return subUnits != null ? subUnits.length : 0;
495
-	}
496
-
497
-	public final UnitValue[] getSubUnits()
498
-	{
499
-		return subUnits;
500
-	}
501
-
502
-	public final int getUnit()
503
-	{
504
-		return unit;
505
-	}
506
-
507
-	public final String getUnitString()
508
-	{
509
-		return unitStr;
510
-	}
511
-
512
-	public final int getOperation()
513
-	{
514
-		return oper;
515
-	}
516
-
517
-	public final float getValue()
518
-	{
519
-		return value;
520
-	}
521
-
522
-	public final boolean isHorizontal()
523
-	{
524
-		return isHor;
525
-	}
526
-
527
-	final public String toString()
528
-	{
529
-		return getClass().getName() + ". Value=" + value + ", unit=" + unit + ", unitString: " + unitStr + ", oper=" + oper + ", isHor: " + isHor;
530
-	}
531
-
532
-	/** Returns the creation string for this object. Note that {@link LayoutUtil#setDesignTime(ContainerWrapper, boolean)} must be
533
-	 * set to <code>true</code> for the creation strings to be stored.
534
-	 * @return The constraint string or <code>null</code> if none is registered.
535
-	 */
536
-	public final String getConstraintString()
537
-	{
538
-		return LayoutUtil.getCCString(this);
539
-	}
540
-
541
-	public final int hashCode()
542
-	{
543
-		return (int) (value * 12345) + (oper >>> 5) + unit >>> 17;
544
-	}
545
-
546
-	/** Adds a global unit converter that can convert from some <code>unit</code> to pixels.
547
-	 * <p>
548
-	 * This converter will be asked before the platform converter so the values for it (e.g. "related" and "unrelated")
549
-	 * can be overridden. It is however not possible to override the built in ones (e.g. "mm", "pixel" or "lp").
550
-	 * @param conv The converter. Not <code>null</code>.
551
-	 */
552
-	public final synchronized static void addGlobalUnitConverter(UnitConverter conv)
553
-	{
554
-		if (conv == null)
555
-			throw new NullPointerException();
556
-		CONVERTERS.add(conv);
557
-	}
558
-
559
-	/** Removed the converter.
560
-	 * @param unit The converter.
561
-	 * @return If there was a converter found and thus removed.
562
-	 */
563
-	public final synchronized static boolean removeGlobalUnitConverter(String unit)
564
-	{
565
-		return CONVERTERS.remove(unit);
566
-	}
567
-
568
-	/** Returns the global converters currently registered. The platform converter will not be in this list.
569
-	 * @return The converters. Never <code>null</code>.
570
-	 */
571
-	public final synchronized static UnitConverter[] getGlobalUnitConverters()
572
-	{
573
-		return CONVERTERS.toArray(new UnitConverter[CONVERTERS.size()]);
574
-	}
575
-
576
-	/** Returns the current default unit. The default unit is the unit used if no unit is set. E.g. "width 10".
577
-	 * @return The current default unit.
578
-	 * @see #PIXEL
579
-	 * @see #LPX
580
-	 * @deprecated Use {@link PlatformDefaults#getDefaultHorizontalUnit()} and {@link PlatformDefaults#getDefaultVerticalUnit()} instead.
581
-	 */
582
-	@Deprecated
583
-	public final static int getDefaultUnit()
584
-	{
585
-		return PlatformDefaults.getDefaultHorizontalUnit();
586
-	}
587
-
588
-	/** Sets the default unit. The default unit is the unit used if no unit is set. E.g. "width 10".
589
-	 * @param unit The new default unit.
590
-	 * @see #PIXEL
591
-	 * @see #LPX
592
-	 * @deprecated Use {@link PlatformDefaults#setDefaultHorizontalUnit(int)} and {@link PlatformDefaults#setDefaultVerticalUnit(int)} instead.
593
-	 */
594
-	@Deprecated
595
-	public final static void setDefaultUnit(int unit)
596
-	{
597
-		PlatformDefaults.setDefaultHorizontalUnit(unit);
598
-		PlatformDefaults.setDefaultVerticalUnit(unit);
599
-	}
600
-
601
-	static {
602
-		LayoutUtil.setDelegate(UnitValue.class, new PersistenceDelegate() {
603
-			protected Expression instantiate(Object oldInstance, Encoder out)
604
-			{
605
-				UnitValue uv = (UnitValue) oldInstance;
606
-                String cs = uv.getConstraintString();
607
-				if (cs == null)
608
-					throw new IllegalStateException("Design time must be on to use XML persistence. See LayoutUtil.");
609
-
610
-				return new Expression(oldInstance, ConstraintParser.class, "parseUnitValueOrAlign", new Object[] {
611
-		                uv.getConstraintString(), (uv.isHorizontal() ? Boolean.TRUE : Boolean.FALSE), null
612
-                });
613
-			}
614
-		});
615
-	}
616
-
617
-	// ************************************************
618
-	// Persistence Delegate and Serializable combined.
619
-	// ************************************************
620
-
621
-	private static final long serialVersionUID = 1L;
622
-
623
-	private Object readResolve() throws ObjectStreamException
624
-	{
625
-		return LayoutUtil.getSerializedObject(this);
626
-	}
627
-
628
-	private void writeObject(ObjectOutputStream out) throws IOException
629
-	{
630
-		if (getClass() == UnitValue.class)
631
-			LayoutUtil.writeAsXML(out, this);
632
-	}
633
-
634
-	private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
635
-	{
636
-		LayoutUtil.setSerializedObject(this, LayoutUtil.readAsXML(in));
637
-	}
638
-}

+ 0
- 637
src/net/miginfocom/swing/MigLayout.java Vedi File

@@ -1,637 +0,0 @@
1
-package net.miginfocom.swing;
2
-/*
3
- * License (BSD):
4
- * ==============
5
- *
6
- * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
7
- * All rights reserved.
8
- *
9
- * Redistribution and use in source and binary forms, with or without modification,
10
- * are permitted provided that the following conditions are met:
11
- * Redistributions of source code must retain the above copyright notice, this list
12
- * of conditions and the following disclaimer.
13
- * Redistributions in binary form must reproduce the above copyright notice, this
14
- * list of conditions and the following disclaimer in the documentation and/or other
15
- * materials provided with the distribution.
16
- * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
17
- * used to endorse or promote products derived from this software without specific
18
- * prior written permission.
19
- *
20
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23
- * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
26
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
29
- * OF SUCH DAMAGE.
30
- *
31
- * @version 1.0
32
- * @author Mikael Grev, MiG InfoCom AB
33
- *         Date: 2006-sep-08
34
- */
35
-
36
-import net.miginfocom.layout.*;
37
-
38
-import javax.swing.*;
39
-import javax.swing.Timer;
40
-import java.awt.*;
41
-import java.awt.event.ActionEvent;
42
-import java.awt.event.ActionListener;
43
-import java.io.*;
44
-import java.lang.ref.WeakReference;
45
-import java.util.*;
46
-
47
-/** A very flexbile layout manager.
48
- * <p>
49
- * Read the documentation that came with this layout manager for information on usage.
50
- */
51
-public final class MigLayout implements LayoutManager2, Externalizable
52
-{
53
-
54
-	/**
55
-	 * A version number for this class. It should be changed whenever the
56
-	 * class structure is changed (or anything else that would prevent
57
-	 * serialized objects being unserialized with the new class).
58
-	 */
59
-	private static final long serialVersionUID = 1;
60
-
61
-	// ******** Instance part ********
62
-
63
-	/** The component to string constraints mappings.
64
-	 */
65
-	private final Map<Component, Object> scrConstrMap = new IdentityHashMap<Component, Object>(8);
66
-
67
-	/** Hold the serializable text representation of the constraints.
68
-	 */
69
-	private Object layoutConstraints = "", colConstraints = "", rowConstraints = "";    // Should never be null!
70
-
71
-
72
-	// ******** Transient part ********
73
-
74
-	private transient ContainerWrapper cacheParentW = null;
75
-
76
-	private transient final Map<ComponentWrapper, CC> ccMap = new HashMap<ComponentWrapper, CC>(8);
77
-	private transient javax.swing.Timer debugTimer = null;
78
-
79
-	private transient LC lc = null;
80
-	private transient AC colSpecs = null, rowSpecs = null;
81
-	private transient Grid grid = null;
82
-	private transient int lastModCount = PlatformDefaults.getModCount();
83
-	private transient int lastHash = -1;
84
-	private transient Dimension lastInvalidSize = null;
85
-
86
-	private transient ArrayList<LayoutCallback> callbackList = null;
87
-
88
-	private transient boolean dirty = true;
89
-
90
-	/** Constructor with no constraints.
91
-	 */
92
-	public MigLayout()
93
-	{
94
-		this("", "", "");
95
-	}
96
-
97
-	/** Constructor.
98
-	 * @param layoutConstraints The constraints that concern the whole layout. <code>null</code> will be treated as "".
99
-	 */
100
-	public MigLayout(String layoutConstraints)
101
-	{
102
-		this(layoutConstraints, "", "");
103
-	}
104
-
105
-	/** Constructor.
106
-	 * @param layoutConstraints The constraints that concern the whole layout. <code>null</code> will be treated as "".
107
-	 * @param colConstraints The constraints for the columns in the grid. <code>null</code> will be treated as "".
108
-	 */
109
-	public MigLayout(String layoutConstraints, String colConstraints)
110
-	{
111
-		this(layoutConstraints, colConstraints, "");
112
-	}
113
-
114
-	/** Constructor.
115
-	 * @param layoutConstraints The constraints that concern the whole layout. <code>null</code> will be treated as "".
116
-	 * @param colConstraints The constraints for the columns in the grid. <code>null</code> will be treated as "".
117
-	 * @param rowConstraints The constraints for the rows in the grid. <code>null</code> will be treated as "".
118
-	 */
119
-	public MigLayout(String layoutConstraints, String colConstraints, String rowConstraints)
120
-	{
121
-		setLayoutConstraints(layoutConstraints);
122
-		setColumnConstraints(colConstraints);
123
-		setRowConstraints(rowConstraints);
124
-	}
125
-
126
-	/** Constructor.
127
-	 * @param layoutConstraints The constraints that concern the whole layout. <code>null</code> will be treated as an empty cosntraint.
128
-	 */
129
-	public MigLayout(LC layoutConstraints)
130
-	{
131
-		this(layoutConstraints, null, null);
132
-	}
133
-
134
-	/** Constructor.
135
-	 * @param layoutConstraints The constraints that concern the whole layout. <code>null</code> will be treated as an empty cosntraint.
136
-	 * @param colConstraints The constraints for the columns in the grid. <code>null</code> will be treated as an empty constraint.
137
-	 */
138
-	public MigLayout(LC layoutConstraints, AC colConstraints)
139
-	{
140
-		this(layoutConstraints, colConstraints, null);
141
-	}
142
-
143
-	/** Constructor.
144
-	 * @param layoutConstraints The constraints that concern the whole layout. <code>null</code> will be treated as an empty cosntraint.
145
-	 * @param colConstraints The constraints for the columns in the grid. <code>null</code> will be treated as an empty constraint.
146
-	 * @param rowConstraints The constraints for the rows in the grid. <code>null</code> will be treated as an empty constraint.
147
-	 */
148
-	public MigLayout(LC layoutConstraints, AC colConstraints, AC rowConstraints)
149
-	{
150
-		setLayoutConstraints(layoutConstraints);
151
-		setColumnConstraints(colConstraints);
152
-		setRowConstraints(rowConstraints);
153
-	}
154
-
155
-	/** Returns layout constraints eighter as a <code>String</code> or {@link net.miginfocom.layout.LC} depending what was sent in
156
-	 * to the constructor or set with {@link #setLayoutConstraints(Object)}.
157
-	 * @return The layout constraints eighter as a <code>String</code> or {@link net.miginfocom.layout.LC} depending what was sent in
158
-	 * to the constructor or set with {@link #setLayoutConstraints(Object)}. Never <code>null</code>.
159
-	 */
160
-	public Object getLayoutConstraints()
161
-	{
162
-		return layoutConstraints;
163
-	}
164
-
165
-	/** Sets the layout constraints for the layout manager instance as a String.
166
-	 * <p>
167
-	 * See the class JavaDocs for information on how this string is formatted.
168
-	 * @param constr The layout constraints as a String representation. <code>null</code> is converted to <code>""</code> for storage.
169
-	 * @throws RuntimeException if the constaint was not valid.
170
-	 */
171
-	public void setLayoutConstraints(Object constr)
172
-	{
173
-		if (constr == null || constr instanceof String) {
174
-			constr = ConstraintParser.prepare((String) constr);
175
-			lc = ConstraintParser.parseLayoutConstraint((String) constr);
176
-		} else if (constr instanceof LC) {
177
-			lc = (LC) constr;
178
-		} else {
179
-			throw new IllegalArgumentException("Illegal constraint type: " + constr.getClass().toString());
180
-		}
181
-		layoutConstraints = constr;
182
-		dirty = true;
183
-	}
184
-
185
-	/** Returns the column layout constraints either as a <code>String</code> or {@link net.miginfocom.layout.AC}.
186
-	 * @return The column constraints eighter as a <code>String</code> or {@link net.miginfocom.layout.LC} depending what was sent in
187
-	 * to the constructor or set with {@link #setLayoutConstraints(Object)}. Never <code>null</code>.
188
-	 */
189
-	public Object getColumnConstraints()
190
-	{
191
-		return colConstraints;
192
-	}
193
-
194
-	/** Sets the column layout constraints for the layout manager instance as a String.
195
-	 * <p>
196
-	 * See the class JavaDocs for information on how this string is formatted.
197
-	 * @param constr The column layout constraints as a String representation. <code>null</code> is converted to <code>""</code> for storage.
198
-	 * @throws RuntimeException if the constaint was not valid.
199
-	 */
200
-	public void setColumnConstraints(Object constr)
201
-	{
202
-		if (constr == null || constr instanceof String) {
203
-			constr = ConstraintParser.prepare((String) constr);
204
-			colSpecs = ConstraintParser.parseColumnConstraints((String) constr);
205
-		} else if (constr instanceof AC) {
206
-			colSpecs = (AC) constr;
207
-		} else {
208
-			throw new IllegalArgumentException("Illegal constraint type: " + constr.getClass().toString());
209
-		}
210
-		colConstraints = constr;
211
-		dirty = true;
212
-	}
213
-
214
-	/** Returns the row layout constraints as a String representation. This string is the exact string as set with {@link #setRowConstraints(Object)}
215
-	 * or sent into the constructor.
216
-	 * <p>
217
-	 * See the class JavaDocs for information on how this string is formatted.
218
-	 * @return The row layout constraints as a String representation. Never <code>null</code>.
219
-	 */
220
-	public Object getRowConstraints()
221
-	{
222
-		return rowConstraints;
223
-	}
224
-
225
-	/** Sets the row layout constraints for the layout manager instance as a String.
226
-	 * <p>
227
-	 * See the class JavaDocs for information on how this string is formatted.
228
-	 * @param constr The row layout constraints as a String representation. <code>null</code> is converted to <code>""</code> for storage.
229
-	 * @throws RuntimeException if the constaint was not valid.
230
-	 */
231
-	public void setRowConstraints(Object constr)
232
-	{
233
-		if (constr == null || constr instanceof String) {
234
-			constr = ConstraintParser.prepare((String) constr);
235
-			rowSpecs = ConstraintParser.parseRowConstraints((String) constr);
236
-		} else if (constr instanceof AC) {
237
-			rowSpecs = (AC) constr;
238
-		} else {
239
-			throw new IllegalArgumentException("Illegal constraint type: " + constr.getClass().toString());
240
-		}
241
-		rowConstraints = constr;
242
-		dirty = true;
243
-	}
244
-
245
-	/** Returns the component constraints as a String representation. This string is the exact string as set with {@link #setComponentConstraints(java.awt.Component, Object)}
246
-	 * or set when adding the component to the parent component.
247
-	 * <p>
248
-	 * See the class JavaDocs for information on how this string is formatted.
249
-	 * @param comp The component to return the constraints for.
250
-	 * @return The component constraints as a String representation ir <code>null</code> if the component is not registered
251
-	 * with this layout manager. The returned values is either a String or a {@link net.miginfocom.layout.CC}
252
-	 * depending on what constraint was sent in when the component was added. May be <code>null</code>.
253
-	 */
254
-	public Object getComponentConstraints(Component comp)
255
-	{
256
-		synchronized(comp.getParent().getTreeLock()) {
257
-			return scrConstrMap.get(comp);
258
-		}
259
-	}
260
-
261
-	/** Sets the component constraint for the component that already must be handleded by this layout manager.
262
-	 * <p>
263
-	 * See the class JavaDocs for information on how this string is formatted.
264
-	 * @param constr The component constraints as a String or {@link net.miginfocom.layout.CC}. <code>null</code> is ok.
265
-	 * @param comp The component to set the constraints for.
266
-	 * @throws RuntimeException if the constaint was not valid.
267
-	 * @throws IllegalArgumentException If the component is not handlering the component.
268
-	 */
269
-	public void setComponentConstraints(Component comp, Object constr)
270
-	{
271
-		setComponentConstraintsImpl(comp, constr, false);
272
-	}
273
-
274
-	/** Sets the component constraint for the component that already must be handleded by this layout manager.
275
-	 * <p>
276
-	 * See the class JavaDocs for information on how this string is formatted.
277
-	 * @param constr The component constraints as a String or {@link net.miginfocom.layout.CC}. <code>null</code> is ok.
278
-	 * @param comp The component to set the constraints for.
279
-	 * @param noCheck Doe not check if the component is handled if true
280
-	 * @throws RuntimeException if the constaint was not valid.
281
-	 * @throws IllegalArgumentException If the component is not handling the component.
282
-	 */
283
-	private void setComponentConstraintsImpl(Component comp, Object constr, boolean noCheck)
284
-	{
285
-		Container parent = comp.getParent();
286
-		synchronized(parent.getTreeLock()) {
287
-			if (noCheck == false && scrConstrMap.containsKey(comp) == false)
288
-				throw new IllegalArgumentException("Component must already be added to parent!");
289
-
290
-			ComponentWrapper cw = new SwingComponentWrapper(comp);
291
-
292
-			if (constr == null || constr instanceof String) {
293
-				String cStr = ConstraintParser.prepare((String) constr);
294
-
295
-				scrConstrMap.put(comp, constr);
296
-				ccMap.put(cw, ConstraintParser.parseComponentConstraint(cStr));
297
-
298
-			} else if (constr instanceof CC) {
299
-
300
-				scrConstrMap.put(comp, constr);
301
-				ccMap.put(cw, (CC) constr);
302
-
303
-			} else {
304
-				throw new IllegalArgumentException("Constraint must be String or ComponentConstraint: " + constr.getClass().toString());
305
-			}
306
-
307
-			dirty = true;
308
-		}
309
-	}
310
-
311
-	/** Returns if this layout manager is currently managing this component.
312
-	 * @param c The component to check. If <code>null</code> then <code>false</code> will be returned.
313
-	 * @return If this layout manager is currently managing this component.
314
-	 */
315
-	public boolean isManagingComponent(Component c)
316
-	{
317
-		return scrConstrMap.containsKey(c);
318
-	}
319
-
320
-	/** Adds the callback function that will be called at different stages of the layout cylce.
321
-	 * @param callback The callback. Not <code>null</code>.
322
-	 */
323
-	public void addLayoutCallback(LayoutCallback callback)
324
-	{
325
-		if (callback == null)
326
-			throw new NullPointerException();
327
-
328
-		if (callbackList == null)
329
-			callbackList = new ArrayList<LayoutCallback>(1);
330
-
331
-		callbackList.add(callback);
332
-	}
333
-
334
-	/** Removes the callback if it exists.
335
-	 * @param callback The callback. May be <code>null</code>.
336
-	 */
337
-	public void removeLayoutCallback(LayoutCallback callback)
338
-	{
339
-		if (callbackList != null)
340
-			callbackList.remove(callback);
341
-	}
342
-
343
-	/** Sets the debugging state for this layout manager instance. If debug is turned on a timer will repaint the last laid out parent
344
-	 * with debug information on top.
345
-	 * <p>
346
-	 * Red fill and dashed darked red outline is used to indicate occupied cells in the grid. Blue dashed outline indicate indicate
347
-	 * component bounds set.
348
-	 * <p>
349
-	 * Note that debug can also be set on the layout constraints. There it will be persisted. The value set here will not. See the class
350
-	 * JavaDocs for information.
351
-	 * @param parentW The parent to set debug for.
352
-	 * @param b <code>true</code> means debug is turned on.
353
-	 */
354
-	private synchronized void setDebug(final ComponentWrapper parentW, boolean b)
355
-	{
356
-		if (b && (debugTimer == null || debugTimer.getDelay() != lc.getDebugMillis())) {
357
-			if (debugTimer != null)
358
-				debugTimer.stop();
359
-
360
-			ContainerWrapper pCW = parentW.getParent();
361
-			final Component parent = pCW != null ? (Component) pCW.getComponent() : null;
362
-
363
-			debugTimer = new Timer(lc.getDebugMillis(), new MyDebugRepaintListener(MigLayout.this));
364
-
365
-			if (parent != null) {
366
-				SwingUtilities.invokeLater(new Runnable() {
367
-					public void run() {
368
-						Container p = parent.getParent();
369
-						if (p != null) {
370
-							if (p instanceof JComponent) {
371
-								((JComponent) p).revalidate();
372
-							} else {
373
-								parent.invalidate();
374
-								p.validate();
375
-							}
376
-						}
377
-					}
378
-				});
379
-			}
380
-
381
-			debugTimer.setInitialDelay(100);
382
-			debugTimer.start();
383
-
384
-		} else if (!b && debugTimer != null) {
385
-			debugTimer.stop();
386
-			debugTimer = null;
387
-		}
388
-	}
389
-
390
-	/** Returns the current debugging state.
391
-	 * @return The current debugging state.
392
-	 */
393
-	private boolean getDebug()
394
-	{
395
-		return debugTimer != null;
396
-	}
397
-
398
-	/** Check if something has changed and if so recrete it to the cached objects.
399
-	 * @param parent The parent that is the target for this layout manager.
400
-	 */
401
-	private void checkCache(Container parent)
402
-	{
403
-		if (parent == null)
404
-			return;
405
-
406
-		if (dirty)
407
-			grid = null;
408
-
409
-		// Check if the grid is valid
410
-		int mc = PlatformDefaults.getModCount();
411
-		if (lastModCount != mc) {
412
-			grid = null;
413
-			lastModCount = mc;
414
-		}
415
-
416
-		if (parent.isValid() == false) {
417
-
418
-			int hash = 0;
419
-			for (Iterator<ComponentWrapper> it = ccMap.keySet().iterator(); it.hasNext();)
420
-				hash += it.next().getLayoutHashCode();
421
-
422
-			if (hash != lastHash) {
423
-				grid = null;
424
-				lastHash = hash;
425
-			}
426
-
427
-			Dimension ps = parent.getSize();
428
-			if (lastInvalidSize == null || !lastInvalidSize.equals(ps)) {
429
-				if (grid != null)
430
-					grid.invalidateContainerSize();
431
-				lastInvalidSize = ps;
432
-			}
433
-		}
434
-
435
-		ContainerWrapper par = checkParent(parent);
436
-
437
-		setDebug(par, lc.getDebugMillis() > 0);
438
-
439
-		if (grid == null)
440
-			grid = new Grid(par, lc, rowSpecs, colSpecs, ccMap, callbackList);
441
-
442
-		dirty = false;
443
-	}
444
-
445
-	private ContainerWrapper checkParent(Container parent)
446
-	{
447
-		if (parent == null)
448
-			return null;
449
-
450
-		if (cacheParentW == null || cacheParentW.getComponent() != parent)
451
-			cacheParentW = new SwingContainerWrapper(parent);
452
-
453
-		return cacheParentW;
454
-	}
455
-
456
-	private long lastSize = 0;
457
-
458
-	public void layoutContainer(final Container parent)
459
-	{
460
-		synchronized(parent.getTreeLock()) {
461
-			checkCache(parent);
462
-
463
-			Insets i = parent.getInsets();
464
-			int[] b = new int[] {
465
-					i.left,
466
-					i.top,
467
-					parent.getWidth() - i.left - i.right,
468
-					parent.getHeight() - i.top - i.bottom
469
-			};
470
-
471
-			if (grid.layout(b, lc.getAlignX(), lc.getAlignY(), getDebug(), true)) {
472
-				grid = null;
473
-				checkCache(parent);
474
-				grid.layout(b, lc.getAlignX(), lc.getAlignY(), getDebug(), false);
475
-			}
476
-
477
-			long newSize = grid.getHeight()[1] + (((long) grid.getWidth()[1]) << 32);
478
-			if (lastSize != newSize) {
479
-				lastSize = newSize;
480
-				SwingUtilities.invokeLater(new Runnable() { // Added 2008-12-04
481
-					public void run() {
482
-						adjustWindowSize(checkParent(parent));
483
-					}
484
-				});
485
-			}
486
-
487
-			lastInvalidSize = null;
488
-		}
489
-	}
490
-
491
-	/** Checks the parent window if its size is within parameters as set by the LC.
492
-	 * @param parent The parent who's window to possibly adjust the size for.
493
-	 */
494
-	private void adjustWindowSize(ContainerWrapper parent)
495
-	{
496
-		BoundSize wBounds = lc.getPackWidth();
497
-		BoundSize hBounds = lc.getPackHeight();
498
-
499
-		if (wBounds == null && hBounds == null)
500
-			return;
501
-
502
-		Window win = ((Window) SwingUtilities.getAncestorOfClass(Window.class, (Component) parent.getComponent()));
503
-		if (win == null)
504
-			return;
505
-
506
-		Dimension prefSize = win.getPreferredSize();
507
-		int targW = constrain(checkParent(win), win.getWidth(), prefSize.width, wBounds);
508
-		int targH = constrain(checkParent(win), win.getHeight(), prefSize.height, hBounds);
509
-
510
-		int x = Math.round(win.getX() - ((targW - win.getWidth()) * (1 - lc.getPackWidthAlign())));
511
-		int y = Math.round(win.getY() - ((targH - win.getHeight()) * (1 - lc.getPackHeightAlign())));
512
-
513
-		win.setBounds(x, y, targW, targH);
514
-	}
515
-
516
-	private int constrain(ContainerWrapper parent, int winSize, int prefSize, BoundSize constrain)
517
-	{
518
-		if (constrain == null)
519
-			return winSize;
520
-
521
-		int retSize = winSize;
522
-		UnitValue wUV = constrain.getPreferred();
523
-		if (wUV != null)
524
-			retSize = wUV.getPixels(prefSize, parent, parent);
525
-
526
-		retSize = constrain.constrain(retSize, prefSize, parent);
527
-
528
-		return constrain.getGapPush() ? Math.max(winSize, retSize) : retSize;
529
-	}
530
-
531
-	public Dimension minimumLayoutSize(Container parent)
532
-	{
533
-		synchronized(parent.getTreeLock()) {
534
-			return getSizeImpl(parent, LayoutUtil.MIN);
535
-		}
536
-	}
537
-
538
-	public Dimension preferredLayoutSize(Container parent)
539
-	{
540
-		synchronized(parent.getTreeLock()) {
541
-			return getSizeImpl(parent, LayoutUtil.PREF);
542
-		}
543
-	}
544
-
545
-	public Dimension maximumLayoutSize(Container parent)
546
-	{
547
-		return new Dimension(Short.MAX_VALUE, Short.MAX_VALUE);
548
-	}
549
-
550
-	// Implementation method that does the job.
551
-	private Dimension getSizeImpl(Container parent, int sizeType)
552
-	{
553
-		checkCache(parent);
554
-
555
-		Insets i = parent.getInsets();
556
-
557
-		int w = LayoutUtil.getSizeSafe(grid != null ? grid.getWidth() : null, sizeType) + i.left + i.right;
558
-		int h = LayoutUtil.getSizeSafe(grid != null ? grid.getHeight() : null, sizeType) + i.top + i.bottom;
559
-
560
-		return new Dimension(w, h);
561
-	}
562
-
563
-	public float getLayoutAlignmentX(Container parent)
564
-	{
565
-		return lc != null && lc.getAlignX() != null ? lc.getAlignX().getPixels(1, checkParent(parent), null) : 0;
566
-	}
567
-
568
-	public float getLayoutAlignmentY(Container parent)
569
-	{
570
-		return lc != null && lc.getAlignY() != null ? lc.getAlignY().getPixels(1, checkParent(parent), null) : 0;
571
-	}
572
-
573
-	public void addLayoutComponent(String s, Component comp)
574
-	{
575
-		addLayoutComponent(comp, s);
576
-	}
577
-
578
-	public void addLayoutComponent(Component comp, Object constraints)
579
-	{
580
-		synchronized(comp.getParent().getTreeLock()) {
581
-			setComponentConstraintsImpl(comp, constraints, true);
582
-		}
583
-	}
584
-
585
-	public void removeLayoutComponent(Component comp)
586
-	{
587
-		synchronized(comp.getParent().getTreeLock()) {
588
-			scrConstrMap.remove(comp);
589
-			ccMap.remove(new SwingComponentWrapper(comp));
590
-		}
591
-	}
592
-
593
-	public void invalidateLayout(Container target)
594
-	{
595
-//		if (lc.isNoCache())  // Commented for 3.5 since there was too often that the "nocache" was needed and the user did not know.
596
-		dirty = true;
597
-
598
-		// the validity of components is maintained automatically.
599
-	}
600
-
601
-	// ************************************************
602
-	// Persistence Delegate and Serializable combined.
603
-	// ************************************************
604
-
605
-	private Object readResolve() throws ObjectStreamException
606
-	{
607
-		return LayoutUtil.getSerializedObject(this);
608
-	}
609
-
610
-	public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
611
-	{
612
-		LayoutUtil.setSerializedObject(this, LayoutUtil.readAsXML(in));
613
-	}
614
-
615
-	public void writeExternal(ObjectOutput out) throws IOException
616
-	{
617
-		if (getClass() == MigLayout.class)
618
-			LayoutUtil.writeAsXML(out, this);
619
-	}
620
-
621
-	private static class MyDebugRepaintListener implements ActionListener
622
-	{
623
-		private final WeakReference<MigLayout> layoutRef;
624
-
625
-		private MyDebugRepaintListener(MigLayout layout)
626
-		{
627
-			this.layoutRef = new WeakReference<MigLayout>(layout);
628
-		}
629
-
630
-		public void actionPerformed(ActionEvent e)
631
-		{
632
-			MigLayout layout = layoutRef.get();
633
-			if (layout != null && layout.grid != null)
634
-				layout.grid.paintDebug();
635
-		}
636
-	}
637
-}

+ 0
- 452
src/net/miginfocom/swing/SwingComponentWrapper.java Vedi File

@@ -1,452 +0,0 @@
1
-package net.miginfocom.swing;
2
-/*
3
- * License (BSD):
4
- * ==============
5
- *
6
- * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
7
- * All rights reserved.
8
- *
9
- * Redistribution and use in source and binary forms, with or without modification,
10
- * are permitted provided that the following conditions are met:
11
- * Redistributions of source code must retain the above copyright notice, this list
12
- * of conditions and the following disclaimer.
13
- * Redistributions in binary form must reproduce the above copyright notice, this
14
- * list of conditions and the following disclaimer in the documentation and/or other
15
- * materials provided with the distribution.
16
- * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
17
- * used to endorse or promote products derived from this software without specific
18
- * prior written permission.
19
- *
20
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23
- * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
26
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
29
- * OF SUCH DAMAGE.
30
- *
31
- * @version 1.0
32
- * @author Mikael Grev, MiG InfoCom AB
33
- *         Date: 2006-sep-08
34
- */
35
-import net.miginfocom.layout.ComponentWrapper;
36
-import net.miginfocom.layout.ContainerWrapper;
37
-import net.miginfocom.layout.PlatformDefaults;
38
-
39
-import javax.swing.*;
40
-import javax.swing.text.JTextComponent;
41
-import java.awt.*;
42
-import java.awt.geom.Rectangle2D;
43
-import java.lang.reflect.Method;
44
-import java.util.IdentityHashMap;
45
-
46
-/**
47
- */
48
-public class SwingComponentWrapper implements ComponentWrapper
49
-{
50
-	private static boolean maxSet = false;
51
-
52
-	private static boolean vp = true;
53
-
54
-	/** Debug color for component bounds outline.
55
-	 */
56
-	private static final Color DB_COMP_OUTLINE = new Color(0, 0, 200);
57
-
58
-	private final Component c;
59
-	private int compType = TYPE_UNSET;
60
-	private Boolean bl = null;
61
-	private boolean prefCalled = false;
62
-
63
-	public SwingComponentWrapper(Component c)
64
-	{
65
-		this.c = c;
66
-	}
67
-
68
-	public final int getBaseline(int width, int height)
69
-	{
70
-		if (BL_METHOD == null)
71
-			return -1;
72
-
73
-		try {
74
-			Object[] args = new Object[] {
75
-				new Integer(width < 0 ? c.getWidth() : width),
76
-				new Integer(height < 0 ? c.getHeight() : height)
77
-			};
78
-			return ((Integer) BL_METHOD.invoke(c, args)).intValue();
79
-		} catch (Exception e) {
80
-			return -1;
81
-		}
82
-	}
83
-
84
-	public final Object getComponent()
85
-	{
86
-		return c;
87
-	}
88
-
89
-	/** Cache.
90
-	 */
91
-	private final static IdentityHashMap<FontMetrics, Point.Float> FM_MAP = new IdentityHashMap<FontMetrics, Point.Float>(4);
92
-	private final static Font SUBST_FONT = new Font("sansserif", Font.PLAIN, 11);
93
-
94
-	public final float getPixelUnitFactor(boolean isHor)
95
-	{
96
-		switch (PlatformDefaults.getLogicalPixelBase()) {
97
-			case PlatformDefaults.BASE_FONT_SIZE:
98
-				Font font = c.getFont();
99
-				FontMetrics fm = c.getFontMetrics(font != null ? font : SUBST_FONT);
100
-				Point.Float p = FM_MAP.get(fm);
101
-				if (p == null) {
102
-					Rectangle2D r = fm.getStringBounds("X", c.getGraphics());
103
-					p = new Point.Float(((float) r.getWidth()) / 6f, ((float) r.getHeight()) / 13.27734375f);
104
-					FM_MAP.put(fm, p);
105
-				}
106
-				return isHor ? p.x : p.y;
107
-
108
-			case PlatformDefaults.BASE_SCALE_FACTOR:
109
-
110
-				Float s = isHor ? PlatformDefaults.getHorizontalScaleFactor() : PlatformDefaults.getVerticalScaleFactor();
111
-				if (s != null)
112
-					return s.floatValue();
113
-				return (isHor ? getHorizontalScreenDPI() : getVerticalScreenDPI()) / (float) PlatformDefaults.getDefaultDPI();
114
-
115
-			default:
116
-				return 1f;
117
-		}
118
-	}
119
-
120
-//	/** Cache.
121
-//	 */
122
-//	private final static IdentityHashMap<FontMetrics, Point.Float> FM_MAP2 = new IdentityHashMap<FontMetrics, Point.Float>(4);
123
-//	private final static Font SUBST_FONT2 = new Font("sansserif", Font.PLAIN, 11);
124
-//
125
-//	public float getDialogUnit(boolean isHor)
126
-//	{
127
-//		Font font = c.getFont();
128
-//		FontMetrics fm = c.getFontMetrics(font != null ? font : SUBST_FONT2);
129
-//		Point.Float dluP = FM_MAP2.get(fm);
130
-//		if (dluP == null) {
131
-//			float w = fm.charWidth('X') / 4f;
132
-//			int ascent = fm.getAscent();
133
-//			float h = (ascent > 14 ? ascent : ascent + (15 - ascent) / 3) / 8f;
134
-//
135
-//			dluP = new Point.Float(w, h);
136
-//			FM_MAP2.put(fm, dluP);
137
-//		}
138
-//		return isHor ? dluP.x : dluP.y;
139
-//	}
140
-
141
-	public final int getX()
142
-	{
143
-		return c.getX();
144
-	}
145
-
146
-	public final int getY()
147
-	{
148
-		return c.getY();
149
-	}
150
-
151
-	public final int getHeight()
152
-	{
153
-		return c.getHeight();
154
-	}
155
-
156
-	public final int getWidth()
157
-	{
158
-		return c.getWidth();
159
-	}
160
-
161
-	public final int getScreenLocationX()
162
-	{
163
-		Point p = new Point();
164
-		SwingUtilities.convertPointToScreen(p, c);
165
-		return p.x;
166
-	}
167
-
168
-	public final int getScreenLocationY()
169
-	{
170
-		Point p = new Point();
171
-		SwingUtilities.convertPointToScreen(p, c);
172
-		return p.y;
173
-	}
174
-
175
-	public final int getMinimumHeight(int sz)
176
-	{
177
-		if (prefCalled == false) {
178
-			c.getPreferredSize(); // To defeat a bug where the minimum size is different before and after the first call to getPreferredSize();
179
-			prefCalled = true;
180
-		}
181
-		return c.getMinimumSize().height;
182
-	}
183
-
184
-	public final int getMinimumWidth(int sz)
185
-	{
186
-		if (prefCalled == false) {
187
-			c.getPreferredSize(); // To defeat a bug where the minimum size is different before and after the first call to getPreferredSize();
188
-			prefCalled = true;
189
-		}
190
-		return c.getMinimumSize().width;
191
-	}
192
-
193
-	public final int getPreferredHeight(int sz)
194
-	{
195
-		// If the component has not got size yet and there is a size hint, trick Swing to return a better height.
196
-		if (c.getWidth() == 0 && c.getHeight() == 0 && sz != -1)
197
-			setBounds(c.getX(), c.getY(), sz, 1);
198
-
199
-		return c.getPreferredSize().height;
200
-	}
201
-
202
-	public final int getPreferredWidth(int sz)
203
-	{
204
-		// If the component has not got size yet and there is a size hint, trick Swing to return a better height.
205
-		if (c.getWidth() == 0 && c.getHeight() == 0 && sz != -1)
206
-			setBounds(c.getX(), c.getY(), 1, sz);
207
-
208
-		return c.getPreferredSize().width;
209
-	}
210
-
211
-	public final int getMaximumHeight(int sz)
212
-	{
213
-		if (!isMaxSet(c))
214
-			return Short.MAX_VALUE;
215
-
216
-		return c.getMaximumSize().height;
217
-	}
218
-
219
-	public final int getMaximumWidth(int sz)
220
-	{
221
-		if (!isMaxSet(c))
222
-			return Short.MAX_VALUE;
223
-
224
-		return c.getMaximumSize().width;
225
-	}
226
-
227
-
228
-	private boolean isMaxSet(Component c)
229
-	{
230
-		if (IMS_METHOD != null) {
231
-			try {
232
-				return ((Boolean) IMS_METHOD.invoke(c, (Object[]) null)).booleanValue();
233
-			} catch (Exception e) {
234
-				IMS_METHOD = null;  // So we do not try every time.
235
-			}
236
-		}
237
-		return isMaxSizeSetOn1_4();
238
-	}
239
-
240
-	public final ContainerWrapper getParent()
241
-	{
242
-		Container p = c.getParent();
243
-		return p != null ? new SwingContainerWrapper(p) : null;
244
-	}
245
-
246
-	public final int getHorizontalScreenDPI()
247
-	{
248
-		return PlatformDefaults.getDefaultDPI();
249
-	}
250
-
251
-	public final int getVerticalScreenDPI()
252
-	{
253
-		return PlatformDefaults.getDefaultDPI();
254
-	}
255
-
256
-	public final int getScreenWidth()
257
-	{
258
-		try {
259
-			return c.getToolkit().getScreenSize().width;
260
-		} catch (HeadlessException ex) {
261
-			return 1024;
262
-		}
263
-	}
264
-
265
-	public final int getScreenHeight()
266
-	{
267
-		try {
268
-			return c.getToolkit().getScreenSize().height;
269
-		} catch (HeadlessException ex) {
270
-			return 768;
271
-		}
272
-	}
273
-
274
-	public final boolean hasBaseline()
275
-	{
276
-		if (bl == null) {
277
-			Dimension d = c.getMinimumSize();
278
-			bl = new Boolean(getBaseline(d.width, d.height) > -1);
279
-		}
280
-		return bl.booleanValue();
281
-	}
282
-
283
-	public final String getLinkId()
284
-	{
285
-		return c.getName();
286
-	}
287
-
288
-	public final void setBounds(int x, int y, int width, int height)
289
-	{
290
-		c.setBounds(x, y, width, height);
291
-	}
292
-
293
-	public boolean isVisible()
294
-	{
295
-		return c.isVisible();
296
-	}
297
-
298
-	public final int[] getVisualPadding()
299
-	{
300
-		if (vp && c instanceof JTabbedPane) {
301
-			if (UIManager.getLookAndFeel().getClass().getName().endsWith("WindowsLookAndFeel"))
302
-				return new int[] {-1, 0, 2, 2};
303
-		}
304
-		return null;
305
-	}
306
-
307
-	public static boolean isMaxSizeSetOn1_4()
308
-	{
309
-		return maxSet;
310
-	}
311
-
312
-	public static void setMaxSizeSetOn1_4(boolean b)
313
-	{
314
-		maxSet = b;
315
-	}
316
-
317
-	public final static boolean isVisualPaddingEnabled()
318
-	{
319
-		return vp;
320
-	}
321
-
322
-	public final static void setVisualPaddingEnabled(boolean b)
323
-	{
324
-		vp = b;
325
-	}
326
-
327
-	public final void paintDebugOutline()
328
-	{
329
-		if (c.isShowing() == false)
330
-			return;
331
-
332
-		Graphics2D g = (Graphics2D) c.getGraphics();
333
-		if (g == null)
334
-			return;
335
-
336
-		g.setPaint(DB_COMP_OUTLINE);
337
-		g.setStroke(new BasicStroke(1f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10f, new float[] {2f, 4f}, 0));
338
-		g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
339
-	}
340
-
341
-	public int getComponetType(boolean disregardScrollPane)
342
-	{
343
-		if (compType == TYPE_UNSET)
344
-			compType = checkType(disregardScrollPane);
345
-
346
-		return compType;
347
-	}
348
-
349
-	public int getLayoutHashCode()
350
-	{
351
-		Dimension d = c.getMaximumSize();
352
-		int h = d.width + (d.height << 5);
353
-
354
-		d = c.getPreferredSize();
355
-		h += (d.width << 10) + (d.height << 15);
356
-
357
-		d = c.getMinimumSize();
358
-		h += (d.width << 20) + (d.height << 25);
359
-
360
-		if (c.isVisible())
361
-			h += 1324511;
362
-
363
-		String id = getLinkId();
364
-		if (id != null)
365
-			h += id.hashCode();
366
-		return h;
367
-
368
-		// Since 2.3 will check the isValid instead everything that affects that can be removed from the layout hashcode.
369
-
370
-//		String id = getLinkId();
371
-//		return id != null ? id.hashCode() : 1;
372
-	}
373
-
374
-	private final int checkType(boolean disregardScrollPane)
375
-	{
376
-		Component c = this.c;
377
-
378
-		if (disregardScrollPane) {
379
-			if (c instanceof JScrollPane) {
380
-				c = ((JScrollPane) c).getViewport().getView();
381
-			} else if (c instanceof ScrollPane) {
382
-				c = ((ScrollPane) c).getComponent(0);
383
-			}
384
-		}
385
-
386
-		if (c instanceof JTextField || c instanceof TextField) {
387
-			return TYPE_TEXT_FIELD;
388
-		} else if (c instanceof JLabel || c instanceof Label) {
389
-			return TYPE_LABEL;
390
-		} else if (c instanceof JToggleButton || c instanceof Checkbox) {
391
-			return TYPE_CHECK_BOX;
392
-		} else if (c instanceof AbstractButton || c instanceof Button) {
393
-			return TYPE_BUTTON;
394
-		} else if (c instanceof JComboBox || c instanceof Choice) {
395
-			return TYPE_LABEL;
396
-		} else if (c instanceof JTextComponent || c instanceof TextComponent) {
397
-			return TYPE_TEXT_AREA;
398
-		} else if (c instanceof JPanel || c instanceof Canvas) {
399
-			return TYPE_PANEL;
400
-		} else if (c instanceof JList || c instanceof List) {
401
-			return TYPE_LIST;
402
-		} else if (c instanceof JTable) {
403
-			return TYPE_TABLE;
404
-		} else if (c instanceof JSeparator) {
405
-			return TYPE_SEPARATOR;
406
-		} else if (c instanceof JSpinner) {
407
-			return TYPE_SPINNER;
408
-		} else if (c instanceof JProgressBar) {
409
-			return TYPE_PROGRESS_BAR;
410
-		} else if (c instanceof JSlider) {
411
-			return TYPE_SLIDER;
412
-		} else if (c instanceof JScrollPane) {
413
-			return TYPE_SCROLL_PANE;
414
-		} else if (c instanceof JScrollBar || c instanceof Scrollbar) {
415
-			return TYPE_SCROLL_BAR;
416
-		} else if (c instanceof Container) {    // only AWT components is not containers.
417
-			return TYPE_CONTAINER;
418
-		}
419
-		return TYPE_UNKNOWN;
420
-	}
421
-
422
-	public final int hashCode()
423
-	{
424
-		return getComponent().hashCode();
425
-	}
426
-
427
-	public final boolean equals(Object o)
428
-	{
429
-		if (o instanceof ComponentWrapper == false)
430
-			return false;
431
-
432
-		return getComponent().equals(((ComponentWrapper) o).getComponent());
433
-	}
434
-
435
-	/** Cached method used for getting base line with reflection.
436
-	 */
437
-	private static Method BL_METHOD = null;
438
-	static {
439
-		try {
440
-			BL_METHOD = Component.class.getDeclaredMethod("getBaseline", new Class[] {int.class, int.class});
441
-		} catch (Throwable e) { // No such method or security exception
442
-		}
443
-	}
444
-
445
-	private static Method IMS_METHOD = null;
446
-	static {
447
-		try {
448
-			IMS_METHOD = Component.class.getDeclaredMethod("isMaximumSizeSet", (Class[]) null);
449
-		} catch (Throwable e) { // No such method or security exception
450
-		}
451
-	}
452
-}

+ 0
- 108
src/net/miginfocom/swing/SwingContainerWrapper.java Vedi File

@@ -1,108 +0,0 @@
1
-package net.miginfocom.swing;
2
-/*
3
- * License (BSD):
4
- * ==============
5
- *
6
- * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
7
- * All rights reserved.
8
- *
9
- * Redistribution and use in source and binary forms, with or without modification,
10
- * are permitted provided that the following conditions are met:
11
- * Redistributions of source code must retain the above copyright notice, this list
12
- * of conditions and the following disclaimer.
13
- * Redistributions in binary form must reproduce the above copyright notice, this
14
- * list of conditions and the following disclaimer in the documentation and/or other
15
- * materials provided with the distribution.
16
- * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
17
- * used to endorse or promote products derived from this software without specific
18
- * prior written permission.
19
- *
20
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23
- * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
26
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
29
- * OF SUCH DAMAGE.
30
- *
31
- * @version 1.0
32
- * @author Mikael Grev, MiG InfoCom AB
33
- *         Date: 2006-sep-08
34
- */
35
-
36
-import net.miginfocom.layout.ComponentWrapper;
37
-import net.miginfocom.layout.ContainerWrapper;
38
-
39
-import java.awt.*;
40
-
41
-/**
42
- */
43
-public final class SwingContainerWrapper extends SwingComponentWrapper implements ContainerWrapper
44
-{
45
-	/** Debug color for cell outline.
46
-	 */
47
-	private static final Color DB_CELL_OUTLINE = new Color(255, 0, 0);
48
-
49
-	public SwingContainerWrapper(Container c)
50
-	{
51
-		super(c);
52
-	}
53
-
54
-	public ComponentWrapper[] getComponents()
55
-	{
56
-		Container c = (Container) getComponent();
57
-		ComponentWrapper[] cws = new ComponentWrapper[c.getComponentCount()];
58
-		for (int i = 0; i < cws.length; i++)
59
-			cws[i] = new SwingComponentWrapper(c.getComponent(i));
60
-		return cws;
61
-	}
62
-
63
-	public int getComponentCount()
64
-	{
65
-		return ((Container) getComponent()).getComponentCount();
66
-	}
67
-
68
-	public Object getLayout()
69
-	{
70
-		return ((Container) getComponent()).getLayout();
71
-	}
72
-
73
-	public final boolean isLeftToRight()
74
-	{
75
-		return ((Container) getComponent()).getComponentOrientation().isLeftToRight();
76
-	}
77
-
78
-	public final void paintDebugCell(int x, int y, int width, int height)
79
-	{
80
-		Component c = (Component) getComponent();
81
-		if (c.isShowing() == false)
82
-			return;
83
-
84
-		Graphics2D g = (Graphics2D) c.getGraphics();
85
-		if (g == null)
86
-			return;
87
-
88
-		g.setStroke(new BasicStroke(1f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10f, new float[] {2f, 3f}, 0));
89
-		g.setPaint(DB_CELL_OUTLINE);
90
-		g.drawRect(x, y, width - 1, height - 1);
91
-	}
92
-
93
-	public int getComponetType(boolean disregardScrollPane)
94
-	{
95
-		return TYPE_CONTAINER;
96
-	}
97
-
98
-	// Removed for 2.3 because the parent.isValid() in MigLayout will catch this instead.
99
-//	public int getLayoutHashCode()
100
-//	{
101
-//		int h = super.getLayoutHashCode();
102
-//
103
-//		if (isLeftToRight())
104
-//			h += 416343;
105
-//
106
-//		return h;
107
-//	}
108
-}

Loading…
Annulla
Salva