Example usage for org.eclipse.jface.resource JFaceResources getColorRegistry

List of usage examples for org.eclipse.jface.resource JFaceResources getColorRegistry

Introduction

In this page you can find the example usage for org.eclipse.jface.resource JFaceResources getColorRegistry.

Prototype

public static ColorRegistry getColorRegistry() 

Source Link

Document

Returns the color registry for JFace itself.

Usage

From source file:org.bbaw.pdr.ae.view.control.customSWTWidges.ReferenceEditorAddFieldToolTip.java

License:Open Source License

@Override
protected final Composite createToolTipContentArea(final Event event, final Composite parent) {
    _mainComp = new Composite(parent, SWT.NONE);

    GridLayout gl = new GridLayout(1, false);
    gl.marginBottom = 0;/*  w  w w  .j  a  va  2  s  .  c o  m*/
    gl.marginTop = 0;
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    gl.marginLeft = 0;
    gl.marginRight = 0;
    gl.verticalSpacing = 1;
    _mainComp.setLayout(gl);

    Composite topArea = new Composite(_mainComp, SWT.NONE);
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
    data.widthHint = 370;
    topArea.setLayoutData(data);
    topArea.setBackground(JFaceResources.getColorRegistry().get(HEADER_BG_COLOR));

    gl = new GridLayout(2, false);
    gl.marginBottom = 2;
    gl.marginTop = 2;
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    gl.marginLeft = 5;
    gl.marginRight = 2;

    topArea.setLayout(gl);

    Label l = new Label(topArea, SWT.NONE);
    l.setText(_headerText);
    l.setBackground(JFaceResources.getColorRegistry().get(HEADER_BG_COLOR));
    l.setFont(JFaceResources.getFontRegistry().get(HEADER_FONT));
    l.setForeground(JFaceResources.getColorRegistry().get(HEADER_FG_COLOR));
    l.setLayoutData(new GridData(GridData.FILL_BOTH));

    Composite iconComp = new Composite(topArea, SWT.NONE);
    iconComp.setLayoutData(new GridData());
    iconComp.setLayout(new GridLayout(2, false));
    iconComp.setBackground(JFaceResources.getColorRegistry().get(HEADER_BG_COLOR));

    gl = new GridLayout(2, false);
    gl.marginBottom = 0;
    gl.marginTop = 0;
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    gl.marginLeft = 0;
    gl.marginRight = 0;
    iconComp.setLayout(gl);

    Label helpIcon = new Label(iconComp, SWT.NONE);
    helpIcon.setBackground(JFaceResources.getColorRegistry().get(HEADER_BG_COLOR));
    helpIcon.setImage(_imageReg.get(IconsInternal.CANCEL));
    helpIcon.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(final MouseEvent e) {
            hide();
            // openHelp();
        }
    });

    Label closeIcon = new Label(iconComp, SWT.NONE);
    closeIcon.setBackground(JFaceResources.getColorRegistry().get(HEADER_BG_COLOR));
    closeIcon.setImage(JFaceResources.getImage(HEADER_CLOSE_ICON));
    closeIcon.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(final MouseEvent e) {
            _parentShell.setFocus();
            hide();
        }
    });

    createContentArea().setLayoutData(new GridData(GridData.FILL_BOTH));

    return _mainComp;
}

From source file:org.bbaw.pdr.ae.view.control.customSWTWidges.RevisionHistoryToolTip.java

License:Open Source License

