Search in sources :

Example 16 with PixelConverter

use of org.eclipse.jface.layout.PixelConverter in project eclipse.platform.text by eclipse.

the class QuickDiffConfigurationBlock method addFiller.

private void addFiller(Composite composite) {
    PixelConverter pixelConverter = new PixelConverter(composite);
    Label filler = new Label(composite, SWT.LEFT);
    GridData gd = new GridData(SWT.FILL, SWT.CENTER, false, false);
    gd.horizontalSpan = 2;
    gd.heightHint = pixelConverter.convertHeightInCharsToPixels(1) / 2;
    filler.setLayoutData(gd);
}
Also used : PixelConverter(org.eclipse.jface.layout.PixelConverter) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData)

Example 17 with PixelConverter

use of org.eclipse.jface.layout.PixelConverter in project eclipse.platform.text by eclipse.

the class SWTUtil method getButtonWidthHint.

/**
 * Returns a width hint for a button control.
 * @param button The button to calculate the width for
 * @return The width of the button
 */
public static int getButtonWidthHint(Button button) {
    button.setFont(JFaceResources.getDialogFont());
    PixelConverter converter = new PixelConverter(button);
    int widthHint = converter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
}
Also used : PixelConverter(org.eclipse.jface.layout.PixelConverter)

Example 18 with PixelConverter

use of org.eclipse.jface.layout.PixelConverter in project linuxtools by eclipse.

the class LaunchConfigurationUtils method getButtonWidthHint.

/**
 * Computes the size of the given {@link Button} and returns the width.
 *
 * @param button
 *            the button for which the size must be computed.
 * @return the width hint for the given button
 */
public static int getButtonWidthHint(final Button button) {
    /* button.setFont(JFaceResources.getDialogFont()); */
    final PixelConverter converter = new PixelConverter(button);
    final int widthHint = converter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
}
Also used : PixelConverter(org.eclipse.jface.layout.PixelConverter)

Example 19 with PixelConverter

use of org.eclipse.jface.layout.PixelConverter in project knime-core by knime.

the class SubnodeLayoutJSONEditorPage method createJSONEditorComposite.

