Search in sources :

Example 81 with PaintEvent

use of org.eclipse.swt.events.PaintEvent in project pentaho-kettle by pentaho.

the class EnterOptionsDialog method addLookTab.

private void addLookTab() {
    int h = 40;
    // ////////////////////////
    // START OF LOOK TAB///
    // /
    wLookTab = new CTabItem(wTabFolder, SWT.NONE);
    wLookTab.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.LookAndFeel.Label"));
    sLookComp = new ScrolledComposite(wTabFolder, SWT.V_SCROLL | SWT.H_SCROLL);
    sLookComp.setLayout(new FillLayout());
    wLookComp = new Composite(sLookComp, SWT.NONE);
    props.setLook(wLookComp);
    FormLayout lookLayout = new FormLayout();
    lookLayout.marginWidth = 3;
    lookLayout.marginHeight = 3;
    wLookComp.setLayout(lookLayout);
    // Fixed font
    int nr = 0;
    Label wlFFont = new Label(wLookComp, SWT.RIGHT);
    wlFFont.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.FixedWidthFont.Label"));
    props.setLook(wlFFont);
    FormData fdlFFont = new FormData();
    fdlFFont.left = new FormAttachment(0, 0);
    fdlFFont.right = new FormAttachment(middle, -margin);
    fdlFFont.top = new FormAttachment(0, nr * h + margin + 10);
    wlFFont.setLayoutData(fdlFFont);
    wdFFont = new Button(wLookComp, SWT.PUSH | SWT.CENTER);
    props.setLook(wdFFont);
    FormData fddFFont = layoutResetOptionButton(wdFFont);
    fddFFont.right = new FormAttachment(100, 0);
    fddFFont.top = new FormAttachment(0, nr * h + margin);
    fddFFont.bottom = new FormAttachment(0, (nr + 1) * h + margin);
    wdFFont.setLayoutData(fddFFont);
    wdFFont.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            fixedFontData = new FontData(PropsUI.getInstance().getFixedFont().getName(), PropsUI.getInstance().getFixedFont().getHeight(), PropsUI.getInstance().getFixedFont().getStyle());
            fixedFont.dispose();
            fixedFont = new Font(display, fixedFontData);
            wFFont.redraw();
        }
    });
    wbFFont = new Button(wLookComp, SWT.PUSH);
    props.setLook(wbFFont);
    FormData fdbFFont = layoutEditOptionButton(wbFFont);
    fdbFFont.right = new FormAttachment(wdFFont, -margin);
    fdbFFont.top = new FormAttachment(0, nr * h + margin);
    fdbFFont.bottom = new FormAttachment(0, (nr + 1) * h + margin);
    wbFFont.setLayoutData(fdbFFont);
    wbFFont.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            FontDialog fd = new FontDialog(shell);
            fd.setFontList(new FontData[] { fixedFontData });
            FontData newfd = fd.open();
            if (newfd != null) {
                fixedFontData = newfd;
                fixedFont.dispose();
                fixedFont = new Font(display, fixedFontData);
                wFFont.redraw();
            }
        }
    });
    wFFont = new Canvas(wLookComp, SWT.BORDER);
    props.setLook(wFFont);
    FormData fdFFont = new FormData();
    fdFFont.left = new FormAttachment(middle, 0);
    fdFFont.right = new FormAttachment(wbFFont, -margin);
    fdFFont.top = new FormAttachment(0, margin);
    fdFFont.bottom = new FormAttachment(0, h);
    wFFont.setLayoutData(fdFFont);
    wFFont.addPaintListener(new PaintListener() {

        public void paintControl(PaintEvent pe) {
            pe.gc.setFont(fixedFont);
            Rectangle max = wFFont.getBounds();
            String name = fixedFontData.getName() + " - " + fixedFontData.getHeight();
            Point size = pe.gc.textExtent(name);
            pe.gc.drawText(name, (max.width - size.x) / 2, (max.height - size.y) / 2, true);
        }
    });
    // Graph font
    nr++;
    Label wlGFont = new Label(wLookComp, SWT.RIGHT);
    wlGFont.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.GraphFont.Label"));
    props.setLook(wlGFont);
    FormData fdlGFont = new FormData();
    fdlGFont.left = new FormAttachment(0, 0);
    fdlGFont.right = new FormAttachment(middle, -margin);
    fdlGFont.top = new FormAttachment(0, nr * h + margin + 10);
    wlGFont.setLayoutData(fdlGFont);
    wdGFont = new Button(wLookComp, SWT.PUSH);
    props.setLook(wdGFont);
    FormData fddGFont = layoutResetOptionButton(wdGFont);
    fddGFont.right = new FormAttachment(100, 0);
    fddGFont.top = new FormAttachment(0, nr * h + margin);
    fddGFont.bottom = new FormAttachment(0, (nr + 1) * h + margin);
    wdGFont.setLayoutData(fddGFont);
    wdGFont.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            graphFont.dispose();
            graphFontData = props.getDefaultFontData();
            graphFont = new Font(display, graphFontData);
            wGFont.redraw();
        }
    });
    wbGFont = new Button(wLookComp, SWT.PUSH);
    props.setLook(wbGFont);
    FormData fdbGFont = layoutEditOptionButton(wbGFont);
    fdbGFont.right = new FormAttachment(wdGFont, -margin);
    fdbGFont.top = new FormAttachment(0, nr * h + margin);
    fdbGFont.bottom = new FormAttachment(0, (nr + 1) * h + margin);
    wbGFont.setLayoutData(fdbGFont);
    wbGFont.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            FontDialog fd = new FontDialog(shell);
            fd.setFontList(new FontData[] { graphFontData });
            FontData newfd = fd.open();
            if (newfd != null) {
                graphFontData = newfd;
                graphFont.dispose();
                graphFont = new Font(display, graphFontData);
                wGFont.redraw();
            }
        }
    });
    wGFont = new Canvas(wLookComp, SWT.BORDER);
    props.setLook(wGFont);
    FormData fdGFont = new FormData();
    fdGFont.left = new FormAttachment(middle, 0);
    fdGFont.right = new FormAttachment(wbGFont, -margin);
    fdGFont.top = new FormAttachment(0, nr * h + margin);
    fdGFont.bottom = new FormAttachment(0, (nr + 1) * h + margin);
    wGFont.setLayoutData(fdGFont);
    wGFont.addPaintListener(new PaintListener() {

        public void paintControl(PaintEvent pe) {
            pe.gc.setFont(graphFont);
            Rectangle max = wGFont.getBounds();
            String name = graphFontData.getName() + " - " + graphFontData.getHeight();
            Point size = pe.gc.textExtent(name);
            pe.gc.drawText(name, (max.width - size.x) / 2, (max.height - size.y) / 2, true);
        }
    });
    // Note font
    nr++;
    Label wlNFont = new Label(wLookComp, SWT.RIGHT);
    wlNFont.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.NoteFont.Label"));
    props.setLook(wlNFont);
    FormData fdlNFont = new FormData();
    fdlNFont.left = new FormAttachment(0, 0);
    fdlNFont.right = new FormAttachment(middle, -margin);
    fdlNFont.top = new FormAttachment(0, nr * h + margin + 10);
    wlNFont.setLayoutData(fdlNFont);
    wdNFont = new Button(wLookComp, SWT.PUSH);
    props.setLook(wdNFont);
    FormData fddNFont = layoutResetOptionButton(wdNFont);
    fddNFont.right = new FormAttachment(100, 0);
    fddNFont.top = new FormAttachment(0, nr * h + margin);
    fddNFont.bottom = new FormAttachment(0, (nr + 1) * h + margin);
    wdNFont.setLayoutData(fddNFont);
    wdNFont.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            noteFontData = props.getDefaultFontData();
            noteFont.dispose();
            noteFont = new Font(display, noteFontData);
            wNFont.redraw();
        }
    });
    wbNFont = new Button(wLookComp, SWT.PUSH);
    props.setLook(wbNFont);
    FormData fdbNFont = layoutEditOptionButton(wbNFont);
    fdbNFont.right = new FormAttachment(wdNFont, -margin);
    fdbNFont.top = new FormAttachment(0, nr * h + margin);
    fdbNFont.bottom = new FormAttachment(0, (nr + 1) * h + margin);
    wbNFont.setLayoutData(fdbNFont);
    wbNFont.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            FontDialog fd = new FontDialog(shell);
            fd.setFontList(new FontData[] { noteFontData });
            FontData newfd = fd.open();
            if (newfd != null) {
                noteFontData = newfd;
                noteFont.dispose();
                noteFont = new Font(display, noteFontData);
                wNFont.redraw();
            }
        }
    });
    wNFont = new Canvas(wLookComp, SWT.BORDER);
    props.setLook(wNFont);
    FormData fdNFont = new FormData();
    fdNFont.left = new FormAttachment(middle, 0);
    fdNFont.right = new FormAttachment(wbNFont, -margin);
    fdNFont.top = new FormAttachment(0, nr * h + margin);
    fdNFont.bottom = new FormAttachment(0, (nr + 1) * h + margin);
    wNFont.setLayoutData(fdNFont);
    wNFont.addPaintListener(new PaintListener() {

        public void paintControl(PaintEvent pe) {
            pe.gc.setFont(noteFont);
            Rectangle max = wNFont.getBounds();
            String name = noteFontData.getName() + " - " + noteFontData.getHeight();
            Point size = pe.gc.textExtent(name);
            pe.gc.drawText(name, (max.width - size.x) / 2, (max.height - size.y) / 2, true);
        }
    });
    // Background color
    nr++;
    Label wlBGColor = new Label(wLookComp, SWT.RIGHT);
    wlBGColor.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.BackgroundColor.Label"));
    props.setLook(wlBGColor);
    FormData fdlBGColor = new FormData();
    fdlBGColor.left = new FormAttachment(0, 0);
    fdlBGColor.right = new FormAttachment(middle, -margin);
    fdlBGColor.top = new FormAttachment(0, nr * h + margin + 10);
    wlBGColor.setLayoutData(fdlBGColor);
    wdBGcolor = new Button(wLookComp, SWT.PUSH);
    props.setLook(wdBGcolor);
    FormData fddBGColor = layoutResetOptionButton(wdBGcolor);
    // to the right of the
    fddBGColor.right = new FormAttachment(100, 0);
    // dialog
    fddBGColor.top = new FormAttachment(0, nr * h + margin);
    fddBGColor.bottom = new FormAttachment(0, (nr + 1) * h + margin);
    wdBGcolor.setLayoutData(fddBGColor);
    wdBGcolor.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            background.dispose();
            backgroundRGB = new RGB(ConstUI.COLOR_BACKGROUND_RED, ConstUI.COLOR_BACKGROUND_GREEN, ConstUI.COLOR_BACKGROUND_BLUE);
            background = new Color(display, backgroundRGB);
            wBGColor.setBackground(background);
            wBGColor.redraw();
        }
    });
    wbBGColor = new Button(wLookComp, SWT.PUSH);
    props.setLook(wbBGColor);
    FormData fdbBGColor = layoutEditOptionButton(wbBGColor);
    // to the
    fdbBGColor.right = new FormAttachment(wdBGcolor, -margin);
    // left of
    // the
    // "default"
    // button
    fdbBGColor.top = new FormAttachment(0, nr * h + margin);
    fdbBGColor.bottom = new FormAttachment(0, (nr + 1) * h + margin);
    wbBGColor.setLayoutData(fdbBGColor);
    wbBGColor.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            ColorDialog cd = new ColorDialog(shell);
            cd.setRGB(props.getBackgroundRGB());
            RGB newbg = cd.open();
            if (newbg != null) {
                backgroundRGB = newbg;
                background.dispose();
                background = new Color(display, backgroundRGB);
                wBGColor.setBackground(background);
                wBGColor.redraw();
            }
        }
    });
    wBGColor = new Canvas(wLookComp, SWT.BORDER);
    props.setLook(wBGColor);
    wBGColor.setBackground(background);
    FormData fdBGColor = new FormData();
    fdBGColor.left = new FormAttachment(middle, 0);
    fdBGColor.right = new FormAttachment(wbBGColor, -margin);
    fdBGColor.top = new FormAttachment(0, nr * h + margin);
    fdBGColor.bottom = new FormAttachment(0, (nr + 1) * h + margin);
    wBGColor.setLayoutData(fdBGColor);
    // Graph background color
    nr++;
    Label wlGrColor = new Label(wLookComp, SWT.RIGHT);
    wlGrColor.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.BackgroundColorGraph.Label"));
    props.setLook(wlGrColor);
    FormData fdlGrColor = new FormData();
    fdlGrColor.left = new FormAttachment(0, 0);
    fdlGrColor.right = new FormAttachment(middle, -margin);
    fdlGrColor.top = new FormAttachment(0, nr * h + margin + 10);
    wlGrColor.setLayoutData(fdlGrColor);
    wdGrColor = new Button(wLookComp, SWT.PUSH);
    props.setLook(wdGrColor);
    FormData fddGrColor = layoutResetOptionButton(wdGrColor);
    fddGrColor.right = new FormAttachment(100, 0);
    fddGrColor.top = new FormAttachment(0, nr * h + margin);
    fddGrColor.bottom = new FormAttachment(0, (nr + 1) * h + margin);
    wdGrColor.setLayoutData(fddGrColor);
    wdGrColor.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            graphColor.dispose();
            graphColorRGB = new RGB(ConstUI.COLOR_GRAPH_RED, ConstUI.COLOR_GRAPH_GREEN, ConstUI.COLOR_GRAPH_BLUE);
            graphColor = new Color(display, graphColorRGB);
            wGrColor.setBackground(graphColor);
            wGrColor.redraw();
        }
    });
    wbGrColor = new Button(wLookComp, SWT.PUSH);
    props.setLook(wbGrColor);
    FormData fdbGrColor = layoutEditOptionButton(wbGrColor);
    fdbGrColor.right = new FormAttachment(wdGrColor, -margin);
    fdbGrColor.top = new FormAttachment(0, nr * h + margin);
    fdbGrColor.bottom = new FormAttachment(0, (nr + 1) * h + margin);
    wbGrColor.setLayoutData(fdbGrColor);
    wbGrColor.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            ColorDialog cd = new ColorDialog(shell);
            cd.setRGB(props.getGraphColorRGB());
            RGB newbg = cd.open();
            if (newbg != null) {
                graphColorRGB = newbg;
                graphColor.dispose();
                graphColor = new Color(display, graphColorRGB);
                wGrColor.setBackground(graphColor);
                wGrColor.redraw();
            }
        }
    });
    wGrColor = new Canvas(wLookComp, SWT.BORDER);
    props.setLook(wGrColor);
    wGrColor.setBackground(graphColor);
    FormData fdGrColor = new FormData();
    fdGrColor.left = new FormAttachment(middle, 0);
    fdGrColor.right = new FormAttachment(wbGrColor, -margin);
    fdGrColor.top = new FormAttachment(0, nr * h + margin);
    fdGrColor.bottom = new FormAttachment(0, (nr + 1) * h + margin);
    wGrColor.setLayoutData(fdGrColor);
    // Tab selected color
    nr++;
    Label wlTabColor = new Label(wLookComp, SWT.RIGHT);
    wlTabColor.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.TabColor.Label"));
    props.setLook(wlTabColor);
    FormData fdlTabColor = new FormData();
    fdlTabColor.left = new FormAttachment(0, 0);
    fdlTabColor.right = new FormAttachment(middle, -margin);
    fdlTabColor.top = new FormAttachment(0, nr * h + margin + 10);
    wlTabColor.setLayoutData(fdlTabColor);
    wdTabColor = new Button(wLookComp, SWT.PUSH | SWT.CENTER);
    props.setLook(wdTabColor);
    FormData fddTabColor = layoutResetOptionButton(wdTabColor);
    fddTabColor.right = new FormAttachment(100, 0);
    fddTabColor.top = new FormAttachment(0, nr * h + margin);
    fddTabColor.bottom = new FormAttachment(0, (nr + 1) * h + margin);
    wdTabColor.setLayoutData(fddTabColor);
    wdTabColor.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            tabColor.dispose();
            tabColorRGB = new RGB(ConstUI.COLOR_TAB_RED, ConstUI.COLOR_TAB_GREEN, ConstUI.COLOR_TAB_BLUE);
            tabColor = new Color(display, tabColorRGB);
            wTabColor.setBackground(tabColor);
            wTabColor.redraw();
        }
    });
    wbTabColor = new Button(wLookComp, SWT.PUSH);
    props.setLook(wbTabColor);
    FormData fdbTabColor = layoutEditOptionButton(wbTabColor);
    fdbTabColor.right = new FormAttachment(wdTabColor, -margin);
    fdbTabColor.top = new FormAttachment(0, nr * h + margin);
    fdbTabColor.bottom = new FormAttachment(0, (nr + 1) * h + margin);
    wbTabColor.setLayoutData(fdbTabColor);
    wbTabColor.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            ColorDialog cd = new ColorDialog(shell);
            cd.setRGB(props.getTabColorRGB());
            RGB newbg = cd.open();
            if (newbg != null) {
                tabColorRGB = newbg;
                tabColor.dispose();
                tabColor = new Color(display, tabColorRGB);
                wTabColor.setBackground(tabColor);
                wTabColor.redraw();
            }
        }
    });
    wTabColor = new Canvas(wLookComp, SWT.BORDER);
    props.setLook(wTabColor);
    wTabColor.setBackground(tabColor);
    FormData fdTabColor = new FormData();
    fdTabColor.left = new FormAttachment(middle, 0);
    fdTabColor.right = new FormAttachment(wbTabColor, -margin);
    fdTabColor.top = new FormAttachment(0, nr * h + margin);
    fdTabColor.bottom = new FormAttachment(0, (nr + 1) * h + margin);
    wTabColor.setLayoutData(fdTabColor);
    // Iconsize line
    Label wlIconsize = new Label(wLookComp, SWT.RIGHT);
    wlIconsize.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.IconSize.Label"));
    props.setLook(wlIconsize);
    FormData fdlIconsize = new FormData();
    fdlIconsize.left = new FormAttachment(0, 0);
    fdlIconsize.right = new FormAttachment(middle, -margin);
    fdlIconsize.top = new FormAttachment(wTabColor, margin);
    wlIconsize.setLayoutData(fdlIconsize);
    wIconsize = new Text(wLookComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wIconsize.setText(Integer.toString(props.getIconSize()));
    props.setLook(wIconsize);
    FormData fdIconsize = new FormData();
    fdIconsize.left = new FormAttachment(middle, 0);
    fdIconsize.right = new FormAttachment(100, -margin);
    fdIconsize.top = new FormAttachment(wTabColor, margin);
    wIconsize.setLayoutData(fdIconsize);
    // LineWidth line
    Label wlLineWidth = new Label(wLookComp, SWT.RIGHT);
    wlLineWidth.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.LineWidth.Label"));
    props.setLook(wlLineWidth);
    FormData fdlLineWidth = new FormData();
    fdlLineWidth.left = new FormAttachment(0, 0);
    fdlLineWidth.right = new FormAttachment(middle, -margin);
    fdlLineWidth.top = new FormAttachment(wIconsize, margin);
    wlLineWidth.setLayoutData(fdlLineWidth);
    wLineWidth = new Text(wLookComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wLineWidth.setText(Integer.toString(props.getLineWidth()));
    props.setLook(wLineWidth);
    FormData fdLineWidth = new FormData();
    fdLineWidth.left = new FormAttachment(middle, 0);
    fdLineWidth.right = new FormAttachment(100, -margin);
    fdLineWidth.top = new FormAttachment(wIconsize, margin);
    wLineWidth.setLayoutData(fdLineWidth);
    // ShadowSize line
    Label wlShadowSize = new Label(wLookComp, SWT.RIGHT);
    wlShadowSize.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.ShadowSize.Label"));
    props.setLook(wlShadowSize);
    FormData fdlShadowSize = new FormData();
    fdlShadowSize.left = new FormAttachment(0, 0);
    fdlShadowSize.right = new FormAttachment(middle, -margin);
    fdlShadowSize.top = new FormAttachment(wLineWidth, margin);
    wlShadowSize.setLayoutData(fdlShadowSize);
    wShadowSize = new Text(wLookComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wShadowSize.setText(Integer.toString(props.getShadowSize()));
    props.setLook(wShadowSize);
    FormData fdShadowSize = new FormData();
    fdShadowSize.left = new FormAttachment(middle, 0);
    fdShadowSize.right = new FormAttachment(100, -margin);
    fdShadowSize.top = new FormAttachment(wLineWidth, margin);
    wShadowSize.setLayoutData(fdShadowSize);
    // MiddlePct line
    Label wlMiddlePct = new Label(wLookComp, SWT.RIGHT);
    wlMiddlePct.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.DialogMiddlePercentage.Label"));
    props.setLook(wlMiddlePct);
    FormData fdlMiddlePct = new FormData();
    fdlMiddlePct.left = new FormAttachment(0, 0);
    fdlMiddlePct.right = new FormAttachment(middle, -margin);
    fdlMiddlePct.top = new FormAttachment(wShadowSize, margin);
    wlMiddlePct.setLayoutData(fdlMiddlePct);
    wMiddlePct = new Text(wLookComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wMiddlePct.setText(Integer.toString(props.getMiddlePct()));
    props.setLook(wMiddlePct);
    FormData fdMiddlePct = new FormData();
    fdMiddlePct.left = new FormAttachment(middle, 0);
    fdMiddlePct.right = new FormAttachment(100, -margin);
    fdMiddlePct.top = new FormAttachment(wShadowSize, margin);
    wMiddlePct.setLayoutData(fdMiddlePct);
    // GridSize line
    Label wlGridSize = new Label(wLookComp, SWT.RIGHT);
    wlGridSize.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.GridSize.Label"));
    wlGridSize.setToolTipText(BaseMessages.getString(PKG, "EnterOptionsDialog.GridSize.ToolTip"));
    props.setLook(wlGridSize);
    FormData fdlGridSize = new FormData();
    fdlGridSize.left = new FormAttachment(0, 0);
    fdlGridSize.right = new FormAttachment(middle, -margin);
    fdlGridSize.top = new FormAttachment(wMiddlePct, margin);
    wlGridSize.setLayoutData(fdlGridSize);
    wGridSize = new Text(wLookComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wGridSize.setText(Integer.toString(props.getCanvasGridSize()));
    wGridSize.setToolTipText(BaseMessages.getString(PKG, "EnterOptionsDialog.GridSize.ToolTip"));
    props.setLook(wGridSize);
    FormData fdGridSize = new FormData();
    fdGridSize.left = new FormAttachment(middle, 0);
    fdGridSize.right = new FormAttachment(100, -margin);
    fdGridSize.top = new FormAttachment(wMiddlePct, margin);
    wGridSize.setLayoutData(fdGridSize);
    // Show Canvas Grid
    Label wlShowCanvasGrid = new Label(wLookComp, SWT.RIGHT);
    wlShowCanvasGrid.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.ShowCanvasGrid.Label"));
    wlShowCanvasGrid.setToolTipText(BaseMessages.getString(PKG, "EnterOptionsDialog.ShowCanvasGrid.ToolTip"));
    props.setLook(wlShowCanvasGrid);
    FormData fdlShowCanvasGrid = new FormData();
    fdlShowCanvasGrid.left = new FormAttachment(0, 0);
    fdlShowCanvasGrid.right = new FormAttachment(middle, -margin);
    fdlShowCanvasGrid.top = new FormAttachment(wGridSize, margin);
    wlShowCanvasGrid.setLayoutData(fdlShowCanvasGrid);
    wShowCanvasGrid = new Button(wLookComp, SWT.CHECK);
    props.setLook(wShowCanvasGrid);
    wShowCanvasGrid.setSelection(props.isShowCanvasGridEnabled());
    FormData fdShowCanvasGrid = new FormData();
    fdShowCanvasGrid.left = new FormAttachment(middle, 0);
    fdShowCanvasGrid.right = new FormAttachment(100, -margin);
    fdShowCanvasGrid.top = new FormAttachment(wGridSize, margin);
    wShowCanvasGrid.setLayoutData(fdShowCanvasGrid);
    // Enable anti-aliasing
    Label wlAntiAlias = new Label(wLookComp, SWT.RIGHT);
    wlAntiAlias.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.CanvasAntiAliasing.Label"));
    props.setLook(wlAntiAlias);
    FormData fdlAntiAlias = new FormData();
    fdlAntiAlias.left = new FormAttachment(0, 0);
    fdlAntiAlias.top = new FormAttachment(wShowCanvasGrid, margin);
    fdlAntiAlias.right = new FormAttachment(middle, -margin);
    wlAntiAlias.setLayoutData(fdlAntiAlias);
    wAntiAlias = new Button(wLookComp, SWT.CHECK);
    props.setLook(wAntiAlias);
    wAntiAlias.setSelection(props.isAntiAliasingEnabled());
    FormData fdAntiAlias = new FormData();
    fdAntiAlias.left = new FormAttachment(middle, 0);
    fdAntiAlias.top = new FormAttachment(wShowCanvasGrid, margin);
    fdAntiAlias.right = new FormAttachment(100, 0);
    wAntiAlias.setLayoutData(fdAntiAlias);
    // Enable anti-aliasing
    Label wlIndicateSlowSteps = new Label(wLookComp, SWT.RIGHT);
    wlIndicateSlowSteps.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.CanvasIndicateSlowSteps.Label"));
    props.setLook(wlIndicateSlowSteps);
    FormData fdlIndicateSlowSteps = new FormData();
    fdlIndicateSlowSteps.left = new FormAttachment(0, 0);
    fdlIndicateSlowSteps.top = new FormAttachment(wAntiAlias, margin);
    fdlIndicateSlowSteps.right = new FormAttachment(middle, -margin);
    wlIndicateSlowSteps.setLayoutData(fdlIndicateSlowSteps);
    wIndicateSlowSteps = new Button(wLookComp, SWT.CHECK);
    props.setLook(wIndicateSlowSteps);
    wIndicateSlowSteps.setSelection(props.isIndicateSlowTransStepsEnabled());
    wIndicateSlowSteps.setToolTipText(BaseMessages.getString(PKG, "EnterOptionsDialog.CanvasIndicateSlowSteps.Tooltip"));
    FormData fdIndicateSlowSteps = new FormData();
    fdIndicateSlowSteps.left = new FormAttachment(middle, 0);
    fdIndicateSlowSteps.top = new FormAttachment(wAntiAlias, margin);
    fdIndicateSlowSteps.right = new FormAttachment(100, 0);
    wIndicateSlowSteps.setLayoutData(fdIndicateSlowSteps);
    // Show original look
    Label wlOriginalLook = new Label(wLookComp, SWT.RIGHT);
    wlOriginalLook.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.UseOSLook.Label"));
    props.setLook(wlOriginalLook);
    FormData fdlOriginalLook = new FormData();
    fdlOriginalLook.left = new FormAttachment(0, 0);
    fdlOriginalLook.top = new FormAttachment(wIndicateSlowSteps, margin);
    fdlOriginalLook.right = new FormAttachment(middle, -margin);
    wlOriginalLook.setLayoutData(fdlOriginalLook);
    wOriginalLook = new Button(wLookComp, SWT.CHECK);
    props.setLook(wOriginalLook);
    wOriginalLook.setSelection(props.isOSLookShown());
    FormData fdOriginalLook = new FormData();
    fdOriginalLook.left = new FormAttachment(middle, 0);
    fdOriginalLook.top = new FormAttachment(wIndicateSlowSteps, margin);
    fdOriginalLook.right = new FormAttachment(100, 0);
    wOriginalLook.setLayoutData(fdOriginalLook);
    // Show branding graphics
    Label wlBranding = new Label(wLookComp, SWT.RIGHT);
    wlBranding.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.Branding.Label"));
    props.setLook(wlBranding);
    FormData fdlBranding = new FormData();
    fdlBranding.left = new FormAttachment(0, 0);
    fdlBranding.top = new FormAttachment(wOriginalLook, margin);
    fdlBranding.right = new FormAttachment(middle, -margin);
    wlBranding.setLayoutData(fdlBranding);
    wBranding = new Button(wLookComp, SWT.CHECK);
    props.setLook(wBranding);
    wBranding.setSelection(props.isBrandingActive());
    FormData fdBranding = new FormData();
    fdBranding.left = new FormAttachment(middle, 0);
    fdBranding.top = new FormAttachment(wOriginalLook, margin);
    fdBranding.right = new FormAttachment(100, 0);
    wBranding.setLayoutData(fdBranding);
    // DefaultLocale line
    Label wlDefaultLocale = new Label(wLookComp, SWT.RIGHT);
    wlDefaultLocale.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.DefaultLocale.Label"));
    props.setLook(wlDefaultLocale);
    FormData fdlDefaultLocale = new FormData();
    fdlDefaultLocale.left = new FormAttachment(0, 0);
    fdlDefaultLocale.right = new FormAttachment(middle, -margin);
    fdlDefaultLocale.top = new FormAttachment(wBranding, margin);
    wlDefaultLocale.setLayoutData(fdlDefaultLocale);
    wDefaultLocale = new Combo(wLookComp, SWT.SINGLE | SWT.READ_ONLY | SWT.LEFT | SWT.BORDER);
    wDefaultLocale.setItems(GlobalMessages.localeDescr);
    wDefaultLocale.setEnabled(!Const.isRunningOnWebspoonMode());
    props.setLook(wDefaultLocale);
    FormData fdDefaultLocale = new FormData();
    fdDefaultLocale.left = new FormAttachment(middle, 0);
    fdDefaultLocale.right = new FormAttachment(100, -margin);
    fdDefaultLocale.top = new FormAttachment(wBranding, margin);
    wDefaultLocale.setLayoutData(fdDefaultLocale);
    // language selections...
    int idxDefault = Const.indexOfString(LanguageChoice.getInstance().getDefaultLocale().toString(), GlobalMessages.localeCodes);
    if (idxDefault >= 0) {
        wDefaultLocale.select(idxDefault);
    }
    fdLookComp = new FormData();
    fdLookComp.left = new FormAttachment(0, 0);
    fdLookComp.right = new FormAttachment(100, 0);
    fdLookComp.top = new FormAttachment(0, 0);
    fdLookComp.bottom = new FormAttachment(100, 100);
    wLookComp.setLayoutData(fdLookComp);
    wLookComp.pack();
    Rectangle bounds = wLookComp.getBounds();
    sLookComp.setContent(wLookComp);
    sLookComp.setExpandHorizontal(true);
    sLookComp.setExpandVertical(true);
    sLookComp.setMinWidth(bounds.width);
    sLookComp.setMinHeight(bounds.height);
    wLookTab.setControl(sLookComp);
// ///////////////////////////////////////////////////////////
// / END OF LOOK TAB
// ///////////////////////////////////////////////////////////
}
Also used : FontDialog(org.eclipse.swt.widgets.FontDialog) Label(org.eclipse.swt.widgets.Label) Rectangle(org.eclipse.swt.graphics.Rectangle) Combo(org.eclipse.swt.widgets.Combo) CTabItem(org.eclipse.swt.custom.CTabItem) Font(org.eclipse.swt.graphics.Font) ColorDialog(org.eclipse.swt.widgets.ColorDialog) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) FormAttachment(org.eclipse.swt.layout.FormAttachment) FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) PaintEvent(org.eclipse.swt.events.PaintEvent) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) PaintListener(org.eclipse.swt.events.PaintListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FontData(org.eclipse.swt.graphics.FontData) Canvas(org.eclipse.swt.widgets.Canvas) Color(org.eclipse.swt.graphics.Color) Text(org.eclipse.swt.widgets.Text) FillLayout(org.eclipse.swt.layout.FillLayout) Point(org.eclipse.swt.graphics.Point) RGB(org.eclipse.swt.graphics.RGB) Point(org.eclipse.swt.graphics.Point)

Example 82 with PaintEvent

use of org.eclipse.swt.events.PaintEvent in project pentaho-kettle by pentaho.

the class StepPerformanceSnapShotDialog method open.

public void open() {
    shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN);
    props.setLook(shell);
    shell.setText(BaseMessages.getString(PKG, "StepPerformanceSnapShotDialog.Title"));
    shell.setImage(GUIResource.getInstance().getImageLogoSmall());
    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = Const.FORM_MARGIN;
    formLayout.marginHeight = Const.FORM_MARGIN;
    shell.setLayout(formLayout);
    // Display 2 lists with the data types and the steps on the left side.
    // Then put a canvas with the graph on the right side
    // 
    dataList = new org.eclipse.swt.widgets.List(shell, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.LEFT | SWT.BORDER);
    props.setLook(dataList);
    dataList.setItems(dataChoices);
    dataList.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            // 
            if (dataList.getSelectionCount() > 1 && stepsList.getSelectionCount() > 1) {
                stepsList.setSelection(stepsList.getSelectionIndices()[0]);
            }
            updateGraph();
        }
    });
    FormData fdDataList = new FormData();
    fdDataList.left = new FormAttachment(0, 0);
    fdDataList.right = new FormAttachment(props.getMiddlePct() / 2, Const.MARGIN);
    fdDataList.top = new FormAttachment(0, 0);
    fdDataList.bottom = new FormAttachment(30, 0);
    dataList.setLayoutData(fdDataList);
    stepsList = new org.eclipse.swt.widgets.List(shell, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.LEFT | SWT.BORDER);
    props.setLook(stepsList);
    stepsList.setItems(steps);
    stepsList.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            // 
            if (dataList.getSelectionCount() > 1 && stepsList.getSelectionCount() > 1) {
                dataList.setSelection(dataList.getSelectionIndices()[0]);
            }
            updateGraph();
        }
    });
    FormData fdStepsList = new FormData();
    fdStepsList.left = new FormAttachment(0, 0);
    fdStepsList.right = new FormAttachment(props.getMiddlePct() / 2, Const.MARGIN);
    fdStepsList.top = new FormAttachment(dataList, Const.MARGIN);
    fdStepsList.bottom = new FormAttachment(100, Const.MARGIN);
    stepsList.setLayoutData(fdStepsList);
    canvas = new Canvas(shell, SWT.NONE);
    props.setLook(canvas);
    FormData fdCanvas = new FormData();
    fdCanvas.left = new FormAttachment(props.getMiddlePct() / 2, 0);
    fdCanvas.right = new FormAttachment(100, 0);
    fdCanvas.top = new FormAttachment(0, 0);
    fdCanvas.bottom = new FormAttachment(100, 0);
    canvas.setLayoutData(fdCanvas);
    shell.addControlListener(new ControlAdapter() {

        public void controlResized(ControlEvent event) {
            updateGraph();
        }
    });
    shell.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent event) {
            if (image != null) {
                image.dispose();
            }
        }
    });
    canvas.addPaintListener(new PaintListener() {

        public void paintControl(PaintEvent event) {
            if (image != null) {
                event.gc.drawImage(image, 0, 0);
            }
        }
    });
    // Refresh automatically every 5 seconds as well.
    // 
    Timer timer = new Timer("step performance snapshot dialog Timer");
    timer.schedule(new TimerTask() {

        public void run() {
            updateGraph();
        }
    }, 0, 5000);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) DisposeListener(org.eclipse.swt.events.DisposeListener) PaintEvent(org.eclipse.swt.events.PaintEvent) ControlAdapter(org.eclipse.swt.events.ControlAdapter) PaintListener(org.eclipse.swt.events.PaintListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Canvas(org.eclipse.swt.widgets.Canvas) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Shell(org.eclipse.swt.widgets.Shell) Timer(java.util.Timer) TimerTask(java.util.TimerTask) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ControlEvent(org.eclipse.swt.events.ControlEvent) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 83 with PaintEvent

use of org.eclipse.swt.events.PaintEvent in project archi by archimatetool.

the class EditPartTipHelper 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 84 with PaintEvent

use of org.eclipse.swt.events.PaintEvent in project xtext-eclipse by eclipse.

the class RenameRefactoringPopup method open.

public void open() {
    // Must cache here, since editor context is not available in menu from popup shell:
    openDialogBinding = getOpenDialogBinding();
    Shell workbenchShell = editor.getSite().getShell();
    final Display display = workbenchShell.getDisplay();
    popup = new Shell(workbenchShell, SWT.ON_TOP | SWT.NO_TRIM | SWT.TOOL);
    popupLayout = new GridLayout(2, false);
    popupLayout.marginWidth = 1;
    popupLayout.marginHeight = 1;
    popupLayout.marginLeft = 4;
    popupLayout.horizontalSpacing = 0;
    popup.setLayout(popupLayout);
    createContent(popup);
    updatePopupLocation();
    new PopupVisibilityManager().start();
    // Leave linked mode when popup loses focus
    // (except when focus goes back to workbench window or menu is open):
    popup.addShellListener(new ShellAdapter() {

        @Override
        public void shellDeactivated(ShellEvent e) {
            if (iSMenuUp)
                return;
            final Shell editorShell = editor.getSite().getShell();
            display.asyncExec(new Runnable() {

                // post to UI thread since editor shell only gets activated after popup has lost focus
                @Override
                public void run() {
                    Shell activeShell = display.getActiveShell();
                    if (activeShell != editorShell) {
                        controller.cancelLinkedMode();
                    }
                }
            });
        }
    });
    if (!MAC) {
        // carbon and cocoa draw their own border...
        popup.addPaintListener(new PaintListener() {

            @Override
            public void paintControl(PaintEvent pe) {
                pe.gc.drawPolygon(getPolygon(true));
            }
        });
    }
    UIJob delayJob = new UIJob(display, "Delayed RenameInformationPopup") {

        @Override
        public IStatus runInUIThread(IProgressMonitor monitor) {
            delayJobFinished = true;
            if (popup != null && !popup.isDisposed()) {
                updateVisibility();
            }
            return Status.OK_STATUS;
        }
    };
    delayJob.setSystem(true);
    delayJob.setPriority(Job.INTERACTIVE);
    delayJob.schedule(POPUP_VISIBILITY_DELAY);
}
Also used : Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) ShellAdapter(org.eclipse.swt.events.ShellAdapter) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) ShellEvent(org.eclipse.swt.events.ShellEvent) UIJob(org.eclipse.ui.progress.UIJob) Display(org.eclipse.swt.widgets.Display)

