miglayout-3.7.4/0000755000175000017500000000000011574447716012323 5ustar tonytonymiglayout-3.7.4/META-INF/0000755000175000017500000000000011521733276013452 5ustar tonytonymiglayout-3.7.4/META-INF/MANIFEST.MF0000644000175000017500000000014311521733274015100 0ustar tonytonyManifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: 17.1-b03-307 (Apple Inc.)
miglayout-3.7.4/net/0000755000175000017500000000000011252374660013077 5ustar tonytonymiglayout-3.7.4/net/miginfocom/0000755000175000017500000000000011252374662015230 5ustar tonytonymiglayout-3.7.4/net/miginfocom/swing/0000755000175000017500000000000011455506144016354 5ustar tonytonymiglayout-3.7.4/net/miginfocom/swing/SwingComponentWrapper.java0000644000175000017500000003106311521471106023526 0ustar tonytonypackage net.miginfocom.swing;
/*
* License (BSD):
* ==============
*
* Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
* Neither the name of the MiG InfoCom AB nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* @version 1.0
* @author Mikael Grev, MiG InfoCom AB
* Date: 2006-sep-08
*/
import net.miginfocom.layout.ComponentWrapper;
import net.miginfocom.layout.ContainerWrapper;
import net.miginfocom.layout.PlatformDefaults;
import javax.swing.*;
import javax.swing.text.JTextComponent;
import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.lang.reflect.Method;
import java.util.IdentityHashMap;
/**
*/
public class SwingComponentWrapper implements ComponentWrapper
{
private static boolean maxSet = false;
private static boolean vp = true;
/** Debug color for component bounds outline.
*/
private static final Color DB_COMP_OUTLINE = new Color(0, 0, 200);
private final Component c;
private int compType = TYPE_UNSET;
private Boolean bl = null;
private boolean prefCalled = false;
public SwingComponentWrapper(Component c)
{
this.c = c;
}
public final int getBaseline(int width, int height)
{
if (BL_METHOD == null)
return -1;
try {
Object[] args = new Object[] {
Integer.valueOf(width < 0 ? c.getWidth() : width),
Integer.valueOf(height < 0 ? c.getHeight() : height)
};
return ((Integer) BL_METHOD.invoke(c, args)).intValue();
} catch (Exception e) {
return -1;
}
}
public final Object getComponent()
{
return c;
}
/** Cache.
*/
private final static IdentityHashMap FM_MAP = new IdentityHashMap(4);
private final static Font SUBST_FONT = new Font("sansserif", Font.PLAIN, 11);
public final float getPixelUnitFactor(boolean isHor)
{
switch (PlatformDefaults.getLogicalPixelBase()) {
case PlatformDefaults.BASE_FONT_SIZE:
Font font = c.getFont();
FontMetrics fm = c.getFontMetrics(font != null ? font : SUBST_FONT);
Point.Float p = FM_MAP.get(fm);
if (p == null) {
Rectangle2D r = fm.getStringBounds("X", c.getGraphics());
p = new Point.Float(((float) r.getWidth()) / 6f, ((float) r.getHeight()) / 13.27734375f);
FM_MAP.put(fm, p);
}
return isHor ? p.x : p.y;
case PlatformDefaults.BASE_SCALE_FACTOR:
Float s = isHor ? PlatformDefaults.getHorizontalScaleFactor() : PlatformDefaults.getVerticalScaleFactor();
if (s != null)
return s.floatValue();
return (isHor ? getHorizontalScreenDPI() : getVerticalScreenDPI()) / (float) PlatformDefaults.getDefaultDPI();
default:
return 1f;
}
}
// /** Cache.
// */
// private final static IdentityHashMap FM_MAP2 = new IdentityHashMap(4);
// private final static Font SUBST_FONT2 = new Font("sansserif", Font.PLAIN, 11);
//
// public float getDialogUnit(boolean isHor)
// {
// Font font = c.getFont();
// FontMetrics fm = c.getFontMetrics(font != null ? font : SUBST_FONT2);
// Point.Float dluP = FM_MAP2.get(fm);
// if (dluP == null) {
// float w = fm.charWidth('X') / 4f;
// int ascent = fm.getAscent();
// float h = (ascent > 14 ? ascent : ascent + (15 - ascent) / 3) / 8f;
//
// dluP = new Point.Float(w, h);
// FM_MAP2.put(fm, dluP);
// }
// return isHor ? dluP.x : dluP.y;
// }
public final int getX()
{
return c.getX();
}
public final int getY()
{
return c.getY();
}
public final int getHeight()
{
return c.getHeight();
}
public final int getWidth()
{
return c.getWidth();
}
public final int getScreenLocationX()
{
Point p = new Point();
SwingUtilities.convertPointToScreen(p, c);
return p.x;
}
public final int getScreenLocationY()
{
Point p = new Point();
SwingUtilities.convertPointToScreen(p, c);
return p.y;
}
public final int getMinimumHeight(int sz)
{
if (prefCalled == false) {
c.getPreferredSize(); // To defeat a bug where the minimum size is different before and after the first call to getPreferredSize();
prefCalled = true;
}
return c.getMinimumSize().height;
}
public final int getMinimumWidth(int sz)
{
if (prefCalled == false) {
c.getPreferredSize(); // To defeat a bug where the minimum size is different before and after the first call to getPreferredSize();
prefCalled = true;
}
return c.getMinimumSize().width;
}
public final int getPreferredHeight(int sz)
{
// If the component has not gotten size yet and there is a size hint, trick Swing to return a better height.
if (c.getWidth() == 0 && c.getHeight() == 0 && sz != -1)
c.setBounds(c.getX(), c.getY(), sz, 1);
return c.getPreferredSize().height;
}
public final int getPreferredWidth(int sz)
{
// If the component has not gotten size yet and there is a size hint, trick Swing to return a better height.
if (c.getWidth() == 0 && c.getHeight() == 0 && sz != -1)
c.setBounds(c.getX(), c.getY(), 1, sz);
return c.getPreferredSize().width;
}
public final int getMaximumHeight(int sz)
{
if (!isMaxSet(c))
return Short.MAX_VALUE;
return c.getMaximumSize().height;
}
public final int getMaximumWidth(int sz)
{
if (!isMaxSet(c))
return Short.MAX_VALUE;
return c.getMaximumSize().width;
}
private boolean isMaxSet(Component c)
{
if (IMS_METHOD != null) {
try {
return ((Boolean) IMS_METHOD.invoke(c, (Object[]) null)).booleanValue();
} catch (Exception e) {
IMS_METHOD = null; // So we do not try every time.
}
}
return isMaxSizeSetOn1_4();
}
public final ContainerWrapper getParent()
{
Container p = c.getParent();
return p != null ? new SwingContainerWrapper(p) : null;
}
public final int getHorizontalScreenDPI()
{
return PlatformDefaults.getDefaultDPI();
}
public final int getVerticalScreenDPI()
{
return PlatformDefaults.getDefaultDPI();
}
public final int getScreenWidth()
{
try {
return c.getToolkit().getScreenSize().width;
} catch (HeadlessException ex) {
return 1024;
}
}
public final int getScreenHeight()
{
try {
return c.getToolkit().getScreenSize().height;
} catch (HeadlessException ex) {
return 768;
}
}
public final boolean hasBaseline()
{
if (bl == null) {
try {
if (BL_RES_METHOD == null || BL_RES_METHOD.invoke(c).toString().equals("OTHER")) {
bl = Boolean.FALSE;
} else {
Dimension d = c.getMinimumSize();
bl = Boolean.valueOf(getBaseline(d.width, d.height) > -1);
}
} catch (Throwable ex) {
bl = Boolean.FALSE;
}
}
return bl.booleanValue();
}
public final String getLinkId()
{
return c.getName();
}
public final void setBounds(int x, int y, int width, int height)
{
c.setBounds(x, y, width, height);
}
public boolean isVisible()
{
return c.isVisible();
}
public final int[] getVisualPadding()
{
if (vp && c instanceof JTabbedPane) {
if (UIManager.getLookAndFeel().getClass().getName().endsWith("WindowsLookAndFeel"))
return new int[] {-1, 0, 2, 2};
}
return null;
}
public static boolean isMaxSizeSetOn1_4()
{
return maxSet;
}
public static void setMaxSizeSetOn1_4(boolean b)
{
maxSet = b;
}
public static boolean isVisualPaddingEnabled()
{
return vp;
}
public static void setVisualPaddingEnabled(boolean b)
{
vp = b;
}
public final void paintDebugOutline()
{
if (c.isShowing() == false)
return;
Graphics2D g = (Graphics2D) c.getGraphics();
if (g == null)
return;
g.setPaint(DB_COMP_OUTLINE);
g.setStroke(new BasicStroke(1f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10f, new float[] {2f, 4f}, 0));
g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
}
public int getComponetType(boolean disregardScrollPane)
{
if (compType == TYPE_UNSET)
compType = checkType(disregardScrollPane);
return compType;
}
public int getLayoutHashCode()
{
Dimension d = c.getMaximumSize();
int h = d.width + (d.height << 5);
d = c.getPreferredSize();
h += (d.width << 10) + (d.height << 15);
d = c.getMinimumSize();
h += (d.width << 20) + (d.height << 25);
if (c.isVisible())
h += 1324511;
String id = getLinkId();
if (id != null)
h += id.hashCode();
return h;
// Since 2.3 will check the isValid instead everything that affects that can be removed from the layout hashcode.
// String id = getLinkId();
// return id != null ? id.hashCode() : 1;
}
private int checkType(boolean disregardScrollPane)
{
Component c = this.c;
if (disregardScrollPane) {
if (c instanceof JScrollPane) {
c = ((JScrollPane) c).getViewport().getView();
} else if (c instanceof ScrollPane) {
c = ((ScrollPane) c).getComponent(0);
}
}
if (c instanceof JTextField || c instanceof TextField) {
return TYPE_TEXT_FIELD;
} else if (c instanceof JLabel || c instanceof Label) {
return TYPE_LABEL;
} else if (c instanceof JToggleButton || c instanceof Checkbox) {
return TYPE_CHECK_BOX;
} else if (c instanceof AbstractButton || c instanceof Button) {
return TYPE_BUTTON;
} else if (c instanceof JComboBox || c instanceof Choice) {
return TYPE_LABEL;
} else if (c instanceof JTextComponent || c instanceof TextComponent) {
return TYPE_TEXT_AREA;
} else if (c instanceof JPanel || c instanceof Canvas) {
return TYPE_PANEL;
} else if (c instanceof JList || c instanceof List) {
return TYPE_LIST;
} else if (c instanceof JTable) {
return TYPE_TABLE;
} else if (c instanceof JSeparator) {
return TYPE_SEPARATOR;
} else if (c instanceof JSpinner) {
return TYPE_SPINNER;
} else if (c instanceof JProgressBar) {
return TYPE_PROGRESS_BAR;
} else if (c instanceof JSlider) {
return TYPE_SLIDER;
} else if (c instanceof JScrollPane) {
return TYPE_SCROLL_PANE;
} else if (c instanceof JScrollBar || c instanceof Scrollbar) {
return TYPE_SCROLL_BAR;
} else if (c instanceof Container) { // only AWT components is not containers.
return TYPE_CONTAINER;
}
return TYPE_UNKNOWN;
}
public final int hashCode()
{
return getComponent().hashCode();
}
public final boolean equals(Object o)
{
if (o instanceof ComponentWrapper == false)
return false;
return getComponent().equals(((ComponentWrapper) o).getComponent());
}
/** Cached method used for getting base line with reflection.
*/
private static Method BL_METHOD = null;
private static Method BL_RES_METHOD = null;
static {
try {
BL_METHOD = Component.class.getDeclaredMethod("getBaseline", new Class[] {int.class, int.class});
BL_RES_METHOD = Component.class.getDeclaredMethod("getBaselineResizeBehavior"); // 3.7.2: Removed Class null since that made the method inaccessible.
} catch (Throwable e) { // No such method or security exception
}
}
private static Method IMS_METHOD = null;
static {
try {
IMS_METHOD = Component.class.getDeclaredMethod("isMaximumSizeSet", (Class[]) null);
} catch (Throwable e) { // No such method or security exception
}
}
}
miglayout-3.7.4/net/miginfocom/swing/MigLayout.java0000644000175000017500000006100111521471050021116 0ustar tonytonypackage net.miginfocom.swing;
/*
* License (BSD):
* ==============
*
* Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
* Neither the name of the MiG InfoCom AB nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* @version 1.0
* @author Mikael Grev, MiG InfoCom AB
* Date: 2006-sep-08
*/
import net.miginfocom.layout.*;
import javax.swing.*;
import javax.swing.Timer;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.util.*;
/** A very flexible layout manager.
*
* Read the documentation that came with this layout manager for information on usage.
*/
public final class MigLayout implements LayoutManager2, Externalizable
{
// ******** Instance part ********
/** The component to string constraints mappings.
*/
private final Map scrConstrMap = new IdentityHashMap(8);
/** Hold the serializable text representation of the constraints.
*/
private Object layoutConstraints = "", colConstraints = "", rowConstraints = ""; // Should never be null!
// ******** Transient part ********
private transient ContainerWrapper cacheParentW = null;
private transient final Map ccMap = new HashMap(8);
private transient javax.swing.Timer debugTimer = null;
private transient LC lc = null;
private transient AC colSpecs = null, rowSpecs = null;
private transient Grid grid = null;
private transient int lastModCount = PlatformDefaults.getModCount();
private transient int lastHash = -1;
private transient Dimension lastInvalidSize = null;
private transient boolean lastWasInvalid = false; // Added in 3.7.1. May have regressions
private transient Dimension lastParentSize = null;
private transient ArrayList callbackList = null;
private transient boolean dirty = true;
/** Constructor with no constraints.
*/
public MigLayout()
{
this("", "", "");
}
/** Constructor.
* @param layoutConstraints The constraints that concern the whole layout. null will be treated as "".
*/
public MigLayout(String layoutConstraints)
{
this(layoutConstraints, "", "");
}
/** Constructor.
* @param layoutConstraints The constraints that concern the whole layout. null will be treated as "".
* @param colConstraints The constraints for the columns in the grid. null will be treated as "".
*/
public MigLayout(String layoutConstraints, String colConstraints)
{
this(layoutConstraints, colConstraints, "");
}
/** Constructor.
* @param layoutConstraints The constraints that concern the whole layout. null will be treated as "".
* @param colConstraints The constraints for the columns in the grid. null will be treated as "".
* @param rowConstraints The constraints for the rows in the grid. null will be treated as "".
*/
public MigLayout(String layoutConstraints, String colConstraints, String rowConstraints)
{
setLayoutConstraints(layoutConstraints);
setColumnConstraints(colConstraints);
setRowConstraints(rowConstraints);
}
/** Constructor.
* @param layoutConstraints The constraints that concern the whole layout. null will be treated as an empty constraint.
*/
public MigLayout(LC layoutConstraints)
{
this(layoutConstraints, null, null);
}
/** Constructor.
* @param layoutConstraints The constraints that concern the whole layout. null will be treated as an empty constraint.
* @param colConstraints The constraints for the columns in the grid. null will be treated as an empty constraint.
*/
public MigLayout(LC layoutConstraints, AC colConstraints)
{
this(layoutConstraints, colConstraints, null);
}
/** Constructor.
* @param layoutConstraints The constraints that concern the whole layout. null will be treated as an empty constraint.
* @param colConstraints The constraints for the columns in the grid. null will be treated as an empty constraint.
* @param rowConstraints The constraints for the rows in the grid. null will be treated as an empty constraint.
*/
public MigLayout(LC layoutConstraints, AC colConstraints, AC rowConstraints)
{
setLayoutConstraints(layoutConstraints);
setColumnConstraints(colConstraints);
setRowConstraints(rowConstraints);
}
/** Returns layout constraints either as a String or {@link net.miginfocom.layout.LC} depending what was sent in
* to the constructor or set with {@link #setLayoutConstraints(Object)}.
* @return The layout constraints either as a String or {@link net.miginfocom.layout.LC} depending what was sent in
* to the constructor or set with {@link #setLayoutConstraints(Object)}. Never null.
*/
public Object getLayoutConstraints()
{
return layoutConstraints;
}
/** Sets the layout constraints for the layout manager instance as a String.
*
* See the class JavaDocs for information on how this string is formatted.
* @param constr The layout constraints as a String representation. null is converted to "" for storage.
* @throws RuntimeException if the constraint was not valid.
*/
public void setLayoutConstraints(Object constr)
{
if (constr == null || constr instanceof String) {
constr = ConstraintParser.prepare((String) constr);
lc = ConstraintParser.parseLayoutConstraint((String) constr);
} else if (constr instanceof LC) {
lc = (LC) constr;
} else {
throw new IllegalArgumentException("Illegal constraint type: " + constr.getClass().toString());
}
layoutConstraints = constr;
dirty = true;
}
/** Returns the column layout constraints either as a String or {@link net.miginfocom.layout.AC}.
* @return The column constraints either as a String or {@link net.miginfocom.layout.LC} depending what was sent in
* to the constructor or set with {@link #setLayoutConstraints(Object)}. Never null.
*/
public Object getColumnConstraints()
{
return colConstraints;
}
/** Sets the column layout constraints for the layout manager instance as a String.
*
* See the class JavaDocs for information on how this string is formatted.
* @param constr The column layout constraints as a String representation. null is converted to "" for storage.
* @throws RuntimeException if the constraint was not valid.
*/
public void setColumnConstraints(Object constr)
{
if (constr == null || constr instanceof String) {
constr = ConstraintParser.prepare((String) constr);
colSpecs = ConstraintParser.parseColumnConstraints((String) constr);
} else if (constr instanceof AC) {
colSpecs = (AC) constr;
} else {
throw new IllegalArgumentException("Illegal constraint type: " + constr.getClass().toString());
}
colConstraints = constr;
dirty = true;
}
/** Returns the row layout constraints as a String representation. This string is the exact string as set with {@link #setRowConstraints(Object)}
* or sent into the constructor.
*
* See the class JavaDocs for information on how this string is formatted.
* @return The row layout constraints as a String representation. Never null.
*/
public Object getRowConstraints()
{
return rowConstraints;
}
/** Sets the row layout constraints for the layout manager instance as a String.
*
* See the class JavaDocs for information on how this string is formatted.
* @param constr The row layout constraints as a String representation. null is converted to "" for storage.
* @throws RuntimeException if the constraint was not valid.
*/
public void setRowConstraints(Object constr)
{
if (constr == null || constr instanceof String) {
constr = ConstraintParser.prepare((String) constr);
rowSpecs = ConstraintParser.parseRowConstraints((String) constr);
} else if (constr instanceof AC) {
rowSpecs = (AC) constr;
} else {
throw new IllegalArgumentException("Illegal constraint type: " + constr.getClass().toString());
}
rowConstraints = constr;
dirty = true;
}
/** Returns a shallow copy of the constraints map.
* @return A shallow copy of the constraints map. Never null.
*/
public Map getConstraintMap()
{
return new IdentityHashMap(scrConstrMap);
}
/** Sets the constraints map.
* @param map The map. Will be copied.
*/
public void setConstraintMap(Map map)
{
scrConstrMap.clear();
ccMap.clear();
for (Map.Entry e : map.entrySet())
setComponentConstraintsImpl(e.getKey(), e.getValue(), true);
}
/** Returns the component constraints as a String representation. This string is the exact string as set with {@link #setComponentConstraints(java.awt.Component, Object)}
* or set when adding the component to the parent component.
*
* See the class JavaDocs for information on how this string is formatted.
* @param comp The component to return the constraints for.
* @return The component constraints as a String representation or null if the component is not registered
* with this layout manager. The returned values is either a String or a {@link net.miginfocom.layout.CC}
* depending on what constraint was sent in when the component was added. May be null.
*/
public Object getComponentConstraints(Component comp)
{
synchronized(comp.getParent().getTreeLock()) {
return scrConstrMap.get(comp);
}
}
/** Sets the component constraint for the component that already must be handled by this layout manager.
*
* See the class JavaDocs for information on how this string is formatted.
* @param constr The component constraints as a String or {@link net.miginfocom.layout.CC}. null is ok.
* @param comp The component to set the constraints for.
* @throws RuntimeException if the constraint was not valid.
* @throws IllegalArgumentException If the component is not handling the component.
*/
public void setComponentConstraints(Component comp, Object constr)
{
setComponentConstraintsImpl(comp, constr, false);
}
/** Sets the component constraint for the component that already must be handled by this layout manager.
*
* See the class JavaDocs for information on how this string is formatted.
* @param constr The component constraints as a String or {@link net.miginfocom.layout.CC}. null is ok.
* @param comp The component to set the constraints for.
* @param noCheck Doe not check if the component is handled if true
* @throws RuntimeException if the constraint was not valid.
* @throws IllegalArgumentException If the component is not handling the component.
*/
private void setComponentConstraintsImpl(Component comp, Object constr, boolean noCheck)
{
Container parent = comp.getParent();
synchronized(parent != null ? parent.getTreeLock() : new Object()) { // 3.7.2. No sync if not added to a hierarchy. Defeats a NPE.
if (noCheck == false && scrConstrMap.containsKey(comp) == false)
throw new IllegalArgumentException("Component must already be added to parent!");
ComponentWrapper cw = new SwingComponentWrapper(comp);
if (constr == null || constr instanceof String) {
String cStr = ConstraintParser.prepare((String) constr);
scrConstrMap.put(comp, constr);
ccMap.put(cw, ConstraintParser.parseComponentConstraint(cStr));
} else if (constr instanceof CC) {
scrConstrMap.put(comp, constr);
ccMap.put(cw, (CC) constr);
} else {
throw new IllegalArgumentException("Constraint must be String or ComponentConstraint: " + constr.getClass().toString());
}
dirty = true;
}
}
/** Returns if this layout manager is currently managing this component.
* @param c The component to check. If null then false will be returned.
* @return If this layout manager is currently managing this component.
*/
public boolean isManagingComponent(Component c)
{
return scrConstrMap.containsKey(c);
}
/** Adds the callback function that will be called at different stages of the layout cylce.
* @param callback The callback. Not null.
*/
public void addLayoutCallback(LayoutCallback callback)
{
if (callback == null)
throw new NullPointerException();
if (callbackList == null)
callbackList = new ArrayList(1);
callbackList.add(callback);
}
/** Removes the callback if it exists.
* @param callback The callback. May be null.
*/
public void removeLayoutCallback(LayoutCallback callback)
{
if (callbackList != null)
callbackList.remove(callback);
}
/** Sets the debugging state for this layout manager instance. If debug is turned on a timer will repaint the last laid out parent
* with debug information on top.
*
* Red fill and dashed red outline is used to indicate occupied cells in the grid. Blue dashed outline indicate indicate
* component bounds set.
*
* 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
* JavaDocs for information.
* @param parentW The parent to set debug for.
* @param b true means debug is turned on.
*/
private void setDebug(final ComponentWrapper parentW, boolean b)
{
if (b && (debugTimer == null || debugTimer.getDelay() != getDebugMillis())) {
if (debugTimer != null)
debugTimer.stop();
ContainerWrapper pCW = parentW.getParent();
final Component parent = pCW != null ? (Component) pCW.getComponent() : null;
debugTimer = new Timer(getDebugMillis(), new MyDebugRepaintListener());
if (parent != null) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Container p = parent.getParent();
if (p != null) {
if (p instanceof JComponent) {
((JComponent) p).revalidate();
} else {
parent.invalidate();
p.validate();
}
}
}
});
}
debugTimer.setInitialDelay(100);
debugTimer.start();
} else if (!b && debugTimer != null) {
debugTimer.stop();
debugTimer = null;
}
}
/** Returns the current debugging state.
* @return The current debugging state.
*/
private boolean getDebug()
{
return debugTimer != null;
}
/** Returns the debug millis. Combines the value from {@link net.miginfocom.layout.LC#getDebugMillis()} and {@link net.miginfocom.layout.LayoutUtil#getGlobalDebugMillis()}
* @return The combined value.
*/
private int getDebugMillis()
{
int globalDebugMillis = LayoutUtil.getGlobalDebugMillis();
return globalDebugMillis > 0 ? globalDebugMillis : lc.getDebugMillis();
}
/** Check if something has changed and if so recreate it to the cached objects.
* @param parent The parent that is the target for this layout manager.
*/
private void checkCache(Container parent)
{
if (parent == null)
return;
if (dirty)
grid = null;
// Check if the grid is valid
int mc = PlatformDefaults.getModCount();
if (lastModCount != mc) {
grid = null;
lastModCount = mc;
}
if (parent.isValid() == false) {
if (lastWasInvalid == false) {
lastWasInvalid = true;
int hash = 0;
boolean resetLastInvalidOnParent = false; // Added in 3.7.3 to resolve a timing regression introduced in 3.7.1
for (Iterator it = ccMap.keySet().iterator(); it.hasNext();) {
ComponentWrapper wrapper = it.next();
Object component = wrapper.getComponent();
if (component instanceof JTextArea || component instanceof JEditorPane)
resetLastInvalidOnParent = true;
hash += wrapper.getLayoutHashCode();
}
if (resetLastInvalidOnParent)
resetLastInvalidOnParent(parent);
if (hash != lastHash) {
grid = null;
lastHash = hash;
}
Dimension ps = parent.getSize();
if (lastInvalidSize == null || !lastInvalidSize.equals(ps)) {
if (grid != null)
grid.invalidateContainerSize();
lastInvalidSize = ps;
}
}
} else {
lastWasInvalid = false;
}
ContainerWrapper par = checkParent(parent);
setDebug(par, getDebugMillis() > 0);
if (grid == null)
grid = new Grid(par, lc, rowSpecs, colSpecs, ccMap, callbackList);
dirty = false;
}
/**
* @since 3.7.3
*/
private void resetLastInvalidOnParent(Container parent)
{
while (parent != null) {
LayoutManager layoutManager = parent.getLayout();
if (layoutManager instanceof MigLayout) {
((MigLayout) layoutManager).lastWasInvalid = false;
}
parent = parent.getParent();
}
}
private ContainerWrapper checkParent(Container parent)
{
if (parent == null)
return null;
if (cacheParentW == null || cacheParentW.getComponent() != parent)
cacheParentW = new SwingContainerWrapper(parent);
return cacheParentW;
}
private long lastSize = 0;
public void layoutContainer(final Container parent)
{
synchronized(parent.getTreeLock()) {
checkCache(parent);
Insets i = parent.getInsets();
int[] b = new int[] {
i.left,
i.top,
parent.getWidth() - i.left - i.right,
parent.getHeight() - i.top - i.bottom
};
if (grid.layout(b, lc.getAlignX(), lc.getAlignY(), getDebug(), true)) {
grid = null;
checkCache(parent);
grid.layout(b, lc.getAlignX(), lc.getAlignY(), getDebug(), false);
}
long newSize = grid.getHeight()[1] + (((long) grid.getWidth()[1]) << 32);
if (lastSize != newSize) {
lastSize = newSize;
final ContainerWrapper containerWrapper = checkParent(parent);
Window win = ((Window) SwingUtilities.getAncestorOfClass(Window.class, (Component)containerWrapper.getComponent()));
if (win != null) {
if (win.isVisible()) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
adjustWindowSize(containerWrapper);
}
});
} else {
adjustWindowSize(containerWrapper);
}
}
}
lastInvalidSize = null;
}
}
/** Checks the parent window if its size is within parameters as set by the LC.
* @param parent The parent who's window to possibly adjust the size for.
*/
private void adjustWindowSize(ContainerWrapper parent)
{
BoundSize wBounds = lc.getPackWidth();
BoundSize hBounds = lc.getPackHeight();
if (wBounds == null && hBounds == null)
return;
Window win = ((Window) SwingUtilities.getAncestorOfClass(Window.class, (Component) parent.getComponent()));
if (win == null)
return;
Dimension prefSize = win.getPreferredSize();
int targW = constrain(checkParent(win), win.getWidth(), prefSize.width, wBounds);
int targH = constrain(checkParent(win), win.getHeight(), prefSize.height, hBounds);
int x = Math.round(win.getX() - ((targW - win.getWidth()) * (1 - lc.getPackWidthAlign())));
int y = Math.round(win.getY() - ((targH - win.getHeight()) * (1 - lc.getPackHeightAlign())));
win.setBounds(x, y, targW, targH);
}
private int constrain(ContainerWrapper parent, int winSize, int prefSize, BoundSize constrain)
{
if (constrain == null)
return winSize;
int retSize = winSize;
UnitValue wUV = constrain.getPreferred();
if (wUV != null)
retSize = wUV.getPixels(prefSize, parent, parent);
retSize = constrain.constrain(retSize, prefSize, parent);
return constrain.getGapPush() ? Math.max(winSize, retSize) : retSize;
}
public Dimension minimumLayoutSize(Container parent)
{
synchronized(parent.getTreeLock()) {
return getSizeImpl(parent, LayoutUtil.MIN);
}
}
public Dimension preferredLayoutSize(Container parent)
{
synchronized(parent.getTreeLock()) {
if (lastParentSize == null || !parent.getSize().equals(lastParentSize)) {
for (ComponentWrapper wrapper : ccMap.keySet()) {
Component c = (Component) wrapper.getComponent();
if (c instanceof JTextArea || c instanceof JEditorPane || (c instanceof JComponent && Boolean.TRUE.equals(((JComponent)c).getClientProperty("migLayout.dynamicAspectRatio")))) {
layoutContainer(parent);
break;
}
}
}
lastParentSize = parent.getSize();
return getSizeImpl(parent, LayoutUtil.PREF);
}
}
public Dimension maximumLayoutSize(Container parent)
{
return new Dimension(Short.MAX_VALUE, Short.MAX_VALUE);
}
// Implementation method that does the job.
private Dimension getSizeImpl(Container parent, int sizeType)
{
checkCache(parent);
Insets i = parent.getInsets();
int w = LayoutUtil.getSizeSafe(grid != null ? grid.getWidth() : null, sizeType) + i.left + i.right;
int h = LayoutUtil.getSizeSafe(grid != null ? grid.getHeight() : null, sizeType) + i.top + i.bottom;
return new Dimension(w, h);
}
public float getLayoutAlignmentX(Container parent)
{
return lc != null && lc.getAlignX() != null ? lc.getAlignX().getPixels(1, checkParent(parent), null) : 0;
}
public float getLayoutAlignmentY(Container parent)
{
return lc != null && lc.getAlignY() != null ? lc.getAlignY().getPixels(1, checkParent(parent), null) : 0;
}
public void addLayoutComponent(String s, Component comp)
{
addLayoutComponent(comp, s);
}
public void addLayoutComponent(Component comp, Object constraints)
{
synchronized(comp.getParent().getTreeLock()) {
setComponentConstraintsImpl(comp, constraints, true);
}
}
public void removeLayoutComponent(Component comp)
{
synchronized(comp.getParent().getTreeLock()) {
scrConstrMap.remove(comp);
ccMap.remove(new SwingComponentWrapper(comp));
}
}
public void invalidateLayout(Container target)
{
// if (lc.isNoCache()) // Commented for 3.5 since there was too often that the "nocache" was needed and the user did not know.
dirty = true;
// the validity of components is maintained automatically.
}
// ************************************************
// Persistence Delegate and Serializable combined.
// ************************************************
private Object readResolve() throws ObjectStreamException
{
return LayoutUtil.getSerializedObject(this);
}
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
{
LayoutUtil.setSerializedObject(this, LayoutUtil.readAsXML(in));
}
public void writeExternal(ObjectOutput out) throws IOException
{
if (getClass() == MigLayout.class)
LayoutUtil.writeAsXML(out, this);
}
private class MyDebugRepaintListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if (grid != null) {
Component comp = (Component) grid.getContainer().getComponent();
if (comp.isShowing()) {
grid.paintDebug();
return;
}
}
debugTimer.stop();
debugTimer = null;
}
}
}miglayout-3.7.4/net/miginfocom/swing/SwingContainerWrapper.java0000644000175000017500000000677311252374662023532 0ustar tonytonypackage net.miginfocom.swing;
/*
* License (BSD):
* ==============
*
* Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
* Neither the name of the MiG InfoCom AB nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* @version 1.0
* @author Mikael Grev, MiG InfoCom AB
* Date: 2006-sep-08
*/
import net.miginfocom.layout.ComponentWrapper;
import net.miginfocom.layout.ContainerWrapper;
import java.awt.*;
/**
*/
public final class SwingContainerWrapper extends SwingComponentWrapper implements ContainerWrapper
{
/** Debug color for cell outline.
*/
private static final Color DB_CELL_OUTLINE = new Color(255, 0, 0);
public SwingContainerWrapper(Container c)
{
super(c);
}
public ComponentWrapper[] getComponents()
{
Container c = (Container) getComponent();
ComponentWrapper[] cws = new ComponentWrapper[c.getComponentCount()];
for (int i = 0; i < cws.length; i++)
cws[i] = new SwingComponentWrapper(c.getComponent(i));
return cws;
}
public int getComponentCount()
{
return ((Container) getComponent()).getComponentCount();
}
public Object getLayout()
{
return ((Container) getComponent()).getLayout();
}
public final boolean isLeftToRight()
{
return ((Container) getComponent()).getComponentOrientation().isLeftToRight();
}
public final void paintDebugCell(int x, int y, int width, int height)
{
Component c = (Component) getComponent();
if (c.isShowing() == false)
return;
Graphics2D g = (Graphics2D) c.getGraphics();
if (g == null)
return;
g.setStroke(new BasicStroke(1f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10f, new float[] {2f, 3f}, 0));
g.setPaint(DB_CELL_OUTLINE);
g.drawRect(x, y, width - 1, height - 1);
}
public int getComponetType(boolean disregardScrollPane)
{
return TYPE_CONTAINER;
}
// Removed for 2.3 because the parent.isValid() in MigLayout will catch this instead.
public int getLayoutHashCode()
{
int h = super.getLayoutHashCode();
if (isLeftToRight())
h += 416343;
return 0;
}
}
miglayout-3.7.4/net/miginfocom/layout/0000755000175000017500000000000011455506144016542 5ustar tonytonymiglayout-3.7.4/net/miginfocom/layout/PlatformDefaults.java0000644000175000017500000007171511367121130022662 0ustar tonytonypackage net.miginfocom.layout;
import javax.swing.*;
import java.util.HashMap;
/*
* License (BSD):
* ==============
*
* Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
* Neither the name of the MiG InfoCom AB nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* @version 1.0
* @author Mikael Grev, MiG InfoCom AB
* Date: 2006-sep-08
* @author Xxxx Xxxx, Xxxx - Gnome support
* Date: 2008-jan-16
*/
/** Currently handles Windows, Mac OS X, and GNOME spacing.
*/
public final class PlatformDefaults
{
private static int DEF_H_UNIT = UnitValue.LPX;
private static int DEF_V_UNIT = UnitValue.LPY;
private static InCellGapProvider GAP_PROVIDER = null;
private static volatile int MOD_COUNT = 0;
private static final UnitValue LPX4 = new UnitValue(4, UnitValue.LPX, null);
private static final UnitValue LPX6 = new UnitValue(6, UnitValue.LPX, null);
private static final UnitValue LPX7 = new UnitValue(7, UnitValue.LPX, null);
// private static final UnitValue LPX8 = new UnitValue(8, UnitValue.LPX, null);
private static final UnitValue LPX9 = new UnitValue(9, UnitValue.LPX, null);
private static final UnitValue LPX10 = new UnitValue(10, UnitValue.LPX, null);
private static final UnitValue LPX11 = new UnitValue(11, UnitValue.LPX, null);
private static final UnitValue LPX12 = new UnitValue(12, UnitValue.LPX, null);
private static final UnitValue LPX14 = new UnitValue(14, UnitValue.LPX, null);
private static final UnitValue LPX16 = new UnitValue(16, UnitValue.LPX, null);
private static final UnitValue LPX18 = new UnitValue(18, UnitValue.LPX, null);
private static final UnitValue LPX20 = new UnitValue(20, UnitValue.LPX, null);
private static final UnitValue LPY4 = new UnitValue(4, UnitValue.LPY, null);
private static final UnitValue LPY6 = new UnitValue(6, UnitValue.LPY, null);
private static final UnitValue LPY7 = new UnitValue(7, UnitValue.LPY, null);
// private static final UnitValue LPY8 = new UnitValue(8, UnitValue.LPY, null);
private static final UnitValue LPY9 = new UnitValue(9, UnitValue.LPY, null);
private static final UnitValue LPY10 = new UnitValue(10, UnitValue.LPY, null);
private static final UnitValue LPY11 = new UnitValue(11, UnitValue.LPY, null);
private static final UnitValue LPY12 = new UnitValue(12, UnitValue.LPY, null);
private static final UnitValue LPY14 = new UnitValue(14, UnitValue.LPY, null);
private static final UnitValue LPY16 = new UnitValue(16, UnitValue.LPY, null);
private static final UnitValue LPY18 = new UnitValue(18, UnitValue.LPY, null);
private static final UnitValue LPY20 = new UnitValue(20, UnitValue.LPY, null);
public static final int WINDOWS_XP = 0;
public static final int MAC_OSX = 1;
public static final int GNOME = 2;
// private static final int KDE = 3;
private static int CUR_PLAF = WINDOWS_XP;
// Used for holding values.
private final static UnitValue[] PANEL_INS = new UnitValue[4];
private final static UnitValue[] DIALOG_INS = new UnitValue[4];
private static String BUTTON_FORMAT = null;
private static final HashMap HOR_DEFS = new HashMap(32);
private static final HashMap VER_DEFS = new HashMap(32);
private static BoundSize DEF_VGAP = null, DEF_HGAP = null;
static BoundSize RELATED_X = null, RELATED_Y = null, UNRELATED_X = null, UNRELATED_Y = null;
private static UnitValue BUTT_WIDTH = null;
private static Float horScale = null, verScale = null;
/** I value indicating that the size of the font for the container of the component
* will be used as a base for calculating the logical pixel size. This is much as how
* Windows calculated DLU (dialog units).
* @see net.miginfocom.layout.UnitValue#LPX
* @see net.miginfocom.layout.UnitValue#LPY
* @see #setLogicalPixelBase(int)
*/
public static final int BASE_FONT_SIZE = 100;
/** I value indicating that the screen DPI will be used as a base for calculating the
* logical pixel size.
*
* This is the default value.
* @see net.miginfocom.layout.UnitValue#LPX
* @see net.miginfocom.layout.UnitValue#LPY
* @see #setLogicalPixelBase(int)
* @see #setVerticalScaleFactor(Float)
* @see #setHorizontalScaleFactor(Float)
*/
public static final int BASE_SCALE_FACTOR = 101;
/** I value indicating that the size of a logical pixel should always be a real pixel
* and thus no compensation will be made.
* @see net.miginfocom.layout.UnitValue#LPX
* @see net.miginfocom.layout.UnitValue#LPY
* @see #setLogicalPixelBase(int)
*/
public static final int BASE_REAL_PIXEL = 102;
private static int LP_BASE = BASE_SCALE_FACTOR;
private static Integer BASE_DPI_FORCED = null;
private static int BASE_DPI = 96;
private static boolean dra = true;
static {
setPlatform(getCurrentPlatform());
MOD_COUNT = 0;
}
/** Returns the platform that the JRE is running on currently.
* @return The platform that the JRE is running on currently. E.g. {@link #MAC_OSX}, {@link #WINDOWS_XP}, or {@link #GNOME}.
*/
public static int getCurrentPlatform()
{
final String os = System.getProperty("os.name");
if (os.startsWith("Mac OS")) {
return MAC_OSX;
} else if (os.startsWith("Linux")) {
return GNOME;
} else {
return WINDOWS_XP;
}
}
private PlatformDefaults()
{
}
/** Set the defaults to the default for the platform
* @param plaf The platform. PlatformDefaults.WINDOWS_XP,
* PlatformDefaults.MAC_OSX, or
* PlatformDefaults.GNOME.
*/
public static void setPlatform(int plaf)
{
switch (plaf) {
case WINDOWS_XP:
setRelatedGap(LPX4, LPY4);
setUnrelatedGap(LPX7, LPY9);
setParagraphGap(LPX14, LPY14);
setIndentGap(LPX9, LPY9);
setGridCellGap(LPX4, LPY4);
setMinimumButtonWidth(new UnitValue(75, UnitValue.LPX, null));
setButtonOrder("L_E+U+YNBXOCAH_R");
setDialogInsets(LPY11, LPX11, LPY11, LPX11);
setPanelInsets(LPY7, LPX7, LPY7, LPX7);
break;
case MAC_OSX:
setRelatedGap(LPX4, LPY4);
setUnrelatedGap(LPX7, LPY9);
setParagraphGap(LPX14, LPY14);
setIndentGap(LPX10, LPY10);
setGridCellGap(LPX4, LPY4);
setMinimumButtonWidth(new UnitValue(68, UnitValue.LPX, null));
setButtonOrder("L_HE+U+NYBXCOA_R");
setDialogInsets(LPY14, LPX20, LPY20, LPX20);
setPanelInsets(LPY16, LPX16, LPY16, LPX16);
// setRelatedGap(LPX8, LPY8);
// setUnrelatedGap(LPX12, LPY12);
// setParagraphGap(LPX16, LPY16);
// setIndentGap(LPX10, LPY10);
// setGridCellGap(LPX8, LPY8);
//
// setMinimumButtonWidth(new UnitValue(68, UnitValue.LPX, null));
// setButtonOrder("L_HE+U+NYBXCOA_R");
// setDialogInsets(LPY14, LPX20, LPY20, LPX20);
// setPanelInsets(LPY16, LPX16, LPY16, LPX16);
break;
case GNOME:
setRelatedGap(LPX6, LPY6); // GNOME HIG 8.2.3
setUnrelatedGap(LPX12, LPY12); // GNOME HIG 8.2.3
setParagraphGap(LPX18, LPY18); // GNOME HIG 8.2.3
setIndentGap(LPX12, LPY12); // GNOME HIG 8.2.3
setGridCellGap(LPX6, LPY6); // GNOME HIG 8.2.3
// GtkButtonBox, child-min-width property default value
setMinimumButtonWidth(new UnitValue(85, UnitValue.LPX, null));
setButtonOrder("L_HE+UNYACBXIO_R"); // GNOME HIG 3.4.2, 3.7.1
setDialogInsets(LPY12, LPX12, LPY12, LPX12); // GNOME HIG 3.4.3
setPanelInsets(LPY6, LPX6, LPY6, LPX6); // ???
break;
default:
throw new IllegalArgumentException("Unknown platform: " + plaf);
}
CUR_PLAF = plaf;
BASE_DPI = BASE_DPI_FORCED != null ? BASE_DPI_FORCED.intValue() : getPlatformDPI(plaf);
}
private static int getPlatformDPI(int plaf)
{
switch (plaf) {
case WINDOWS_XP:
case GNOME:
return 96;
case MAC_OSX:
try {
return System.getProperty("java.version").compareTo("1.6") < 0 ? 72 : 96; // Default DPI was 72 prior to JSE 1.6
} catch (Throwable t) {
return 72;
}
default:
throw new IllegalArgumentException("Unknown platform: " + plaf);
}
}
/** Returns the current platform
* @return PlatformDefaults.WINDOWS or PlatformDefaults.MAC_OSX
*/
public static int getPlatform()
{
return CUR_PLAF;
}
public static int getDefaultDPI()
{
return BASE_DPI;
}
/** Sets the default platform DPI. Normally this is set in the {@link #setPlatform(int)} for the different platforms
* but it can be tweaked here. For instance SWT on Mac does this.
*
* Note that this is not the actual current DPI, but the base DPI for the toolkit.
* @param dpi The base DPI. If null the default DPI is reset to the platform base DPI.
*/
public static void setDefaultDPI(Integer dpi)
{
BASE_DPI = dpi != null ? dpi.intValue() : getPlatformDPI(CUR_PLAF);
BASE_DPI_FORCED = dpi;
}
/** The forced scale factor that all screen relative units (e.g. millimeters, inches and logical pixels) will be multiplied
* with. If null this will default to a scale that will scale the current screen to the default screen resolution
* (72 DPI for Mac and 92 DPI for Windows).
* @return The forced scale or null for default scaling.
* @see #getHorizontalScaleFactor()
* @see ComponentWrapper#getHorizontalScreenDPI()
*/
public static Float getHorizontalScaleFactor()
{
return horScale;
}
/** The forced scale factor that all screen relative units (e.g. millimeters, inches and logical pixels) will be multiplied
* with. If null this will default to a scale that will scale the current screen to the default screen resolution
* (72 DPI for Mac and 92 DPI for Windows).
* @param f The forced scale or null for default scaling.
* @see #getHorizontalScaleFactor()
* @see ComponentWrapper#getHorizontalScreenDPI()
*/
public static void setHorizontalScaleFactor(Float f)
{
if (LayoutUtil.equals(horScale, f) == false) {
horScale = f;
MOD_COUNT++;
}
}
/** The forced scale factor that all screen relative units (e.g. millimeters, inches and logical pixels) will be multiplied
* with. If null this will default to a scale that will scale the current screen to the default screen resolution
* (72 DPI for Mac and 92 DPI for Windows).
* @return The forced scale or null for default scaling.
* @see #getHorizontalScaleFactor()
* @see ComponentWrapper#getVerticalScreenDPI()
*/
public static Float getVerticalScaleFactor()
{
return verScale;
}
/** The forced scale factor that all screen relative units (e.g. millimeters, inches and logical pixels) will be multiplied
* with. If null this will default to a scale that will scale the current screen to the default screen resolution
* (72 DPI for Mac and 92 DPI for Windows).
* @param f The forced scale or null for default scaling.
* @see #getHorizontalScaleFactor()
* @see ComponentWrapper#getVerticalScreenDPI()
*/
public static void setVerticalScaleFactor(Float f)
{
if (LayoutUtil.equals(verScale, f) == false) {
verScale = f;
MOD_COUNT++;
}
}
/** What base value should be used to calculate logical pixel sizes.
* @return The current base. Default is {@link #BASE_SCALE_FACTOR}
* @see #BASE_FONT_SIZE
* @see # BASE_SCREEN_DPI_FACTOR
* @see #BASE_REAL_PIXEL
*/
public static int getLogicalPixelBase()
{
return LP_BASE;
}
/** What base value should be used to calculate logical pixel sizes.
* @param base The new base. Default is {@link #BASE_SCALE_FACTOR}
* @see #BASE_FONT_SIZE
* @see # BASE_SCREEN_DPI_FACTOR
* @see #BASE_REAL_PIXEL
*/
public static void setLogicalPixelBase(int base)
{
if (LP_BASE != base) {
if (base < BASE_FONT_SIZE || base > BASE_SCALE_FACTOR)
throw new IllegalArgumentException("Unrecognized base: " + base);
LP_BASE = base;
MOD_COUNT++;
}
}
/** Sets gap value for components that are "related".
* @param x The value that will be transformed to pixels. If null the current value will not change.
* @param y The value that will be transformed to pixels. If null the current value will not change.
*/
public static void setRelatedGap(UnitValue x, UnitValue y)
{
setUnitValue(new String[] {"r", "rel", "related"}, x, y);
RELATED_X = new BoundSize(x, x, null, "rel:rel");
RELATED_Y = new BoundSize(y, y, null, "rel:rel");
}
/** Sets gap value for components that are "unrelated".
* @param x The value that will be transformed to pixels. If null the current value will not change.
* @param y The value that will be transformed to pixels. If null the current value will not change.
*/
public static void setUnrelatedGap(UnitValue x, UnitValue y)
{
setUnitValue(new String[] {"u", "unrel", "unrelated"}, x, y);
UNRELATED_X = new BoundSize(x, x, null, "unrel:unrel");
UNRELATED_Y = new BoundSize(y, y, null, "unrel:unrel");
}
/** Sets paragraph gap value for components.
* @param x The value that will be transformed to pixels. If null the current value will not change.
* @param y The value that will be transformed to pixels. If null the current value will not change.
*/
public static void setParagraphGap(UnitValue x, UnitValue y)
{
setUnitValue(new String[] {"p", "para", "paragraph"}, x, y);
}
/** Sets gap value for components that are "intended".
* @param x The value that will be transformed to pixels. If null the current value will not change.
* @param y The value that will be transformed to pixels. If null the current value will not change.
*/
public static void setIndentGap(UnitValue x, UnitValue y)
{
setUnitValue(new String[] {"i", "ind", "indent"}, x, y);
}
/** 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
* on the component constraints. The value will be the min and preferred size of the gap.
* @param x The value that will be transformed to pixels. If null the current value will not change.
* @param y The value that will be transformed to pixels. If null the current value will not change.
*/
public static void setGridCellGap(UnitValue x, UnitValue y)
{
if (x != null)
DEF_HGAP = new BoundSize(x, x, null, null);
if (y != null)
DEF_VGAP = new BoundSize(y, y, null, null);
MOD_COUNT++;
}
/** Sets the recommended minimum button width.
* @param width The recommended minimum button width.
*/
public static void setMinimumButtonWidth(UnitValue width)
{
BUTT_WIDTH = width;
MOD_COUNT++;
}
/** Returns the recommended minimum button width depending on the current set platform.
* @return The recommended minimum button width depending on the current set platform.
*/
public static UnitValue getMinimumButtonWidth()
{
return BUTT_WIDTH;
}
/** Returns the unit value associated with the unit. (E.i. "related" or "indent"). Must be lower case.
* @param unit The unit string.
* @return The unit value associated with the unit. null for unrecognized units.
*/
public static UnitValue getUnitValueX(String unit)
{
return HOR_DEFS.get(unit);
}
/** Returns the unit value associated with the unit. (E.i. "related" or "indent"). Must be lower case.
* @param unit The unit string.
* @return The unit value associated with the unit. null for unrecognized units.
*/
public static UnitValue getUnitValueY(String unit)
{
return VER_DEFS.get(unit);
}
/** Sets the unit value associated with a unit string. This may be used to store values for new unit strings
* or modify old. Note that if a built in unit (such as "related") is modified all versions of it must be
* set (I.e. "r", "rel" and "related"). The build in values will be reset to the default ones if the platform
* is re-set.
* @param unitStrings The unit strings. E.g. "mu", "myunit". Will be converted to lower case and trimmed. Not null.
* @param x The value for the horizontal dimension. If null the value is not changed.
* @param y The value for the vertical dimension. Might be same object as for x. If null the value is not changed.
*/
public static final void setUnitValue(String[] unitStrings, UnitValue x, UnitValue y)
{
for (int i = 0; i < unitStrings.length; i++) {
String s = unitStrings[i].toLowerCase().trim();
if (x != null)
HOR_DEFS.put(s, x);
if (y != null)
VER_DEFS.put(s, y);
}
MOD_COUNT++;
}
/** Understands ("r", "rel", "related") OR ("u", "unrel", "unrelated") OR ("i", "ind", "indent") OR ("p", "para", "paragraph").
*/
static final int convertToPixels(float value, String unit, boolean isHor, float ref, ContainerWrapper parent, ComponentWrapper comp)
{
UnitValue uv = (isHor ? HOR_DEFS : VER_DEFS).get(unit);
return uv != null ? Math.round(value * uv.getPixels(ref, parent, comp)) : UnitConverter.UNABLE;
}
/** Returns the order for the typical buttons in a standard button bar. It is one letter per button type.
* @return The button order.
* @see #setButtonOrder(String)
*/
public static final String getButtonOrder()
{
return BUTTON_FORMAT;
}
/** Sets the order for the typical buttons in a standard button bar. It is one letter per button type.
*
* Letter in upper case will get the minimum button width that the {@link #getMinimumButtonWidth()} specifies
* and letters in lower case will get the width the current look&feel specifies.
*
* Gaps will never be added to before the first component or after the last component. However, '+' (push) will be
* applied before and after as well, but with a minimum size of 0 if first/last so there will not be a gap
* before or after.
*
* If gaps are explicitly set on buttons they will never be reduced, but they may be increased.
*
* These are the characters that can be used:
*
*
'L' - Buttons with this style tag will staticall end up on the left end of the bar.
*
'R' - Buttons with this style tag will staticall end up on the right end of the bar.
*
'H' - A tag for the "help" button that normally is supposed to be on the right.
*
'E' - A tag for the "help2" button that normally is supposed to be on the left.
*
'Y' - A tag for the "yes" button.
*
'N' - A tag for the "no" button.
*
'X' - A tag for the "next >" or "forward >" button.
*
'B' - A tag for the "< back>" or "< previous" button.
*
'I' - A tag for the "finish".
*
'A' - A tag for the "apply" button.
*
'C' - A tag for the "cancel" or "close" button.
*
'O' - A tag for the "ok" or "done" button.
*
'U' - All Uncategorized, Other, or "Unknown" buttons. Tag will be "other".
*
'+' - A glue push gap that will take as much space as it can and at least an "unrelated" gap. (Platform dependant)
*
'_' - (underscore) An "unrelated" gap. (Platform dependant)
*
*
* Even though the style tags are normally applied to buttons this works with all components.
*
* The normal style for MAC OS X is "L_HE+U+FBI_NYCOA_R",
* for Windows is "L_E+U+FBI_YNOCAH_R", and for GNOME is
* "L_HE+UNYACBXIO_R".
*
* @param order The new button order for the current platform.
*/
public static final void setButtonOrder(String order)
{
BUTTON_FORMAT = order;
MOD_COUNT++;
}
/** Returns the tag (used in the {@link CC}) for a char. The char is same as used in {@link #getButtonOrder()}.
* @param c The char. Must be lower case!
* @return The tag that corresponds to the char or null if the char is unrecognized.
*/
static final String getTagForChar(char c)
{
switch (c) {
case 'o':
return "ok";
case 'c':
return "cancel";
case 'h':
return "help";
case 'e':
return "help2";
case 'y':
return "yes";
case 'n':
return "no";
case 'a':
return "apply";
case 'x':
return "next"; // a.k.a forward
case 'b':
return "back"; // a.k.a. previous
case 'i':
return "finish";
case 'l':
return "left";
case 'r':
return "right";
case 'u':
return "other";
default:
return null;
}
}
/** Returns the platform recommended inter-cell gap in the horizontal (x) dimension..
* @return The platform recommended inter-cell gap in the horizontal (x) dimension..
*/
public static BoundSize getGridGapX()
{
return DEF_HGAP;
}
/** Returns the platform recommended inter-cell gap in the vertical (x) dimension..
* @return The platform recommended inter-cell gap in the vertical (x) dimension..
*/
public static BoundSize getGridGapY()
{
return DEF_VGAP;
}
/** Returns the default dialog inset depending of the current platform.
* @param side top == 0, left == 1, bottom = 2, right = 3.
* @return The inset. Never null.
*/
public static UnitValue getDialogInsets(int side)
{
return DIALOG_INS[side];
}
/** Sets the default insets for a dialog. Values that are null will not be changed.
* @param top The top inset. May be null.
* @param left The left inset. May be null.
* @param bottom The bottom inset. May be null.
* @param right The right inset. May be null.
*/
public static void setDialogInsets(UnitValue top, UnitValue left, UnitValue bottom, UnitValue right)
{
if (top != null)
DIALOG_INS[0] = top;
if (left != null)
DIALOG_INS[1] = left;
if (bottom != null)
DIALOG_INS[2] = bottom;
if (right != null)
DIALOG_INS[3] = right;
MOD_COUNT++;
}
/** Returns the default panel inset depending of the current platform.
* @param side top == 0, left == 1, bottom = 2, right = 3.
* @return The inset. Never null.
*/
public static UnitValue getPanelInsets(int side)
{
return PANEL_INS[side];
}
/** Sets the default insets for a dialog. Values that are null will not be changed.
* @param top The top inset. May be null.
* @param left The left inset. May be null.
* @param bottom The bottom inset. May be null.
* @param right The right inset. May be null.
*/
public static void setPanelInsets(UnitValue top, UnitValue left, UnitValue bottom, UnitValue right)
{
if (top != null)
PANEL_INS[0] = top;
if (left != null)
PANEL_INS[1] = left;
if (bottom != null)
PANEL_INS[2] = bottom;
if (right != null)
PANEL_INS[3] = right;
MOD_COUNT++;
}
/** Returns the percentage used for alignment for labels (0 is left, 50 is center and 100 is right).
* @return The percentage used for alignment for labels
*/
public static float getLabelAlignPercentage()
{
return CUR_PLAF == MAC_OSX ? 1f : 0f;
}
/** Returns the default gap between two components that are in the same cell.
* @param comp The component that the gap is for. Never null.
* @param adjacentComp The adjacent component if any. May be null.
* @param adjacentSide What side the adjacentComp is on. {@link javax.swing.SwingUtilities#TOP} or
* {@link javax.swing.SwingUtilities#LEFT} or {@link javax.swing.SwingUtilities#BOTTOM} or {@link javax.swing.SwingUtilities#RIGHT}.
* @param tag The tag string that the component might be tagged with in the component constraints. May be null.
* @param isLTR If it is left-to-right.
* @return The default gap between two components or null if there should be no gap.
*/
static BoundSize getDefaultComponentGap(ComponentWrapper comp, ComponentWrapper adjacentComp, int adjacentSide, String tag, boolean isLTR)
{
if (GAP_PROVIDER != null)
return GAP_PROVIDER.getDefaultGap(comp, adjacentComp, adjacentSide, tag, isLTR);
if (adjacentComp == null)
return null;
// if (adjacentComp == null || adjacentSide == SwingConstants.LEFT || adjacentSide == SwingConstants.TOP)
// return null;
return (adjacentSide == SwingConstants.LEFT || adjacentSide == SwingConstants.RIGHT) ? RELATED_X : RELATED_Y;
}
/** Returns the current gap provider or null if none is set and "related" should always be used.
* @return The current gap provider or null if none is set and "related" should always be used.
*/
public static InCellGapProvider getGapProvider()
{
return GAP_PROVIDER;
}
/** Sets the current gap provider or null if none is set and "related" should always be used.
* @param provider The current gap provider or null if none is set and "related" should always be used.
*/
public static void setGapProvider(InCellGapProvider provider)
{
GAP_PROVIDER = provider;
}
/** Returns how many times the defaults has been changed. This can be used as a light weight check to
* see if layout caches needs to be refreshed.
* @return How many times the defaults has been changed.
*/
public static int getModCount()
{
return MOD_COUNT;
}
/** Tells all layout manager instances to revalidate and recalculated everything.
*/
public void invalidate()
{
MOD_COUNT++;
}
/** Returns the current default unit. The default unit is the unit used if no unit is set. E.g. "width 10".
* @return The current default unit.
* @see UnitValue#PIXEL
* @see UnitValue#LPX
*/
public final static int getDefaultHorizontalUnit()
{
return DEF_H_UNIT;
}
/** Sets the default unit. The default unit is the unit used if no unit is set. E.g. "width 10".
* @param unit The new default unit.
* @see UnitValue#PIXEL
* @see UnitValue#LPX
*/
public final static void setDefaultHorizontalUnit(int unit)
{
if (unit < UnitValue.PIXEL || unit > UnitValue.LABEL_ALIGN)
throw new IllegalArgumentException("Illegal Unit: " + unit);
if (DEF_H_UNIT != unit) {
DEF_H_UNIT = unit;
MOD_COUNT++;
}
}
/** Returns the current default unit. The default unit is the unit used if no unit is set. E.g. "width 10".
* @return The current default unit.
* @see UnitValue#PIXEL
* @see UnitValue#LPY
*/
public final static int getDefaultVerticalUnit()
{
return DEF_V_UNIT;
}
/** Sets the default unit. The default unit is the unit used if no unit is set. E.g. "width 10".
* @param unit The new default unit.
* @see UnitValue#PIXEL
* @see UnitValue#LPY
*/
public final static void setDefaultVerticalUnit(int unit)
{
if (unit < UnitValue.PIXEL || unit > UnitValue.LABEL_ALIGN)
throw new IllegalArgumentException("Illegal Unit: " + unit);
if (DEF_V_UNIT != unit) {
DEF_V_UNIT = unit;
MOD_COUNT++;
}
}
/** The default alignment for rows. Pre v3.5 this was false but now it is
* true.
* @return The current value. Default is true.
* @since 3.5
*/
public static boolean getDefaultRowAlignmentBaseline()
{
return dra;
}
/** The default alignment for rows. Pre v3.5 this was false but now it is
* true.
* @param b The new value. Default is true from v3.5.
* @since 3.5
*/
public static void setDefaultRowAlignmentBaseline(boolean b)
{
dra = b;
}
}
miglayout-3.7.4/net/miginfocom/layout/CC.java0000644000175000017500000023231711302377550017700 0ustar tonytonypackage net.miginfocom.layout;
import java.io.*;
import java.util.ArrayList;
/*
* License (BSD):
* ==============
*
* Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
* Neither the name of the MiG InfoCom AB nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* @version 1.0
* @author Mikael Grev, MiG InfoCom AB
* Date: 2006-sep-08
*/
/** A simple value holder for one component's constraint.
*/
public final class CC implements Externalizable
{
private static final BoundSize DEF_GAP = BoundSize.NULL_SIZE; // Only used to denote default wrap/newline gap.
static final String[] DOCK_SIDES = {"north", "west", "south", "east"};
// See the getters and setters for information about the properties below.
private int dock = -1;
private UnitValue[] pos = null; // [x1, y1, x2, y2]
private UnitValue[] padding = null; // top, left, bottom, right
private Boolean flowX = null;
private int skip = 0;
private int split = 1;
private int spanX = 1, spanY = 1;
private int cellX = -1, cellY = 0; // If cellX is -1 then cellY is also considered -1. cellY is never negative.
private String tag = null;
private String id = null;
private int hideMode = -1;
private DimConstraint hor = new DimConstraint();
private DimConstraint ver = new DimConstraint();
private BoundSize newline = null;
private BoundSize wrap = null;
private boolean boundsInGrid = true;
private boolean external = false;
private Float pushX = null, pushY = null;
// ***** Tmp cache field
private static final String[] EMPTY_ARR = new String[0];
private transient String[] linkTargets = null;
/** Empty constructor.
*/
public CC()
{
}
String[] getLinkTargets()
{
if (linkTargets == null) {
final ArrayList targets = new ArrayList(2);
if (pos != null) {
for (int i = 0; i < pos.length ; i++)
addLinkTargetIDs(targets, pos[i]);
}
linkTargets = targets.size() == 0 ? EMPTY_ARR : targets.toArray(new String[targets.size()]);
}
return linkTargets;
}
private void addLinkTargetIDs(ArrayList targets, UnitValue uv)
{
if (uv != null) {
String linkId = uv.getLinkTargetId();
if (linkId != null) {
targets.add(linkId);
} else {
for (int i = uv.getSubUnitCount() - 1; i >= 0; i--) {
UnitValue subUv = uv.getSubUnitValue(i);
if (subUv.isLinkedDeep())
addLinkTargetIDs(targets, subUv);
}
}
}
}
// **********************************************************
// Chaining constraint setters
// **********************************************************
/** Specifies that the component should be put in the end group s and will thus share the same ending
* coordinate as them within the group.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param s A name to associate on the group that should be the same for other rows/columns in the same group.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
*/
public final CC endGroupX(String s)
{
hor.setEndGroup(s);
return this;
}
/** Specifies that the component should be put in the size group s and will thus share the same size
* as them within the group.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param s A name to associate on the group that should be the same for other rows/columns in the same group.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
*/
public final CC sizeGroupX(String s)
{
hor.setSizeGroup(s);
return this;
}
/** The minimum size for the component. The value will override any value that is set on the component itself.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param size The size expressed as a UnitValue. E.g. "100px" or "200mm".
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
*/
public final CC minWidth(String size)
{
hor.setSize(LayoutUtil.derive(hor.getSize(), ConstraintParser.parseUnitValue(size, true), null, null));
return this;
}
/** The size for the component as a min and/or preferref and/or maximum size. The value will override any value that is set on
* the component itself.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param size The size expressed as a BoundSize. E.g. "50:100px:200mm" or "100px".
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
*/
public final CC width(String size)
{
hor.setSize(ConstraintParser.parseBoundSize(size, false, true));
return this;
}
/** The maximum size for the component. The value will override any value that is set on the component itself.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param size The size expressed as a UnitValue. E.g. "100px" or "200mm".
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
*/
public final CC maxWidth(String size)
{
hor.setSize(LayoutUtil.derive(hor.getSize(), null, null, ConstraintParser.parseUnitValue(size, true)));
return this;
}
/** The horizontal gap before and/or after the component. The gap is towards cell bounds and/or other component bounds.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param before The size of the gap expressed as a BoundSize. E.g. "50:100px:200mm" or "100px!".
* @param after The size of the gap expressed as a BoundSize. E.g. "50:100px:200mm" or "100px!".
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
*/
public final CC gapX(String before, String after)
{
if (before != null)
hor.setGapBefore(ConstraintParser.parseBoundSize(before, true, true));
if (after != null)
hor.setGapAfter(ConstraintParser.parseBoundSize(after, true, true));
return this;
}
/** Same functionality as getHorizontal().setAlign(ConstraintParser.parseUnitValue(unitValue, true)) only this method
* returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param align The align keyword or for instance "100px". E.g "left", "right", "leading" or "trailing".
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
*/
public final CC alignX(String align)
{
hor.setAlign(ConstraintParser.parseUnitValueOrAlign(align, true, null));
return this;
}
/** The grow priority compared to other components in the same cell.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param p The grow priority.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
*/
public final CC growPrioX(int p)
{
hor.setGrowPriority(p);
return this;
}
/** Grow priority for the component horizontally and optionally vertically.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param widthHeight The new shrink weight and height. 1-2 arguments, never null.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
* @since 3.7.2
*/
public final CC growPrio(int ... widthHeight)
{
switch (widthHeight.length) {
default:
throw new IllegalArgumentException("Illegal argument count: " + widthHeight.length);
case 2:
growPrioY(widthHeight[1]);
case 1:
growPrioX(widthHeight[0]);
}
return this;
}
/** Grow weight for the component horizontally. It default to weight 100.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
* @see #growX(float)
*/
public final CC growX()
{
hor.setGrow(ResizeConstraint.WEIGHT_100);
return this;
}
/** Grow weight for the component horizontally.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param w The new grow weight.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
*/
public final CC growX(float w)
{
hor.setGrow(new Float(w));
return this;
}
/** grow weight for the component horizontally and optionally vertically.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param widthHeight The new shrink weight and height. 1-2 arguments, never null.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
* @since 3.7.2
*/
public final CC grow(float ... widthHeight)
{
switch (widthHeight.length) {
default:
throw new IllegalArgumentException("Illegal argument count: " + widthHeight.length);
case 2:
growY(widthHeight[1]);
case 1:
growX(widthHeight[0]);
}
return this;
}
/** The shrink priority compared to other components in the same cell.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param p The shrink priority.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
*/
public final CC shrinkPrioX(int p)
{
hor.setShrinkPriority(p);
return this;
}
/** Shrink priority for the component horizontally and optionally vertically.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param widthHeight The new shrink weight and height. 1-2 arguments, never null.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
* @since 3.7.2
*/
public final CC shrinkPrio(int ... widthHeight)
{
switch (widthHeight.length) {
default:
throw new IllegalArgumentException("Illegal argument count: " + widthHeight.length);
case 2:
shrinkPrioY(widthHeight[1]);
case 1:
shrinkPrioX(widthHeight[0]);
}
return this;
}
/** Shrink weight for the component horizontally.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param w The new shrink weight.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
*/
public final CC shrinkX(float w)
{
hor.setShrink(new Float(w));
return this;
}
/** Shrink weight for the component horizontally and optionally vertically.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param widthHeight The new shrink weight and height. 1-2 arguments, never null.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
* @since 3.7.2
*/
public final CC shrink(float ... widthHeight)
{
switch (widthHeight.length) {
default:
throw new IllegalArgumentException("Illegal argument count: " + widthHeight.length);
case 2:
shrinkY(widthHeight[1]);
case 1:
shrinkX(widthHeight[0]);
}
return this;
}
/** The end group that this componet should be placed in.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param s The name of the group. If null that means no group (default)
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
*/
public final CC endGroupY(String s)
{
ver.setEndGroup(s);
return this;
}
/** The end group(s) that this componet should be placed in.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param xy The end group for x and y repsectively. 1-2 arguments, not null.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
* @since 3.7.2
*/
public final CC endGroup(String ... xy)
{
switch (xy.length) {
default:
throw new IllegalArgumentException("Illegal argument count: " + xy.length);
case 2:
endGroupY(xy[1]);
case 1:
endGroupX(xy[0]);
}
return this;
}
/** The size group that this componet should be placed in.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param s The name of the group. If null that means no group (default)
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
*/
public final CC sizeGroupY(String s)
{
ver.setSizeGroup(s);
return this;
}
/** The size group(s) that this componet should be placed in.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param xy The size group for x and y repsectively. 1-2 arguments, not null.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
* @since 3.7.2
*/
public final CC sizeGroup(String ... xy)
{
switch (xy.length) {
default:
throw new IllegalArgumentException("Illegal argument count: " + xy.length);
case 2:
sizeGroupY(xy[1]);
case 1:
sizeGroupX(xy[0]);
}
return this;
}
/** The minimum size for the component. The value will override any value that is set on the component itself.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param size The size expressed as a UnitValue. E.g. "100px" or "200mm".
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
*/
public final CC minHeight(String size)
{
ver.setSize(LayoutUtil.derive(ver.getSize(), ConstraintParser.parseUnitValue(size, false), null, null));
return this;
}
/** The size for the component as a min and/or preferref and/or maximum size. The value will override any value that is set on
* the component itself.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param size The size expressed as a BoundSize. E.g. "50:100px:200mm" or "100px".
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
*/
public final CC height(String size)
{
ver.setSize(ConstraintParser.parseBoundSize(size, false, false));
return this;
}
/** The maximum size for the component. The value will override any value that is set on the component itself.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param size The size expressed as a UnitValue. E.g. "100px" or "200mm".
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
*/
public final CC maxHeight(String size)
{
ver.setSize(LayoutUtil.derive(ver.getSize(), null, null, ConstraintParser.parseUnitValue(size, false)));
return this;
}
/** The vertical gap before (normally above) and/or after (normally below) the component. The gap is towards cell bounds and/or other component bounds.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param before The size of the gap expressed as a BoundSize. E.g. "50:100px:200mm" or "100px!".
* @param after The size of the gap expressed as a BoundSize. E.g. "50:100px:200mm" or "100px!".
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
*/
public final CC gapY(String before, String after)
{
if (before != null)
ver.setGapBefore(ConstraintParser.parseBoundSize(before, true, false));
if (after != null)
ver.setGapAfter(ConstraintParser.parseBoundSize(after, true, false));
return this;
}
/** Same functionality as getVertical().setAlign(ConstraintParser.parseUnitValue(unitValue, true)) only this method
* returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param align The align keyword or for instance "100px". E.g "top" or "bottom".
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
*/
public final CC alignY(String align)
{
ver.setAlign(ConstraintParser.parseUnitValueOrAlign(align, false, null));
return this;
}
/** The grow priority compared to other components in the same cell.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param p The grow priority.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
*/
public final CC growPrioY(int p)
{
ver.setGrowPriority(p);
return this;
}
/** Grow weight for the component vertically. Defaults to 100.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
* @see #growY(Float)
*/
public final CC growY()
{
ver.setGrow(ResizeConstraint.WEIGHT_100);
return this;
}
/** Grow weight for the component vertically.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param w The new grow weight.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
*/
public final CC growY(Float w)
{
ver.setGrow(w);
return this;
}
/** The shrink priority compared to other components in the same cell.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param p The shrink priority.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
*/
public final CC shrinkPrioY(int p)
{
ver.setShrinkPriority(p);
return this;
}
/** Shrink weight for the component horizontally.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param w The new shrink weight.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
*/
public final CC shrinkY(float w)
{
ver.setShrink(new Float(w));
return this;
}
/** How this component, if hidden (not visible), should be treated.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param mode The mode. Default to the mode in the {@link net.miginfocom.layout.LC}.
* 0 == Normal. Bounds will be calculated as if the component was visible.
* 1 == If hidden the size will be 0, 0 but the gaps remain.
* 2 == If hidden the size will be 0, 0 and gaps set to zero.
* 3 == If hidden the component will be disregarded completely and not take up a cell in the grid..
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
*/
public final CC hideMode(int mode)
{
setHideMode(mode);
return this;
}
/** The id used to reference this component in some constraints.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param s The id or null. May consist of a groupID and an componentID which are separated by a dot: ".". E.g. "grp1.id1".
* The dot should never be first or last if present.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
*/
public final CC id(String s)
{
setId(s);
return this;
}
/** Same functionality as {@link #setTag(String tag)} only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param tag The new tag. May be null.
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @see #setTag(String)
*/
public final CC tag(String tag)
{
setTag(tag);
return this;
}
/** Set the cell(s) that the component should occupy in the grid. Same functionality as {@link #setCellX(int col)} and
* {@link #setCellY(int row)} together with {@link #setSpanX(int width)} and {@link #setSpanY(int height)}. This method
* returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param colRowWidthHeight cellX, cellY, spanX, spanY repectively. 1-4 arguments, not null.
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @see #setCellX(int)
* @see #setCellY(int)
* @see #setSpanX(int)
* @see #setSpanY(int)
* @since 3.7.2. Replacing cell(int, int) and cell(int, int, int, int)
*/
public final CC cell(int ... colRowWidthHeight)
{
switch (colRowWidthHeight.length) {
default:
throw new IllegalArgumentException("Illegal argument count: " + colRowWidthHeight.length);
case 4:
setSpanY(colRowWidthHeight[3]);
case 3:
setSpanX(colRowWidthHeight[2]);
case 2:
setCellY(colRowWidthHeight[1]);
case 1:
setCellX(colRowWidthHeight[0]);
}
return this;
}
/** Same functionality as spanX(cellsX).spanY(cellsY) which means this cell will span cells in both x and y.
* This method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* Since 3.7.2 this takes an array/vararg whereas it previously only took two specific values, xSpan and ySpan.
* @param cells spanX and spanY, when present, and in that order.
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @see #setSpanY(int)
* @see #setSpanX(int)
* @see #spanY()
* @see #spanX()
* @since 3.7.2 Replaces span(int, int).
*/
public final CC span(int ... cells)
{
if (cells == null || cells.length == 0) {
setSpanX(LayoutUtil.INF);
setSpanY(1);
} else if (cells.length == 1) {
setSpanX(cells[0]);
setSpanY(1);
} else {
setSpanX(cells[0]);
setSpanY(cells[1]);
}
return this;
}
/** Corresponds exactly to the "gap left right top bottom" keyword.
* @param args Same as for the "gap" keyword. Length 1-4, never null buf elements can be null.
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @since 3.7.2
*/
public final CC gap(String ... args)
{
switch (args.length) {
default:
throw new IllegalArgumentException("Illegal argument count: " + args.length);
case 4:
gapBottom(args[3]);
case 3:
gapTop(args[2]);
case 2:
gapRight(args[1]);
case 1:
gapLeft(args[0]);
}
return this;
}
/** Sets the horizontal gap before the component.
*
* Note! This is currently same as gapLeft(). This might change in 4.x.
* @param boundsSize The size of the gap expressed as a BoundSize. E.g. "50:100px:200mm" or "100px!".
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @since 3.7.2
*/
public final CC gapBefore(String boundsSize)
{
hor.setGapBefore(ConstraintParser.parseBoundSize(boundsSize, true, true));
return this;
}
/** Sets the horizontal gap before the component.
*
* Note! This is currently same as gapLeft(). This might change in 4.x.
* @param boundsSize The size of the gap expressed as a BoundSize. E.g. "50:100px:200mm" or "100px!".
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @since 3.7.2
*/
public final CC gapAfter(String boundsSize)
{
hor.setGapAfter(ConstraintParser.parseBoundSize(boundsSize, true, true));
return this;
}
/** Sets the gap above the component.
* @param boundsSize The size of the gap expressed as a BoundSize. E.g. "50:100px:200mm" or "100px!".
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @since 3.7.2
*/
public final CC gapTop(String boundsSize)
{
ver.setGapBefore(ConstraintParser.parseBoundSize(boundsSize, true, false));
return this;
}
/** Sets the gap above the component.
* @param boundsSize The size of the gap expressed as a BoundSize. E.g. "50:100px:200mm" or "100px!".
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @since 3.7.2
*/
public final CC gapLeft(String boundsSize)
{
hor.setGapBefore(ConstraintParser.parseBoundSize(boundsSize, true, true));
return this;
}
/** Sets the gap above the component.
* @param boundsSize The size of the gap expressed as a BoundSize. E.g. "50:100px:200mm" or "100px!".
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @since 3.7.2
*/
public final CC gapBottom(String boundsSize)
{
ver.setGapAfter(ConstraintParser.parseBoundSize(boundsSize, true, false));
return this;
}
/** Sets the gap above the component.
* @param boundsSize The size of the gap expressed as a BoundSize. E.g. "50:100px:200mm" or "100px!".
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @since 3.7.2
*/
public final CC gapRight(String boundsSize)
{
hor.setGapAfter(ConstraintParser.parseBoundSize(boundsSize, true, true));
return this;
}
/** Same functionality as {@link #setSpanY(int LayoutUtil.INF)} which means this cell will span the rest of the column.
* This method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @see #setSpanY(int)
* @see #spanY()
*/
public final CC spanY()
{
return spanY(LayoutUtil.INF);
}
/** Same functionality as {@link #setSpanY(int cells)} only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param cells The number of cells to span (i.e. merge).
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @see #setSpanY(int)
*/
public final CC spanY(int cells)
{
setSpanY(cells);
return this;
}
/** Same functionality as {@link #setSpanX(int LayoutUtil.INF)} which means this cell will span the rest of the row.
* This method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @see #setSpanX(int)
* @see #spanX()
*/
public final CC spanX()
{
return spanX(LayoutUtil.INF);
}
/** Same functionality as {@link #setSpanX(int cells)} only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param cells The number of cells to span (i.e. merge).
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @see #setSpanY(int)
*/
public final CC spanX(int cells)
{
setSpanX(cells);
return this;
}
/** Same functionality as pushX().pushY() which means this cell will push in both x and y dimensions.
* This method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @see #setPushX(Float)
* @see #setPushX(Float)
* @see #pushY()
* @see #pushX()
*/
public final CC push()
{
return pushX().pushY();
}
/** Same functionality as pushX(weightX).pushY(weightY) which means this cell will push in both x and y dimensions.
* This method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param weightX The weight used in the push.
* @param weightY The weight used in the push.
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @see #setPushY(Float)
* @see #setPushX(Float)
* @see #pushY()
* @see #pushX()
*/
public final CC push(Float weightX, Float weightY)
{
return pushX(weightX).pushY(weightY);
}
/** Same functionality as {@link #setPushY(Float))} which means this cell will push the rest of the column.
* This method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @see #setPushY(Float)
* @see #pushY()
*/
public final CC pushY()
{
return pushY(ResizeConstraint.WEIGHT_100);
}
/** Same functionality as {@link #setPushY(Float weight)} only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param weight The weight used in the push.
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @see #setPushY(Float)
*/
public final CC pushY(Float weight)
{
setPushY(weight);
return this;
}
/** Same functionality as {@link #setPushX(Float)} which means this cell will push the rest of the row.
* This method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @see #setPushX(Float)
* @see #pushX()
*/
public final CC pushX()
{
return pushX(ResizeConstraint.WEIGHT_100);
}
/** Same functionality as {@link #setPushX(Float weight)} only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param weight The weight used in the push.
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @see #setPushY(Float)
*/
public final CC pushX(Float weight)
{
setPushX(weight);
return this;
}
/** Same functionality as {@link #setSplit(int parts)} only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param parts The number of parts (i.e. component slots) the cell should be divided into.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
* @see #setSplit(int)
*/
public final CC split(int parts)
{
setSplit(parts);
return this;
}
/** Same functionality as split(LayoutUtil.INF), which means split until one of the keywords that breaks the split is found for
* a component after this one (e.g. wrap, newline and skip).
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
* @see #setSplit(int)
* @since 3.7.2
*/
public final CC split()
{
setSplit(LayoutUtil.INF);
return this;
}
/** Same functionality as {@link #setSkip(int)} only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param cells How many cells in the grid that should be skipped before the component that this constraint belongs to
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
* @see #setSkip(int)
*/
public final CC skip(int cells)
{
setSkip(cells);
return this;
}
/** Same functionality as skip(1).
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
* @see #setSkip(int)
* @since 3.7.2
*/
public final CC skip()
{
setSkip(1);
return this;
}
/** Same functionality as {@link #setExternal(boolean true)} only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
* @see #setExternal(boolean)
*/
public final CC external()
{
setExternal(true);
return this;
}
/** Same functionality as {@link #setFlowX(Boolean .TRUE)} only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
* @see #setFlowX(Boolean)
*/
public final CC flowX()
{
setFlowX(Boolean.TRUE);
return this;
}
/** Same functionality as {@link #setFlowX(Boolean .FALSE)} only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
* @see #setFlowX(Boolean)
*/
public final CC flowY()
{
setFlowX(Boolean.FALSE);
return this;
}
/** Same functionality as {@link #growX()} and {@link #growY()}.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
* @see #growX()
* @see #growY()
*/
public final CC grow()
{
growX();
growY();
return this;
}
/** Same functionality as {@link #setNewline(boolean true)} only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
* @see #setNewline(boolean)
*/
public final CC newline()
{
setNewline(true);
return this;
}
/** Same functionality as {@link #setNewlineGapSize(BoundSize)} only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param gapSize The gap size that will override the gap size in the row/colum constraints if != null. E.g. "5px" or "unrel".
* If null or "" the newline size will be set to the default size and turned on. This is different compared to
* {@link #setNewlineGapSize(BoundSize)}.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
* @see #setNewlineGapSize(BoundSize)
*/
public final CC newline(String gapSize)
{
BoundSize bs = ConstraintParser.parseBoundSize(gapSize, true, (flowX != null && flowX == false));
if (bs != null) {
setNewlineGapSize(bs);
} else {
setNewline(true);
}
return this;
}
/** Same functionality as {@link #setWrap(boolean true)} only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
* @see #setWrap(boolean)
*/
public final CC wrap()
{
setWrap(true);
return this;
}
/** Same functionality as {@link #setWrapGapSize(BoundSize)} only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param gapSize The gap size that will override the gap size in the row/colum constraints if != null. E.g. "5px" or "unrel".
* If null or "" the wrap size will be set to the default size and turned on. This is different compared to
* {@link #setWrapGapSize(BoundSize)}.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
* @see #setWrapGapSize(BoundSize)
*/
public final CC wrap(String gapSize)
{
BoundSize bs = ConstraintParser.parseBoundSize(gapSize, true, (flowX != null && flowX == false));
if (bs != null) {
setWrapGapSize(bs);
} else {
setWrap(true);
}
return this;
}
/** Same functionality as {@link #setDockSide(int 0)} only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
* @see #setDockSide(int)
*/
public final CC dockNorth()
{
setDockSide(0);
return this;
}
/** Same functionality as {@link #setDockSide(int 1)} only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
* @see #setDockSide(int)
*/
public final CC dockWest()
{
setDockSide(1);
return this;
}
/** Same functionality as {@link #setDockSide(int 2)} only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
* @see #setDockSide(int)
*/
public final CC dockSouth()
{
setDockSide(2);
return this;
}
/** Same functionality as {@link #setDockSide(int 3)} only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
* @see #setDockSide(int)
*/
public final CC dockEast()
{
setDockSide(3);
return this;
}
/** Sets the x-coordinate for the component. This is used to set the x coordinate position to a specific value. The component
* bounds is still precalculated to the grid cell and this method should be seen as a way to correct the x position.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param x The x position as a UnitValue. E.g. "10" or "40mm" or "container.x+10".
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
* @see #setPos(UnitValue[])
* @see #setBoundsInGrid(boolean)
*/
public final CC x(String x)
{
return corrPos(x, 0);
}
/** Sets the y-coordinate for the component. This is used to set the y coordinate position to a specific value. The component
* bounds is still precalculated to the grid cell and this method should be seen as a way to correct the y position.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param y The y position as a UnitValue. E.g. "10" or "40mm" or "container.x+10".
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
* @see #setPos(UnitValue[])
* @see #setBoundsInGrid(boolean)
*/
public final CC y(String y)
{
return corrPos(y, 1);
}
/** Sets the x2-coordinate for the component (right side). This is used to set the x2 coordinate position to a specific value. The component
* bounds is still precalculated to the grid cell and this method should be seen as a way to correct the x position.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param x2 The x2 side's position as a UnitValue. E.g. "10" or "40mm" or "container.x2 - 10".
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
* @see #setPos(UnitValue[])
* @see #setBoundsInGrid(boolean)
*/
public final CC x2(String x2)
{
return corrPos(x2, 2);
}
/** Sets the y2-coordinate for the component (bottom side). This is used to set the y2 coordinate position to a specific value. The component
* bounds is still precalculated to the grid cell and this method should be seen as a way to correct the y position.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param y2 The y2 side's position as a UnitValue. E.g. "10" or "40mm" or "container.x2 - 10".
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
* @see #setPos(UnitValue[])
* @see #setBoundsInGrid(boolean)
*/
public final CC y2(String y2)
{
return corrPos(y2, 3);
}
private final CC corrPos(String uv, int ix)
{
UnitValue[] b = getPos();
if (b == null)
b = new UnitValue[4];
b[ix] = ConstraintParser.parseUnitValue(uv, (ix % 2 == 0));
setPos(b);
setBoundsInGrid(true);
return this;
}
/** Same functionality as {@link #x(String x)} and {@link #y(String y)} toghether.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param x The x position as a UnitValue. E.g. "10" or "40mm" or "container.x+10".
* @param y The y position as a UnitValue. E.g. "10" or "40mm" or "container.x+10".
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
* @see #setPos(UnitValue[])
*/
public final CC pos(String x, String y)
{
UnitValue[] b = getPos();
if (b == null)
b = new UnitValue[4];
b[0] = ConstraintParser.parseUnitValue(x, true);
b[1] = ConstraintParser.parseUnitValue(y, false);
setPos(b);
setBoundsInGrid(false);
return this;
}
/** Same functionality as {@link #x(String x)}, {@link #y(String y)}, {@link #y2(String y)} and {@link #y2(String y)} toghether.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param x The x position as a UnitValue. E.g. "10" or "40mm" or "container.x+10".
* @param y The y position as a UnitValue. E.g. "10" or "40mm" or "container.x+10".
* @param x2 The x2 side's position as a UnitValue. E.g. "10" or "40mm" or "container.x2 - 10".
* @param y2 The y2 side's position as a UnitValue. E.g. "10" or "40mm" or "container.x2 - 10".
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
* @see #setPos(UnitValue[])
*/
public final CC pos(String x, String y, String x2, String y2)
{
setPos(new UnitValue[] {
ConstraintParser.parseUnitValue(x, true),
ConstraintParser.parseUnitValue(y, false),
ConstraintParser.parseUnitValue(x2, true),
ConstraintParser.parseUnitValue(y2, false),
});
setBoundsInGrid(false);
return this;
}
/** Same functionality as {@link #setPadding(UnitValue[])} but the unit values as absolute pixels. This method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param top The top padding that will be added to the y coordinate at the last stage in the layout.
* @param left The top padding that will be added to the x coordinate at the last stage in the layout.
* @param bottom The top padding that will be added to the y2 coordinate at the last stage in the layout.
* @param right The top padding that will be added to the x2 coordinate at the last stage in the layout.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
* @see #setTag(String)
*/
public final CC pad(int top, int left, int bottom, int right)
{
setPadding(new UnitValue[] {
new UnitValue(top), new UnitValue(left), new UnitValue(bottom), new UnitValue(right)
});
return this;
}
/** Same functionality as setPadding(ConstraintParser.parseInsets(pad, false))} only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param pad The string to parse. E.g. "10 10 10 10" or "20". If less than 4 groups the last will be used for the missing.
* @return this so it is possible to chain calls. E.g. new ComponentConstraint().noGrid().gap().fill().
* @see #setTag(String)
*/
public final CC pad(String pad)
{
setPadding(pad != null ? ConstraintParser.parseInsets(pad, false) : null);
return this;
}
// **********************************************************
// Bean properties
// **********************************************************
/** Returns the horizontal dimension constraint for this component constraint. It has constraints for the horizontal size
* and grow/shink priorities and weights.
*
* Note! If any changes is to be made it must be made direct when the object is returned. It is not allowed to save the
* constraint for later use.
* @return The current dimension constraint. Never null.
*/
public DimConstraint getHorizontal()
{
return hor;
}
/** Sets the horizontal dimension constraint for this component constraint. It has constraints for the horizontal size
* and grow/shink priorities and weights.
* @param h The new dimension constraint. If null it will be reset to new DimConstraint();
*/
public void setHorizontal(DimConstraint h)
{
hor = h != null ? h : new DimConstraint();
}
/** Returns the vertical dimension constraint for this component constraint. It has constraints for the vertical size
* and grow/shink priorities and weights.
*
* Note! If any changes is to be made it must be made direct when the object is returned. It is not allowed to save the
* constraint for later use.
* @return The current dimension constraint. Never null.
*/
public DimConstraint getVertical()
{
return ver;
}
/** Sets the vertical dimension constraint for this component constraint. It has constraints for the vertical size
* and grow/shink priorities and weights.
* @param v The new dimension constraint. If null it will be reset to new DimConstraint();
*/
public void setVertical(DimConstraint v)
{
ver = v != null ? v : new DimConstraint();
}
/** Returns the vertical or horizontal dim constraint.
*
* Note! If any changes is to be made it must be made direct when the object is returned. It is not allowed to save the
* constraint for later use.
* @param isHor If the horizontal constraint should be returned.
* @return The dim constraint. Never null.
*/
public DimConstraint getDimConstraint(boolean isHor)
{
return isHor ? hor : ver;
}
/** Returns the absolute positioning of one or more of the edges. This will be applied last in the layout cycle and will not
* affect the flow or grid positions. The positioning is relative to the parent and can not (as padding) be used
* to adjust the edges relative to the old value. May be null and elements may be null.
* null value(s) for the x2 and y2 will be interpreted as to keep the preferred size and thus the x1
* and x2 will just absolutely positions the component.
*
* Note that {@link #setBoundsInGrid(boolean)} changes the interpretation of thisproperty slightly.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return The current value as a new array, free to modify.
*/
public UnitValue[] getPos()
{
return pos != null ? new UnitValue[] {pos[0], pos[1], pos[2], pos[3]} : null;
}
/** Sets absolute positioning of one or more of the edges. This will be applied last in the layout cycle and will not
* affect the flow or grid positions. The positioning is relative to the parent and can not (as padding) be used
* to adjust the edges relative to the old value. May be null and elements may be null.
* null value(s) for the x2 and y2 will be interpreted as to keep the preferred size and thus the x1
* and x2 will just absolutely positions the component.
*
* Note that {@link #setBoundsInGrid(boolean)} changes the interpretation of thisproperty slightly.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param pos UnitValue[] {x, y, x2, y2}. Must be null or of length 4. Elements can be null.
*/
public void setPos(UnitValue[] pos)
{
this.pos = pos != null ? new UnitValue[] {pos[0], pos[1], pos[2], pos[3]} : null;
linkTargets = null;
}
/** Returns if the absolute pos value should be corrections to the component that is in a normal cell. If false
* the value of pos is truly absolute in that it will not affect the grid or have a default bounds in the grid.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return The current value.
* @see #getPos()
*/
public boolean isBoundsInGrid()
{
return boundsInGrid;
}
/** Sets if the absolute pos value should be corrections to the component that is in a normal cell. If false
* the value of pos is truly absolute in that it will not affect the grid or have a default bounds in the grid.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param b true for bounds taken from the grid position. false is default.
* @see #setPos(UnitValue[])
*/
void setBoundsInGrid(boolean b)
{
this.boundsInGrid = b;
}
/** Returns the absolute cell position in the grid or -1 if cell positioning is not used.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return The current value.
*/
public int getCellX()
{
return cellX;
}
/** Set an absolute cell x-position in the grid. If >= 0 this point points to the absolute cell that this constaint's component should occupy.
* If there's already a component in that cell they will split the cell. The flow will then continue after this cell.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param x The x-position or -1 to disable cell positioning.
*/
public void setCellX(int x)
{
cellX = x;
}
/** Returns the absolute cell position in the grid or -1 if cell positioning is not used.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return The current value.
*/
public int getCellY()
{
return cellX < 0 ? -1 : cellY;
}
/** Set an absolute cell x-position in the grid. If >= 0 this point points to the absolute cell that this constaint's component should occupy.
* If there's already a component in that cell they will split the cell. The flow will then continue after this cell.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param y The y-position or -1 to disable cell positioning.
*/
public void setCellY(int y)
{
if (y < 0)
cellX = -1;
cellY = y < 0 ? 0 : y;
}
/** Sets the docking side. -1 means no docking.
* Valid sides are: north = 0, west = 1, south = 2, east = 3.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return The current side.
*/
public int getDockSide()
{
return dock;
}
/** Sets the docking side. -1 means no docking.
* Valid sides are: north = 0, west = 1, south = 2, east = 3.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param side -1 or 0-3.
*/
public void setDockSide(int side)
{
if (side < -1 || side > 3)
throw new IllegalArgumentException("Illegal dock side: " + side);
dock = side;
}
/** Returns if this component should have its bounds handled by an external source and not this layout manager.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return The current value.
*/
public boolean isExternal()
{
return external;
}
/** If this boolean is true this component is not handled in any way by the layout manager and the component can have its bounds set by an external
* handler which is normally by the use of some component.setBounds(x, y, width, height) directly (for Swing).
*
* The bounds will not affect the minimum and preferred size of the container.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param b true means that the bounds are not changed.
*/
public void setExternal(boolean b)
{
this.external = b;
}
/** Returns if the flow in the cell is in the horizontal dimension. Vertical if false. Only the first
* component is a cell can set the flow.
*
* If null the flow direction is inherited by from the {@link net.miginfocom.layout.LC}.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return The current value.
*/
public Boolean getFlowX()
{
return flowX;
}
/** Sets if the flow in the cell is in the horizontal dimension. Vertical if false. Only the first
* component is a cell can set the flow.
*
* If null the flow direction is inherited by from the {@link net.miginfocom.layout.LC}.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param b Boolean.TRUE means horizontal flow in the cell.
*/
public void setFlowX(Boolean b)
{
this.flowX = b;
}
/** Sets how a component that is hidden (not visible) should be treated by default.
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return The mode:
* 0 == Normal. Bounds will be calculated as if the component was visible.
* 1 == If hidden the size will be 0, 0 but the gaps remain.
* 2 == If hidden the size will be 0, 0 and gaps set to zero.
* 3 == If hidden the component will be disregarded completely and not take up a cell in the grid..
*/
public int getHideMode()
{
return hideMode;
}
/** Sets how a component that is hidden (not visible) should be treated by default.
* @param mode The mode:
* 0 == Normal. Bounds will be calculated as if the component was visible.
* 1 == If hidden the size will be 0, 0 but the gaps remain.
* 2 == If hidden the size will be 0, 0 and gaps set to zero.
* 3 == If hidden the component will be disregarded completely and not take up a cell in the grid..
*/
public void setHideMode(int mode)
{
if (mode < -1 || mode > 3)
throw new IllegalArgumentException("Wrong hideMode: " + mode);
hideMode = mode;
}
/** Returns the id used to reference this component in some constraints.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return The id or null. May consist of a groupID and an componentID which are separated by a dot: ".". E.g. "grp1.id1".
* The dot should never be first or last if present.
*/
public String getId()
{
return id;
}
/** Sets the id used to reference this component in some constraints.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param id The id or null. May consist of a groupID and an componentID which are separated by a dot: ".". E.g. "grp1.id1".
* The dot should never be first or last if present.
*/
public void setId(String id)
{
this.id = id;
}
/** Returns the absolute resizing in the last stage of the layout cycle. May be null and elements may be null.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return The current value. null or of length 4.
*/
public UnitValue[] getPadding()
{
return padding != null ? new UnitValue[] {padding[0], padding[1], padding[2], padding[3]} : null;
}
/** Sets the absolute resizing in the last stage of the layout cycle. These values are added to the edges and can thus for
* instance be used to grow or reduce the size or move the component an absolute number of pixels. May be null
* and elements may be null.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param sides top, left, bottom right. Must be null or of length 4.
*/
public void setPadding(UnitValue[] sides)
{
this.padding = sides != null ? new UnitValue[] {sides[0], sides[1], sides[2], sides[3]} : null;
}
/** Returns how many cells in the grid that should be skipped before the component that this constraint belongs to.
*
* Note that only the first component will be checked for this property.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return The current value. 0 if no skip.
*/
public int getSkip()
{
return skip;
}
/** Sets how many cells in the grid that should be skipped before the component that this constraint belongs to.
*
* Note that only the first component will be checked for this property.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param cells How many cells in the grid that should be skipped before the component that this constraint belongs to
*/
public void setSkip(int cells)
{
this.skip = cells;
}
/** Returns the number of cells the cell that this constraint's component will span in the indicated dimension. 1 is default and
* means that it only spans the current cell. LayoutUtil.INF is used to indicate a span to the end of the column/row.
*
* Note that only the first component will be checked for this property.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return The current value.
*/
public int getSpanX()
{
return spanX;
}
/** Sets the number of cells the cell that this constraint's component will span in the indicated dimension. 1 is default and
* means that it only spans the current cell. LayoutUtil.INF is used to indicate a span to the end of the column/row.
*
* Note that only the first component will be checked for this property.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param cells The number of cells to span (i.e. merge).
*/
public void setSpanX(int cells)
{
this.spanX = cells;
}
/** Returns the number of cells the cell that this constraint's component will span in the indicated dimension. 1 is default and
* means that it only spans the current cell. LayoutUtil.INF is used to indicate a span to the end of the column/row.
*
* Note that only the first component will be checked for this property.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return The current value.
*/
public int getSpanY()
{
return spanY;
}
/** Sets the number of cells the cell that this constraint's component will span in the indicated dimension. 1 is default and
* means that it only spans the current cell. LayoutUtil.INF is used to indicate a span to the end of the column/row.
*
* Note that only the first component will be checked for this property.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param cells The number of cells to span (i.e. merge).
*/
public void setSpanY(int cells)
{
this.spanY = cells;
}
/** "pushx" indicates that the column that this component is in (this first if the component spans) should default to growing.
* If any other column has been set to grow this push value on the component does nothing as the column's explicit grow weight
* will take precedence. Push is normally used when the grid has not been defined in the layout.
*
* If multiple components in a column has push weights set the largest one will be used for the column.
* @return The current push value. Default is null.
*/
public Float getPushX()
{
return pushX;
}
/** "pushx" indicates that the column that this component is in (this first if the component spans) should default to growing.
* If any other column has been set to grow this push value on the component does nothing as the column's explicit grow weight
* will take precedence. Push is normally used when the grid has not been defined in the layout.
*
* If multiple components in a column has push weights set the largest one will be used for the column.
* @param weight The new push value. Default is null.
*/
public void setPushX(Float weight)
{
this.pushX = weight;
}
/** "pushx" indicates that the row that this component is in (this first if the component spans) should default to growing.
* If any other row has been set to grow this push value on the component does nothing as the row's explicit grow weight
* will take precedence. Push is normally used when the grid has not been defined in the layout.
*
* If multiple components in a row has push weights set the largest one will be used for the row.
* @return The current push value. Default is null.
*/
public Float getPushY()
{
return pushY;
}
/** "pushx" indicates that the row that this component is in (this first if the component spans) should default to growing.
* If any other row has been set to grow this push value on the component does nothing as the row's explicit grow weight
* will take precedence. Push is normally used when the grid has not been defined in the layout.
*
* If multiple components in a row has push weights set the largest one will be used for the row.
* @param weight The new push value. Default is null.
*/
public void setPushY(Float weight)
{
this.pushY = weight;
}
/** Returns in how many parts the current cell (that this constraint's component will be in) should be split in. If for instance
* it is split in two, the next componet will also share the same cell. Note that the cell can also span a number of
* cells, which means that you can for instance span three cells and split that big cell for two components. Split can be
* set to a very high value to make all components in the same row/column share the same cell (e.g. LayoutUtil.INF).
*
* Note that only the first component will be checked for this property.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return The current value.
*/
public int getSplit()
{
return split;
}
/** Sets in how many parts the current cell (that this constraint's component will be in) should be split in. If for instance
* it is split in two, the next componet will also share the same cell. Note that the cell can also span a number of
* cells, which means that you can for instance span three cells and split that big cell for two components. Split can be
* set to a very high value to make all components in the same row/column share the same cell (e.g. LayoutUtil.INF).
*
* Note that only the first component will be checked for this property.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param parts The number of parts (i.e. component slots) the cell should be divided into.
*/
public void setSplit(int parts)
{
this.split = parts;
}
/** Tags the component with metadata. Currently only used to tag buttons with for instance "cancel" or "ok" to make them
* show up in the correct order depending on platform. See {@link PlatformDefaults#setButtonOrder(String)} for information.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return The current value. May be null.
*/
public String getTag()
{
return tag;
}
/** Optinal tag that gives more context to this constraint's component. It is for instance used to tag buttons in a
* button bar with the button type such as "ok", "help" or "cancel".
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param tag The new tag. May be null.
*/
public void setTag(String tag)
{
this.tag = tag;
}
/** Returns if the flow should wrap to the next line/column after the component that this constraint belongs to.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return The current value.
*/
public boolean isWrap()
{
return wrap != null;
}
/** Sets if the flow should wrap to the next line/column after the component that this constraint belongs to.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param b true means wrap after.
*/
public void setWrap(boolean b)
{
wrap = b ? (wrap == null ? DEF_GAP : wrap) : null;
}
/** Returns the wrap size if it is a custom size. If wrap was set to true with {@link #setWrap(boolean)} then this method will
* return null since that means that the gap size should be the default one as defined in the rows spec.
* @return The custom gap size. NOTE! Will return null for both no wrap and default wrap.
* @see #isWrap()
* @see #setWrap(boolean)
* @since 2.4.2
*/
public BoundSize getWrapGapSize()
{
return wrap == DEF_GAP ? null : wrap;
}
/** Set the wrap size and turns wrap on if != null.
* @param s The custom gap size. NOTE! null will not turn on or off wrap, it will only set the wrap gap size to "default".
* A non-null value will turn on wrap though.
* @see #isWrap()
* @see #setWrap(boolean)
* @since 2.4.2
*/
public void setWrapGapSize(BoundSize s)
{
wrap = s == null ? (wrap != null ? DEF_GAP : null) : s;
}
/** Returns if the flow should wrap to the next line/column before the component that this constraint belongs to.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return The current value.
*/
public boolean isNewline()
{
return newline != null;
}
/** Sets if the flow should wrap to the next line/column before the component that this constraint belongs to.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param b true means wrap before.
*/
public void setNewline(boolean b)
{
newline = b ? (newline == null ? DEF_GAP : newline) : null;
}
/** Returns the newline size if it is a custom size. If newline was set to true with {@link #setNewline(boolean)} then this method will
* return null since that means that the gap size should be the default one as defined in the rows spec.
* @return The custom gap size. NOTE! Will return null for both no newline and default newline.
* @see #isNewline()
* @see #setNewline(boolean)
* @since 2.4.2
*/
public BoundSize getNewlineGapSize()
{
return newline == DEF_GAP ? null : newline;
}
/** Set the newline size and turns newline on if != null.
* @param s The custom gap size. NOTE! null will not turn on or off newline, it will only set the newline gap size to "default".
* A non-null value will turn on newline though.
* @see #isNewline()
* @see #setNewline(boolean)
* @since 2.4.2
*/
public void setNewlineGapSize(BoundSize s)
{
newline = s == null ? (newline != null ? DEF_GAP : null) : s;
}
// ************************************************
// Persistence Delegate and Serializable combined.
// ************************************************
private Object readResolve() throws ObjectStreamException
{
return LayoutUtil.getSerializedObject(this);
}
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
{
LayoutUtil.setSerializedObject(this, LayoutUtil.readAsXML(in));
}
public void writeExternal(ObjectOutput out) throws IOException
{
if (getClass() == CC.class)
LayoutUtil.writeAsXML(out, this);
}
}miglayout-3.7.4/net/miginfocom/layout/BoundSize.java0000644000175000017500000002323411252374662021316 0ustar tonytonypackage net.miginfocom.layout;
import java.beans.Encoder;
import java.beans.Expression;
import java.beans.PersistenceDelegate;
import java.io.*;
/*
* License (BSD):
* ==============
*
* Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
* Neither the name of the MiG InfoCom AB nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* @version 1.0
* @author Mikael Grev, MiG InfoCom AB
* Date: 2006-sep-08
*/
/** A size that contains minimum, preferred and maximum size of type {@link UnitValue}.
*
* This class is a simple value container and it is immutable.
*
* If a size is missing (i.e., null) that boundary should be considered "not in use".
*
* You can create a BoundSize from a String with the use of {@link ConstraintParser#parseBoundSize(String, boolean, boolean)}
*/
public class BoundSize implements Serializable
{
public static final BoundSize NULL_SIZE = new BoundSize(null, null);
public static final BoundSize ZERO_PIXEL = new BoundSize(UnitValue.ZERO, "0px");
private final transient UnitValue min;
private final transient UnitValue pref;
private final transient UnitValue max;
private final transient boolean gapPush;
/** Constructor that use the same value for min/preferred/max size.
* @param minMaxPref The value to use for min/preferred/max size.
* @param createString The string used to create the BoundsSize.
*/
public BoundSize(UnitValue minMaxPref, String createString)
{
this(minMaxPref, minMaxPref, minMaxPref, createString);
}
/** Constructor. This method is here for serilization only and should normally not be used. Use
* {@link ConstraintParser#parseBoundSize(String, boolean, boolean)} instead.
* @param min The minimum size. May be null.
* @param preferred The preferred size. May be null.
* @param max The maximum size. May be null.
* @param createString The string used to create the BoundsSize.
*/
public BoundSize(UnitValue min, UnitValue preferred, UnitValue max, String createString) // Bound to old delegate!!!!!
{
this(min, preferred, max, false, createString);
}
/** Constructor. This method is here for serilization only and should normally not be used. Use
* {@link ConstraintParser#parseBoundSize(String, boolean, boolean)} instead.
* @param min The minimum size. May be null.
* @param preferred The preferred size. May be null.
* @param max The maximum size. May be null.
* @param gapPush If the size should be hinted as "pushing" and thus want to occupy free space if no one else is claiming it.
* @param createString The string used to create the BoundsSize.
*/
public BoundSize(UnitValue min, UnitValue preferred, UnitValue max, boolean gapPush, String createString)
{
this.min = min;
this.pref = preferred;
this.max = max;
this.gapPush = gapPush;
LayoutUtil.putCCString(this, createString); // this escapes!!
}
/** Returns the minimum size as sent into the constructor.
* @return The minimum size as sent into the constructor. May be null.
*/
public final UnitValue getMin()
{
return min;
}
/** Returns the preferred size as sent into the constructor.
* @return The preferred size as sent into the constructor. May be null.
*/
public final UnitValue getPreferred()
{
return pref;
}
/** Returns the maximum size as sent into the constructor.
* @return The maximum size as sent into the constructor. May be null.
*/
public final UnitValue getMax()
{
return max;
}
/** If the size should be hinted as "pushing" and thus want to occupy free space if noone else is claiming it.
* @return The value.
*/
public boolean getGapPush()
{
return gapPush;
}
/** Returns if this bound size has no min, preferred and maximum size set (they are all null)
* @return If unset.
*/
public boolean isUnset()
{
// Most common case by far is this == ZERO_PIXEL...
return this == ZERO_PIXEL || (pref == null && min == null && max == null && gapPush == false);
}
/** Makes sure that size is within min and max of this size.
* @param size The size to constrain.
* @param refValue The reference to use for relative sizes.
* @param parent The parent container.
* @return The size, constrained within min and max.
*/
public int constrain(int size, float refValue, ContainerWrapper parent)
{
if (max != null)
size = Math.min(size, max.getPixels(refValue, parent, parent));
if (min != null)
size = Math.max(size, min.getPixels(refValue, parent, parent));
return size;
}
/** Returns the minimum, preferred or maximum size for this bounded size.
* @param sizeType The type. LayoutUtil.MIN, LayoutUtil.PREF or LayoutUtil.MAX.
* @return
*/
final UnitValue getSize(int sizeType)
{
switch(sizeType) {
case LayoutUtil.MIN:
return min;
case LayoutUtil.PREF:
return pref;
case LayoutUtil.MAX:
return max;
default:
throw new IllegalArgumentException("Unknown size: " + sizeType);
}
}
/** Convert the bound sizes to pixels.
*
* null bound sizes will be 0 for min and preferred and {@link net.miginfocom.layout.LayoutUtil#INF} for max.
* @param refSize The reference size.
* @param parent The parent. Not null.
* @param comp The component, if applicable, can be null.
* @return An array of lenth three (min,pref,max).
*/
final int[] getPixelSizes(float refSize, ContainerWrapper parent, ComponentWrapper comp)
{
return new int[] {
min != null ? min.getPixels(refSize, parent, comp) : 0,
pref != null ? pref.getPixels(refSize, parent, comp) : 0,
max != null ? max.getPixels(refSize, parent, comp) : LayoutUtil.INF
};
}
/** Returns the a constraint string that can be re-parsed to be the exact same UnitValue.
* @return A String. Never null.
*/
String getConstraintString()
{
String cs = LayoutUtil.getCCString(this);
if (cs != null)
return cs;
if (min == pref && pref == max)
return min != null ? (min.getConstraintString() + "!") : "null";
StringBuilder sb = new StringBuilder(16);
if (min != null)
sb.append(min.getConstraintString()).append(':');
if (pref != null) {
if (min == null && max != null)
sb.append(":");
sb.append(pref.getConstraintString());
} else if (min != null) {
sb.append('n');
}
if (max != null)
sb.append(sb.length() == 0 ? "::" : ":").append(max.getConstraintString());
if (gapPush) {
if (sb.length() > 0)
sb.append(':');
sb.append("push");
}
return sb.toString();
}
void checkNotLinked()
{
if (min != null && min.isLinkedDeep() || pref != null && pref.isLinkedDeep() || max != null && max.isLinkedDeep())
throw new IllegalArgumentException("Size may not contain links");
}
static {
LayoutUtil.setDelegate(BoundSize.class, new PersistenceDelegate() {
protected Expression instantiate(Object oldInstance, Encoder out)
{
BoundSize bs = (BoundSize) oldInstance;
if (Grid.TEST_GAPS) {
return new Expression(oldInstance, BoundSize.class, "new", new Object[] {
bs.getMin(), bs.getPreferred(), bs.getMax(), bs.getGapPush(), bs.getConstraintString()
});
} else {
return new Expression(oldInstance, BoundSize.class, "new", new Object[] {
bs.getMin(), bs.getPreferred(), bs.getMax(), bs.getConstraintString()
});
}
}
});
}
// ************************************************
// Persistence Delegate and Serializable combined.
// ************************************************
private static final long serialVersionUID = 1L;
protected Object readResolve() throws ObjectStreamException
{
return LayoutUtil.getSerializedObject(this);
}
private void writeObject(ObjectOutputStream out) throws IOException
{
if (getClass() == BoundSize.class)
LayoutUtil.writeAsXML(out, this);
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
{
LayoutUtil.setSerializedObject(this, LayoutUtil.readAsXML(in));
}
}miglayout-3.7.4/net/miginfocom/layout/UnitValue.java0000644000175000017500000005030011521470652021315 0ustar tonytonypackage net.miginfocom.layout;
/*
* License (BSD):
* ==============
*
* Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
* Neither the name of the MiG InfoCom AB nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* @version 1.0
* @author Mikael Grev, MiG InfoCom AB
* Date: 2006-sep-08
*/
import java.beans.Encoder;
import java.beans.Expression;
import java.beans.PersistenceDelegate;
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
public final class UnitValue implements Serializable
{
private static final HashMap UNIT_MAP = new HashMap(32);
private static final ArrayList CONVERTERS = new ArrayList();
/** An operation indicating a static value.
*/
public static final int STATIC = 100;
/** An operation indicating a addition of two sub units.
*/
public static final int ADD = 101; // Must have "sub-unit values"
/** An operation indicating a subtraction of two sub units
*/
public static final int SUB = 102; // Must have "sub-unit values"
/** An operation indicating a multiplication of two sub units.
*/
public static final int MUL = 103; // Must have "sub-unit values"
/** An operation indicating a division of two sub units.
*/
public static final int DIV = 104; // Must have "sub-unit values"
/** An operation indicating the minimum of two sub units
*/
public static final int MIN = 105; // Must have "sub-unit values"
/** An operation indicating the maximum of two sub units
*/
public static final int MAX = 106; // Must have "sub-unit values"
/** An operation indicating the middle value of two sub units
*/
public static final int MID = 107; // Must have "sub-unit values"
/** A unit indicating pixels.
*/
public static final int PIXEL = 0;
/** A unit indicating logical horizontal pixels.
*/
public static final int LPX = 1;
/** A unit indicating logical vertical pixels.
*/
public static final int LPY = 2;
/** A unit indicating millimeters.
*/
public static final int MM = 3;
/** A unit indicating centimeters.
*/
public static final int CM = 4;
/** A unit indicating inches.
*/
public static final int INCH = 5;
/** A unit indicating percent.
*/
public static final int PERCENT = 6;
/** A unit indicating points.
*/
public static final int PT = 7;
/** A unit indicating screen percentage width.
*/
public static final int SPX = 8;
/** A unit indicating screen percentage height.
*/
public static final int SPY = 9;
/** A unit indicating alignment.
*/
public static final int ALIGN = 12;
/** A unit indicating minimum size.
*/
public static final int MIN_SIZE = 13;
/** A unit indicating preferred size.
*/
public static final int PREF_SIZE = 14;
/** A unit indicating maximum size.
*/
public static final int MAX_SIZE = 15;
/** A unit indicating botton size.
*/
public static final int BUTTON = 16;
/** A unit indicating linking to x.
*/
public static final int LINK_X = 18; // First link
/** A unit indicating linking to y.
*/
public static final int LINK_Y = 19;
/** A unit indicating linking to width.
*/
public static final int LINK_W = 20;
/** A unit indicating linking to height.
*/
public static final int LINK_H = 21;
/** A unit indicating linking to x2.
*/
public static final int LINK_X2 = 22;
/** A unit indicating linking to y2.
*/
public static final int LINK_Y2 = 23;
/** A unit indicating linking to x position on screen.
*/
public static final int LINK_XPOS = 24;
/** A unit indicating linking to y position on screen.
*/
public static final int LINK_YPOS = 25; // Last link
/** A unit indicating a lookup.
*/
public static final int LOOKUP = 26;
/** A unit indicating label alignment.
*/
public static final int LABEL_ALIGN = 27;
private static final int IDENTITY = -1;
static {
UNIT_MAP.put("px", Integer.valueOf(PIXEL));
UNIT_MAP.put("lpx", Integer.valueOf(LPX));
UNIT_MAP.put("lpy", Integer.valueOf(LPY));
UNIT_MAP.put("%", Integer.valueOf(PERCENT));
UNIT_MAP.put("cm", Integer.valueOf(CM));
UNIT_MAP.put("in", Integer.valueOf(INCH));
UNIT_MAP.put("spx", Integer.valueOf(SPX));
UNIT_MAP.put("spy", Integer.valueOf(SPY));
UNIT_MAP.put("al", Integer.valueOf(ALIGN));
UNIT_MAP.put("mm", Integer.valueOf(MM));
UNIT_MAP.put("pt", Integer.valueOf(PT));
UNIT_MAP.put("min", Integer.valueOf(MIN_SIZE));
UNIT_MAP.put("minimum", Integer.valueOf(MIN_SIZE));
UNIT_MAP.put("p", Integer.valueOf(PREF_SIZE));
UNIT_MAP.put("pref", Integer.valueOf(PREF_SIZE));
UNIT_MAP.put("max", Integer.valueOf(MAX_SIZE));
UNIT_MAP.put("maximum", Integer.valueOf(MAX_SIZE));
UNIT_MAP.put("button", Integer.valueOf(BUTTON));
UNIT_MAP.put("label", Integer.valueOf(LABEL_ALIGN));
}
static final UnitValue ZERO = new UnitValue(0, null, PIXEL, true, STATIC, null, null, "0px");
static final UnitValue TOP = new UnitValue(0, null, PERCENT, false, STATIC, null, null, "top");
static final UnitValue LEADING = new UnitValue(0, null, PERCENT, true, STATIC, null, null, "leading");
static final UnitValue LEFT = new UnitValue(0, null, PERCENT, true, STATIC, null, null, "left");
static final UnitValue CENTER = new UnitValue(50, null, PERCENT, true, STATIC, null, null, "center");
static final UnitValue TRAILING = new UnitValue(100, null, PERCENT, true, STATIC, null, null, "trailing");
static final UnitValue RIGHT = new UnitValue(100, null, PERCENT, true, STATIC, null, null, "right");
static final UnitValue BOTTOM = new UnitValue(100, null, PERCENT, false, STATIC, null, null, "bottom");
static final UnitValue LABEL = new UnitValue(0, null, LABEL_ALIGN, false, STATIC, null, null, "label");
static final UnitValue INF = new UnitValue(LayoutUtil.INF, null, PIXEL, true, STATIC, null, null, "inf");
static final UnitValue BASELINE_IDENTITY = new UnitValue(0, null, IDENTITY, false, STATIC, null, null, "baseline");
private final transient float value;
private final transient int unit;
private final transient int oper;
private final transient String unitStr;
private transient String linkId = null; // Should be final, but initializes in a sub method.
private final transient boolean isHor;
private final transient UnitValue[] subUnits;
// Pixel
public UnitValue(float value) // If hor/ver does not matter.
{
this(value, null, PIXEL, true, STATIC, null, null, value + "px");
}
public UnitValue(float value, int unit, String createString) // If hor/ver does not matter.
{
this(value, null, unit, true, STATIC, null, null, createString);
}
UnitValue(float value, String unitStr, boolean isHor, int oper, String createString)
{
this(value, unitStr, -1, isHor, oper, null, null, createString);
}
UnitValue(boolean isHor, int oper, UnitValue sub1, UnitValue sub2, String createString)
{
this(0, "", -1, isHor, oper, sub1, sub2, createString);
if (sub1 == null || sub2 == null)
throw new IllegalArgumentException("Sub units is null!");
}
private UnitValue(float value, String unitStr, int unit, boolean isHor, int oper, UnitValue sub1, UnitValue sub2, String createString)
{
if (oper < STATIC || oper > MID)
throw new IllegalArgumentException("Unknown Operation: " + oper);
if (oper >= ADD && oper <= MID && (sub1 == null || sub2 == null))
throw new IllegalArgumentException(oper + " Operation may not have null sub-UnitValues.");
this.value = value;
this.oper = oper;
this.isHor = isHor;
this.unitStr = unitStr;
this.unit = unitStr != null ? parseUnitString() : unit;
this.subUnits = sub1 != null && sub2 != null ? new UnitValue[] {sub1, sub2} : null;
LayoutUtil.putCCString(this, createString); // "this" escapes!! Safe though.
}
/** Returns the size in pixels rounded.
* @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.
* @param parent The parent. May be null for testing the validity of the value, but should normally not and are not
* required to return any usable value if null.
* @param comp The component, if any, that the value is for. Might be null if the value is not
* connected to any component.
* @return The size in pixels.
*/
public final int getPixels(float refValue, ContainerWrapper parent, ComponentWrapper comp)
{
return Math.round(getPixelsExact(refValue, parent, comp));
}
private static final float[] SCALE = new float[] {25.4f, 2.54f, 1f, 0f, 72f};
/** Returns the size in pixels.
* @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.
* @param parent The parent. May be null for testing the validity of the value, but should normally not and are not
* required to return any usable value if null.
* @param comp The component, if any, that the value is for. Might be null if the value is not
* connected to any component.
* @return The size in pixels.
*/
public final float getPixelsExact(float refValue, ContainerWrapper parent, ComponentWrapper comp)
{
if (parent == null)
return 1;
if (oper == STATIC) {
switch (unit) {
case PIXEL:
return value;
case LPX:
case LPY:
return parent.getPixelUnitFactor(unit == LPX) * value;
case MM:
case CM:
case INCH:
case PT:
float f = SCALE[unit - MM];
Float s = isHor ? PlatformDefaults.getHorizontalScaleFactor() : PlatformDefaults.getVerticalScaleFactor();
if (s != null)
f *= s.floatValue();
return (isHor ? parent.getHorizontalScreenDPI() : parent.getVerticalScreenDPI()) * value / f;
case PERCENT:
return value * refValue * 0.01f;
case SPX:
case SPY:
return (unit == SPX ? parent.getScreenWidth() : parent.getScreenHeight()) * value * 0.01f;
case ALIGN:
Integer st = LinkHandler.getValue(parent.getLayout(), "visual", isHor ? LinkHandler.X : LinkHandler.Y);
Integer sz = LinkHandler.getValue(parent.getLayout(), "visual", isHor ? LinkHandler.WIDTH : LinkHandler.HEIGHT);
if (st == null || sz == null)
return 0;
return value * (Math.max(0, sz.intValue()) - refValue) + st.intValue();
case MIN_SIZE:
if (comp == null)
return 0;
return isHor ? comp.getMinimumWidth(comp.getHeight()) : comp.getMinimumHeight(comp.getWidth());
case PREF_SIZE:
if (comp == null)
return 0;
return isHor ? comp.getPreferredWidth(comp.getHeight()) : comp.getPreferredHeight(comp.getWidth());
case MAX_SIZE:
if (comp == null)
return 0;
return isHor ? comp.getMaximumWidth(comp.getHeight()) : comp.getMaximumHeight(comp.getWidth());
case BUTTON:
return PlatformDefaults.getMinimumButtonWidth().getPixels(refValue, parent, comp);
case LINK_X:
case LINK_Y:
case LINK_W:
case LINK_H:
case LINK_X2:
case LINK_Y2:
case LINK_XPOS:
case LINK_YPOS:
Integer v = LinkHandler.getValue(parent.getLayout(), getLinkTargetId(), unit - (unit >= LINK_XPOS ? LINK_XPOS : LINK_X));
if (v == null)
return 0;
if (unit == LINK_XPOS)
return parent.getScreenLocationX() + v.intValue();
if (unit == LINK_YPOS)
return parent.getScreenLocationY() + v.intValue();
return v.intValue();
case LOOKUP:
float res = lookup(refValue, parent, comp);
if (res != UnitConverter.UNABLE)
return res;
case LABEL_ALIGN:
return PlatformDefaults.getLabelAlignPercentage() * refValue;
case IDENTITY:
}
throw new IllegalArgumentException("Unknown/illegal unit: " + unit + ", unitStr: " + unitStr);
}
if (subUnits != null && subUnits.length == 2) {
float r1 = subUnits[0].getPixelsExact(refValue, parent, comp);
float r2 = subUnits[1].getPixelsExact(refValue, parent, comp);
switch (oper) {
case ADD:
return r1 + r2;
case SUB:
return r1 - r2;
case MUL:
return r1 * r2;
case DIV:
return r1 / r2;
case MIN:
return r1 < r2 ? r1 : r2;
case MAX:
return r1 > r2 ? r1 : r2;
case MID:
return (r1 + r2) * 0.5f;
}
}
throw new IllegalArgumentException("Internal: Unknown Oper: " + oper);
}
private float lookup(float refValue, ContainerWrapper parent, ComponentWrapper comp)
{
float res = UnitConverter.UNABLE;
for (int i = CONVERTERS.size() - 1; i >= 0; i--) {
res = CONVERTERS.get(i).convertToPixels(value, unitStr, isHor, refValue, parent, comp);
if (res != UnitConverter.UNABLE)
return res;
}
return PlatformDefaults.convertToPixels(value, unitStr, isHor, refValue, parent, comp);
}
private int parseUnitString()
{
int len = unitStr.length();
if (len == 0)
return isHor ? PlatformDefaults.getDefaultHorizontalUnit() : PlatformDefaults.getDefaultVerticalUnit();
Integer u = UNIT_MAP.get(unitStr);
if (u != null)
return u.intValue();
if (unitStr.equals("lp"))
return isHor ? LPX : LPY;
if (unitStr.equals("sp"))
return isHor ? SPX : SPY;
if (lookup(0, null, null) != UnitConverter.UNABLE) // To test so we can fail fast
return LOOKUP;
// Only link left. E.g. "otherID.width"
int pIx = unitStr.indexOf('.');
if (pIx != -1) {
linkId = unitStr.substring(0, pIx);
String e = unitStr.substring(pIx + 1);
if (e.equals("x"))
return LINK_X;
if (e.equals("y"))
return LINK_Y;
if (e.equals("w") || e.equals("width"))
return LINK_W;
if (e.equals("h") || e.equals("height"))
return LINK_H;
if (e.equals("x2"))
return LINK_X2;
if (e.equals("y2"))
return LINK_Y2;
if (e.equals("xpos"))
return LINK_XPOS;
if (e.equals("ypos"))
return LINK_YPOS;
}
throw new IllegalArgumentException("Unknown keyword: " + unitStr);
}
final boolean isLinked()
{
return linkId != null;
}
final boolean isLinkedDeep()
{
if (subUnits == null)
return linkId != null;
for (int i = 0; i < subUnits.length; i++) {
if (subUnits[i].isLinkedDeep())
return true;
}
return false;
}
final String getLinkTargetId()
{
return linkId;
}
final UnitValue getSubUnitValue(int i)
{
return subUnits[i];
}
final int getSubUnitCount()
{
return subUnits != null ? subUnits.length : 0;
}
public final UnitValue[] getSubUnits()
{
return subUnits != null ? subUnits.clone() : null;
}
public final int getUnit()
{
return unit;
}
public final String getUnitString()
{
return unitStr;
}
public final int getOperation()
{
return oper;
}
public final float getValue()
{
return value;
}
public final boolean isHorizontal()
{
return isHor;
}
final public String toString()
{
return getClass().getName() + ". Value=" + value + ", unit=" + unit + ", unitString: " + unitStr + ", oper=" + oper + ", isHor: " + isHor;
}
/** Returns the creation string for this object. Note that {@link LayoutUtil#setDesignTime(ContainerWrapper, boolean)} must be
* set to true for the creation strings to be stored.
* @return The constraint string or null if none is registered.
*/
public final String getConstraintString()
{
return LayoutUtil.getCCString(this);
}
public final int hashCode()
{
return (int) (value * 12345) + (oper >>> 5) + unit >>> 17;
}
/** Adds a global unit converter that can convert from some unit to pixels.
*
* This converter will be asked before the platform converter so the values for it (e.g. "related" and "unrelated")
* can be overridden. It is however not possible to override the built in ones (e.g. "mm", "pixel" or "lp").
* @param conv The converter. Not null.
*/
public synchronized static void addGlobalUnitConverter(UnitConverter conv)
{
if (conv == null)
throw new NullPointerException();
CONVERTERS.add(conv);
}
/** Removed the converter.
* @param unit The converter.
* @return If there was a converter found and thus removed.
*/
public synchronized static boolean removeGlobalUnitConverter(UnitConverter unit)
{
return CONVERTERS.remove(unit);
}
/** Returns the global converters currently registered. The platform converter will not be in this list.
* @return The converters. Never null.
*/
public synchronized static UnitConverter[] getGlobalUnitConverters()
{
return CONVERTERS.toArray(new UnitConverter[CONVERTERS.size()]);
}
/** Returns the current default unit. The default unit is the unit used if no unit is set. E.g. "width 10".
* @return The current default unit.
* @see #PIXEL
* @see #LPX
* @deprecated Use {@link PlatformDefaults#getDefaultHorizontalUnit()} and {@link PlatformDefaults#getDefaultVerticalUnit()} instead.
*/
public static int getDefaultUnit()
{
return PlatformDefaults.getDefaultHorizontalUnit();
}
/** Sets the default unit. The default unit is the unit used if no unit is set. E.g. "width 10".
* @param unit The new default unit.
* @see #PIXEL
* @see #LPX
* @deprecated Use {@link PlatformDefaults#setDefaultHorizontalUnit(int)} and {@link PlatformDefaults#setDefaultVerticalUnit(int)} instead.
*/
public static void setDefaultUnit(int unit)
{
PlatformDefaults.setDefaultHorizontalUnit(unit);
PlatformDefaults.setDefaultVerticalUnit(unit);
}
static {
LayoutUtil.setDelegate(UnitValue.class, new PersistenceDelegate() {
protected Expression instantiate(Object oldInstance, Encoder out)
{
UnitValue uv = (UnitValue) oldInstance;
String cs = uv.getConstraintString();
if (cs == null)
throw new IllegalStateException("Design time must be on to use XML persistence. See LayoutUtil.");
return new Expression(oldInstance, ConstraintParser.class, "parseUnitValueOrAlign", new Object[] {
uv.getConstraintString(), (uv.isHorizontal() ? Boolean.TRUE : Boolean.FALSE), null
});
}
});
}
// ************************************************
// Persistence Delegate and Serializable combined.
// ************************************************
private static final long serialVersionUID = 1L;
private Object readResolve() throws ObjectStreamException
{
return LayoutUtil.getSerializedObject(this);
}
private void writeObject(ObjectOutputStream out) throws IOException
{
if (getClass() == UnitValue.class)
LayoutUtil.writeAsXML(out, this);
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
{
LayoutUtil.setSerializedObject(this, LayoutUtil.readAsXML(in));
}
}miglayout-3.7.4/net/miginfocom/layout/ContainerWrapper.java0000644000175000017500000000617611252374662022705 0ustar tonytonypackage net.miginfocom.layout;
/*
* License (BSD):
* ==============
*
* Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
* Neither the name of the MiG InfoCom AB nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* @version 1.0
* @author Mikael Grev, MiG InfoCom AB
* Date: 2006-sep-08
*/
/** A class that wraps a container that contains components.
*/
public interface ContainerWrapper extends ComponentWrapper
{
/** Returns the components of the container that wrapper is wrapping.
* @return The components of the container that wrapper is wrapping. Never null.
*/
public abstract ComponentWrapper[] getComponents();
/** Returns the number of components that this parent has.
* @return The number of components that this parent has.
*/
public abstract int getComponentCount();
/** Returns the LayoutHandler (in Swing terms) that is handling the layout of this container.
* If there exist no such class the method should return the same as {@link #getComponent()}, which is the
* container itself.
* @return The layout handler instance. Never null.
*/
public abstract Object getLayout();
/** Returns if this container is using left-to-right component ordering.
* @return If this container is using left-to-right component ordering.
*/
public abstract boolean isLeftToRight();
/** Paints a cell to indicate where it is.
* @param x The x coordinate to start the drwaing.
* @param y The x coordinate to start the drwaing.
* @param width The width to draw/fill
* @param height The height to draw/fill
*/
public abstract void paintDebugCell(int x, int y, int width, int height);
}
miglayout-3.7.4/net/miginfocom/layout/LC.java0000644000175000017500000013465711301446666017725 0ustar tonytonypackage net.miginfocom.layout;
import java.io.*;
/*
* License (BSD):
* ==============
*
* Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
* Neither the name of the MiG InfoCom AB nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* @version 1.0
* @author Mikael Grev, MiG InfoCom AB
* Date: 2006-sep-08
*/
/** Contains the constraints for an instance of the {@link LC} layout manager.
*/
public final class LC implements Externalizable
{
// See the corresponding set/get method for documentation of the property!
private int wrapAfter = LayoutUtil.INF;
private Boolean leftToRight = null;
private UnitValue[] insets = null; // Never null elememts but if unset array is null
private UnitValue alignX = null, alignY = null;
private BoundSize gridGapX = null, gridGapY = null;
private BoundSize width = BoundSize.NULL_SIZE, height = BoundSize.NULL_SIZE;
private BoundSize packW = BoundSize.NULL_SIZE, packH = BoundSize.NULL_SIZE;
private float pwAlign = 0.5f, phAlign = 1.0f;
private int debugMillis = 0;
private int hideMode = 0;
private boolean noCache = false;
private boolean flowX = true;
private boolean fillX = false, fillY = false;
private boolean topToBottom = true;
private boolean noGrid = false;
private boolean visualPadding = true;
/** Empty constructor.
*/
public LC()
{
}
// ************************************************************************
// * JavaBean get/set methods.
// ************************************************************************
/** If components have sizes or positions linked to the bounds of the parent in some way (as for instance the "%" unit has) the cache
* must be turned off for the panel. If components does not get the correct or expected size or position try to set this property to true.
* @return true means no cache and slightly slower layout.
*/
public boolean isNoCache()
{
return noCache;
}
/** If components have sizes or positions linked to the bounds of the parent in some way (as for instance the "%" unit has) the cache
* must be turned off for the panel. If components does not get the correct or expected size or position try to set this property to true.
* @param b true means no cache and slightly slower layout.
*/
public void setNoCache(boolean b)
{
this.noCache = b;
}
/** If the laid out components' bounds in total is less than the final size of the container these align values will be used to align the components
* in the parent. null is default and that means top/left alignment. The relative distances between the components will not be affected
* by this property.
* @return The current alignment.
*/
public final UnitValue getAlignX()
{
return alignX;
}
/** If the laid out components' bounds in total is less than the final size of the container these align values will be used to align the components
* in the parent. null is default and that means top/left alignment. The relative distances between the components will not be affected
* by this property.
* @param uv The new alignment. Use {@link ConstraintParser#parseAlignKeywords(String, boolean)} to create the {@link UnitValue}. May be null.
*/
public final void setAlignX(UnitValue uv)
{
this.alignX = uv;
}
/** If the laid out components' bounds in total is less than the final size of the container these align values will be used to align the components
* in the parent. null is default and that means top/left alignment. The relative distances between the components will not be affected
* by this property.
* @return The current alignment.
*/
public final UnitValue getAlignY()
{
return alignY;
}
/** If the laid out components' bounds in total is less than the final size of the container these align values will be used to align the components
* in the parent. null is default and that means top/left alignment. The relative distances between the components will not be affected
* by this property.
* @param uv The new alignment. Use {@link ConstraintParser#parseAlignKeywords(String, boolean)} to create the {@link UnitValue}. May be null.
*/
public final void setAlignY(UnitValue uv)
{
this.alignY = uv;
}
/** If > 0 the debug decorations will be repainted every millis. No debug information if <= 0 (default).
* @return The current debug repaint interval.
*/
public final int getDebugMillis()
{
return debugMillis;
}
/** If > 0 the debug decorations will be repainted every millis. No debug information if <= 0 (default).
* @param millis The new debug repaint interval.
*/
public final void setDebugMillis(int millis)
{
this.debugMillis = millis;
}
/** If the layout should always claim the whole bounds of the laid out container even if the preferred size is smaller.
* @return true means fill. false is default.
*/
public final boolean isFillX()
{
return fillX;
}
/** If the layout should always claim the whole bounds of the laid out container even if the preferred size is smaller.
* @param b true means fill. false is default.
*/
public final void setFillX(boolean b)
{
this.fillX = b;
}
/** If the layout should always claim the whole bounds of the laid out container even if the preferred size is smaller.
* @return true means fill. false is default.
*/
public final boolean isFillY()
{
return fillY;
}
/** If the layout should always claim the whole bounds of the laid out container even if the preferred size is smaller.
* @param b true means fill. false is default.
*/
public final void setFillY(boolean b)
{
this.fillY = b;
}
/** The default flow direction. Normally (which is true) this is horizontal and that means that the "next" component
* will be put in the cell to the right (or to the left if left-to-right is false).
* @return true is the default flow horizontally.
* @see #setLeftToRight(Boolean)
*/
public final boolean isFlowX()
{
return flowX;
}
/** The default flow direction. Normally (which is true) this is horizontal and that means that the "next" component
* will be put in the cell to the right (or to the left if left-to-right is false).
* @param b true is the default flow horizontally.
* @see #setLeftToRight(Boolean)
*/
public final void setFlowX(boolean b)
{
this.flowX = b;
}
/** If non-null (null is default) these value will be used as the default gaps between the columns in the grid.
* @return The default grid gap between columns in the grid. null if the platform default is used.
*/
public final BoundSize getGridGapX()
{
return gridGapX;
}
/** If non-null (null is default) these value will be used as the default gaps between the columns in the grid.
* @param x The default grid gap between columns in the grid. If null the platform default is used.
*/
public final void setGridGapX(BoundSize x)
{
this.gridGapX = x;
}
/** If non-null (null is default) these value will be used as the default gaps between the rows in the grid.
* @return The default grid gap between rows in the grid. null if the platform default is used.
*/
public final BoundSize getGridGapY()
{
return gridGapY;
}
/** If non-null (null is default) these value will be used as the default gaps between the rows in the grid.
* @param y The default grid gap between rows in the grid. If null the platform default is used.
*/
public final void setGridGapY(BoundSize y)
{
this.gridGapY = y;
}
/** How a component that is hidden (not visible) should be treated by default.
* @return The mode:
* 0 == Normal. Bounds will be caclulated as if the component was visible.
* 1 == If hidden the size will be 0, 0 but the gaps remain.
* 2 == If hidden the size will be 0, 0 and gaps set to zero.
* 3 == If hidden the component will be disregarded completely and not take up a cell in the grid..
*/
public final int getHideMode()
{
return hideMode;
}
/** How a component that is hidden (not visible) should be treated.
* @param mode The mode:
* 0 == Normal. Bounds will be caclulated as if the component was visible.
* 1 == If hidden the size will be 0, 0 but the gaps remain.
* 2 == If hidden the size will be 0, 0 and gaps set to zero.
* 3 == If hidden the component will be disregarded completely and not take up a cell in the grid..
*/
public final void setHideMode(int mode)
{
if (mode < 0 || mode > 3)
throw new IllegalArgumentException("Wrong hideMode: " + mode);
this.hideMode = mode;
}
/** The insets for the layed out panel. The insets will be an empty space around the components in the panel. null values
* means that the default panel insets for the platform is used. See {@link PlatformDefaults#setDialogInsets(net.miginfocom.layout.UnitValue, net.miginfocom.layout.UnitValue, net.miginfocom.layout.UnitValue, net.miginfocom.layout.UnitValue)}.
* @return The insets. Of length 4 (top, left, bottom, right) or null. The elements (1 to 4) may be null. The array is a copy and can be used freely.
* @see net.miginfocom.layout.ConstraintParser#parseInsets(String, boolean)
*/
public final UnitValue[] getInsets()
{
return insets != null ? new UnitValue[] {insets[0], insets[1], insets[2], insets[3]} : null;
}
/** The insets for the layed out panel. The insets will be an empty space around the components in the panel. null values
* means that the default panel insets for the platform is used. See {@link PlatformDefaults#setDialogInsets(net.miginfocom.layout.UnitValue, net.miginfocom.layout.UnitValue, net.miginfocom.layout.UnitValue, net.miginfocom.layout.UnitValue)}.
* @param ins The new insets. Must be of length 4 (top, left, bottom, right) or null. The elements (1 to 4) may be null to use
* the platform default for that side. The array is copied for storage.
* @see net.miginfocom.layout.ConstraintParser#parseInsets(String, boolean)
*/
public final void setInsets(UnitValue[] ins)
{
this.insets = ins != null ? new UnitValue[] {ins[0], ins[1], ins[2], ins[3]} : null;
}
/** If the layout should be forced to be left-to-right or right-to-left. A value of null is default and
* means that this will be picked up from the {@link java.util.Locale} that the container being layed out is reporting.
* @return Boolean.TRUE if force left-to-right. Boolean.FALSE if force tight-to-left. null
* for the default "let the current Locale decide".
*/
public final Boolean getLeftToRight()
{
return leftToRight;
}
/** If the layout should be forced to be left-to-right or right-to-left. A value of null is default and
* means that this will be picked up from the {@link java.util.Locale} that the container being layed out is reporting.
* @param b Boolean.TRUE to force left-to-right. Boolean.FALSE to force tight-to-left. null
* for the default "let the current Locale decide".
*/
public final void setLeftToRight(Boolean b)
{
this.leftToRight = b;
}
/** If the whole layout should be non grid based. It is the same as setting the "nogrid" property on every row/column in the grid.
* @return true means not grid based. false is default.
*/
public final boolean isNoGrid()
{
return noGrid;
}
/** If the whole layout should be non grid based. It is the same as setting the "nogrid" property on every row/column in the grid.
* @param b true means no grid. false is default.
*/
public final void setNoGrid(boolean b)
{
this.noGrid = b;
}
/** If the layout should go from the default top-to-bottom in the grid instead of the optinal bottom-to-top.
* @return true for the default top-to-bottom.
*/
public final boolean isTopToBottom()
{
return topToBottom;
}
/** If the layout should go from the default top-to-bottom in the grid instead of the optinal bottom-to-top.
* @param b true for the default top-to-bottom.
*/
public final void setTopToBottom(boolean b)
{
this.topToBottom = b;
}
/** If visual padding should be automatically used and compensated for by this layout instance.
* @return true if visual padding.
*/
public final boolean isVisualPadding()
{
return visualPadding;
}
/** If visual padding should be automatically used and compensated for by this layout instance.
* @param b true turns on visual padding.
*/
public final void setVisualPadding(boolean b)
{
this.visualPadding = b;
}
/** Returns after what cell the grid should always auto wrap.
* @return After what cell the grid should always auto wrap. If 0 the number of columns/rows in the
* {@link net.miginfocom.layout.AC} is used. LayoutUtil.INF is used for no auto wrap.
*/
public final int getWrapAfter()
{
return wrapAfter;
}
/** Sets after what cell the grid should always auto wrap.
* @param count After what cell the grid should always auto wrap. If 0 the number of columns/rows in the
* {@link net.miginfocom.layout.AC} is used. LayoutUtil.INF is used for no auto wrap.
*/
public final void setWrapAfter(int count)
{
this.wrapAfter = count;
}
/** Returns the "pack width" for the window that this container is located in. When the size of this container changes
* the size of the window will be corrected to be within this BoundsSize. It can be used to set the minimum and/or maximum size of the window
* as well as the size window should optimally get. This optimal size is normaly its "preferred" size which is why "preferred"
* is the normal value to set here.
*
* ":push" can be appended to the bound size to only push the size bigger and never shrink it if the preferred size gets smaller.
*
* E.g. "pref", "100:pref", "pref:700", "300::700", "pref:push"
* @return The current value. Never null. Check if not set with .isUnset().
* @since 3.5
*/
public final BoundSize getPackWidth()
{
return packW;
}
/** Sets the "pack width" for the window that this container is located in. When the size of this container changes
* the size of the window will be corrected to be within this BoundsSize. It can be used to set the minimum and/or maximum size of the window
* as well as the size window should optimally get. This optimal size is normaly its "preferred" size which is why "preferred"
* is the normal value to set here.
*
* ":push" can be appended to the bound size to only push the size bigger and never shrink it if the preferred size gets smaller.
*
* E.g. "pref", "100:pref", "pref:700", "300::700", "pref:push"
* @param size The new pack size. If null it will be corrected to an "unset" BoundSize.
* @since 3.5
*/
public final void setPackWidth(BoundSize size)
{
packW = size != null ? size : BoundSize.NULL_SIZE;
}
/** Returns the "pack height" for the window that this container is located in. When the size of this container changes
* the size of the window will be corrected to be within this BoundsSize. It can be used to set the minimum and/or maximum size of the window
* as well as the size window should optimally get. This optimal size is normaly its "preferred" size which is why "preferred"
* is the normal value to set here.
*
* ":push" can be appended to the bound size to only push the size bigger and never shrink it if the preferred size gets smaller.
*
* E.g. "pref", "100:pref", "pref:700", "300::700", "pref:push"
* @return The current value. Never null. Check if not set with .isUnset().
* @since 3.5
*/
public final BoundSize getPackHeight()
{
return packH;
}
/** Sets the "pack height" for the window that this container is located in. When the size of this container changes
* the size of the window will be corrected to be within this BoundsSize. It can be used to set the minimum and/or maximum size of the window
* as well as the size window should optimally get. This optimal size is normaly its "preferred" size which is why "preferred"
* is the normal value to set here.
*
* ":push" can be appended to the bound size to only push the size bigger and never shrink it if the preferred size gets smaller.
*
* E.g. "pref", "100:pref", "pref:700", "300::700", "pref:push"
* @param size The new pack size. If null it will be corrected to an "unset" BoundSize.
* @since 3.5
*/
public final void setPackHeight(BoundSize size)
{
packH = size != null ? size : BoundSize.NULL_SIZE;
}
/** If there is a resize of the window due to packing (see {@link #setPackHeight(BoundSize)} this value, which is between 0f and 1f,
* decides where the extra/surpurflous size is placed. 0f means that the window will resize so that the upper part moves up and the
* lower side stays in the same place. 0.5f will expand/reduce the window equally upwards and downwards. 1f will do the opposite of 0f
* of course.
* @return The pack alignment. Always between 0f and 1f, inclusive.
* @since 3.5
*/
public final float getPackHeightAlign()
{
return phAlign;
}
/** If there is a resize of the window due to packing (see {@link #setPackHeight(BoundSize)} this value, which is between 0f and 1f,
* decides where the extra/surpurflous size is placed. 0f means that the window will resize so that the upper part moves up and the
* lower side stays in the same place. 0.5f will expand/reduce the window equally upwards and downwards. 1f will do the opposite of 0f
* of course.
* @param align The pack alignment. Always between 0f and 1f, inclusive. Values outside this will be truncated.
* @since 3.5
*/
public final void setPackHeightAlign(float align)
{
phAlign = Math.max(0f, Math.min(1f, align));
}
/** If there is a resize of the window due to packing (see {@link #setPackHeight(BoundSize)} this value, which is between 0f and 1f,
* decides where the extra/surpurflous size is placed. 0f means that the window will resize so that the left part moves left and the
* right side stays in the same place. 0.5f will expand/reduce the window equally to the right and lefts. 1f will do the opposite of 0f
* of course.
* @return The pack alignment. Always between 0f and 1f, inclusive.
* @since 3.5
*/
public final float getPackWidthAlign()
{
return pwAlign;
}
/** If there is a resize of the window due to packing (see {@link #setPackHeight(BoundSize)} this value, which is between 0f and 1f,
* decides where the extra/surpurflous size is placed. 0f means that the window will resize so that the left part moves left and the
* right side stays in the same place. 0.5f will expand/reduce the window equally to the right and lefts. 1f will do the opposite of 0f
* of course.
* @param align The pack alignment. Always between 0f and 1f, inclusive. Values outside this will be truncated.
* @since 3.5
*/
public final void setPackWidthAlign(float align)
{
pwAlign = Math.max(0f, Math.min(1f, align));
}
/** Returns the minimum/preferred/maximum size for the container that this layout constraint is set for. Any of these
* sizes that is not null will be returned directly instead of determining the correspondig size through
* asking the components in this container.
* @return The width for the container that this layout constraint is set for. Not null but
* all sizes can be null.
* @since 3.5
*/
public final BoundSize getWidth()
{
return width;
}
/** Sets the minimum/preferred/maximum size for the container that this layout constraint is set for. Any of these
* sizes that is not null will be returned directly instead of determining the correspondig size through
* asking the components in this container.
* @param size The width for the container that this layout constraint is set for. null is translated to
* a bound size containing only null sizes.
* @since 3.5
*/
public final void setWidth(BoundSize size)
{
this.width = size != null ? size : BoundSize.NULL_SIZE;
}
/** Returns the minimum/preferred/maximum size for the container that this layout constraint is set for. Any of these
* sizes that is not null will be returned directly instead of determining the correspondig size through
* asking the components in this container.
* @return The height for the container that this layout constraint is set for. Not null but
* all sizes can be null.
* @since 3.5
*/
public final BoundSize getHeight()
{
return height;
}
/** Sets the minimum/preferred/maximum size for the container that this layout constraint is set for. Any of these
* sizes that is not null will be returned directly instead of determining the correspondig size through
* asking the components in this container.
* @param size The height for the container that this layout constraint is set for. null is translated to
* a bound size containing only null sizes.
* @since 3.5
*/
public final void setHeight(BoundSize size)
{
this.height = size != null ? size : BoundSize.NULL_SIZE;
}
// ************************************************************************
// * Builder methods.
// ************************************************************************
/** Short for, and thus same as, .pack("pref", "pref").
*
* Same functionality as {@link #setPackHeight(BoundSize)} and {@link #setPackWidth(net.miginfocom.layout.BoundSize)}
* only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @since 3.5
*/
public final LC pack()
{
return pack("pref", "pref");
}
/** Sets the pack width and height.
*
* Same functionality as {@link #setPackHeight(BoundSize)} and {@link #setPackWidth(net.miginfocom.layout.BoundSize)}
* only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param width The pack width. May be null.
* @param height The pack height. May be null.
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @since 3.5
*/
public final LC pack(String width, String height)
{
setPackWidth(width != null ? ConstraintParser.parseBoundSize(width, false, false) : BoundSize.NULL_SIZE);
setPackHeight(height != null ? ConstraintParser.parseBoundSize(height, false, false) : BoundSize.NULL_SIZE);
return this;
}
/** Sets the pack width and height alignment.
*
* Same functionality as {@link #setPackHeightAlign(float)} and {@link #setPackWidthAlign(float)}
* only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param alignX The pack width alignment. 0.5f is default.
* @param alignY The pack height alignment. 0.5f is default.
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @since 3.5
*/
public final LC packAlign(float alignX, float alignY)
{
setPackWidthAlign(alignX);
setPackHeightAlign(alignY);
return this;
}
/** Sets a wrap after the number of columns/rows that is defined in the {@link net.miginfocom.layout.AC}.
*
* Same functionality as {@link #setWrapAfter(int 0)} only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
*/
public final LC wrap()
{
setWrapAfter(0);
return this;
}
/** Same functionality as {@link #setWrapAfter(int)} only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param count After what cell the grid should always auto wrap. If 0 the number of columns/rows in the
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
*/
public final LC wrapAfter(int count)
{
setWrapAfter(count);
return this;
}
/** Same functionality as {@link #setNoCache(boolean true)} only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
*/
public final LC noCache()
{
setNoCache(true);
return this;
}
/** Same functionality as {@link #setFlowX(boolean false)} only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
*/
public final LC flowY()
{
setFlowX(false);
return this;
}
/** Same functionality as {@link #setFlowX(boolean true)} only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
*/
public final LC flowX()
{
setFlowX(true);
return this;
}
/** Same functionality as {@link #setFillX(boolean true)} and {@link #setFillY(boolean true)} conmbined.T his method returns
* this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
*/
public final LC fill()
{
setFillX(true);
setFillY(true);
return this;
}
/** Same functionality as {@link #setFillX(boolean true)} only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
*/
public final LC fillX()
{
setFillX(true);
return this;
}
/** Same functionality as {@link #setFillY(boolean true)} only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
*/
public final LC fillY()
{
setFillY(true);
return this;
}
/** Same functionality as {@link #setLeftToRight(Boolean)} only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param b true for forcing left-to-right. false for forcing right-to-left.
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
*/
public final LC leftToRight(boolean b)
{
setLeftToRight(b ? Boolean.TRUE : Boolean.FALSE); // Not .valueOf due to retroweaver...
return this;
}
/** Same functionality as setLeftToRight(false) only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @since 3.7.2
*/
public final LC rightToLeft()
{
setLeftToRight(Boolean.FALSE);
return this;
}
/** Same functionality as {@link #setTopToBottom(boolean false)} only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
*/
public final LC bottomToTop()
{
setTopToBottom(false);
return this;
}
/** Same functionality as {@link #setTopToBottom(boolean true)} only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @since 3.7.2
*/
public final LC topToBottom()
{
setTopToBottom(true);
return this;
}
/** Same functionality as {@link #setNoGrid(boolean true)} only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
*/
public final LC noGrid()
{
setNoGrid(true);
return this;
}
/** Same functionality as {@link #setVisualPadding(boolean false)} only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
*/
public final LC noVisualPadding()
{
setVisualPadding(false);
return this;
}
/** Sets the same inset (expressed as a UnitValue, e.g. "10px" or "20mm") all around.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param allSides The unit value to set for all sides. May be null which means that the default panel insets
* for the platform is used.
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @see #setInsets(UnitValue[])
*/
public final LC insetsAll(String allSides)
{
UnitValue insH = ConstraintParser.parseUnitValue(allSides, true);
UnitValue insV = ConstraintParser.parseUnitValue(allSides, false);
insets = new UnitValue[] {insV, insH, insV, insH}; // No setter to avoid copy again
return this;
}
/** Same functionality as setInsets(ConstraintParser.parseInsets(s, true)). This method returns this
* for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param s The string to parse. E.g. "10 10 10 10" or "20". If less than 4 groups the last will be used for the missing.
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @see #setInsets(UnitValue[])
*/
public final LC insets(String s)
{
insets = ConstraintParser.parseInsets(s, true);
return this;
}
/** Sets the different insets (expressed as a UnitValues, e.g. "10px" or "20mm") for the corresponding sides.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param top The top inset. E.g. "10px" or "10mm" or "related". May be null in which case the default inset for this
* side for the platform will be used.
* @param left The left inset. E.g. "10px" or "10mm" or "related". May be null in which case the default inset for this
* side for the platform will be used.
* @param bottom The bottom inset. E.g. "10px" or "10mm" or "related". May be null in which case the default inset for this
* side for the platform will be used.
* @param right The right inset. E.g. "10px" or "10mm" or "related". May be null in which case the default inset for this
* side for the platform will be used.
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @see #setInsets(UnitValue[])
*/
public final LC insets(String top, String left, String bottom, String right)
{
insets = new UnitValue[] { // No setter to avoid copy again
ConstraintParser.parseUnitValue(top, false),
ConstraintParser.parseUnitValue(left, true),
ConstraintParser.parseUnitValue(bottom, false),
ConstraintParser.parseUnitValue(right, true)};
return this;
}
/** Same functionality as setAlignX(ConstraintParser.parseUnitValueOrAlign(unitValue, true)) only this method returns this
* for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param align The align keyword or for instance "100px". E.g "left", "right", "leading" or "trailing".
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @see #setAlignX(UnitValue)
*/
public final LC alignX(String align)
{
setAlignX(ConstraintParser.parseUnitValueOrAlign(align, true, null));
return this;
}
/** Same functionality as setAlignY(ConstraintParser.parseUnitValueOrAlign(align, false)) only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param align The align keyword or for instance "100px". E.g "top" or "bottom".
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @see #setAlignY(UnitValue)
*/
public final LC alignY(String align)
{
setAlignY(ConstraintParser.parseUnitValueOrAlign(align, false, null));
return this;
}
/** Sets both the alignX and alignY as the same time.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param ax The align keyword or for instance "100px". E.g "left", "right", "leading" or "trailing".
* @param ay The align keyword or for instance "100px". E.g "top" or "bottom".
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @see #alignX(String)
* @see #alignY(String)
*/
public final LC align(String ax, String ay)
{
if (ax != null)
alignX(ax);
if (ay != null)
alignY(ay);
return this;
}
/** Same functionality as setGridGapX(ConstraintParser.parseBoundSize(boundsSize, true, true)) only this method
* returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param boundsSize The BoundSize of the gap. This is a minimum and/or preferred and/or maximum size. E.g.
* "50:100:200" or "100px".
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @see #setGridGapX(BoundSize)
*/
public final LC gridGapX(String boundsSize)
{
setGridGapX(ConstraintParser.parseBoundSize(boundsSize, true, true));
return this;
}
/** Same functionality as setGridGapY(ConstraintParser.parseBoundSize(boundsSize, true, false)) only this method
* returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param boundsSize The BoundSize of the gap. This is a minimum and/or preferred and/or maximum size. E.g.
* "50:100:200" or "100px".
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @see #setGridGapY(BoundSize)
*/
public final LC gridGapY(String boundsSize)
{
setGridGapY(ConstraintParser.parseBoundSize(boundsSize, true, false));
return this;
}
/** Sets both grid gaps at the same time. see {@link #gridGapX(String)} and {@link #gridGapY(String)}.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param gapx The BoundSize of the gap. This is a minimum and/or preferred and/or maximum size. E.g.
* "50:100:200" or "100px".
* @param gapy The BoundSize of the gap. This is a minimum and/or preferred and/or maximum size. E.g.
* "50:100:200" or "100px".
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @see #gridGapX(String)
* @see #gridGapY(String)
*/
public final LC gridGap(String gapx, String gapy)
{
if (gapx != null)
gridGapX(gapx);
if (gapy != null)
gridGapY(gapy);
return this;
}
/** Same functionality as {@link #setDebugMillis(int repaintMillis)} only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param repaintMillis The new debug repaint interval.
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @see #setDebugMillis(int)
*/
public final LC debug(int repaintMillis)
{
setDebugMillis(repaintMillis);
return this;
}
/** Same functionality as {@link #setHideMode(int mode)} only this method returns this for chaining multiple calls.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param mode The mode:
* 0 == Normal. Bounds will be caclulated as if the component was visible.
* 1 == If hidden the size will be 0, 0 but the gaps remain.
* 2 == If hidden the size will be 0, 0 and gaps set to zero.
* 3 == If hidden the component will be disregarded completely and not take up a cell in the grid..
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
* @see #setHideMode(int)
*/
public final LC hideMode(int mode)
{
setHideMode(mode);
return this;
}
/** The minimum width for the container. The value will override any value that is set on the container itself.
*
* For a more thorough explanation of what this constraint does see the white paper or Cheat Sheet at www.migcontainers.com.
* @param width The width expressed as a UnitValue. E.g. "100px" or "200mm".
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
*/
public final LC minWidth(String width)
{
setWidth(LayoutUtil.derive(getWidth(), ConstraintParser.parseUnitValue(width, true), null, null));
return this;
}
/** The width for the container as a min and/or preferref and/or maximum width. The value will override any value that is set on
* the container itself.
*
* For a more thorough explanation of what this constraint does see the white paper or Cheat Sheet at www.migcontainers.com.
* @param width The width expressed as a Boundwidth. E.g. "50:100px:200mm" or "100px".
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
*/
public final LC width(String width)
{
setWidth(ConstraintParser.parseBoundSize(width, false, true));
return this;
}
/** The maximum width for the container. The value will override any value that is set on the container itself.
*
* For a more thorough explanation of what this constraint does see the white paper or Cheat Sheet at www.migcontainers.com.
* @param width The width expressed as a UnitValue. E.g. "100px" or "200mm".
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
*/
public final LC maxWidth(String width)
{
setWidth(LayoutUtil.derive(getWidth(), null, null, ConstraintParser.parseUnitValue(width, true)));
return this;
}
/** The minimum height for the container. The value will override any value that is set on the container itself.
*
* For a more thorough explanation of what this constraint does see the white paper or Cheat Sheet at www.migcontainers.com.
* @param height The height expressed as a UnitValue. E.g. "100px" or "200mm".
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
*/
public final LC minHeight(String height)
{
setHeight(LayoutUtil.derive(getHeight(), ConstraintParser.parseUnitValue(height, false), null, null));
return this;
}
/** The height for the container as a min and/or preferref and/or maximum height. The value will override any value that is set on
* the container itself.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcontainers.com.
* @param height The height expressed as a Boundheight. E.g. "50:100px:200mm" or "100px".
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
*/
public final LC height(String height)
{
setHeight(ConstraintParser.parseBoundSize(height, false, false));
return this;
}
/** The maximum height for the container. The value will override any value that is set on the container itself.
*
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcontainers.com.
* @param height The height expressed as a UnitValue. E.g. "100px" or "200mm".
* @return this so it is possible to chain calls. E.g. new LayoutConstraint().noGrid().gap().fill().
*/
public final LC maxHeight(String height)
{
setHeight(LayoutUtil.derive(getHeight(), null, null, ConstraintParser.parseUnitValue(height, false)));
return this;
}
// ************************************************
// Persistence Delegate and Serializable combined.
// ************************************************
private Object readResolve() throws ObjectStreamException
{
return LayoutUtil.getSerializedObject(this);
}
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
{
LayoutUtil.setSerializedObject(this, LayoutUtil.readAsXML(in));
}
public void writeExternal(ObjectOutput out) throws IOException
{
if (getClass() == LC.class)
LayoutUtil.writeAsXML(out, this);
}
}
miglayout-3.7.4/net/miginfocom/layout/InCellGapProvider.java0000644000175000017500000000324011455506464022722 0ustar tonytonypackage net.miginfocom.layout;
/** An interface to implement if you want to decide the gaps between two types of components within the same cell.
*
are in the same cell.
* @param comp The component that the gap is for. Never null.
* @param adjacentComp The adjacent component if any. May be null.
* @param adjacentSide What side the adjacentComp is on. {@link javax.swing.SwingUtilities#TOP} or
* {@link javax.swing.SwingUtilities#LEFT} or {@link javax.swing.SwingUtilities#BOTTOM} or {@link javax.swing.SwingUtilities#RIGHT}.
* @param tag The tag string that the component might be tagged with in the component constraints. May be null.
* @param isLTR If it is left-to-right.
* @return The default gap between two components or null if there should be no gap.
*/
public abstract BoundSize getDefaultGap(ComponentWrapper comp, ComponentWrapper adjacentComp, int adjacentSide, String tag, boolean isLTR);
}
miglayout-3.7.4/net/miginfocom/layout/ComponentWrapper.java0000644000175000017500000003376511366642712022731 0ustar tonytonypackage net.miginfocom.layout;
/*
* License (BSD):
* ==============
*
* Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
* Neither the name of the MiG InfoCom AB nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* @version 1.0
* @author Mikael Grev, MiG InfoCom AB
* Date: 2006-sep-08
*/
/** A class that wraps the important parts of a Component.
*
* NOTE!.equals() and .hashcode() should be shunted to the wrapped component. E.g.
*
* public int hashCode()
{
return getComponent().hashCode();
}
public final boolean equals(Object o)
{
if (o instanceof ComponentWrapper == false)
return false;
return getComponent().equals(((ComponentWrapper) o).getComponent());
}
*
*/
public interface ComponentWrapper
{
static final int TYPE_UNSET = -1;
public static final int TYPE_UNKNOWN = 0;
public static final int TYPE_CONTAINER = 1;
public static final int TYPE_LABEL = 2;
public static final int TYPE_TEXT_FIELD = 3;
public static final int TYPE_TEXT_AREA = 4;
public static final int TYPE_BUTTON = 5;
public static final int TYPE_LIST = 6;
public static final int TYPE_TABLE = 7;
public static final int TYPE_SCROLL_PANE = 8;
public static final int TYPE_IMAGE = 9;
public static final int TYPE_PANEL = 10;
public static final int TYPE_COMBO_BOX = 11;
public static final int TYPE_SLIDER = 12;
public static final int TYPE_SPINNER = 13;
public static final int TYPE_PROGRESS_BAR = 14;
public static final int TYPE_TREE = 15;
public static final int TYPE_CHECK_BOX = 16;
public static final int TYPE_SCROLL_BAR = 17;
public static final int TYPE_SEPARATOR = 18;
/** Returns the actual object that this wrapper is aggregating. This might be needed for getting
* information about the object that the wrapper interface does not provide.
*
* If this is a container the container should be returned instead.
* @return The actual object that this wrapper is aggregating. Not null.
*/
public abstract Object getComponent();
/** Returns the current x coordinate for this component.
* @return The current x coordinate for this component.
*/
public abstract int getX();
/** Returns the current y coordinate for this component.
* @return The current y coordinate for this component.
*/
public abstract int getY();
/** Returns the current width for this component.
* @return The current width for this component.
*/
public abstract int getWidth();
/** Returns the current height for this component.
* @return The current height for this component.
*/
public abstract int getHeight();
/** Returns the screen x-coordinate for the upper left coordinate of the component layout-able bounds.
* @return The screen x-coordinate for the upper left coordinate of the component layout-able bounds.
*/
public abstract int getScreenLocationX();
/** Returns the screen y-coordinate for the upper left coordinate of the component layout-able bounds.
* @return The screen y-coordinate for the upper left coordinate of the component layout-able bounds.
*/
public abstract int getScreenLocationY();
/** Returns the minimum width of the component.
* @param hHint The Size hint for the other dimension. An implementation can use this value or the
* current size for the widget in this dimension, or a combination of both, to calculate the correct size.
* Use -1 to denote that there is no hint. This corresponds with SWT.DEFAULT.
* @return The minimum width of the component.
* @since 3.5. Added the hint as a parameter knowing that a correction and recompilation is necessary for
* any implementing classes. This change was worth it though.
*/
public abstract int getMinimumWidth(int hHint);
/** Returns the minimum height of the component.
* @param wHint The Size hint for the other dimension. An implementation can use this value or the
* current size for the widget in this dimension, or a combination of both, to calculate the correct size.
* Use -1 to denote that there is no hint. This corresponds with SWT.DEFAULT.
* @return The minimum height of the component.
* @since 3.5. Added the hint as a parameter knowing that a correction and recompilation is necessary for
* any implementing classes. This change was worth it though.
*/
public abstract int getMinimumHeight(int wHint);
/** Returns the preferred width of the component.
* @param hHint The Size hint for the other dimension. An implementation can use this value or the
* current size for the widget in this dimension, or a combination of both, to calculate the correct size.
* Use -1 to denote that there is no hint. This corresponds with SWT.DEFAULT.
* @return The preferred width of the component.
* @since 3.5. Added the hint as a parameter knowing that a correction and recompilation is necessary for
* any implementing classes. This change was worth it though.
*/
public abstract int getPreferredWidth(int hHint);
/** Returns the preferred height of the component.
* @param wHint The Size hint for the other dimension. An implementation can use this value or the
* current size for the widget in this dimension, or a combination of both, to calculate the correct size.
* Use -1 to denote that there is no hint. This corresponds with SWT.DEFAULT.
* @return The preferred height of the component.
* @since 3.5. Added the hint as a parameter knowing that a correction and recompilation is necessary for
* any implementing classes. This change was worth it though.
*/
public abstract int getPreferredHeight(int wHint);
/** Returns the maximum width of the component.
* @param hHint The Size hint for the other dimension. An implementation can use this value or the
* current size for the widget in this dimension, or a combination of both, to calculate the correct size.
* Use -1 to denote that there is no hint. This corresponds with SWT.DEFAULT.
* @return The maximum width of the component.
* @since 3.5. Added the hint as a parameter knowing that a correction and recompilation is necessary for
* any implementing classes. This change was worth it though.
*/
public abstract int getMaximumWidth(int hHint);
/** Returns the maximum height of the component.
* @param wHint The Size hint for the other dimension. An implementation can use this value or the
* current size for the widget in this dimension, or a combination of both, to calculate the correct size.
* Use -1 to denote that there is no hint. This corresponds with SWT.DEFAULT.
* @return The maximum height of the component.
* @since 3.5. Added the hint as a parameter knowing that a correction and recompilation is necessary for
* any implementing classes. This change was worth it though.
*/
public abstract int getMaximumHeight(int wHint);
/** Sets the component's bounds.
* @param x The x coordinate.
* @param y The y coordinate.
* @param width The width.
* @param height The height.
*/
public abstract void setBounds(int x, int y, int width, int height);
/** Returns if the component's visibility is set to true. This should not return if the component is
* actually visible, but if the visibility is set to true or not.
* @return true means visible.
*/
public abstract boolean isVisible();
/** Returns the baseline for the component given the suggested height.
* @param width The width to calculate for if other than the current. If -1 the current size should be used.
* @param height The height to calculate for if other than the current. If -1 the current size should be used.
* @return The baseline from the top or -1 if not applicable.
*/
public abstract int getBaseline(int width, int height);
/** Returns if the component has a baseline and if it can be retrieved. Should for instance return
* false for Swing before mustang.
* @return If the component has a baseline and if it can be retrieved.
*/
public abstract boolean hasBaseline();
/** Returns the container for this component.
* @return The container for this component. Will return null if the component has no parent.
*/
public abstract ContainerWrapper getParent();
/** Returns the pixel unit factor for the horizontal or vertical dimension.
*
* The factor is 1 for both dimensions on the normal font in a JPanel on Windows. The factor should increase with a bigger "X".
*
* @param isHor If it is the horizontal factor that should be returned.
* @return The factor.
*/
public abstract float getPixelUnitFactor(boolean isHor);
/** Returns the DPI (Dots Per Inch) of the screen the component is currently in or for the default
* screen if the component is not visible.
*
* If headless mode {@link net.miginfocom.layout.PlatformDefaults#getDefaultDPI} will be returned.
* @return The DPI.
*/
public abstract int getHorizontalScreenDPI();
/** Returns the DPI (Dots Per Inch) of the screen the component is currently in or for the default
* screen if the component is not visible.
*
* If headless mode {@link net.miginfocom.layout.PlatformDefaults#getDefaultDPI} will be returned.
* @return The DPI.
*/
public abstract int getVerticalScreenDPI();
/** Returns the pixel size of the screen that the component is currently in or for the default
* screen if the component is not visible or null.
*
* If in headless mode 1024 is returned.
* @return The screen size. E.g. 1280.
*/
public abstract int getScreenWidth();
/** Returns the pixel size of the screen that the component is currently in or for the default
* screen if the component is not visible or null.
*
* If in headless mode 768 is returned.
* @return The screen size. E.g. 1024.
*/
public abstract int getScreenHeight();
/** Returns a String id that can be used to reference the component in link constraints. This value should
* return the default id for the component. The id can be set for a component in the constraints and if
* so the value returned by this method will never be used. If there are no sensible id for the component
* null should be returned.
*
* For instance the Swing implementation returns the string returned from Component.getName().
* @return The string link id or null.
*/
public abstract String getLinkId();
/** Returns a hash code that should be reasonably different for anything that might change the layout. This value is used to
* know if the component layout needs to clear any caches.
* @return A hash code that should be reasonably different for anything that might change the layout. Returns -1 if the widget is
* disposed.
*/
public abstract int getLayoutHashCode();
/** Returns the padding on a component by component basis. This method can be overridden to return padding to compensate for example for
* borders that have shadows or where the outer most pixel is not the visual "edge" to align to.
*
* Default implementation returns null for all components except for Windows XP's JTabbedPane which will return new Insets(0, 0, 2, 2).
*
* NOTE! To reduce generated garbage the returned padding should never be changed so that the same insets can be returned many times.
* @return null if no padding. NOTE! To reduce generated garbage the returned padding should never be changed so that
* the same insets can be returned many times. [top, left, bottom, right]
*/
public int[] getVisualPadding();
/** Paints component outline to indicate where it is.
*/
public abstract void paintDebugOutline();
/** Returns the type of component that this wrapper is wrapping.
*
* This method can be invoked often so the result should be cached.
*
* NOTE! This is misspelled. Keeping it that way though since this is only used by developers who
* port MigLayout.
* @param disregardScrollPane Is true any wrapping scroll pane should be disregarded and the type
* of the scrolled component should be returned.
* @return The type of component that this wrapper is wrapping. E.g. {@link #TYPE_LABEL}.
*/
public abstract int getComponetType(boolean disregardScrollPane);
}miglayout-3.7.4/net/miginfocom/layout/LinkHandler.java0000644000175000017500000001470511521467274021613 0ustar tonytonypackage net.miginfocom.layout;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
/*
* License (BSD):
* ==============
*
* Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
* Neither the name of the MiG InfoCom AB nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* @version 1.0
* @author Mikael Grev, MiG InfoCom AB
* Date: 2006-sep-08
*/
/**
*/
public final class LinkHandler
{
public static final int X = 0;
public static final int Y = 1;
public static final int WIDTH = 2;
public static final int HEIGHT = 3;
public static final int X2 = 4;
public static final int Y2 = 5;
private static final ArrayList> LAYOUTS = new ArrayList>(4);
private static final ArrayList> VALUES = new ArrayList>(4);
private static final ArrayList> VALUES_TEMP = new ArrayList>(4);
private LinkHandler()
{
}
public synchronized static Integer getValue(Object layout, String key, int type)
{
Integer ret = null;
boolean cont = true;
for (int i = LAYOUTS.size() - 1; i >= 0; i--) {
Object l = LAYOUTS.get(i).get();
if (ret == null && l == layout) {
int[] rect = VALUES_TEMP.get(i).get(key);
if (cont && rect != null && rect[type] != LayoutUtil.NOT_SET) {
ret = Integer.valueOf(rect[type]);
} else {
rect = VALUES.get(i).get(key);
ret = (rect != null && rect[type] != LayoutUtil.NOT_SET) ? Integer.valueOf(rect[type]) : null;
}
cont = false;
}
if (l == null) {
LAYOUTS.remove(i);
VALUES.remove(i);
VALUES_TEMP.remove(i);
}
}
return ret;
}
/** Sets a key that can be linked to from any component.
* @param layout The MigLayout instance
* @param key The key to link to. This is the same as the ID in a component constraint.
* @param x x
* @param y y
* @param width Width
* @param height Height
* @return If the value was changed
*/
public synchronized static boolean setBounds(Object layout, String key, int x, int y, int width, int height)
{
return setBounds(layout, key, x, y, width, height, false, false);
}
synchronized static boolean setBounds(Object layout, String key, int x, int y, int width, int height, boolean temporary, boolean incCur)
{
for (int i = LAYOUTS.size() - 1; i >= 0; i--) {
Object l = LAYOUTS.get(i).get();
if (l == layout) {
HashMap map = (temporary ? VALUES_TEMP : VALUES).get(i);
int[] old = map.get(key);
if (old == null || old[X] != x || old[Y] != y || old[WIDTH] != width || old[HEIGHT] != height) {
if (old == null || incCur == false) {
map.put(key, new int[] {x, y, width, height, x + width, y + height});
return true;
} else {
boolean changed = false;
if (x != LayoutUtil.NOT_SET) {
if (old[X] == LayoutUtil.NOT_SET || x < old[X]) {
old[X] = x;
old[WIDTH] = old[X2] - x;
changed = true;
}
if (width != LayoutUtil.NOT_SET) {
int x2 = x + width;
if (old[X2] == LayoutUtil.NOT_SET || x2 > old[X2]) {
old[X2] = x2;
old[WIDTH] = x2 - old[X];
changed = true;
}
}
}
if (y != LayoutUtil.NOT_SET) {
if (old[Y] == LayoutUtil.NOT_SET || y < old[Y]) {
old[Y] = y;
old[HEIGHT] = old[Y2] - y;
changed = true;
}
if (height != LayoutUtil.NOT_SET) {
int y2 = y + height;
if (old[Y2] == LayoutUtil.NOT_SET || y2 > old[Y2]) {
old[Y2] = y2;
old[HEIGHT] = y2 - old[Y];
changed = true;
}
}
}
return changed;
}
}
return false;
}
}
LAYOUTS.add(new WeakReference