use of org.eclipse.swt.widgets.Display in project eclipse.themes.darker by jinmingjian.
the class CSSPropertyDarkerButtonBackgroundColorHandler method applyCSSProperty.
public boolean applyCSSProperty(Object element, String property, CSSValue value, String pseudo, CSSEngine engine) throws Exception {
final Widget widget = SWTElementHelpers.getWidget(element);
final Display display = widget.getDisplay();
final Color color = (Color) engine.convert(value, Color.class, display);
if (widget instanceof Button) {
final Button b = (Button) widget;
if ((b.getStyle() & SWT.PUSH) != 0) {
b.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
b.setBackground(color);
e.gc.setBackground(color);
e.gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
e.gc.fillRoundRectangle(0, 0, b.getBounds().width, b.getBounds().height, 2, 2);
// e.gc.drawRoundRectangle(0, 0,
// b.getBounds().width,
// b.getBounds().height,
// 2, 2);
e.gc.drawString(b.getText(), 5, 5);
}
});
return true;
}
}
return false;
}
use of org.eclipse.swt.widgets.Display in project dbeaver by serge-rider.
the class DBeaverIcons method getViewMenuImage.
public static synchronized Image getViewMenuImage() {
if (viewMenuImage == null) {
Display d = Display.getCurrent();
Image viewMenu = new Image(d, 16, 16);
Image viewMenuMask = new Image(d, 16, 16);
Display display = Display.getCurrent();
GC gc = new GC(viewMenu);
GC maskgc = new GC(viewMenuMask);
gc.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
gc.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND));
int[] shapeArray = new int[] { 6, 3, 15, 3, 11, 7, 10, 7 };
gc.fillPolygon(shapeArray);
gc.drawPolygon(shapeArray);
Color black = display.getSystemColor(SWT.COLOR_BLACK);
Color white = display.getSystemColor(SWT.COLOR_WHITE);
maskgc.setBackground(black);
maskgc.fillRectangle(0, 0, 16, 16);
maskgc.setBackground(white);
maskgc.setForeground(white);
maskgc.fillPolygon(shapeArray);
maskgc.drawPolygon(shapeArray);
gc.dispose();
maskgc.dispose();
ImageData data = viewMenu.getImageData();
data.transparentPixel = data.getPixel(0, 0);
viewMenuImage = new Image(d, viewMenu.getImageData(), viewMenuMask.getImageData());
viewMenu.dispose();
viewMenuMask.dispose();
}
return viewMenuImage;
}
use of org.eclipse.swt.widgets.Display in project dbeaver by serge-rider.
the class DBeaverApplication method stop.
@Override
public void stop() {
//$NON-NLS-1$
log.debug("DBeaver is stopping");
try {
final IWorkbench workbench = PlatformUI.getWorkbench();
if (workbench == null)
return;
instanceServer = null;
DBeaverInstanceServer.stopInstanceServer();
final Display display = workbench.getDisplay();
DBeaverUI.syncExec(new Runnable() {
@Override
public void run() {
if (!display.isDisposed())
workbench.close();
}
});
} catch (Throwable e) {
log.error(e);
} finally {
instance = null;
stopDebugWriter();
}
}
use of org.eclipse.swt.widgets.Display in project translationstudio8 by heartsome.
the class TSWizardDialog method aboutToStart.
/**
* About to start a long running operation triggered through the wizard.
* Shows the progress monitor and disables the wizard's buttons and
* controls.
*
* @param enableCancelButton
* <code>true</code> if the Cancel button should be enabled,
* and <code>false</code> if it should be disabled
* @return the saved UI state
*/
private Object aboutToStart(boolean enableCancelButton) {
Map savedState = null;
if (getShell() != null) {
// Save focus control
Control focusControl = getShell().getDisplay().getFocusControl();
if (focusControl != null && focusControl.getShell() != getShell()) {
focusControl = null;
}
boolean needsProgressMonitor = wizard.needsProgressMonitor();
// Set the busy cursor to all shells.
Display d = getShell().getDisplay();
waitCursor = new Cursor(d, SWT.CURSOR_WAIT);
setDisplayCursor(waitCursor);
if (useCustomProgressMonitorPart) {
cancelButton.removeSelectionListener(cancelListener);
// Set the arrow cursor to the cancel component.
arrowCursor = new Cursor(d, SWT.CURSOR_ARROW);
cancelButton.setCursor(arrowCursor);
}
// Deactivate shell
savedState = saveUIState(useCustomProgressMonitorPart && needsProgressMonitor && enableCancelButton);
if (focusControl != null) {
savedState.put(FOCUS_CONTROL, focusControl);
}
// Activate cancel behavior.
if (needsProgressMonitor) {
if (enableCancelButton || useCustomProgressMonitorPart) {
progressMonitorPart.attachToCancelComponent(cancelButton);
}
progressMonitorPart.setVisible(true);
}
// Install traverse listener once in order to implement 'Enter' and 'Space' key blocking
if (timeWhenLastJobFinished == -1) {
timeWhenLastJobFinished = 0;
getShell().addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent e) {
if (e.detail == SWT.TRAVERSE_RETURN || (e.detail == SWT.TRAVERSE_MNEMONIC && e.keyCode == 32)) {
// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=287887
if (timeWhenLastJobFinished != 0 && System.currentTimeMillis() - timeWhenLastJobFinished < RESTORE_ENTER_DELAY) {
e.doit = false;
return;
}
timeWhenLastJobFinished = 0;
}
}
});
}
}
return savedState;
}
use of org.eclipse.swt.widgets.Display in project translationstudio8 by heartsome.
the class TableCombo method dropDown.
/**
* handle DropDown request
* @param drop
*/
void dropDown(boolean drop) {
// if already dropped then return
if (drop == isDropped())
return;
// closing the dropDown
if (!drop) {
popup.setVisible(false);
if (!isDisposed() && isFocusControl()) {
text.setFocus();
}
return;
}
// if not visible then return
if (!isVisible())
return;
// create a new popup if needed.
if (getShell() != popup.getParent()) {
int selectionIndex = table.getSelectionIndex();
table.removeListener(SWT.Dispose, listener);
popup.dispose();
popup = null;
table = null;
createPopup(selectionIndex);
}
// get the size of the TableCombo.
Point tableComboSize = getSize();
// calculate the table height.
int itemCount = table.getItemCount();
itemCount = (itemCount == 0) ? visibleItemCount : Math.min(visibleItemCount, itemCount);
int itemHeight = (table.getItemHeight() * itemCount);
// visible item count.
if (table.getItemCount() <= visibleItemCount) {
itemHeight += 1;
}
// add height of header if the header is being displayed.
if (table.getHeaderVisible()) {
itemHeight += table.getHeaderHeight();
}
// get table column references
TableColumn[] tableColumns = table.getColumns();
int totalColumns = (tableColumns == null ? 0 : tableColumns.length);
// then just create a blank one.
if (table.getColumnCount() == 0) {
new TableColumn(table, SWT.NONE);
totalColumns = 1;
tableColumns = table.getColumns();
}
int totalColumnWidth = 0;
// now pack any columns that do not have a explicit value set for them.
for (int colIndex = 0; colIndex < totalColumns; colIndex++) {
if (!wasColumnWidthSpecified(colIndex)) {
tableColumns[colIndex].pack();
}
totalColumnWidth += tableColumns[colIndex].getWidth();
}
// reset the last column's width to the preferred size if it has a
// explicit value.
int lastColIndex = totalColumns - 1;
if (wasColumnWidthSpecified(lastColIndex)) {
tableColumns[lastColIndex].setWidth(columnWidths[lastColIndex]);
}
// calculate the table size after making adjustments.
Point tableSize = table.computeSize(SWT.DEFAULT, itemHeight, false);
// calculate the table width and table height.
double pct = tableWidthPercentage / 100d;
int tableWidth = (int) (Math.max(tableComboSize.x - 2, tableSize.x) * pct);
int tableHeight = tableSize.y;
// not viewing the full table.
if (tableWidthPercentage < 100) {
tableHeight += table.getHorizontalBar().getSize().y;
}
// set the bounds on the table.
table.setBounds(1, 1, tableWidth, tableHeight);
// it is needed or not.
if (!table.getVerticalBar().getVisible() && tableSize.x - table.getVerticalBar().getSize().x >= tableComboSize.x - 2) {
tableWidth = tableWidth - table.getVerticalBar().getSize().x;
// reset the bounds on the table.
table.setBounds(1, 1, tableWidth, tableHeight);
}
table.getHorizontalBar().setVisible(false);
// adjust the last column to make sure that there is no empty space.
autoAdjustColumnWidthsIfNeeded(tableColumns, tableWidth, totalColumnWidth);
// set the table top index if there is a valid selection.
String indexStr = (String) text.getData();
if (indexStr != null && !indexStr.equals("")) {
int index = Integer.parseInt(indexStr);
table.setSelection(index);
table.setTopIndex(index);
}
// calculate popup dimensions.
Display display = getDisplay();
Rectangle tableRect = table.getBounds();
Rectangle parentRect = display.map(getParent(), null, getBounds());
Point comboSize = getSize();
Rectangle displayRect = getMonitor().getClientArea();
int overallWidth = 0;
// now set what the overall width should be.
if (tableWidthPercentage < 100) {
overallWidth = tableRect.width + 2;
} else {
overallWidth = Math.max(comboSize.x, tableRect.width + 2);
}
int overallHeight = tableRect.height + 2;
int x = parentRect.x;
int y = parentRect.y + comboSize.y;
if (y + overallHeight > displayRect.y + displayRect.height)
y = parentRect.y - overallHeight;
if (x + overallWidth > displayRect.x + displayRect.width)
x = displayRect.x + displayRect.width - tableRect.width;
// set the bounds of the popup
popup.setBounds(x, y, overallWidth, overallHeight);
// set the popup visible
popup.setVisible(true);
// set focus on the table.
table.setFocus();
}
Aggregations