use of org.apache.pivot.wtk.ScrollPane 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.ScrollPane in project pivot by apache.
the class ScrollPaneSkin method isOptimizeScrolling.
private boolean isOptimizeScrolling() {
boolean optimizeScrollingLocal = this.optimizeScrolling;
if (optimizeScrollingLocal) {
// Due to Sun bug #6293145, we cannot call copyArea if scaling is
// applied to the graphics context.
// Due to Sun bug #4033851, we cannot call copyArea if the display
// host is obscured. For a full description of why this is the case,
// see http://people.apache.org/~tvolkert/tests/scrolling/
ScrollPane scrollPane = (ScrollPane) getComponent();
ApplicationContext.DisplayHost displayHost = scrollPane.getDisplay().getDisplayHost();
optimizeScrollingLocal = (displayHost.getScale() == 1 && (DesktopApplicationContext.isActive() && displayHost.isDisplayable()));
}
return optimizeScrollingLocal;
}
use of org.apache.pivot.wtk.ScrollPane in project pivot by apache.
the class ScrollPaneSkin method scrollLeftChanged.
@Override
public void scrollLeftChanged(Viewport viewport, int previousScrollLeft) {
// NOTE we don't invalidate the component here because we need only
// reposition the view and column header. Invalidating would yield
// the correct positioning, but it would do much more work than needed.
ScrollPane scrollPane = (ScrollPane) viewport;
Component view = scrollPane.getView();
Component rowHeader = scrollPane.getRowHeader();
Component columnHeader = scrollPane.getColumnHeader();
int rowHeaderWidth = 0;
if (rowHeader != null) {
rowHeaderWidth = rowHeader.getWidth();
}
int scrollLeft = scrollPane.getScrollLeft();
if (view != null && view.isShowing() && isOptimizeScrolling()) {
Bounds blitArea = view.getVisibleArea();
int blitX = blitArea.x + view.getX();
int blitY = blitArea.y + view.getY();
int blitWidth = blitArea.width;
int blitHeight = blitArea.height;
if (columnHeader != null) {
// Blit the column header as well
int columnHeaderHeight = columnHeader.getHeight();
blitY -= columnHeaderHeight;
blitHeight += columnHeaderHeight;
}
int deltaScrollLeft = scrollLeft - previousScrollLeft;
blitX += Math.max(deltaScrollLeft, 0);
blitWidth -= Math.abs(deltaScrollLeft);
Graphics2D graphics = scrollPane.getGraphics();
graphics.copyArea(blitX, blitY, blitWidth, blitHeight, -deltaScrollLeft, 0);
scrollPane.setConsumeRepaint(true);
try {
view.setLocation(rowHeaderWidth - scrollLeft, view.getY());
if (columnHeader != null) {
columnHeader.setLocation(rowHeaderWidth - scrollLeft, 0);
}
} finally {
scrollPane.setConsumeRepaint(false);
}
boolean repaintAllViewport = scrollPane.isRepaintAllViewport();
if (!repaintAllViewport) {
scrollPane.repaint(rowHeaderWidth + (deltaScrollLeft > 0 ? blitWidth : 0), blitY, Math.abs(deltaScrollLeft), blitHeight, true);
} else {
Bounds viewportBounds = getViewportBounds();
scrollPane.repaint(viewportBounds.x, viewportBounds.y, viewportBounds.width, viewportBounds.height, true);
}
} else {
if (view != null) {
view.setLocation(rowHeaderWidth - scrollLeft, view.getY());
}
if (columnHeader != null) {
columnHeader.setLocation(rowHeaderWidth - scrollLeft, 0);
}
}
if (scrollLeft >= 0 && scrollLeft <= getMaxScrollLeft()) {
horizontalScrollBar.setValue(scrollLeft);
}
}
Aggregations