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

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

Introduction

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

Prototype

public static int convertWidthInCharsToPixels(FontMetrics fontMetrics, int chars) 

Source Link

Document

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

Usage

From source file:de.byteholder.geoclipse.util.PixelConverter.java

License:Open Source License

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

From source file:de.innot.avreclipse.ui.propertypages.AbstractTabAVRDudeBytes.java

License:Open Source License

/**
 * The "Upload from direct values" Section.
 * <p>//from  w  w w.  jav  a2s.  c om
 * Contains controls to edit all bytes directly and two buttons to read the byte values from the
 * programmer and to copy the values from the file.
 * </p>
 * 
 * @param parent
 *            Parent <code>Composite</code>
 */
private void addImmediateSection(Composite parent) {

    // add the radio button
    fImmediateButton = new Button(parent, SWT.RADIO);
    fImmediateButton.setText(MessageFormat.format(TEXT_IMMEDIATE, getType().getMaxBytes() > 1 ? "s" : ""));
    GridData buttonGD = new GridData(SWT.BEGINNING, SWT.TOP, false, false);
    // This is somewhat arbitrarily and looks good on my setup.
    // Your mileage may vary.
    buttonGD.verticalIndent = 8;
    fImmediateButton.setLayoutData(buttonGD);
    fImmediateButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (fImmediateButton.getSelection() == false) {
                // Button was deselected (another button has been selected
                // The other button will handle everything
                return;
            }
            fBytes.setWrite(true);
            fBytes.setUseFile(false);
            enableFileGroup(false);
            enableByteGroup(true);
            updateFields();

            // Check if the byte values are compatible and display a warning if required
            checkValid();
        }
    });

    // add the byte editor composites (wrapped in a composite)
    fBytesCompo = new Composite(parent, SWT.NONE);
    GridData bytesGD = new GridData(SWT.BEGINNING, SWT.TOP, false, false, 1, 1);

    // Make the size of the byte edit fields somewhat dependent on the font
    // size. I use 6 chars instead of the actual required 2, because 2 was
    // just to small.
    FontMetrics fm = getFontMetrics(parent);
    bytesGD.widthHint = Dialog.convertWidthInCharsToPixels(fm, 6) * getType().getMaxBytes();
    fBytesCompo.setLayoutData(bytesGD);
    fBytesCompo.setLayout(new FillLayout(SWT.HORIZONTAL));

    // Insert the byte editor compos
    for (int i = 0; i < getType().getMaxBytes(); i++) {
        makeByteEditComposite(fBytesCompo, i);
    }

    // Add the actions menu

    fActionsToolBar = createActionsToolbar(parent);
    GridData toolbarGD = new GridData(SWT.BEGINNING, SWT.TOP, false, false);
    fActionsToolBar.setLayoutData(toolbarGD);

    // and the loading label
    fLoadingLabel = new Label(parent, SWT.NONE);
    fLoadingLabel.setText(TEXT_LOADING);
    GridData loadingGD = new GridData(SWT.BEGINNING, SWT.TOP, true, false);
    fLoadingLabel.setLayoutData(loadingGD);
    fLoadingLabel.setVisible(false);

    // Adjust the Layout: try to get all components to line up on their baseline.
    // This is more or less a hack and probably only looks good on my system.
    // But I don't know SWT well enough to do this the right way.
    // Feel free to do something else!
    Point sizeButton = fImmediateButton.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    Point sizeToolBar = fActionsToolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    Point sizeEditors = fByteCompos[0].getChildren()[0].computeSize(SWT.DEFAULT, SWT.DEFAULT);
    Point sizeLabel = fLoadingLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT);

    // Toolbar is the master. Align the tops of the other three components in this row according
    // to the height of the toolbar.
    int tbheight = sizeToolBar.y;

    buttonGD.verticalIndent = tbheight - sizeButton.y - 3;
    bytesGD.verticalIndent = tbheight - sizeEditors.y - 2;
    loadingGD.verticalIndent = tbheight - sizeLabel.y - 5;
}

From source file:de.innot.avreclipse.ui.propertypages.TabAVRDudeProgrammer.java

License:Open Source License

/**
 * The JTAG bitclock section.//  w  ww .j av a  2 s .c o  m
 * <p>
 * The primary control in this section is a text field, that accepts only
 * floating point numbers.
 * </p>
 * 
 * @param parent
 *            <code>Composite</code>
 */
