Search in sources :

Example 56 with DisposeListener

use of org.eclipse.swt.events.DisposeListener in project yamcs-studio by yamcs.

the class OverviewOutlinePage method createControl.

@Override
public void createControl(Composite parent) {
    overview = new Canvas(parent, SWT.NONE);
    LightweightSystem lws = new LightweightSystem(overview);
    thumbnail = new ScrollableThumbnail((Viewport) rootEP.getFigure());
    thumbnail.setBorder(new MarginBorder(3));
    thumbnail.setSource(rootEP.getLayer(LayerConstants.PRINTABLE_LAYERS));
    lws.setContents(thumbnail);
    disposeListener = new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            if (thumbnail != null) {
                thumbnail.deactivate();
                thumbnail = null;
            }
        }
    };
    rootEP.getViewer().getControl().addDisposeListener(disposeListener);
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) Canvas(org.eclipse.swt.widgets.Canvas) MarginBorder(org.eclipse.draw2d.MarginBorder) Viewport(org.eclipse.draw2d.Viewport) LightweightSystem(org.eclipse.draw2d.LightweightSystem) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ScrollableThumbnail(org.eclipse.draw2d.parts.ScrollableThumbnail)

Example 57 with DisposeListener

use of org.eclipse.swt.events.DisposeListener in project yamcs-studio by yamcs.

the class ContentProposalAdapter method initPopup.

/*
     * Init & open the popup on asynchronous call.
     */
