📄 flowarrangement.java
字号:
}
/**
* Arranges the blocks in the container with a fixed width and a range
* constraint on the height.
*
* @param container the container.
* @param constraint the constraint.
* @param g2 the graphics device.
*
* @return The size following the arrangement.
*/
protected Size2D arrangeFR(BlockContainer container, Graphics2D g2,
RectangleConstraint constraint) {
Size2D s = arrangeFN(container, g2, constraint);
if (constraint.getHeightRange().contains(s.height)) {
return s;
}
else {
RectangleConstraint c = constraint.toFixedHeight(
constraint.getHeightRange().constrain(s.getHeight())
);
return arrangeFF(container, g2, c);
}
}
/**
* Arranges the blocks in the container with the overall height and width
* specified as fixed constraints.
*
* @param container the container.
* @param constraint the constraint.
* @param g2 the graphics device.
*
* @return The size following the arrangement.
*/
protected Size2D arrangeFF(BlockContainer container, Graphics2D g2,
RectangleConstraint constraint) {
// TODO: implement this properly
return arrangeFN(container, g2, constraint);
}
/**
* Arranges the blocks with the overall width and height to fit within
* specified ranges.
*
* @param container the container.
* @param constraint the constraint.
* @param g2 the graphics device.
*
* @return The size after the arrangement.
*/
protected Size2D arrangeRR(BlockContainer container, Graphics2D g2,
RectangleConstraint constraint) {
// first arrange without constraints, and see if this fits within
// the required ranges...
Size2D s1 = arrangeNN(container, g2);
if (constraint.getWidthRange().contains(s1.width)) {
return s1; // TODO: we didn't check the height yet
}
else {
RectangleConstraint c = constraint.toFixedWidth(
constraint.getWidthRange().getUpperBound()
);
return arrangeFR(container, g2, c);
}
}
/**
* Arranges the blocks in the container with a range constraint on the
* width and a fixed height.
*
* @param container the container.
* @param constraint the constraint.
* @param g2 the graphics device.
*
* @return The size following the arrangement.
*/
protected Size2D arrangeRF(BlockContainer container, Graphics2D g2,
RectangleConstraint constraint) {
Size2D s = arrangeNF(container, g2, constraint);
if (constraint.getWidthRange().contains(s.width)) {
return s;
}
else {
RectangleConstraint c = constraint.toFixedWidth(
constraint.getWidthRange().constrain(s.getWidth())
);
return arrangeFF(container, g2, c);
}
}
/**
* Arranges the block with a range constraint on the width, and no
* constraint on the height.
*
* @param container the container.
* @param constraint the constraint.
* @param g2 the graphics device.
*
* @return The size following the arrangement.
*/
protected Size2D arrangeRN(BlockContainer container, Graphics2D g2,
RectangleConstraint constraint) {
// first arrange without constraints, then see if the width fits
// within the required range...if not, call arrangeFN() at max width
Size2D s1 = arrangeNN(container, g2);
if (constraint.getWidthRange().contains(s1.width)) {
return s1;
}
else {
RectangleConstraint c = constraint.toFixedWidth(
constraint.getWidthRange().getUpperBound()
);
return arrangeFN(container, g2, c);
}
}
/**
* Arranges the blocks without any constraints. This puts all blocks
* into a single row.
*
* @param container the container.
* @param g2 the graphics device.
*
* @return The size after the arrangement.
*/
protected Size2D arrangeNN(BlockContainer container, Graphics2D g2) {
double x = 0.0;
double width = 0.0;
double maxHeight = 0.0;
List blocks = container.getBlocks();
int blockCount = blocks.size();
if (blockCount > 0) {
Size2D[] sizes = new Size2D[blocks.size()];
for (int i = 0; i < blocks.size(); i++) {
Block block = (Block) blocks.get(i);
sizes[i] = block.arrange(g2, RectangleConstraint.NONE);
width = width + sizes[i].getWidth();
maxHeight = Math.max(sizes[i].height, maxHeight);
block.setBounds(
new Rectangle2D.Double(
x, 0.0, sizes[i].width, sizes[i].height
)
);
x = x + sizes[i].width + this.horizontalGap;
}
if (blockCount > 1) {
width = width + this.horizontalGap * (blockCount - 1);
}
if (this.verticalAlignment != VerticalAlignment.TOP) {
for (int i = 0; i < blocks.size(); i++) {
//Block b = (Block) blocks.get(i);
if (this.verticalAlignment == VerticalAlignment.CENTER) {
//TODO: shift block down by half
}
else if (this.verticalAlignment
== VerticalAlignment.BOTTOM) {
//TODO: shift block down to bottom
}
}
}
}
return new Size2D(width, maxHeight);
}
/**
* Arranges the blocks with no width constraint and a fixed height
* constraint. This puts all blocks into a single row.
*
* @param container the container.
* @param constraint the constraint.
* @param g2 the graphics device.
*
* @return The size after the arrangement.
*/
protected Size2D arrangeNF(BlockContainer container, Graphics2D g2,
RectangleConstraint constraint) {
// TODO: for now we are ignoring the height constraint
return arrangeNN(container, g2);
}
/**
* Clears any cached information.
*/
public void clear() {
// no action required.
}
/**
* Tests this instance for equality with an arbitrary object.
*
* @param obj the object (<code>null</code> permitted).
*
* @return A boolean.
*/
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof FlowArrangement)) {
return false;
}
FlowArrangement that = (FlowArrangement) obj;
if (this.horizontalAlignment != that.horizontalAlignment) {
return false;
}
if (this.verticalAlignment != that.verticalAlignment) {
return false;
}
if (this.horizontalGap != that.horizontalGap) {
return false;
}
if (this.verticalGap != that.verticalGap) {
return false;
}
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -