Search in sources :

Example 1 with PaintListener

use of org.eclipse.swt.events.PaintListener in project tdi-studio-se by Talend.

the class Marker method createHover.

/**
     * Creates the hover.
     * 
     * @param key The hover key
     * @return The hover
     */
private Shell createHover(final String key) {
    Shell hover = new Shell(lineHover, SWT.NO_TRIM | SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);
    hover.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
    hover.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            String text = texts.get(key);
            if (text != null) {
                e.gc.drawText(texts.get(key), OFFSET + MARGIN, OFFSET);
            }
        }
    });
    hover.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_DARK_GREEN));
    hover.setAlpha(150);
    return hover;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener)

Example 2 with PaintListener

use of org.eclipse.swt.events.PaintListener in project tdi-studio-se by Talend.

the class Marker method createLineHover.

private void createLineHover(Integer invertedSeriesIndex) {
    if (lineHover == null || lineHover.isDisposed() || !lineHover.isVisible()) {
        lineHover = new Shell(chart.getShell(), SWT.NO_TRIM | SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL | SWT.NO_BACKGROUND);
        lineHover.addPaintListener(new PaintListener() {

            @Override
            public void paintControl(PaintEvent e) {
                e.gc.setLineStyle(SWT.LINE_DOT);
                e.gc.setAntialias(SWT.ON);
                e.gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
                //        			e.gc.fillOval(2-1,150-1, 3, 3);
                e.gc.drawLine(2, 0, 2, chart.getPlotArea().getSize().y);
            }
        });
        lineHover.addMouseTrackListener(new MouseTrackAdapter() {

            @Override
            public void mouseEnter(MouseEvent e) {
                if (!isDisposed()) {
                    setPosition(mouseXPosition);
                }
            }
        });
    }
    lineHover.setSize(4, chart.getPlotArea().getSize().y);
    ISeries largestSeries = getLargestSeries();
    Date[] dates = largestSeries.getXDateSeries();
    long time = dates[dates.length - invertedSeriesIndex].getTime();
    int timeInPixel = chart.getAxisSet().getXAxes()[0].getPixelCoordinate(time);
    lineHover.setLocation(chart.getPlotArea().toDisplay(timeInPixel - 3, 0));
    lineHover.redraw();
    lineHover.setVisible(true);
}
Also used : Shell(org.eclipse.swt.widgets.Shell) PaintEvent(org.eclipse.swt.events.PaintEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) PaintListener(org.eclipse.swt.events.PaintListener) MouseTrackAdapter(org.eclipse.swt.events.MouseTrackAdapter) ISeries(org.swtchart.ISeries) Date(java.util.Date) Point(org.eclipse.swt.graphics.Point)

Example 3 with PaintListener

use of org.eclipse.swt.events.PaintListener in project tdi-studio-se by Talend.

the class TalendEditPartTipHelper method hookShellListeners.

@Override
protected void hookShellListeners() {
    /*
         * If the cursor leaves the tip window, hide the tooltip and dispose of its shell
         */
    getShell().addMouseTrackListener(new MouseTrackAdapter() {

        @Override
        public void mouseExit(MouseEvent e) {
            getShell().setCapture(false);
            dispose();
        }
    });
    /*
         * If the mouseExit listener does not get called, dispose of the shell if the cursor is no longer in the
         * tooltip. This occurs in the rare case that a mouseEnter is not received on the tooltip when it appears.
         */
    getShell().addMouseMoveListener(new MouseMoveListener() {

        @Override
        public void mouseMove(MouseEvent e) {
            Point eventPoint = getShell().toDisplay(new Point(e.x, e.y));
            if (!getShell().getBounds().contains(eventPoint)) {
                if (isShowing()) {
                    getShell().setCapture(false);
                }
                dispose();
            }
        }
    });
    // window.
    if (shellListener == null) {
        shellListener = new ShellAdapter() {

            @Override
            public void shellDeactivated(ShellEvent event) {
                Display.getCurrent().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        Shell active = Display.getCurrent().getActiveShell();
                        if (getShell() == active || control.getShell() == active || getShell().isDisposed()) {
                            return;
                        }
                        if (isShowing()) {
                            getShell().setCapture(false);
                        }
                        dispose();
                    }
                });
            }
        };
        control.getShell().addShellListener(shellListener);
        getShell().addShellListener(shellListener);
    }
    /*
         * Workaround for GTK Bug - Control.setCapture(boolean) not implemented: If the cursor is not over the shell
         * when it is first painted, hide the tooltip and dispose of the shell.
         */
    if (SWT.getPlatform().equals("gtk")) {
        //$NON-NLS-1$
        getShell().addPaintListener(new PaintListener() {

            @Override
            public void paintControl(PaintEvent event) {
                Point cursorLoc = Display.getCurrent().getCursorLocation();
                if (!getShell().getBounds().contains(cursorLoc)) {
                    // This must be run asynchronously. If not, other paint
                    // listeners may attempt to paint on a disposed control.
                    Display.getCurrent().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            if (isShowing()) {
                                getShell().setCapture(false);
                            }
                            dispose();
                        }
                    });
                }
            }
        });
    }
}
Also used : MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) ShellAdapter(org.eclipse.swt.events.ShellAdapter) Shell(org.eclipse.swt.widgets.Shell) MouseEvent(org.eclipse.swt.events.MouseEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) MouseTrackAdapter(org.eclipse.swt.events.MouseTrackAdapter) ShellEvent(org.eclipse.swt.events.ShellEvent) Point(org.eclipse.swt.graphics.Point)

Example 4 with PaintListener

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

the class ReverseConversionWizardPage method createFilesGroup.

/**
	 * 创建文件列表区域
	 * @param contents
	 *            ;
	 */
private Composite createFilesGroup(Composite contents) {
    Composite filesComposite = new Composite(contents, SWT.NONE);
    filesComposite.setLayout(new GridLayout(1, false));
    filesComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
    filesTable = new Table(filesComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
    GridData tableData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
    tableData.heightHint = 100;
    filesTable.setLayoutData(tableData);
    filesTable.setLinesVisible(true);
    filesTable.setHeaderVisible(true);
    filesTable.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            TableItem[] selected = filesTable.getSelection();
            if (selected.length == 0) {
                return;
            }
            //$NON-NLS-1$
            String strTgtEnc = "";
            for (int i = 0; i < selected.length; i++) {
                String curTgtEnc = selected[i].getText(2);
                if (i == 0) {
                    strTgtEnc = curTgtEnc;
                } else {
                    if (!strTgtEnc.equals(curTgtEnc)) {
                        //$NON-NLS-1$
                        strTgtEnc = "";
                        break;
                    }
                }
            }
            if (!"".equals(strTgtEnc)) {
                //$NON-NLS-1$
                tgtEncCombo.setText(strTgtEnc);
            } else {
                tgtEncCombo.deselectAll();
            }
        }
    });
    tableViewer = new TableViewer(filesTable);
    lineNumberColumn = new TableViewerColumn(tableViewer, SWT.NONE).getColumn();
    lineNumberColumn.setText(Messages.getString("wizard.ReverseConversionWizardPage.lineNumberColumn"));
    xliffColumn = new TableViewerColumn(tableViewer, SWT.NONE).getColumn();
    //$NON-NLS-1$
    xliffColumn.setText(Messages.getString("wizard.ReverseConversionWizardPage.xliffColumn"));
    tgtEncColumn = new TableViewerColumn(tableViewer, SWT.NONE).getColumn();
    //$NON-NLS-1$
    tgtEncColumn.setText(Messages.getString("wizard.ReverseConversionWizardPage.tgtEncColumn"));
    targetColumn = new TableViewerColumn(tableViewer, SWT.NONE).getColumn();
    //$NON-NLS-1$
    targetColumn.setText(Messages.getString("wizard.ReverseConversionWizardPage.targetColumn"));
    IValueProperty[] valueProperties = BeanProperties.values(ConversionConfigBean.class, new String[] { "index", "source", "targetEncoding", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    "target" });
    ViewerSupport.bind(tableViewer, new WritableList(conversionConfigBeans, ConversionConfigBean.class), valueProperties);
    filesComposite.addPaintListener(new PaintListener() {

        public void paintControl(PaintEvent arg0) {
            int width = filesTable.getClientArea().width;
            lineNumberColumn.setWidth(width * 1 / 10);
            targetColumn.setWidth(width * 4 / 10);
            tgtEncColumn.setWidth(width * 1 / 10);
            xliffColumn.setWidth(width * 4 / 10);
        }
    });
    return filesComposite;
}
Also used : Table(org.eclipse.swt.widgets.Table) PaintEvent(org.eclipse.swt.events.PaintEvent) Composite(org.eclipse.swt.widgets.Composite) PaintListener(org.eclipse.swt.events.PaintListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridLayout(org.eclipse.swt.layout.GridLayout) WritableList(org.eclipse.core.databinding.observable.list.WritableList) ConversionConfigBean(net.heartsome.cat.convert.ui.model.ConversionConfigBean) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IValueProperty(org.eclipse.core.databinding.property.value.IValueProperty) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 5 with PaintListener

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

the class QueryExecuter method makeResult.

/**
	 * Make query editor result panel,including table panel and sql text and
	 * message text
	 *
	 * @param resultTbl the Table.
	 * @param sqlText the Text.
	 * @param messageText the StyledText.
	 */
public void makeResult(final TableSelectSupport tableSelectSupport, StyledText messageText, boolean multiQueryResult) {
    this.selectableSupport = tableSelectSupport;
    this.tblResult = tableSelectSupport.getTable();
    logMessageText = messageText;
    int[] queryInfoRange = new int[2];
    int[] queryRange = new int[2];
    StringBuilder resultMessage = new StringBuilder();
    resultMessage.append(getQueryMsg() == null ? "" : getQueryMsg().trim());
    queryInfoRange[0] = 0;
    queryInfoRange[1] = resultMessage.length();
    resultMessage.append(StringUtil.NEWLINE).append(QueryUtil.SPLIT_LINE_FOR_QUERY_RESULT).append(StringUtil.NEWLINE);
    queryRange[0] = resultMessage.length();
    resultMessage.append(query);
    queryRange[1] = query.length();
    ServerInfo serverInfo = database.getServer() == null ? null : database.getServer().getServerInfo();
    String fontString = QueryOptions.getFontString(serverInfo);
    Font tmpFont = ResourceManager.getFont(fontString);
    if (tmpFont == null) {
        String[] fontData = QueryOptions.getDefaultFont();
        tmpFont = ResourceManager.getFont(fontData[0], Integer.valueOf(fontData[1]), Integer.valueOf(fontData[2]));
    }
    font = tmpFont;
    tblResult.setFont(font);
    int[] fontColor = QueryOptions.getFontColor(serverInfo);
    color = ResourceManager.getColor(fontColor[0], fontColor[1], fontColor[2]);
    tblResult.setForeground(color);
    // Set font and foreground
    selectableSupport.getTableCursor().setFont(font);
    selectableSupport.getTableCursor().setForeground(color);
    selectableSupport.setShowDetailOperator(this);
    tblResult.addPaintListener(new PaintListener() {

        public void paintControl(PaintEvent e) {
            selectableSupport.redrawMoreButton();
        }
    });
    if (queryEditor != null) {
        if (!multiQueryResult) {
            createContextMenuItems();
        }
        editor = new ControlEditor(selectableSupport.getTableCursor());
        editor.horizontalAlignment = SWT.LEFT;
        editor.grabHorizontal = true;
        editor.grabVertical = true;
        bindEvents();
        addTableItemToolTips();
    }
    makeColumn();
    makeItem();
    if (!StringUtil.isEmpty(queryPlanLog)) {
        resultMessage.append(StringUtil.NEWLINE).append(QueryUtil.SPLIT_LINE_FOR_QUERY_RESULT);
        resultMessage.append(StringUtil.NEWLINE).append(queryPlanLog);
    }
    if (!StringUtil.isEmpty(statsLog)) {
        resultMessage.append(StringUtil.NEWLINE).append(Messages.queryStat).append(":");
        resultMessage.append(StringUtil.NEWLINE).append(QueryUtil.SPLIT_LINE_FOR_QUERY_RESULT);
        resultMessage.append(StringUtil.NEWLINE).append(statsLog);
    }
    messageText.setText(resultMessage.toString());
    // Styled Query info
    StyleRange queryInfoStyle = new StyleRange();
    queryInfoStyle.start = queryInfoRange[0];
    queryInfoStyle.length = queryInfoRange[1];
    queryInfoStyle.fontStyle = SWT.NORMAL;
    queryInfoStyle.foreground = ResourceManager.getColor(SWT.COLOR_BLUE);
    messageText.setStyleRange(queryInfoStyle);
    StyleRange queryStyle = new StyleRange();
    queryStyle.start = queryRange[0];
    queryStyle.length = queryRange[1];
    queryStyle.fontStyle = SWT.BOLD;
    messageText.setStyleRange(queryStyle);
    // styled log text
    updateStyledLogTextForStatistics(messageText);
    updateStyledLogTextForPlan(messageText);
    updateStyledLogTextForTrace(messageText);
}
Also used : ControlEditor(org.eclipse.swt.custom.ControlEditor) PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) StyleRange(org.eclipse.swt.custom.StyleRange) Font(org.eclipse.swt.graphics.Font)

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