private void initPopup(ContentProposalList proposalList, boolean autoActivated) {
    if (proposalList.fullLength() > 0) {
        if (DEBUG) {
            // $NON-NLS-1$
            System.out.println("POPUP OPENED BY PRECEDING EVENT");
        }
        popup = new ContentProposalPopup(this, null, proposalList);
        popup.open();
        popup.getShell().addDisposeListener(new DisposeListener() {

            public void widgetDisposed(DisposeEvent event) {
                popup = null;
            }
        });
        internalPopupOpened();
        notifyPopupOpened();
    } else if (!autoActivated) {
        getControl().getDisplay().beep();
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) DisposeEvent(org.eclipse.swt.events.DisposeEvent)

Example 58 with DisposeListener

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

the class AboutDialog method createDialogArea.

/**
	 * Creates the page content
	 *
	 * @param parent the parent composite to contain the dialog area
	 * @return the dialog area control
	 */
protected Control createDialogArea(Composite parent) {
    final Cursor hand = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND);
    final Cursor busy = new Cursor(parent.getDisplay(), SWT.CURSOR_WAIT);
    setHandCursor(hand);
    setBusyCursor(busy);
    getShell().addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent event) {
            setHandCursor(null);
            hand.dispose();
            setBusyCursor(null);
            busy.dispose();
        }
    });
    // brand the about box if there is product info
    Image aboutImage = null;
    if (product != null && aboutImageDescriptor != null) {
        aboutImage = aboutImageDescriptor.createImage();
    }
    Composite workArea = new Composite(parent, SWT.NONE);
    GridLayout workLayout = new GridLayout();
    workLayout.marginHeight = 0;
    workLayout.marginWidth = 0;
    workLayout.verticalSpacing = 0;
    workLayout.horizontalSpacing = 0;
    workArea.setLayout(workLayout);
    workArea.setLayoutData(new GridData(GridData.FILL_BOTH));
    // page group
    Color background = JFaceColors.getBannerBackground(parent.getDisplay());
    Color foreground = JFaceColors.getBannerForeground(parent.getDisplay());
    Composite top = (Composite) super.createDialogArea(workArea);
    // override any layout inherited from createDialogArea
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.verticalSpacing = 0;
    layout.horizontalSpacing = 0;
    top.setLayout(layout);
    top.setLayoutData(new GridData(GridData.FILL_BOTH));
    top.setBackground(background);
    top.setForeground(foreground);
    // the image & text
    Composite topContainer = new Composite(top, SWT.NONE);
    topContainer.setBackground(background);
    topContainer.setForeground(foreground);
    layout = new GridLayout();
    layout.numColumns = (aboutImage == null || getItem() == null ? 1 : 2);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.verticalSpacing = 0;
    layout.horizontalSpacing = 0;
    topContainer.setLayout(layout);
    GridData data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.grabExcessHorizontalSpace = true;
    topContainer.setLayoutData(data);
    // image on left side of dialog
    if (aboutImage != null) {
        Label imageLabel = new Label(topContainer, SWT.NONE);
        imageLabel.setBackground(background);
        imageLabel.setForeground(foreground);
        data = new GridData();
        data.horizontalAlignment = GridData.FILL;
        data.verticalAlignment = GridData.BEGINNING;
        data.grabExcessHorizontalSpace = false;
        imageLabel.setLayoutData(data);
        imageLabel.setImage(aboutImage);
    }
    if (getItem() != null) {
        Composite textContainer = new Composite(topContainer, SWT.NONE);
        textContainer.setBackground(background);
        textContainer.setForeground(foreground);
        layout = new GridLayout();
        layout.numColumns = 1;
        textContainer.setLayout(layout);
        data = new GridData();
        data.horizontalAlignment = GridData.FILL;
        data.verticalAlignment = GridData.BEGINNING;
        data.grabExcessHorizontalSpace = true;
        textContainer.setLayoutData(data);
        // text on the right
        text = new StyledText(textContainer, SWT.MULTI | SWT.READ_ONLY);
        text.setCaret(null);
        text.setFont(parent.getFont());
        data = new GridData();
        data.horizontalAlignment = GridData.FILL;
        data.verticalAlignment = GridData.BEGINNING;
        data.grabExcessHorizontalSpace = true;
        text.setText(getItem().getText());
        text.setLayoutData(data);
        text.setCursor(null);
        text.setBackground(background);
        text.setForeground(foreground);
        setLinkRanges(text, getItem().getLinkRanges());
        addListeners(text);
    }
    // horizontal bar
    Label bar = new Label(workArea, SWT.HORIZONTAL | SWT.SEPARATOR);
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    bar.setLayoutData(data);
    // add image buttons for bundle groups that have them
    Composite bottom = (Composite) super.createDialogArea(workArea);
    // override any layout inherited from createDialogArea
    layout = new GridLayout();
    bottom.setLayout(layout);
    bottom.setLayoutData(new GridData(GridData.FILL_BOTH));
    // spacer
    bar = new Label(bottom, SWT.NONE);
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    bar.setLayoutData(data);
    return workArea;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) GridLayout(org.eclipse.swt.layout.GridLayout) StyledText(org.eclipse.swt.custom.StyledText) Composite(org.eclipse.swt.widgets.Composite) Color(org.eclipse.swt.graphics.Color) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) Cursor(org.eclipse.swt.graphics.Cursor) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Image(org.eclipse.swt.graphics.Image)

Example 59 with DisposeListener

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

the class StyleTextCellRenderer method draw.

