use of javax.swing.SizeRequirements in project jdk8u_jdk by JetBrains.
the class TableView method calculateMinorAxisRequirements.
// --- BoxView methods -----------------------------------------
/**
* Calculate the requirements for the minor axis. This is called by
* the superclass whenever the requirements need to be updated (i.e.
* a preferenceChanged was messaged through this view).
* <p>
* This is implemented to calculate the requirements as the sum of the
* requirements of the columns and then adjust it if the
* CSS width or height attribute is specified and applicable to
* the axis.
*/
protected SizeRequirements calculateMinorAxisRequirements(int axis, SizeRequirements r) {
updateGrid();
// calculate column requirements for each column
calculateColumnRequirements(axis);
// the requirements are the sum of the columns.
if (r == null) {
r = new SizeRequirements();
}
long min = 0;
long pref = 0;
int n = columnRequirements.length;
for (int i = 0; i < n; i++) {
SizeRequirements req = columnRequirements[i];
min += req.minimum;
pref += req.preferred;
}
int adjust = (n + 1) * cellSpacing + 2 * borderWidth;
min += adjust;
pref += adjust;
r.minimum = (int) min;
r.preferred = (int) pref;
r.maximum = (int) pref;
AttributeSet attr = getAttributes();
CSS.LengthValue cssWidth = (CSS.LengthValue) attr.getAttribute(CSS.Attribute.WIDTH);
if (BlockView.spanSetFromAttributes(axis, r, cssWidth, null)) {
if (r.minimum < (int) min) {
// The user has requested a smaller size than is needed to
// show the table, override it.
r.maximum = r.minimum = r.preferred = (int) min;
}
}
totalColumnRequirements.minimum = r.minimum;
totalColumnRequirements.preferred = r.preferred;
totalColumnRequirements.maximum = r.maximum;
// set the alignment
Object o = attr.getAttribute(CSS.Attribute.TEXT_ALIGN);
if (o != null) {
// set horizontal alignment
String ta = o.toString();
if (ta.equals("left")) {
r.alignment = 0;
} else if (ta.equals("center")) {
r.alignment = 0.5f;
} else if (ta.equals("right")) {
r.alignment = 1;
} else {
r.alignment = 0;
}
} else {
r.alignment = 0;
}
return r;
}
use of javax.swing.SizeRequirements in project jdk8u_jdk by JetBrains.
the class TableView method updateGrid.
/**
* Fill in the grid locations that are placeholders
* for multi-column, multi-row, and missing grid
* locations.
*/
void updateGrid() {
if (!gridValid) {
relativeCells = false;
multiRowCells = false;
// determine which views are table rows and clear out
// grid points marked filled.
captionIndex = -1;
rows.removeAllElements();
int n = getViewCount();
for (int i = 0; i < n; i++) {
View v = getView(i);
if (v instanceof RowView) {
rows.addElement((RowView) v);
RowView rv = (RowView) v;
rv.clearFilledColumns();
rv.rowIndex = rows.size() - 1;
rv.viewIndex = i;
} else {
Object o = v.getElement().getAttributes().getAttribute(StyleConstants.NameAttribute);
if (o instanceof HTML.Tag) {
HTML.Tag kind = (HTML.Tag) o;
if (kind == HTML.Tag.CAPTION) {
captionIndex = i;
}
}
}
}
int maxColumns = 0;
int nrows = rows.size();
for (int row = 0; row < nrows; row++) {
RowView rv = getRow(row);
int col = 0;
for (int cell = 0; cell < rv.getViewCount(); cell++, col++) {
View cv = rv.getView(cell);
if (!relativeCells) {
AttributeSet a = cv.getAttributes();
CSS.LengthValue lv = (CSS.LengthValue) a.getAttribute(CSS.Attribute.WIDTH);
if ((lv != null) && (lv.isPercentage())) {
relativeCells = true;
}
}
// advance to a free column
for (; rv.isFilled(col); col++) ;
int rowSpan = getRowsOccupied(cv);
if (rowSpan > 1) {
multiRowCells = true;
}
int colSpan = getColumnsOccupied(cv);
if ((colSpan > 1) || (rowSpan > 1)) {
// fill in the overflow entries for this cell
int rowLimit = row + rowSpan;
int colLimit = col + colSpan;
for (int i = row; i < rowLimit; i++) {
for (int j = col; j < colLimit; j++) {
if (i != row || j != col) {
addFill(i, j);
}
}
}
if (colSpan > 1) {
col += colSpan - 1;
}
}
}
maxColumns = Math.max(maxColumns, col);
}
// setup the column layout/requirements
columnSpans = new int[maxColumns];
columnOffsets = new int[maxColumns];
columnRequirements = new SizeRequirements[maxColumns];
for (int i = 0; i < maxColumns; i++) {
columnRequirements[i] = new SizeRequirements();
columnRequirements[i].maximum = Integer.MAX_VALUE;
}
gridValid = true;
}
}
use of javax.swing.SizeRequirements in project jdk8u_jdk by JetBrains.
the class TableView method checkMultiColumnCell.
/**
* check the requirements of a table cell that spans multiple
* columns.
*/
void checkMultiColumnCell(int axis, int col, int ncols, View v) {
// calculate the totals
long min = 0;
long pref = 0;
long max = 0;
for (int i = 0; i < ncols; i++) {
SizeRequirements req = columnRequirements[col + i];
min += req.minimum;
pref += req.preferred;
max += req.maximum;
}
// check if the minimum size needs adjustment.
int cmin = (int) v.getMinimumSpan(axis);
if (cmin > min) {
/*
* the columns that this cell spans need adjustment to fit
* this table cell.... calculate the adjustments.
*/
SizeRequirements[] reqs = new SizeRequirements[ncols];
for (int i = 0; i < ncols; i++) {
reqs[i] = columnRequirements[col + i];
}
int[] spans = new int[ncols];
int[] offsets = new int[ncols];
SizeRequirements.calculateTiledPositions(cmin, null, reqs, offsets, spans);
// apply the adjustments
for (int i = 0; i < ncols; i++) {
SizeRequirements req = reqs[i];
req.minimum = Math.max(spans[i], req.minimum);
req.preferred = Math.max(req.minimum, req.preferred);
req.maximum = Math.max(req.preferred, req.maximum);
}
}
// check if the preferred size needs adjustment.
int cpref = (int) v.getPreferredSpan(axis);
if (cpref > pref) {
/*
* the columns that this cell spans need adjustment to fit
* this table cell.... calculate the adjustments.
*/
SizeRequirements[] reqs = new SizeRequirements[ncols];
for (int i = 0; i < ncols; i++) {
reqs[i] = columnRequirements[col + i];
}
int[] spans = new int[ncols];
int[] offsets = new int[ncols];
SizeRequirements.calculateTiledPositions(cpref, null, reqs, offsets, spans);
// apply the adjustments
for (int i = 0; i < ncols; i++) {
SizeRequirements req = reqs[i];
req.preferred = Math.max(spans[i], req.preferred);
req.maximum = Math.max(req.preferred, req.maximum);
}
}
}
use of javax.swing.SizeRequirements in project jdk8u_jdk by JetBrains.
the class TableView method calculateColumnRequirements.
/**
* Calculate the requirements for each column. The calculation
* is done as two passes over the table. The table cells that
* occupy a single column are scanned first to determine the
* maximum of minimum, preferred, and maximum spans along the
* give axis. Table cells that span multiple columns are excluded
* from the first pass. A second pass is made to determine if
* the cells that span multiple columns are satisfied. If the
* column requirements are not satisified, the needs of the
* multi-column cell is mixed into the existing column requirements.
* The calculation of the multi-column distribution is based upon
* the proportions of the existing column requirements and taking
* into consideration any constraining maximums.
*/
void calculateColumnRequirements(int axis) {
// clean columnRequirements
for (SizeRequirements req : columnRequirements) {
req.minimum = 0;
req.preferred = 0;
req.maximum = Integer.MAX_VALUE;
}
Container host = getContainer();
if (host != null) {
if (host instanceof JTextComponent) {
skipComments = !((JTextComponent) host).isEditable();
} else {
skipComments = true;
}
}
// pass 1 - single column cells
boolean hasMultiColumn = false;
int nrows = getRowCount();
for (int i = 0; i < nrows; i++) {
RowView row = getRow(i);
int col = 0;
int ncells = row.getViewCount();
for (int cell = 0; cell < ncells; cell++) {
View cv = row.getView(cell);
if (skipComments && !(cv instanceof CellView)) {
continue;
}
// advance to a free column
for (; row.isFilled(col); col++) ;
int rowSpan = getRowsOccupied(cv);
int colSpan = getColumnsOccupied(cv);
if (colSpan == 1) {
checkSingleColumnCell(axis, col, cv);
} else {
hasMultiColumn = true;
col += colSpan - 1;
}
col++;
}
}
// pass 2 - multi-column cells
if (hasMultiColumn) {
for (int i = 0; i < nrows; i++) {
RowView row = getRow(i);
int col = 0;
int ncells = row.getViewCount();
for (int cell = 0; cell < ncells; cell++) {
View cv = row.getView(cell);
if (skipComments && !(cv instanceof CellView)) {
continue;
}
// advance to a free column
for (; row.isFilled(col); col++) ;
int colSpan = getColumnsOccupied(cv);
if (colSpan > 1) {
checkMultiColumnCell(axis, col, colSpan, cv);
col += colSpan - 1;
}
col++;
}
}
}
}
use of javax.swing.SizeRequirements in project jsql-injection by ron190.
the class HTMLEditorKitTextPaneWrap method getViewFactory.
@Override
public ViewFactory getViewFactory() {
return new HTMLFactory() {
@Override
public View create(Element e) {
View v = super.create(e);
if (v instanceof InlineView) {
return new InlineView(e) {
@Override
public int getBreakWeight(int axis, float pos, float len) {
return GoodBreakWeight;
}
@Override
public View breakView(int axis, int p0, float pos, float len) {
if (axis == View.X_AXIS) {
this.checkPainter();
int p1 = this.getGlyphPainter().getBoundedPosition(this, p0, pos, len);
if (p0 == this.getStartOffset() && p1 == this.getEndOffset()) {
return this;
}
return this.createFragment(p0, p1);
}
return this;
}
};
} else if (v instanceof ParagraphView) {
return new ParagraphView(e) {
@Override
protected SizeRequirements calculateMinorAxisRequirements(int axis, SizeRequirements valueR) {
SizeRequirements r = valueR;
if (r == null) {
r = new SizeRequirements();
}
float pref = this.layoutPool.getPreferredSpan(axis);
float min = this.layoutPool.getMinimumSpan(axis);
// Don't include insets, Box.getXXXSpan will include
// them.
r.minimum = (int) min;
r.preferred = Math.max(r.minimum, (int) pref);
r.maximum = Integer.MAX_VALUE;
r.alignment = 0.5f;
return r;
}
};
}
return v;
}
};
}
Aggregations