@Override
protected final Composite createToolTipContentArea(final Event event, final Composite parent) {
    Composite comp = new Composite(parent, SWT.NONE);

    GridLayout gl = new GridLayout(1, false);
    gl.marginBottom = 0;//from   w w w.jav  a2 s.c  om
    gl.marginTop = 0;
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    gl.marginLeft = 0;
    gl.marginRight = 0;
    gl.verticalSpacing = 1;
    comp.setLayout(gl);

    Composite topArea = new Composite(comp, SWT.NONE);
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
    data.widthHint = 200;
    topArea.setLayoutData(data);
    topArea.setBackground(JFaceResources.getColorRegistry().get(HEADER_BG_COLOR));

    gl = new GridLayout(2, false);
    gl.marginBottom = 2;
    gl.marginTop = 2;
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    gl.marginLeft = 5;
    gl.marginRight = 2;

    topArea.setLayout(gl);

    Label l = new Label(topArea, SWT.NONE);
    l.setText(_headerText);
    l.setBackground(JFaceResources.getColorRegistry().get(HEADER_BG_COLOR));
    l.setFont(JFaceResources.getFontRegistry().get(HEADER_FONT));
    l.setForeground(JFaceResources.getColorRegistry().get(HEADER_FG_COLOR));
    l.setLayoutData(new GridData(GridData.FILL_BOTH));

    Composite iconComp = new Composite(topArea, SWT.NONE);
    iconComp.setLayoutData(new GridData());
    iconComp.setLayout(new GridLayout(2, false));
    iconComp.setBackground(JFaceResources.getColorRegistry().get(HEADER_BG_COLOR));

    gl = new GridLayout(2, false);
    gl.marginBottom = 0;
    gl.marginTop = 0;
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    gl.marginLeft = 0;
    gl.marginRight = 0;
    iconComp.setLayout(gl);

    Label helpIcon = new Label(iconComp, SWT.NONE);
    helpIcon.setBackground(JFaceResources.getColorRegistry().get(HEADER_BG_COLOR));
    helpIcon.setImage(_imageReg.get(IconsInternal.USER));
    helpIcon.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(final MouseEvent e) {
            hide();
        }
    });

    Label closeIcon = new Label(iconComp, SWT.NONE);
    closeIcon.setBackground(JFaceResources.getColorRegistry().get(HEADER_BG_COLOR));
    closeIcon.setImage(JFaceResources.getImage(HEADER_CLOSE_ICON));
    closeIcon.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(final MouseEvent e) {
            _parentShell.setFocus();
            hide();
        }
    });

    createContentArea(comp).setLayoutData(new GridData(GridData.FILL_BOTH));

    return comp;
}

From source file:org.bbaw.pdr.ae.view.control.customSWTWidges.TimeSliderToolTip.java

License:Open Source License

