List of usage examples for org.eclipse.jface.dialogs Dialog convertWidthInCharsToPixels
public static int convertWidthInCharsToPixels(FontMetrics fontMetrics, int chars)
From source file:org.eclipse.equinox.internal.p2.ui.dialogs.StructuredIUGroup.java
License:Open Source License
protected int convertWidthInCharsToPixels(int dlus) { return Dialog.convertWidthInCharsToPixels(fm, dlus); }
From source file:org.eclipse.equinox.internal.p2.ui.viewers.IUColumnConfig.java
License:Open Source License
/** * Get the width in pixels of this column when displayed in the specified * control. If a specific width in pixels has already been specified by a client, * that width is used. Otherwise, the value is computed based on the character * width specified for the column.//from w w w. j av a2 s . c om * @param control * @return the width in pixels that should be used for the column * * @since 3.6 * * @see #setWidthInPixels(int) */ public int getWidthInPixels(Control control) { if (columnWidthInPixels >= 0) return columnWidthInPixels; GC gc = new GC(control); FontMetrics fm = gc.getFontMetrics(); columnWidthInPixels = Dialog.convertWidthInCharsToPixels(fm, columnWidth); gc.dispose(); return columnWidthInPixels; }
From source file:org.eclipse.gmf.runtime.common.ui.services.elementselection.ElementSelectionComposite.java
License:Open Source License
/** * Creates the composite.//from w ww. j a v a2 s . co m * * @param parent * the parent composite * @return the new composite */ public Composite createComposite(Composite parent) { Composite result = new Composite(parent, SWT.NONE); result.setLayout(new GridLayout()); result.setLayoutData(new GridData(GridData.FILL_BOTH)); // Add the selection title label Label label = new Label(result, SWT.NONE); label.setText(title); // Add the element selection text widget filterText = new Text(result, SWT.SINGLE | SWT.BORDER); filterText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); filterText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { handleFilterChange(); } }); // Add the table viewer int selectStyle = SWT.SINGLE; tableViewer = new TableViewer(result, selectStyle | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); tableViewer.setUseHashlookup(true); Table table = tableViewer.getTable(); GridData gridData = new GridData(GridData.FILL_BOTH); GC gc = new GC(result); gc.setFont(JFaceResources.getDefaultFont()); FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose(); gridData.widthHint = Dialog.convertWidthInCharsToPixels(fontMetrics, 80); gridData.heightHint = table.getItemHeight() * 15; table.setLayoutData(gridData); table.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { handleSelectionChange(); } public void widgetDefaultSelected(SelectionEvent e) { handleWidgetDefaultSelected(); } }); progressBar = new ProgressMonitorPart(result, new GridLayout()); progressBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); progressBar.setVisible(false); tableViewer.setLabelProvider(new LabelProvider() { public Image getImage(Object element) { assert element instanceof AbstractMatchingObject; return ((AbstractMatchingObject) element).getImage(); } public String getText(Object element) { assert element instanceof AbstractMatchingObject; return ((AbstractMatchingObject) element).getDisplayName(); } }); tableViewer.setSorter(new ViewerSorter() { public int compare(Viewer viewer, Object e1, Object e2) { if (e1 instanceof IMatchingObject && e2 instanceof IMatchingObject) return ((IMatchingObject) e1).getName().toLowerCase() .compareTo(((IMatchingObject) e2).getName().toLowerCase()); return super.compare(viewer, e1, e2); } }); createCompositeAdditions(result); return result; }
From source file:org.eclipse.jdt.debug.ui.breakpoints.JavaBreakpointConditionEditor.java
License:Open Source License
/** * Creates the condition editor widgets and returns the top level * control./*from ww w . ja v a 2s . c o m*/ * * @param parent composite to embed the editor controls in * @return top level control */ @Override public Control createControl(Composite parent) { Composite controls = SWTFactory.createComposite(parent, parent.getFont(), 2, 1, GridData.FILL_HORIZONTAL, 0, 0); fConditional = SWTFactory.createCheckButton(controls, processMnemonics(PropertyPageMessages.JavaBreakpointConditionEditor_0), null, false, 1); fConditional.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); fConditional.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { boolean checked = fConditional.getSelection(); setEnabled(checked, true); setDirty(PROP_CONDITION_ENABLED); } }); Composite radios = SWTFactory.createComposite(controls, controls.getFont(), 2, 1, GridData.FILL_HORIZONTAL, 0, 0); fWhenTrue = SWTFactory.createRadioButton(radios, processMnemonics(PropertyPageMessages.JavaBreakpointConditionEditor_1)); fWhenTrue.setLayoutData(new GridData()); fWhenChange = SWTFactory.createRadioButton(radios, processMnemonics(PropertyPageMessages.JavaBreakpointConditionEditor_2)); fWhenChange.setLayoutData(new GridData()); fWhenTrue.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { setDirty(PROP_CONDITION_SUSPEND_POLICY); } }); fWhenChange.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { setDirty(PROP_CONDITION_SUSPEND_POLICY); } }); if (fConditionHistoryDialogSettings != null) { fLocalConditionHistory = new HashMap<IJavaLineBreakpoint, Stack<String>>(); fConditionHistory = SWTFactory.createCombo(parent, SWT.DROP_DOWN | SWT.READ_ONLY, 1, null); initializeConditionHistoryDropDown(); fConditionHistory.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { int historyIndex = fConditionHistory.getSelectionIndex() - 1; if (historyIndex >= 0 && historyIndex != fSeparatorIndex) fViewer.getDocument().set(getConditionHistory()[historyIndex]); } }); GridData data = new GridData(GridData.FILL_HORIZONTAL); data.widthHint = 10; fConditionHistory.setLayoutData(data); fLocalConditionHistory = new HashMap<IJavaLineBreakpoint, Stack<String>>(10); } fViewer = new JDISourceViewer(parent, null, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.LEFT_TO_RIGHT); fViewer.setEditable(false); ControlDecoration decoration = new ControlDecoration(fViewer.getControl(), SWT.TOP | SWT.LEFT); decoration.setShowOnlyOnFocus(true); FieldDecoration dec = FieldDecorationRegistry.getDefault() .getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL); decoration.setImage(dec.getImage()); decoration.setDescriptionText(dec.getDescription()); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); // set height/width hints based on font GC gc = new GC(fViewer.getTextWidget()); gc.setFont(fViewer.getTextWidget().getFont()); FontMetrics fontMetrics = gc.getFontMetrics(); gd.heightHint = Dialog.convertHeightInCharsToPixels(fontMetrics, 17); gd.widthHint = Dialog.convertWidthInCharsToPixels(fontMetrics, 40); gc.dispose(); fViewer.getControl().setLayoutData(gd); fContentAssistHandler = new AbstractHandler() { public Object execute(ExecutionEvent event) throws org.eclipse.core.commands.ExecutionException { fViewer.doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS); return null; } }; fUndoHandler = new AbstractHandler() { public Object execute(ExecutionEvent event) throws org.eclipse.core.commands.ExecutionException { fViewer.doOperation(ITextOperationTarget.UNDO); return null; } }; fRedoHandler = new AbstractHandler() { public Object execute(ExecutionEvent event) throws org.eclipse.core.commands.ExecutionException { fViewer.doOperation(ITextOperationTarget.REDO); return null; } }; fHandlerService = (IHandlerService) PlatformUI.getWorkbench().getAdapter(IHandlerService.class); fViewer.getControl().addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { activateHandlers(); } @Override public void focusLost(FocusEvent e) { deactivateHandlers(); } }); parent.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { dispose(); } }); return parent; }
From source file:org.eclipse.jst.jsf.common.ui.internal.dialogfield.LayoutUtil.java
License:Open Source License
/** * Returns a width hint for a button control. * @param button //from w ww . ja va 2 s . c om * @return the hint value */ static int getButtonWidthHint(Button button) { if (button.getFont().equals(JFaceResources.getDefaultFont())) button.setFont(JFaceResources.getDialogFont()); GC gc = new GC(button); gc.setFont(button.getFont()); FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose(); int length = button.getText().length(); int widthHint = Dialog.convertWidthInCharsToPixels(fontMetrics, length < 2 ? 2 : length); return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); }
From source file:org.eclipse.jst.jsf.ui.internal.validation.PixelConverter.java
License:Open Source License
int convertWidthInCharsToPixels(int chars) { return Dialog.convertWidthInCharsToPixels(fFontMetrics, chars); }
From source file:org.eclipse.jubula.client.ui.rcp.dialogs.VersionComposite.java
License:Open Source License
/** * @param area The composite. creates the text field to edit the TestSuite name. * @param version the inital version for the fields *///ww w. jav a 2 s. com private void createVersionFields(Composite area, ProjectVersion version) { new Label(area, SWT.NONE).setText(Messages.CreateNewProjectVersionActionVersionNumbers); m_majorVersionField = new CheckedIntText(area, SWT.SINGLE | SWT.BORDER, true, 0, Integer.MAX_VALUE); GridData gridData = newGridData(); LayoutUtil.addToolTipAndMaxWidth(gridData, m_majorVersionField); gridData.widthHint = Dialog.convertWidthInCharsToPixels(LayoutUtil.getFontMetrics(m_majorVersionField), 10); m_majorVersionField.setLayoutData(gridData); m_majorVersionField.setText(version.getMajorNumber() != null ? String.valueOf(version.getMajorNumber()) : StringConstants.EMPTY); LayoutUtil.setMaxChar(m_majorVersionField, m_length); m_majorVersionField.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { modifyVersionFieldAction(); } }); m_majorVersionField.setData(SwtToolkitConstants.WIDGET_NAME, "VersionComposite.MajorVersionField"); //$NON-NLS-1$ m_minorVersionField = new CheckedIntText(area, SWT.SINGLE | SWT.BORDER, true, 0, Integer.MAX_VALUE); gridData = newGridData(); LayoutUtil.addToolTipAndMaxWidth(gridData, m_minorVersionField); gridData.widthHint = Dialog.convertWidthInCharsToPixels(LayoutUtil.getFontMetrics(m_minorVersionField), 10); m_minorVersionField.setLayoutData(gridData); m_minorVersionField.setText(version.getMinorNumber() != null ? String.valueOf(version.getMinorNumber()) : StringConstants.EMPTY); LayoutUtil.setMaxChar(m_minorVersionField, m_length); m_minorVersionField.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { modifyVersionFieldAction(); } }); m_minorVersionField.setData(SwtToolkitConstants.WIDGET_NAME, "VersionComposite.MinorVersionField"); //$NON-NLS-1$ m_microVersionField = new CheckedIntText(area, SWT.SINGLE | SWT.BORDER, true, 0, Integer.MAX_VALUE); gridData = newGridData(); LayoutUtil.addToolTipAndMaxWidth(gridData, m_microVersionField); gridData.widthHint = Dialog.convertWidthInCharsToPixels(LayoutUtil.getFontMetrics(m_microVersionField), 10); m_microVersionField.setLayoutData(gridData); m_microVersionField.setText(version.getMicroNumber() != null ? String.valueOf(version.getMicroNumber()) : StringConstants.EMPTY); LayoutUtil.setMaxChar(m_microVersionField, m_length); m_microVersionField.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { modifyVersionFieldAction(); } }); m_microVersionField.setData(SwtToolkitConstants.WIDGET_NAME, "VersionComposite.MicroVersionField"); //$NON-NLS-1$ new Label(area, SWT.NONE).setText(Messages.CreateNewProjectVersionActionQualifierLabel); m_versionQualifierField = new Text(area, SWT.SINGLE | SWT.BORDER); gridData = newGridData(); LayoutUtil.addToolTipAndMaxWidth(gridData, m_versionQualifierField); gridData.widthHint = 0; gridData.horizontalSpan = 3; gridData.horizontalAlignment = GridData.FILL; m_versionQualifierField.setLayoutData(gridData); m_versionQualifierField .setText(StringUtils.defaultIfBlank(version.getVersionQualifier(), StringConstants.EMPTY)); LayoutUtil.setMaxChar(m_versionQualifierField, m_length); m_versionQualifierField.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { modifyVersionFieldAction(); } }); m_versionQualifierField.setData(SwtToolkitConstants.WIDGET_NAME, "VersionComposite.VersionQualifierField"); //$NON-NLS-1$ }
From source file:org.eclipse.jubula.client.ui.rcp.preferences.TestResultPreferencePage.java
License:Open Source License
/** * @param parent The composite.// w ww .j ava 2 s .c o m * @return a new m_text field */ private Text newTextField(Composite parent) { final Text textField = new Text(parent, SWT.BORDER); GridData textGrid = new GridData(GridData.FILL, GridData.CENTER, true, false, 3, 1); textGrid.widthHint = Dialog.convertWidthInCharsToPixels(LayoutUtil.getFontMetrics(textField), LayoutUtil.WIDTH); textField.setLayoutData(textGrid); return textField; }
From source file:org.eclipse.jubula.client.ui.utils.LayoutUtil.java
License:Open Source License
/** * Defines a constant width for a control and shows a tool tip with the text * of this control, when this text is longer than the constant width. * @param gridData The gridData object./* ww w . ja v a2 s. co m*/ * @param control The actual SWT control. */ public static void addToolTipAndMaxWidth(GridData gridData, final Control control) { gridData.widthHint = Dialog.convertWidthInCharsToPixels(LayoutUtil.getFontMetrics(control), LayoutUtil.WIDTH); if (control instanceof Text) { final Text textField = (Text) control; setVisibilityToolTip(textField, textField.getText()); textField.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent event) { setVisibilityToolTip(textField, textField.getText()); } }); } else if (control instanceof Combo) { final Combo combo = (Combo) control; setVisibilityToolTip(combo, combo.getText()); combo.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent event) { setVisibilityToolTip(combo, combo.getText()); } }); } }
From source file:org.eclipse.jubula.client.ui.utils.LayoutUtil.java
License:Open Source License
/** * Sets the tooltip for a control if its text does not fit within its * bounds. Otherwise clears the tooltip for the control. * /*w w w . java 2 s . com*/ * @param control The control for which to set/clear the tooltip. * @param text The text in the control. */ private static void setVisibilityToolTip(Control control, String text) { int width = Dialog.convertWidthInCharsToPixels(LayoutUtil.getFontMetrics(control), text.length()); if (width > control.getBounds().width) { control.setToolTipText(text); } else { control.setToolTipText(null); } }