Example usage for org.eclipse.jface.resource JFaceResources getDialogFont

List of usage examples for org.eclipse.jface.resource JFaceResources getDialogFont

Introduction

In this page you can find the example usage for org.eclipse.jface.resource JFaceResources getDialogFont.

Prototype

public static Font getDialogFont() 

Source Link

Document

Returns the JFace's dialog font.

Usage

From source file:com.google.dart.tools.ui.internal.util.SWTUtil.java

License:Open Source License

/**
 * Returns a width hint for a button control.
 *///from ww w .  j a  v  a2 s .co m
public static int getButtonWidthHint(Button button) {
    button.setFont(JFaceResources.getDialogFont());
    @SuppressWarnings("deprecation")
    PixelConverter converter = new PixelConverter(button);
    int widthHint = converter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
}

From source file:com.google.dart.tools.ui.omni.OmniBoxPopup.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);

    boolean isWin32 = Util.isWindows();
    GridLayoutFactory.fillDefaults().extendedMargins(isWin32 ? 0 : 3, 3, 2, 2).applyTo(composite);
    Composite tableComposite = new Composite(composite, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(tableComposite);

    TableColumnLayout tableColumnLayout = new TableColumnLayout();
    tableComposite.setLayout(tableColumnLayout);

    table = new Table(tableComposite, SWT.SINGLE | SWT.FULL_SELECTION);
    textLayout = new TextLayout(table.getDisplay());
    textLayout.setOrientation(getDefaultOrientation());
    Font boldFont = resourceManager
            .createFont(FontDescriptor.createFrom(JFaceResources.getDialogFont()).setStyle(SWT.BOLD));
    textLayout.setFont(table.getFont());
    textLayout.setText(OmniBoxMessages.OmniBox_Providers);
    int maxProviderWidth = (int) (textLayout.getBounds().width * 1.1);
    textLayout.setFont(boldFont);//from   w w  w.j av  a 2  s  . c o m
    for (int i = 0; i < providers.length; i++) {
        OmniProposalProvider provider = providers[i];
        textLayout.setText(provider.getName());
        int width = (int) (textLayout.getBounds().width * 1.1);
        if (width > maxProviderWidth) {
            maxProviderWidth = width;
        }
    }

    //TODO (pquitslund): just a placeholder column for now
    tableColumnLayout.setColumnData(new TableColumn(table, SWT.NONE),
            new ColumnWeightData(0, 3 /* maxProviderWidth) */));
    tableColumnLayout.setColumnData(new TableColumn(table, SWT.NONE), new ColumnWeightData(100, 100));

    //TODO (pquitslund): and with this goes the ability to resize...
    //    table.getShell().addControlListener(new ControlAdapter() {
    //      @Override
    //      public void controlResized(ControlEvent e) {
    //        if (!showAllMatches) {
    //          if (!resized) {
    //            resized = true;
    //            e.display.timerExec(100, new Runnable() {
    //              @Override
    //              public void run() {
    //                if (getShell() != null && !getShell().isDisposed()) {
    //                  refresh(getFilterText());
    //                }
    //                resized = false;
    //              }
    //
    //            });
    //          }
    //        }
    //      }
    //    });

    /*
     * Since the control is unfocused, we need to hijack paint events and draw our own selections.
     */
    final Color selectionColor = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION);
    table.addListener(SWT.EraseItem, new Listener() {
        @Override
        public void handleEvent(Event event) {
            event.detail &= ~SWT.HOT;
            if ((event.detail & SWT.SELECTED) == 0) {
                return; /* item not selected */
            }

            Widget item = event.item;
            if (item instanceof TableItem) {
                Object data = ((TableItem) item).getData();
                if (data instanceof OmniEntry) {
                    if (((OmniEntry) data).element instanceof HeaderElement) {
                        event.detail &= ~SWT.SELECTED;
                        return;
                    }
                }
            }

            int clientWidth = table.getClientArea().width;
            GC gc = event.gc;
            Color oldBackground = gc.getBackground();
            gc.setBackground(selectionColor);
            gc.fillRectangle(new Rectangle(0, event.y, clientWidth, event.height));
            gc.setBackground(oldBackground);
            event.detail &= ~SWT.SELECTED;
        }
    });

    table.addKeyListener(getKeyAdapter());
    table.addKeyListener(new KeyListener() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.ARROW_UP && table.getSelectionIndex() == 0) {
                setFilterFocus();
            } else if (e.character == SWT.ESC) {
                close();
            }
        }

        @Override
        public void keyReleased(KeyEvent e) {
            // do nothing
        }
    });
    table.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseUp(MouseEvent e) {

            if (table.getSelectionCount() < 1) {
                return;
            }

            if (e.button != 1) {
                return;
            }

            if (table.equals(e.getSource())) {
                Object o = table.getItem(new Point(e.x, e.y));
                TableItem selection = table.getSelection()[0];
                if (selection.equals(o)) {
                    handleSelection();
                }
            }
        }
    });
    table.addMouseMoveListener(new MouseMoveListener() {
        TableItem lastItem = null;

        @Override
        public void mouseMove(MouseEvent e) {
            if (table.equals(e.getSource())) {
                Object o = table.getItem(new Point(e.x, e.y));
                if (lastItem == null ^ o == null) {
                    table.setCursor(o == null ? null : table.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
                }
                if (o instanceof TableItem) {
                    if (!o.equals(lastItem)) {
                        lastItem = (TableItem) o;
                        table.setSelection(new TableItem[] { lastItem });
                    }
                } else if (o == null) {
                    lastItem = null;
                }
            }
        }
    });

    table.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            handleSelection();
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (Util.isMac()) {
                handleSelection();
            }
        }
    });

    final TextStyle boldStyle;
    if (PlatformUI.getPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.USE_COLORED_LABELS)) {
        boldStyle = new TextStyle(boldFont, null, null);
        // italicsFont = resourceManager.createFont(FontDescriptor.createFrom(
        // table.getFont()).setStyle(SWT.ITALIC));
    } else {
        boldStyle = null;
    }
    final TextStyle grayStyle = new TextStyle(table.getFont(), OmniBoxColors.SEARCH_ENTRY_ITEM_TEXT, null);

    Listener listener = new Listener() {
        @Override
        public void handleEvent(Event event) {
            OmniEntry entry = (OmniEntry) event.item.getData();
            if (entry != null) {
                switch (event.type) {
                case SWT.MeasureItem:
                    entry.measure(event, textLayout, resourceManager, boldStyle);
                    break;
                case SWT.PaintItem:
                    entry.paint(event, textLayout, resourceManager, boldStyle, grayStyle);
                    break;
                case SWT.EraseItem:
                    entry.erase(event);
                    break;
                }
            }
        }
    };

    table.addListener(SWT.MeasureItem, listener);
    table.addListener(SWT.EraseItem, listener);
    table.addListener(SWT.PaintItem, listener);
    //In GTK linux, the table is hungry for focus and steals it on updates
    //When the table has focus it grabs key events that are intended for the
    //search entry box; to make things right, we need to punt focus back
    //to the search box
    if (Util.isLinux()) {
        table.addFocusListener(new FocusListener() {

            @Override
            public void focusGained(FocusEvent e) {
                Display.getDefault().syncExec(new Runnable() {
                    @Override
                    public void run() {
                        //punt focus back to the text box
                        getFocusControl().setFocus();
                    }
                });
            }

            @Override
            public void focusLost(FocusEvent e) {
            }
        });
    }

    return composite;
}

From source file:com.google.gdt.eclipse.core.actions.AbstractOpenWizardAction.java

License:Open Source License

@Override
public void run() {
    Shell localShell = getShell();//from w  w  w . ja va  2  s .  c  om
    if (!doCreateProjectFirstOnEmptyWorkspace(localShell)) {
        return;
    }

    try {
        INewWizard wizard = createWizard();
        wizard.init(PlatformUI.getWorkbench(), getSelection());

        WizardDialog dialog = new WizardDialog(localShell, wizard);
        IPixelConverter converter = PixelConverterFactory.createPixelConverter(JFaceResources.getDialogFont());
        dialog.setMinimumPageSize(converter.convertWidthInCharsToPixels(70),
                converter.convertHeightInCharsToPixels(20));
        dialog.create();
        int res = dialog.open();
        if (res == Window.OK && wizard instanceof NewElementWizard) {
            createdElement = ((NewElementWizard) wizard).getCreatedElement();
        }

        notifyResult(res == Window.OK);
    } catch (CoreException e) {
        String title = NewWizardMessages.AbstractOpenWizardAction_createerror_title;
        String message = NewWizardMessages.AbstractOpenWizardAction_createerror_message;
        ExceptionHandler.handle(e, localShell, title, message);
    }
}

From source file:com.google.gdt.eclipse.managedapis.BaseResources.java

License:Open Source License

/**
 * Method produces a font descriptor for the specified style and size. This
 * method should only be called from a UI thread; the doInitResources() method
 * ensures that this constraint is met.//from w  ww . ja  v  a  2 s  .  c  o m
 */
private FontDescriptor createFontDescriptor(int style, float heightMultiplier) {
    Font baseFont = JFaceResources.getDialogFont();
    FontData[] fontData = baseFont.getFontData();
    FontData[] newFontData = new FontData[fontData.length];
    for (int i = 0; i < newFontData.length; i++) {
        newFontData[i] = new FontData(fontData[i].getName(), (int) (fontData[i].getHeight() * heightMultiplier),
                fontData[i].getStyle() | style);
    }
    return FontDescriptor.createFrom(newFontData);
}

From source file:com.google.gwt.eclipse.core.compile.ui.GWTCompileDialog.java

License:Open Source License

private void createAdvancedOptions(Composite parent) {
    IPixelConverter converter = PixelConverterFactory.createPixelConverter(JFaceResources.getDialogFont());

    // Expandable panel for advanced options
    final ExpandableComposite expandPanel = new ExpandableComposite(parent, SWT.NONE,
            ExpandableComposite.TWISTIE | ExpandableComposite.CLIENT_INDENT);
    expandPanel.setText("Advanced");
    expandPanel.setExpanded(false);/* ww  w .j av a 2s  . co m*/
    expandPanel.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT));
    GridData expandPanelGridData = new GridData(GridData.FILL, GridData.FILL, true, false, 3, 1);
    expandPanelGridData.verticalIndent = converter.convertHeightInCharsToPixels(1);
    expandPanel.setLayoutData(expandPanelGridData);
    expandPanel.addExpansionListener(new ExpansionAdapter() {
        @Override
        public void expansionStateChanged(ExpansionEvent e) {
            Shell shell = getShell();
            shell.setLayoutDeferred(true); // Suppress redraw flickering

            Point size = shell.getSize();
            int shellHeightDeltaOnExpand = advancedContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
            if (expandPanel.isExpanded()) {
                shell.setSize(size.x, size.y + shellHeightDeltaOnExpand);
            } else {
                shell.setSize(size.x, size.y - shellHeightDeltaOnExpand);
            }
            shell.layout(true, true);

            shell.setLayoutDeferred(false);
        }
    });

    advancedContainer = new Composite(expandPanel, SWT.NONE);
    advancedContainer.setLayoutData(new GridData());
    advancedContainer.setFont(parent.getFont());
    advancedContainer.setLayout(new GridLayout(1, false));
    expandPanel.setClient(advancedContainer);

    // Additional compiler parameters field
    SWTFactory.createLabel(advancedContainer, "Additional compiler arguments:", 1);
    extraArgsText = SWTUtilities.createMultilineTextbox(advancedContainer, SWT.BORDER, false);
    GridData extraArgsGridData = new GridData(GridData.FILL_HORIZONTAL);
    extraArgsGridData.heightHint = converter.convertHeightInCharsToPixels(5);
    extraArgsText.setLayoutData(extraArgsGridData);

    // Additional VM args field
    SWTFactory.createLabel(advancedContainer, "VM arguments:", 1);
    vmArgsText = SWTUtilities.createMultilineTextbox(advancedContainer, SWT.BORDER, false);
    GridData vmArgsGridData = new GridData(GridData.FILL_HORIZONTAL);
    vmArgsGridData.heightHint = converter.convertHeightInCharsToPixels(5);
    vmArgsText.setLayoutData(vmArgsGridData);
}

