private void init() { shell.setLayout(new GridLayout(2, false)); fontRegistry = new FontRegistry(display); fontRegistry.put("button-text", new FontData[]{new FontData("Arial", 9, SWT.BOLD)} ); fontRegistry.put("code", new FontData[]{new FontData("Courier New", 10, SWT.NORMAL)}); Text text = new Text(shell, SWT.MULTI | SWT.BORDER | SWT.WRAP); text.setFont(fontRegistry.get("code")); text.setForeground(display.getSystemColor(SWT.COLOR_BLUE)); text.setText("public static void main() {\n\tSystem.out.println(\"Hello\"); \n}"); GridData gd = new GridData(GridData.FILL_BOTH); gd.horizontalSpan = 2; text.setLayoutData(gd); Button executeButton = new Button(shell, SWT.PUSH); executeButton.setText("Execute"); executeButton.setFont(fontRegistry.get("button-text")); Button cancelButton = new Button(shell, SWT.PUSH); cancelButton.setText("Cancel"); cancelButton.setFont(fontRegistry.get("button-text")); }
/** * Private constructor to avoid instantiation. */ private XYGraphMediaFactory() { _colorRegistry = new ColorRegistry(); _imageRegistry = new ImageRegistry(); _fontRegistry = new FontRegistry(); _imageCache = new HashMap<ImageDescriptor, Image>(); // dispose all images from the image cache, when the display is disposed Display.getDefault().addListener(SWT.Dispose, new Listener() { public void handleEvent(final Event event) { for (Image img : _imageCache.values()) { img.dispose(); } disposeResources(); } }); }
/** * @see org.eclipse.ui.forms.IDetailsPage#createContents(org.eclipse.swt.widgets.Composite) */ public void createContents(Composite parent) { FormToolkit toolkit = this.managedForm.getToolkit(); fontRegistry = new FontRegistry(parent.getDisplay()); // Initializes the parent control. parent.setLayout(new FillLayout()); // Creates the section this.section = toolkit.createSection(parent, Section.TITLE_BAR); this.section.marginHeight = 5; this.section.marginWidth = 10; // Createst the section content and its layout this.sectionContent = toolkit.createComposite(section); this.section.setClient(this.sectionContent); GridLayout layout = new GridLayout(1, true); layout.marginWidth = 0; layout.marginHeight = 0; this.sectionContent.setLayout(layout); // Creates the editor content. this.editorContainer = managedForm.getToolkit().createComposite(sectionContent); this.editorContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Creates controls displaying the setting note. this.noteLabel = this.managedForm.getToolkit().createFormText(sectionContent, false); this.noteLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); this.noteLabel.setFont(EMPHASIS, fontRegistry.getItalic("")); this.noteLabel.addHyperlinkListener(new MyHyperlinkListener(this)); }
/** * Starts a new {@link StyleRange} given a specific line type. */ private StyleRange initDiffStyleRangeForLineType(DiffLineType lineType, int startTextOffset) { ColorRegistry reg = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry(); StyleRange range = new StyleRange(); range.start = startTextOffset; switch (lineType) { case ADD: range.foreground = reg.get(THEME_DiffAddForegroundColor); range.background = reg.get(THEME_DiffAddBackgroundColor); break; case REMOVE: range.foreground = reg.get(THEME_DiffRemoveForegroundColor); range.background = reg.get(THEME_DiffRemoveBackgroundColor); break; case HUNK: range.foreground = reg.get(THEME_DiffHunkForegroundColor); range.background = reg.get(THEME_DiffHunkBackgroundColor); break; case HEADLINE: range.foreground = reg.get(THEME_DiffHeadlineForegroundColor); range.background = reg.get(THEME_DiffHeadlineBackgroundColor); FontRegistry fontReg = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getFontRegistry(); range.font = fontReg.get(THEME_DiffHeadlineFont); break; default: break; } return range; }
public void start(BundleContext context) throws Exception { super.start(context); plugin = this; fontReg = new FontRegistry(Display.getCurrent()); // initialise some fonts fontReg.put(FONT_8, new FontData[] {new FontData("Arial", 8, SWT.None)}); fontReg.put(FONT_10, new FontData[] {new FontData("Arial", 10, SWT.None)}); fontReg.put(FONT_12, new FontData[] {new FontData("Arial", 12, SWT.None)}); }
/** * Create the FontListener. Starts listening to the font registry * provided. It the control already has a FontListener, it is disposed. * @param control The control who's font this class will update. * @param fontPref The preference this class will update. * @param registry The registry to get font preferences from. */ private FontListener( Control control, ExternalPreference fontPref, FontRegistry registry ) { this.control = control; this.fontPref = fontPref; this.registry = registry; registry.addListener( this ); removeListener( control ); currentListeners.put( control, this ); }
private static Font deriveFontSize(Font font, String preferenceKey) { int pixelHeight = TIMELINE_PREFERENCES.getInt(preferenceKey); if (font == null) { font = Display.getDefault().getSystemFont(); } Device device = font.getDevice(); if (device == null) { device = WidgetUtils.getDisplay(); } int pixelsPerInch = device.getDPI().y; int pointHeight; if (pixelsPerInch == 0) { pointHeight = pixelHeight; } else { pointHeight = POINTS_PER_INCH * pixelHeight / pixelsPerInch; } FontData[] fontData = font.getFontData(); for (int i=0; i<fontData.length; i++) { fontData[i].setHeight(pointHeight); } String symbolicFontName = font.toString() + "_" + pointHeight; FontRegistry fontRegistry = FontUtils.FONT_REGISTRY_INSTANCE; boolean fontExists = fontRegistry.getKeySet().contains(symbolicFontName); Font desiredFont = null; if(!fontExists) { desiredFont = FontUtils.getStyledFont(font.getDevice(), fontData); fontRegistry.put(symbolicFontName, fontData); } else { desiredFont = fontRegistry.get(symbolicFontName); } return desiredFont; }
private Font getBoldFont() { Font systemFont = FontUtils.getSystemFont(); int desiredFontHeight = 10; String symbolicFontName = systemFont.toString() + "_" + desiredFontHeight; FontRegistry fontRegistry = FontUtils.FONT_REGISTRY_INSTANCE; boolean fontExists = fontRegistry.getKeySet().contains(symbolicFontName); Font font = null; if(!fontExists) { font = FontUtils.getStyledFont(desiredFontHeight, SWT.NONE); fontRegistry.put(symbolicFontName, font.getFontData()); } else { font = fontRegistry.get(symbolicFontName); } return font; }
/** * Inits the fonts for the dialog. * * @param fontRegistry * fontRegistry */ public static void initFonts(FontRegistry fontRegistry) { FontData[] fontData = JFaceResources.getDialogFontDescriptor().getFontData(); if (fontData.length > 0) { fontData[0].setStyle(SWT.ITALIC); fontData[0].setHeight(fontData[0].getHeight() - 1); } fontRegistry.put("titleLabel", fontData); fontRegistry.put("content", JFaceResources.getDialogFontDescriptor().getFontData()); }
protected void populateTree(Map<String, List<UpgradeConflict>> upgradeConflicts) { TreeSet<String> sortedComponentTypes = new TreeSet<>(); sortedComponentTypes.addAll(upgradeConflicts.keySet()); // loop thru sorted list creating upgrade component tree for (String componentType : sortedComponentTypes) { // create root component type node TreeItem componentTypeTreeItem = new TreeItem(getTreeComponentConflicts(), SWT.NONE); componentTypeTreeItem.setText(componentType); FontRegistry registry = new FontRegistry(); Font boldFont = registry.getBold(Display.getCurrent().getSystemFont().getFontData()[0].getName()); componentTypeTreeItem.setFont(boldFont); componentTypeTreeItem.setExpanded(true); // loop thru each component instance and create named node List<UpgradeConflict> upgradeComponents = upgradeConflicts.get(componentType); for (UpgradeConflict upgradeConflict : upgradeComponents) { TreeItem componentTreeItem = new TreeItem(componentTypeTreeItem, SWT.NONE); componentTreeItem.setText(upgradeConflict.getLocalComponent().getFileName()); componentTreeItem.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE)); componentTreeItem.setData("local", upgradeConflict.getLocalComponent()); componentTreeItem.setData("remote", upgradeConflict.getRemoteComponent()); componentTreeItem.setExpanded(true); } } }
public void updateSummaryLabel(int candidateCnt, String orgUserName) { if (lblSummary != null) { lblSummary.setText("Found " + candidateCnt + " deployment candidates"); FontRegistry registry = new FontRegistry(); Font boldFont = registry.getBold(Display.getCurrent().getSystemFont().getFontData()[0].getName()); lblSummary.setFont(boldFont); lblSummary.update(); } }
public static Font getPreferenceFont(Display display, String name) { FontRegistry fontRegistry = JFaceResources.getFontRegistry(); FontData[] fonts = fontRegistry.filterData(getPreferenceFont(name), display); if (fonts == null) return fontRegistry.defaultFont(); return new Font(display, fonts); }
private void initFonts() { FontData[] fontData = Display.getCurrent().getSystemFont().getFontData(); String fontName = fontData[0].getName(); FontRegistry registry = JFaceResources.getFontRegistry(); boldFont = registry.getBold(fontName); }
private static void updateFontEntries( Display display ) { FontRegistry fontRegistry = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getFontRegistry(); if( fontRegistry.getFontData( "org.eclipse.jface.textfont" )[ 0 ].getName().equals( FONT_FACE ) ) { updateFontEntry( display, fontRegistry, "org.eclipse.ui.workbench.texteditor.blockSelectionModeFont" ); updateFontEntry( display, fontRegistry, "org.eclipse.jface.textfont" ); updateFontEntry( display, fontRegistry, "org.eclipse.jdt.ui.editors.textfont" ); } }
private static void updateFontEntry( Display display, FontRegistry fontRegistry, String symbolicName ) { Font textFont = fontRegistry.get( symbolicName ); fontRegistry.put( symbolicName, display.getSystemFont().getFontData() ); display.readAndDispatch(); fontRegistry.put( symbolicName, textFont.getFontData() ); display.readAndDispatch(); }
public static void updateFont(String cfgName){ FontRegistry fr = JFaceResources.getFontRegistry(); FontData[] fd = PreferenceConverter.getFontDataArray(new SettingsPreferenceStore(CoreHub.userCfg), cfgName); fr.put(cfgName, fd); }
public static Font getFont(String cfgName){ FontRegistry fr = JFaceResources.getFontRegistry(); if (!fr.hasValueFor(cfgName)) { FontData[] fd = PreferenceConverter.getFontDataArray(new SettingsPreferenceStore(CoreHub.userCfg), cfgName); fr.put(cfgName, fd); } return fr.get(cfgName); }
public static Font getFont(String name, int height, int style){ String key = name + ":" + Integer.toString(height) + ":" + Integer.toString(style); //$NON-NLS-1$ //$NON-NLS-2$ FontRegistry fr = JFaceResources.getFontRegistry(); if (!fr.hasValueFor(key)) { FontData[] fd = new FontData[] { new FontData(name, height, style) }; fr.put(key, fd); } return fr.get(key); }
protected Font getBoldFont() { final FontRegistry reg = JFaceResources.getFontRegistry(); return reg.getBold(JFaceResources.DEFAULT_FONT); }
protected Font getItalicFont() { final FontRegistry reg = JFaceResources.getFontRegistry(); return reg.getItalic(JFaceResources.DEFAULT_FONT); }
private void registerFont(final Control control) { final FontRegistry fontRegistry = JFaceResources.getFontRegistry(); if (!fontRegistry.hasValueFor(symbolicName)) { fontRegistry.put(symbolicName, control.getFont().getFontData()); } }
/** * Default constructor. * * @param parent * parent * @param conflict * conflict */ public ContextComponent(DecisionBox parent, VisualConflict conflict) { super(parent, SWT.NONE); ConflictContext context = conflict.getConflictContext(); GridLayout layout = new GridLayout(3, false); layout.verticalSpacing = 1; layout.horizontalSpacing = 20; this.setLayout(layout); this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); setBackground(parent.getBackground()); FontRegistry fontRegistry = UIDecisionUtil.getFontRegistry(); Label meTitle = new Label(this, SWT.NONE); meTitle.setText(context.getModelElementTitleLabel()); meTitle.setFont(fontRegistry.get("titleLabel")); meTitle.setBackground(getBackground()); Label attTitle = new Label(this, SWT.NONE); attTitle.setText(context.getAttributeTitleLabel()); attTitle.setFont(fontRegistry.get("titleLabel")); attTitle.setBackground(getBackground()); Label oppTitle = new Label(this, SWT.NONE); oppTitle.setText(context.getOpponentTitleLabel()); oppTitle.setFont(fontRegistry.get("titleLabel")); oppTitle.setBackground(getBackground()); adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE); AdapterFactoryLabelProvider provider = new AdapterFactoryLabelProvider(adapterFactory); CLabel meLabel = new CLabel(this, SWT.NONE); meLabel.setImage(provider.getImage(context.getModelElement())); meLabel.setText(UIDecisionUtil.cutString(provider.getText(context.getModelElement()), 40, true)); meLabel.setToolTipText(DecisionUtil.getClassAndName(context.getModelElement())); meLabel.setFont(fontRegistry.get("content")); meLabel.setBackground(getBackground()); Label attLabel = new Label(this, SWT.NONE); attLabel.setText(context.getAttribute()); attLabel.setFont(fontRegistry.get("content")); attLabel.setBackground(getBackground()); Label oppLable = new Label(this, SWT.NONE); oppLable.setText(context.getOpponent()); oppLable.setFont(fontRegistry.get("content")); oppLable.setBackground(getBackground()); }
/** * Update the UI with the test results for an asynchronous test run. */ @VisibleForTesting public void processAsyncTestResults(final Map<IResource, List<String>> testResources, final List<ApexTestResult> testResults, final boolean expandFailedResults) { if (Utils.isEmpty(testResources) || Utils.isEmpty(testResults)) { return; } Display display = PlatformUI.getWorkbench().getDisplay(); display.syncExec(new Runnable() { @Override public void run() { // Map of tree items whose key is apex class id and the value is the tree item Map<String, TreeItem> testClassNodes = Maps.newLinkedHashMap(); FontRegistry registry = new FontRegistry(); Font boldFont = registry.getBold(Display.getCurrent().getSystemFont().getFontData()[0].getName()); runTestComposite.clearAllExceptProgress(); Tree resultsTree = runTestComposite.getTree(); // Add each test result to the tree for (ApexTestResult testResult: testResults) { // Create or find the tree node for the test class String classId = testResult.getApexClassId(); if (!testClassNodes.containsKey(classId)) { TreeItem newClassNode = createTestClassTreeItem(resultsTree, testResources, boldFont, classId); testClassNodes.put(classId, newClassNode); } // Add the a test method tree node to the test class tree node TreeItem classNode = testClassNodes.get(classId); String className = classNode.getText(); // Create a tree item for the test method and save the test result TreeItem newTestMethodNode = createTestMethodTreeItem(classNode, testResult, className); // Set the color and icon of test method tree node based on test outcome setColorAndIconForNode(newTestMethodNode, testResult.getOutcome()); // Update the color & icon of class tree node only if the test method // outcome is worse than what the class tree node indicates setColorAndIconForTheWorse(classNode, testResult.getOutcome()); } if (expandFailedResults) { // Expand the test classes that did not pass expandProblematicTestClasses(resultsTree); } } }); }
private void setElementBackgroundColor(TableView wQueryElement, String text) { FontRegistry fontRegistry= new FontRegistry(Display.getCurrent()); fontRegistry.put("font", new FontData[]{new FontData("Sans Serif", 9, SWT.BOLD|SWT.ITALIC)} ); FontRegistry defaultFontRegistry= new FontRegistry(Display.getCurrent()); defaultFontRegistry.put("font", new FontData[]{new FontData("Sans Serif", 9, SWT.NORMAL)} ); wQueryElement.table.setFont(defaultFontRegistry.get("font")); if (text.equalsIgnoreCase("CSW_RECORD")&& wQueryElement.table.getItemCount()>=15){ wQueryElement.table.getItem(0).setFont(fontRegistry.get("font")); wQueryElement.table.getItem(1).setFont(fontRegistry.get("font")); wQueryElement.table.getItem(6).setFont(fontRegistry.get("font")); wQueryElement.table.getItem(7).setFont(fontRegistry.get("font")); wQueryElement.table.getItem(10).setFont(fontRegistry.get("font")); wQueryElement.table.getItem(13).setFont(fontRegistry.get("font")); wQueryElement.table.getItem(14).setFont(fontRegistry.get("font")); //wQueryElement.table.getItem(17).setFont(fontRegistry.get("font")); //set foreground color wQueryElement.table.getItem(0).setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED)); wQueryElement.table.getItem(1).setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED)); wQueryElement.table.getItem(6).setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED)); wQueryElement.table.getItem(7).setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED)); wQueryElement.table.getItem(10).setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED)); wQueryElement.table.getItem(13).setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED)); wQueryElement.table.getItem(14).setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED)); }else{ if (text.equalsIgnoreCase("MD_METADATA")&& wQueryElement.table.getItemCount()>=51){ wQueryElement.table.getItem(0).setFont(fontRegistry.get("font")); wQueryElement.table.getItem(1).setFont(fontRegistry.get("font")); wQueryElement.table.getItem(4).setFont(fontRegistry.get("font")); wQueryElement.table.getItem(5).setFont(fontRegistry.get("font")); wQueryElement.table.getItem(12).setFont(fontRegistry.get("font")); wQueryElement.table.getItem(17).setFont(fontRegistry.get("font")); wQueryElement.table.getItem(18).setFont(fontRegistry.get("font")); wQueryElement.table.getItem(25).setFont(fontRegistry.get("font")); wQueryElement.table.getItem(43).setFont(fontRegistry.get("font")); wQueryElement.table.getItem(46).setFont(fontRegistry.get("font")); wQueryElement.table.getItem(47).setFont(fontRegistry.get("font")); wQueryElement.table.getItem(48).setFont(fontRegistry.get("font")); wQueryElement.table.getItem(49).setFont(fontRegistry.get("font")); wQueryElement.table.getItem(50).setFont(fontRegistry.get("font")); wQueryElement.table.getItem(51).setFont(fontRegistry.get("font")); //set foreground color wQueryElement.table.getItem(0).setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED)); wQueryElement.table.getItem(1).setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED)); wQueryElement.table.getItem(4).setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED)); wQueryElement.table.getItem(5).setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED)); wQueryElement.table.getItem(12).setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED)); wQueryElement.table.getItem(17).setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED)); wQueryElement.table.getItem(18).setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED)); wQueryElement.table.getItem(25).setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED)); wQueryElement.table.getItem(43).setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED)); wQueryElement.table.getItem(46).setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED)); wQueryElement.table.getItem(47).setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED)); wQueryElement.table.getItem(48).setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED)); wQueryElement.table.getItem(49).setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED)); wQueryElement.table.getItem(50).setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED)); wQueryElement.table.getItem(51).setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED)); } } }
/** * Returns the font registry. All fonts should be placed in this registry so * they can be properly managed. */ public FontRegistry getFontRegistry() { return fontRegistry; }
/** * Return this themes font registry. * * @return this themes font registry */ FontRegistry getFontRegistry();
/******************************************************* * Constructs a label provider for the results tree view in UI * * @param ir * The {@link SimpleImageRegistry} to be used for locating images * @param fr * The {@link FontRegistry} to be used by this label provider *******************************************************/ public TreeLabelProvider(SimpleImageRegistry ir, FontRegistry fr) { mIr = ir; mFr = fr; }