Search in sources :

Example 46 with PaintListener

use of org.eclipse.swt.events.PaintListener in project translationstudio8 by heartsome.

the class InnerTag method init.

// 初始化组件。
private void init() {
    addPaintListener(new PaintListener() {

        public void paintControl(PaintEvent e) {
            tagRender.draw(e.gc, innerTagBean, 0, 0);
        }
    });
    addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            Control parent = getParent();
            if (parent instanceof StyledText) {
                StyledText text = (StyledText) parent;
                Point size = getSize();
                Point p = getLocation();
                int offset = text.getOffsetAtLocation(p);
                int mouseX = e.x;
                if (mouseX > size.x / 2) {
                    text.setCaretOffset(offset + 1);
                } else {
                    text.setCaretOffset(offset);
                }
            }
        }
    });
}
Also used : Control(org.eclipse.swt.widgets.Control) PaintEvent(org.eclipse.swt.events.PaintEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) StyledText(org.eclipse.swt.custom.StyledText) PaintListener(org.eclipse.swt.events.PaintListener) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Point(org.eclipse.swt.graphics.Point)

Example 47 with PaintListener

use of org.eclipse.swt.events.PaintListener in project translationstudio8 by heartsome.

the class CheckBoxCellEditor method activateCell.

/**
	 * As soon as the editor is activated, flip the current data value and commit it.<br/>
	 * The repaint will pick up the new value and flip the image.
	 */
@Override
protected Control activateCell(Composite parent, Object originalCanonicalValue, Character initialEditValue) {
    setCanonicalValue(originalCanonicalValue);
    checked = !checked;
    canvas = new Canvas(parent, SWT.NONE);
    canvas.addPaintListener(new PaintListener() {

        public void paintControl(PaintEvent paintEvent) {
            Rectangle bounds = canvas.getBounds();
            Rectangle rect = new Rectangle(0, 0, bounds.width, bounds.height);
            checkBoxCellPainter.paintIconImage(paintEvent.gc, rect, bounds.height / 2 - checkBoxCellPainter.getPreferredHeight(checked) / 2, checked);
        }
    });
    canvas.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseUp(MouseEvent e) {
            checked = !checked;
            canvas.redraw();
        }
    });
    commit(MoveDirectionEnum.NONE, false);
    return canvas;
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) PaintListener(org.eclipse.swt.events.PaintListener) Canvas(org.eclipse.swt.widgets.Canvas) Rectangle(org.eclipse.swt.graphics.Rectangle) MouseAdapter(org.eclipse.swt.events.MouseAdapter)

Example 48 with PaintListener

use of org.eclipse.swt.events.PaintListener in project cubrid-manager by CUBRID.

the class CommonUITool method hackForYosemite.

/**
	 * Because the table has some problems of SWT library on Yosemite, all the table need add this patch. 
	 * Fix for #64 Mac OSX yosemite didn't show all records while running a query on CUBRID manager.
	 * 
	 * @param table
	 */
public static void hackForYosemite(final Table table) {
    if (!isYosemite() || table == null || table.isDisposed()) {
        return;
    }
    if (table.getHeaderVisible()) {
        table.setHeaderVisible(true);
        Display.getDefault().asyncExec(new Runnable() {

            public void run() {
                if (!table.isDisposed()) {
                    try {
                        Method getViewMethod = Control.class.getDeclaredMethod("contentView");
                        getViewMethod.setAccessible(true);
                        Object viewObject = getViewMethod.invoke(table);
                        Method tileMethod = viewObject.getClass().getMethod("tile");
                        tileMethod.invoke(viewObject);
                    } catch (NoSuchMethodException ex) {
                        LOGGER.error(ex.getMessage());
                    } catch (SecurityException ex) {
                        LOGGER.error(ex.getMessage());
                    } catch (IllegalAccessException ex) {
                        LOGGER.error(ex.getMessage());
                    } catch (IllegalArgumentException ex) {
                        LOGGER.error(ex.getMessage());
                    } catch (InvocationTargetException ex) {
                        LOGGER.error(ex.getMessage());
                    }
                }
            }
        });
        table.addPaintListener(new PaintListener() {

            boolean isAdjusted = false;

            public void paintControl(PaintEvent e) {
                if (!table.isDisposed() && !isAdjusted) {
                    Rectangle bounds = table.getBounds();
                    table.setSize(table.computeSize(SWT.DEFAULT, SWT.DEFAULT));
                    table.setBounds(bounds);
                    isAdjusted = true;
                }
            }
        });
    }
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) Rectangle(org.eclipse.swt.graphics.Rectangle) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) Control(org.eclipse.swt.widgets.Control)

Example 49 with PaintListener

use of org.eclipse.swt.events.PaintListener in project dbeaver by serge-rider.

the class ViewValuePanel method viewValue.