public void draw(GC gc, JaretTable jaretTable, ICellStyle cellStyle, Rectangle drawingArea, IRow row, IColumn column, boolean drawFocus, boolean selected, boolean printing) {
    super.draw(gc, jaretTable, cellStyle, drawingArea, row, column, drawFocus, selected, printing);
    // Color bg = gc.getBackground();
    // Color fg = gc.getForeground();
    Rectangle drect = drawBorder(gc, cellStyle, drawingArea, printing);
    Rectangle rect = applyInsets(drect);
    String s = convertValue(row, column);
    if (s != null && strStyleText != null && !strStyleText.equals("")) {
        if (selected && !printing) {
            Color color = ColorManager.getColorManager(Display.getCurrent()).getColor(new RGB(218, 218, 218));
            gc.setBackground(color);
        } else {
            gc.setBackground(getBackgroundColor(cellStyle, printing));
        }
        if (textLayout == null) {
            textLayout = new TextLayout(gc.getDevice());
            jaretTable.getParent().addDisposeListener(new DisposeListener() {

                public void widgetDisposed(DisposeEvent e) {
                    textLayout.dispose();
                }
            });
        }
        textLayout.setOrientation(jaretTable.getOrientation());
        textLayout.setText(s);
        textLayout.setFont(gc.getFont());
        textLayout.setWidth(rect.width);
        if (blnIsApplyRegular) {
            Pattern pattern = null;
            if (blnIsCaseSensitive) {
                pattern = Pattern.compile(strStyleText);
            } else {
                pattern = Pattern.compile(strStyleText, Pattern.CASE_INSENSITIVE);
            }
            Matcher matcher = pattern.matcher(s);
            while (matcher.find()) {
                textLayout.setStyle(style, matcher.start(), matcher.end() - 1);
            }
            gc.fillRectangle(rect);
            textLayout.draw(gc, rect.x, rect.y);
            gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_FOREGROUND));
        } else {
            int index = -1;
            if (!blnIsCaseSensitive) {
                index = s.toUpperCase().indexOf(strStyleText.toUpperCase());
            } else {
                index = s.indexOf(strStyleText);
            }
            if (index != -1) {
                for (int i = 1; i < s.length(); i++) {
                    int j = TextUtil.indexOf(s, strStyleText, i, blnIsCaseSensitive);
                    if (j != -1) {
                        textLayout.setStyle(style, j, j + strStyleText.length() - 1);
                    } else {
                        break;
                    }
                }
                gc.fillRectangle(rect);
                textLayout.draw(gc, rect.x, rect.y);
                gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_FOREGROUND));
            }
        }
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle) RGB(org.eclipse.swt.graphics.RGB) DisposeEvent(org.eclipse.swt.events.DisposeEvent) TextLayout(org.eclipse.swt.graphics.TextLayout)

Example 60 with DisposeListener

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

the class ProjectSettingDialog method createHelpControl.

/**
	 * 添加帮助按钮
	 * robert	2012-09-06
	 */
@Override
protected Control createHelpControl(Composite parent) {
    // ROBERTHELP 项目设置
    String language = CommonFunction.getSystemLanguage();
    final String helpUrl = MessageFormat.format("/net.heartsome.cat.ts.ui.help/html/{0}/ch05s03.html#project-setting", language);
    Image helpImage = JFaceResources.getImage(DLG_IMG_HELP);
    ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS);
    ((GridLayout) parent.getLayout()).numColumns++;
    toolBar.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
    final Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND);
    toolBar.setCursor(cursor);
    toolBar.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            cursor.dispose();
        }
    });
    ToolItem helpItem = new ToolItem(toolBar, SWT.NONE);
    helpItem.setImage(helpImage);
    //$NON-NLS-1$
    helpItem.setToolTipText(JFaceResources.getString("helpToolTip"));
    helpItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            PlatformUI.getWorkbench().getHelpSystem().displayHelpResource(helpUrl);
        }
    });
    return toolBar;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ToolBar(org.eclipse.swt.widgets.ToolBar) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Image(org.eclipse.swt.graphics.Image) Cursor(org.eclipse.swt.graphics.Cursor) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ToolItem(org.eclipse.swt.widgets.ToolItem)

Aggregations

DisposeListener (org.eclipse.swt.events.DisposeListener)118 DisposeEvent (org.eclipse.swt.events.DisposeEvent)117 SelectionEvent (org.eclipse.swt.events.SelectionEvent)41 GridData (org.eclipse.swt.layout.GridData)38 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)33 Image (org.eclipse.swt.graphics.Image)29 Cursor (org.eclipse.swt.graphics.Cursor)26 ToolBar (org.eclipse.swt.widgets.ToolBar)25 ToolItem (org.eclipse.swt.widgets.ToolItem)23 Composite (org.eclipse.swt.widgets.Composite)19 Color (org.eclipse.swt.graphics.Color)17 GridLayout (org.eclipse.swt.layout.GridLayout)17 Point (org.eclipse.swt.graphics.Point)16 ControlEvent (org.eclipse.swt.events.ControlEvent)11 SelectionListener (org.eclipse.swt.events.SelectionListener)10 Control (org.eclipse.swt.widgets.Control)10 TextLayout (org.eclipse.swt.graphics.TextLayout)9 Listener (org.eclipse.swt.widgets.Listener)9 ControlListener (org.eclipse.swt.events.ControlListener)8 MouseEvent (org.eclipse.swt.events.MouseEvent)8