List of usage examples for org.eclipse.jface.resource ColorRegistry getRGB
public RGB getRGB(String symbolicName)
From source file:com.dubture.twig.ui.editor.SemanticHighlightingStyle.java
License:Open Source License
/** * Returns the RGB for the given key in the given color registry. * /* w w w. jav a2 s .c o m*/ * @param key * the key for the constant in the registry * @param defaultRGB * the default RGB if no entry is found * @return RGB the RGB */ private static RGB findRGB(String key, RGB defaultRGB) { if (!PlatformUI.isWorkbenchRunning()) return defaultRGB; ColorRegistry registry = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry(); RGB rgb = registry.getRGB(key); if (rgb != null) return rgb; return defaultRGB; }
From source file:com.google.dart.tools.ui.internal.text.editor.SemanticHighlighting.java
License:Open Source License
/** * Returns the RGB for the given key in the given color registry. * /*from ww w . ja v a2 s . com*/ * @param registry the color registry * @param key the key for the constant in the registry * @param defaultRGB the default RGB if no entry is found * @return RGB the RGB */ private static RGB findRGB(ColorRegistry registry, String key, RGB defaultRGB) { RGB rgb = registry.getRGB(key); if (rgb != null) { return rgb; } return defaultRGB; }
From source file:com.google.dart.tools.ui.PreferenceConstants.java
License:Open Source License
/** * Returns the RGB for the given key in the given color registry. * /*from w ww .j a v a2s .c om*/ * @param registry the color registry * @param key the key for the constant in the registry * @param defaultRGB the default RGB if no entry is found * @return RGB the RGB */ private static RGB findRGB(ColorRegistry registry, String key, RGB defaultRGB) { if (registry == null) { return defaultRGB; } RGB rgb = registry.getRGB(key); if (rgb != null) { return rgb; } return defaultRGB; }
From source file:com.imperial.fiksen.codesimilarity.compare.ParseTreeMergeViewer.java
License:Open Source License
private void updateColors(Display display) { if (display == null) display = getControl().getDisplay(); Color bgColor = null;//from w w w. j a v a2 s . co m if (fBackground != null) bgColor = getColor(display, fBackground); if (fAncestor != null) fAncestor.setBackgroundColor(bgColor); if (fLeft != null) fLeft.setBackgroundColor(bgColor); if (fRight != null) fRight.setBackgroundColor(bgColor); Color fgColor = null; if (fForeground != null) fgColor = getColor(display, fForeground); if (fAncestor != null) fAncestor.setForegroundColor(fgColor); if (fLeft != null) fLeft.setForegroundColor(fgColor); if (fRight != null) fRight.setForegroundColor(fgColor); ColorRegistry registry = JFaceResources.getColorRegistry(); RGB bg = getBackground(display); SELECTED_INCOMING = registry.getRGB(INCOMING_COLOR); if (SELECTED_INCOMING == null) SELECTED_INCOMING = new RGB(0, 0, 255); // BLUE INCOMING = interpolate(SELECTED_INCOMING, bg, 0.6); INCOMING_FILL = interpolate(SELECTED_INCOMING, bg, 0.97); INCOMING_TEXT_FILL = interpolate(SELECTED_INCOMING, bg, 0.85); SELECTED_OUTGOING = registry.getRGB(OUTGOING_COLOR); if (SELECTED_OUTGOING == null) SELECTED_OUTGOING = new RGB(0, 0, 0); // BLACK //INFO FIKSEN: OUTGOING is the highlight bar in th margin colour OUTGOING = new RGB(180, 180, 0); OUTGOING_FILL = new RGB(180, 180, 0); OUTGOING_TEXT_FILL = new RGB(180, 180, 0); SELECTED_CONFLICT = registry.getRGB(CONFLICTING_COLOR); if (SELECTED_CONFLICT == null) SELECTED_CONFLICT = new RGB(255, 0, 0); // RED CONFLICT = interpolate(SELECTED_CONFLICT, bg, 0.6); CONFLICT_FILL = interpolate(SELECTED_CONFLICT, bg, 0.97); CONFLICT_TEXT_FILL = interpolate(SELECTED_CONFLICT, bg, 0.85); RESOLVED = registry.getRGB(RESOLVED_COLOR); if (RESOLVED == null) RESOLVED = new RGB(0, 255, 0); // GREEN updatePresentation(); }
From source file:com.mentor.nucleus.bp.model.compare.contentmergeviewer.ModelContentMergeViewer.java
License:Open Source License
public void updateColors() { ColorRegistry registry = JFaceResources.getColorRegistry(); RGB bg = getBackground(PlatformUI.getWorkbench().getDisplay()); INCOMING_BASE = registry.getRGB(INCOMING_COLOR); if (INCOMING_BASE == null) { INCOMING_BASE = new RGB(0, 0, 255); registry.put(INCOMING_COLOR, INCOMING_BASE); }/* ww w . j a va2s. c o m*/ INCOMING = interpolate(INCOMING_BASE, bg, 0.6); OUTGOING_BASE = registry.getRGB(OUTGOING_COLOR); if (OUTGOING_BASE == null) { OUTGOING_BASE = new RGB(0, 0, 0); // BLACK registry.put(OUTGOING_COLOR, OUTGOING_BASE); } OUTGOING = interpolate(OUTGOING_BASE, bg, 0.6); CONFLICT_BASE = registry.getRGB(CONFLICTING_COLOR); if (CONFLICT_BASE == null) { CONFLICT_BASE = new RGB(255, 0, 0); registry.put(CONFLICTING_COLOR, CONFLICT_BASE); // RED } CONFLICT = interpolate(CONFLICT_BASE, bg, 0.6); RESOLVED = registry.getRGB(RESOLVED_COLOR); if (RESOLVED == null) RESOLVED = new RGB(0, 255, 0); // GREEN }
From source file:descent.internal.ui.infoviews.AbstractInfoView.java
License:Open Source License
private void inititalizeColors() { if (getSite().getShell().isDisposed()) return;//from w ww .j av a 2 s.c o m Display display = getSite().getShell().getDisplay(); if (display == null || display.isDisposed()) return; setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND)); ColorRegistry registry = JFaceResources.getColorRegistry(); registry.addListener(this); fBackgroundColorRGB = registry.getRGB(getBackgroundColorKey()); Color bgColor; if (fBackgroundColorRGB == null) { bgColor = display.getSystemColor(SWT.COLOR_INFO_BACKGROUND); fBackgroundColorRGB = bgColor.getRGB(); } else { bgColor = new Color(display, fBackgroundColorRGB); fBackgroundColor = bgColor; } setBackground(bgColor); }
From source file:ext.org.eclipse.jdt.internal.ui.JavaUIPreferenceInitializer.java
License:Open Source License
/** * Returns the RGB for the given key in the given color registry. * * @param registry the color registry/*www. j av a 2 s. c o m*/ * @param key the key for the constant in the registry * @param defaultRGB the default RGB if no entry is found * @return RGB the RGB * @since 3.4 */ private static RGB findRGB(ColorRegistry registry, String key, RGB defaultRGB) { if (registry == null) return defaultRGB; RGB rgb = registry.getRGB(key); if (rgb != null) return rgb; return defaultRGB; }
From source file:org.dawb.workbench.ui.data.PlotDataComponent.java
License:Open Source License
/** * Create contents of the view part.//w ww . j a va 2s . c om * @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.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 ww. java2 s.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);// w ww . ja va 2 s.c o 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(); }