List of usage examples for org.eclipse.jface.resource JFaceResources getDialogFont
public static Font getDialogFont()
From source file:net.sf.eclipsensis.installoptions.properties.tabbed.section.ListItemsPropertySectionCreator.java
License:Open Source License
protected CheckboxTableViewer createListItemsAndStateSection(Composite parent, TabbedPropertySheetWidgetFactory widgetFactory, final InstallOptionsCommandHelper commandHelper) { final IPropertyDescriptor listItemsDescriptor = getWidget() .getPropertyDescriptor(InstallOptionsModel.PROPERTY_LISTITEMS); final IPropertyDescriptor stateDescriptor = getWidget() .getPropertyDescriptor(InstallOptionsModel.PROPERTY_STATE); if (listItemsDescriptor != null && stateDescriptor != null) { final boolean[] nonUserChange = { false }; Composite parent2 = widgetFactory.createGroup(parent, listItemsDescriptor.getDisplayName()); GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); data.horizontalSpan = 2;/* ww w. j ava 2 s . com*/ parent2.setLayoutData(data); GridLayout gridLayout = new GridLayout(2, false); gridLayout.verticalSpacing = 0; gridLayout.marginHeight = 0; gridLayout.marginTop = 2; parent2.setLayout(gridLayout); final Table table = widgetFactory.createTable(parent2, SWT.FLAT | SWT.CHECK | SWT.MULTI); GC gc = new GC(table); gc.setFont(JFaceResources.getDialogFont()); FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose(); data = new GridData(SWT.FILL, SWT.FILL, true, true); data.widthHint = fontMetrics.getAverageCharWidth() * 30; data.heightHint = fontMetrics.getHeight() * 5; table.setLayoutData(data); final CheckboxTableViewer viewer = new CheckboxTableViewer(table); viewer.setContentProvider(new CollectionContentProvider()); viewer.setLabelProvider(new LabelProvider()); viewer.setComparer(new IElementComparer() { public boolean equals(Object a, Object b) { if (a instanceof String && b instanceof String) { return Common.stringsAreEqual((String) a, (String) b, true); } return Common.objectsAreEqual(a, b); } public int hashCode(Object element) { Object element2 = element; if (element2 != null) { if (element2 instanceof String) { element2 = ((String) element2).toLowerCase(); } return element2.hashCode(); } return 0; } }); final InstallOptionsListItems widget = (InstallOptionsListItems) getWidget(); final List<String> listItems = new ArrayList<String>(widget.getListItems()); String[] state = Common.tokenize(widget.getState(), IInstallOptionsConstants.LIST_SEPARATOR); final ICellEditorValidator stateValidator = PropertyDescriptorHelper .getCellEditorValidator((PropertyDescriptor) stateDescriptor); viewer.addCheckStateListener(new ICheckStateListener() { public void checkStateChanged(CheckStateChangedEvent event) { if (!nonUserChange[0]) { boolean checked = event.getChecked(); String oldState = getWidget().getStringPropertyValue(InstallOptionsModel.PROPERTY_STATE); String newState; if (checked && !((InstallOptionsListItems) getWidget()).isMultiSelect()) { String element = (String) event.getElement(); viewer.setCheckedElements(new String[] { element }); newState = element; } else { newState = Common.flatten(viewer.getCheckedElements(), IInstallOptionsConstants.LIST_SEPARATOR); } if (!Common.stringsAreEqual(oldState, newState, true)) { String error = stateValidator.isValid(newState); if (Common.isEmpty(error)) { commandHelper.propertyChanged(InstallOptionsModel.PROPERTY_STATE, stateDescriptor.getDisplayName(), getWidget(), newState); } else { Common.openError(viewer.getTable().getShell(), error, InstallOptionsPlugin.getShellImage()); viewer.setCheckedElements( Common.tokenize(oldState, IInstallOptionsConstants.LIST_SEPARATOR)); } } } } }); viewer.setInput(listItems); viewer.setCheckedElements(state); final PropertyChangeListener listener = new PropertyChangeListener() { @SuppressWarnings("unchecked") public void propertyChange(PropertyChangeEvent evt) { nonUserChange[0] = true; try { if (evt.getPropertyName().equals(InstallOptionsModel.PROPERTY_LISTITEMS)) { List<String> list = (List<String>) evt.getNewValue(); if (Common.isValid(viewer.getControl())) { List<String> oldInput = (List<String>) viewer.getInput(); if (!Common.objectsAreEqual(list, oldInput)) { viewer.setInput(new ArrayList<String>(list)); String state = ((InstallOptionsListItems) getWidget()).getState(); viewer.setCheckedElements( Common.tokenize(state, IInstallOptionsConstants.LIST_SEPARATOR)); } } } else if (evt.getPropertyName().equals(InstallOptionsModel.PROPERTY_STATE)) { String state = (String) evt.getNewValue(); if (Common.isValid(viewer.getControl())) { viewer.setCheckedElements( Common.tokenize(state, IInstallOptionsConstants.LIST_SEPARATOR)); } } } finally { nonUserChange[0] = false; } } }; widget.addPropertyChangeListener(listener); table.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { widget.removePropertyChangeListener(listener); } }); Composite buttons = widgetFactory.createComposite(parent2); buttons.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true)); GridLayout layout = new GridLayout(2, true); layout.marginHeight = layout.marginWidth = 0; buttons.setLayout(layout); createListAndStateButtons(buttons, viewer, widgetFactory, commandHelper); CLabel l = widgetFactory.createCLabel(parent2, InstallOptionsPlugin.getResourceString("listitems.state.checked.items.message"), SWT.FLAT); //$NON-NLS-1$ FontData[] fd = l.getFont().getFontData(); for (int i = 0; i < fd.length; i++) { fd[i].setStyle(fd[i].getStyle() | SWT.BOLD); fd[i].setHeight((int) (fd[i].getHeight() * 0.9)); } final Font f = new Font(l.getDisplay(), fd); l.setFont(f); l.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { f.dispose(); } }); data = new GridData(SWT.FILL, SWT.FILL, true, false); data.horizontalSpan = 2; l.setLayoutData(data); return viewer; } return null; }
From source file:net.sf.eclipsensis.template.AbstractTemplateSettings.java
License:Open Source License
protected void createContents() { GC gc = new GC(this); Font old = gc.getFont();/*from w w w . j ava 2s. c o m*/ gc.setFont(JFaceResources.getDialogFont()); FontMetrics fontMetrics = gc.getFontMetrics(); gc.setFont(old); gc.dispose(); GridLayout layout = new GridLayout(); layout.numColumns = 2; layout.marginHeight = 0; layout.marginWidth = 0; this.setLayout(layout); Composite innerParent = new Composite(this, SWT.NONE); GridLayout innerLayout = new GridLayout(); innerLayout.numColumns = 2; innerLayout.marginHeight = 0; innerLayout.marginWidth = 0; innerParent.setLayout(innerLayout); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); gd.horizontalSpan = 2; innerParent.setLayoutData(gd); final Table table = new Table(innerParent, SWT.CHECK | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.V_SCROLL); GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); data.widthHint = fontMetrics.getAverageCharWidth() * 3; data.heightHint = fontMetrics.getHeight() * 10; table.setLayoutData(data); table.setHeaderVisible(true); table.setLinesVisible(true); TableColumn[] columns = { new TableColumn(table, SWT.NONE) }; columns[0].setText(EclipseNSISPlugin.getResourceString("template.settings.name.label")); //$NON-NLS-1$ mTableViewer = new CheckboxTableViewer(table); mTableViewer.setLabelProvider(new CollectionLabelProvider()); mTableViewer.setContentProvider(new EmptyContentProvider() { /* (non-Javadoc) * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) */ @Override public Object[] getElements(Object inputElement) { if (inputElement != null && inputElement.equals(mTemplateManager)) { return mTemplateManager.getTemplates().toArray(); } return super.getElements(inputElement); } }); Collator collator = Collator.getInstance(); collator.setStrength(Collator.PRIMARY); mTableViewer.setSorter(new ViewerSorter(collator)); ViewerFilter filter = new ViewerFilter() { @Override @SuppressWarnings("unchecked") public boolean select(Viewer viewer, Object parentElement, Object element) { if (element != null && mTemplateManager.getTemplateClass().isAssignableFrom(element.getClass())) { T template = (T) element; return template.isAvailable() && !template.isDeleted(); } return true; } }; mTableViewer.addFilter(filter); final INSISHomeListener nsisHomeListener = new INSISHomeListener() { public void nsisHomeChanged(IProgressMonitor monitor, NSISHome oldHome, NSISHome newHome) { Display.getDefault().asyncExec(new Runnable() { public void run() { mTableViewer.refresh(); mTableViewer.setCheckedElements(getEnabledTemplates()); } }); } }; NSISPreferences.getInstance().addListener(nsisHomeListener); table.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { NSISPreferences.getInstance().removeListener(nsisHomeListener); } }); mTableViewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent e) { edit(); } }); mTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent e) { doSelectionChanged(); } }); mTableViewer.addCheckStateListener(new ICheckStateListener() { @SuppressWarnings("unchecked") public void checkStateChanged(CheckStateChangedEvent event) { T oldTemplate = (T) event.getElement(); T newTemplate = (T) oldTemplate.clone(); newTemplate.setEnabled(!oldTemplate.isEnabled()); getTemplateManager().updateTemplate(oldTemplate, newTemplate); mTableViewer.refresh(true); mTableViewer.setSelection(new StructuredSelection(newTemplate)); mTableViewer.setChecked(newTemplate, newTemplate.isEnabled()); doSelectionChanged(); } }); Composite buttons = new Composite(innerParent, SWT.NONE); buttons.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false)); layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; buttons.setLayout(layout); createButtons(buttons); Label label = new Label(this, SWT.NONE); label.setText(EclipseNSISPlugin.getResourceString("template.settings.description.label")); //$NON-NLS-1$ data = new GridData(); data.horizontalSpan = 2; label.setLayoutData(data); mDescriptionText = new StyledText(this, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY | SWT.WRAP); mDescriptionText.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); mDescriptionText.setCursor(null); mDescriptionText.setCaret(null); data = new GridData(SWT.FILL, SWT.FILL, true, true); data.horizontalSpan = 2; data.heightHint = fontMetrics.getHeight() * 5; mDescriptionText.setLayoutData(data); mTableViewer.setInput(mTemplateManager); mTableViewer.setCheckedElements(getEnabledTemplates()); updateButtons(); table.addControlListener(new TableResizer()); Dialog.applyDialogFont(this); }
From source file:net.sf.jmoney.views.feedback.FeedbackHistorySelectionDialog.java
License:Open Source License
@Override protected Control createDialogArea(Composite container) { Composite ancestor = (Composite) super.createDialogArea(container); createMessageArea(ancestor);// w w w . j a va2s . c o m Composite parent = new Composite(ancestor, SWT.NONE); GridLayout layout = new GridLayout(); layout.numColumns = 2; layout.marginHeight = 0; layout.marginWidth = 0; parent.setLayout(layout); parent.setLayoutData(new GridData(GridData.FILL_BOTH)); fViewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION); fViewer.setContentProvider(new ArrayContentProvider()); final Table table = fViewer.getTable(); table.addMouseListener(new MouseAdapter() { @Override public void mouseDoubleClick(MouseEvent e) { okPressed(); } }); fViewer.setLabelProvider(new FeedbackLabelProvider()); GridData gd = new GridData(GridData.FILL_BOTH); gd.heightHint = convertHeightInCharsToPixels(15); gd.widthHint = convertWidthInCharsToPixels(WIDTH_IN_CHARACTERS); table.setLayoutData(gd); fRemoveButton = new Button(parent, SWT.PUSH); fRemoveButton.setText("&Remove"); fRemoveButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { buttonPressed(REMOVE_ID); } }); GridData removeButtonLayoutData = new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false); fRemoveButton.setFont(JFaceResources.getDialogFont()); GC gc = new GC(fRemoveButton); gc.setFont(fRemoveButton.getFont()); FontMetrics fFontMetrics = gc.getFontMetrics(); gc.dispose(); int widthHint = Dialog.convertHorizontalDLUsToPixels(fFontMetrics, IDialogConstants.BUTTON_WIDTH); removeButtonLayoutData.widthHint = Math.max(widthHint, fRemoveButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); removeButtonLayoutData.horizontalAlignment = GridData.FILL; fRemoveButton.setLayoutData(removeButtonLayoutData); fViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { validateDialogState(); } }); Label fLink = new Label(parent, SWT.NONE); fLink.setText(MessageFormat.format("History limited to {0} result sets not shown in views.", new Integer(historyLimit))); fLink.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1)); applyDialogFont(ancestor); // set input & selections last, so all the widgets are created. fViewer.setInput(fInput); fViewer.getTable().setFocus(); return ancestor; }
From source file:net.tourbook.common.UI.java
License:Open Source License
/** * This is a copy with modifications from {@link org.eclipse.jface.dialogs.Dialog} * /*from w ww.j a va 2 s . c o m*/ * @param statePrefix */ public static void saveDialogBounds(final IDialogSettings state, final String statePrefix, final Shell shell, final Shell parentShell) { if (state != null) { final Point shellLocation = shell.getLocation(); final Point shellSize = shell.getSize(); if (parentShell != null) { final Point parentLocation = parentShell.getLocation(); shellLocation.x -= parentLocation.x; shellLocation.y -= parentLocation.y; } state.put(statePrefix + DIALOG_ORIGIN_X, shellLocation.x); state.put(statePrefix + DIALOG_ORIGIN_Y, shellLocation.y); state.put(statePrefix + DIALOG_WIDTH, shellSize.x); state.put(statePrefix + DIALOG_HEIGHT, shellSize.y); final FontData[] fontDatas = JFaceResources.getDialogFont().getFontData(); if (fontDatas.length > 0) { state.put(statePrefix + DIALOG_FONT_DATA, fontDatas[0].toString()); } } }
From source file:net.tourbook.common.UI.java
License:Open Source License
private static boolean setupUI_FontMetrics() { if (_fontMetrics != null) { return true; }/*from ww w. j a va2 s . com*/ // Compute and keep a font metric final Shell activeShell = Display.getDefault().getActiveShell(); if (activeShell == null) { // this can occure when called too early return false; } final GC gc = new GC(activeShell); { gc.setFont(JFaceResources.getDialogFont()); _fontMetrics = gc.getFontMetrics(); } gc.dispose(); return true; }
From source file:org.apache.directory.studio.aciitemeditor.Activator.java
License:Apache License
/** * Returns the button with respect to the font metrics. * * @param control a control/*from w ww.ja v a2 s . c o m*/ * @return the button width */ public static int getButtonWidth(Control control) { GC gc = new GC(control); try { gc.setFont(JFaceResources.getDialogFont()); FontMetrics fontMetrics = gc.getFontMetrics(); int width = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_WIDTH); return width; } finally { gc.dispose(); } }
From source file:org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils.java
License:Apache License
/** * Creates a button under the given parent. * The button width is set to the default width. * * @param parent the parent/*from ww w. j a v a2 s .c om*/ * @param text the label of the button * @param span the horizontal span * @return the created button */ public static Button createButton(Composite parent, String text, int span) { GC gc = new GC(parent); try { gc.setFont(JFaceResources.getDialogFont()); FontMetrics fontMetrics = gc.getFontMetrics(); Button button = new Button(parent, SWT.PUSH); GridData gridData = new GridData(); gridData.widthHint = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_WIDTH); gridData.horizontalSpan = span; button.setLayoutData(gridData); button.setText(text); return button; } finally { gc.dispose(); } }
From source file:org.apache.directory.studio.ldapbrowser.common.dialogs.TextDialog.java
License:Apache License
protected Button createButton(Composite parent, int id, String label, boolean defaultButton, int style) { // increment the number of columns in the button bar ((GridLayout) parent.getLayout()).numColumns++; Button button = new Button(parent, style); button.setText(label);/* ww w .j av a 2 s .co m*/ button.setFont(JFaceResources.getDialogFont()); button.setData(Integer.valueOf(id)); button.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { buttonPressed(((Integer) event.widget.getData()).intValue()); } }); if (defaultButton) { Shell shell = parent.getShell(); if (shell != null) { shell.setDefaultButton(button); } } buttons.put(Integer.valueOf(id), button); setButtonLayoutData(button); return button; }
From source file:org.bbaw.pdr.ae.config.editor.internal.CreateConfigDialog.java
License:Open Source License
/** * creates OKButton.//from w w w.jav a 2 s. c om * * @param parent * parent composite * @param id * id * @param label * label of button * @param defaultButton * is default * @return button */ protected final Button createOkButton(final Composite parent, final int id, final String label, final boolean defaultButton) { // increment the number of columns in the button bar ((GridLayout) parent.getLayout()).numColumns++; _okbutton = new Button(parent, SWT.PUSH); _okbutton.setText(label); _okbutton.setFont(JFaceResources.getDialogFont()); _okbutton.setData(new Integer(id)); _okbutton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent event) { if (isValidInput()) { okPressed(); saveInput(); close(); } } }); if (defaultButton) { Shell shell = parent.getShell(); if (shell != null) { shell.setDefaultButton(_okbutton); } } setButtonLayoutData(_okbutton); return _okbutton; }
From source file:org.bbaw.pdr.ae.config.editor.view.ConfigEditor.java
License:Open Source License
/** * create ok button.// w w w . j a va 2 s . co m * @param parent parent composite * @param id button id * @param label button label * @param defaultButton is default * @return button */ protected final Button createOkButton(final Composite parent, final int id, final String label, final boolean defaultButton) { // increment the number of columns in the button bar ((GridLayout) parent.getLayout()).numColumns++; Button button = new Button(parent, SWT.PUSH); button.setText(label); button.setFont(JFaceResources.getDialogFont()); button.setData(new Integer(id)); button.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent event) { Object[] objects = _treeViewer.getExpandedElements(); _treeViewer.setInput(_datatypeDesc); for (Object o : objects) { _treeViewer.setExpandedState(o, true); } } }); setButtonLayoutData(button); return button; }