removed classes from MigLayout

master
melvin 2012-06-17 14:30:13 +08:00
parent 07a24b45b8
commit 80165b330b
21 changed files with 0 additions and 12882 deletions

View File

@ -1,539 +0,0 @@
package 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 constraint that holds the column <b>or</b> row constraints for the grid. It also holds the gaps between the rows and columns.
* <p>
* This class is a holder and builder for a number of {@link net.miginfocom.layout.DimConstraint}s.
* <p>
* For a more thorough explanation of what these constraints do, and how to build the constraints, see the White Paper or Cheat Sheet at www.migcomponents.com.
* <p>
* Note that there are two way to build this constraint. Through String (e.g. <code>"[100]3[200,fill]"</code> or through API (E.g.
* <code>new AxisConstraint().size("100").gap("3").size("200").fill()</code>.
*/
public final class AC
{
private final ArrayList<DimConstraint> cList = new ArrayList<DimConstraint>(8);
private transient int curIx = 0;
/** Constructor. Creates an instance that can be configured manually. Will be initialized with a default
* {@link net.miginfocom.layout.DimConstraint}.
*/
public AC()
{
cList.add(new DimConstraint());
}
/** Property. The different {@link net.miginfocom.layout.DimConstraint}s that this object consists of.
* These <code><DimConstraints/code> contains all information in this class.
* <p>
* Yes, we are embarrassingly aware that the method is misspelled.
* @return The different {@link net.miginfocom.layout.DimConstraint}s that this object consists of. A new list and
* never <code>null</code>.
*/
public final DimConstraint[] getConstaints()
{
return cList.toArray(new DimConstraint[cList.size()]);
}
/** Sets the different {@link net.miginfocom.layout.DimConstraint}s that this object should consists of.
* <p>
* Yes, we are embarrassingly aware that the method is misspelled.
* @param constr The different {@link net.miginfocom.layout.DimConstraint}s that this object consists of. The list
* will be copied for storage. <code>null</code> or and emty array will reset the constraints to one <code>DimConstraint</code>
* with default values.
*/
public final void setConstaints(DimConstraint[] constr)
{
if (constr == null || constr.length < 1 )
constr = new DimConstraint[] {new DimConstraint()};
cList.clear();
cList.ensureCapacity(constr.length);
for (DimConstraint c : constr)
cList.add(c);
}
/** Returns the number of rows/columns that this constraints currently have.
* @return The number of rows/columns that this constraints currently have. At least 1.
*/
public int getCount()
{
return cList.size();
}
/** Sets the total number of rows/columns to <code>size</code>. If the number of rows/columns is already more
* than <code>size</code> nothing will happen.
* @param size The total number of rows/columns
* @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
*/
public final AC count(int size)
{
makeSize(size);
return this;
}
/** Specifies that the current row/column should not be grid-like. The while row/colum will have its components layed out
* in one single cell. It is the same as to say that the cells in this column/row will all be merged (a.k.a spanned).
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
*/
public final AC noGrid()
{
return noGrid(curIx);
}
/** Specifies that the indicated rows/columns should not be grid-like. The while row/colum will have its components layed out
* in one single cell. It is the same as to say that the cells in this column/row will all be merged (a.k.a spanned).
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint.
* @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
*/
public final AC noGrid(int... indexes)
{
for (int i = indexes.length - 1; i >= 0; i--) {
int ix = indexes[i];
makeSize(ix);
cList.get(ix).setNoGrid(true);
}
return this;
}
/** Sets the current row/column to <code>i</code>. If the current number of rows/columns is less than <code>i</code> a call
* to {@link #count(int)} will set the size accordingly.
* <p>
* The next call to any of the constraint methods (e.g. {@link net.miginfocom.layout.AC#noGrid}) will be carried
* out on this new row/column.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param i The new current row/column.
* @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
*/
public final AC index(int i)
{
makeSize(i);
curIx = i;
return this;
}
/** Specifies that the current row/column's component should grow by default. It does not affect the size of the row/column.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
*/
public final AC fill()
{
return fill(curIx);
}
/** Specifies that the indicated rows'/columns' component should grow by default. It does not affect the size of the row/column.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint.
* @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
*/
public final AC fill(int... indexes)
{
for (int i = indexes.length - 1; i >= 0; i--) {
int ix = indexes[i];
makeSize(ix);
cList.get(ix).setFill(true);
}
return this;
}
// /** Specifies that the current row/column should be put in the end group <code>s</code> and will thus share the same ending
// * coordinate within the group.
// * <p>
// * 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 <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
// */
// public final AxisConstraint endGroup(String s)
// {
// return endGroup(s, curIx);
// }
//
// /** Specifies that the indicated rows/columns should be put in the end group <code>s</code> and will thus share the same ending
// * coordinate within the group.
// * <p>
// * 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.
// * @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint.
// * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
// */
// public final AxisConstraint endGroup(String s, int... indexes)
// {
// for (int i = indexes.length - 1; i >= 0; i--) {
// int ix = indexes[i];
// makeSize(ix);
// cList.get(ix).setEndGroup(s);
// }
// return this;
// }
/** Specifies that the current row/column should be put in the size group <code>s</code> and will thus share the same size
* constraints as the other components in the group.
* <p>
* Same as <code>sizeGroup("")</code>
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
* @since 3.7.2
*/
public final AC sizeGroup()
{
return sizeGroup("", curIx);
}
/** Specifies that the current row/column should be put in the size group <code>s</code> and will thus share the same size
* constraints as the other components in the group.
* <p>
* 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 <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
*/
public final AC sizeGroup(String s)
{
return sizeGroup(s, curIx);
}
/** Specifies that the indicated rows/columns should be put in the size group <code>s</code> and will thus share the same size
* constraints as the other components in the group.
* <p>
* 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.
* @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint.
* @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
*/
public final AC sizeGroup(String s, int... indexes)
{
for (int i = indexes.length - 1; i >= 0; i--) {
int ix = indexes[i];
makeSize(ix);
cList.get(ix).setSizeGroup(s);
}
return this;
}
/** Specifies the current row/column's min and/or preferred and/or max size. E.g. <code>"10px"</code> or <code>"50:100:200"</code>.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param s The minimum and/or preferred and/or maximum size of this row. The string will be interpreted
* as a <b>BoundSize</b>. For more info on how <b>BoundSize</b> is formatted see the documentation.
* @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
*/
public final AC size(String s)
{
return size(s, curIx);
}
/** Specifies the indicated rows'/columns' min and/or preferred and/or max size. E.g. <code>"10px"</code> or <code>"50:100:200"</code>.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param size The minimum and/or preferred and/or maximum size of this row. The string will be interpreted
* as a <b>BoundSize</b>. For more info on how <b>BoundSize</b> is formatted see the documentation.
* @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint.
* @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
*/
public final AC size(String size, int... indexes)
{
BoundSize bs = ConstraintParser.parseBoundSize(size, false, true);
for (int i = indexes.length - 1; i >= 0; i--) {
int ix = indexes[i];
makeSize(ix);
cList.get(ix).setSize(bs);
}
return this;
}
/** Specifies the gap size to be the default one <b>AND</b> moves to the next column/row. The method is called <code>.gap()</code>
* rather the more natural <code>.next()</code> to indicate that it is very much related to the other <code>.gap(..)</code> methods.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
*/
public final AC gap()
{
curIx++;
return this;
}
/** Specifies the gap size to <code>size</code> <b>AND</b> moves to the next column/row.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param size minimum and/or preferred and/or maximum size of the gap between this and the next row/column.
* The string will be interpreted as a <b>BoundSize</b>. For more info on how <b>BoundSize</b> is formatted see the documentation.
* @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
*/
public final AC gap(String size)
{
return gap(size, curIx++);
}
/** Specifies the indicated rows'/columns' gap size to <code>size</code>.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param size minimum and/or preferred and/or maximum size of the gap between this and the next row/column.
* The string will be interpreted as a <b>BoundSize</b>. For more info on how <b>BoundSize</b> is formatted see the documentation.
* @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint.
* @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
*/
public final AC gap(String size, int... indexes)
{
BoundSize bsa = size != null ? ConstraintParser.parseBoundSize(size, true, true) : null;
for (int i = indexes.length - 1; i >= 0; i--) {
int ix = indexes[i];
makeSize(ix);
if (bsa != null)
cList.get(ix).setGapAfter(bsa);
}
return this;
}
/** Specifies the current row/column's columns default alignment <b>for its components</b>. It does not affect the positioning
* or size of the columns/row itself. For columns it is the horizonal alignment (e.g. "left") and for rows it is the vertical
* alignment (e.g. "top").
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param side The default side to align the components. E.g. "top" or "left", or "leading" or "trailing" or "bottom" or "right".
* @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
*/
public final AC align(String side)
{
return align(side, curIx);
}
/** Specifies the indicated rows'/columns' columns default alignment <b>for its components</b>. It does not affect the positioning
* or size of the columns/row itself. For columns it is the horizonal alignment (e.g. "left") and for rows it is the vertical
* alignment (e.g. "top").
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param side The default side to align the components. E.g. "top" or "left", or "before" or "after" or "bottom" or "right".
* @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint.
* @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
*/
public final AC align(String side, int... indexes)
{
UnitValue al = ConstraintParser.parseAlignKeywords(side, true);
if (al == null)
al = ConstraintParser.parseAlignKeywords(side, false);
for (int i = indexes.length - 1; i >= 0; i--) {
int ix = indexes[i];
makeSize(ix);
cList.get(ix).setAlign(al);
}
return this;
}
/** Specifies the current row/column's grow priority.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param p The new grow priority.
* @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
*/
public final AC growPrio(int p)
{
return growPrio(p, curIx);
}
/** Specifies the indicated rows'/columns' grow priority.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param p The new grow priority.
* @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint.
* @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
*/
public final AC growPrio(int p, int... indexes)
{
for (int i = indexes.length - 1; i >= 0; i--) {
int ix = indexes[i];
makeSize(ix);
cList.get(ix).setGrowPriority(p);
}
return this;
}
/** Specifies the current row/column's grow weight within columns/rows with the <code>grow priority</code> 100f.
* <p>
* Same as <code>grow(100f)</code>
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
* @since 3.7.2
*/
public final AC grow()
{
return grow(1f, curIx);
}
/** Specifies the current row/column's grow weight within columns/rows with the same <code>grow priority</code>.
* <p>
* 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 <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
*/
public final AC grow(float w)
{
return grow(w, curIx);
}
/** Specifies the indicated rows'/columns' grow weight within columns/rows with the same <code>grow priority</code>.
* <p>
* 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.
* @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint.
* @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
*/
public final AC grow(float w, int... indexes)
{
Float gw = new Float(w);
for (int i = indexes.length - 1; i >= 0; i--) {
int ix = indexes[i];
makeSize(ix);
cList.get(ix).setGrow(gw);
}
return this;
}
/** Specifies the current row/column's shrink priority.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param p The new shrink priority.
* @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
*/
public final AC shrinkPrio(int p)
{
return shrinkPrio(p, curIx);
}
/** Specifies the indicated rows'/columns' shrink priority.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param p The new shrink priority.
* @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint.
* @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
*/
public final AC shrinkPrio(int p, int... indexes)
{
for (int i = indexes.length - 1; i >= 0; i--) {
int ix = indexes[i];
makeSize(ix);
cList.get(ix).setShrinkPriority(p);
}
return this;
}
/** Specifies that the current row/column's shrink weight withing the columns/rows with the <code>shrink priority</code> 100f.
* <p>
* Same as <code>shrink(100f)</code>.
* <p>
* For a more thorough explanation of what this constraint does see the White Paper or Cheat Sheet at www.migcomponents.com.
* @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
* @since 3.7.2
*/
public final AC shrink()
{
return shrink(100f, curIx);
}
/** Specifies that the current row/column's shrink weight withing the columns/rows with the same <code>shrink priority</code>.
* <p>
* For a more thorough explanation of what this constraint does see the White Paper or Cheat Sheet at www.migcomponents.com.
* @param w The shrink weight.
* @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
* @since 3.7.2
*/
public final AC shrink(float w)
{
return shrink(w, curIx);
}
/** Specifies the indicated rows'/columns' shrink weight withing the columns/rows with the same <code>shrink priority</code>.
* <p>
* For a more thorough explanation of what this constraint does see the White Paper or Cheat Sheet at www.migcomponents.com.
* @param w The shrink weight.
* @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint.
* @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
* @since 3.7.2
*/
public final AC shrink(float w, int... indexes)
{
Float sw = new Float(w);
for (int i = indexes.length - 1; i >= 0; i--) {
int ix = indexes[i];
makeSize(ix);
cList.get(ix).setShrink(sw);
}
return this;
}
private void makeSize(int sz)
{
if (cList.size() <= sz) {
cList.ensureCapacity(sz);
for (int i = cList.size(); i <= sz; i++)
cList.add(new DimConstraint());
}
}
// ************************************************
// 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() == AC.class)
LayoutUtil.writeAsXML(out, this);
}
}

View File

@ -1,273 +0,0 @@
package 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}.
* <p>
* This class is a simple value container and it is immutable.
* <p>
* If a size is missing (i.e., <code>null</code>) that boundary should be considered "not in use".
* <p>
* 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. <b>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 <code>null</code>.
* @param preferred The preferred size. May be <code>null</code>.
* @param max The maximum size. May be <code>null</code>.
* @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. <b>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 <code>null</code>.
* @param preferred The preferred size. May be <code>null</code>.
* @param max The maximum size. May be <code>null</code>.
* @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 <code>null</code>.
*/
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 <code>null</code>.
*/
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 <code>null</code>.
*/
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 <code>null</code>)
* @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 <code>size</code> 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. <code>LayoutUtil.MIN</code>, <code>LayoutUtil.PREF</code> or <code>LayoutUtil.MAX</code>.
* @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.
* <p>
* <code>null</code> 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 <code>null</code>.
* @param comp The component, if applicable, can be <code>null</code>.
* @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 <code>null</code>.
*/
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 {
if(LayoutUtil.HAS_BEANS){
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));
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,297 +0,0 @@
package net.miginfocom.layout;
/*
* License (BSD):
* ==============
*
* Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
* Neither the name of the MiG InfoCom AB nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* @version 1.0
* @author Mikael Grev, MiG InfoCom AB
* Date: 2006-sep-08
*/
/** A class that wraps the important parts of a Component.
* <p>
* <b>NOTE!</b>.equals() and .hashcode() should be shunted to the wrapped component. E.g.
* <pre>
* public int hashCode()
{
return getComponent().hashCode();
}
public final boolean equals(Object o)
{
if (o instanceof ComponentWrapper == false)
return false;
return getComponent().equals(((ComponentWrapper) o).getComponent());
}
* </pre>
*/
public interface ComponentWrapper
{
static final int TYPE_UNSET = -1;
public static final int TYPE_UNKNOWN = 0;
public static final int TYPE_CONTAINER = 1;
public static final int TYPE_LABEL = 2;
public static final int TYPE_TEXT_FIELD = 3;
public static final int TYPE_TEXT_AREA = 4;
public static final int TYPE_BUTTON = 5;
public static final int TYPE_LIST = 6;
public static final int TYPE_TABLE = 7;
public static final int TYPE_SCROLL_PANE = 8;
public static final int TYPE_IMAGE = 9;
public static final int TYPE_PANEL = 10;
public static final int TYPE_COMBO_BOX = 11;
public static final int TYPE_SLIDER = 12;
public static final int TYPE_SPINNER = 13;
public static final int TYPE_PROGRESS_BAR = 14;
public static final int TYPE_TREE = 15;
public static final int TYPE_CHECK_BOX = 16;
public static final int TYPE_SCROLL_BAR = 17;
public static final int TYPE_SEPARATOR = 18;
/** Returns the actual object that this wrapper is aggregating. This might be needed for getting
* information about the object that the wrapper interface does not provide.
* <p>
* If this is a container the container should be returned instead.
* @return The actual object that this wrapper is aggregating. Not <code>null</code>.
*/
public abstract Object getComponent();
/** Returns the current x coordinate for this component.
* @return The current x coordinate for this component.
*/
public abstract int getX();
/** Returns the current y coordinate for this component.
* @return The current y coordinate for this component.
*/
public abstract int getY();
/** Returns the current width for this component.
* @return The current width for this component.
*/
public abstract int getWidth();
/** Returns the current height for this component.
* @return The current height for this component.
*/
public abstract int getHeight();
/** Returns the screen x-coordinate for the upper left coordinate of the component 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.<br>
* 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.<br>
* 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.<br>
* 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.<br>
* 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.<br>
* 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.<br>
* 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 <code>true</code>. This should not return if the component is
* actually visible, but if the visibility is set to true or not.
* @return <code>true</code> means visible.
*/
public abstract boolean isVisible();
/** Returns the baseline for the component given the suggested height.
* @param width The width to calculate for if other than the current. If <code>-1</code> the current size should be used.
* @param height The height to calculate for if other than the current. If <code>-1</code> the current size should be used.
* @return The baseline from the top or -1 if not applicable.
*/
public abstract int getBaseline(int width, int height);
/** Returns if the component has a baseline and if it can be retrieved. Should for instance return
* <code>false</code> for Swing before mustang.
* @return If the component has a baseline and if it can be retrieved.
*/
public abstract boolean hasBaseline();
/** Returns the container for this component.
* @return The container for this component. Will return <code>null</code> if the component has no parent.
*/
public abstract ContainerWrapper getParent();
/** Returns the pixel unit factor for the horizontal or vertical dimension.
* <p>
* The factor is 1 for both dimensions on the normal font in a JPanel on Windows. The factor should increase with a bigger "X".
* <p>
* This is the Swing version:
* <pre>
* Rectangle2D r = fm.getStringBounds("X", parent.getGraphics());
* wFactor = r.getWidth() / 6;
* hFactor = r.getHeight() / 13.27734375f;
* </pre>
* @param isHor If it is the horizontal factor that should be returned.
* @return The factor.
*/
public abstract float getPixelUnitFactor(boolean isHor);
/** Returns the DPI (Dots Per Inch) of the screen the component is currently in or for the default
* screen if the component is not visible.
* <p>
* 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.
* <p>
* 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 <code>null</code>.
* <p>
* If in headless mode <code>1024</code> is returned.
* @return The screen size. E.g. <code>1280</code>.
*/
public abstract int getScreenWidth();
/** Returns the pixel size of the screen that the component is currently in or for the default
* screen if the component is not visible or <code>null</code>.
* <p>
* If in headless mode <code>768</code> is returned.
* @return The screen size. E.g. <code>1024</code>.
*/
public abstract int getScreenHeight();
/** Returns a String id that can be used to reference the component in link constraints. This value should
* return the default id for the component. The id can be set for a component in the constraints and if
* so the value returned by this method will never be used. If there are no sensible id for the component
* <code>null</code> should be returned.
* <p>
* For instance the Swing implementation returns the string returned from <code>Component.getName()</code>.
* @return The string link id or <code>null</code>.
*/
public abstract String getLinkId();
/** Returns a hash code that should be 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.
* <p>
* Default implementation returns <code>null</code> for all components except for Windows XP's JTabbedPane which will return new Insets(0, 0, 2, 2).
* <p>
* <b>NOTE!</B> To reduce generated garbage the returned padding should never be changed so that the same insets can be returned many times.
* @return <code>null</code> if no padding. <b>NOTE!</B> To reduce 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.
* <p>
* This method can be invoked often so the result should be cached.
* <p>
* <b>NOTE!</b> This is misspelled. Keeping it that way though since this is only used by developers who
* port MigLayout.
* @param disregardScrollPane Is <code>true</code> any wrapping scroll pane should be disregarded and the type
* of the scrolled component should be returned.
* @return The type of component that this wrapper is wrapping. E.g. {@link #TYPE_LABEL}.
*/
public abstract int getComponetType(boolean disregardScrollPane);
}