@Override
protected final Composite createToolTipContentArea(final Event event, final Composite parent) {
    Composite comp = new Composite(parent, SWT.NONE);

    GridLayout gl = new GridLayout(1, false);
    gl.marginBottom = 0;//from w w  w  .ja  v  a2s.co  m
    gl.marginTop = 0;
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    gl.marginLeft = 0;
    gl.marginRight = 0;
    gl.verticalSpacing = 1;
    comp.setLayout(gl);

    Composite topArea = new Composite(comp, SWT.NONE);
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
    data.widthHint = 400;
    topArea.setLayoutData(data);
    topArea.setBackground(JFaceResources.getColorRegistry().get(HEADER_BG_COLOR));

    gl = new GridLayout(3, false);
    gl.marginBottom = 2;
    gl.marginTop = 2;
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    gl.marginLeft = 5;
    gl.marginRight = 2;

    topArea.setLayout(gl);

    Label l = new Label(topArea, SWT.NONE);
    l.setText(_headerText + ":");
    l.setBackground(JFaceResources.getColorRegistry().get(HEADER_BG_COLOR));
    l.setFont(JFaceResources.getFontRegistry().get(HEADER_FONT));
    l.setForeground(JFaceResources.getColorRegistry().get(HEADER_FG_COLOR));
    l.setLayoutData(new GridData(GridData.FILL_BOTH));

    _year = new Label(topArea, SWT.NONE);
    int i = _time + THOUSAND;
    _year.setText("" + i);
    _year.setBackground(JFaceResources.getColorRegistry().get(HEADER_BG_COLOR));
    _year.setFont(JFaceResources.getFontRegistry().get(HEADER_FONT));
    _year.setForeground(JFaceResources.getColorRegistry().get(HEADER_FG_COLOR));
    _year.setLayoutData(new GridData(GridData.FILL_BOTH));

    Composite iconComp = new Composite(topArea, SWT.NONE);
    iconComp.setLayoutData(new GridData());
    iconComp.setLayout(new GridLayout(2, false));
    iconComp.setBackground(JFaceResources.getColorRegistry().get(HEADER_BG_COLOR));
    gl = new GridLayout(2, false);
    gl.marginBottom = 0;
    gl.marginTop = 0;
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    gl.marginLeft = 0;
    gl.marginRight = 0;
    iconComp.setLayout(gl);

    Label closeIcon = new Label(iconComp, SWT.NONE);
    closeIcon.setImage(_imageReg.get(IconsInternal.TIME));
    closeIcon.setBackground(JFaceResources.getColorRegistry().get(HEADER_BG_COLOR));
    _timeScale = new Scale(comp, SWT.HORIZONTAL);

    _timeScale.setMinimum(0);
    _timeScale.setMaximum(1100);
    _timeScale.setIncrement(1);
    _timeScale.setPageIncrement(10);
    _timeScale.setSelection(_time);
    _timeScale.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
    _timeScale.setLayoutData(new GridData());
    ((GridData) _timeScale.getLayoutData()).horizontalAlignment = SWT.FILL;
    ((GridData) _timeScale.getLayoutData()).verticalAlignment = SWT.FILL;
    ((GridData) _timeScale.getLayoutData()).grabExcessHorizontalSpace = true;
    _timeScale.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent e) {

            _yearSpinner.setSelection(_timeScale.getSelection() + THOUSAND);
            int i = _timeScale.getSelection() + THOUSAND;
            _year.setText("" + i);
            _yearSpinner.notifyListeners(SWT.Selection, new Event());
        }
    });

    // XXX RAP auskommentiert
    // _timeScale.addMouseWheelListener(new MouseWheelListener()
    // {
    //
    // @Override
    // public void mouseScrolled(final MouseEvent e)
    // {
    // Scale src = (Scale) e.getSource();
    // src.setSelection(src.getSelection() - e.count);
    // _yearSpinner.setSelection(_timeScale.getSelection() + 1000);
    // int i = _timeScale.getSelection() + 1000;
    // _year.setText("" + i);
    //
    // _yearSpinner.notifyListeners(SWT.Selection, new Event());
    //
    // }
    // });
    createContentArea(comp).setLayoutData(new GridData(GridData.FILL_BOTH));
    _timeScale.setFocus();
    return comp;
}

From source file:org.bonitasoft.studio.common.jface.DataStyledTreeLabelProvider.java

License:Open Source License

private void initStyle() {
    italicGrey = new StyledString.Styler() {
        @Override/*from  w  w w  .  j a  v a2s  .c om*/
        public void applyStyles(TextStyle textStyle) {
            textStyle.font = BonitaStudioFontRegistry.getTransientDataFont();
            textStyle.foreground = JFaceResources.getColorRegistry().get(JFacePreferences.QUALIFIER_COLOR);
        }
    };
}

From source file:org.csstudio.autocomplete.ui.content.ContentProposalPopup.java

License:Open Source License

protected Color getForeground() {
    return JFaceResources.getColorRegistry().get(JFacePreferences.CONTENT_ASSIST_FOREGROUND_COLOR);
}

From source file:org.csstudio.autocomplete.ui.content.ContentProposalPopup.java

License:Open Source License

protected Color getBackground() {
    return JFaceResources.getColorRegistry().get(JFacePreferences.CONTENT_ASSIST_BACKGROUND_COLOR);
}

From source file:org.dawb.workbench.ui.data.PlotDataComponent.java

License:Open Source License

/**
 * Create contents of the view part./*  w  ww. j av a 2 s  . c  o m*/
 * @param parent
 */