private Composite createJSONEditorComposite(final Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, true));
    composite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
    if (isWindows()) {
        Composite embedComposite = new Composite(composite, SWT.EMBEDDED | SWT.NO_BACKGROUND);
        final GridLayout gridLayout = new GridLayout();
        gridLayout.verticalSpacing = 0;
        gridLayout.marginWidth = 0;
        gridLayout.marginHeight = 0;
        gridLayout.horizontalSpacing = 0;
        embedComposite.setLayout(gridLayout);
        embedComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
        Frame frame = SWT_AWT.new_Frame(embedComposite);
        Panel heavyWeightPanel = new Panel();
        heavyWeightPanel.setLayout(new BoxLayout(heavyWeightPanel, BoxLayout.Y_AXIS));
        frame.add(heavyWeightPanel);
        frame.setFocusTraversalKeysEnabled(false);
        // Use JApplet with JRootPane as layer in between heavyweightPanel and RTextScrollPane
        // This reduces flicker on resize in RSyntaxTextArea
        JApplet applet = new JApplet();
        JRootPane root = applet.getRootPane();
        Container contentPane = root.getContentPane();
        contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
        heavyWeightPanel.add(applet);
        m_textArea = new RSyntaxTextArea(10, 60);
        m_textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JSON);
        m_textArea.setCodeFoldingEnabled(true);
        m_textArea.setAntiAliasingEnabled(true);
        RTextScrollPane sp = new RTextScrollPane(m_textArea);
        sp.setDoubleBuffered(true);
        m_textArea.setText(m_jsonDocument);
        m_textArea.setEditable(true);
        m_textArea.setEnabled(true);
        contentPane.add(sp);
        Dimension size = sp.getPreferredSize();
        embedComposite.setSize(size.width, size.height);
        // forward focus to RSyntaxTextArea
        embedComposite.addFocusListener(new FocusAdapter() {

            @Override
            public void focusGained(final FocusEvent e) {
                ViewUtils.runOrInvokeLaterInEDT(new Runnable() {

                    @Override
                    public void run() {
                        m_textArea.requestFocus();
                        m_textArea.setCaretPosition(m_caretPosition);
                    }
                });
            }

            @Override
            public void focusLost(final FocusEvent e) {
            // do nothing
            }
        });
        // delete content of status line, when something is inserted or deleted
        m_textArea.getDocument().addDocumentListener(new DocumentListener() {

            @Override
            public void changedUpdate(final DocumentEvent arg0) {
                if (!composite.isDisposed()) {
                    composite.getDisplay().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            if (m_statusLine != null && !m_statusLine.isDisposed()) {
                                m_statusLine.setText("");
                                updateModelFromJson();
                            }
                        }
                    });
                }
            }

            @Override
            public void insertUpdate(final DocumentEvent arg0) {
            /* do nothing */
            }

            @Override
            public void removeUpdate(final DocumentEvent arg0) {
            /* do nothing */
            }
        });
        // remember caret position
        m_textArea.addCaretListener(new CaretListener() {

            @Override
            public void caretUpdate(final CaretEvent arg0) {
                m_caretPosition = arg0.getDot();
            }
        });
    } else {
        m_text = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
        GridData layoutData = new GridData(GridData.FILL_BOTH);
        layoutData.widthHint = 600;
        layoutData.heightHint = 400;
        m_text.setLayoutData(layoutData);
        m_text.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(final ModifyEvent e) {
                m_jsonDocument = m_text.getText();
                if (m_statusLine != null && !m_statusLine.isDisposed()) {
                    m_statusLine.setText("");
                    updateModelFromJson();
                }
            }
        });
        m_text.setText(m_jsonDocument);
    }
    // add status line
    m_statusLine = new Label(composite, SWT.SHADOW_NONE | SWT.WRAP);
    GridData statusGridData = new GridData(SWT.LEFT | SWT.FILL, SWT.BOTTOM, true, false);
    int maxHeight = new PixelConverter(m_statusLine).convertHeightInCharsToPixels(3);
    statusGridData.heightHint = maxHeight + 5;
    // seems to have no impact on the layout. The height will still be 3 rows (at least on Windows 8)
    statusGridData.minimumHeight = new PixelConverter(m_statusLine).convertHeightInCharsToPixels(1);
    m_statusLine.setLayoutData(statusGridData);
    compareNodeIDs();
    return composite;
}
Also used : CaretEvent(javax.swing.event.CaretEvent) FocusAdapter(org.eclipse.swt.events.FocusAdapter) DocumentListener(javax.swing.event.DocumentListener) Frame(java.awt.Frame) ModifyListener(org.eclipse.swt.events.ModifyListener) BoxLayout(javax.swing.BoxLayout) Label(org.eclipse.swt.widgets.Label) FocusEvent(org.eclipse.swt.events.FocusEvent) GridLayout(org.eclipse.swt.layout.GridLayout) JApplet(javax.swing.JApplet) NodeContainer(org.knime.core.node.workflow.NodeContainer) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) Container(java.awt.Container) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Text(org.eclipse.swt.widgets.Text) Dimension(java.awt.Dimension) DocumentEvent(javax.swing.event.DocumentEvent) Point(org.eclipse.swt.graphics.Point) Panel(java.awt.Panel) CaretListener(javax.swing.event.CaretListener) RSyntaxTextArea(org.fife.ui.rsyntaxtextarea.RSyntaxTextArea) GridData(org.eclipse.swt.layout.GridData) PixelConverter(org.eclipse.jface.layout.PixelConverter) JRootPane(javax.swing.JRootPane) RTextScrollPane(org.fife.ui.rtextarea.RTextScrollPane)

Aggregations

PixelConverter (org.eclipse.jface.layout.PixelConverter)19 GridData (org.eclipse.swt.layout.GridData)13 Label (org.eclipse.swt.widgets.Label)10 GridLayout (org.eclipse.swt.layout.GridLayout)8 Composite (org.eclipse.swt.widgets.Composite)8 SelectionEvent (org.eclipse.swt.events.SelectionEvent)6 Button (org.eclipse.swt.widgets.Button)5 Text (org.eclipse.swt.widgets.Text)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3 SelectionListener (org.eclipse.swt.events.SelectionListener)3 Point (org.eclipse.swt.graphics.Point)3 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)2 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)2 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)2 FocusAdapter (org.eclipse.swt.events.FocusAdapter)2 ModifyEvent (org.eclipse.swt.events.ModifyEvent)2 ModifyListener (org.eclipse.swt.events.ModifyListener)2 Container (java.awt.Container)1 Dimension (java.awt.Dimension)1 Frame (java.awt.Frame)1