use of org.eclipse.swt.widgets.ScrollBar in project usbdm-eclipse-plugins by podonoghue.
the class ImageCanvas method initScrollBars.
/**
* Initialise the scroll-bar and register listeners.
*/
private void initScrollBars() {
ScrollBar horizontal = getHorizontalBar();
horizontal.setEnabled(false);
horizontal.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
scrollHorizontally((ScrollBar) event.widget);
}
});
ScrollBar vertical = getVerticalBar();
vertical.setEnabled(false);
vertical.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
scrollVertically((ScrollBar) event.widget);
}
});
}
use of org.eclipse.swt.widgets.ScrollBar in project usbdm-eclipse-plugins by podonoghue.
the class ImageCanvas method syncScrollBars.
/**
* Synchronize the scroll-bar with the image. If the transform is out
* of range, it will correct it. This function considers only following
* factors :<b> transform, image size, client area</b>.
*/
public void syncScrollBars() {
if (sourceImage == null) {
redraw();
return;
}
AffineTransform af = fTransform;
double sx = af.getScaleX(), sy = af.getScaleY();
double tx = af.getTranslateX(), ty = af.getTranslateY();
if (tx > 0)
tx = 0;
if (ty > 0)
ty = 0;
ScrollBar horizontal = getHorizontalBar();
horizontal.setIncrement((int) (getClientArea().width / 100));
horizontal.setPageIncrement(getClientArea().width);
Rectangle imageBound = sourceImage.getBounds();
int cw = getClientArea().width, ch = getClientArea().height;
if (imageBound.width * sx > cw) {
/* image is wider than client area */
horizontal.setMaximum((int) (imageBound.width * sx));
horizontal.setEnabled(true);
if (((int) -tx) > horizontal.getMaximum() - cw)
tx = -horizontal.getMaximum() + cw;
} else {
/* image is narrower than client area */
horizontal.setEnabled(false);
// center if too small.
tx = (cw - imageBound.width * sx) / 2;
}
horizontal.setSelection((int) (-tx));
horizontal.setThumb((int) (getClientArea().width));
ScrollBar vertical = getVerticalBar();
vertical.setIncrement((int) (getClientArea().height / 100));
vertical.setPageIncrement((int) (getClientArea().height));
if (imageBound.height * sy > ch) {
/* image is higher than client area */
vertical.setMaximum((int) (imageBound.height * sy));
vertical.setEnabled(true);
if (((int) -ty) > vertical.getMaximum() - ch)
ty = -vertical.getMaximum() + ch;
} else {
/* image is less higher than client area */
vertical.setEnabled(false);
// center if too small.
ty = (ch - imageBound.height * sy) / 2;
}
vertical.setSelection((int) (-ty));
vertical.setThumb((int) (getClientArea().height));
/* update transform. */
af = AffineTransform.getScaleInstance(sx, sy);
af.preConcatenate(AffineTransform.getTranslateInstance(tx, ty));
fTransform = af;
redraw();
}
use of org.eclipse.swt.widgets.ScrollBar in project dbeaver by dbeaver.
the class ConsoleTextPresentation method performHorizontalScroll.
@Override
protected void performHorizontalScroll(int scrollCount) {
ScrollBar hsb = text.getHorizontalBar();
if (hsb != null && hsb.isVisible()) {
int curPosition = text.getHorizontalPixel();
int pageIncrement = UIUtils.getFontHeight(text.getFont()) * 10;
if (scrollCount > 0) {
if (curPosition > 0) {
curPosition -= pageIncrement;
}
} else {
curPosition += pageIncrement;
}
if (curPosition < 0)
curPosition = 0;
text.setHorizontalPixel(curPosition);
// text.setHorizontalIndex();
}
}
use of org.eclipse.swt.widgets.ScrollBar in project dbeaver by serge-rider.
the class ConsoleTextPresentation method createPresentation.
@Override
public void createPresentation(@NotNull final IResultSetController controller, @NotNull Composite parent) {
super.createPresentation(controller, parent);
UIUtils.createHorizontalLine(parent);
text = new StyledText(parent, SWT.READ_ONLY | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
text.setBlockSelection(true);
text.setCursor(parent.getDisplay().getSystemCursor(SWT.CURSOR_IBEAM));
text.setMargins(4, 4, 4, 4);
text.setForeground(UIStyles.getDefaultTextForeground());
text.setBackground(UIStyles.getDefaultTextBackground());
text.setTabs(controller.getPreferenceStore().getInt(ResultSetPreferences.RESULT_TEXT_TAB_SIZE));
text.setTabStops(null);
text.setFont(UIUtils.getMonospaceFont());
text.setLayoutData(new GridData(GridData.FILL_BOTH));
text.addCaretListener(event -> onCursorChange(event.caretOffset));
text.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
curSelection = text.getSelectionText();
fireSelectionChanged(new PlainTextSelectionImpl());
}
});
final ScrollBar verticalBar = text.getVerticalBar();
verticalBar.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (verticalBar.getSelection() + verticalBar.getPageIncrement() >= verticalBar.getMaximum()) {
if (controller.getPreferenceStore().getBoolean(ResultSetPreferences.RESULT_SET_AUTO_FETCH_NEXT_SEGMENT) && !controller.isRecordMode() && controller.isHasMoreData()) {
controller.readNextSegment();
}
}
}
});
findReplaceTarget = new StyledTextFindReplaceTarget(text);
TextEditorUtils.enableHostEditorKeyBindingsSupport(controller.getSite(), text);
applyCurrentThemeSettings();
registerContextMenu();
activateTextKeyBindings(controller, text);
trackPresentationControl();
}
use of org.eclipse.swt.widgets.ScrollBar in project dbeaver by serge-rider.
the class PlainTextPresentation method createPresentation.
@Override
public void createPresentation(@NotNull final IResultSetController controller, @NotNull Composite parent) {
super.createPresentation(controller, parent);
UIUtils.createHorizontalLine(parent);
text = new StyledText(parent, SWT.READ_ONLY | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
text.setBlockSelection(true);
text.setCursor(parent.getDisplay().getSystemCursor(SWT.CURSOR_IBEAM));
text.setMargins(4, 4, 4, 4);
text.setForeground(UIStyles.getDefaultTextForeground());
text.setBackground(UIStyles.getDefaultTextBackground());
text.setTabs(controller.getPreferenceStore().getInt(ResultSetPreferences.RESULT_TEXT_TAB_SIZE));
text.setTabStops(null);
text.setFont(UIUtils.getMonospaceFont());
text.setLayoutData(new GridData(GridData.FILL_BOTH));
text.addCaretListener(event -> onCursorChange(event.caretOffset));
text.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
curSelection = text.getSelectionText();
fireSelectionChanged(new PlainTextSelectionImpl());
}
});
final ScrollBar verticalBar = text.getVerticalBar();
verticalBar.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (verticalBar.getSelection() + verticalBar.getPageIncrement() >= verticalBar.getMaximum()) {
if (controller.getPreferenceStore().getBoolean(ResultSetPreferences.RESULT_SET_AUTO_FETCH_NEXT_SEGMENT) && !controller.isRecordMode() && controller.isHasMoreData()) {
controller.readNextSegment();
}
}
}
});
findReplaceTarget = new StyledTextFindReplaceTarget(text);
TextEditorUtils.enableHostEditorKeyBindingsSupport(controller.getSite(), text);
applyCurrentThemeSettings();
registerContextMenu();
activateTextKeyBindings(controller, text);
trackPresentationControl();
}
Aggregations