public void createPartControl(final Composite parent, IActionBars bars) throws Exception {

    this.container = new Composite(parent, SWT.NONE);
    if (parent.getLayout() instanceof GridLayout)
        container.setLayoutData(new GridData(GridData.FILL_BOTH));
    container.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));

    GridLayout gl_container = new GridLayout(1, false);
    gl_container.verticalSpacing = 0;
    gl_container.marginWidth = 0;
    gl_container.marginHeight = 0;
    gl_container.horizontalSpacing = 0;

    container.setLayout(gl_container);

    final Text searchText = new Text(container, SWT.SINGLE | SWT.BORDER | SWT.SEARCH | SWT.ICON_CANCEL);
    searchText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
    searchText.setToolTipText(
            "Search on data set name or shape\nFor instance '132, 4096' to find all of that shape.");

    this.dataViewer = new TableViewer(container,
            SWT.FULL_SELECTION | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.VIRTUAL);

    dataViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
    dataViewer.getTable().addMouseListener(this);
    dataViewer.getTable().addKeyListener(this);
    dataViewer.getTable().setLinesVisible(true);
    dataViewer.getTable().setHeaderVisible(true);

    ColorRegistry colorRegistry = JFaceResources.getColorRegistry();
    Label label = new Label(container, SWT.RIGHT);
    label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false));
    label.setForeground(new Color(label.getDisplay(), colorRegistry.getRGB(JFacePreferences.QUALIFIER_COLOR)));
    label.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
    label.setText("* Click to change value  ");

    label = new Label(container, SWT.HORIZONTAL | SWT.SEPARATOR);
    label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    createColumns();
    dataViewer.setColumnProperties(new String[] { "Data", "Length" });

    dataViewer.getTable().setItemCount(data.size());
    dataViewer.setUseHashlookup(true);

    dataViewer.setContentProvider(new IStructuredContentProvider() {
        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(Object inputElement) {

            List<ITransferableDataObject> visible = new ArrayList<ITransferableDataObject>(data);
            if (Activator.getDefault().getPreferenceStore().getBoolean(EditorConstants.SHOW_SIGNAL_ONLY)) {
                filterNonSignalData(visible);
            }
            return visible.toArray(new Object[visible.size()]);
        }
    });

    // Maybe being the selection provider cause the left mouse problem
    //if (getSite()!=null) getSite().setSelectionProvider(dataViewer);
    dataViewer.setInput(new String());

    createActions(bars);

    setColumnVisible(2, 36,
            Activator.getDefault().getPreferenceStore().getBoolean(EditorConstants.SHOW_XY_COLUMN));
    setColumnVisible(3, 150,
            Activator.getDefault().getPreferenceStore().getBoolean(EditorConstants.SHOW_DATA_SIZE));
    setColumnVisible(4, 150, Activator.getDefault().getPreferenceStore().getBoolean(EditorConstants.SHOW_DIMS));
    setColumnVisible(5, 150,
            Activator.getDefault().getPreferenceStore().getBoolean(EditorConstants.SHOW_SHAPE));
    setColumnVisible(6, 150,
            Activator.getDefault().getPreferenceStore().getBoolean(EditorConstants.SHOW_VARNAME));

    try {

        this.traceListener = new ITraceListener.Stub() {
            @Override
            public void tracesUpdated(TraceEvent evt) {
                updateSelection(true);
                dataViewer.refresh();
            }
        };
        if (getPlottingSystem() != null)
            getPlottingSystem().addTraceListener(traceListener);

        if (dataReduction != null) {
            this.toolListener = new IToolChangeListener() {

                @Override
                public void toolChanged(ToolChangeEvent evt) {
                    if (dataReduction != null) {
                        dataReduction.setEnabled(isDataReductionToolActive());
                    }
                }
            };
            if (getAbstractPlottingSystem() != null)
                getAbstractPlottingSystem().addToolChangeListener(toolListener);
        }
        if (getAbstractPlottingSystem() != null)
            getAbstractPlottingSystem().addPropertyChangeListener(new IPropertyChangeListener() {
                @Override
                public void propertyChange(PropertyChangeEvent event) {
                    try {
                        saveAxisSettings(".xAxis", getPlottingSystem().getSelectedXAxis());
                        saveAxisSettings(".yAxis", getPlottingSystem().getSelectedYAxis());
                    } catch (Throwable ne) {
                        logger.error("Cannot save settings for plotting configuration!", ne);
                    }
                }
            });

        readAxisSettings(".xAxis", getPlottingSystem().getSelectedXAxis());
        readAxisSettings(".yAxis", getPlottingSystem().getSelectedYAxis());

        this.dataFilter = new DataTableFilter();
        dataViewer.addFilter(dataFilter);
        searchText.addModifyListener(new ModifyListener() {
            @Override
            public void modifyText(ModifyEvent e) {
                if (parent.isDisposed())
                    return;
                dataFilter.setSearchText(searchText.getText());
                dataViewer.refresh();
            }
        });
    } catch (Exception ne) {
        logger.error("Cannot add trace listener!", ne);
    }

    // Allow the colours to be drawn nicely.
    final Table table = dataViewer.getTable();
    if (OSUtils.isWindowsOS())
        table.addListener(SWT.EraseItem, new Listener() {
            public void handleEvent(Event event) {

                GC gc = event.gc;
                Color foreground = gc.getForeground();
                Color background = gc.getBackground();

                try {
                    Rectangle area = table.getClientArea();
                    /*
                     * If you wish to paint the selection beyond the end of last column,
                     * you must change the clipping region.
                     */
                    int columnCount = table.getColumnCount();
                    if (event.index == columnCount - 1 || columnCount == 0) {
                        int width = area.x + area.width - event.x;
                        if (width > 0) {
                            Region region = new Region();
                            gc.getClipping(region);
                            region.add(event.x, event.y, width, event.height);
                            gc.setClipping(region);
                            region.dispose();
                        }
                    }

                    gc.setAdvanced(true);
                    if (gc.getAdvanced())
                        gc.setAlpha(50);

                    if ((event.detail & SWT.SELECTED) != 0) {
                        gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_SELECTION));
                        gc.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
                    }

                    final TableItem item = table.getItem(new Point(event.x, event.y));
                    // Draw the colour in the Value column
                    if (item != null && item.getData() instanceof TransferableDataObject) {

                        Rectangle nameArea = item.getBounds(1); // Name column
                        TransferableDataObject cn = (TransferableDataObject) item.getData();

                        if (cn.isChecked() && !cn.isExpression() && nameArea.contains(event.x, event.y)) {
                            int origAlpha = gc.getAlpha();
                            gc.setAlpha(255);
                            final Color plotColor = get1DPlotColor(cn);
                            if (plotColor != null) {
                                gc.setForeground(plotColor);
                                int offset = cn.getFilterPath() != null ? 20 : 0;
                                gc.drawText(cn.getDisplayName(rootName), item.getBounds().x + 16 + offset,
                                        item.getBounds().y + 1);
                                event.doit = false;
                            }
                            gc.setAlpha(origAlpha);
                        }

                        if ((event.detail & SWT.HOT) != 0) {
                            // Draw the colour in the Value column
                            gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_SELECTION));
                            Rectangle bounds = event.getBounds();
                            gc.fillGradientRectangle(0, bounds.y, 500, bounds.height, false);
                        }
                    }

                } finally {
                    if ((event.detail & SWT.SELECTED) != 0)
                        event.detail &= ~SWT.SELECTED;
                    if ((event.detail & SWT.HOT) != 0)
                        event.detail &= ~SWT.HOT;
                    // restore colors for subsequent drawing
                    gc.setForeground(foreground);
                    gc.setBackground(background);
                }

            }

        });

}

