Example usage for org.eclipse.jface.dialogs Dialog convertHeightInCharsToPixels

List of usage examples for org.eclipse.jface.dialogs Dialog convertHeightInCharsToPixels

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs Dialog convertHeightInCharsToPixels.

Prototype

public static int convertHeightInCharsToPixels(FontMetrics fontMetrics, int chars) 

Source Link

Document

Returns the number of pixels corresponding to the height of the given number of characters.

Usage

From source file:ar.com.tadp.xml.rinzo.jdt.eclipse.copies.PixelConverter.java

License:Open Source License

public int convertHeightInCharsToPixels(int chars) {
    return Dialog.convertHeightInCharsToPixels(fFontMetrics, chars);
}

From source file:ccw.preferences.SyntaxColoringPreferencePage.java

License:Open Source License

/**
 * Returns the number of pixels corresponding to the height of the given
 * number of characters.//from  w w  w  .  j  av  a2  s .  c  om
 * <p>
 * This method may only be called after <code>initializeDialogUnits</code>
 * has been called.
 * </p>
 * <p>
 * Clients may call this framework method, but should not override it.
 * </p>
 * 
 * @param chars
 *            the number of characters
 * @return the number of pixels
 */
protected int convertHeightInCharsToPixels(int chars) {
    // test for failure to initialize for backward compatibility
    if (fFontMetrics == null)
        return 0;
    return Dialog.convertHeightInCharsToPixels(fFontMetrics, chars);
}

From source file:com.android.ide.eclipse.adt.installer.InstallSdkDialog.java

License:Open Source License

private int getHeightHint(Composite parent, int lines) {
    GC gc = new GC(parent);
    int heightHint = Dialog.convertHeightInCharsToPixels(gc.getFontMetrics(), lines);
    gc.dispose();//from   w w w  . j  a  v a  2s .com
    return heightHint;
}

From source file:com.aptana.internal.ui.text.spelling.PixelConverter.java

License:Open Source License

public int convertHeightInCharsToPixels(int chars) {
    return Dialog.convertHeightInCharsToPixels(this.fFontMetrics, chars);
}

From source file:com.axmor.eclipse.typescript.editor.TypeScriptQuickOutlineDialog.java

License:Open Source License

/**
 * @param parent parent control//from ww w. ja  v a 2  s.  c om
 */
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);
}

From source file:com.cisco.yangide.editor.preferences.YangEditorColoringConfigurationBlock.java

License:Open Source License

private int convertHeightInCharsToPixels(int chars) {
    // test for failure to initialize for backward compatibility
    if (fFontMetrics == null) {
        return 0;
    }//from  w w w.  j av a2  s  .c o  m
    return Dialog.convertHeightInCharsToPixels(fFontMetrics, chars);
}

From source file:com.ebmwebsourcing.petals.services.eip.designer.actions.ExportDiagramAction.java

License:Open Source License