private void viewValue(boolean forceRefresh) {
    if (valueSaving) {
        return;
    }
    if (valueManager == null || valueEditor == null) {
        forceRefresh = true;
    }
    if (forceRefresh) {
        cleanupPanel();
        // Create a new one
        valueManager = previewController.getValueManager();
        try {
            valueEditor = valueManager.createEditor(previewController);
        } catch (Throwable e) {
            UIUtils.showErrorDialog(viewPlaceholder.getShell(), "Value preview", "Can't create value viewer", e);
            return;
        }
        if (valueEditor != null) {
            try {
                valueEditor.createControl();
            } catch (Exception e) {
                log.error(e);
            }
            Control control = valueEditor.getControl();
            if (control != null) {
                UIUtils.addFocusTracker(presentation.getController().getSite(), VALUE_VIEW_CONTROL_ID, control);
                presentation.getController().lockActionsByFocus(control);
            }
            referenceValueEditor = new ReferenceValueEditor(previewController, valueEditor);
            if (referenceValueEditor.isReferenceValue()) {
                GridLayout gl = new GridLayout(1, false);
                viewPlaceholder.setLayout(gl);
                valueEditor.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
                referenceValueEditor.createEditorSelector(viewPlaceholder);
            } else {
                viewPlaceholder.setLayout(new FillLayout());
            }
        } else {
            final Composite placeholder = UIUtils.createPlaceholder(viewPlaceholder, 1);
            placeholder.setBackground(placeholder.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
            placeholder.addPaintListener(new PaintListener() {

                @Override
                public void paintControl(PaintEvent e) {
                    Rectangle bounds = placeholder.getBounds();
                    String message = "No editor for [" + previewController.getValueType().getTypeName() + "]";
                    Point ext = e.gc.textExtent(message);
                    e.gc.drawText(message, (bounds.width - ext.x) / 2, bounds.height / 3 + 20);
                }
            });
            referenceValueEditor = null;
        }
        viewPlaceholder.layout();
    }
    if (valueEditor instanceof BaseValueEditor) {
        ((BaseValueEditor) valueEditor).setAutoSaveEnabled(false);
    }
    if (valueEditor != null) {
        try {
            Object newValue = previewController.getValue();
            if (newValue instanceof DBDValue) {
                // Do not check for difference
                valueEditor.primeEditorValue(newValue);
            } else {
                Object oldValue = null;
                try {
                    if (previewController.getExecutionContext() != null) {
                        oldValue = valueEditor.extractEditorValue();
                    }
                } catch (Throwable e) {
                // Some error extracting current value
                // This may happen if we were disconnected
                }
                if (!CommonUtils.equalObjects(oldValue, newValue)) {
                    valueEditor.primeEditorValue(newValue);
                }
            }
        } catch (DBException e) {
            log.error(e);
        }
        valueEditor.setDirty(false);
    }
    if (valueEditor instanceof BaseValueEditor) {
        ((BaseValueEditor) valueEditor).setAutoSaveEnabled(true);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) PaintEvent(org.eclipse.swt.events.PaintEvent) Composite(org.eclipse.swt.widgets.Composite) PaintListener(org.eclipse.swt.events.PaintListener) Rectangle(org.eclipse.swt.graphics.Rectangle) FillLayout(org.eclipse.swt.layout.FillLayout) Point(org.eclipse.swt.graphics.Point) ReferenceValueEditor(org.jkiss.dbeaver.ui.data.editors.ReferenceValueEditor) DBException(org.jkiss.dbeaver.DBException) BaseValueEditor(org.jkiss.dbeaver.ui.data.editors.BaseValueEditor) Control(org.eclipse.swt.widgets.Control) GridLayout(org.eclipse.swt.layout.GridLayout) DBDValue(org.jkiss.dbeaver.model.data.DBDValue) GridData(org.eclipse.swt.layout.GridData)

Example 50 with PaintListener

use of org.eclipse.swt.events.PaintListener in project dbeaver by serge-rider.

the class ProgressEditorPart method createProgressPane.

private void createProgressPane(final Composite parent) {
    progressCanvas = new Canvas(parent, SWT.NONE);
    progressCanvas.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            e.gc.drawText("Connecting to datasource '" + getEditorInput().getDatabaseObject().getName() + "'...", 5, 5, true);
        }
    });
    InitNodeService loadingService = new InitNodeService();
    LoadingJob<IDatabaseEditorInput> loadJob = LoadingJob.createService(loadingService, new InitNodeVisualizer(loadingService));
    loadJob.schedule();
}
Also used : IDatabaseEditorInput(org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput) PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) Canvas(org.eclipse.swt.widgets.Canvas)

Aggregations

PaintListener (org.eclipse.swt.events.PaintListener)89 PaintEvent (org.eclipse.swt.events.PaintEvent)88 Canvas (org.eclipse.swt.widgets.Canvas)32 Composite (org.eclipse.swt.widgets.Composite)29 MouseEvent (org.eclipse.swt.events.MouseEvent)26 GridData (org.eclipse.swt.layout.GridData)26 Rectangle (org.eclipse.swt.graphics.Rectangle)25 Point (org.eclipse.swt.graphics.Point)23 GridLayout (org.eclipse.swt.layout.GridLayout)22 MouseAdapter (org.eclipse.swt.events.MouseAdapter)15 SelectionEvent (org.eclipse.swt.events.SelectionEvent)15 DisposeEvent (org.eclipse.swt.events.DisposeEvent)14 DisposeListener (org.eclipse.swt.events.DisposeListener)14 FillLayout (org.eclipse.swt.layout.FillLayout)14 Control (org.eclipse.swt.widgets.Control)14 ControlEvent (org.eclipse.swt.events.ControlEvent)13 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)12 Event (org.eclipse.swt.widgets.Event)11 GC (org.eclipse.swt.graphics.GC)10 Button (org.eclipse.swt.widgets.Button)10