private void addBitClockSection(Composite parent) {

    // TODO this could be replaced by a combo to select standard values.
    // Also this could be implemented as a frequency selector like in AVR
    // Studio
    // However, investigations into the avrdude source code indicate, that
    // the different programmer backends interpret this number differently.
    // Especially the stk500v2 backend interprets this number relative to the
    // clock frequency of the stk500 programmer.

    Group group = new Group(parent, SWT.NONE);
    group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    group.setLayout(new GridLayout(3, false));
    group.setText(GROUP_BITCLOCK);

    Label label = new Label(group, SWT.WRAP);
    label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 3, 1));
    label.setText(LABEL_BITCLOCK);

    setupLabel(group, TEXT_BITCLOCK, 1, SWT.NONE);

    fBitClockText = new Text(group, SWT.BORDER | SWT.RIGHT);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, false, false);
    FontMetrics fm = getFontMetrics(parent);
    gd.widthHint = Dialog.convertWidthInCharsToPixels(fm, 12);
    fBitClockText.setLayoutData(gd);
    fBitClockText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            fTargetProps.setBitclock(fBitClockText.getText());
            updateAVRDudePreview(fTargetProps);
        }
    });
    fBitClockText.addVerifyListener(new VerifyListener() {
        public void verifyText(VerifyEvent event) {
            // Accept only digits and -at most- one dot '.'
            int dotcount = 0;
            if (fBitClockText.getText().contains(".")) {
                dotcount++;
            }
            String text = event.text;
            for (int i = 0; i < text.length(); i++) {
                char ch = text.charAt(i);
                if (ch == '.') {
                    dotcount++;
                    if (dotcount > 1) {
                        event.doit = false;
                        return;
                    }
                } else if (!('0' <= ch && ch <= '9')) {
                    event.doit = false;
                    return;
                }
            }
        }
    });

    // Label with the units (microseconds)
    setupLabel(group, LABEL_BITCLOCK_UNIT, 1, SWT.FILL);
}

From source file:de.innot.avreclipse.ui.propertypages.TabAVRDudeProgrammer.java

License:Open Source License

/**
 * The BitBang bit change delay section.
 * <p>/*from   w  w w .ja v a  2  s . c om*/
 * The primary control in this section is a text field, that accepts only
 * integers.
 * </p>
 * 
 * @param parent
 *            <code>Composite</code>
 */
private void addBitBangDelaySection(Composite parent) {

    Group group = new Group(parent, SWT.NONE);
    group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    group.setLayout(new GridLayout(3, false));
    group.setText(GROUP_DELAY);

    Label label = new Label(group, SWT.WRAP);
    label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 3, 1));
    label.setText(LABEL_DELAY);

    setupLabel(group, TEXT_DELAY, 1, SWT.NONE);

    fBitBangDelayText = new Text(group, SWT.BORDER | SWT.RIGHT);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, false, false);
    FontMetrics fm = getFontMetrics(parent);
    gd.widthHint = Dialog.convertWidthInCharsToPixels(fm, 12);
    fBitBangDelayText.setLayoutData(gd);
    fBitBangDelayText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            fTargetProps.setBitBangDelay(fBitBangDelayText.getText());
            updateAVRDudePreview(fTargetProps);
        }
    });
    fBitBangDelayText.addVerifyListener(new VerifyListener() {
        public void verifyText(VerifyEvent event) {
            // Accept only digits
            String text = event.text;
            for (int i = 0; i < text.length(); i++) {
                char ch = text.charAt(i);
                if (!('0' <= ch && ch <= '9')) {
                    event.doit = false;
                    return;
                }
            }
        }
    });

    // Label with the units (microseconds)
    setupLabel(group, LABEL_DELAY_UNIT, 1, SWT.FILL);
}

From source file:de.innot.avreclipse.ui.propertypages.TabTargetHardware.java

License:Open Source License

