/** * Setup some sensible paging information. */ public static void setupPagingInformation(ScrolledComposite composite) { GC gc = new GC(composite); FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose(); int fontHeight = fontMetrics.getHeight(); int fontWidth = fontMetrics.getAverageCharWidth(); Rectangle clientArea = composite.getClientArea(); int lines = clientArea.height / fontHeight; int pageHeight = lines * fontHeight; int pageWidth = clientArea.width - fontWidth; composite.getVerticalBar().setIncrement(fontHeight); composite.getVerticalBar().setPageIncrement(pageHeight); composite.getHorizontalBar().setIncrement(fontWidth); composite.getHorizontalBar().setPageIncrement(pageWidth); }
/** * Get the size hints for the receiver. These are used for * layout data. * @return Point - the preferred x and y coordinates */ public Point getSizeHints() { Display display = canvas.getDisplay(); GC gc = new GC(canvas); FontMetrics fm = gc.getFontMetrics(); int charWidth = fm.getAverageCharWidth(); int charHeight = fm.getHeight(); int maxWidth = display.getBounds().width / 2; int maxHeight = display.getBounds().height / 6; int fontWidth = charWidth * maxCharacterWidth; int fontHeight = charHeight * numShowItems; if (maxWidth < fontWidth) { fontWidth = maxWidth; } if (maxHeight < fontHeight) { fontHeight = maxHeight; } gc.dispose(); return new Point(fontWidth, fontHeight); }
/** * Calculates the bounds of the text in the box as measured by the given * graphics context and font metrics. * * @param gc graphics context from which the measurements are done * @return point representing the dimensions of the text's bounds */ private Point calculateTextBounds(final GC gc) { final SWTGraphics2D g2 = new SWTGraphics2D(gc, Display.getDefault()); g2.setFont(font); final FontMetrics fm = g2.getSWTFontMetrics(); final Point textBounds = new Point(0, 0); boolean firstLine = true; final Iterator lineIterator = lines.iterator(); while (lineIterator.hasNext()) { String line = (String) lineIterator.next(); Point lineBounds = gc.stringExtent(line); if (firstLine) { textBounds.x = lineBounds.x; textBounds.y += fm.getAscent() + fm.getDescent() + fm.getLeading(); firstLine = false; } else { textBounds.x = Math.max(lineBounds.x, textBounds.x); textBounds.y += fm.getHeight(); } } return textBounds; }
private void computeMetrics() { Control control = getControl(); if (control == null && Display.getCurrent() != null) { control = Display.getCurrent().getActiveShell(); } if (control == null) { return; } /* Compute metrics in pixels */ final GC gc = new GC(control); final FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose(); horizontalSpacing = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_SPACING); verticalSpacing = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_SPACING); spacing = Math.max(horizontalSpacing, verticalSpacing); horizontalMargin = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_MARGIN); verticalMargin = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_MARGIN); }
public BaseControl(final Composite parent, final int style) { super(parent, style); /* Compute metrics in pixels */ final GC gc = new GC(this); final FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose(); horizontalSpacing = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_SPACING); verticalSpacing = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_SPACING); spacing = Math.max(horizontalSpacing, verticalSpacing); horizontalMargin = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_MARGIN); verticalMargin = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_MARGIN); minimumMessageAreaWidth = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH); }
/** * Obtains a {@link FontMetrics} object corresponding to the specified * {@link Control}. This method creates and disposes a {@link GC} object to * get {@link FontMetrics}. * * @param control * a {@link Control} to get {@link FontMetrics} for (must not be * <code>null</code>) * @return a {@link FontMetrics} object (never <code>null</code>) */ public static FontMetrics getFontMetrics(final Control control) { Check.notNull(control, "control"); //$NON-NLS-1$ /* * TODO A possible performance enhancement would be to cache the * FontMetrics on a Control (control.setData). This would allow multiple * calls to this method for the same control to avoid the overhead of * creating and disposing a GC each time. We should do this only if * profiling indicates a performance problem. If we do this, we should * provide an overload of this method that takes a boolean that controls * whether the cache is used or not - useful when the client changes the * font on a control in between calls, etc. */ final GC gc = new GC(control); try { gc.setFont(control.getFont()); return gc.getFontMetrics(); } finally { gc.dispose(); } }
private final void computeMetrics() { Control control = getControl(); if (control == null && Display.getCurrent() != null) { control = Display.getCurrent().getActiveShell(); } if (control == null) { return; } /* Compute metrics in pixels */ final GC gc = new GC(control); final FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose(); horizontalSpacing = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_SPACING); verticalSpacing = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_SPACING); spacing = Math.max(horizontalSpacing, verticalSpacing); horizontalMargin = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_MARGIN); verticalMargin = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_MARGIN); initializedMetrics = true; }
protected void createFilesPreviewControl(Composite parent) { Font font = parent.getFont(); // file preview group Composite filePreview = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); layout.numColumns = 1; layout.marginWidth = 0; filePreview.setLayout(layout); filePreview.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); filePreview.setFont(font); // Generated files Label label = new Label(filePreview, SWT.NONE); label.setText(AngularCLIMessages.NgGenerateBlueprintWizardPage_generated_files); label.setFont(font); generatedFiles = new Text(filePreview, SWT.READ_ONLY | SWT.MULTI | SWT.H_SCROLL); GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL); GC gc = new GC(generatedFiles); gc.setFont(font); FontMetrics fm = gc.getFontMetrics(); data.heightHint = 7 * fm.getHeight(); generatedFiles.setLayoutData(data); gc.dispose(); }
/** * Does not paint hidden annotations. Annotations are hidden when they * only span one line. * * @see ProjectionAnnotation#paint(org.eclipse.swt.graphics.GC, * org.eclipse.swt.widgets.Canvas, * org.eclipse.swt.graphics.Rectangle) */ @Override public void paint(GC gc, Canvas canvas, Rectangle rectangle) { /* workaround for BUG85874 */ /* * only need to check annotations that are expanded because hidden * annotations should never have been given the chance to collapse. */ if (!isCollapsed()) { // working with rectangle, so line height FontMetrics metrics = gc.getFontMetrics(); if (metrics != null) { // do not draw annotations that only span one line and // mark them as not visible if ((rectangle.height / metrics.getHeight()) <= 1) { visible = false; return; } } } visible = true; super.paint(gc, canvas, rectangle); }
/** * @param parent * parent control */ private void createFilterText(Composite parent) { // Create the widget filterText = new Text(parent, SWT.NONE); // Set the font GC gc = new GC(parent); gc.setFont(parent.getFont()); FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose(); // Create the layout GridData data = new GridData(GridData.FILL_HORIZONTAL); data.heightHint = Dialog.convertHeightInCharsToPixels(fontMetrics, 1); data.horizontalAlignment = GridData.FILL; data.verticalAlignment = GridData.CENTER; filterText.setLayoutData(data); }
private GridData getButtonGridData(Button button) { GridData gd = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); GC gc = new GC(button); gc.setFont(button.getFont()); FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose(); int widthHint = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_WIDTH); gd.widthHint = Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); gd.heightHint = Dialog .convertVerticalDLUsToPixels(fontMetrics, 14 /*IDialogConstants.BUTTON_HEIGHT*/); return gd; }
/** * Returns the difference between the baseline of the widget and the * baseline as specified by the font for <code>gc</code>. When drawing * line numbers, the returned bias should be added to obtain text lined up * on the correct base line of the text widget. * * @param gc the <code>GC</code> to get the font metrics from * @param widgetLine the widget line * @return the baseline bias to use when drawing text that is lined up with * <code>fCachedTextWidget</code> * @since 3.2 */ private int getBaselineBias(GC gc, int widgetLine) { /* * https://bugs.eclipse.org/bugs/show_bug.cgi?id=62951 * widget line height may be more than the font height used for the * line numbers, since font styles (bold, italics...) can have larger * font metrics than the simple font used for the numbers. */ int offset= fCachedTextWidget.getOffsetAtLine(widgetLine); int widgetBaseline= fCachedTextWidget.getBaseline(offset); FontMetrics fm= gc.getFontMetrics(); int fontBaseline= fm.getAscent() + fm.getLeading(); int baselineBias= widgetBaseline - fontBaseline; return Math.max(0, baselineBias); }
/** Populates the height and width of the system font. */ private static void populateSystemFont() { // create a tiny image to bind our GC to (not that it can't be size 0) Image dummyImg = new Image(assertUI(), 1, 1); GC gc = new GC(dummyImg); FontMetrics metrics = gc.getFontMetrics(); systemFontHeight = metrics.getHeight(); systemFontWidth = metrics.getAverageCharWidth(); if (OS.getNative().isMac()) { // add 20% width on Mac systemFontWidth = (systemFontWidth * 12) / 10; } gc.dispose(); dummyImg.dispose(); }
/** * Returns a new Image with the given String rotated left (by 90 degrees). * The String will be rendered using the provided colors and fonts. The * client is responsible for disposing the returned Image. Strings cannot * contain newline or tab characters. * * @param string * the String to be rendered * @param font * the font * @param foreground * the text's color * @param background * the background color * @return an Image which must be disposed */ public static Image createRotatedImageOfString(String string, Font font, Color foreground, Color background) { Display display = Display.getDefault(); FontMetrics metrics = FigureUtilities.getFontMetrics(font); Dimension strSize = FigureUtilities.getStringExtents(string, font); Image srcImage = new Image(display, strSize.width, metrics.getAscent()); GC gc = new GC(srcImage); gc.setFont(font); gc.setForeground(foreground); gc.setBackground(background); gc.fillRectangle(srcImage.getBounds()); gc.drawString(string, 0, 0 - metrics.getLeading()); Image result = createRotatedImage(srcImage); gc.dispose(); srcImage.dispose(); return result; }
/** * Set the GridData on button to be one that is spaced for the * current font. * @param button the button the data is being set on. */ protected void setButtonLayoutData(Button button) { GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); // Compute and store a font metric GC gc = new GC(button); gc.setFont(button.getFont()); FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose(); int widthHint = org.eclipse.jface.dialogs.Dialog .convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_WIDTH); data.widthHint = Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); button.setLayoutData(data); }
private static void initializeConstants() { if (dialogMargins != null) { return; } GC gc = new GC(Display.getCurrent()); gc.setFont(JFaceResources.getDialogFont()); FontMetrics fontMetrics = gc.getFontMetrics(); dialogMargins = new Point(Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_MARGIN), Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_MARGIN)); dialogSpacing = new Point(Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_SPACING), Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_SPACING)); minButtonSize = new Point(Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_WIDTH), 0); gc.dispose(); }
@Override public void initializePanel(Composite parent) { final FillLayout rl = new FillLayout(); parent.setLayout(rl); final Text t = new Text(parent, SWT.SINGLE | SWT.ICON_CANCEL | SWT.CANCEL); t.setText(startString); final int chars = 30; final GC gc = new GC(t); final FontMetrics fm = gc.getFontMetrics(); final int width = chars * fm.getAverageCharWidth(); final int height = fm.getHeight(); gc.dispose(); t.setSize(t.computeSize(width, height)); t.addListener(SWT.DefaultSelection, this); t.addListener(SWT.Modify, this); }
private void showNullChart( Dimension dSize ) { // Display error message for null chart. This behavior is consistent // with invalid table. String MSG = Messages.getString( "DesignerRepresentation.msg.InvalidChart" ); //$NON-NLS-1$ logger.log( ILogger.ERROR, Messages.getString( "DesignerRepresentation.log.UnableToFind" ) ); //$NON-NLS-1$ Device dv = Display.getCurrent( ); Font font = FontManager.getFont( "Dialog", 10, SWT.ITALIC ); //$NON-NLS-1$ gc.setFont( font ); FontMetrics fm = gc.getFontMetrics( ); gc.setForeground( dv.getSystemColor( SWT.COLOR_RED ) ); gc.setBackground( dv.getSystemColor( SWT.COLOR_WHITE ) ); gc.fillRectangle( 0, 0, dSize.width - 1, dSize.height - 1 ); gc.drawRectangle( 0, 0, dSize.width - 1, dSize.height - 1 ); String[] texts = splitOnBreaks( MSG, font, dSize.width - 10 ); int y = 5; for ( String text : texts ) { gc.drawText( text, 5, y ); y += fm.getHeight( ); } }
public Control[] doFillIntoGrid( Composite parent, int nColumns ) { assertEnoughColumns( nColumns ); Button button = getSelectionButton( parent ); GridData gd = new GridData( ); gd.horizontalSpan = nColumns; gd.horizontalAlignment = GridData.FILL; if ( fButtonStyle == SWT.PUSH ) { GC gc = new GC( button.getFont( ).getDevice( ) ); gc.setFont( button.getFont( ) ); FontMetrics fFontMetrics = gc.getFontMetrics( ); gc.dispose( ); int widthHint = Dialog.convertHorizontalDLUsToPixels( fFontMetrics, IDialogConstants.BUTTON_WIDTH ); gd.widthHint = Math.max( widthHint, button.computeSize( SWT.DEFAULT, SWT.DEFAULT, true ).x ); } button.setLayoutData( gd ); return new Control[]{ button }; }
/** * Paint. */ protected void onPaint(GC gc) { final Rectangle b = getBounds(); final TestStatus status = counter != null ? counter.getAggregatedStatus() : null; if (status != null) { final int total = Math.max(expectedTotal, counter.getTotal()); // this is our 100% value final int value = counter.getTotal(); // current value final int totalPx = b.width; final int valuePx = Math.round(totalPx * (((float) value) / ((float) total))); gc.setBackground(getColorForStatus(status)); gc.fillRectangle(0, 0, valuePx, b.height); gc.setBackground(getBackground()); gc.fillRectangle(0 + valuePx, 0, b.width - valuePx, b.height); } else { // clear gc.setBackground(getBackground()); gc.fillRectangle(b); } if (counter != null) { final FontMetrics fm = gc.getFontMetrics(); gc.setForeground(getForeground()); final int pending = expectedTotal > 0 ? expectedTotal - counter.getTotal() : -1; gc.drawString(counter.toString(true, pending, SWT.RIGHT), 4, b.height / 2 - fm.getHeight() / 2 - fm.getDescent(), true); } }
private int averageCharacterWidth(Font font) { int width; GC gc = new GC(Display.getDefault()); gc.setFont(font); FontMetrics fontMetrics = gc.getFontMetrics(); width = fontMetrics.getAverageCharWidth(); gc.dispose(); return width; }
private void setHeight(FormData fd, Control control, int rowcount) { GC gc = new GC(control); try { gc.setFont(control.getFont()); FontMetrics fm = gc.getFontMetrics(); fd.height = rowcount * fm.getHeight(); } finally { gc.dispose(); } }
public void update(String currentPageId) { if (composite == null || composite.isDisposed()) return; GC metricsGC = new GC(composite); FontMetrics metrics = metricsGC.getFontMetrics(); metricsGC.dispose(); List buttons = (List) buttonMap.get(currentPageId); Control[] children = composite.getChildren(); int visibleChildren = 0; Button closeButton = getButton(IDialogConstants.CLOSE_ID); for (int i = 0; i < children.length; i++) { Control control = children[i]; if (closeButton == control) closeButton.dispose(); else { control.setVisible(false); setButtonLayoutData(metrics, control, false); } } if (buttons != null) { for (int i = 0; i < buttons.size(); i++) { Button button = (Button) buttons.get(i); button.setVisible(true); setButtonLayoutData(metrics, button, true); GridData data = (GridData) button.getLayoutData(); data.exclude = false; visibleChildren++; } } GridLayout compositeLayout = (GridLayout) composite.getLayout(); compositeLayout.numColumns = visibleChildren; composite.layout(true); }
protected void setButtonLayoutData(FontMetrics metrics, Control button, boolean visible) { GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); int widthHint = Dialog.convertHorizontalDLUsToPixels(metrics, IDialogConstants.BUTTON_WIDTH); Point minSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); data.widthHint = Math.max(widthHint, minSize.x); data.exclude = !visible; button.setLayoutData(data); }
private int getReaderSize(final KeyText r) { final GC gc = new GC(r); try { gc.setFont(r.getFont()); final FontMetrics fm = gc.getFontMetrics(); return READER_ROWS * fm.getHeight(); } finally { gc.dispose(); } }
/** * Paints this object normally (show it's text). Note that the entire text * gets rendered so that it's upper left corner appears at the origin of * this local object. * * @param ppc The graphics context to paint into. */ public void paintAsText(final PPaintContext ppc) { final SWTGraphics2D sg2 = (SWTGraphics2D) ppc.getGraphics(); if (!transparent) { if (getPaint() == null) { sg2.setBackground(Color.WHITE); } else { sg2.setBackground((Color) getPaint()); } sg2.fillRect(0, 0, (int) getWidth(), (int) getHeight()); } sg2.translate(padding, padding); sg2.setColor(penColor); sg2.setFont(font); String line; double y = 0; final FontMetrics fontMetrics = sg2.getSWTFontMetrics(); final Iterator lineIterator = lines.iterator(); while (lineIterator.hasNext()) { line = (String) lineIterator.next(); if (line.length() != 0) { sg2.drawString(line, 0, y, true); } y += fontMetrics.getHeight(); } sg2.translate(-padding, -padding); }
@Override public final void createPartControl(final Composite parent) { /* Compute metrics in pixels */ final GC gc = new GC(parent); final FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose(); final GridLayout layout = new GridLayout(2, false); layout.horizontalSpacing = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_SPACING) * 2; layout.verticalSpacing = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_SPACING); layout.marginWidth = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_MARGIN); layout.marginHeight = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_MARGIN); parent.setLayout(layout); final Label imageLabel = new Label(parent, SWT.NONE); imageLabel.setImage(Display.getCurrent().getSystemImage(SWT.ICON_INFORMATION)); final Link textLabel = new Link(parent, SWT.READ_ONLY | SWT.WRAP); textLabel.setText(Messages.getString("DeprecatedByTeamExplorerView.DeprecatedText")); //$NON-NLS-1$ textLabel.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { try { final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); page.showView(TeamExplorerView.ID); } catch (final Exception f) { log.warn("Could not open Team Explorer View", f); //$NON-NLS-1$ MessageDialog.openError( getSite().getShell(), Messages.getString("DeprecatedByTeamExplorerView.OpenViewFailedTitle"), //$NON-NLS-1$ Messages.getString("DeprecatedByTeamExplorerView.OpenViewFailedMessage")); //$NON-NLS-1$ } } }); GridDataBuilder.newInstance().hGrab().hFill().applyTo(textLabel); }
public static int TextHeight(final Text control, final int width) { final GC gc = new GC(control); final FontMetrics fm = gc.getFontMetrics(); gc.dispose(); if (control.getText() == null) { return SWT.DEFAULT; } return (fm.getHeight() * (int) Math.ceil((((fm.getAverageCharWidth() * 1.0) * control.getText().length()) / width) + 0.25)) + 2; }
public static final void setButtonToButtonBarSize(final Button button) { final GC gc = new GC(button); final FontMetrics fm = gc.getFontMetrics(); gc.dispose(); final int widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH); final Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); size.x = Math.max(widthHint, size.x); ControlSize.setSizeHints(button, size); }
@Override public Point computeSize(final Composite composite, final int wHint, final int hHint, final boolean flush) { if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT) { return new Point(wHint, hHint); } final Table table = (Table) composite; /* Remove ourselves to avoid recursions */ table.setLayout(null); final Point tableSize = table.computeSize(wHint, hHint, flush); table.setLayout(this); /* Get the font metrics for the table to handle charWidth */ final FontMetrics fontMetrics = ControlSize.getFontMetrics(composite); int minWidth = 0; for (int i = 0; i < columnData.length; i++) { int persistWidth = -1; if (persistenceStore != null && columnData[i].persistenceKey != null) { persistWidth = persistenceStore.getColumnWidth(columnData[i].persistenceKey); } if (persistWidth >= 0) { minWidth += persistWidth; } else if (columnData[i].width >= 0) { minWidth += columnData[i].width; } else if (columnData[i].charWidth >= 0) { minWidth += columnData[i].charWidth * fontMetrics.getAverageCharWidth(); } } if (minWidth > tableSize.x) { tableSize.x = minWidth; } return tableSize; }
private ImageData createColorImage(Control w, String fileLocation) { GC gc = new GC(w); FontMetrics fm = gc.getFontMetrics(); int size = fm.getAscent(); gc.dispose(); int indent = 6; int extent = DEFAULT_EXTENT; if (w instanceof Table) { extent = ((Table) w).getItemHeight() - 1; } else if (w instanceof Tree) { extent = ((Tree) w).getItemHeight() - 1; } if (size > extent) { size = extent; } int width = indent + size; int height = extent; ImageData data = null; // If its a url then we will not show anything. boolean isUrl = Converter.isStringUrl(fileLocation); if (!isUrl) { try { Image rImage = new Image(Display.getCurrent(), fileLocation); data = rImage.getImageData().scaledTo(width, height); } catch (Exception e) { ForgedUICorePlugin.logError(e); } return data; } else { return null; } }
private GridData getButtonGridData(Button button) { GridData gd = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); GC gc = new GC(button); gc.setFont(button.getFont()); FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose(); int widthHint = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_WIDTH); gd.widthHint = Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); gd.heightHint = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_HEIGHT); return gd; }
public static int getCharWidth(Drawable control) { GC gc = new GC(control); FontMetrics fm = gc.getFontMetrics(); int w = fm.getAverageCharWidth(); gc.dispose(); return w; }
public static int getCharHeight(Drawable control) { GC gc = new GC(control); FontMetrics fm = gc.getFontMetrics(); int h = fm.getHeight(); gc.dispose(); return h; }
public void drawString(String s, int x, int y) { // System.err.println("drawString(" + s + "," + x + "," + y + ")"); java.awt.FontMetrics fm = _g2d.getFontMetrics(); int dy = fm.getAscent(); // Shape clip = g2d.getClip(); // g2d.setClip(null); _g2d.drawString(s, x, y + dy); // g2d.setClip(clip); }