use of org.eclipse.swt.graphics.Rectangle in project cogtool by cogtool.
the class StandardDrawingEditor method movePointNearEdge.
/**
* Check to see if a point is near to an edge. Get the dragDelta
* which is used to indicate how much to "grow" the window based on the
* mouse position.
*
* Returns a boolean, which dictates if the cursor was inside or outside the
* window frame. (this is done to allow mouse states to know exit and
* entered times)
*
* Also ensures that the specified X & Y are visible.
*
* @param eventX
* @param eventY
* @param dragDelta
* @return
*/
public boolean movePointNearEdge(int eventX, int eventY, Point dragDelta) {
Rectangle clientArea = scrollComposite.getClientArea();
Point origin = scrollComposite.getOrigin();
// TODO: Switch this to base at 0. Then use an acceleration curve.
// Use the getOrigin to get the top left corner of the view.. this
// is the location that you are currently scrolled too.
// Compute the difference between the origin and the mouse cursor.
// If the difference is near the edge of the visible rectangle, then
// use set the delta to non zero. If outside, return false. if inside,
// return true, and set dragDelta to 0,0,
// Use getClientArea to find the width/height of the visible region
int relativeX = eventX - origin.x;
int relativeY = eventY - origin.y;
boolean xIsOutside = false;
boolean yIsOutside = false;
if (relativeX < 0) {
dragDelta.x = 0;
xIsOutside = true;
} else if (relativeX < 5) {
dragDelta.x = -10;
} else if (relativeX < 10) {
dragDelta.x = -5;
} else if (relativeX > clientArea.width) {
dragDelta.x = 0;
xIsOutside = true;
} else if (relativeX > clientArea.width - 5) {
dragDelta.x = 10;
} else if (relativeX > clientArea.width - 10) {
dragDelta.x = 5;
} else {
dragDelta.x = 0;
}
if (relativeY < 0) {
dragDelta.y = 0;
yIsOutside = true;
} else if (relativeY < 5) {
dragDelta.y = -10;
} else if (relativeY < 10) {
dragDelta.y = -5;
} else if (relativeY > clientArea.height) {
dragDelta.y = 0;
yIsOutside = true;
} else if (relativeY > clientArea.height - 5) {
dragDelta.y = 10;
} else if (relativeY > clientArea.height - 10) {
dragDelta.y = 5;
} else {
dragDelta.y = 0;
}
ensurePointIsVisible(dragDelta.x, dragDelta.y, eventX, eventY);
return (xIsOutside || yIsOutside);
}
use of org.eclipse.swt.graphics.Rectangle in project dbeaver by serge-rider.
the class ProgressLoaderVisualizer method showProgress.
private void showProgress() {
if (progressOverlay == null) {
// Start progress visualization
cancelButton = new Button(progressPane, SWT.PUSH);
cancelButton.setText("Cancel");
GridData gd = new GridData(GridData.FILL_BOTH);
gd.verticalIndent = DBeaverIcons.getImage(UIIcon.PROGRESS0).getBounds().height * 2;
cancelButton.setLayoutData(gd);
cancelButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
cancelButton.setText("Canceled");
cancelButton.setEnabled(false);
Point buttonSize = cancelButton.computeSize(SWT.DEFAULT, SWT.DEFAULT);
progressOverlay.minimumWidth = buttonSize.x;
progressOverlay.minimumHeight = buttonSize.y;
progressOverlay.layout();
try {
loadService.cancel();
} catch (InvocationTargetException e1) {
log.error(e1.getTargetException());
}
}
});
painListener = new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
Image image = DBeaverIcons.getImage(PROGRESS_IMAGES[drawCount % PROGRESS_IMAGES.length]);
Rectangle buttonBounds = cancelButton.getBounds();
Rectangle imageBounds = image.getBounds();
e.gc.drawImage(image, (buttonBounds.x + buttonBounds.width / 2) - imageBounds.width / 2, buttonBounds.y - imageBounds.height - 5);
long elapsedTime = System.currentTimeMillis() - loadStartTime;
String elapsedString = elapsedTime > 10000 ? String.valueOf(elapsedTime / 1000) : String.valueOf(((double) (elapsedTime / 100)) / 10);
String statusMessage = CommonUtils.truncateString(progressMessage.replaceAll("\\s", " "), 64);
String status = statusMessage + " - " + elapsedString + "s";
Point statusSize = e.gc.textExtent(status);
int statusX = (buttonBounds.x + buttonBounds.width / 2) - statusSize.x / 2;
int statusY = buttonBounds.y - imageBounds.height - 10 - statusSize.y;
e.gc.setForeground(progressPane.getForeground());
e.gc.setBackground(progressPane.getBackground());
e.gc.fillRectangle(statusX - 2, statusY - 2, statusSize.x + 4, statusSize.y + 4);
e.gc.drawText(status, statusX, statusY, true);
e.gc.setForeground(shadowColor);
e.gc.drawRoundRectangle(statusX - 3, statusY - 3, statusSize.x + 5, statusSize.y + 5, 5, 5);
}
};
progressPane.addPaintListener(painListener);
progressOverlay = new ControlEditor(progressPane);
Point buttonSize = cancelButton.computeSize(SWT.DEFAULT, SWT.DEFAULT);
progressOverlay.minimumWidth = buttonSize.x;
progressOverlay.minimumHeight = buttonSize.y;
progressOverlay.setEditor(cancelButton);
}
drawCount++;
progressOverlay.layout();
progressPane.redraw();
}
use of org.eclipse.swt.graphics.Rectangle in project dbeaver by serge-rider.
the class DB2RunstatsDialog method createControls.
@Override
protected void createControls(Composite parent) {
Group optionsGroup = UIUtils.createControlGroup(parent, DB2Messages.dialog_table_tools_options, 1, 0, 0);
optionsGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Composite composite = new Composite(optionsGroup, 2);
composite.setLayout(new GridLayout(2, false));
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
// RUNSTATS ON COLUMNS
UIUtils.createLabel(composite, DB2Messages.dialog_table_tools_runstats_cols_title).setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
Composite groupCols = new Composite(composite, SWT.NONE);
groupCols.setLayout(new RowLayout(SWT.VERTICAL));
dlgColsAllAndDistribution = new Button(groupCols, SWT.RADIO);
dlgColsAllAndDistribution.setText(DB2Messages.dialog_table_tools_runstats_cols_all_and_distribution);
dlgColsAllAndDistribution.addSelectionListener(SQL_CHANGE_LISTENER);
dlgColsAll = new Button(groupCols, SWT.RADIO);
dlgColsAll.setText(DB2Messages.dialog_table_tools_runstats_cols_all);
dlgColsAll.addSelectionListener(SQL_CHANGE_LISTENER);
Button dlgColsNo = new Button(groupCols, SWT.RADIO);
dlgColsNo.setText(DB2Messages.dialog_table_tools_runstats_cols_no);
dlgColsNo.addSelectionListener(SQL_CHANGE_LISTENER);
// RUNSTATS ON INDEXES
UIUtils.createLabel(composite, DB2Messages.dialog_table_tools_runstats_indexes_title).setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
Composite groupIx = new Composite(composite, SWT.NULL);
groupIx.setLayout(new RowLayout(SWT.VERTICAL));
dlgIndexesDetailed = new Button(groupIx, SWT.RADIO);
dlgIndexesDetailed.setText(DB2Messages.dialog_table_tools_runstats_indexes_detailed);
dlgIndexesDetailed.addSelectionListener(SQL_CHANGE_LISTENER);
dlgIndexesAll = new Button(groupIx, SWT.RADIO);
dlgIndexesAll.setText(DB2Messages.dialog_table_tools_runstats_indexes_all);
dlgIndexesAll.addSelectionListener(SQL_CHANGE_LISTENER);
Button dlgIndexesNo = new Button(groupIx, SWT.RADIO);
dlgIndexesNo.setText(DB2Messages.dialog_table_tools_runstats_indexes_no);
dlgIndexesNo.addSelectionListener(SQL_CHANGE_LISTENER);
// SAMPLING
dlgSample = UIUtils.createCheckbox(composite, DB2Messages.dialog_table_tools_runstats_stats_title, false);
dlgSample.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
dlgSampleValue.setEnabled(dlgSample.getSelection());
updateSQL();
}
});
dlgSampleValue = new Spinner(composite, SWT.BORDER);
dlgSampleValue.setMinimum(0);
dlgSampleValue.setMaximum(100);
dlgSampleValue.setIncrement(1);
Rectangle clientArea = getShell().getClientArea();
dlgSampleValue.setLocation(clientArea.x, clientArea.y);
dlgSampleValue.pack();
dlgSampleValue.addSelectionListener(SQL_CHANGE_LISTENER);
// Initial setup
dlgColsAllAndDistribution.setSelection(true);
dlgIndexesDetailed.setSelection(true);
dlgSampleValue.setSelection(0);
dlgSampleValue.setEnabled(false);
// Object Selector
createObjectsSelector(parent);
}
use of org.eclipse.swt.graphics.Rectangle in project dbeaver by serge-rider.
the class ValueViewDialog method initializeBounds.
@Override
protected void initializeBounds() {
super.initializeBounds();
Shell shell = getShell();
String sizeString = dialogSettings.get(getDialogSizePrefId());
if (!CommonUtils.isEmpty(sizeString) && sizeString.contains(":")) {
int divPos = sizeString.indexOf(':');
shell.setSize(new Point(Integer.parseInt(sizeString.substring(0, divPos)), Integer.parseInt(sizeString.substring(divPos + 1))));
shell.layout();
}
Monitor primary = shell.getMonitor();
Rectangle bounds = primary.getBounds();
Rectangle rect = shell.getBounds();
int x = bounds.x + (bounds.width - rect.width) / 2;
int y = bounds.y + (bounds.height - rect.height) / 3;
x += dialogCount * 20;
y += dialogCount * 20;
shell.setLocation(x, y);
}
use of org.eclipse.swt.graphics.Rectangle in project dbeaver by serge-rider.
the class Spreadsheet method redrawGrid.
public void redrawGrid() {
Rectangle bounds = super.getBounds();
super.redraw(bounds.x, bounds.y, bounds.width, bounds.height, true);
}
Aggregations