From source file:com.google.gwt.eclipse.core.markers.quickfixes.CreateAsyncInterfaceProposal.java

License:Open Source License

@Override
public void apply(IDocument document) {
    StructuredSelection selection = new StructuredSelection(compilationUnit);
    NewElementWizard wizard = createWizard(selection);
    wizard.init(JavaPlugin.getDefault().getWorkbench(), selection);

    IType localCreatedType = null;/*from   w  ww.  j  a v  a2 s  .c o  m*/

    if (isShowDialog()) {
        Shell shell = JavaPlugin.getActiveWorkbenchShell();
        WizardDialog dialog = new WizardDialog(shell, wizard);

        IPixelConverter converter = PixelConverterFactory.createPixelConverter(JFaceResources.getDialogFont());
        dialog.setMinimumPageSize(converter.convertWidthInCharsToPixels(70),
                converter.convertHeightInCharsToPixels(20));
        dialog.create();
        dialog.getShell().setText(NewAsyncRemoteServiceInterfaceCreationWizard.DEFAULT_WINDOW_TITLE);

        if (dialog.open() == Window.OK) {
            localCreatedType = (IType) wizard.getCreatedElement();
        }
    } else {
        wizard.addPages();
        try {
            NewTypeWizardPage page = getPage(wizard);
            page.createType(null);
            localCreatedType = page.getCreatedType();
        } catch (CoreException e) {
            JavaPlugin.log(e);
        } catch (InterruptedException e) {
        }
    }

    if (localCreatedType != null) {
        IJavaElement container = localCreatedType.getParent();
        if (container instanceof ICompilationUnit) {
            container = container.getParent();
        }

        if (!container.equals(typeContainer)) {
            // add import
            try {
                ImportRewrite rewrite = StubUtility.createImportRewrite(compilationUnit, true);
                rewrite.addImport(localCreatedType.getFullyQualifiedName('.'));
                JavaModelUtil.applyEdit(compilationUnit, rewrite.rewriteImports(null), false, null);
            } catch (CoreException e) {
            }
        }
        this.createdType = localCreatedType;
    }
}

From source file:com.googlecode.goclipse.editors.assist.InformationControl.java

License:Open Source License

