- java.lang.Object
-
- net.miginfocom.layout.LayoutUtil
-
public final class LayoutUtil extends java.lang.Object
A utility class that has only static helper methods.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.WeakHashMap<java.lang.Object,java.lang.String>
CR_MAP
private static java.util.WeakHashMap<java.lang.Object,java.lang.Boolean>
DT_MAP
private static int
eSz
private static int
globalDebugMillis
static boolean
HAS_BEANS
static int
HORIZONTAL
static int
INF
A substitute value for a really large value.static int
MAX
static int
MIN
(package private) static int
NOT_SET
Tag int for a value that in considered "not set".static int
PREF
private static byte[]
readBuf
private static java.util.IdentityHashMap<java.lang.Object,java.lang.Object>
SER_MAP
static int
VERTICAL
private static java.io.ByteArrayOutputStream
writeOutputStream
-
Constructor Summary
Constructors Modifier Constructor Description private
LayoutUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static int[]
calculateSerial(int[][] sizes, ResizeConstraint[] resConstr, java.lang.Float[] defPushWeights, int startSizeType, int bounds)
Takes a number on min/preferred/max sizes and resize constraints and returns the calculated sizes which sum should add up tobounds
.(package private) static float
clamp(float f, float min, float max)
Keeps f within min and max.(package private) static int
clamp(int i, int min, int max)
Keeps i within min and max.(package private) static BoundSize
derive(BoundSize bs, UnitValue min, UnitValue pref, UnitValue max)
(package private) static boolean
equals(java.lang.Object o1, java.lang.Object o2)
Safe equals.private static int
getBrokenBoundary(float sz, int lower, int upper)
Returns the broken boundary ifsz
is outside the boundarieslower
orupper
.(package private) static java.lang.String
getCCString(java.lang.Object con)
Returns strings set withputCCString(Object, String)
ornull
if nothing is associated orisDesignTime(ContainerWrapper)
returnsfalse
.static int
getDesignTimeEmptySize()
The size of an empty row or columns in a grid during design time.static int
getGlobalDebugMillis()
If global debug should be on or off.(package private) static java.lang.Object
getIndexSafe(java.lang.Object[] arr, int ix)
(package private) static UnitValue
getInsets(LC lc, int side, boolean getDefault)
Returns the insets for the side.static java.lang.Object
getSerializedObject(java.lang.Object caller)
Returns the serialized object that are associated withcaller
.static int
getSizeSafe(int[] sizes, int sizeType)
static java.lang.String
getVersion()
Returns the current version of MiG Layout.private static boolean
hasBeans()
static boolean
isDesignTime(ContainerWrapper cw)
Returns if design time is turned on for a Container inContainerWrapper
.static boolean
isLeftToRight(LC lc, ContainerWrapper container)
Returns if left-to-right orientation is used.(package private) static void
putCCString(java.lang.Object con, java.lang.String s)
Associatescon
with the creation strings
.static java.lang.Object
readAsXML(java.io.ObjectInput in)
Reads an object fromin
using the(package private) static int[]
roundSizes(float[] sizes)
Round a number of float sizes into int sizes so that the total length match up(package private) static void
setDelegate(java.lang.Class<?> c, java.beans.PersistenceDelegate del)
Sets/add the persistence delegates to be used for a class.static void
setDesignTime(ContainerWrapper cw, boolean b)
Sets if design time is turned on for a Container inContainerWrapper
.static void
setDesignTimeEmptySize(int pixels)
The size of an empty row or columns in a grid during design time.static void
setGlobalDebugMillis(int millis)
If global debug should be on or off.static void
setSerializedObject(java.lang.Object caller, java.lang.Object o)
Sets the serialized object and associates it withcaller
.(package private) static int
sum(int[] terms)
(package private) static int
sum(int[] terms, int start, int len)
(package private) static void
throwCC()
static void
writeAsXML(java.io.ObjectOutput out, java.lang.Object o)
Writes an object to XML.(package private) static void
writeXMLObject(java.io.OutputStream os, java.lang.Object o, java.beans.ExceptionListener listener)
Writes the object and CLOSES the stream.
-
-
-
Field Detail
-
INF
public static final int INF
A substitute value for a really large value. Integer.MAX_VALUE is not used since that means a lot of defensive code for potential overflow must exist in many places. This value is large enough for being unreasonable yet it is hard to overflow.- See Also:
- Constant Field Values
-
NOT_SET
static final int NOT_SET
Tag int for a value that in considered "not set". Used as "null" element in int arrays.- See Also:
- Constant Field Values
-
MIN
public static final int MIN
- See Also:
- Constant Field Values
-
PREF
public static final int PREF
- See Also:
- Constant Field Values
-
MAX
public static final int MAX
- See Also:
- Constant Field Values
-
HORIZONTAL
public static final int HORIZONTAL
- See Also:
- Constant Field Values
-
VERTICAL
public static final int VERTICAL
- See Also:
- Constant Field Values
-
CR_MAP
private static volatile java.util.WeakHashMap<java.lang.Object,java.lang.String> CR_MAP
-
DT_MAP
private static volatile java.util.WeakHashMap<java.lang.Object,java.lang.Boolean> DT_MAP
-
eSz
private static int eSz
-
globalDebugMillis
private static int globalDebugMillis
-
HAS_BEANS
public static final boolean HAS_BEANS
-
writeOutputStream
private static java.io.ByteArrayOutputStream writeOutputStream
-
readBuf
private static byte[] readBuf
-
SER_MAP
private static final java.util.IdentityHashMap<java.lang.Object,java.lang.Object> SER_MAP
-
-
Method Detail
-
hasBeans
private static boolean hasBeans()
-
getVersion
public static java.lang.String getVersion()
Returns the current version of MiG Layout.- Returns:
- The current version of MiG Layout. E.g. "3.6.3" or "4.0"
-
getGlobalDebugMillis
public static int getGlobalDebugMillis()
If global debug should be on or off. If > 0 then debug is turned on for all MigLayout instances.- Returns:
- The current debug milliseconds.
- See Also:
LC.setDebugMillis(int)
-
setGlobalDebugMillis
public static void setGlobalDebugMillis(int millis)
If global debug should be on or off. If > 0 then debug is turned on for all MigLayout instances.Note! This is a passive value and will be read by panels when the needed, which is normally when they repaint/layout.
- Parameters:
millis
- The new debug milliseconds. 0 turns of global debug and leaves debug up to every individual panel.- See Also:
LC.setDebugMillis(int)
-
setDesignTime
public static void setDesignTime(ContainerWrapper cw, boolean b)
Sets if design time is turned on for a Container inContainerWrapper
.- Parameters:
cw
- The container to set design time for.null
is legal and can be used as a key to turn on/off design time "in general". Note though that design time "in general" is always on as long as there is at least one ContainerWrapper with design time.If this method has not ever been called it will default to what
Beans.isDesignTime()
returns. This means that if you call this method you indicate that you will take responsibility for the design time value.b
-true
means design time on.
-
isDesignTime
public static boolean isDesignTime(ContainerWrapper cw)
Returns if design time is turned on for a Container inContainerWrapper
.- Parameters:
cw
- The container to set design time for.null
is legal will returntrue
if there is at least oneContainerWrapper
(ornull
) that have design time turned on.- Returns:
- If design time is set for
cw
.
-
getDesignTimeEmptySize
public static int getDesignTimeEmptySize()
The size of an empty row or columns in a grid during design time.- Returns:
- The number of pixels. Default is 15.
-
setDesignTimeEmptySize
public static void setDesignTimeEmptySize(int pixels)
The size of an empty row or columns in a grid during design time.- Parameters:
pixels
- The number of pixels. Default is 0 (it was 15 prior to v3.7.2, but since that meant different behaviour under design time by default it was changed to be 0, same as non-design time). IDE vendors can still set it to 15 to get the old behaviour.
-
putCCString
static void putCCString(java.lang.Object con, java.lang.String s)
Associatescon
with the creation strings
. Thecon
object should probably have an equals method that compares identities orcon
objects that .equals() will only be able to have one creation string.If
isDesignTime(ContainerWrapper)
returnsfalse
the method does nothing.- Parameters:
con
- The object. ifnull
the method does nothing.s
- The creation string. ifnull
the method does nothing.
-
setDelegate
static void setDelegate(java.lang.Class<?> c, java.beans.PersistenceDelegate del)
Sets/add the persistence delegates to be used for a class.- Parameters:
c
- The class to set the registered delegate for.del
- The new delegate ornull
to erase to old one.
-
getCCString
static java.lang.String getCCString(java.lang.Object con)
Returns strings set withputCCString(Object, String)
ornull
if nothing is associated orisDesignTime(ContainerWrapper)
returnsfalse
.- Parameters:
con
- The constrain object.- Returns:
- The creation string or
null
if nothing is registered with thecon
object.
-
throwCC
static void throwCC()
-
calculateSerial
static int[] calculateSerial(int[][] sizes, ResizeConstraint[] resConstr, java.lang.Float[] defPushWeights, int startSizeType, int bounds)
Takes a number on min/preferred/max sizes and resize constraints and returns the calculated sizes which sum should add up tobounds
. Whether the sum will actually equalbounds
is dependent on the pref/max sizes and resize constraints.- Parameters:
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) but if the array itself is null it will not get any size.resConstr
- Elements can benull
and the whole array can benull
.null
means that the size will not be flexible at all. Can have length less thansizes
in which case the last element should be used for the elements missing.defPushWeights
- If there is no grow weight for a resConstr the corresponding value of this array is used. These forced resConstr will be grown last though and only if needed to fill to the bounds.startSizeType
- The initial size to use. E.g.MIN
.bounds
- To use for relative sizes.- Returns:
- The sizes. Array length will match
sizes
.
-
getIndexSafe
static java.lang.Object getIndexSafe(java.lang.Object[] arr, int ix)
-
getBrokenBoundary
private static int getBrokenBoundary(float sz, int lower, int upper)
Returns the broken boundary ifsz
is outside the boundarieslower
orupper
. If both boundaries are broken, the lower one is returned. Ifsz
is < 0 thennew Float(0f)
is returned so that no sizes can be negative.- Parameters:
sz
- The size to checklower
- The lower boundary (ornull
for no boundary).upper
- The upper boundary (ornull
for no boundary).- Returns:
- The broken boundary.
-
sum
static int sum(int[] terms, int start, int len)
-
sum
static int sum(int[] terms)
-
clamp
static float clamp(float f, float min, float max)
Keeps f within min and max. Min is of higher priority if min is larger than max.- Parameters:
f
- The value to clampmin
-max
-- Returns:
- The clamped value, between min and max.
-
clamp
static int clamp(int i, int min, int max)
Keeps i within min and max. Min is of higher priority if min is larger than max.- Parameters:
i
- The value to clampmin
-max
-- Returns:
- The clamped value, between min and max.
-
getSizeSafe
public static int getSizeSafe(int[] sizes, int sizeType)
-
isLeftToRight
public static boolean isLeftToRight(LC lc, ContainerWrapper container)
Returns if left-to-right orientation is used. If not set explicitly in the layout constraints the Locale of theparent
is used.- Parameters:
lc
- The constraint if there is one. Can benull
.container
- The parent that may be used to get the left-to-right if lc does not specify this.- Returns:
- If left-to-right orientation is currently used.
-
roundSizes
static int[] roundSizes(float[] sizes)
Round a number of float sizes into int sizes so that the total length match up- Parameters:
sizes
- The sizes to round- Returns:
- An array of equal length as
sizes
.
-
equals
static boolean equals(java.lang.Object o1, java.lang.Object o2)
Safe equals. null == null, but null never equals anything else.- Parameters:
o1
- The first object. May benull
.o2
- The second object. May benull
.- Returns:
- Returns
true
ifo1
ando2
are equal (using .equals()) or both arenull
.
-
getInsets
static UnitValue getInsets(LC lc, int side, boolean getDefault)
Returns the insets for the side.- Parameters:
side
- top == 0, left == 1, bottom = 2, right = 3.getDefault
- Iftrue
the default insets will get retrieved iflc
has none set.- Returns:
- The insets for the side. Never
null
.
-
writeXMLObject
static void writeXMLObject(java.io.OutputStream os, java.lang.Object o, java.beans.ExceptionListener listener)
Writes the object and CLOSES the stream. Uses the persistence delegate registered in this class.- Parameters:
os
- The stream to write to. Will be closed.o
- The object to be serialized.listener
- The listener to receive the exceptions if there are any. Ifnull
not used.
-
writeAsXML
public static void writeAsXML(java.io.ObjectOutput out, java.lang.Object o) throws java.io.IOException
Writes an object to XML.- Parameters:
out
- The object out to write to. Will not be closed.o
- The object to write.- Throws:
java.io.IOException
-
readAsXML
public static java.lang.Object readAsXML(java.io.ObjectInput in) throws java.io.IOException
Reads an object fromin
using the- Parameters:
in
- The object input to read from.- Returns:
- The object. Never
null
. - Throws:
java.io.IOException
- If there was a problem saving as XML
-
setSerializedObject
public static void setSerializedObject(java.lang.Object caller, java.lang.Object o)
Sets the serialized object and associates it withcaller
.- Parameters:
caller
- The object createdo
o
- The just serialized object.
-
getSerializedObject
public static java.lang.Object getSerializedObject(java.lang.Object caller)
Returns the serialized object that are associated withcaller
. It also removes it from the list.- Parameters:
caller
- The original creator of the object.- Returns:
- The object.
-
-