Search in sources :

Example 1 with Display

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;
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) Button(org.eclipse.swt.widgets.Button) PaintListener(org.eclipse.swt.events.PaintListener) Color(org.eclipse.swt.graphics.Color) Widget(org.eclipse.swt.widgets.Widget) Display(org.eclipse.swt.widgets.Display)

Example 2 with Display

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;
}
Also used : ImageData(org.eclipse.swt.graphics.ImageData) Color(org.eclipse.swt.graphics.Color) Image(org.eclipse.swt.graphics.Image) DBPImage(org.jkiss.dbeaver.model.DBPImage) GC(org.eclipse.swt.graphics.GC) Display(org.eclipse.swt.widgets.Display)

Example 3 with Display

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();
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) Display(org.eclipse.swt.widgets.Display)

Example 4 with Display

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;
}
Also used : Control(org.eclipse.swt.widgets.Control) TraverseEvent(org.eclipse.swt.events.TraverseEvent) TraverseListener(org.eclipse.swt.events.TraverseListener) Cursor(org.eclipse.swt.graphics.Cursor) Map(java.util.Map) HashMap(java.util.HashMap) Display(org.eclipse.swt.widgets.Display)

Example 5 with Display

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();
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) TableColumn(org.eclipse.swt.widgets.TableColumn) Point(org.eclipse.swt.graphics.Point) Display(org.eclipse.swt.widgets.Display)

Aggregations

Display (org.eclipse.swt.widgets.Display)191 Shell (org.eclipse.swt.widgets.Shell)49 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)28 InvocationTargetException (java.lang.reflect.InvocationTargetException)25 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)22 Point (org.eclipse.swt.graphics.Point)17 ITask (com.cubrid.common.core.task.ITask)15 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)15 Color (org.eclipse.swt.graphics.Color)15 GridLayout (org.eclipse.swt.layout.GridLayout)14 Button (org.eclipse.swt.widgets.Button)14 FillLayout (org.eclipse.swt.layout.FillLayout)13 GridData (org.eclipse.swt.layout.GridData)12 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)11 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)11 IStatus (org.eclipse.core.runtime.IStatus)11 Status (org.eclipse.core.runtime.Status)11 Composite (org.eclipse.swt.widgets.Composite)11 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)10 ArrayList (java.util.ArrayList)10