use of org.eclipse.swt.widgets.ScrollBar in project eclipse.platform.swt by eclipse.
the class CTable method onScrollVertical.
void onScrollVertical(Event event) {
ScrollBar vBar = getVerticalBar();
if (vBar == null)
return;
int newSelection = vBar.getSelection();
update();
GC gc = new GC(this);
gc.copyArea(0, 0, clientArea.width, clientArea.height, 0, (topIndex - newSelection) * itemHeight);
gc.dispose();
topIndex = newSelection;
}
use of org.eclipse.swt.widgets.ScrollBar in project eclipse.platform.swt by eclipse.
the class CTable method onArrowDown.
void onArrowDown(int stateMask) {
if ((stateMask & (SWT.SHIFT | SWT.CTRL)) == 0) {
/* Down Arrow with no modifiers */
int newFocusIndex = focusItem.index + 1;
if (newFocusIndex == itemsCount)
return;
/* at bottom */
selectItem(items[newFocusIndex], false);
setFocusItem(items[newFocusIndex], true);
redrawItem(newFocusIndex, true);
showItem(items[newFocusIndex]);
Event newEvent = new Event();
newEvent.item = items[newFocusIndex];
notifyListeners(SWT.Selection, newEvent);
return;
}
if ((getStyle() & SWT.SINGLE) != 0) {
if ((stateMask & SWT.CTRL) != 0) {
/* CTRL+Down Arrow, CTRL+Shift+Down Arrow */
int visibleItemCount = (clientArea.height - getHeaderHeight()) / itemHeight;
if (itemsCount <= topIndex + visibleItemCount)
return;
/* at bottom */
update();
topIndex++;
ScrollBar vBar = getVerticalBar();
if (vBar != null)
vBar.setSelection(topIndex);
GC gc = new GC(this);
gc.copyArea(0, 0, clientArea.width, clientArea.height, 0, -itemHeight);
gc.dispose();
return;
}
/* Shift+Down Arrow */
int newFocusIndex = focusItem.index + 1;
if (newFocusIndex == itemsCount)
return;
/* at bottom */
selectItem(items[newFocusIndex], false);
setFocusItem(items[newFocusIndex], true);
redrawItem(newFocusIndex, true);
showItem(items[newFocusIndex]);
Event newEvent = new Event();
newEvent.item = items[newFocusIndex];
notifyListeners(SWT.Selection, newEvent);
return;
}
/* SWT.MULTI */
if ((stateMask & SWT.CTRL) != 0) {
if ((stateMask & SWT.SHIFT) != 0) {
/* CTRL+Shift+Down Arrow */
int visibleItemCount = (clientArea.height - getHeaderHeight()) / itemHeight;
if (itemsCount <= topIndex + visibleItemCount)
return;
/* at bottom */
update();
topIndex++;
ScrollBar vBar = getVerticalBar();
if (vBar != null)
vBar.setSelection(topIndex);
GC gc = new GC(this);
gc.copyArea(0, 0, clientArea.width, clientArea.height, 0, -itemHeight);
gc.dispose();
return;
}
/* CTRL+Down Arrow */
int focusIndex = focusItem.index;
if (focusIndex == itemsCount - 1)
return;
/* at bottom */
CTableItem newFocusItem = items[focusIndex + 1];
setFocusItem(newFocusItem, true);
redrawItem(newFocusItem.index, true);
showItem(newFocusItem);
return;
}
/* Shift+Down Arrow */
int newFocusIndex = focusItem.index + 1;
if (newFocusIndex == itemsCount)
return;
/* at bottom */
if (anchorItem == null)
anchorItem = focusItem;
if (focusItem.index < anchorItem.index) {
deselectItem(focusItem);
redrawItem(focusItem.index, true);
}
selectItem(items[newFocusIndex], true);
setFocusItem(items[newFocusIndex], true);
redrawItem(newFocusIndex, true);
showItem(items[newFocusIndex]);
Event newEvent = new Event();
newEvent.item = items[newFocusIndex];
notifyListeners(SWT.Selection, newEvent);
}
use of org.eclipse.swt.widgets.ScrollBar in project eclipse.platform.swt by eclipse.
the class CTable method setFont.
@Override
public void setFont(Font value) {
checkWidget();
Font oldFont = getFont();
super.setFont(value);
Font font = getFont();
if (font.equals(oldFont))
return;
GC gc = new GC(this);
/* recompute the receiver's cached font height and item height values */
fontHeight = gc.getFontMetrics().getHeight();
setItemHeight(Math.max(fontHeight, imageHeight) + 2 * getCellPadding());
Point headerSize = header.getSize();
int newHeaderHeight = Math.max(fontHeight, headerImageHeight) + 2 * getHeaderPadding();
if (headerSize.y != newHeaderHeight) {
header.setSize(headerSize.x, newHeaderHeight);
}
header.setFont(font);
/*
* Notify all columns and items of the font change so that elements that
* use the receiver's font can recompute their cached string widths.
*/
for (CTableColumn column : columns) {
column.updateFont(gc);
}
for (int i = 0; i < itemsCount; i++) {
items[i].updateFont(gc);
}
gc.dispose();
if (drawCount <= 0 && header.isVisible())
header.redraw();
/* update scrollbars */
if (columns.length == 0)
updateHorizontalBar();
ScrollBar vBar = getVerticalBar();
if (vBar != null) {
int thumb = (clientArea.height - getHeaderHeight()) / itemHeight;
vBar.setThumb(thumb);
vBar.setPageIncrement(thumb);
topIndex = vBar.getSelection();
vBar.setVisible(thumb < vBar.getMaximum());
}
redraw();
}
use of org.eclipse.swt.widgets.ScrollBar in project eclipse.platform.swt by eclipse.
the class CTable method updateHorizontalBar.
/*
* This is a naive implementation that computes the value from scratch.
*/
void updateHorizontalBar() {
if (drawCount > 0)
return;
ScrollBar hBar = getHorizontalBar();
if (hBar == null)
return;
int maxX = 0;
if (columns.length > 0) {
for (CTableColumn column : columns) {
maxX += column.width;
}
} else {
for (int i = 0; i < itemsCount; i++) {
Rectangle itemBounds = items[i].getCellBounds(0);
maxX = Math.max(maxX, itemBounds.x + itemBounds.width + horizontalOffset);
}
}
int clientWidth = clientArea.width;
if (maxX != hBar.getMaximum()) {
hBar.setMaximum(Math.max(1, maxX));
/* setting a value of 0 here is ignored */
}
int thumb = Math.min(clientWidth, maxX);
if (thumb != hBar.getThumb()) {
hBar.setThumb(thumb);
hBar.setPageIncrement(thumb);
}
hBar.setVisible(clientWidth < maxX);
/* reclaim any space now left on the right */
if (maxX < horizontalOffset + thumb) {
horizontalOffset = maxX - thumb;
hBar.setSelection(horizontalOffset);
redraw();
} else {
int selection = hBar.getSelection();
if (selection != horizontalOffset) {
horizontalOffset = selection;
redraw();
}
}
}
use of org.eclipse.swt.widgets.ScrollBar in project eclipse.platform.swt by eclipse.
the class ImageAnalyzer method resizeScrollBars.
void resizeScrollBars() {
// Set the max and thumb for the image canvas scroll bars.
ScrollBar horizontal = imageCanvas.getHorizontalBar();
ScrollBar vertical = imageCanvas.getVerticalBar();
Rectangle canvasBounds = imageCanvas.getClientArea();
int width = Math.round(imageData.width * xscale);
if (width > canvasBounds.width) {
// The image is wider than the canvas.
horizontal.setEnabled(true);
horizontal.setMaximum(width);
horizontal.setThumb(canvasBounds.width);
horizontal.setPageIncrement(canvasBounds.width);
} else {
// The canvas is wider than the image.
horizontal.setEnabled(false);
if (ix != 0) {
// Make sure the image is completely visible.
ix = 0;
imageCanvas.redraw();
}
}
int height = Math.round(imageData.height * yscale);
if (height > canvasBounds.height) {
// The image is taller than the canvas.
vertical.setEnabled(true);
vertical.setMaximum(height);
vertical.setThumb(canvasBounds.height);
vertical.setPageIncrement(canvasBounds.height);
} else {
// The canvas is taller than the image.
vertical.setEnabled(false);
if (iy != 0) {
// Make sure the image is completely visible.
iy = 0;
imageCanvas.redraw();
}
}
// Set the max and thumb for the palette canvas scroll bar.
vertical = paletteCanvas.getVerticalBar();
if (imageData.palette.isDirect) {
vertical.setEnabled(false);
} else {
// indexed palette
canvasBounds = paletteCanvas.getClientArea();
// 10 pixels each index + 20 for margins.
int paletteHeight = imageData.palette.getRGBs().length * 10 + 20;
vertical.setEnabled(true);
vertical.setMaximum(paletteHeight);
vertical.setThumb(canvasBounds.height);
vertical.setPageIncrement(canvasBounds.height);
}
}
Aggregations