use of org.apache.pivot.wtk.ScrollPane in project pivot by apache.
the class Pivot811 method startup.
@Override
public void startup(final Display displayArgument, Map<String, String> properties) throws Exception {
this.display = displayArgument;
Frame listFrame = new Frame();
listFrame.setTitle("List Frame");
listFrame.setPreferredSize(400, 300);
listFrame.setLocation(20, 20);
listFrame.getStyles().put(Style.padding, Insets.NONE);
BoxPane boxPane = new BoxPane();
boxPane.getStyles().put(Style.fill, true);
boxPane.setOrientation(Orientation.VERTICAL);
listFrame.setContent(boxPane);
Label infoLabel = new Label("Double click on a list item to open a detail frame");
boxPane.add(infoLabel);
ScrollPane scrollPane = new ScrollPane();
scrollPane.setHorizontalScrollBarPolicy(ScrollBarPolicy.FILL);
scrollPane.setVerticalScrollBarPolicy(ScrollBarPolicy.FILL_TO_CAPACITY);
// workaround for pivot-738,
scrollPane.setRepaintAllViewport(true);
// needed only in in some cases
boxPane.add(scrollPane);
final ListView listView = new ListView();
List<String> listData = new ArrayList<>();
for (int i = 0; i < 50; ++i) {
listData.add("List Item " + i);
}
listView.setListData(listData);
scrollPane.setView(listView);
listView.getListViewSelectionListeners().add(new ListViewSelectionListener() {
@Override
public void selectedItemChanged(ListView listViewArgument, Object previousSelectedItem) {
System.out.println("selectedItemChanged : " + listViewArgument.getSelectedItem());
}
});
listView.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener() {
@Override
public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
System.out.println("mouseClick : " + count);
if (count == 2) {
System.out.println("double click, now open a detail frame");
Frame detailFrame = new Frame();
detailFrame.setTitle("Detail Frame");
detailFrame.setPreferredSize(400, 300);
int selectedIndex = listView.getSelectedIndex();
detailFrame.setLocation(80 + (selectedIndex * 10), 80 + (selectedIndex * 10));
detailFrame.getStyles().put(Style.padding, Insets.NONE);
BoxPane boxPaneLocal = new BoxPane();
boxPaneLocal.getStyles().put(Style.fill, true);
boxPaneLocal.setOrientation(Orientation.VERTICAL);
detailFrame.setContent(boxPaneLocal);
String selectedItem = listView.getSelectedItem().toString();
Label label = new Label("Selected Item is \"" + selectedItem + "\"");
boxPaneLocal.add(label);
// spacer
boxPaneLocal.add(new Label(""));
boxPaneLocal.add(new Label("Click inside the text input to focus it"));
TextInput textInput = new TextInput();
textInput.setText("Focusable component");
// workaround for pivot-811:
boxPaneLocal.add(textInput);
// add a focusable element
// inside the frame
detailFrame.open(displayArgument);
// workaround for pivot-811: force the focus on the first
// focusable element inside the frame
detailFrame.requestFocus();
// textInput.requestFocus(); // or use this ...
}
return true;
}
});
listFrame.open(displayArgument);
listView.setSelectedIndex(0);
listView.requestFocus();
}
use of org.apache.pivot.wtk.ScrollPane in project pivot by apache.
the class ScrollPaneSkin method valueChanged.
// ScrollBarValueListener methods
@Override
public void valueChanged(ScrollBar scrollBar, int previousValue) {
ScrollPane scrollPane = (ScrollPane) getComponent();
int value = scrollBar.getValue();
if (scrollBar == horizontalScrollBar) {
scrollPane.setScrollLeft(value);
} else {
scrollPane.setScrollTop(value);
}
}
use of org.apache.pivot.wtk.ScrollPane in project pivot by apache.
the class ScrollPaneSkin method getMaxScrollTop.
/**
* Gets the maximum legal <tt>scrollTop</tt> value this this skin imposes.
* This is the largest value possible that still shows as much of the view
* component as it can.
*
* @return The maximum scrollTop value
*/
private int getMaxScrollTop() {
int maxScrollTop = 0;
ScrollPane scrollPane = (ScrollPane) getComponent();
Component view = scrollPane.getView();
if (view != null) {
int viewHeight = view.getHeight();
int columnHeaderHeight = 0;
int horizontalScrollBarHeight = 0;
int height = getHeight();
Component columnHeader = scrollPane.getColumnHeader();
if (columnHeader != null) {
columnHeaderHeight = columnHeader.getHeight();
}
if (horizontalScrollBar.isVisible()) {
horizontalScrollBarHeight = horizontalScrollBar.getHeight();
}
maxScrollTop = Math.max(viewHeight + columnHeaderHeight + horizontalScrollBarHeight - height, 0);
}
return maxScrollTop;
}
use of org.apache.pivot.wtk.ScrollPane in project pivot by apache.
the class ScrollPaneSkin method getPreferredHeight.
@Override
public int getPreferredHeight(int width) {
int preferredHeight = 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 horizontalPolicy = scrollPane.getHorizontalScrollBarPolicy();
if (horizontalPolicy != ScrollBarPolicy.FILL) {
// Get the unconstrained preferred size of the view
Dimensions preferredViewSize = view.getPreferredSize();
if (horizontalPolicy == ScrollBarPolicy.FILL_TO_CAPACITY) {
if (width < 0) {
horizontalPolicy = ScrollBarPolicy.AUTO;
} else {
int preferredWidth = preferredViewSize.width + preferredRowHeaderWidth;
if (preferredWidth < width) {
horizontalPolicy = ScrollBarPolicy.FILL;
} else {
horizontalPolicy = ScrollBarPolicy.AUTO;
}
}
}
if (horizontalPolicy == ScrollBarPolicy.ALWAYS || horizontalPolicy == ScrollBarPolicy.NEVER || horizontalPolicy == ScrollBarPolicy.AUTO) {
preferredHeight = preferredViewSize.height + preferredColumnHeaderHeight;
// height calculation
if (horizontalPolicy == ScrollBarPolicy.ALWAYS || (horizontalPolicy == ScrollBarPolicy.AUTO && width > 0 && preferredViewSize.width + preferredRowHeaderWidth > width)) {
preferredHeight += horizontalScrollBar.getPreferredHeight(-1);
}
}
}
if (horizontalPolicy == ScrollBarPolicy.FILL) {
// Preferred height is the sum of the constrained preferred height
// of the view and the unconstrained preferred height of the column header
int widthUpdated = width;
if (widthUpdated >= 0) {
// Subtract the unconstrained preferred width of the row header
// from the width constraint
widthUpdated = Math.max(widthUpdated - preferredRowHeaderWidth, 0);
}
preferredHeight = view.getPreferredHeight(widthUpdated) + preferredColumnHeaderHeight;
}
}
return preferredHeight;
}
use of org.apache.pivot.wtk.ScrollPane in project pivot by apache.
the class ScrollPaneSkin method scrollTopChanged.
// ViewportListener methods
@Override
public void scrollTopChanged(Viewport viewport, int previousScrollTop) {
// NOTE we don't invalidate the component here because we need only
// reposition the view and row 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 columnHeaderHeight = 0;
if (columnHeader != null) {
columnHeaderHeight = columnHeader.getHeight();
}
int scrollTop = scrollPane.getScrollTop();
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 (rowHeader != null) {
// Blit the row header as well
int rowHeaderWidth = rowHeader.getWidth();
blitX -= rowHeaderWidth;
blitWidth += rowHeaderWidth;
}
int deltaScrollTop = scrollTop - previousScrollTop;
blitY += Math.max(deltaScrollTop, 0);
blitHeight -= Math.abs(deltaScrollTop);
Graphics2D graphics = scrollPane.getGraphics();
graphics.copyArea(blitX, blitY, blitWidth, blitHeight, 0, -deltaScrollTop);
scrollPane.setConsumeRepaint(true);
try {
view.setLocation(view.getX(), columnHeaderHeight - scrollTop);
if (rowHeader != null) {
rowHeader.setLocation(0, columnHeaderHeight - scrollTop);
}
} finally {
scrollPane.setConsumeRepaint(false);
}
boolean repaintAllViewport = scrollPane.isRepaintAllViewport();
if (!repaintAllViewport) {
scrollPane.repaint(blitX, (columnHeaderHeight + (deltaScrollTop > 0 ? blitHeight : 0)), blitWidth, Math.abs(deltaScrollTop), true);
} else {
Bounds viewportBounds = getViewportBounds();
scrollPane.repaint(viewportBounds.x, viewportBounds.y, viewportBounds.width, viewportBounds.height, true);
}
} else {
if (view != null) {
view.setLocation(view.getX(), columnHeaderHeight - scrollTop);
}
if (rowHeader != null) {
rowHeader.setLocation(0, columnHeaderHeight - scrollTop);
}
}
if (scrollTop >= 0 && scrollTop <= getMaxScrollTop()) {
verticalScrollBar.setValue(scrollTop);
}
}
Aggregations