@Override
public void run() {

    // Determine the export location
    FileDialog dlg = new FileDialog(new Shell(), SWT.SAVE);
    dlg.setText("Image Export");
    dlg.setOverwrite(true);/*from  w  ww. jav  a  2 s.  c  o  m*/
    dlg.setFilterNames(new String[] { "JPEG Files (*.jpg)", "PNG Files (*.png)", "GIF Files (*.gif)" });
    String[] extensions = new String[] { "*.jpg", "*.png", "*.gif" };
    dlg.setFilterExtensions(extensions);
    String path = dlg.open();

    if (path != null) {

        String ext = extensions[dlg.getFilterIndex()].substring(1);
        if (!path.endsWith(ext))
            path += ext;

        // Only print printable layers
        ScalableFreeformRootEditPart rootEditPart = (ScalableFreeformRootEditPart) this.graphicalViewer
                .getEditPartRegistry().get(LayerManager.ID);
        IFigure rootFigure = ((LayerManager) rootEditPart).getLayer(LayerConstants.PRINTABLE_LAYERS);
        IFigure eipChainFigure = null;
        for (Object o : rootFigure.getChildren()) {
            if (o instanceof FreeformLayer)
                eipChainFigure = (FreeformLayer) o;
        }

        Rectangle bounds = eipChainFigure == null ? rootFigure.getBounds() : eipChainFigure.getBounds();
        GC figureCanvasGC = new GC(this.graphicalViewer.getControl());

        // Add 20 pixels to write the title of the diagram on the image
        Image img = new Image(null, bounds.width, bounds.height);
        GC gc = new GC(img);
        gc.setBackground(figureCanvasGC.getBackground());
        gc.setForeground(figureCanvasGC.getForeground());
        gc.setFont(figureCanvasGC.getFont());
        gc.setLineStyle(figureCanvasGC.getLineStyle());
        gc.setLineWidth(figureCanvasGC.getLineWidth());
        Graphics imgGraphics = new SWTGraphics(gc);

        // Paint it...
        rootFigure.paint(imgGraphics);

        // Prepare the next step
        Font font = new Font(Display.getCurrent(), "Arial", 14, SWT.BOLD);
        gc.setFont(font);
        int height = Dialog.convertHeightInCharsToPixels(gc.getFontMetrics(), 1);
        gc.dispose();

        // Create a second image with the title and diagram version
        bounds.height += height + (height % 2 == 0 ? 6 : 7); // Write the title and its border
        bounds.height += 3 * BORDER_MARGIN_UPDOWN + 2; // Add a border + some margin
        bounds.width += 2 * BORDER_MARGIN_SIDES + 2; // Add a border

        Image finalImg = new Image(null, bounds.width, bounds.height);
        gc = new GC(finalImg);

        // Draw a surrounding border
        gc.setAntialias(SWT.ON);
        gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
        gc.drawLine(BORDER_MARGIN_SIDES, BORDER_MARGIN_UPDOWN, BORDER_MARGIN_SIDES,
                bounds.height - BORDER_MARGIN_UPDOWN);
        gc.drawLine(BORDER_MARGIN_SIDES, bounds.height - BORDER_MARGIN_UPDOWN,
                bounds.width - BORDER_MARGIN_SIDES, bounds.height - BORDER_MARGIN_UPDOWN);
        gc.drawLine(BORDER_MARGIN_SIDES, BORDER_MARGIN_UPDOWN, bounds.width - BORDER_MARGIN_SIDES,
                BORDER_MARGIN_UPDOWN);
        gc.drawLine(bounds.width - BORDER_MARGIN_SIDES, BORDER_MARGIN_UPDOWN,
                bounds.width - BORDER_MARGIN_SIDES, bounds.height - BORDER_MARGIN_UPDOWN);

        // Draw the title
        gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
        gc.setFont(font);
        gc.setClipping((Region) null);
        gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));

        String title = this.eipChain.getTitle() != null ? this.eipChain.getTitle() : "No diagram title";
        if (!StringUtils.isEmpty(this.eipChain.getVersion()))
            title += " - Version " + this.eipChain.getVersion().trim();

        int width = Dialog.convertWidthInCharsToPixels(gc.getFontMetrics(), title.length());
        if (width > bounds.width) {
            title = Dialog.shortenText(title, this.graphicalViewer.getControl());
            width = Dialog.convertWidthInCharsToPixels(gc.getFontMetrics(), title.length());
        }

        gc.drawText(title, 6 + BORDER_MARGIN_SIDES, 4 + BORDER_MARGIN_UPDOWN, true);

        // Draw a surrounding shape for the title
        gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
        Rectangle titleRectangle = new Rectangle(BORDER_MARGIN_SIDES, BORDER_MARGIN_UPDOWN,
                BORDER_MARGIN_SIDES + width + (width % 2 == 0 ? 10 : 11),
                BORDER_MARGIN_UPDOWN + height + (height % 2 == 0 ? 6 : 7));

        final int arrowPadding = (titleRectangle.height + bounds.y) / 2;
        gc.drawLine(titleRectangle.x, titleRectangle.height, titleRectangle.width, titleRectangle.height);

        gc.drawLine(titleRectangle.width, titleRectangle.y, titleRectangle.width + arrowPadding, arrowPadding);

        gc.drawLine(titleRectangle.width, titleRectangle.height, titleRectangle.width + arrowPadding,
                arrowPadding);

        // Draw the image
        gc.drawImage(img, BORDER_MARGIN_SIDES + 1, BORDER_MARGIN_UPDOWN + titleRectangle.height + 1);

        // Save the second image
        ImageData[] imgData = new ImageData[1];
        imgData[0] = finalImg.getImageData();

        int format;
        String tail = path.toLowerCase().substring(path.length() - 4);
        if (tail.endsWith(".jpg"))
            format = SWT.IMAGE_JPEG;
        else if (tail.endsWith(".png"))
            format = SWT.IMAGE_PNG;
        else
            format = SWT.IMAGE_GIF;

        ImageLoader imgLoader = new ImageLoader();
        imgLoader.data = imgData;
        imgLoader.save(path, format);

        // Dispose everything
        figureCanvasGC.dispose();
        gc.dispose();
        img.dispose();
        finalImg.dispose();
        font.dispose();
    }
}

From source file:com.google.dart.tools.ui.internal.cleanup.preference.DartEditorAppearanceConfigurationBlock.java

License:Open Source License

/**
 * Returns the number of pixels corresponding to the height of the given number of characters.
 * <p>/*from  w  ww  .  j  a  v a 2 s  . co m*/
 * This method may only be called after <code>initializeDialogUnits</code> has been called.
 * </p>
 * <p>
 * Clients may call this framework method, but should not override it.
 * </p>
 * 
 * @param chars the number of characters
 * @return the number of pixels
 */
protected int convertHeightInCharsToPixels(int chars) {
    // test for failure to initialize for backward compatibility
    if (fFontMetrics == null) {
        return 0;
    }
    return Dialog.convertHeightInCharsToPixels(fFontMetrics, chars);
}

From source file:com.googlecode.eclipse.navigatorext.utils.PixelConverter.java

License:Open Source License

/**
 * @see org.eclipse.jface.dialogs.DialogPage#convertHeightInCharsToPixels(int)
 */// w  w w . j  a v  a  2s. com
public int convertHeightInCharsToPixels(int chars) {
    return Dialog.convertHeightInCharsToPixels(fFontMetrics, chars);
}

From source file:com.iw.plugins.spindle.ui.PixelConverter.java

License:Mozilla Public License

/**
 * @see org.eclipse.jface.dialogs.DialogPage#convertHeightInCharsToPixels(int)
 *///from  w  w  w  .ja  v  a  2 s.co m
public int convertHeightInCharsToPixels(int chars) {
    return Dialog.convertHeightInCharsToPixels(fontMetrics, chars);
}