use of org.apache.pivot.wtk.Dimensions in project pivot by apache.
the class ScrollPaneSkin method getPreferredWidth.
@Override
public int getPreferredWidth(int height) {
int preferredWidth = 0;
ScrollPane scrollPane = (ScrollPane) getComponent();
Component view = scrollPane.getView();
if (view != null) {
int preferredRowHeaderWidth = 0;
Component rowHeader = scrollPane.getRowHeader();
if (rowHeader != null) {
preferredRowHeaderWidth = rowHeader.getPreferredWidth(-1);
}
int preferredColumnHeaderHeight = 0;
Component columnHeader = scrollPane.getColumnHeader();
if (columnHeader != null) {
preferredColumnHeaderHeight = columnHeader.getPreferredHeight(-1);
}
ScrollBarPolicy verticalPolicy = scrollPane.getVerticalScrollBarPolicy();
if (verticalPolicy != ScrollBarPolicy.FILL) {
// Get the unconstrained preferred size of the view
Dimensions preferredViewSize = view.getPreferredSize();
if (verticalPolicy == ScrollBarPolicy.FILL_TO_CAPACITY) {
if (height < 0) {
verticalPolicy = ScrollBarPolicy.AUTO;
} else {
int preferredHeight = preferredViewSize.height + preferredColumnHeaderHeight;
if (preferredHeight < height) {
verticalPolicy = ScrollBarPolicy.FILL;
} else {
verticalPolicy = ScrollBarPolicy.AUTO;
}
}
}
if (verticalPolicy == ScrollBarPolicy.ALWAYS || verticalPolicy == ScrollBarPolicy.NEVER || verticalPolicy == ScrollBarPolicy.AUTO) {
preferredWidth = preferredViewSize.width + preferredRowHeaderWidth;
// preferred width calculation
if (verticalPolicy == ScrollBarPolicy.ALWAYS || (verticalPolicy == ScrollBarPolicy.AUTO && height > 0 && preferredViewSize.height + preferredColumnHeaderHeight > height)) {
preferredWidth += verticalScrollBar.getPreferredWidth(-1);
}
}
}
if (verticalPolicy == ScrollBarPolicy.FILL) {
// Preferred width is the sum of the constrained preferred
// width of the view and the unconstrained preferred width of
// the row header
int heightUpdated = height;
if (heightUpdated >= 0) {
// Subtract the unconstrained preferred height of the
// column header from the height constraint
heightUpdated = Math.max(heightUpdated - preferredColumnHeaderHeight, 0);
}
preferredWidth = view.getPreferredWidth(heightUpdated) + preferredRowHeaderWidth;
}
}
return preferredWidth;
}
use of org.apache.pivot.wtk.Dimensions in project pivot by apache.
the class TextAreaSkin method setLineWidth.
public void setLineWidth(int lineWidth) {
if (this.lineWidth != lineWidth) {
this.lineWidth = lineWidth;
int missingGlyphCode = font.getMissingGlyphCode();
FontRenderContext fontRenderContext = Platform.getFontRenderContext();
GlyphVector missingGlyphVector = font.createGlyphVector(fontRenderContext, new int[] { missingGlyphCode });
Rectangle2D textBounds = missingGlyphVector.getLogicalBounds();
Rectangle2D maxCharBounds = font.getMaxCharBounds(fontRenderContext);
averageCharacterSize = new Dimensions((int) Math.ceil(textBounds.getWidth()), (int) Math.ceil(maxCharBounds.getHeight()));
invalidateComponent();
}
}
use of org.apache.pivot.wtk.Dimensions in project pivot by apache.
the class TextPaneSkin method getPreferredWidth.
@Override
public int getPreferredWidth(int height) {
int preferredWidth;
if (documentView == null) {
preferredWidth = 0;
} else {
Dimensions documentDimensions = documentView.getPreferredSize(Integer.MAX_VALUE);
preferredWidth = documentDimensions.width + margin.getWidth();
}
return preferredWidth;
}
use of org.apache.pivot.wtk.Dimensions in project pivot by apache.
the class TextPaneSkin method getPreferredSize.
@Override
public Dimensions getPreferredSize() {
int preferredHeight;
int preferredWidth;
if (documentView == null) {
preferredWidth = 0;
preferredHeight = 0;
} else {
Dimensions documentDimensions = documentView.getPreferredSize(Integer.MAX_VALUE);
preferredWidth = documentDimensions.width + margin.getWidth();
preferredHeight = documentDimensions.height + margin.getHeight();
}
return new Dimensions(preferredWidth, preferredHeight);
}
use of org.apache.pivot.wtk.Dimensions in project pivot by apache.
the class TextPaneSkinComponentNodeView method getPreferredSize.
@Override
public Dimensions getPreferredSize(int breakWidth) {
ComponentNode componentNode = (ComponentNode) getNode();
Component component = componentNode.getComponent();
if (component == null) {
return new Dimensions(0, 0);
}
return new Dimensions(component.getPreferredWidth(), component.getPreferredHeight());
}
Aggregations