FieldLayout.java revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* ident "%Z%%M% %I% %E% SMI"
*
* Copyright (c) 1996-2001 by Sun Microsystems, Inc.
* All rights reserved.
*/
/**
* <CODE>FieldLayout</CODE> treats components as a list of
* labeled fields, where each label is placed on the left
* edge of the container with its associated field to its
* right.<P>
*
* Two kinds of components may be added: "Label" and "Field."
* Labels and Fields must be added in pairs, because there is
* a one-to-one correspondence between them.<P>
*
* When a <CODE>Field</CODE> is added, it is associated with the
* last <CODE>Label</CODE> added.<P>
*/
public class FieldLayout implements LayoutManager {
class Row {
double yRatio;
boolean center;
public Row() {
yRatio = 1;
center = true;
}
}
int hgap;
int vgap;
/**
* Constructs a new <CODE>FieldLayout</CODE> with a centered alignment.
*/
public FieldLayout() {
this(5, 5);
}
/**
* Constructs a new <CODE>FieldLayout</CODE> with the specified gap values.
* @param hgap</VAR> The horizontal gap variable.
* @param vgap</VAR> The vertical gap variable.
*/
}
/**
* Adds the specified component to the layout.
* @param name</VAR> The name of the component.
* @param comp</VAR> The component to be added.
*/
r.center = true;
rows.addElement(r);
r.center = false;
rows.addElement(r);
}
}
/**
* Removes the specified component from the layout.
* @param comp</VAR> The component to remove.
*/
while (en.hasMoreElements()) {
rows.removeElement(r);
return;
}
}
}
/**
* Returns the preferred dimensions for this layout given the components
* in the specified target container.
* @param target</VAR> The component that needs to be laid out.
* @see java.awt.Container
* @see #minimumLayoutSize
*/
while (en.hasMoreElements()) {
continue;
}
}
return dim;
}
/**
* Returns the minimum dimensions needed to layout the components
* contained in the specified target container.
* @param target</VAR> The component that needs to be laid out.
* @see #preferredLayoutSize
*/
while (en.hasMoreElements()) {
continue;
}
}
return dim;
}
/**
* Performs the layout of the container. Components are treated
* either as labels or fields. Labels go on the left (right-aligned),
* with their associated fields placed immediately to their right.
* @param target</VAR> The specified component being laid out.
* @see java.awt.Container
*/
int widestLabel = 0;
int ySlop = 0;
// Compute whether preferred sizes will fit
boolean usingPreferred = true;
usingPreferred = false;
// Compute leftover vertical space
if (ySlop < 0) {
ySlop = 0;
}
}
/*
* Find widest label. Our policy on horizontal space is that labels
* are fully satisfied and fields get whatever's left.
* For vertical space, if there's any leftovers then allocate it
* in proportion to demand, which we'll define as the ratio between
* preferred size and minimum size.
*/
double sumRatios = 0;
while (en.hasMoreElements()) {
r.label.getMinimumSize();
if (!usingPreferred) {
}
// If there is no demand, then adjust ratio to zero
if (r.yRatio == 1.0) {
r.yRatio = 0;
}
}
}
// lay out rows, right-aligning labels
while (en.hasMoreElements()) {
// Skip the row if both aren't visible
continue;
l.getMinimumSize();
f.getMinimumSize();
/*
* If the field is visible, move it right to line up with
* the widest line.
*/
offset = 0;
if (r.center) {
// center label on field
}
int labelHeight = rowHeight;
/*
* If label doesn't look like it wants extra space, don't give it;
* otherwise, JLabels will get drawn centered even if user
* specified it as a top alignment when doing the layout.
*/
}
}
}
/**
* Returns the <CODE>String</CODE> representation of this
* <CODE>FieldLayout</CODE>'s values.
*/
}
}