From source file:org.dawnsci.conversion.ui.pages.CompareConvertPage.java

License:Open Source License

@Override
public void setContext(IConversionContext context) {

    if (context != null && context.equals(this.context))
        return;/*from   w w w  . j a  va2 s  .c o m*/

    this.context = context;
    setErrorMessage(null);
    if (context == null) { // new context being prepared.
        this.imeta = null;
        this.holder = null;
        setPageComplete(false);
        return;
    }
    // We populate the names later using a wizard task.
    try {
        getDataSetNames();
    } catch (Exception e) {
        logger.error("Cannot extract data sets!", e);
    }

    final File source = new File(getSourcePath(context));

    setPageComplete(true);

    if (context.getFilePaths().size() < 2) { // !Multi
        setErrorMessage("Compare can only be done on more than one file!");
        setPageComplete(false);
        return;
    }

    setPath(FileUtils.getUnique(source.getParentFile(), "compare_file", "nxs").getAbsolutePath());
    setDirectory(false);

    GridUtils.setVisible(multiFileMessage, true);
    this.overwriteButton.setSelection(false);
    this.overwrite = false;
    this.openButton.setSelection(true);
    this.open = true;
    this.openButton.setEnabled(true);

    final File firstFile = new File(context.getFilePaths().get(0));
    String label = "*The data written is based on the first file, '" + firstFile.getName() + "'.";
    ColorRegistry colorRegistry = JFaceResources.getColorRegistry();
    info.setText(label);
    info.setStyleRange(new StyleRange(0, label.length(), colorRegistry.get(JFacePreferences.DECORATIONS_COLOR),
            info.getParent().getBackground()));
    info.setToolTipText("The compare is done by forcing each file in the stack to\n"
            + "use the same data size as the data in the first file.\n\n"
            + "So the required size may be obtained by making a local copy of the\n"
            + "data and ensuring the first file has the correct size. It is also\n"
            + "possible to set the sizes manually, please contact your support\n"
            + "representative if you require this.");

}