File diff suppressed because it is too large Load Diff

View File

@ -1,69 +0,0 @@
package net.miginfocom.layout;
/*
* License (BSD):
* ==============
*
* Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
* Neither the name of the MiG InfoCom AB nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* @version 1.0
* @author Mikael Grev, MiG InfoCom AB
* Date: 2006-sep-08
*/
/** A class that wraps 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 <code>null</code>.
*/
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 <code>LayoutHandler</code> (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 <code>null</code>.
*/
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);
}

View File

@ -1,471 +0,0 @@
package 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
*/
/** A simple value holder for a constraint for one dimension.
*/
public final class DimConstraint
{
/** How this entity can be resized in the dimension that this constraint represents.
*/
final ResizeConstraint resize = new ResizeConstraint();
// Look at the properties' getter/setter methods for explanation
private String sizeGroup = null; // A "context" compared with equals.
private BoundSize size = BoundSize.NULL_SIZE; // Min, pref, max. Never null, but sizes can be null.
private BoundSize gapBefore = null, gapAfter = null;
private UnitValue align = null;
// ************** Only applicable on components! *******************
private String endGroup = null; // A "context" compared with equals.
// ************** Only applicable on rows/columns! *******************
private boolean fill = false;
private boolean noGrid = false;
/** Empty constructor.
*/
public DimConstraint()
{
}
/** Returns the grow priority. Relative priority is used for determining which entities gets the extra space first.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return The grow priority.
*/
public int getGrowPriority()
{
return resize.growPrio;
}
/** Sets the grow priority. Relative priority is used for determining which entities gets the extra space first.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param p The new grow priority.
*/
public void setGrowPriority(int p)
{
resize.growPrio = p;
}
/** Returns the grow weight.<p>
* Grow weight is how flexible the entity should be, relative to other entities, when it comes to growing. <code>null</code> or
* zero mean it will never grow. An entity that has twice the grow weight compared to another entity will get twice
* as much of available space.
* <p>
* GrowWeight are only compared within the same GrowPrio.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return The current grow weight.
*/
public Float getGrow()
{
return resize.grow;
}
/** Sets the grow weight.<p>
* Grow weight is how flexible the entity should be, relative to other entities, when it comes to growing. <code>null</code> or
* zero mean it will never grow. An entity that has twice the grow weight compared to another entity will get twice
* as much of available space.
* <p>
* GrowWeight are only compared within the same GrowPrio.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param weight The new grow weight.
*/
public void setGrow(Float weight)
{
resize.grow = weight;
}
/** Returns the shrink priority. Relative priority is used for determining which entities gets smaller first when space is scarce.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return The shrink priority.
*/
public int getShrinkPriority()
{
return resize.shrinkPrio;
}
/** Sets the shrink priority. Relative priority is used for determining which entities gets smaller first when space is scarce.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param p The new shrink priority.
*/
public void setShrinkPriority(int p)
{
resize.shrinkPrio = p;
}
/** Returns the shrink priority. Relative priority is used for determining which entities gets smaller first when space is scarce.
* Shrink weight is how flexible the entity should be, relative to other entities, when it comes to shrinking. <code>null</code> or
* zero mean it will never shrink (default). An entity that has twice the shrink weight compared to another entity will get twice
* as much of available space.
* <p>
* Shrink(Weight) are only compared within the same ShrinkPrio.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return The current shrink weight.
*/
public Float getShrink()
{
return resize.shrink;
}
/** Sets the shrink priority. Relative priority is used for determining which entities gets smaller first when space is scarce.
* Shrink weight is how flexible the entity should be, relative to other entities, when it comes to shrinking. <code>null</code> or
* zero mean it will never shrink (default). An entity that has twice the shrink weight compared to another entity will get twice
* as much of available space.
* <p>
* Shrink(Weight) are only compared within the same ShrinkPrio.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param weight The new shrink weight.
*/
public void setShrink(Float weight)
{
resize.shrink = weight;
}
public UnitValue getAlignOrDefault(boolean isCols)
{
if (align != null)
return align;
if (isCols)
return UnitValue.LEADING;
return fill || PlatformDefaults.getDefaultRowAlignmentBaseline() == false ? UnitValue.CENTER : UnitValue.BASELINE_IDENTITY;
}
/** Returns the alignment used either as a default value for sub-entities or for this entity.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return The alignment.
*/
public UnitValue getAlign()
{
return align;
}
/** Sets the alignment used wither as a default value for sub-entities or for this entity.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param uv The new shrink priority. E.g. {@link UnitValue#CENTER} or {@link net.miginfocom.layout.UnitValue#LEADING}.
*/
public void setAlign(UnitValue uv)
{
this.align = uv;
}
/** Returns the gap after this entity. The gap is an empty space and can have a min/preferred/maximum size so that it can shrink and
* grow depending on available space. Gaps are against other entities' edges and not against other entities' gaps.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return The gap after this entity
*/
public BoundSize getGapAfter()
{
return gapAfter;
}
/** Sets the gap after this entity. The gap is an empty space and can have a min/preferred/maximum size so that it can shrink and
* grow depending on available space. Gaps are against other entities' edges and not against other entities' gaps.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param size The new gap.
* @see net.miginfocom.layout.ConstraintParser#parseBoundSize(String, boolean, boolean).
*/
public void setGapAfter(BoundSize size)
{
this.gapAfter = size;
}
boolean hasGapAfter()
{
return gapAfter != null && gapAfter.isUnset() == false;
}
boolean isGapAfterPush()
{
return gapAfter != null && gapAfter.getGapPush();
}
/** Returns the gap before this entity. The gap is an empty space and can have a min/preferred/maximum size so that it can shrink and
* grow depending on available space. Gaps are against other entities' edges and not against other entities' gaps.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return The gap before this entity
*/
public BoundSize getGapBefore()
{
return gapBefore;
}
/** Sets the gap before this entity. The gap is an empty space and can have a min/preferred/maximum size so that it can shrink and
* grow depending on available space. Gaps are against other entities' edges and not against other entities' gaps.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param size The new gap.
* @see net.miginfocom.layout.ConstraintParser#parseBoundSize(String, boolean, boolean).
*/
public void setGapBefore(BoundSize size)
{
this.gapBefore = size;
}
boolean hasGapBefore()
{
return gapBefore != null && gapBefore.isUnset() == false;
}
boolean isGapBeforePush()
{
return gapBefore != null && gapBefore.getGapPush();
}
/** Returns the min/preferred/max size for the entity in the dimension that this object describes.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return The current size. Never <code>null</code> since v3.5.
* @see net.miginfocom.layout.ConstraintParser#parseBoundSize(String, boolean, boolean).
*/
public BoundSize getSize()
{
return size;
}
/** Sets the min/preferred/max size for the entity in the dimension that this object describes.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param size The new size. May be <code>null</code>.
*/
public void setSize(BoundSize size)
{
if (size != null)
size.checkNotLinked();
this.size = size;
}
/** Returns the size group that this entity should be in for the dimension that this object is describing.
* If this constraint is in a size group that is specified here. <code>null</code> means no size group
* and all other values are legal. Comparison with .equals(). Components/columnss/rows in the same size group
* will have the same min/preferred/max size; that of the largest in the group for the first two and the
* smallest for max.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return The current size group. May be <code>null</code>.
*/
public String getSizeGroup()
{
return sizeGroup;
}
/** Sets the size group that this entity should be in for the dimension that this object is describing.
* If this constraint is in a size group that is specified here. <code>null</code> means no size group
* and all other values are legal. Comparison with .equals(). Components/columnss/rows in the same size group
* will have the same min/preferred/max size; that of the largest in the group for the first two and the
* smallest for max.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param s The new size group. <code>null</code> disables size grouping.
*/
public void setSizeGroup(String s)
{
sizeGroup = s;
}
// ************** Only applicable on components ! *******************
/** Returns the end group that this entity should be in for the demension that this object is describing.
* If this constraint is in an end group that is specified here. <code>null</code> means no end group
* and all other values are legal. Comparison with .equals(). Components in the same end group
* will have the same end coordinate.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return The current end group. <code>null</code> may be returned.
*/
public String getEndGroup()
{
return endGroup;
}
/** Sets the end group that this entity should be in for the demension that this object is describing.
* If this constraint is in an end group that is specified here. <code>null</code> means no end group
* and all other values are legal. Comparison with .equals(). Components in the same end group
* will have the same end coordinate.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param s The new end group. <code>null</code> disables end grouping.
*/
public void setEndGroup(String s)
{
endGroup = s;
}
// ************** Not applicable on components below ! *******************
/** Returns if the component in the row/column that this constraint should default be grown in the same dimension that
* this constraint represents (width for column and height for a row).
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return code>true</code> means that components should grow.
*/
public boolean isFill()
{
return fill;
}
/** Sets if the component in the row/column that this constraint should default be grown in the same dimension that
* this constraint represents (width for column and height for a row).
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param b <code>true</code> means that components should grow.
*/
public void setFill(boolean b)
{
fill = b;
}
/** Returns if the row/column should default to flow and not to grid behaviour. This means that the whole row/column
* will be one cell and all components will end up in that cell.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @return <code>true</code> means that the whole row/column should be one cell.
*/
public boolean isNoGrid()
{
return noGrid;
}
/** Sets if the row/column should default to flow and not to grid behaviour. This means that the whole row/column
* will be one cell and all components will end up in that cell.
* <p>
* For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
* @param b <code>true</code> means that the whole row/column should be one cell.
*/
public void setNoGrid(boolean b)
{
this.noGrid = b;
}
/** Returns the gaps as pixel values.
* @param parent The parent. Used to get the pixel values.
* @param defGap The default gap to use if there is no gap set on this object (i.e. it is null).
* @param refSize The reference size used to get the pixel sizes.
* @param before IF it is the gap before rather than the gap after to return.
* @return The [min,preferred,max] sizes for the specified gap. Uses {@link net.miginfocom.layout.LayoutUtil#NOT_SET}
* for gap sizes that are <code>null</code>. Returns <code>null</code> if there was no gap specified. A new and free to use array.
*/
int[] getRowGaps(ContainerWrapper parent, BoundSize defGap, int refSize, boolean before)
{
BoundSize gap = before ? gapBefore : gapAfter;
if (gap == null || gap.isUnset())
gap = defGap;
if (gap == null || gap.isUnset())
return null;
int[] ret = new int[3];
for (int i = LayoutUtil.MIN; i <= LayoutUtil.MAX; i++) {
UnitValue uv = gap.getSize(i);
ret[i] = uv != null ? uv.getPixels(refSize, parent, null) : LayoutUtil.NOT_SET;
}
return ret;
}
/** Returns the gaps as pixel values.
* @param parent The parent. Used to get the pixel values.
* @param comp The component that the gap is for. If not for a component it is <code>null</code>.
* @param adjGap The gap that the adjacent component, if any, has towards <code>comp</code>.
* @param adjacentComp The adjacent component if any. May be <code>null</code>.
* @param refSize The reference size used to get the pixel sizes.
* @param adjacentSide What side the <code>adjacentComp</code> is on. 0 = top, 1 = left, 2 = bottom, 3 = right.
* @param tag The tag string that the component might be tagged with in the component constraints. May be <code>null</code>.
* @param isLTR If it is left-to-right.
* @return The [min,preferred,max] sizes for the specified gap. Uses {@link net.miginfocom.layout.LayoutUtil#NOT_SET}
* for gap sizes that are <code>null</code>. Returns <code>null</code> if there was no gap specified. A new and free to use array.
*/
int[] getComponentGaps(ContainerWrapper parent, ComponentWrapper comp, BoundSize adjGap, ComponentWrapper adjacentComp, String tag, int refSize, int adjacentSide, boolean isLTR)
{
BoundSize gap = adjacentSide < 2 ? gapBefore : gapAfter;
boolean hasGap = gap != null && gap.getGapPush();
if ((gap == null || gap.isUnset()) && (adjGap == null || adjGap.isUnset()) && comp != null)
gap = PlatformDefaults.getDefaultComponentGap(comp, adjacentComp, adjacentSide + 1, tag, isLTR);
if (gap == null)
return hasGap ? new int[] {0, 0, LayoutUtil.NOT_SET} : null;
int[] ret = new int[3];
for (int i = LayoutUtil.MIN; i <= LayoutUtil.MAX; i++) {
UnitValue uv = gap.getSize(i);
ret[i] = uv != null ? uv.getPixels(refSize, parent, null) : LayoutUtil.NOT_SET;
}
return ret;
}
// ************************************************
// 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() == DimConstraint.class)
LayoutUtil.writeAsXML(out, this);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,789 +0,0 @@
package net.miginfocom.layout;
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
*/
/** This class contains static methods to be used by IDE vendors to convert to and from String/API constraints.
* <p>
* <b>Note that {@link LayoutUtil#setDesignTime(ContainerWrapper, boolean)} should be set to <code>true</code> for this class'
* methods to work.</b>
*/
public class IDEUtil
{
/** A direct reference to the corresponding value for predefined UnitValues in {@link UnitValue}.
*/
public static final UnitValue ZERO = UnitValue.ZERO;
/** A direct reference to the corresponding value for predefined UnitValues in {@link UnitValue}.
*/
public static final UnitValue TOP = UnitValue.TOP;
/** A direct reference to the corresponding value for predefined UnitValues in {@link UnitValue}.
*/
public static final UnitValue LEADING = UnitValue.LEADING;
/** A direct reference to the corresponding value for predefined UnitValues in {@link UnitValue}.
*/
public static final UnitValue LEFT = UnitValue.LEFT;
/** A direct reference to the corresponding value for predefined UnitValues in {@link UnitValue}.
*/
public static final UnitValue CENTER = UnitValue.CENTER;
/** A direct reference to the corresponding value for predefined UnitValues in {@link UnitValue}.
*/
public static final UnitValue TRAILING = UnitValue.TRAILING;
/** A direct reference to the corresponding value for predefined UnitValues in {@link UnitValue}.
*/
public static final UnitValue RIGHT = UnitValue.RIGHT;
/** A direct reference to the corresponding value for predefined UnitValues in {@link UnitValue}.
*/
public static final UnitValue BOTTOM = UnitValue.BOTTOM;
/** A direct reference to the corresponding value for predefined UnitValues in {@link UnitValue}.
*/
public static final UnitValue LABEL = UnitValue.LABEL;
/** A direct reference to the corresponding value for predefined UnitValues in {@link UnitValue}.
*/
public static final UnitValue INF = UnitValue.INF;
/** A direct reference to the corresponding value for predefined UnitValues in {@link UnitValue}.
*/
public static final UnitValue BASELINE_IDENTITY = UnitValue.BASELINE_IDENTITY;
private final static String[] X_Y_STRINGS = new String[] {"x", "y", "x2", "y2"};
/** Returns the version of IDEUtil
* @return The version.
*/
public String getIDEUtilVersion()
{
return "1.0";
}
/** Returns the grid cells that the components in <code>parentContainer</code> has.
* @param parentContainer The parent container. It is an object since MigLayout is GUI toolkit
* independent.
* @return A new hashmap with the components mapped to an array [x, y, spanx, spany].
* <p>
* Dock components will always have x and y less than -30000 or more than 30000. This is since they
* are actually part of the grid, but on the outer edges.
* <p>
* Components that span the "rest of the row/column" have really large span values. Actually 30000-x or
* 30000-y.
* <p>
* Generally, the grid does not need to have the upper left at 0, 0. Though it normally does if you
* don't set the cells explicitly to other values. Rows and columns that are completely empty and
* that does not have an explicit row/column constraint will be totally disregarded.
*/
public static HashMap<Object, int[]> getGridPositions(Object parentContainer)
{
return Grid.getGridPositions(parentContainer);
}
/** Returns the sizes of the rows and gaps for a container.
* There will be two arrays returned [0] and [1].
* <p>
* The first array will be the indexes of the rows where indexes that
* are less than 30000 or larger than 30000 is docking rows. There might be extra docking rows that aren't
* visible but they always have size 0. Non docking indexes will probably always be 0, 1, 2, 3, etc..
* <p>
* The second array is the sizes of the form:<br>
* <code>[left inset][row size 1][gap 1][row size 2][gap 2][row size n][right inset]</code>.
* <p>
* The returned sizes will be the ones calculated in the last layout cycle.
* @param parentContainer The container to retuern the row sizes and gaps for. In Swing it will be a {@link java.awt.Container} and
* in SWT it will be a {@link org.eclipse.swt.widgets.Composite}.
* @return The sizes or <code>null</code> if {@link LayoutUtil#isDesignTime(ContainerWrapper)} is <code>false</code> or
* <code>parentContainer</code> does not have a MigLayout layout manager.
* The returned sizes will be the ones calculated in the last layout cycle.
* @see LayoutUtil#isDesignTime(ContainerWrapper)
*/
public static int[][] getRowSizes(Object parentContainer)
{
return Grid.getSizesAndIndexes(parentContainer, true);
}
/** Returns the sizes of the columns and gaps for a container.
* There will be two arrays returned [0] and [1].
* <p>
* The first array will be the indexes of the columns where indexes that
* are less than 30000 or larger than 30000 is docking columns. There might be extra docking columns that aren't
* visible but they always have size 0. Non docking indexes will probably always be 0, 1, 2, 3, etc..
* <p>
* The second array is the sizes of the form:<br>
* <code>[top inset][column size 1][gap 1][column size 2][gap 2][column size n][bottom inset]</code>.
* <p>
* The returned sizes will be the ones calculated in the last layout cycle.
* @param parentContainer The container to retuern the column sizes and gaps for. In Swing it will be a {@link java.awt.Container} and
* in SWT it will be a {@link org.eclipse.swt.widgets.Composite}.
* @return The sizes and indexes or <code>null</code> if {@link LayoutUtil#isDesignTime(ContainerWrapper)} is <code>false</code> or
* <code>parentContainer</code> does not have a MigLayout layout manager.
* The returned sizes will be the ones calculated in the last layout cycle.
* @see LayoutUtil#isDesignTime(ContainerWrapper)
*/
public static int[][] getColumnSizes(Object parentContainer)
{
return Grid.getSizesAndIndexes(parentContainer, false);
}
/** Returns the a constraint string that can be re-parsed to be the exact same AxisConstraint.
* @param ac The axis constraint to return as a constraint string.
* @param asAPI If the returned string should be of API type (e.g. .flowX().gap("rel").align("right")) or
* as a String type (e.g. "flowx, gap rel, right").
* @param isCols The the constraint should be returned for columns rather than rows.
* @return A String. Never <code>null</code>.
*/
public static String getConstraintString(AC ac, boolean asAPI, boolean isCols)
{
StringBuffer sb = new StringBuffer(32);
DimConstraint[] dims = ac.getConstaints();
BoundSize defGap = isCols ? PlatformDefaults.getGridGapX() : PlatformDefaults.getGridGapY();
for (int i = 0; i < dims.length; i++) {
DimConstraint dc = dims[i];
addRowDimConstraintString(dc, sb, asAPI);
if (i < dims.length - 1) {
BoundSize gap = dc.getGapAfter();
if (gap == defGap || gap == null)
gap = dims[i + 1].getGapBefore();
if (gap != null) {
String gapStr = getBS(gap);
if (asAPI) {
sb.append(".gap(\"").append(gapStr).append("\")");
} else {
sb.append(gapStr);
}
} else {
if (asAPI)
sb.append(".gap()");
}
}
}
return sb.toString();
}
/** Adds the a constraint string that can be re-parsed to be the exact same DimConstraint.
* @param dc The layout constraint to return as a constraint string.
* @param asAPI If the returned string should be of API type (e.g. .flowX().gap("rel").align("right")) or
* as a String type (e.g. "flowx, gap rel, right").
*/
private static void addRowDimConstraintString(DimConstraint dc, StringBuffer sb, boolean asAPI)
{
int gp = dc.getGrowPriority();
int firstComma = sb.length();
BoundSize size = dc.getSize();
if (size.isUnset() == false) {
if (asAPI) {
sb.append(".size(\"").append(getBS(size)).append("\")");
} else {
sb.append(',').append(getBS(size));
}
}
if (gp != 100) {
if (asAPI) {
sb.append(".growPrio(").append(gp).append("\")");
} else {
sb.append(",growprio ").append(gp);
}
}
Float gw = dc.getGrow();
if (gw != null) {
String g = gw != 100f ? floatToString(gw, asAPI) : "";
if (asAPI) {
if (g.length() == 0) {
sb.append(".grow()");
} else {
sb.append(".grow(\"").append(g).append("\")");
}
} else {
sb.append(",grow").append(g.length() > 0 ? (" " + g) : "");
}
}
int sp = dc.getShrinkPriority();
if (sp != 100) {
if (asAPI) {
sb.append(".shrinkPrio(").append(sp).append("\")");
} else {
sb.append(",shrinkprio ").append(sp);
}
}
Float sw = dc.getShrink();
if (sw != null && sw.intValue() != 100) {
String s = floatToString(sw, asAPI);
if (asAPI) {
sb.append(".shrink(\"").append(s).append("\")");
} else {
sb.append(",shrink ").append(s);
}
}
String eg = dc.getEndGroup();
if (eg != null) {
if (asAPI) {
sb.append(".endGroup(\"").append(eg).append("\")");
} else {
sb.append(",endgroup ").append(eg);
}
}
String sg = dc.getSizeGroup();
if (sg != null) {
if (asAPI) {
sb.append(".sizeGroup(\"").append(sg).append("\")");
} else {
sb.append(",sizegroup ").append(sg);
}
}
UnitValue al = dc.getAlign();
if (al != null) {
if (asAPI) {
sb.append(".align(\"").append(getUV(al)).append("\")");
} else {
String s = getUV(al);
String alKw = (s.equals("top") || s.equals("bottom") || s.equals("left") || s.equals("label") ||
s.equals("leading") || s.equals("center") || s.equals("trailing") ||
s.equals("right") || s.equals("baseline")) ? "" : "align ";
sb.append(',').append(alKw).append(s);
}
}
if (dc.isNoGrid()) {
if (asAPI) {
sb.append(".noGrid()");
} else {
sb.append(",nogrid");
}
}
if (dc.isFill()) {
if (asAPI) {
sb.append(".fill()");
} else {
sb.append(",fill");
}
}
if (asAPI == false) {
if (sb.length() > firstComma) {
sb.setCharAt(firstComma, '[');
sb.append(']');
} else {
sb.append("[]");
}
}
}
/** Returns the a constraint string that can be re-parsed to be the exact same DimConstraint.
* @param dc The layout constraint to return as a constraint string.
* @param asAPI If the returned string should be of API type (e.g. .flowX().gap("rel").align("right")) or
* as a String type (e.g. "flowx, gap rel, right").
* @param isHor The the DimConstraint is decoration something horizontal (column or x).
* @param noGrowAdd If <code>true</code> no grow constraints will be added.
* @return A constraint string. Never <code>null</code>.
*/
private static void addComponentDimConstraintString(DimConstraint dc, StringBuffer sb, boolean asAPI, boolean isHor, boolean noGrowAdd)
{
int gp = dc.getGrowPriority();
if (gp != 100) {
if (asAPI) {
sb.append(isHor ? ".growPrioX(" : ".growPrioY(").append(gp).append(')');
} else {
sb.append(isHor ? ",growpriox " : ",growprioy ").append(gp);
}
}
if (noGrowAdd == false) {
Float gw = dc.getGrow();
if (gw != null) {
String g = gw != 100f ? floatToString(gw, asAPI) : "";
if (asAPI) {
sb.append(isHor ? ".growX(" : ".growY(").append(g).append(')');
} else {
sb.append(isHor ? ",growx" : ",growy").append(g.length() > 0 ? (" " + g) : "");
}
}
}
int sp = dc.getShrinkPriority();
if (sp != 100) {
if (asAPI) {
sb.append(isHor ? ".shrinkPrioX(" : ".shrinkPrioY(").append(sp).append(')');
} else {
sb.append(isHor ? ",shrinkpriox " : ",shrinkprioy ").append(sp);
}
}
Float sw = dc.getShrink();
if (sw != null && sw.intValue() != 100) {
String s = floatToString(sw, asAPI);
if (asAPI) {
sb.append(isHor ? ".shrinkX(" : ".shrinkY(").append(s).append(')');
} else {
sb.append(isHor ? ",shrinkx " : ",shrinky ").append(s);
}
}
String eg = dc.getEndGroup();
if (eg != null) {
if (asAPI) {
sb.append(isHor ? ".endGroupX(\"" : ".endGroupY(\"").append(eg).append("\")");
} else {
sb.append(isHor ? ",endgroupx " : ",endgroupy ").append(eg);
}
}
String sg = dc.getSizeGroup();
if (sg != null) {
if (asAPI) {
sb.append(isHor ? ".sizeGroupX(\"" : ".sizeGroupY(\"").append(sg).append("\")");
} else {
sb.append(isHor ? ",sizegroupx " : ",sizegroupy ").append(sg);
}
}
appendBoundSize(dc.getSize(), sb, isHor, asAPI);
UnitValue al = dc.getAlign();
if (al != null) {
if (asAPI) {
sb.append(isHor ? ".alignX(\"" : ".alignY(\"").append(getUV(al)).append("\")");
} else {
sb.append(isHor ? ",alignx " : ",aligny ").append(getUV(al));
}
}
BoundSize gapBef = dc.getGapBefore();
BoundSize gapAft= dc.getGapAfter();
if (gapBef != null || gapAft != null) {
if (asAPI) {
sb.append(isHor ? ".gapX(\"" : ".gapY(\"").append(getBS(gapBef)).append("\", \"").append(getBS(gapAft)).append("\")");
} else {
sb.append(isHor ? ",gapx " : ",gapy ").append(getBS(gapBef));
if (gapAft != null)
sb.append(' ').append(getBS(gapAft));
}
}
}
private static void appendBoundSize(BoundSize size, StringBuffer sb, boolean isHor, boolean asAPI)
{
if (size.isUnset() == false) {
if (size.getPreferred() == null) {
if (size.getMin() == null) {
if (asAPI) {
sb.append(isHor ? ".maxWidth(\"" : ".maxHeight(\"").append(getUV(size.getMax())).append("\")");
} else {
sb.append(isHor ? ",wmax " : ",hmax ").append(getUV(size.getMax()));
}
} else if (size.getMax() == null) {
if (asAPI) {
sb.append(isHor ? ".minWidth(\"" : ".minHeight(\"").append(getUV(size.getMin())).append("\")");
} else {
sb.append(isHor ? ",wmin " : ",hmin ").append(getUV(size.getMin()));
}
} else { // None are null
if (asAPI) {
sb.append(isHor ? ".width(\"" : ".height(\"").append(getUV(size.getMin())).append("::").append(getUV(size.getMax())).append("\")");
} else {
sb.append(isHor ? ",width " : ",height ").append(getUV(size.getMin())).append("::").append(getUV(size.getMax()));
}
}
} else {
if (asAPI) {
sb.append(isHor ? ".width(\"" : ".height(\"").append(getBS(size)).append("\")");
} else {
sb.append(isHor ? ",width " : ",height ").append(getBS(size));
}
}
}
}
/** Returns the a constraint string that can be re-parsed to be the exact same LayoutConstraint.
* @param cc The component constraint to return as a constraint string.
* @param asAPI If the returned string should be of API type (e.g. .flowX().gap("rel").align("right")) or
* as a String type (e.g. "flowx, gap rel, right").
* @return A String. Never <code>null</code>.
*/
public static String getConstraintString(CC cc, boolean asAPI)
{
StringBuffer sb = new StringBuffer(16);
if (cc.isNewline())
sb.append(asAPI ? ".newline()" : ",newline");
if (cc.isExternal())
sb.append(asAPI ? ".external()" : ",external");
Boolean flowX = cc.getFlowX();
if (flowX != null) {
if (asAPI) {
sb.append(flowX ? ".flowX()" : ".flowY()");
} else {
sb.append(flowX ? ",flowx" : ",flowy");
}
}
UnitValue[] pad = cc.getPadding();
if (pad != null) {
sb.append(asAPI ? ".pad(\"" : ",pad ");
for (int i = 0; i < pad.length; i++)
sb.append(getUV(pad[i])).append(i < pad.length - 1 ? " " : "");
if (asAPI)
sb.append("\")");
}
UnitValue[] pos = cc.getPos();
if (pos != null) {
if (cc.isBoundsInGrid()) {
for (int i = 0; i < 4; i++) {
if (pos[i] != null) {
if (asAPI) {
sb.append('.').append(X_Y_STRINGS[i]).append("(\"").append(getUV(pos[i])).append("\")");
} else {
sb.append(',').append(X_Y_STRINGS[i]).append(getUV(pos[i]));
}
}
}
} else {
sb.append(asAPI ? ".pos(\"" : ",pos ");
int iSz = (pos[2] != null || pos[3] != null) ? 4 : 2; // "pos x y" vs "pos x1 y1 x2 y2".
for (int i = 0; i < iSz; i++)
sb.append(getUV(pos[i])).append(i < iSz - 1 ? " " : "");
if (asAPI)
sb.append("\")");
}
}
String id = cc.getId();
if (id != null) {
if (asAPI) {
sb.append(".id(\"").append(id).append("\")");
} else {
sb.append(",id ").append(id);
}
}
String tag = cc.getTag();
if (tag != null) {
if (asAPI) {
sb.append(".tag(\"").append(tag).append("\")");
} else {
sb.append(",tag ").append(tag);
}
}
int hideMode = cc.getHideMode();
if (hideMode >= 0) {
if (asAPI) {
sb.append(".hidemode(").append(hideMode).append(')');
} else {
sb.append(",hidemode ").append(hideMode);
}
}
int skip = cc.getSkip();
if (skip > 0) {
if (asAPI) {
sb.append(".skip(").append(skip).append(')');
} else {
sb.append(",skip ").append(skip);
}
}
int split = cc.getSplit();
if (split > 1) {
String s = split == LayoutUtil.INF ? "" : String.valueOf(split);
if (asAPI) {
sb.append(".split(").append(s).append(')');
} else {
sb.append(",split ").append(s);
}
}
int cx = cc.getCellX();
int cy = cc.getCellY();
int spanX = cc.getSpanX();
int spanY = cc.getSpanY();
if (cx >= 0 && cy >= 0) {
if (asAPI) {
sb.append(".cell(").append(cx).append(", ").append(cy);
if (spanX > 1 || spanY > 1)
sb.append(", ").append(spanX).append(", ").append(spanY);
sb.append(')');
} else {
sb.append(",cell ").append(cx).append(' ').append(cy);
if (spanX > 1 || spanY > 1)
sb.append(' ').append(spanX).append(' ').append(spanY);
}
} else if (spanX > 1 || spanY > 1) {
if (spanX > 1 && spanY > 1) {
sb.append(asAPI ? ".span(" : ",span ").append(spanX).append(asAPI ? ", " : " ").append(spanY);
} else if (spanX > 1) {
sb.append(asAPI ? ".spanX(" : ",spanx ").append(spanX == LayoutUtil.INF ? "" : (String.valueOf(spanX)));
} else if (spanY > 1) {
sb.append(asAPI ? ".spanY(" : ",spany ").append(spanY == LayoutUtil.INF ? "" : (String.valueOf(spanY)));
}
if (asAPI)
sb.append(')');
}
Float pushX = cc.getPushX();
Float pushY = cc.getPushY();
if (pushX != null || pushY != null) {
if (pushX != null && pushY != null) {
sb.append(asAPI ? ".push(" : ",push ");
if (pushX != 100.0 || pushY != 100.0)
sb.append(pushX).append(asAPI ? ", " : " ").append(pushY);
} else if (pushX != null) {
sb.append(asAPI ? ".pushX(" : ",pushx ").append(pushX == 100 ? "" : (String.valueOf(pushX)));
} else if (pushY != null) {
sb.append(asAPI ? ".pushY(" : ",pushy ").append(pushY == 100 ? "" : (String.valueOf(pushY)));
}
if (asAPI)
sb.append(')');
}
int dock = cc.getDockSide();
if (dock >= 0) {
String ds = CC.DOCK_SIDES[dock];
if (asAPI) {
sb.append(".dock").append(Character.toUpperCase(ds.charAt(0))).append(ds.substring(1)).append("()");
} else {
sb.append(",").append(ds);
}
}
boolean noGrowAdd = cc.getHorizontal().getGrow() != null && cc.getHorizontal().getGrow().intValue() == 100 &&
cc.getVertical().getGrow() != null && cc.getVertical().getGrow().intValue() == 100;
addComponentDimConstraintString(cc.getHorizontal(), sb, asAPI, true, noGrowAdd);
addComponentDimConstraintString(cc.getVertical(), sb, asAPI, false, noGrowAdd);
if (noGrowAdd)
sb.append(asAPI ? ".grow()" : ",grow"); // Combine ".growX().growY()" into ".grow()".
if (cc.isWrap())
sb.append(asAPI ? ".wrap()" : ",wrap");
String s = sb.toString();
return s.length() == 0 || s.charAt(0) != ',' ? s : s.substring(1);
}
/** Returns the a constraint string that can be re-parsed to be the exact same LayoutConstraint.
* @param lc The layout constraint to return as a constraint string.
* @param asAPI If the returned string should be of API type (e.g. .flowX().gap("rel").align("right")) or
* as a String type (e.g. "flowx, gap rel, right").
* @return A String. Never <code>null</code>.
*/
public static String getConstraintString(LC lc, boolean asAPI)
{
StringBuffer sb = new StringBuffer(16);
if (lc.isFlowX() == false)
sb.append(asAPI ? ".flowY()" : ",flowy");
boolean fillX = lc.isFillX();
boolean fillY = lc.isFillY();
if (fillX || fillY) {
if (fillX == fillY) {
sb.append(asAPI ? ".fill()" : ",fill");
} else {
sb.append(asAPI ? (fillX ? ".fillX()" : ".fillY()") : (fillX ? ",fillx" : ",filly"));
}
}
Boolean leftToRight = lc.getLeftToRight();
if (leftToRight != null) {
if (asAPI) {
sb.append(".leftToRight(").append(leftToRight).append(')');
} else {
sb.append(leftToRight ? ",ltr" : ",rtl");
}
}
if (!lc.getPackWidth().isUnset() || !lc.getPackHeight().isUnset()) {
if (asAPI) {
String w = getBS(lc.getPackWidth());
String h = getBS(lc.getPackHeight());
sb.append(".pack(");
if (w.equals("pref") && h.equals("pref")) {
sb.append(')');
} else {
sb.append('\"').append(w).append("\", \"").append(h).append("\")");
}
} else {
sb.append(",pack");
String size = getBS(lc.getPackWidth()) + " " + getBS(lc.getPackHeight());
if (size.equals("pref pref") == false)
sb.append(' ').append(size);
}
}
if (lc.getPackWidthAlign() != 0.5f || lc.getPackHeightAlign() != 1f) {
if (asAPI) {
sb.append(".packAlign(").append(floatToString(lc.getPackWidthAlign(), asAPI)).append(", ").append(floatToString(lc.getPackHeightAlign(), asAPI)).append(')');
} else {
sb.append(",packalign ").append(floatToString(lc.getPackWidthAlign(), asAPI)).append(' ').append(floatToString(lc.getPackHeightAlign(), asAPI));
}
}
if (lc.isTopToBottom() == false)
sb.append(asAPI ? ".bottomToTop()" : ",btt");
UnitValue[] insets = lc.getInsets();
if (insets != null) {
String cs = LayoutUtil.getCCString(insets);
if (cs != null) {
if (asAPI) {
sb.append(".insets(\"").append(cs).append("\")");
} else {
sb.append(",insets ").append(cs);
}
} else {
sb.append(asAPI ? ".insets(\"" : ",insets ");
for (int i = 0; i < insets.length; i++)
sb.append(getUV(insets[i])).append(i < insets.length - 1 ? " " : "");
if (asAPI)
sb.append("\")");
}
}
if (lc.isNoGrid())
sb.append(asAPI ? ".noGrid()" : ",nogrid");
if (lc.isVisualPadding() == false)
sb.append(asAPI ? ".noVisualPadding()" : ",novisualpadding");
int hideMode = lc.getHideMode();
if (hideMode > 0) {
if (asAPI) {
sb.append(".hideMode(").append(hideMode).append(')');
} else {
sb.append(",hideMode ").append(hideMode);
}
}
appendBoundSize(lc.getWidth(), sb, true, asAPI);
appendBoundSize(lc.getHeight(), sb, false, asAPI);
UnitValue alignX = lc.getAlignX();
UnitValue alignY = lc.getAlignY();
if (alignX != null || alignY != null) {
if (alignX != null && alignY != null) {
sb.append(asAPI ? ".align(\"" : ",align ").append(getUV(alignX)).append(' ').append(getUV(alignY));
} else if (alignX != null) {
sb.append(asAPI ? ".alignX(\"" : ",alignx ").append(getUV(alignX));
} else if (alignY != null) {
sb.append(asAPI ? ".alignY(\"" : ",aligny ").append(getUV(alignY));
}
if (asAPI)
sb.append("\")");
}
BoundSize gridGapX = lc.getGridGapX();
BoundSize gridGapY = lc.getGridGapY();
if (gridGapX != null || gridGapY != null) {
if (gridGapX != null && gridGapY != null) {
sb.append(asAPI ? ".gridGap(\"" : ",gap ").append(getBS(gridGapX)).append(' ').append(getBS(gridGapY));
} else if (gridGapX != null) {
sb.append(asAPI ? ".gridGapX(\"" : ",gapx ").append(getBS(gridGapX));
} else if (gridGapY != null) {
sb.append(asAPI ? ".gridGapY(\"" : ",gapy ").append(getBS(gridGapY));
}
if (asAPI)
sb.append("\")");
}
int wrapAfter = lc.getWrapAfter();
if (wrapAfter != LayoutUtil.INF) {
String ws = wrapAfter > 0 ? String.valueOf(wrapAfter) : "";
if (asAPI) {
sb.append(".wrap(").append(ws).append(')');
} else {
sb.append(",wrap ").append(ws);
}
}
int debugMillis = lc.getDebugMillis();
if (debugMillis > 0) {
if (asAPI) {
sb.append(".debug(").append(debugMillis).append(')');
} else {
sb.append(",debug ").append(debugMillis);
}
}
String s = sb.toString();
return s.length() == 0 || s.charAt(0) != ',' ? s : s.substring(1);
}
private static String getUV(UnitValue uv)
{
return uv != null ? uv.getConstraintString() : "null";
}
private static String getBS(BoundSize bs)
{
return bs != null ? bs.getConstraintString() : "null";
}
/** Converts a <code>float</code> to a string and is removing the ".0" if the float is an integer.
* @param f the float.
* @return <code>f</code> as a string. Never <code>null</code>.
*/
private static String floatToString(float f, boolean asAPI)
{
String valS = String.valueOf(f);
return valS.endsWith(".0") ? valS.substring(0, valS.length() - 2) : (valS + (asAPI ? "f" : ""));
}
}

View File

@ -1,65 +0,0 @@
package net.miginfocom.layout;
/*
* License (BSD):
* ==============
*
* Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
* Neither the name of the MiG InfoCom AB nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* @version 1.0
* @author Mikael Grev, MiG InfoCom AB
* Date: 2006-sep-08
*/
/** An interface to implement if you want to decide the gaps between two types of components within the same cell.
* <p>
* E.g.:
*
* <pre>
* if (adjacentComp == null || adjacentSide == SwingConstants.LEFT || adjacentSide == SwingConstants.TOP)
* return null;
*
* boolean isHor = (adjacentSide == SwingConstants.LEFT || adjacentSide == SwingConstants.RIGHT);
*
* if (adjacentComp.getComponentType(false) == ComponentWrapper.TYPE_LABEL && comp.getComponentType(false) == ComponentWrapper.TYPE_TEXT_FIELD)
* return isHor ? UNRELATED_Y : UNRELATED_Y;
*
* return (adjacentSide == SwingConstants.LEFT || adjacentSide == SwingConstants.RIGHT) ? RELATED_X : RELATED_Y;
* </pre
*/
public interface InCellGapProvider
{
/** Returns the default gap between two components that <b>are in the same cell</b>.
* @param comp The component that the gap is for. Never <code>null</code>.
* @param adjacentComp The adjacent component if any. May be <code>null</code>.
* @param adjacentSide What side the <code>adjacentComp</code> 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 <code>null</code>.
* @param isLTR If it is left-to-right.
* @return The default gap between two components or <code>null</code> if there should be no gap.
*/
public abstract BoundSize getDefaultGap(ComponentWrapper comp, ComponentWrapper adjacentComp, int adjacentSide, String tag, boolean isLTR);
}

File diff suppressed because it is too large Load Diff

View File

@ -1,77 +0,0 @@
package net.miginfocom.layout;
/*
* License (BSD):
* ==============
*
* Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
* Neither the name of the MiG InfoCom AB nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* @version 1.0
* @author Mikael Grev, MiG InfoCom AB
* Date: 2006-sep-08
*/
/** A class to extend if you want to provide more control over where a component is placed or the size of it.
* <p>
* Note! Returned arrays from this class will never be altered. This means that caching of arrays in these methods
* is OK.
*/
public abstract class LayoutCallback
{
/** Returns a position similar to the "pos" the component constraint.
* @param comp The component wrapper that holds the actual component (JComponent is Swing and Control in SWT).
* <b>Should not be altered.</b>
* @return The [x, y, x2, y2] as explained in the documentation for "pos". If <code>null</code>
* is returned nothing is done and this is the default.
* @see UnitValue
* @see net.miginfocom.layout.ConstraintParser#parseUnitValue(String, boolean)
*/
public UnitValue[] getPosition(ComponentWrapper comp)
{
return null;
}
/** Returns a size similar to the "width" and "height" in the component constraint.
* @param comp The component wrapper that holds the actual component (JComponent is Swing and Control in SWT).
* <b>Should not be altered.</b>
* @return The [width, height] as explained in the documentation for "width" and "height". If <code>null</code>
* is returned nothing is done and this is the default.
* @see net.miginfocom.layout.BoundSize
* @see net.miginfocom.layout.ConstraintParser#parseBoundSize(String, boolean, boolean)
*/
public BoundSize[] getSize(ComponentWrapper comp)
{
return null;
}
/** A last minute change of the bounds. The bound for the layout cycle has been set and you can correct there
* after any set of rules you like.
* @param comp The component wrapper that holds the actual component (JComponent is Swing and Control in SWT).
*/
public void correctBounds(ComponentWrapper comp)
{
}
}

View File

@ -1,566 +0,0 @@
package net.miginfocom.layout;
import java.beans.*;
import java.io.*;
import java.util.IdentityHashMap;
import java.util.TreeSet;
import java.util.WeakHashMap;
/*
* 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 utility class that has only static helper methods.
*/
public final class LayoutUtil
{
/** A substitute value for aa really large value. Integer.MAX_VALUE is not used since that means a lot of defensive code
* for potential overflow must exist in many places. This value is large enough for being unreasonable yet it is hard to
* overflow.
*/
public static final int INF = (Integer.MAX_VALUE >> 10) - 100; // To reduce likelihood of overflow errors when calculating.
/** Tag int for a value that in considered "not set". Used as "null" element in int arrays.
*/
static final int NOT_SET = Integer.MIN_VALUE + 12346; // Magic value...
// Index for the different sizes
public static final int MIN = 0;
public static final int PREF = 1;
public static final int MAX = 2;
private static volatile WeakHashMap<Object, String> CR_MAP = null;
private static volatile WeakHashMap<Object, Boolean> DT_MAP = null; // The Containers that have design time. Value not used.
private static int eSz = 0;
private static int globalDebugMillis = 0;
public static final boolean HAS_BEANS = hasBeans();
private static boolean hasBeans()
{
try {
LayoutUtil.class.getClassLoader().loadClass("java.beans.Beans");
return true;
} catch (ClassNotFoundException e) {
return false;
}
}
private LayoutUtil()
{
}
/** Returns the current version of MiG Layout.
* @return The current version of MiG Layout. E.g. "3.6.3" or "4.0"
*/
public static String getVersion()
{
return "4.0.1";
}
/** If global debug should be on or off. If &gt; 0 then debug is turned on for all MigLayout
* instances.
* @return The current debug milliseconds.
* @see LC#setDebugMillis(int)
*/
public static int getGlobalDebugMillis()
{
return globalDebugMillis;
}
/** If global debug should be on or off. If &gt; 0 then debug is turned on for all MigLayout
* instances.
* <p>
* Note! This is a passive value and will be read by panels when the needed, which is normally
* when they repaint/layout.
* @param millis The new debug milliseconds. 0 turns of global debug and leaves debug up to every
* individual panel.
* @see LC#setDebugMillis(int)
*/
public static void setGlobalDebugMillis(int millis)
{
globalDebugMillis = millis;
}
/** Sets if design time is turned on for a Container in {@link ContainerWrapper}.
* @param cw The container to set design time for. <code>null</code> is legal and can be used as
* a key to turn on/off design time "in general". Note though that design time "in general" is
* always on as long as there is at least one ContainerWrapper with design time.
* <p>
* <strong>If this method has not ever been called it will default to what
* <code>Beans.isDesignTime()</code> returns.</strong> This means that if you call
* this method you indicate that you will take responsibility for the design time value.
* @param b <code>true</code> means design time on.
*/
public static void setDesignTime(ContainerWrapper cw, boolean b)
{
if (DT_MAP == null)
DT_MAP = new WeakHashMap<Object, Boolean>();
DT_MAP.put((cw != null ? cw.getComponent() : null), b);
}
/** Returns if design time is turned on for a Container in {@link ContainerWrapper}.
* @param cw The container to set design time for. <code>null</code> is legal will return <code>true</code>
* if there is at least one <code>ContainerWrapper</code> (or <code>null</code>) that have design time
* turned on.
* @return If design time is set for <code>cw</code>.
*/
public static boolean isDesignTime(ContainerWrapper cw)
{
if (DT_MAP == null)
return HAS_BEANS && Beans.isDesignTime();
if (cw != null && DT_MAP.containsKey(cw.getComponent()) == false)
cw = null;
Boolean b = DT_MAP.get(cw != null ? cw.getComponent() : null);
return b != null && b;
}
/** The size of an empty row or columns in a grid during design time.
* @return The number of pixels. Default is 15.
*/
public static int getDesignTimeEmptySize()
{
return eSz;
}
/** The size of an empty row or columns in a grid during design time.
* @param pixels The number of pixels. Default is 0 (it was 15 prior to v3.7.2, but since that meant different behaviour
* under design time by default it was changed to be 0, same as non-design time). IDE vendors can still set it to 15 to
* get the old behaviour.
*/
public static void setDesignTimeEmptySize(int pixels)
{
eSz = pixels;
}
/** Associates <code>con</code> with the creation string <code>s</code>. The <code>con</code> object should
* probably have an equals method that compares identities or <code>con</code> objects that .equals() will only
* be able to have <b>one</b> creation string.
* <p>
* If {@link LayoutUtil#isDesignTime(ContainerWrapper)} returns <code>false</code> the method does nothing.
* @param con The object. if <code>null</code> the method does nothing.
* @param s The creation string. if <code>null</code> the method does nothing.
*/
static void putCCString(Object con, String s)
{
if (s != null && con != null && isDesignTime(null)) {
if (CR_MAP == null)
CR_MAP = new WeakHashMap<Object, String>(64);
CR_MAP.put(con, s);
}
}
/** Sets/add the persistence delegates to be used for a class.
* @param c The class to set the registered deligate for.
* @param del The new delegate or <code>null</code> to erase to old one.
*/
static synchronized void setDelegate(Class c, PersistenceDelegate del)
{
try {
Introspector.getBeanInfo(c, Introspector.IGNORE_ALL_BEANINFO).getBeanDescriptor().setValue("persistenceDelegate", del);
} catch (Exception ignored) {
}
}
/** Returns strings set with {@link #putCCString(Object, String)} or <code>null</code> if nothing is associated or
* {@link LayoutUtil#isDesignTime(ContainerWrapper)} returns <code>false</code>.
* @param con The constrain object.
* @return The creation string or <code>null</code> if nothing is registered with the <code>con</code> object.
*/
static String getCCString(Object con)
{
return CR_MAP != null ? CR_MAP.get(con) : null;
}
static void throwCC()
{
throw new IllegalStateException("setStoreConstraintData(true) must be set for strings to be saved.");
}
/** Takes a number on min/preferred/max sizes and resize constraints and returns the calculated sizes which sum should add up to <code>bounds</code>. Whether the sum
* will actually equal <code>bounds</code> is dependent om the pref/max sizes and resize constraints.
* @param sizes [ix],[MIN][PREF][MAX]. Grid.CompWrap.NOT_SET will be treated as N/A or 0. A "[MIN][PREF][MAX]" array with null elements will be interpreted as very flexible (no bounds)
* but if the array itself is null it will not get any size.
* @param resConstr Elements can be <code>null</code> and the whole array can be <code>null</code>. <code>null</code> means that the size will not be flexible at all.
* Can have length less than <code>sizes</code> in which case the last element should be used for the elements missing.
* @param defPushWeights If there is no grow weight for a resConstr the corresponding value of this array is used.
* These forced resConstr will be grown last though and only if needed to fill to the bounds.
* @param startSizeType The initial size to use. E.g. {@link net.miginfocom.layout.LayoutUtil#MIN}.
* @param bounds To use for relative sizes.
* @return The sizes. Array length will match <code>sizes</code>.
*/
static int[] calculateSerial(int[][] sizes, ResizeConstraint[] resConstr, Float[] defPushWeights, int startSizeType, int bounds)
{
float[] lengths = new float[sizes.length]; // heights/widths that are set
float usedLength = 0.0f;
// Give all preferred size to start with
for (int i = 0; i < sizes.length; i++) {
if (sizes[i] != null) {
float len = sizes[i][startSizeType] != NOT_SET ? sizes[i][startSizeType] : 0;
int newSizeBounded = getBrokenBoundary(len, sizes[i][MIN], sizes[i][MAX]);
if (newSizeBounded != NOT_SET)
len = newSizeBounded;
usedLength += len;
lengths[i] = len;
}
}
int useLengthI = Math.round(usedLength);
if (useLengthI != bounds && resConstr != null) {
boolean isGrow = useLengthI < bounds;
// Create a Set with the available priorities
TreeSet<Integer> prioList = new TreeSet<Integer>();
for (int i = 0; i < sizes.length; i++) {
ResizeConstraint resC = (ResizeConstraint) getIndexSafe(resConstr, i);
if (resC != null)
prioList.add(isGrow ? resC.growPrio : resC.shrinkPrio);
}
Integer[] prioIntegers = prioList.toArray(new Integer[prioList.size()]);
for (int force = 0; force <= ((isGrow && defPushWeights != null) ? 1 : 0); force++) { // Run twice if defGrow and the need for growing.
for (int pr = prioIntegers.length - 1; pr >= 0; pr--) {
int curPrio = prioIntegers[pr];
float totWeight = 0f;
Float[] resizeWeight = new Float[sizes.length];
for (int i = 0; i < sizes.length; i++) {
if (sizes[i] == null) // if no min/pref/max size at all do not grow or shrink.
continue;
ResizeConstraint resC = (ResizeConstraint) getIndexSafe(resConstr, i);
if (resC != null) {
int prio = isGrow ? resC.growPrio : resC.shrinkPrio;
if (curPrio == prio) {
if (isGrow) {
resizeWeight[i] = (force == 0 || resC.grow != null) ? resC.grow : (defPushWeights[i < defPushWeights.length ? i : defPushWeights.length - 1]);
} else {
resizeWeight[i] = resC.shrink;
}
if (resizeWeight[i] != null)
totWeight += resizeWeight[i];
}
}
}
if (totWeight > 0f) {
boolean hit;
do {
float toChange = bounds - usedLength;
hit = false;
float changedWeight = 0f;
for (int i = 0; i < sizes.length && totWeight > 0.0001f; i++) {
Float weight = resizeWeight[i];
if (weight != null) {
float sizeDelta = toChange * weight / totWeight;
float newSize = lengths[i] + sizeDelta;
if (sizes[i] != null) {
int newSizeBounded = getBrokenBoundary(newSize, sizes[i][MIN], sizes[i][MAX]);
if (newSizeBounded != NOT_SET) {
resizeWeight[i] = null;
hit = true;
changedWeight += weight;
newSize = newSizeBounded;
sizeDelta = newSize - lengths[i];
}
}
lengths[i] = newSize;
usedLength += sizeDelta;
}
}
totWeight -= changedWeight;
} while (hit);
}
}
}
}
return roundSizes(lengths);
}
static Object getIndexSafe(Object[] arr, int ix)
{
return arr != null ? arr[ix < arr.length ? ix : arr.length - 1] : null;
}
/** Returns the broken boundary if <code>sz</code> is outside the boundaries <code>lower</code> or <code>upper</code>. If both boundaries
* are broken, the lower one is returned. If <code>sz</code> is &lt; 0 then <code>new Float(0f)</code> is returned so that no sizes can be
* negative.
* @param sz The size to check
* @param lower The lower boundary (or <code>null</code> fo no boundary).
* @param upper The upper boundary (or <code>null</code> fo no boundary).
* @return The broken boundary.
*/
private static int getBrokenBoundary(float sz, int lower, int upper)
{
if (lower != NOT_SET) {
if (sz < lower)
return lower;
} else if (sz < 0f) {
return 0;
}
if (upper != NOT_SET && sz > upper)
return upper;
return NOT_SET;
}
static int sum(int[] terms, int start, int len)
{
int s = 0;
for (int i = start, iSz = start + len; i < iSz; i++)
s += terms[i];
return s;
}
static int sum(int[] terms)
{
return sum(terms, 0, terms.length);
}
public static int getSizeSafe(int[] sizes, int sizeType)
{
if (sizes == null || sizes[sizeType] == NOT_SET)
return sizeType == MAX ? LayoutUtil.INF : 0;
return sizes[sizeType];
}
static BoundSize derive(BoundSize bs, UnitValue min, UnitValue pref, UnitValue max)
{
if (bs == null || bs.isUnset())
return new BoundSize(min, pref, max, null);
return new BoundSize(
min != null ? min : bs.getMin(),
pref != null ? pref : bs.getPreferred(),
max != null ? max : bs.getMax(),
bs.getGapPush(),
null);
}
/** Returns if left-to-right orientation is used. If not set explicitly in the layout constraints the Locale
* of the <code>parent</code> is used.
* @param lc The constraint if there is one. Can be <code>null</code>.
* @param container The parent that may be used to get the left-to-right if ffc does not specify this.
* @return If left-to-right orientation is currently used.
*/
public static boolean isLeftToRight(LC lc, ContainerWrapper container)
{
if (lc != null && lc.getLeftToRight() != null)
return lc.getLeftToRight();
return container == null || container.isLeftToRight();
}
/** Round a number of float sizes into int sizes so that the total length match up
* @param sizes The sizes to round
* @return An array of equal length as <code>sizes</code>.
*/
static int[] roundSizes(float[] sizes)
{
int[] retInts = new int[sizes.length];
float posD = 0;
for (int i = 0; i < retInts.length; i++) {
int posI = (int) (posD + 0.5f);
posD += sizes[i];
retInts[i] = (int) (posD + 0.5f) - posI;
}
return retInts;
}
/** Safe equals. null == null, but null never equals anything else.
* @param o1 The first object. May be <code>null</code>.
* @param o2 The second object. May be <code>null</code>.
* @return Returns <code>true</code> if <code>o1</code> and <code>o2</code> are equal (using .equals()) or both are <code>null</code>.
*/
static boolean equals(Object o1, Object o2)
{
return o1 == o2 || (o1 != null && o2 != null && o1.equals(o2));
}
// static int getBaselineCorrect(Component comp)
// {
// Dimension pSize = comp.getPreferredSize();
// int baseline = comp.getBaseline(pSize.width, pSize.height);
// int nextBaseline = comp.getBaseline(pSize.width, pSize.height + 1);
//
// // Amount to add to height when calculating where baseline
// // lands for a particular height:
// int padding = 0;
//
// // Where the baseline is relative to the mid point
// int baselineOffset = baseline - pSize.height / 2;
// if (pSize.height % 2 == 0 && baseline != nextBaseline) {
// padding = 1;
// } else if (pSize.height % 2 == 1 && baseline == nextBaseline) {
// baselineOffset--;
// padding = 1;
// }
//
// // The following calculates where the baseline lands for
// // the height z:
// return (pSize.height + padding) / 2 + baselineOffset;
// }
/** Returns the inset for the side.
* @param side top == 0, left == 1, bottom = 2, right = 3.
* @param getDefault If <code>true</code> the default insets will get retrieved if <code>lc</code> has none set.
* @return The inset for the side. Never <code>null</code>.
*/
static UnitValue getInsets(LC lc, int side, boolean getDefault)
{
UnitValue[] i = lc.getInsets();
return (i != null && i[side] != null) ? i[side] : (getDefault ? PlatformDefaults.getPanelInsets(side) : UnitValue.ZERO);
}
/** Writes the objet and CLOSES the stream. Uses the persistence delegate registered in this class.
* @param os The stream to write to. Will be closed.
* @param o The object to be serialized.
* @param listener The listener to recieve the exeptions if there are any. If <code>null</code> not used.
*/
static void writeXMLObject(OutputStream os, Object o, ExceptionListener listener)
{
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(LayoutUtil.class.getClassLoader());
XMLEncoder encoder = new XMLEncoder(os);
if (listener != null)
encoder.setExceptionListener(listener);
encoder.writeObject(o);
encoder.close(); // Must be closed to write.
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
private static ByteArrayOutputStream writeOutputStream = null;
/** Writes an object to XML.
* @param out The boject out to write to. Will not be closed.
* @param o The object to write.
*/
public static synchronized void writeAsXML(ObjectOutput out, Object o) throws IOException
{
if (writeOutputStream == null)
writeOutputStream = new ByteArrayOutputStream(16384);
writeOutputStream.reset();
writeXMLObject(writeOutputStream, o, new ExceptionListener() {
public void exceptionThrown(Exception e) {
e.printStackTrace();
}});
byte[] buf = writeOutputStream.toByteArray();
out.writeInt(buf.length);
out.write(buf);
}
private static byte[] readBuf = null;
/** Reads an object from <code>in</code> using the
* @param in The object input to read from.
* @return The object. Never <code>null</code>.
* @throws IOException If there was a problem saving as XML
*/
public static synchronized Object readAsXML(ObjectInput in) throws IOException
{
if (readBuf == null)
readBuf = new byte[16384];
Thread cThread = Thread.currentThread();
ClassLoader oldCL = null;
try {
oldCL = cThread.getContextClassLoader();
cThread.setContextClassLoader(LayoutUtil.class.getClassLoader());
} catch(SecurityException ignored) {
}
Object o = null;
try {
int length = in.readInt();
if (length > readBuf.length)
readBuf = new byte[length];
in.readFully(readBuf, 0, length);
o = new XMLDecoder(new ByteArrayInputStream(readBuf, 0, length)).readObject();
} catch(EOFException ignored) {
}
if (oldCL != null)
cThread.setContextClassLoader(oldCL);
return o;
}
private static final IdentityHashMap<Object, Object> SER_MAP = new IdentityHashMap<Object, Object>(2);
/** Sets the serialized object and associates it with <code>caller</code>.
* @param caller The object created <code>o</code>
* @param o The just serialized object.
*/
public static void setSerializedObject(Object caller, Object o)
{
synchronized(SER_MAP) {
SER_MAP.put(caller, o);
}
}
/** Returns the serialized object that are associated with <code>caller</code>. It also removes it from the list.
* @param caller The original creator of the object.
* @return The object.
*/
public static Object getSerializedObject(Object caller)
{
synchronized(SER_MAP) {
return SER_MAP.remove(caller);
}
}
}

View File

@ -1,200 +0,0 @@
package 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<WeakReference<Object>> LAYOUTS = new ArrayList<WeakReference<Object>>(4);
private static final ArrayList<HashMap<String, int[]>> VALUES = new ArrayList<HashMap<String, int[]>>(4);
private static final ArrayList<HashMap<String, int[]>> VALUES_TEMP = new ArrayList<HashMap<String, int[]>>(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 = rect[type];
} else {
rect = VALUES.get(i).get(key);
ret = (rect != null && rect[type] != LayoutUtil.NOT_SET) ? 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<String, int[]> 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<Object>(layout));
int[] bounds = new int[] {x, y, width, height, x + width, y + height};
HashMap<String, int[]> values = new HashMap<String, int[]>(4);
if (temporary)
values.put(key, bounds);
VALUES_TEMP.add(values);
values = new HashMap<String, int[]>(4);
if (temporary == false)
values.put(key, bounds);
VALUES.add(values);
return true;
}
/** This method clear any weak references right away instead of waiting for the GC. This might be advantageous
* if lots of layout are created and disposed of quickly to keep memory consumption down.
* @since 3.7.4
*/
public synchronized static void clearWeakReferencesNow()
{
LAYOUTS.clear();
}
public synchronized static boolean clearBounds(Object layout, String key)
{
for (int i = LAYOUTS.size() - 1; i >= 0; i--) {
Object l = LAYOUTS.get(i).get();
if (l == layout)
return VALUES.get(i).remove(key) != null;
}
return false;
}
synchronized static void clearTemporaryBounds(Object layout)
{
for (int i = LAYOUTS.size() - 1; i >= 0; i--) {
Object l = LAYOUTS.get(i).get();
if (l == layout) {
VALUES_TEMP.get(i).clear();
return;
}
}
}
}

