List of usage examples for org.eclipse.jface.resource JFaceResources getDialogFont
public static Font getDialogFont()
From source file:org.eclipse.ui.internal.editors.text.TextEditorDefaultsPreferencePage.java
License:Open Source License
private Button addCheckBoxWithLink(Composite parent, final Preference preference, String linkText, final Domain domain, int indentation, final SelectionListener listener) { GridData gd = new GridData(GridData.FILL, GridData.FILL, true, false); gd.horizontalSpan = 3;//from w w w .ja v a 2s.c om gd.horizontalIndent = indentation; Composite composite = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; layout.horizontalSpacing = 0; layout.numColumns = 2; composite.setLayout(layout); composite.setLayoutData(gd); final Button checkBox = new Button(composite, SWT.CHECK); checkBox.setFont(JFaceResources.getDialogFont()); checkBox.setText(preference.getName()); gd = new GridData(GridData.FILL, GridData.CENTER, false, false); checkBox.setLayoutData(gd); checkBox.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { checkboxControlChanged(preference, domain, checkBox); } }); gd = new GridData(GridData.FILL, GridData.CENTER, false, false); Link link = new Link(composite, SWT.NONE); link.setText(linkText); link.setLayoutData(gd); if (listener != null) { link.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { listener.widgetSelected(e); } }); } fInitializers.add(fInitializerFactory.create(preference, checkBox)); return checkBox; }
From source file:org.eclipse.ui.internal.ide.dialogs.ResourceFilterGroup.java
License:Open Source License
private static int getButtonWidthHint(Button button) { button.setFont(JFaceResources.getDialogFont()); FontMetrics fontMetrics;//from w w w .j av a 2 s. c om GC gc = new GC(button); try { gc.setFont(button.getFont()); fontMetrics = gc.getFontMetrics(); } finally { gc.dispose(); } int widthHint = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_WIDTH); return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); }
From source file:org.eclipse.ui.internal.quickaccess.QuickAccessContents.java
License:Open Source License
/** * @param composite/*from w w w .ja va2 s.co m*/ */ public Table createTable(Composite composite, int defaultOrientation) { composite.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { doDispose(); } }); Composite tableComposite = new Composite(composite, SWT.NONE); GridDataFactory.fillDefaults().grab(true, true).applyTo(tableComposite); TableColumnLayout tableColumnLayout = new TableColumnLayout(); tableComposite.setLayout(tableColumnLayout); table = new Table(tableComposite, SWT.SINGLE | SWT.FULL_SELECTION); textLayout = new TextLayout(table.getDisplay()); textLayout.setOrientation(defaultOrientation); Font boldFont = resourceManager .createFont(FontDescriptor.createFrom(JFaceResources.getDialogFont()).setStyle(SWT.BOLD)); textLayout.setFont(table.getFont()); textLayout.setText(QuickAccessMessages.QuickAccess_AvailableCategories); int maxProviderWidth = (int) (textLayout.getBounds().width * 1.1); textLayout.setFont(boldFont); for (int i = 0; i < providers.length; i++) { QuickAccessProvider provider = providers[i]; textLayout.setText(provider.getName()); int width = (int) (textLayout.getBounds().width * 1.1); if (width > maxProviderWidth) { maxProviderWidth = width; } } tableColumnLayout.setColumnData(new TableColumn(table, SWT.NONE), new ColumnWeightData(0, maxProviderWidth)); tableColumnLayout.setColumnData(new TableColumn(table, SWT.NONE), new ColumnWeightData(100, 100)); table.getShell().addControlListener(new ControlAdapter() { public void controlResized(ControlEvent e) { if (!showAllMatches) { if (!resized) { resized = true; e.display.timerExec(100, new Runnable() { public void run() { if (table != null && !table.isDisposed()) { refresh(filterText.getText().toLowerCase()); } resized = false; } }); } } } }); table.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { if (e.keyCode == SWT.ARROW_UP && table.getSelectionIndex() == 0) { filterText.setFocus(); } else if (e.character == SWT.ESC) { doClose(); } } public void keyReleased(KeyEvent e) { // do nothing } }); table.addMouseListener(new MouseAdapter() { public void mouseUp(MouseEvent e) { if (table.getSelectionCount() < 1) return; if (e.button != 1) return; if (table.equals(e.getSource())) { Object o = table.getItem(new Point(e.x, e.y)); TableItem selection = table.getSelection()[0]; if (selection.equals(o)) handleSelection(); } } }); table.addMouseMoveListener(new MouseMoveListener() { TableItem lastItem = null; public void mouseMove(MouseEvent e) { if (table.equals(e.getSource())) { Object o = table.getItem(new Point(e.x, e.y)); if (lastItem == null ^ o == null) { table.setCursor(o == null ? null : table.getDisplay().getSystemCursor(SWT.CURSOR_HAND)); } if (o instanceof TableItem) { if (!o.equals(lastItem)) { lastItem = (TableItem) o; table.setSelection(new TableItem[] { lastItem }); } } else if (o == null) { lastItem = null; } } } }); table.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { // do nothing } public void widgetDefaultSelected(SelectionEvent e) { handleSelection(); } }); final TextStyle boldStyle; if (PlatformUI.getPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.USE_COLORED_LABELS)) { boldStyle = new TextStyle(boldFont, null, null); // italicsFont = // resourceManager.createFont(FontDescriptor.createFrom( // table.getFont()).setStyle(SWT.ITALIC)); grayColor = resourceManager .createColor(ColorUtil.blend(table.getBackground().getRGB(), table.getForeground().getRGB())); } else { boldStyle = null; } Listener listener = new Listener() { public void handleEvent(Event event) { QuickAccessEntry entry = (QuickAccessEntry) event.item.getData(); if (entry != null) { switch (event.type) { case SWT.MeasureItem: entry.measure(event, textLayout, resourceManager, boldStyle); break; case SWT.PaintItem: entry.paint(event, textLayout, resourceManager, boldStyle, grayColor); break; case SWT.EraseItem: entry.erase(event); break; } } } }; table.addListener(SWT.MeasureItem, listener); table.addListener(SWT.EraseItem, listener); table.addListener(SWT.PaintItem, listener); return table; }
From source file:org.eclipse.ui.internal.themes.ColorsAndFontsPreferencePage.java
License:Open Source License
/** * Apply the dialog font to the control and store * it for later so that it can be used for a later * update./*from w ww. java 2 s . c o m*/ * @param control */ private void myApplyDialogFont(Control control) { control.setFont(JFaceResources.getDialogFont()); dialogFontWidgets.add(control); }
From source file:org.eclipse.ui.texteditor.templates.CTemplatePreferencePage.java
License:Open Source License
protected Control createContents(Composite ancestor) { Composite parent = new Composite(ancestor, SWT.NONE); GridLayout layout = new GridLayout(); layout.numColumns = 2;//from w ww .ja v a 2s . c om layout.marginHeight = 0; layout.marginWidth = 0; parent.setLayout(layout); Composite innerParent = new Composite(parent, SWT.NONE); GridLayout innerLayout = new GridLayout(); innerLayout.numColumns = 2; innerLayout.marginHeight = 0; innerLayout.marginWidth = 0; innerParent.setLayout(innerLayout); GridData gd = new GridData(GridData.FILL_BOTH); gd.horizontalSpan = 2; innerParent.setLayoutData(gd); Composite tableComposite = new Composite(innerParent, SWT.NONE); GridData data = new GridData(GridData.FILL_BOTH); data.widthHint = 360; data.heightHint = convertHeightInCharsToPixels(10); tableComposite.setLayoutData(data); ColumnLayout columnLayout = new ColumnLayout(); tableComposite.setLayout(columnLayout); Table table = new Table(tableComposite, SWT.CHECK | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL); table.setHeaderVisible(true); table.setLinesVisible(true); GC gc = new GC(getShell()); gc.setFont(JFaceResources.getDialogFont()); TableColumn column1 = new TableColumn(table, SWT.NONE); column1.setText("Name"); int minWidth = computeMinimumColumnWidth(gc, "Name"); columnLayout.addColumnData(new ColumnWeightData(2, minWidth, true)); // TableColumn column2 = new TableColumn(table, SWT.NONE); // column2.setText("Context"); // minWidth = computeMinimumContextColumnWidth(gc); // columnLayout.addColumnData(new ColumnWeightData(1, minWidth, true)); TableColumn column3 = new TableColumn(table, SWT.NONE); column3.setText("File Name"); minWidth = computeMinimumColumnWidth(gc, "File Name"); columnLayout.addColumnData(new ColumnWeightData(3, minWidth, true)); // TableColumn column4 = new TableColumn(table, SWT.NONE); // column4.setAlignment(SWT.CENTER); // column4.setText("Auto Insert"); // minWidth = computeMinimumColumnWidth(gc, "Auto Insert"); // minWidth = Math.max(minWidth, computeMinimumColumnWidth(gc, "on")); // columnLayout.addColumnData(new ColumnPixelData(minWidth, false, // false)); gc.dispose(); fTableViewer = new CheckboxTableViewer(table); fTableViewer.setLabelProvider(new TemplateLabelProvider()); fTableViewer.setContentProvider(new TemplateContentProvider()); fTableViewer.setComparator(new ViewerComparator() { public int compare(Viewer viewer, Object object1, Object object2) { if ((object1 instanceof TemplatePersistenceData) && (object2 instanceof TemplatePersistenceData)) { Template left = ((TemplatePersistenceData) object1).getTemplate(); Template right = ((TemplatePersistenceData) object2).getTemplate(); int result = Collator.getInstance().compare(left.getName(), right.getName()); if (result != 0) return result; return Collator.getInstance().compare(left.getDescription(), right.getDescription()); } return super.compare(viewer, object1, object2); } public boolean isSorterProperty(Object element, String property) { return true; } }); fTableViewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent e) { edit(); } }); fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent e) { selectionChanged1(); } }); fTableViewer.addCheckStateListener(new ICheckStateListener() { public void checkStateChanged(CheckStateChangedEvent event) { TemplatePersistenceData d = (TemplatePersistenceData) event.getElement(); d.setEnabled(event.getChecked()); } }); Composite buttons = new Composite(innerParent, SWT.NONE); buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; buttons.setLayout(layout); fAddButton = new Button(buttons, SWT.PUSH); fAddButton.setText("New..."); fAddButton.setLayoutData(getButtonGridData(fAddButton)); fAddButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { add(); } }); fAddButton.setEnabled(false); fEditButton = new Button(buttons, SWT.PUSH); fEditButton.setText("Edit..."); fEditButton.setLayoutData(getButtonGridData(fEditButton)); fEditButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { edit(); } }); fRemoveButton = new Button(buttons, SWT.PUSH); fRemoveButton.setText("Remove"); fRemoveButton.setLayoutData(getButtonGridData(fRemoveButton)); fRemoveButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { remove(); } }); fRemoveButton.setEnabled(false); createSeparator(buttons); fRestoreButton = new Button(buttons, SWT.PUSH); fRestoreButton.setText("Restore Removed"); fRestoreButton.setLayoutData(getButtonGridData(fRestoreButton)); fRestoreButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { restoreDeleted(); } }); fRevertButton = new Button(buttons, SWT.PUSH); fRevertButton.setText("Revert to Default"); fRevertButton.setLayoutData(getButtonGridData(fRevertButton)); fRevertButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { revert(); } }); createSeparator(buttons); fImportButton = new Button(buttons, SWT.PUSH); fImportButton.setText("Import..."); fImportButton.setLayoutData(getButtonGridData(fImportButton)); fImportButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { import_(); } }); fImportButton.setEnabled(false); fExportButton = new Button(buttons, SWT.PUSH); fExportButton.setText("Export..."); fExportButton.setLayoutData(getButtonGridData(fExportButton)); fExportButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { export(); } }); fExportButton.setEnabled(false); fPatternViewer = doCreateViewer(parent); if (isShowFormatterSetting()) { fFormatButton = new Button(parent, SWT.CHECK); fFormatButton.setText("Code Format"); GridData gd1 = new GridData(); gd1.horizontalSpan = 2; fFormatButton.setLayoutData(gd1); fFormatButton.setSelection(getPreferenceStore().getBoolean(getFormatterPreferenceKey())); } fTableViewer.setInput(fTemplateStore); fTableViewer.setAllChecked(false); fTableViewer.setCheckedElements(getEnabledTemplates()); updateButtons(); Dialog.applyDialogFont(parent); innerParent.layout(); return parent; }
From source file:org.eclipse.ui.texteditor.templates.TemplatePreferencePage.java
License:Open Source License
protected Control createContents(Composite ancestor) { Composite parent = new Composite(ancestor, SWT.NONE); GridLayout layout = new GridLayout(); layout.numColumns = 2;/* w w w .j av a 2s .co m*/ layout.marginHeight = 0; layout.marginWidth = 0; parent.setLayout(layout); Composite innerParent = new Composite(parent, SWT.NONE); GridLayout innerLayout = new GridLayout(); innerLayout.numColumns = 2; innerLayout.marginHeight = 0; innerLayout.marginWidth = 0; innerParent.setLayout(innerLayout); GridData gd = new GridData(GridData.FILL_BOTH); gd.horizontalSpan = 2; innerParent.setLayoutData(gd); Composite tableComposite = new Composite(innerParent, SWT.NONE); GridData data = new GridData(GridData.FILL_BOTH); data.widthHint = 360; data.heightHint = convertHeightInCharsToPixels(10); tableComposite.setLayoutData(data); ColumnLayout columnLayout = new ColumnLayout(); tableComposite.setLayout(columnLayout); Table table = new Table(tableComposite, SWT.CHECK | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL); table.setHeaderVisible(true); table.setLinesVisible(true); GC gc = new GC(getShell()); gc.setFont(JFaceResources.getDialogFont()); TableColumn column1 = new TableColumn(table, SWT.NONE); column1.setText(TemplatesMessages.TemplatePreferencePage_column_name); int minWidth = computeMinimumColumnWidth(gc, TemplatesMessages.TemplatePreferencePage_column_name); columnLayout.addColumnData(new ColumnWeightData(2, minWidth, true)); TableColumn column2 = new TableColumn(table, SWT.NONE); column2.setText(TemplatesMessages.TemplatePreferencePage_column_context); minWidth = computeMinimumContextColumnWidth(gc); columnLayout.addColumnData(new ColumnWeightData(1, minWidth, true)); TableColumn column3 = new TableColumn(table, SWT.NONE); column3.setText(TemplatesMessages.TemplatePreferencePage_column_description); minWidth = computeMinimumColumnWidth(gc, TemplatesMessages.TemplatePreferencePage_column_description); columnLayout.addColumnData(new ColumnWeightData(3, minWidth, true)); TableColumn column4 = new TableColumn(table, SWT.NONE); column4.setAlignment(SWT.CENTER); column4.setText(TemplatesMessages.TemplatePreferencePage_column_autoinsert); minWidth = computeMinimumColumnWidth(gc, TemplatesMessages.TemplatePreferencePage_column_autoinsert); minWidth = Math.max(minWidth, computeMinimumColumnWidth(gc, TemplatesMessages.TemplatePreferencePage_on)); columnLayout.addColumnData(new ColumnPixelData(minWidth, false, false)); gc.dispose(); fTableViewer = new CheckboxTableViewer(table); fTableViewer.setLabelProvider(new TemplateLabelProvider()); fTableViewer.setContentProvider(new TemplateContentProvider()); fTableViewer.setComparator(new ViewerComparator() { public int compare(Viewer viewer, Object object1, Object object2) { if ((object1 instanceof TemplatePersistenceData) && (object2 instanceof TemplatePersistenceData)) { Template left = ((TemplatePersistenceData) object1).getTemplate(); Template right = ((TemplatePersistenceData) object2).getTemplate(); int result = Collator.getInstance().compare(left.getName(), right.getName()); if (result != 0) return result; return Collator.getInstance().compare(left.getDescription(), right.getDescription()); } return super.compare(viewer, object1, object2); } public boolean isSorterProperty(Object element, String property) { return true; } }); fTableViewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent e) { edit(); } }); fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent e) { selectionChanged1(); } }); fTableViewer.addCheckStateListener(new ICheckStateListener() { public void checkStateChanged(CheckStateChangedEvent event) { TemplatePersistenceData d = (TemplatePersistenceData) event.getElement(); d.setEnabled(event.getChecked()); } }); Composite buttons = new Composite(innerParent, SWT.NONE); buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; buttons.setLayout(layout); fAddButton = new Button(buttons, SWT.PUSH); fAddButton.setText(TemplatesMessages.TemplatePreferencePage_new); fAddButton.setLayoutData(getButtonGridData(fAddButton)); fAddButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { add(); } }); fEditButton = new Button(buttons, SWT.PUSH); fEditButton.setText(TemplatesMessages.TemplatePreferencePage_edit); fEditButton.setLayoutData(getButtonGridData(fEditButton)); fEditButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { edit(); } }); fRemoveButton = new Button(buttons, SWT.PUSH); fRemoveButton.setText(TemplatesMessages.TemplatePreferencePage_remove); fRemoveButton.setLayoutData(getButtonGridData(fRemoveButton)); fRemoveButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { remove(); } }); createSeparator(buttons); fRestoreButton = new Button(buttons, SWT.PUSH); fRestoreButton.setText(TemplatesMessages.TemplatePreferencePage_restore); fRestoreButton.setLayoutData(getButtonGridData(fRestoreButton)); fRestoreButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { restoreDeleted(); } }); fRevertButton = new Button(buttons, SWT.PUSH); fRevertButton.setText(TemplatesMessages.TemplatePreferencePage_revert); fRevertButton.setLayoutData(getButtonGridData(fRevertButton)); fRevertButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { revert(); } }); createSeparator(buttons); fImportButton = new Button(buttons, SWT.PUSH); fImportButton.setText(TemplatesMessages.TemplatePreferencePage_import); fImportButton.setLayoutData(getButtonGridData(fImportButton)); fImportButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { import_(); } }); fExportButton = new Button(buttons, SWT.PUSH); fExportButton.setText(TemplatesMessages.TemplatePreferencePage_export); fExportButton.setLayoutData(getButtonGridData(fExportButton)); fExportButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { export(); } }); fPatternViewer = doCreateViewer(parent); if (isShowFormatterSetting()) { fFormatButton = new Button(parent, SWT.CHECK); fFormatButton.setText(TemplatesMessages.TemplatePreferencePage_use_code_formatter); GridData gd1 = new GridData(); gd1.horizontalSpan = 2; fFormatButton.setLayoutData(gd1); fFormatButton.setSelection(getPreferenceStore().getBoolean(getFormatterPreferenceKey())); } fTableViewer.setInput(fTemplateStore); fTableViewer.setAllChecked(false); fTableViewer.setCheckedElements(getEnabledTemplates()); updateButtons(); Dialog.applyDialogFont(parent); innerParent.layout(); return parent; }
From source file:org.eclipse.userstorage.ui.AbstractDialog.java
License:Open Source License
private boolean hasSameFont(IDialogSettings settings) { String previousFontData = settings.get(DIALOG_FONT_DATA); if (StringUtil.isEmpty(previousFontData)) { return false; }/* w ww. j a v a2 s . co m*/ FontData[] fontDatas = JFaceResources.getDialogFont().getFontData(); if (fontDatas.length == 0) { return false; } String currentFontData = fontDatas[0].toString(); return previousFontData.equalsIgnoreCase(currentFontData); }
From source file:org.eclipse.virgo.ide.ui.editors.text.JFaceAbstractInformationControl.java
License:Open Source License
private void createStatusLabel(final String statusFieldText, Color foreground, Color background) { this.fStatusLabel = new Label(this.fStatusComposite, SWT.RIGHT); this.fStatusLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); this.fStatusLabel.setText(statusFieldText); FontData[] fontDatas = JFaceResources.getDialogFont().getFontData(); for (FontData element : fontDatas) { element.setHeight(element.getHeight() * 9 / 10); }/*from ww w. j a v a2 s . c o m*/ this.fStatusLabel.setFont(new Font(this.fStatusLabel.getDisplay(), fontDatas)); this.fStatusLabel .setForeground(this.fStatusLabel.getDisplay().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW)); this.fStatusLabel.setBackground(background); setColor(this.fStatusComposite, foreground, background); }
From source file:org.eclipse.virgo.ide.ui.editors.text.JFaceAbstractInformationControl.java
License:Open Source License
/** * Computes the size constraints based on the {@link JFaceResources#getDialogFont() dialog font}. Subclasses can * override or extend./*from w ww .j a v a 2 s. com*/ * * @see org.eclipse.jface.text.IInformationControlExtension5#computeSizeConstraints(int, int) */ public Point computeSizeConstraints(int widthInChars, int heightInChars) { GC gc = new GC(this.fContentComposite); gc.setFont(JFaceResources.getDialogFont()); int width = gc.getFontMetrics().getAverageCharWidth(); int height = gc.getFontMetrics().getHeight(); gc.dispose(); return new Point(widthInChars * width, heightInChars * height); }
From source file:org.eclipse.virgo.ide.ui.editors.text.JFaceDefaultInformationControl.java
License:Open Source License
@Override protected void createContent(Composite parent) { this.fText = new StyledText(parent, SWT.MULTI | SWT.READ_ONLY | this.fAdditionalTextStyles); this.fText.setForeground(parent.getForeground()); this.fText.setBackground(parent.getBackground()); this.fText.setFont(JFaceResources.getDialogFont()); FillLayout layout = (FillLayout) parent.getLayout(); if (this.fText.getWordWrap()) { // indent does not work for wrapping StyledText, see // https://bugs.eclipse.org/bugs/show_bug.cgi?id=56342 and // https://bugs.eclipse.org/bugs/show_bug.cgi?id=115432 layout.marginHeight = INNER_BORDER; layout.marginWidth = INNER_BORDER; } else {// www . j av a 2s. co m this.fText.setIndent(INNER_BORDER); } }