List of usage examples for org.eclipse.jface.dialogs Dialog convertWidthInCharsToPixels
public static int convertWidthInCharsToPixels(FontMetrics fontMetrics, int chars)
From source file:org.eclipse.wst.jsdt.debug.internal.ui.breakpoints.editors.JavaScriptBreakpointConditionEditor.java
License:Open Source License
/** * Creates the condition editor widgets and returns the top level * control./* w ww . ja v a 2 s. c om*/ * * @param parent composite to embed the editor controls in * @return top level control */ public Control createControl(Composite parent) { Composite controls = SWTFactory.createComposite(parent, parent.getFont(), 2, 1, GridData.FILL_HORIZONTAL, 0, 0); fConditional = SWTFactory.createCheckButton(controls, processMnemonics(Messages.conditional), null, false, 1); fConditional.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); fConditional.addSelectionListener(new SelectionAdapter() { 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(Messages.suspend_when_true)); fWhenTrue.setLayoutData(new GridData()); fWhenChange = SWTFactory.createRadioButton(radios, processMnemonics(Messages.suspend_when_changed)); fWhenChange.setLayoutData(new GridData()); fWhenTrue.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { setDirty(PROP_CONDITION_SUSPEND_POLICY); } }); fWhenChange.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { setDirty(PROP_CONDITION_SUSPEND_POLICY); } }); fViewer = new JavaScriptSourceViewer(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, 10); gd.widthHint = Dialog.convertWidthInCharsToPixels(fontMetrics, 40); gc.dispose(); fViewer.getControl().setLayoutData(gd); fHandler = new AbstractHandler() { public Object execute(ExecutionEvent event) throws org.eclipse.core.commands.ExecutionException { fViewer.doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS); return null; } }; fHandlerService = (IHandlerService) PlatformUI.getWorkbench().getAdapter(IHandlerService.class); fViewer.getControl().addFocusListener(new FocusAdapter() { public void focusGained(FocusEvent e) { activateContentAssist(); } public void focusLost(FocusEvent e) { deactivateContentAssist(); } }); parent.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { dispose(); } }); return parent; }
From source file:org.eclipse.wst.sse.ui.internal.preferences.ui.AbstractPreferenceTab.java
License:Open Source License
/** * Returns the number of pixels corresponding to the width of the given * number of characters. This method was copied from * org.eclipse.jface.dialogs.DialogPage/*w w w . ja va 2 s.c om*/ * <p> * * @param a * control in the page * @param chars * the number of characters * @return the number of pixels */ private int convertWidthInCharsToPixels(Control testControl, int chars) { // Compute and store a font metric GC gc = new GC(testControl); gc.setFont(JFaceResources.getDialogFont()); FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose(); // test for failure to initialize for backward compatibility if (fontMetrics == null) return 0; return Dialog.convertWidthInCharsToPixels(fontMetrics, chars); }
From source file:org.eclipsetrader.ui.charts.BaseChartViewer.java
License:Open Source License
public BaseChartViewer(Composite parent, int style) { composite = new Composite(parent, style | SWT.H_SCROLL); GridLayout gridLayout = new GridLayout(2, false); gridLayout.marginWidth = gridLayout.marginHeight = 0; gridLayout.horizontalSpacing = gridLayout.verticalSpacing = 3; composite.setLayout(gridLayout);//from ww w . j ava 2s.c o m GC gc = new GC(composite); FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose(); sashForm = new SashForm(composite, SWT.VERTICAL | SWT.NO_FOCUS); sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); datesAxis = new DateValuesAxis(); datesAxis.additionalSpace = 15; dateScaleCanvas = new DateScaleCanvas(composite); dateScaleCanvas.getControl().setVisible(false); ((GridData) dateScaleCanvas.getControl().getLayoutData()).exclude = true; dateScaleCanvas.getControl().addControlListener(new ControlAdapter() { @Override public void controlResized(ControlEvent e) { updateScrollbars(); revalidate(); redraw(); } }); verticalScaleLabel = new Label(composite, SWT.NONE); verticalScaleLabel .setLayoutData(new GridData(Dialog.convertWidthInCharsToPixels(fontMetrics, 12), SWT.DEFAULT)); verticalScaleLabel.setVisible(false); ((GridData) verticalScaleLabel.getLayoutData()).exclude = true; Label label = new Label(sashForm, SWT.NONE); label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); composite.getHorizontalBar().setVisible(false); composite.getHorizontalBar().addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { revalidate(); redraw(); composite.update(); } }); composite.addControlListener(new ControlAdapter() { @Override public void controlResized(ControlEvent e) { redraw(); } }); summaryDecorator = new SummaryBarDecorator(); decorator = new CrosshairDecorator(); decorator.createSummaryLabel(sashForm); }
From source file:org.eclipsetrader.ui.charts.ChartCanvas.java
License:Open Source License
public ChartCanvas(Composite parent) { composite = new Composite(parent, SWT.NONE); GridLayout gridLayout = new GridLayout(2, false); gridLayout.marginWidth = gridLayout.marginHeight = 0; gridLayout.horizontalSpacing = 3;//from w w w . j av a2s. c o m gridLayout.verticalSpacing = 0; composite.setLayout(gridLayout); composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); GC gc = new GC(composite); FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose(); summary = new SummaryBar(composite, SWT.NONE); summary.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); canvas = new Canvas(composite, SWT.DOUBLE_BUFFERED | SWT.NO_BACKGROUND); canvas.setData(this); canvas.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); canvas.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); canvas.addControlListener(new ControlAdapter() { @Override public void controlResized(ControlEvent e) { if (image != null) { image.dispose(); image = null; } redraw(); } }); canvas.addDisposeListener(new DisposeListener() { @Override public void widgetDisposed(DisposeEvent e) { removeObservers(); if (image != null) { image.dispose(); image = null; } } }); canvas.addPaintListener(new PaintListener() { @Override public void paintControl(PaintEvent e) { if (chartObject != null) { onPaint(e); } } }); verticalScaleCanvas = new Canvas(composite, SWT.DOUBLE_BUFFERED | SWT.NO_BACKGROUND); verticalScaleCanvas.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); verticalScaleCanvas.setLayoutData(new GridData(SWT.BEGINNING, SWT.FILL, false, false)); ((GridData) verticalScaleCanvas.getLayoutData()).widthHint = Dialog.convertWidthInCharsToPixels(fontMetrics, 12); verticalScaleCanvas.addControlListener(new ControlAdapter() { @Override public void controlResized(ControlEvent e) { if (verticalScaleImage != null) { verticalScaleImage.dispose(); verticalScaleImage = null; } redraw(); } }); verticalScaleCanvas.addDisposeListener(new DisposeListener() { @Override public void widgetDisposed(DisposeEvent e) { if (verticalScaleImage != null) { verticalScaleImage.dispose(); verticalScaleImage = null; } } }); verticalScaleCanvas.addPaintListener(new PaintListener() { @Override public void paintControl(PaintEvent e) { if (chartObject != null) { onPaintVerticalScale(e); } } }); label = new Label(verticalScaleCanvas, SWT.NONE); label.setBackground(verticalScaleCanvas.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); label.setBounds(-200, 0, 0, 0); }
From source file:org.eclipsetrader.ui.internal.trading.portfolio.PortfolioViewPart.java
License:Open Source License
protected void createViewer(Composite parent) { viewer = new TreeViewer(parent, SWT.FULL_SELECTION | SWT.MULTI); viewer.getTree().setHeaderVisible(true); viewer.getTree().setLinesVisible(false); viewer.setContentProvider(new PortfolioContentProvider()); viewer.setSorter(new ViewerSorter()); viewer.setInput(new PortfolioView()); GC gc = new GC(parent); FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose();/*from www. java 2s .c om*/ TreeViewerColumn viewerColumn = new TreeViewerColumn(viewer, SWT.RIGHT); viewerColumn.getColumn().setWidth(Dialog.convertWidthInCharsToPixels(fontMetrics, 40)); viewerColumn.setLabelProvider(new ElementLabelProvider()); viewerColumn = new TreeViewerColumn(viewer, SWT.RIGHT); viewerColumn.getColumn().setText(Messages.PortfolioViewPart_Position); viewerColumn.getColumn().setWidth(Dialog.convertWidthInCharsToPixels(fontMetrics, 15)); viewerColumn.setLabelProvider(new PositionLabelProvider()); viewerColumn = new TreeViewerColumn(viewer, SWT.RIGHT); viewerColumn.getColumn().setText(Messages.PortfolioViewPart_Price); viewerColumn.getColumn().setWidth(Dialog.convertWidthInCharsToPixels(fontMetrics, 15)); viewerColumn.setLabelProvider(new PriceLabelProvider()); viewerColumn = new TreeViewerColumn(viewer, SWT.RIGHT); viewerColumn.getColumn().setText(Messages.PortfolioViewPart_PL); viewerColumn.getColumn().setWidth(Dialog.convertWidthInCharsToPixels(fontMetrics, 30)); viewerColumn.setLabelProvider(new GainLabelProvider()); }
From source file:org.eclipsetrader.ui.internal.views.Level2View.java
License:Open Source License
@Override public void createPartControl(Composite parent) { Composite content = new Composite(parent, SWT.NONE); GridLayout gridLayout = new GridLayout(1, false); gridLayout.marginWidth = gridLayout.marginHeight = 0; gridLayout.verticalSpacing = 0;/*from ww w .j av a 2s. c o m*/ content.setLayout(gridLayout); GC gc = new GC(content); gc.setFont(JFaceResources.getDialogFont()); FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose(); Composite group = new Composite(content, SWT.NONE); group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); group.setLayout(new GridLayout(4, false)); Label label = new Label(group, SWT.NONE); label.setText(Messages.Level2View_Symbol); symbol = new Text(group, SWT.BORDER); symbol.setLayoutData(new GridData(Dialog.convertWidthInCharsToPixels(fontMetrics, 15), SWT.DEFAULT)); symbol.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { onSetSymbol(); } }); symbol.addSelectionListener(new SelectionAdapter() { @Override public void widgetDefaultSelected(SelectionEvent e) { onSetSymbol(); } }); final ImageHyperlink connectorButton = new ImageHyperlink(group, SWT.NONE); connectorButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); connectorButton.setImage(UIActivator.getDefault().getImageRegistry().get(UIConstants.TOOLBAR_ARROW_RIGHT)); connectorButton.setToolTipText(Messages.Level2View_SelectDataSource); connectorButton.addHyperlinkListener(new IHyperlinkListener() { private Menu dropDownMenu; @Override public void linkActivated(HyperlinkEvent e) { if (dropDownMenu != null) { dropDownMenu.dispose(); } dropDownMenu = new Menu(connectorButton); List<IFeedConnector> c = Arrays.asList(feedService.getConnectors()); Collections.sort(c, new Comparator<IFeedConnector>() { @Override public int compare(IFeedConnector o1, IFeedConnector o2) { return o1.getName().compareTo(o2.getName()); } }); for (IFeedConnector connector : c) { if (connector instanceof IFeedConnector2) { MenuItem menuItem = new MenuItem(dropDownMenu, SWT.CHECK); menuItem.setText(connector.getName()); menuItem.setData(connector); menuItem.setSelection(Level2View.this.connector == connector); menuItem.addSelectionListener(connectionSelectionListener); } } dropDownMenu.setVisible(true); } @Override public void linkEntered(HyperlinkEvent e) { } @Override public void linkExited(HyperlinkEvent e) { } }); activeConnector = new Label(group, SWT.NONE); activeConnector.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); summaryGroup = createSummary(content); if (hideSummaryAction != null) { summaryGroup.setVisible(!hideSummaryAction.isChecked()); ((GridData) summaryGroup.getLayoutData()).exclude = hideSummaryAction.isChecked(); } pressureBar = new PressureBar(content, SWT.NONE); GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, false); gridData.heightHint = 16; pressureBar.getControl().setLayoutData(gridData); createBookViewer(content); if (memento != null) { String s = memento.getString("symbol"); //$NON-NLS-1$ if (s != null) { symbol.setText(s); ISecurity security = getSecurityFromSymbol(s); if (security != null) { getSite().getSelectionProvider().setSelection(new StructuredSelection(security)); setPartName(security.getName()); setTitleToolTip(NLS.bind(VIEW_TITLE_TOOLTIP, new Object[] { security.getName() })); } } String id = memento.getString("connector"); //$NON-NLS-1$ if (id != null) { IFeedConnector connector = feedService.getConnector(id); if (connector == null) { connector = CoreActivator.getDefault().getDefaultConnector(); } if (connector instanceof IFeedConnector2) { this.connector = (IFeedConnector2) connector; activeConnector.setText(this.connector.getName()); } } if (s != null && connector != null) { subscription = this.connector.subscribeLevel2(s); subscription.addSubscriptionListener(subscriptionListener); lastClose = subscription.getLastClose(); lastTrade = subscription.getTrade(); update(subscription.getTodayOHL()); update(); } } Display.getDefault().timerExec(100, bookUpdateRunnable); }
From source file:org.elbe.relations.internal.forms.AbstractEditForm.java
License:Open Source License
protected int convertWidthInCharsToPixels(final Control inTestControl, final int inCharsNumber) { if (fontMetrics == null) { final GC lGC = new GC(inTestControl); lGC.setFont(JFaceResources.getDialogFont()); fontMetrics = lGC.getFontMetrics(); lGC.dispose();/*from w w w . j a v a2 s . co m*/ } return Dialog.convertWidthInCharsToPixels(fontMetrics, inCharsNumber); }
From source file:org.erlide.ui.util.PixelConverter.java
License:Open Source License
/** * @see org.eclipse.jface.dialogs.DialogPage#convertWidthInCharsToPixels(int) *///w ww.jav a2s. co m public int convertWidthInCharsToPixels(final int chars) { return Dialog.convertWidthInCharsToPixels(fFontMetrics, chars); }
From source file:org.gemoc.execution.concurrent.ccsljavaxdsml.ui.dashboard.form.FormHelper.java
License:Open Source License
/** * Force control size.//w ww . ja v a 2 s .co m * * @param control_p * @param widthInChars_p * The expected width, in number of chars to display. * @param heightInChars_p * The expected height, in number of chars to display. */ public static void forceControlSize(Control control_p, int widthInChars_p, int heightInChars_p) { // Preconditions. if ((null == control_p) || (0 >= widthInChars_p) || (0 >= heightInChars_p)) { return; } // Get font metrics. GC gc = new GC(control_p); FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose(); // Get layout data. Object layoutData = control_p.getLayoutData(); if (layoutData instanceof GridData) { GridData data = (GridData) layoutData; data.widthHint = Dialog.convertWidthInCharsToPixels(fontMetrics, widthInChars_p); data.heightHint = Dialog.convertHeightInCharsToPixels(fontMetrics, heightInChars_p); } else if (layoutData instanceof TableWrapData) { TableWrapData data = (TableWrapData) layoutData; data.heightHint = Dialog.convertHeightInCharsToPixels(fontMetrics, heightInChars_p); } }
From source file:org.geotools.swt.styling.simple.AbstractSimpleConfigurator.java
License:Open Source License
/** * Construct a subpart labeled with the provided tag. * <p>//w w w . ja v a 2s .c om * Creates a composite with a grid layout of the specifed columns, * and a label with text from label. * </p> * @param parent * @param label * @return Composite with one label */ public static Composite subpart(Composite parent, String label) { Composite subpart = new Composite(parent, SWT.NONE); RowLayout across = new RowLayout(); across.type = SWT.HORIZONTAL; across.wrap = true; across.pack = true; across.fill = true; across.marginBottom = 1; across.marginRight = 2; subpart.setLayout(across); Label labell = new Label(subpart, SWT.LEFT); labell.setText(label); RowData data = new RowData(); data.width = 40; // check to see if width is not enough space GC gc = new GC(parent.getParent()); gc.setFont(parent.getParent().getFont()); FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose(); int labelWidth = Dialog.convertWidthInCharsToPixels(fontMetrics, labell.getText().length() + 1); if (labelWidth > data.width) { data.width = labelWidth; } // TODO: adjust the methods that call this one to keep a consistent // width (otherwise they're misaligned) data.height = 10; labell.setLayoutData(data); return subpart; }