View File

@ -1,772 +0,0 @@
package 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<String, UnitValue> HOR_DEFS = new HashMap<String, UnitValue>(32);
private static final HashMap<String, UnitValue> VER_DEFS = new HashMap<String, UnitValue>(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.
* <p>
* 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. <code>PlatformDefaults.WINDOWS_XP</code>,
* <code>PlatformDefaults.MAC_OSX</code>, or
* <code>PlatformDefaults.GNOME</code>.
*/
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 : 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 <code>PlatformDefaults.WINDOWS</code> or <code>PlatformDefaults.MAC_OSX</code>
*/
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.
* <p>
* 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 : 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 <code>null</code> 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 <code>null</code> 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 <code>null</code> 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 <code>null</code> 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 <code>null</code> 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 <code>null</code> 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 <code>null</code> 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 <code>null</code> 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_SCALE_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_SCALE_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 <code>null</code> the current value will not change.
* @param y The value that will be transformed to pixels. If <code>null</code> 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 <code>null</code> the current value will not change.
* @param y The value that will be transformed to pixels. If <code>null</code> 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 <code>null</code> the current value will not change.
* @param y The value that will be transformed to pixels. If <code>null</code> 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 <code>null</code> the current value will not change.
* @param y The value that will be transformed to pixels. If <code>null</code> 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 <code>null</code> the current value will not change.
* @param y The value that will be transformed to pixels. If <code>null</code> 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. <code>null</code> 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. <code>null</code> 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 <code>null</code>.
* @param x The value for the horizontal dimension. If <code>null</code> the value is not changed.
* @param y The value for the vertical dimension. Might be same object as for <code>x</code>. If <code>null</code> the value is not changed.
*/
public static final void setUnitValue(String[] unitStrings, UnitValue x, UnitValue y)
{
for (String unitString : unitStrings) {
String s = unitString.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 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 String getButtonOrder()
{
return BUTTON_FORMAT;
}
/** Sets the order for the typical buttons in a standard button bar. It is one letter per button type.
* <p>
* 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.
* <p>
* 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.
* <p>
* If gaps are explicitly set on buttons they will never be reduced, but they may be increased.
* <p>
* These are the characters that can be used:
* <ul>
* <li><code>'L'</code> - Buttons with this style tag will staticall end up on the left end of the bar.
* <li><code>'R'</code> - Buttons with this style tag will staticall end up on the right end of the bar.
* <li><code>'H'</code> - A tag for the "help" button that normally is supposed to be on the right.
* <li><code>'E'</code> - A tag for the "help2" button that normally is supposed to be on the left.
* <li><code>'Y'</code> - A tag for the "yes" button.
* <li><code>'N'</code> - A tag for the "no" button.
* <li><code>'X'</code> - A tag for the "next >" or "forward >" button.
* <li><code>'B'</code> - A tag for the "< back>" or "< previous" button.
* <li><code>'I'</code> - A tag for the "finish".
* <li><code>'A'</code> - A tag for the "apply" button.
* <li><code>'C'</code> - A tag for the "cancel" or "close" button.
* <li><code>'O'</code> - A tag for the "ok" or "done" button.
* <li><code>'U'</code> - All Uncategorized, Other, or "Unknown" buttons. Tag will be "other".
* <li><code>'+'</code> - A glue push gap that will take as much space as it can and at least an "unrelated" gap. (Platform dependant)
* <li><code>'_'</code> - (underscore) An "unrelated" gap. (Platform dependant)
* </ul>
* <p>
* Even though the style tags are normally applied to buttons this works with all components.
* <p>
* The normal style for MAC OS X is <code>"L_HE+U+FBI_NYCOA_R"</code>,
* for Windows is <code>"L_E+U+FBI_YNOCAH_R"</code>, and for GNOME is
* <code>"L_HE+UNYACBXIO_R"</code>.
*
* @param order The new button order for the current platform.
*/
public static 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 <code>null</code> if the char is unrecognized.
*/
static 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 <code>null</code>.
*/
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 <code>null</code>.
* @param left The left inset. May be <code>null</code>.
* @param bottom The bottom inset. May be <code>null</code>.
* @param right The right inset. May be <code>null</code>.
*/
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 <code>null</code>.
*/
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 <code>null</code>.
* @param left The left inset. May be <code>null</code>.
* @param bottom The bottom inset. May be <code>null</code>.
* @param right The right inset. May be <code>null</code>.
*/
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 <b>are in the same cell</b>.
* @param comp The component that the gap is for. Never <code>null</code>.
* @param adjacentComp The adjacent component if any. May be <code>null</code>.
* @param adjacentSide What side the <code>adjacentComp</code> 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 <code>null</code>.
* @param isLTR If it is left-to-right.
* @return The default gap between two components or <code>null</code> 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 <code>null</code> if none is set and "related" should always be used.
* @return The current gap provider or <code>null</code> if none is set and "related" should always be used.
*/
public static InCellGapProvider getGapProvider()
{
return GAP_PROVIDER;
}
/** Sets the current gap provider or <code>null</code> if none is set and "related" should always be used.
* @param provider The current gap provider or <code>null</code> 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 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 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 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 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 <code>false</code> but now it is
* <code>true</code>.
* @return The current value. Default is <code>true</code>.
* @since 3.5
*/
public static boolean getDefaultRowAlignmentBaseline()
{
return dra;
}
/** The default alignment for rows. Pre v3.5 this was <code>false</code> but now it is
* <code>true</code>.
* @param b The new value. Default is <code>true</code> from v3.5.
* @since 3.5
*/
public static void setDefaultRowAlignmentBaseline(boolean b)
{
dra = b;
}
}

View File

@ -1,92 +0,0 @@
package 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
*/
/** A parsed constraint that specifies how an entity (normally column/row or component) can shrink or
* grow compared to other entities.
*/
final class ResizeConstraint
{
static final Float WEIGHT_100 = new Float(100);
/** How flexilble the entity should be, relative to other entities, when it comes to growing. <code>null</code> or
* zero mean it will never grow. An entity that has twise the growWeight compared to another entity will get twice
* as much of available space.
* <p>
* "grow" are only compared within the same "growPrio".
*/
Float grow = null;
/** The relative priority used for determining which entities gets the extra space first.
*/
int growPrio = 100;
Float shrink = WEIGHT_100;
int shrinkPrio = 100;
public ResizeConstraint() // For Externalizable
{
}
ResizeConstraint(int shrinkPrio, Float shrinkWeight, int growPrio, Float growWeight)
{
this.shrinkPrio = shrinkPrio;
this.shrink = shrinkWeight;
this.growPrio = growPrio;
this.grow = growWeight;
}
// ************************************************
// 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() == ResizeConstraint.class)
LayoutUtil.writeAsXML(out, this);
}
}

View File

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

View File

@ -1,615 +0,0 @@
package net.miginfocom.layout;
/*
* License (BSD):
* ==============
*
* Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
* Neither the name of the MiG InfoCom AB nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* @version 1.0
* @author Mikael Grev, MiG InfoCom AB
* Date: 2006-sep-08
*/
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<String, Integer> UNIT_MAP = new HashMap<String, Integer>(32);
private static final ArrayList<UnitConverter> CONVERTERS = new ArrayList<UnitConverter>();
/** 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", PIXEL);
UNIT_MAP.put("lpx", LPX);
UNIT_MAP.put("lpy", LPY);
UNIT_MAP.put("%", PERCENT);
UNIT_MAP.put("cm", CM);
UNIT_MAP.put("in", INCH);
UNIT_MAP.put("spx", SPX);
UNIT_MAP.put("spy", SPY);
UNIT_MAP.put("al", ALIGN);
UNIT_MAP.put("mm", MM);
UNIT_MAP.put("pt", PT);
UNIT_MAP.put("min", MIN_SIZE);
UNIT_MAP.put("minimum", MIN_SIZE);
UNIT_MAP.put("p", PREF_SIZE);
UNIT_MAP.put("pref", PREF_SIZE);
UNIT_MAP.put("max", MAX_SIZE);
UNIT_MAP.put("maximum", MAX_SIZE);
UNIT_MAP.put("button", BUTTON);
UNIT_MAP.put("label", 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 <code>null</code> for testing the validity of the value, but should normally not and are not
* required to return any usable value if <code>null</code>.
* @param comp The component, if any, that the value is for. Might be <code>null</code> 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 <code>null</code> for testing the validity of the value, but should normally not and are not
* required to return any usable value if <code>null</code>.
* @param comp The component, if any, that the value is for. Might be <code>null</code> if the value is not
* connected to any component.
* @return The size in pixels.
*/
@SuppressWarnings("fallthrough")
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;
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;
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;
if (unit == LINK_YPOS)
return parent.getScreenLocationY() + v;
return v;
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;
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 (UnitValue subUnit : subUnits) {
if (subUnit.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 <code>true</code> for the creation strings to be stored.
* @return The constraint string or <code>null</code> 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 <code>unit</code> to pixels.
* <p>
* 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 <code>null</code>.
*/
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 <code>null</code>.
*/
public synchronized static UnitConverter[] getGlobalUnitConverters()
{
return CONVERTERS.toArray(new UnitConverter[CONVERTERS.size()]);
}
static {
if(LayoutUtil.HAS_BEANS){
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));
}
}

View File

@ -1,722 +0,0 @@
package 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.
* <p>
* Read the documentation that came with this layout manager for information on usage.
*/
public final class MigLayout implements LayoutManager2
{
// ******** Instance part ********
/** The component to string constraints mappings.
*/
private final Map<Component, Object> scrConstrMap = new IdentityHashMap<Component, Object>(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<ComponentWrapper, CC> ccMap = new HashMap<ComponentWrapper, CC>(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<LayoutCallback> callbackList = null;
private transient boolean dirty = true;
/** Constructor with no constraints.
*/
public MigLayout()
{
this("", "", "");
}
/** Constructor.
* @param layoutConstraints The constraints that concern the whole layout. <code>null</code> will be treated as "".
*/
public MigLayout(String layoutConstraints)
{
this(layoutConstraints, "", "");
}
/** Constructor.
* @param layoutConstraints The constraints that concern the whole layout. <code>null</code> will be treated as "".
* @param colConstraints The constraints for the columns in the grid. <code>null</code> will be treated as "".
*/
public MigLayout(String layoutConstraints, String colConstraints)
{
this(layoutConstraints, colConstraints, "");
}
/** Constructor.
* @param layoutConstraints The constraints that concern the whole layout. <code>null</code> will be treated as "".
* @param colConstraints The constraints for the columns in the grid. <code>null</code> will be treated as "".
* @param rowConstraints The constraints for the rows in the grid. <code>null</code> 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. <code>null</code> 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. <code>null</code> will be treated as an empty constraint.
* @param colConstraints The constraints for the columns in the grid. <code>null</code> 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. <code>null</code> will be treated as an empty constraint.
* @param colConstraints The constraints for the columns in the grid. <code>null</code> will be treated as an empty constraint.
* @param rowConstraints The constraints for the rows in the grid. <code>null</code> 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 <code>String</code> 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 <code>String</code> or {@link net.miginfocom.layout.LC} depending what was sent in
* to the constructor or set with {@link #setLayoutConstraints(Object)}. Never <code>null</code>.
*/
public Object getLayoutConstraints()
{
return layoutConstraints;
}
/** Sets the layout constraints for the layout manager instance as a String.
* <p>
* See the class JavaDocs for information on how this string is formatted.
* @param constr The layout constraints as a String representation. <code>null</code> is converted to <code>""</code> 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 <code>String</code> or {@link net.miginfocom.layout.AC}.
* @return The column constraints either as a <code>String</code> or {@link net.miginfocom.layout.LC} depending what was sent in
* to the constructor or set with {@link #setLayoutConstraints(Object)}. Never <code>null</code>.
*/
public Object getColumnConstraints()
{
return colConstraints;
}
/** Sets the column layout constraints for the layout manager instance as a String.
* <p>
* See the class JavaDocs for information on how this string is formatted.
* @param constr The column layout constraints as a String representation. <code>null</code> is converted to <code>""</code> 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.
* <p>
* See the class JavaDocs for information on how this string is formatted.
* @return The row layout constraints as a String representation. Never <code>null</code>.
*/
public Object getRowConstraints()
{
return rowConstraints;
}
/** Sets the row layout constraints for the layout manager instance as a String.
* <p>
* See the class JavaDocs for information on how this string is formatted.
* @param constr The row layout constraints as a String representation. <code>null</code> is converted to <code>""</code> 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 <code>null</code>.
*/
public Map<Component, Object> getConstraintMap()
{
return new IdentityHashMap<Component, Object>(scrConstrMap);
}
/** Sets the constraints map.
* @param map The map. Will be copied.
*/
public void setConstraintMap(Map<Component, Object> map)
{
scrConstrMap.clear();
ccMap.clear();
for (Map.Entry<Component, Object> 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.
* <p>
* 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 <code>null</code> 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 <code>null</code>.
*/
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.
* <p>
* 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}. <code>null</code> 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.
* <p>
* 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}. <code>null</code> 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 <code>null</code> then <code>false</code> 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 <code>null</code>.
*/
public void addLayoutCallback(LayoutCallback callback)
{
if (callback == null)
throw new NullPointerException();
if (callbackList == null)
callbackList = new ArrayList<LayoutCallback>(1);
callbackList.add(callback);
}
/** Removes the callback if it exists.
* @param callback The callback. May be <code>null</code>.
*/
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.
* <p>
* Red fill and dashed red outline is used to indicate occupied cells in the grid. Blue dashed outline indicate
* component bounds set.
* <p>
* 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 <code>true</code> 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;
cleanConstraintMaps(parent);
// 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 (ComponentWrapper wrapper : ccMap.keySet()) {
Object component = wrapper.getComponent();
if (component instanceof JTextArea || component instanceof JEditorPane)
resetLastInvalidOnParent = true;
hash ^= wrapper.getLayoutHashCode();
hash += 285134905;
}
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;
}
/** Checks so all components in ccMap actually exist in the parent's collection. Removes
* any references that don't.
* @param parent The parent to compare ccMap against. Never null.
*/
private void cleanConstraintMaps(Container parent)
{
HashSet<Component> parentCompSet = new HashSet<Component>(Arrays.asList(parent.getComponents()));
Iterator<Map.Entry<ComponentWrapper, CC>> it = ccMap.entrySet().iterator();
while(it.hasNext()) {
Component c = (Component) it.next().getKey().getComponent();
if (parentCompSet.contains(c) == false) {
it.remove();
scrConstrMap.remove(c);
}
}
}
/**
* @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;
}
}
}

View File

@ -1,459 +0,0 @@
package 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[] {
width < 0 ? c.getWidth() : width,
height < 0 ? c.getHeight() : height
};
return (Integer) BL_METHOD.invoke(c, args);
} catch (Exception e) {
return -1;
}
}
public final Object getComponent()
{
return c;
}
/** Cache.
*/
private final static IdentityHashMap<FontMetrics, Point.Float> FM_MAP = new IdentityHashMap<FontMetrics, Point.Float>(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;
return (isHor ? getHorizontalScreenDPI() : getVerticalScreenDPI()) / (float) PlatformDefaults.getDefaultDPI();
default:
return 1f;
}
}
// /** Cache.
// */
// private final static IdentityHashMap<FontMetrics, Point.Float> FM_MAP2 = new IdentityHashMap<FontMetrics, Point.Float>(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);
} 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 = getBaseline(d.width, d.height) > -1;
}
} catch (Throwable ex) {
bl = Boolean.FALSE;
}
}
return bl;
}
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 hash = d.width + (d.height << 5);
d = c.getPreferredSize();
hash += (d.width << 10) + (d.height << 15);
d = c.getMinimumSize();
hash += (d.width << 20) + (d.height << 25);
if (c.isVisible())
hash += 1324511;
String id = getLinkId();
if (id != null)
hash += id.hashCode();
return hash;
}
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
}
}
}

View File

@ -1,109 +0,0 @@
package 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()
{
long n = System.nanoTime();
int h = super.getLayoutHashCode();
if (isLeftToRight())
h += 416343;
return 0;
}
}