From source file:org.dawnsci.plotting.tools.diffraction.DiffractionTool.java

License:Open Source License

@Override
public void createControl(final Composite parent) {

    this.control = new Composite(parent, SWT.NONE);
    control.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
    control.setLayout(new GridLayout(1, false));
    GridUtils.removeMargins(control);//from   w  w w . j  av a  2s . c  om

    this.filteredTree = new ClearableFilteredTree(control,
            SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, new NodeFilter(this), true,
            "Enter search string to filter the tree.\nThis will match on name, value or units");
    viewer = filteredTree.getViewer();
    viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    createColumns(viewer);
    viewer.setContentProvider(new TreeNodeContentProvider()); // Swing tree nodes
    viewer.getTree().setLinesVisible(true);
    viewer.getTree().setHeaderVisible(true);

    Composite status = new Composite(control, SWT.NONE);
    status.setLayoutData(new GridData(SWT.FILL, GridData.FILL, true, false));
    status.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
    status.setLayout(new GridLayout(2, true));
    GridUtils.removeMargins(status);

    statusMessage = new Label(status, SWT.LEFT);
    statusMessage.setLayoutData(new GridData(SWT.FILL, GridData.CENTER, true, false));
    ColorRegistry colorRegistry = JFaceResources.getColorRegistry();
    statusMessage.setForeground(
            new Color(statusMessage.getDisplay(), colorRegistry.getRGB(JFacePreferences.QUALIFIER_COLOR)));
    statusMessage.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
    if (statusString != null && statusString[0] != null)
        statusMessage.setText(statusString[0]);

    final Label label = new Label(status, SWT.RIGHT);
    label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false));
    label.setForeground(new Color(label.getDisplay(), colorRegistry.getRGB(JFacePreferences.QUALIFIER_COLOR)));
    label.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
    label.setText("* Click to change value  ");

    createDiffractionModel(false);
    createActions();
    createListeners();
    //false by default
    if (!hide)
        createToolPageActions();

}

From source file:org.dawnsci.plotting.tools.grid.GridTool.java

License:Open Source License