private void addMCUSection(Composite parent) {

    GridData gd = new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1);
    FontMetrics fm = getFontMetrics(parent);
    gd.widthHint = Dialog.convertWidthInCharsToPixels(fm, 20);

    // MCU Selection Combo
    setupLabel(parent, LABEL_MCUTYPE, 1, SWT.NONE);
    // Label label = new Label(parent, SWT.NONE);
    // label.setText(LABEL_MCUTYPE);
    // label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));

    fMCUcombo = new Combo(parent, SWT.READ_ONLY | SWT.DROP_DOWN);
    fMCUcombo.setLayoutData(gd);//  w w  w .ja  v  a2  s.c  o  m
    fMCUcombo.setItems(fMCUNames);
    fMCUcombo.setVisibleItemCount(Math.min(fMCUNames.length, 20));

    fMCUcombo.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            String mcuname = fMCUcombo.getItem(fMCUcombo.getSelectionIndex());
            String mcuid = AVRMCUidConverter.name2id(mcuname);
            fTargetProps.setMCUId(mcuid);

            // Check if supported by avrdude and set the errorpane as
            // required
            checkAVRDude(mcuid);

            // Check fuse byte settings and pop a message if the settings
            // are not compatible
            checkFuseBytes(mcuid);
        }
    });

    // Load from Device Button
    fLoadButton = setupButton(parent, TEXT_LOADBUTTON, 1, SWT.NONE);
    fLoadButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    fLoadButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            loadComboFromDevice();
        }
    });

    // Dummy Label for Padding
    Label label = new Label(parent, SWT.NONE);
    label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    // The Warning Composite
    fMCUWarningComposite = new Composite(parent, SWT.NONE);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 4;
    fMCUWarningComposite.setLayoutData(gd);
    GridLayout gl = new GridLayout(2, false);
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    gl.verticalSpacing = 0;
    gl.horizontalSpacing = 0;
    fMCUWarningComposite.setLayout(gl);

    Label warnicon = new Label(fMCUWarningComposite, SWT.LEFT);
    warnicon.setLayoutData(new GridData(GridData.BEGINNING));
    warnicon.setImage(IMG_WARN);

    Label warnmessage = new Label(fMCUWarningComposite, SWT.LEFT);
    warnmessage.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    warnmessage.setText("This MCU is not supported by AVRDude");

    fMCUWarningComposite.setVisible(false);
}

From source file:de.innot.avreclipse.ui.propertypages.TabTargetHardware.java

License:Open Source License

private void addFCPUSection(Composite parent) {

    GridData gd = new GridData();
    FontMetrics fm = getFontMetrics(parent);
    gd.widthHint = Dialog.convertWidthInCharsToPixels(fm, 14);

    setupLabel(parent, LABEL_FCPU, 1, SWT.NONE);

    fFCPUcombo = new Combo(parent, SWT.DROP_DOWN);
    fFCPUcombo.setLayoutData(gd);// ww  w .  j a  v  a  2s  . c o m
    fFCPUcombo.setTextLimit(8); // max. 99 MHz
    fFCPUcombo.setToolTipText("Target Hardware Clock Frequency in Hz");
    fFCPUcombo.setVisibleItemCount(FCPU_VALUES.length);
    fFCPUcombo.setItems(FCPU_VALUES);

    fFCPUcombo.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            if (fTargetProps != null) {
                fTargetProps.setFCPU(fFCPUcombo.getText());
            }
        }
    });

    // Ensure that only integer values are entered
    fFCPUcombo.addVerifyListener(new VerifyListener() {
        public void verifyText(VerifyEvent event) {
            String text = event.text;
            if (!text.matches("[0-9]*")) {
                event.doit = false;
            }
        }
    });
}

From source file:de.walware.ecommons.ui.util.PixelConverter.java

License:Open Source License

/**
 * @see org.eclipse.jface.dialogs.DialogPage#convertWidthInCharsToPixels(int)
 *///from   ww  w. j  a  v  a  2  s .  c om
public int convertWidthInCharsToPixels(final int chars) {
    if (fMonospace) {
        return Dialog.convertWidthInCharsToPixels(fFontMetrics, chars);
    } else {
        return (int) (FONT_WS_FACTOR * Dialog.convertWidthInCharsToPixels(fFontMetrics, chars));
    }
}

From source file:descent.internal.ui.preferences.JavaEditorColoringConfigurationBlock.java

License:Open Source License

/**
  * Returns the number of pixels corresponding to the width of the given
  * number of characters./*from  w  ww .j ava  2  s. c o m*/
  * <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
  */
private int convertWidthInCharsToPixels(int chars) {
    // test for failure to initialize for backward compatibility
    if (fFontMetrics == null)
        return 0;
    return Dialog.convertWidthInCharsToPixels(fFontMetrics, chars);
}

From source file:gov.redhawk.ui.util.PixelConverter.java

License:Open Source License

/**
 * Convert width in chars to pixels./*from  w w  w  .  j  a  va  2  s .  co m*/
 * 
 * @param chars the chars
 * @return the int
 * @see DialogPage#convertWidthInCharsToPixels
 */
public int convertWidthInCharsToPixels(final int chars) {
    return Dialog.convertWidthInCharsToPixels(this.fFontMetrics, chars);
}

From source file:net.bpelunit.toolsupport.editors.wizards.components.DataComponent.java

License:Open Source License

protected int getMaxFieldWidth() {
    return Dialog.convertWidthInCharsToPixels(fFontMetrics, 40);
}