private void createStatusLabel(final String statusFieldText, Color foreground, Color background) {
    fStatusLabel = new Label(fStatusComposite, SWT.RIGHT);
    fStatusLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    fStatusLabel.setText(statusFieldText);

    FontData[] fontDatas = JFaceResources.getDialogFont().getFontData();
    for (int i = 0; i < fontDatas.length; i++) {
        fontDatas[i].setHeight(fontDatas[i].getHeight() * 9 / 10);
    }//from  w  ww .j a  v  a  2s .c  o m
    fStatusLabelFont = new Font(fStatusLabel.getDisplay(), fontDatas);
    fStatusLabel.setFont(fStatusLabelFont);

    fStatusLabel.setForeground(fStatusLabel.getDisplay().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
    fStatusLabel.setBackground(background);
    setColor(fStatusComposite, foreground, background);
}

From source file:com.googlecode.goclipse.editors.assist.InformationControl.java

License:Open Source License

/**
 * Computes the size constraints based on the
 * {@link JFaceResources#getDialogFont() dialog font}. Subclasses can
 * override or extend./*  w ww  . j  a  v  a 2  s.  com*/
 *
 * @see org.eclipse.jface.text.IInformationControlExtension5#computeSizeConstraints(int, int)
 */
@Override
public Point computeSizeConstraints(int widthInChars, int heightInChars) {
    GC gc = new GC(fContentComposite);
    gc.setFont(JFaceResources.getDialogFont());
    int width = gc.getFontMetrics().getAverageCharWidth();
    int height = gc.getFontMetrics().getHeight();
    gc.dispose();

    return new Point(widthInChars * width, heightInChars * height);
}

From source file:com.gorillalogic.monkeyconsole.editors.utils.TitleAreaDialogStyledTextMessage.java

License:Open Source License

protected Control createContents(Composite parent) {
    // create the overall composite
    Composite contents = new Composite(parent, SWT.NONE);
    contents.setLayoutData(new GridData(GridData.FILL_BOTH));
    // initialize the dialog units
    initializeDialogUnits(contents);//from w w  w . j ava2s  . co  m
    FormLayout layout = new FormLayout();
    contents.setLayout(layout);
    // Now create a work area for the rest of the dialog
    workArea = new Composite(contents, SWT.NONE);
    GridLayout childLayout = new GridLayout();
    childLayout.marginHeight = 0;
    childLayout.marginWidth = 0;
    childLayout.verticalSpacing = 0;
    workArea.setLayout(childLayout);
    Control top = createTitleArea(contents);
    resetWorkAreaAttachments(top);
    workArea.setFont(JFaceResources.getDialogFont());
    // initialize the dialog units
    initializeDialogUnits(workArea);
    // create the dialog area and button bar
    dialogArea = createDialogArea(workArea);
    buttonBar = createButtonBar(workArea);
    return contents;
}

From source file:com.gorillalogic.monkeyconsole.editors.utils.TitleAreaDialogStyledTextMessage.java

License:Open Source License

/**
 * Creates the dialog's title area./*from  ww w.  jav a2 s . c om*/
 * 
 * @param parent
 *            the SWT parent for the title area widgets
 * @return Control with the highest x axis value.
 */
private Control createTitleArea(Composite parent) {

    // add a dispose listener
    parent.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent e) {
            if (titleAreaColor != null) {
                titleAreaColor.dispose();
            }
        }
    });
    // Determine the background color of the title bar
    Display display = parent.getDisplay();
    Color background;
    Color foreground;
    if (titleAreaRGB != null) {
        titleAreaColor = new Color(display, titleAreaRGB);
        background = titleAreaColor;
        foreground = null;
    } else {
        background = JFaceColors.getBannerBackground(display);
        foreground = JFaceColors.getBannerForeground(display);
    }

    parent.setBackground(background);
    int verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    int horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
    // Dialog image @ right
    titleImageLabel = new Label(parent, SWT.CENTER);
    titleImageLabel.setBackground(background);
    if (titleAreaImage == null)
        titleImageLabel.setImage(JFaceResources.getImage(DLG_IMG_TITLE_BANNER));
    else
        titleImageLabel.setImage(titleAreaImage);

    FormData imageData = new FormData();
    imageData.top = new FormAttachment(0, 0);
    // Note: do not use horizontalSpacing on the right as that would be a
    // regression from
    // the R2.x style where there was no margin on the right and images are
    // flush to the right
    // hand side. see reopened comments in 41172
    imageData.right = new FormAttachment(100, 0); // horizontalSpacing
    titleImageLabel.setLayoutData(imageData);
    // Title label @ top, left
    titleLabel = new Label(parent, SWT.LEFT);
    JFaceColors.setColors(titleLabel, foreground, background);
    titleLabel.setFont(JFaceResources.getBannerFont());
    titleLabel.setText(" ");//$NON-NLS-1$
    FormData titleData = new FormData();
    titleData.top = new FormAttachment(0, verticalSpacing);
    titleData.right = new FormAttachment(titleImageLabel);
    titleData.left = new FormAttachment(0, horizontalSpacing);
    titleLabel.setLayoutData(titleData);
    // Message image @ bottom, left
    messageImageLabel = new Label(parent, SWT.CENTER);
    messageImageLabel.setBackground(background);
    // Message label @ bottom, center
    messageLabel = new Link(parent, SWT.WRAP | SWT.READ_ONLY);
    JFaceColors.setColors(messageLabel, foreground, background);
    messageLabel.setText(" \n "); // two lines//$NON-NLS-1$
    messageLabel.setFont(JFaceResources.getDialogFont());
    messageLabelHeight = messageLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
    // Filler labels
    leftFillerLabel = new Label(parent, SWT.CENTER);
    leftFillerLabel.setBackground(background);
    bottomFillerLabel = new Label(parent, SWT.CENTER);
    bottomFillerLabel.setBackground(background);
    setLayoutsForNormalMessage(verticalSpacing, horizontalSpacing);
    determineTitleImageLargest();
    if (titleImageLargest)
        return titleImageLabel;
    return messageLabel;
}