@Override
public void createControl(Composite parent) {

    final Action reselect = new Action("Create new grid.", getImageDescriptor()) {
        public void run() {
            createNewRegion(true);/*from  ww  w  .j av  a2 s  .  co  m*/
        }
    };

    IActionBars actionbars = getSite() != null ? getSite().getActionBars() : null;
    if (actionbars != null) {
        actionbars.getToolBarManager()
                .add(new Separator("org.dawb.workbench.plotting.tools.profile.newProfileGroup"));
        actionbars.getToolBarManager().insertAfter("org.dawb.workbench.plotting.tools.profile.newProfileGroup",
                reselect);
        actionbars.getToolBarManager()
                .add(new Separator("org.dawb.workbench.plotting.tools.profile.newProfileGroupAfter"));
    }

    this.control = new Composite(parent, SWT.NONE);
    control.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
    control.setLayout(new GridLayout(1, false));
    GridUtils.removeMargins(control);

    this.filteredTree = new ClearableFilteredTree(control,
            SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, new NodeFilter(this), true,
            "Enter search string to filter the tree.\nThis will match on name, value or units");
    viewer = filteredTree.getViewer();
    viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    createColumns(viewer);
    viewer.setContentProvider(new TreeNodeContentProvider()); // Swing tree nodes
    viewer.getTree().setLinesVisible(true);
    viewer.getTree().setHeaderVisible(true);

    final Label label = new Label(control, SWT.NONE);
    label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false));
    ColorRegistry colorRegistry = JFaceResources.getColorRegistry();
    label.setForeground(new Color(label.getDisplay(), colorRegistry.getRGB(JFacePreferences.QUALIFIER_COLOR)));
    label.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
    label.setText("* Click to change value  ");

    createGridModel();
    createActions();

    // Allow the colours to be drawn nicely.
    final Tree tree = viewer.getTree();
    tree.addListener(SWT.EraseItem, new Listener() {
        public void handleEvent(Event event) {
            if ((event.detail & SWT.SELECTED) != 0) {
                GC gc = event.gc;
                Rectangle area = tree.getClientArea();
                /*
                 * If you wish to paint the selection beyond the end of last column,
                 * you must change the clipping region.
                 */
                int columnCount = tree.getColumnCount();
                if (event.index == columnCount - 1 || columnCount == 0) {
                    int width = area.x + area.width - event.x;
                    if (width > 0) {
                        Region region = new Region();
                        gc.getClipping(region);
                        region.add(event.x, event.y, width, event.height);
                        gc.setClipping(region);
                        region.dispose();
                    }
                }
                gc.setAdvanced(true);
                if (gc.getAdvanced())
                    gc.setAlpha(50);
                Rectangle rect = event.getBounds();
                Color foreground = gc.getForeground();
                Color background = gc.getBackground();
                gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_SELECTION));
                gc.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
                gc.fillGradientRectangle(0, rect.y, 500, rect.height, false);

                final TreeItem item = tree.getItem(new Point(event.x, event.y));
                // Draw the colour in the Value column
                if (item != null && item.getData() instanceof ColorNode) {
                    gc.setAlpha(255);
                    Rectangle col = item.getBounds(1);
                    ColorNode cn = (ColorNode) item.getData();
                    gc.setBackground(cn.getColor());
                    gc.fillRectangle(col);
                }

                // restore colors for subsequent drawing
                gc.setForeground(foreground);
                gc.setBackground(background);
                event.detail &= ~SWT.SELECTED;
                return;
            }

            if ((event.detail & SWT.HOT) != 0) {
                final TreeItem item = tree.getItem(new Point(event.x, event.y));
                // Draw the colour in the Value column
                if (item != null && item.getData() instanceof LabelNode) {
                    LabelNode ln = (LabelNode) item.getData();
                    GC gc = event.gc;
                    Color foreground = gc.getForeground();
                    Color background = gc.getBackground();
                    gc.setAdvanced(true);
                    gc.setForeground(ColorConstants.black);
                    gc.drawText(ln.getLabel(), item.getBounds().x + 2, item.getBounds().y + 1);
                    event.doit = false;
                    event.detail &= ~SWT.HOT;
                    gc.setForeground(foreground);
                    gc.setBackground(background);
                }
            }
        }
    });

    tree.addMouseListener(new MouseAdapter() {
        public void mouseDown(MouseEvent e) {
            final TreeItem item = tree.getItem(new Point(e.x, e.y));
            if (item == null)
                return;
            if (item.getData() instanceof BooleanNode) {
                if (item != null) {
                    Rectangle r = item.getBounds(1);
                    if (r.contains(new Point(e.x, e.y))) {
                        BooleanNode bn = (BooleanNode) item.getData();
                        bn.setValue(!bn.isValue());
                        viewer.update(bn, new String[] { "Value" });
                    }
                }

            }
        }
    });
    gridPreferences = getGridPreferences();

    connectBeamCenterControls();
    updateBeamCentre();
}