Example 85 with PaintEvent

use of org.eclipse.swt.events.PaintEvent in project mylyn.docs by eclipse.

the class ImageManager method selectionChanged.

public void selectionChanged(SelectionChangedEvent event) {
    GC gc = new GC(viewer.getTextWidget());
    try {
        Event e = new Event();
        e.gc = gc;
        e.widget = viewer.getTextWidget();
        Rectangle bounds = viewer.getTextWidget().getBounds();
        e.height = bounds.height;
        e.width = bounds.width;
        e.x = 0;
        e.y = 0;
        PaintEvent paintEvent = new PaintEvent(e);
        painter.paintControl(paintEvent);
    } finally {
        gc.dispose();
    }
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) Rectangle(org.eclipse.swt.graphics.Rectangle) DisposeEvent(org.eclipse.swt.events.DisposeEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) DocumentEvent(org.eclipse.jface.text.DocumentEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Event(org.eclipse.swt.widgets.Event) GC(org.eclipse.swt.graphics.GC)

Aggregations

PaintEvent (org.eclipse.swt.events.PaintEvent)96 PaintListener (org.eclipse.swt.events.PaintListener)92 Canvas (org.eclipse.swt.widgets.Canvas)32 Composite (org.eclipse.swt.widgets.Composite)31 Rectangle (org.eclipse.swt.graphics.Rectangle)29 MouseEvent (org.eclipse.swt.events.MouseEvent)27 GridData (org.eclipse.swt.layout.GridData)26 Point (org.eclipse.swt.graphics.Point)24 GridLayout (org.eclipse.swt.layout.GridLayout)23 DisposeEvent (org.eclipse.swt.events.DisposeEvent)18 SelectionEvent (org.eclipse.swt.events.SelectionEvent)18 DisposeListener (org.eclipse.swt.events.DisposeListener)15 FillLayout (org.eclipse.swt.layout.FillLayout)15 Event (org.eclipse.swt.widgets.Event)15 MouseAdapter (org.eclipse.swt.events.MouseAdapter)14 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)13 ControlEvent (org.eclipse.swt.events.ControlEvent)12 Control (org.eclipse.swt.widgets.Control)12 GC (org.eclipse.swt.graphics.GC)11 Listener (org.eclipse.swt.widgets.Listener)11