本文整理汇总了Java中javax.swing.SizeRequirements类的典型用法代码示例。如果您正苦于以下问题:Java SizeRequirements类的具体用法?Java SizeRequirements怎么用?Java SizeRequirements使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SizeRequirements类属于javax.swing包,在下文中一共展示了SizeRequirements类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: spanSetFromAttributes
import javax.swing.SizeRequirements; //导入依赖的package包/类
/**
* Adjust the given requirements to the CSS width or height if
* it is specified along the applicable axis. Return true if the
* size is exactly specified, false if the span is not specified
* in an attribute or the size specified is a percentage.
*/
static boolean spanSetFromAttributes(int axis, SizeRequirements r,
CSS.LengthValue cssWidth,
CSS.LengthValue cssHeight) {
if (axis == X_AXIS) {
if ((cssWidth != null) && (! cssWidth.isPercentage())) {
r.minimum = r.preferred = r.maximum = (int) cssWidth.getValue();
return true;
}
} else {
if ((cssHeight != null) && (! cssHeight.isPercentage())) {
r.minimum = r.preferred = r.maximum = (int) cssHeight.getValue();
return true;
}
}
return false;
}
示例2: BoxView
import javax.swing.SizeRequirements; //导入依赖的package包/类
/**
* Creates a new <code>BoxView</code> for the given
* <code>Element</code> and axis. Valid values for the axis are
* {@link View#X_AXIS} and {@link View#Y_AXIS}.
*
* @param element the element that is rendered by this BoxView
* @param axis the axis along which the box is laid out
*/
public BoxView(Element element, int axis)
{
super(element);
myAxis = axis;
layoutValid[0] = false;
layoutValid[1] = false;
requirementsValid[X_AXIS] = false;
requirementsValid[Y_AXIS] = false;
span[0] = 0;
span[1] = 0;
requirements[0] = new SizeRequirements();
requirements[1] = new SizeRequirements();
// Initialize the cache arrays.
spans[0] = new int[0];
spans[1] = new int[0];
offsets[0] = new int[0];
offsets[1] = new int[0];
}
示例3: replace
import javax.swing.SizeRequirements; //导入依赖的package包/类
/**
* Replaces some child views with a new set of child views. This is
* implemented to call the superclass behaviour and invalidates the row
* grid so that rows and columns will be recalculated.
*
* @param offset the start offset at which to replace views
* @param length the number of views to remove
* @param views the new set of views
*/
public void replace(int offset, int length, View[] views)
{
super.replace(offset, length, views);
int viewCount = getViewCount();
if (columnRequirements == null
|| viewCount > columnRequirements.length)
{
columnRequirements = new SizeRequirements[viewCount];
for (int i = 0; i < columnRequirements.length; i++)
columnRequirements[i] = new SizeRequirements();
}
if (columnOffsets == null || columnOffsets.length < viewCount)
columnOffsets = new int[viewCount];
if (columnSpans == null || columnSpans.length < viewCount)
columnSpans = new int[viewCount];
layoutChanged(X_AXIS);
}
示例4: updateColumnRequirements
import javax.swing.SizeRequirements; //导入依赖的package包/类
/**
* Updates the column requirements.
*/
private void updateColumnRequirements()
{
int rowCount = getViewCount();
for (int r = 0; r < rowCount; ++r)
{
TableRow row = (TableRow) getView(r);
int columnCount = row.getViewCount();
for (int c = 0; c < columnCount; ++c)
{
View cell = row.getView(c);
SizeRequirements cr = columnRequirements[c];
cr.minimum = Math.max(cr.minimum, (int) cell.getMinimumSpan(X_AXIS));
cr.preferred = Math.max(cr.preferred,
(int) cell.getPreferredSpan(X_AXIS));
cr.maximum = Math.max(cr.maximum, (int) cell.getMaximumSpan(X_AXIS));
}
}
}
示例5: setCSSSpan
import javax.swing.SizeRequirements; //导入依赖的package包/类
/**
* Sets the span on the SizeRequirements object according to the
* according CSS span value, when it is set.
*
* @param r the size requirements
* @param axis the axis
*
* @return <code>true</code> when the CSS span has been set,
* <code>false</code> otherwise
*/
private boolean setCSSSpan(SizeRequirements r, int axis)
{
boolean ret = false;
if (axis == X_AXIS)
{
if (cssWidth != null && ! cssWidth.isPercentage())
{
r.minimum = (int) cssWidth.getValue();
r.preferred = (int) cssWidth.getValue();
r.maximum = (int) cssWidth.getValue();
ret = true;
}
}
else
{
if (cssHeight != null && ! cssWidth.isPercentage())
{
r.minimum = (int) cssHeight.getValue();
r.preferred = (int) cssHeight.getValue();
r.maximum = (int) cssHeight.getValue();
ret = true;
}
}
return ret;
}
示例6: setCSSSpan
import javax.swing.SizeRequirements; //导入依赖的package包/类
/**
* Sets the span on the SizeRequirements object according to the
* according CSS span value, when it is set.
*
* @param r the size requirements
* @param axis the axis
*
* @return <code>true</code> when the CSS span has been set,
* <code>false</code> otherwise
*/
private boolean setCSSSpan(SizeRequirements r, int axis)
{
boolean ret = false;
Length span = cssSpans[axis];
// We can't set relative CSS spans here because we don't know
// yet about the allocated span. Instead we use the view's
// normal requirements.
if (span != null && ! span.isPercentage())
{
r.minimum = (int) span.getValue();
r.preferred = (int) span.getValue();
r.maximum = (int) span.getValue();
ret = true;
}
return ret;
}
示例7: setCSSSpan
import javax.swing.SizeRequirements; //导入依赖的package包/类
/**
* Sets the span on the SizeRequirements object according to the
* according CSS span value, when it is set.
*
* @param r the size requirements
* @param axis the axis
*
* @return <code>true</code> when the CSS span has been set,
* <code>false</code> otherwise
*/
private boolean setCSSSpan(SizeRequirements r, int axis)
{
boolean ret = false;
if (axis == X_AXIS)
{
if (cssWidth != null && ! cssWidth.isPercentage())
{
r.minimum = (int) cssWidth.getValue();
r.preferred = (int) cssWidth.getValue();
r.maximum = (int) cssWidth.getValue();
ret = true;
}
}
else
{
if (cssHeight != null && ! cssWidth.isPercentage())
{
r.minimum = (int) cssHeight.getValue();
r.preferred = (int) cssHeight.getValue();
r.maximum = (int) cssHeight.getValue();
ret = true;
}
}
return ret;
}
示例8: setCSSSpan
import javax.swing.SizeRequirements; //导入依赖的package包/类
/**
* Sets the span on the SizeRequirements object according to the
* according CSS span value, when it is set.
*
* @param r the size requirements
* @param axis the axis
*
* @return <code>true</code> when the CSS span has been set,
* <code>false</code> otherwise
*/
private boolean setCSSSpan(SizeRequirements r, int axis)
{
boolean ret = false;
Length span = cssSpans[axis];
// We can't set relative CSS spans here because we don't know
// yet about the allocated span. Instead we use the view's
// normal requirements.
if (span != null && ! span.isPercentage())
{
r.minimum = (int) span.getValue();
r.preferred = (int) span.getValue();
r.maximum = (int) span.getValue();
ret = true;
}
return ret;
}
示例9: getTiledSizeRequirements
import javax.swing.SizeRequirements; //导入依赖的package包/类
/**
* @see javax.swing.SizeRequirements#getTiledSizeRequirements(SizeRequirements[])
*
* @param sr SizeRequirements where results to be copied. If sr is null, new object is created
*
* @return SizeRequirements sr or newly created object
*/
public static SizeRequirements
getTiledSizeRequirements(final SizeRequirements[] children,
final SizeRequirements sr) {
SizeRequirements result = (sr != null) ? sr : new SizeRequirements();
result.minimum = 0;
result.preferred = 0;
result.maximum = 0;
result.alignment = 0.5f;
for (int iChild = 0; iChild < children.length; iChild++) {
result.minimum = Utilities.safeIntSum(children[iChild].minimum, result.minimum);
result.preferred = Utilities.safeIntSum(children[iChild].preferred, result.preferred);
result.maximum = Utilities.safeIntSum(children[iChild].maximum, result.maximum);
}
return result;
}
示例10: calculateMinorAxisRequirements
import javax.swing.SizeRequirements; //导入依赖的package包/类
protected SizeRequirements calculateMinorAxisRequirements(final int axis,
final SizeRequirements r) {
final SizeRequirements result = r != null ? r : new SizeRequirements();
final SizeRequirements[] children = getRequirements(axis);
int min = 0;
int pref = 0;
final int count = getViewCount();
for (int i = 0; i < count; i++) {
min = Math.max(min, children[i].minimum);
pref = Math.max(pref, children[i].preferred);
}
result.minimum = min;
result.preferred = pref;
result.maximum = Integer.MAX_VALUE;
result.alignment = ALIGN_CENTER;
return result;
}
示例11: resizeArray
import javax.swing.SizeRequirements; //导入依赖的package包/类
/**
* Resizes an array of size requirements.
* <small>(Probably may be optimized to not copy old array contents)</small>
*
* @param array the array to resize
* @param index index where remove and add operations occur
* @param toRemove the number of items to remove
* @param toAdd the number of items to add
* @return array with the new size
*/
private SizeRequirements[] resizeArray(final SizeRequirements[] array,
final int index,
final int toRemove,
final int toAdd) {
if (toRemove == toAdd) {
return array;
}
int size = array.length - toRemove + toAdd;
if (size == 0) {
return EMPTY_REQUIREMENTS_ARRAY;
}
SizeRequirements[] newArray = new SizeRequirements[size];
System.arraycopy(array, 0, newArray, 0, index);
System.arraycopy(array, index + toRemove, newArray, index + toAdd,
array.length - (index + toRemove));
return newArray;
}
示例12: testBaselineRequirements01
import javax.swing.SizeRequirements; //导入依赖的package包/类
/**
* Tests <code>baselineRequirements</code> with ordinary children along
* major axis - Y.
*/
public void testBaselineRequirements01() {
SizeRequirements sr;
final int axis = Y_AXIS;
sr = view.baselineRequirements(axis, null);
// The sizes to the left and to the right from the alignment point
int left = getLeft(PREFERRED, axis);
int right = getRight(PREFERRED, axis);
int size = left + right;
assertEquals(size, sr.minimum);
assertEquals(size, sr.preferred);
assertEquals(size, sr.maximum);
assertEquals((float) left / (float) size, sr.alignment, 0.00001f);
SizeRequirements another = view.baselineRequirements(axis, sr);
assertSame(sr, another);
}
示例13: testBaselineRequirements02
import javax.swing.SizeRequirements; //导入依赖的package包/类
/**
* Tests <code>baselineRequirements</code> with flexible children along
* major axis - Y.
*/
public void testBaselineRequirements02() {
if (!isHarmony()) {
return;
}
makeFlexible();
SizeRequirements sr;
final int axis = Y_AXIS;
sr = view.baselineRequirements(axis, null);
// The sizes to the left and to the right from the alignment point
int minL = getLeft(MINIMUM, axis);
int minR = getRight(MINIMUM, axis);
int prefL = getLeft(PREFERRED, axis);
int prefR = getRight(PREFERRED, axis);
int maxL = getLeft(MAXIMUM, axis);
int maxR = getRight(MAXIMUM, axis);
int min = minL + minR;
int pref = prefL + prefR;
int max = maxL + maxR;
assertEquals(min, sr.minimum);
assertEquals(pref, sr.preferred);
assertEquals(max, sr.maximum);
assertEquals((float) prefL / (float) pref, sr.alignment, 0.00001f);
}
示例14: testLayoutMinorAxis03
import javax.swing.SizeRequirements; //导入依赖的package包/类
/**
* Tests layout of minor axis with <em>resizable</em> children in the case
* where <code>targetSpan</code> <em>is less than the minimum span</em>
* of at least one of the children.
*/
public void testLayoutMinorAxis03() {
int[] offsets = new int[view.getViewCount()];
int[] spans = new int[view.getViewCount()];
makeFlexible();
SizeRequirements[] childReq = new SizeRequirements[view.getViewCount()];
fillRequirements(childReq, X_AXIS);
shape.width = 16;
view.layoutMinorAxis(shape.width, X_AXIS, offsets, spans);
boolean widthLessMinimum = false;
for (int i = 0; i < view.getViewCount(); i++) {
widthLessMinimum |= childReq[i].minimum > shape.width;
int span = getChildSpan(shape.width, childReq[i]);
assertEquals("Spans are different @ " + i, span, spans[i]);
assertEquals("Offsets are different @ " + i, getChildOffset(shape.width, span,
childReq[i].alignment), offsets[i]);
}
assertTrue("Minimum span of at least one child view must "
+ "be greater than targetSpan", widthLessMinimum);
}
示例15: testCalculateMajorAxisRequirements
import javax.swing.SizeRequirements; //导入依赖的package包/类
public void testCalculateMajorAxisRequirements() {
SizeRequirements r = view.calculateMajorAxisRequirements(Y_AXIS, null);
assertEquals(r.preferred, r.minimum);
assertEquals(0, r.preferred);
assertEquals(0, r.maximum);
doc.getStyleSheet().addRule("p {width: 305pt}");
view.setPropertiesFromAttributes();
SizeRequirements sr = view.calculateMajorAxisRequirements(Y_AXIS, r);
assertSame(r, sr);
assertEquals(0, r.minimum);
assertEquals(0, r.preferred);
assertEquals(0, r.maximum);
doc.getStyleSheet().addRule("p {height: 40pt}");
view.setPropertiesFromAttributes();
view.calculateMajorAxisRequirements(Y_AXIS, r);
assertEquals(25, r.minimum);
assertEquals(25, r.preferred);
assertEquals(25, r.maximum);
}