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

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

Introduction

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

Prototype

public static FontRegistry getFontRegistry() 

Source Link

Document

Returns the font registry for JFace itself.

Usage

From source file:fr.lip6.move.coloane.core.ui.figures.nodes.PlaceNode.java

License:Open Source License

/**
 * {@inheritDoc}/*from   w ww  . j  av  a  2  s  .  c  om*/
 */
@Override
protected final void outlineShape(Graphics graphics) {
    Rectangle r = Rectangle.SINGLETON;
    r.setBounds(getBounds());
    r.width--;
    r.height--;
    int lineWidth = getLineWidth();
    r.shrink((lineWidth - 1) / 2, (lineWidth - 1) / 2);
    graphics.drawOval(r);

    if (toshow > 0 && toshow < 10) {
        switch (toshow) {
        case 0:
            return;
        case 1: {
            drawToken(0.52, 0.52, graphics);
            return;
        }
        case 2: {
            drawToken(0.2, 0.40, graphics);
            drawToken(0.65, 0.50, graphics);
            return;
        }
        case 3: {
            drawToken(0.2, 0.3, graphics);
            drawToken(0.4, 0.6, graphics);
            drawToken(0.6, 0.3, graphics);
            return;
        }
        default: {
            Point x = getBounds().getLeft().translate(6, -7);
            graphics.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
            graphics.drawString("" + toshow, x);
            return;
        }
        }
    }

}

From source file:fr.lip6.move.coloane.core.ui.figures.nodes.ScalarDelegate.java

License:Open Source License

/**
 * {@inheritDoc}//  ww w . j av  a 2s  . com
 */
@Override
protected final void outlineShape(final Graphics graphics) {
    Rectangle r = getBounds();

    boolean isPublic = getModel().getAttribute("visibility").getValue().equals("public");

    int lineWidth = getLineWidth();
    int x = r.x + lineWidth / 2;
    int y = r.y + lineWidth / 2;
    int w = r.width - Math.max(1, lineWidth);
    int h = r.height - Math.max(1, lineWidth);
    graphics.drawRectangle(x, y, w, h);

    // double the line for public transition : gives a "bold" effect.
    if (isPublic) {
        int ix = x + 2;
        int iy = y + 2;
        int iw = Math.max(1, w - 4);
        int ih = Math.max(1, h - 4);
        graphics.drawRectangle(ix, iy, iw, ih);
    }

    String type = getModel().getAttribute("kind").getValue();
    graphics.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
    graphics.drawText(type, getBounds().getTopLeft().translate(5, 3));

}

From source file:fr.lip6.move.coloane.extensions.exporttosvg.ExportToSVG.java

License:Open Source License

/**
 * Create attribute figures// w w w. ja  v  a  2s . c o  m
 * 
 * @param attributes
 *            list of attribute
 * @return list of figure for each attributes
 */
private Collection<IFigure> createAttributeFigures(Collection<IAttribute> attributes) {
    List<IFigure> list = new ArrayList<IFigure>();
    for (IAttribute attr : attributes) {
        if (attr.getAttributeFormalism().isDrawable()
                && !attr.getValue().equals(attr.getAttributeFormalism().getDefaultValue())) {
            final Point location = attr.getGraphicInfo().getLocation();
            Label label = new Label() {
                @Override
                public void paint(Graphics graphics) {
                    graphics.setFont(getFont());
                    graphics.setForegroundColor(getForegroundColor());
                    graphics.setBackgroundColor(getBackgroundColor());
                    graphics.fillText(getText(), location);
                }
            };
            label.setOpaque(true);
            label.setText(attr.getValue());
            label.setLocation(attr.getGraphicInfo().getLocation());
            label.setForegroundColor(attr.getGraphicInfo().getForeground());
            label.setBackgroundColor(attr.getGraphicInfo().getBackground());

            Font font = JFaceResources.getDefaultFont();
            if (attr.getAttributeFormalism().isBold()) {
                font = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT);
            } else if (attr.getAttributeFormalism().isItalic()) {
                font = JFaceResources.getFontRegistry().getItalic(JFaceResources.DEFAULT_FONT);
            }
            label.setFont(font);
            label.setBounds(label.getTextBounds());

            list.add(label);
        }
    }
    return list;
}

From source file:gov.nasa.ensemble.common.ui.ide.navigator.EnsembleFilteredTree.java

License:Open Source License

/**
 * Return a bold font if the given element matches the given pattern.
 * Clients can opt to call this method from a Viewer's label provider to get
 * a bold font for which to highlight the given element in the tree.
 * /* w  ww  . jav  a  2 s  .  c  o m*/
 * @param element
 *            element for which a match should be determined
 * @param tree
 *            FilteredTree in which the element resides
 * @param filter
 *            PatternFilter which determines a match
 * 
 * @return bold font
 */
public static Font getBoldFont(Object element, EnsembleFilteredTree tree, EnsemblePatternFilter filter) {
    String filterText = tree.getFilterString();

    if (filterText == null) {
        return null;
    }

    // Do nothing if it's empty string
    String initialText = tree.getInitialText();
    if (!filterText.equals("") && !filterText.equals(initialText)) {//$NON-NLS-1$
        if (tree.getPatternFilter() != filter) {
            boolean initial = initialText != null && initialText.equals(filterText);
            if (initial) {
                filter.setPattern(null);
            } else if (filterText != null) {
                filter.setPattern(filterText);
            }
        }
        if (filter.isElementVisible(tree.getViewer(), element)
                && filter.isLeafMatch(tree.getViewer(), element)) {
            return JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT);
        }
    }
    return null;
}

From source file:hierarchyviewer.ios.View.java

License:GNU General Public License

public void createPartControl(Composite parent) {
    Composite top = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;//from   w w w. ja  va  2  s  .  com
    layout.marginWidth = 0;
    top.setLayout(layout);
    // top banner
    Composite banner = new Composite(top, SWT.NONE);
    banner.setLayoutData(
            new GridData(GridData.HORIZONTAL_ALIGN_FILL, GridData.VERTICAL_ALIGN_BEGINNING, true, false));
    layout = new GridLayout();
    layout.marginHeight = 5;
    layout.marginWidth = 10;
    layout.numColumns = 2;
    banner.setLayout(layout);

    // setup bold font
    Font boldFont = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT);

    Label l = new Label(banner, SWT.WRAP);
    l.setText("Subject:");
    l.setFont(boldFont);
    l = new Label(banner, SWT.WRAP);
    l.setText("This is a message about the cool Eclipse RCP!");

    l = new Label(banner, SWT.WRAP);
    l.setText("From:");
    l.setFont(boldFont);

    final Link link = new Link(banner, SWT.NONE);
    link.setText("<a>nicole@mail.org</a>");
    link.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            MessageDialog.openInformation(getSite().getShell(), "Not Implemented",
                    "Imagine the address book or a new message being created now.");
        }
    });

    l = new Label(banner, SWT.WRAP);
    l.setText("Date:");
    l.setFont(boldFont);
    l = new Label(banner, SWT.WRAP);
    l.setText("10:34 am");
    // message contents
    messageText = new Text(top, SWT.MULTI | SWT.WRAP);
    messageText.setText(
            "This RCP Application was generated from the PDE Plug-in Project wizard. This sample shows how to:\n"
                    + "- add a top-level menu and toolbar with actions\n" + "- add keybindings to actions\n"
                    + "- create views that can't be closed and\n" + "  multiple instances of the same view\n"
                    + "- perspectives with placeholders for new views\n" + "- use the default about dialog\n"
                    + "- create a product definition\n");
    messageText.setLayoutData(new GridData(GridData.FILL_BOTH));
}

From source file:hydrograph.ui.expression.editor.sourceviewer.SourceViewer.java

License:Apache License

private void initializeViewer(IDocument document) {
    fAnnotationPreferences = EditorsPlugin.getDefault().getMarkerAnnotationPreferences();
    setDocument(document);/*from   w  w  w .  j  ava2  s.  c  o  m*/
    installViewerConfiguration();
    setEditable(true);
    Font font = JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT);
    getTextWidget().setFont(font);
    getTextWidget().setData("document", document);
    Control control = getControl();
    GridData data = new GridData(GridData.FILL_BOTH);
    control.setLayoutData(data);
    prependVerifyKeyListener(new VerifyKeyListener() {

        @Override
        public void verifyKey(VerifyEvent event) {
            handleVerifyKeyPressed(event);
        }
    });
    addDocumentListener(document);
}

From source file:io.usethesource.impulse.preferences.fields.FontFieldEditor.java

License:Open Source License

/**
 * Updates the change font button and the previewer to reflect the
 * newly selected font.//w w w. j  a va 2 s.  c om
 * @param font The FontData[] to update with.
 */
private void updateFont(FontData font[]) {
    FontData[] bestFont = JFaceResources.getFontRegistry().filterData(font, valueControl.getDisplay());

    //if we have nothing valid do as best we can
    if (bestFont == null) {
        bestFont = getDefaultFontData();
    }

    //Now cache this value in the receiver
    this.chosenFont = bestFont;

    if (valueControl != null) {
        valueControl.setText(StringConverter.asString(chosenFont[0]));
    }
    if (previewer != null) {
        previewer.setFont(bestFont);
    }
    setInherited(false);
    valueChanged();
}

From source file:it.albertus.eqbulletin.gui.AboutDialog.java

private void createContents(final Shell shell) {
    GridLayoutFactory.swtDefaults().applyTo(shell);

    final LinkSelectionListener linkSelectionListener = new LinkSelectionListener();

    final Link info = new Link(shell, SWT.WRAP);
    final FontRegistry fontRegistry = JFaceResources.getFontRegistry();
    if (!fontRegistry.hasValueFor(SYM_NAME_FONT_DEFAULT)) {
        fontRegistry.put(SYM_NAME_FONT_DEFAULT, info.getFont().getFontData());
    }/*  w  ww  .  j ava2s.co m*/
    info.setFont(fontRegistry.getBold(SYM_NAME_FONT_DEFAULT));
    final Version version = Version.getInstance();
    GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.CENTER).grab(true, false).applyTo(info);
    Date versionDate;
    try {
        versionDate = version.getDate();
    } catch (final Exception e) {
        logger.log(Level.WARNING, e.toString(), e);
        versionDate = new Date();
    }
    info.setText(buildAnchor(Messages.get("url"), Messages.get("msg.application.name")) + ' '
            + Messages.get("msg.version", version.getNumber(),
                    DateFormat.getDateInstance(DateFormat.MEDIUM, Messages.getLanguage().getLocale())
                            .format(versionDate)));
    info.addSelectionListener(linkSelectionListener);

    final Link acknowledgementsLocations = new Link(shell, SWT.WRAP);
    GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.CENTER).grab(true, false)
            .applyTo(acknowledgementsLocations);
    acknowledgementsLocations.setText(Messages.get("lbl.about.acknowledgements.locations",
            buildAnchor(Messages.get("url.geofon"), Messages.get("lbl.geofon")),
            buildAnchor(Messages.get("url.gfz"), Messages.get("lbl.gfz")),
            buildAnchor(Messages.get("url.gevn"), Messages.get("lbl.gevn"))));
    acknowledgementsLocations.addSelectionListener(linkSelectionListener);

    final Label acknowledgementsData = new Label(shell, SWT.WRAP);
    GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.CENTER).grab(true, false).applyTo(acknowledgementsData);
    acknowledgementsData.setText(Messages.get("lbl.about.acknowledgements.data", Messages.get("lbl.geofon"),
            Messages.get("lbl.gfz")));

    final Link linkLicense = new Link(shell, SWT.WRAP);
    GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.CENTER).grab(true, false).applyTo(linkLicense);
    linkLicense.setText(
            Messages.get("lbl.about.license", buildAnchor(Messages.get("url.gpl"), Messages.get("lbl.gpl"))));
    linkLicense.addSelectionListener(linkSelectionListener);

    final Text appLicense = new Text(shell, SWT.BORDER | SWT.V_SCROLL);
    appLicense.setText(loadTextResource("/META-INF/LICENSE.txt"));
    appLicense.setEditable(false);
    appLicense.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER)
            .hint(SWT.DEFAULT, SwtUtils.convertVerticalDLUsToPixels(appLicense, 80)).applyTo(appLicense);

    final Link linkEclipseLicense = new Link(shell, SWT.WRAP);
    GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.CENTER).grab(true, false).applyTo(linkEclipseLicense);
    linkEclipseLicense.setText(Messages.get("lbl.about.license.thirdparty",
            buildAnchor(Messages.get("url.epl"), Messages.get("lbl.epl"))));
    linkEclipseLicense.addSelectionListener(linkSelectionListener);

    final Button okButton = new Button(shell, SWT.PUSH);
    okButton.setText(Messages.get("lbl.button.ok"));
    final int buttonWidth = SwtUtils.convertHorizontalDLUsToPixels(okButton, IDialogConstants.BUTTON_WIDTH);
    GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.CENTER).grab(true, false)
            .minSize(buttonWidth, SWT.DEFAULT).applyTo(okButton);
    okButton.setFocus();
    okButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent se) {
            shell.close();
        }
    });
    shell.setDefaultButton(okButton);
}

From source file:name.schedenig.eclipse.grepconsole.view.items.EditableItemsPanel.java

License:Open Source License

/**
 * Creates the GUI content.//from   w  w  w .  j a v  a  2  s.  co  m
 */
private void init() {
    addDisposeListener(new DisposeListener() {
        @Override
        public void widgetDisposed(DisposeEvent e) {
            colorRegistry.disposeColors();
        }
    });

    headerFont = JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT);// JFaceResources.getHeaderFont();

    colorRegistry = new ColorRegistry(Activator.getDefault().getColorRegistry());
    clipboard = new Clipboard(getDisplay());

    setLayoutData(new GridData(GridData.FILL_BOTH));

    FormLayout layout = new FormLayout();
    setLayout(layout);

    panelTreeAndButtons = new Composite(this, SWT.NONE);
    new GridLayoutBuilder(panelTreeAndButtons, 2, false).setMargins(0).apply();

    treePanel = new ItemsTreePanel(panelTreeAndButtons, SWT.BORDER);
    treePanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 10));
    treePanel.addListener(this);

    hookTreeDragAndDrop();

    Tree tree = treePanel.getTree();

    treeMenu = new Menu(tree);
    treeMenu.addMenuListener(new MenuAdapter() {
        @Override
        public void menuShown(MenuEvent e) {
            refreshMenuItems();
        }
    });

    miCut = new MenuItem(treeMenu, SWT.PUSH);
    miCut.setText(Messages.EditableItemsPanel_cut);

    miCut.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            doCopy(true);
        }
    });

    miCopy = new MenuItem(treeMenu, SWT.PUSH);
    miCopy.setText(Messages.EditableItemsPanel_copy);

    miCopy.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            doCopy(false);
        }
    });

    miPaste = new MenuItem(treeMenu, SWT.PUSH);
    miPaste.setText(Messages.EditableItemsPanel_paste);

    miPaste.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            doPaste();
        }
    });

    tree.setMenu(treeMenu);

    tree.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (e.character == SWT.DEL) {
                doRemove();
                e.doit = false;
            } else if (e.keyCode == SWT.F2) {
                doEdit();
                e.doit = false;
            } else if (e.keyCode == 'c' && (e.stateMask & SWT.MOD1) != 0) {
                doCopy(false);
                e.doit = false;
            } else if (e.keyCode == 'x' && (e.stateMask & SWT.MOD1) != 0) {
                doCopy(true);
                e.doit = false;
            } else if (e.keyCode == 'v' && (e.stateMask & SWT.MOD1) != 0) {
                doPaste();
            }
        }
    });

    btnAddFolder = new Button(panelTreeAndButtons, SWT.PUSH);
    btnAddFolder.setText(Messages.EditableItemsPanel_add_folder);
    btnAddFolder.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));

    btnAddFolder.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            doAddFolder();
        }
    });

    btnAddExpression = new Button(panelTreeAndButtons, SWT.PUSH);
    btnAddExpression.setText(Messages.EditableItemsPanel_add_expression);
    btnAddExpression.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));

    btnAddExpression.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            doAddExpression(null);
        }
    });

    btnEdit = new Button(panelTreeAndButtons, SWT.PUSH);
    btnEdit.setText(Messages.EditableItemsPanel_edit);
    btnEdit.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));

    btnEdit.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            doEdit();
        }
    });

    btnRemove = new Button(panelTreeAndButtons, SWT.PUSH);
    btnRemove.setText(Messages.EditableItemsPanel_remove);
    btnRemove.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));

    btnRemove.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            doRemove();
        }
    });

    btnLoad = new Button(panelTreeAndButtons, SWT.PUSH);
    btnLoad.setText(Messages.EditableItemsPanel_load);
    btnLoad.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));

    btnLoad.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            doLoad();
        }
    });

    btnSaveSelected = new Button(panelTreeAndButtons, SWT.PUSH);
    btnSaveSelected.setText(Messages.EditableItemsPanel_save_selected);
    btnSaveSelected.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));

    btnSaveSelected.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            doSave(false);
        }
    });

    btnSaveAll = new Button(panelTreeAndButtons, SWT.PUSH);
    btnSaveAll.setText(Messages.EditableItemsPanel_save_all);
    btnSaveAll.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));

    btnSaveAll.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            doSave(true);
        }
    });

    sash = new Sash(this, SWT.HORIZONTAL | SWT.SMOOTH);

    labelPreview = new Label(this, SWT.NONE);
    labelPreview.setFont(headerFont);
    labelPreview.setText(Messages.EditableItemsPanel_preview);

    grepLineStyleListener = new GrepLineStyleListener(getShell(), null);
    grepLineStyleListener.setColorRegistry(colorRegistry);

    stPreview = new StyledText(this, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    stPreview.addLineStyleListener(grepLineStyleListener);
    stPreview.setFont(JFaceResources.getTextFont());

    menuPreview = new Menu(stPreview);
    miAddExpressionFromPreview = new MenuItem(menuPreview, SWT.PUSH);
    miAddExpressionFromPreview.setText(Messages.EditableItemsPanel_add_expression);
    miAddExpressionFromPreview.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            doAddExpression(stPreview.getSelectionText());
        }
    });

    miLoadDefault = new MenuItem(menuPreview, SWT.PUSH);
    miLoadDefault.setText(Messages.EditableItemsPanel_load_default);
    miLoadDefault.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            doLoadDefaultPreview();
        }
    });

    miSaveDefault = new MenuItem(menuPreview, SWT.PUSH);
    miSaveDefault.setText(Messages.EditableItemsPanel_save_default);
    miSaveDefault.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            doSaveDefaultPreview();
        }
    });

    new MenuItem(menuPreview, SWT.SEPARATOR);
    new PreviewColorHandler(stPreview, menuPreview);

    menuPreview.addMenuListener(new MenuAdapter() {
        @Override
        public void menuShown(MenuEvent e) {
            Set<AbstractGrepModelElement> selection = treePanel.getSelectedElements();
            boolean hasSelection = selection != null && !selection.isEmpty();

            String text = stPreview.getSelectionText();
            miAddExpressionFromPreview.setEnabled(hasSelection && text != null && text.length() > 0);

            super.menuShown(e);
        }
    });

    stPreview.setMenu(menuPreview);

    int preferredPreviewHeight = ((getDisplay().getDPI().y
            * JFaceResources.getTextFont().getFontData()[0].getHeight()) / 72) * 4;

    FormData fd = new FormData();
    fd.top = new FormAttachment(0, 0);
    fd.bottom = new FormAttachment(sash, 0);
    fd.left = new FormAttachment(0, 0);
    fd.right = new FormAttachment(100, 0);
    panelTreeAndButtons.setLayoutData(fd);

    fd = new FormData();
    fd.bottom = new FormAttachment(100, -sash.computeSize(SWT.DEFAULT, SWT.DEFAULT).y - preferredPreviewHeight);
    fd.left = new FormAttachment(0, 0);
    fd.right = new FormAttachment(100, 0);
    sash.setLayoutData(fd);

    fd = new FormData();
    fd.top = new FormAttachment(sash, 5);
    fd.left = new FormAttachment(0, 0);
    fd.right = new FormAttachment(100, 0);
    //fd.bottom = new FormAttachment(100, 0);
    labelPreview.setLayoutData(fd);

    fd = new FormData();
    fd.top = new FormAttachment(labelPreview, 0);
    fd.left = new FormAttachment(0, 0);
    fd.right = new FormAttachment(100, 0);
    fd.bottom = new FormAttachment(100, 0);
    stPreview.setLayoutData(fd);

    sash.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            Rectangle sashBounds = sash.getBounds();
            Rectangle clientArea = getClientArea();

            setSashPosition(-(clientArea.height - sashBounds.height - e.y));
        }
    });

    addControlListener(new ControlAdapter() {
        @Override
        public void controlResized(ControlEvent e) {
            int height = getSize().y;
            FormData fd = (FormData) sash.getLayoutData();

            int min = -height + 50;

            if (min > 0) {
                min = 0;
            }

            if (fd.bottom.offset <= min) {
                setSashPosition(min);
            }
        }
    });

    if (sashPosition != null) {
        setSashPosition(sashPosition);
    }

    refreshButtons();

    if (previewText == null || previewText.trim().length() == 0) {
        stPreview.setText(Activator.getDefault().getPreviewText());
    } else {
        stPreview.setText(previewText);
    }
}

From source file:name.schedenig.eclipse.grepconsole.view.items.ExpressionDialog.java

License:Open Source License

/**
 * @see org.eclipse.jface.dialogs.Dialog#createContents(org.eclipse.swt.widgets.Composite)
 *//* w  w w.  j a  va2s  .c  om*/
@Override
protected Control createDialogArea(Composite parent) {
    headerFont = JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT);

    parent.addDisposeListener(new DisposeListener() {
        @Override
        public void widgetDisposed(DisposeEvent e) {
            if (colorRegistry != null) {
                colorRegistry.disposeColors();
            }
        }
    });

    PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, Activator.PLUGIN_ID + ".edit_expression"); //$NON-NLS-1$

    colorRegistry = new ColorRegistry(Activator.getDefault().getColorRegistry());
    clipboard = new Clipboard(parent.getDisplay());

    Composite composite = parent;
    new GridLayoutBuilder(composite, 1, false).apply();

    panelHeader = createHeaderPanel(composite);
    panelHeader.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));

    tabs = new TabFolder(composite, SWT.TOP);
    tabs.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    tiGeneral = new TabItem(tabs, SWT.NONE);
    tiGeneral.setText(Messages.ExpressionDialog_general);

    panelGeneral = createGeneralPanel(tabs);
    tiGeneral.setControl(panelGeneral);

    tiStyles = new TabItem(tabs, SWT.NONE);
    tiStyles.setText(Messages.ExpressionDialog_styles_links);

    tiGrepView = new TabItem(tabs, SWT.NONE);
    tiGrepView.setText(Messages.ExpressionDialog_grep_view);

    panelGrepView = createGrepViewPanel(tabs);
    tiGrepView.setControl(panelGrepView);

    tiNotifications = new TabItem(tabs, SWT.NONE);
    tiNotifications.setText(Messages.ExpressionDialog_notifications_tab);

    panelNotifications = createNotificationsPanel(tabs);
    tiNotifications.setControl(panelNotifications);

    tiStatistics = new TabItem(tabs, SWT.NONE);
    tiStatistics.setText(Messages.ExpressionDialog_statistics_tab);

    panelStatistics = createStatisticsPanel(tabs);
    tiStatistics.setControl(panelStatistics);

    panelStyleTables = new SashForm(tabs, SWT.HORIZONTAL);
    panelStyleTables.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    tiStyles.setControl(panelStyleTables);

    panelStyleAssignments = new Composite(panelStyleTables, SWT.NONE);
    panelStyleAssignments.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    GridLayoutBuilder builder = new GridLayoutBuilder(panelStyleAssignments, 3, false).setMarginRight(0);
    builder.apply();
    GridLayout panelStyleAssignmentsLayout = builder.getLayout();

    panelStyleTables.setSashWidth(((GridLayout) panelStyleAssignments.getLayout()).marginLeft);

    tableStyleAssignments = new Table(panelStyleAssignments, SWT.BORDER | SWT.FULL_SELECTION);
    tableStyleAssignments.setHeaderVisible(true);
    tableStyleAssignments.setLinesVisible(false);
    tableStyleAssignments.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
    viewerStyleAssignments = new TableViewer(tableStyleAssignments);
    viewerStyleAssignments.setContentProvider(new StyleAssignmentsContentProvider());

    groupLabelProvider = new StyleAssignmentsGroupLabelProvider(viewerStyleAssignments);

    colGroup = new TableViewerColumn(viewerStyleAssignments, SWT.LEFT);
    colGroup.getColumn().setText(Messages.ExpressionDialog_column_group);
    colGroup.getColumn().setWidth(130);
    colGroup.setLabelProvider(groupLabelProvider);

    colStyle = new TableViewerColumn(viewerStyleAssignments, SWT.LEFT);
    colStyle.getColumn().setText(Messages.ExpressionDialog_column_style);
    colStyle.getColumn().setWidth(130);
    colStyle.setLabelProvider(new StyleAssignmentsStyleLabelProvider(viewerStyleAssignments));

    colLink = new TableViewerColumn(viewerStyleAssignments, SWT.RIGHT);
    colLink.getColumn().setText(Messages.ExpressionDialog_link);
    colLink.getColumn().setWidth(70);
    colLink.setLabelProvider(new StyleAssignmentsLinkLabelProvider(viewerStyleAssignments));

    ColumnViewerToolTipSupport.enableFor(viewerStyleAssignments);

    menuGroups = new Menu(tableStyleAssignments);

    miCopyLink = new MenuItem(menuGroups, SWT.PUSH);
    miCopyLink.setText(Messages.ExpressionDialog_copy_link);
    miCopyLink.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            copyLink();
        }
    });

    miPasteLink = new MenuItem(menuGroups, SWT.PUSH);
    miPasteLink.setText(Messages.ExpressionDialog_paste_link);
    miPasteLink.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            pasteLink();
        }
    });

    menuGroups.addMenuListener(new MenuAdapter() {
        @Override
        public void menuShown(MenuEvent e) {
            Integer group = getSelectedGroup((IStructuredSelection) viewerStyleAssignments.getSelection());

            miCopyLink.setEnabled(group != null && getGroup(group).getLink() != null);
            miPasteLink.setEnabled(group != null);
        }
    });

    tableStyleAssignments.setMenu(menuGroups);

    viewerStyleAssignments.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            groupSelected(getSelectedGroup((IStructuredSelection) event.getSelection()));
        }
    });

    TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(viewerStyleAssignments,
            new FocusCellOwnerDrawHighlighter(viewerStyleAssignments));

    ColumnViewerEditorActivationStrategy activationSupport = new ColumnViewerEditorActivationStrategy(
            viewerStyleAssignments) {
        protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
            // Enable editor only with mouse double click
            if (event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION) {
                EventObject source = event.sourceEvent;

                if (source instanceof MouseEvent && ((MouseEvent) source).button == 3) {
                    return false;
                }

                return true;
            }

            return false;
        }
    };

    TableViewerEditor.create(viewerStyleAssignments, focusCellManager, activationSupport,
            ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
                    | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION);

    EditingSupport nameEditingSupport = new EditingSupport(viewerStyleAssignments) {
        @Override
        protected void setValue(Object element, Object value) {
            String s = ((String) value).trim();

            if (s.length() == 0) {
                s = null;
            }

            getGroup((Integer) element).setName(s);
            viewerStyleAssignments.refresh(element);
            updateDuplicateGroupNames();
        }

        @Override
        protected Object getValue(Object element) {
            GrepGroup group = getGroup((Integer) element);
            return group.getName() == null ? "" : group.getName(); //$NON-NLS-1$
        }

        @Override
        protected CellEditor getCellEditor(Object element) {
            return new TextCellEditor(viewerStyleAssignments.getTable());
        }

        @Override
        protected boolean canEdit(Object element) {
            return true;
        }
    };

    colGroup.setEditingSupport(nameEditingSupport);

    DoubleClickEditingSupport styleEditingSupport = new DoubleClickEditingSupport(viewerStyleAssignments) {
        @Override
        protected void doEdit(Object value) {
            Integer group = getSelectedGroup((IStructuredSelection) viewerStyleAssignments.getSelection());
            final GrepStyle style = getGroup(group).getStyle();

            getShell().getDisplay().asyncExec(new Runnable() {
                public void run() {
                    if (style == null) {
                        panelAvailableStyles.doNewStyle();
                    } else {
                        panelAvailableStyles.doEditStyle(style);
                    }
                }
            });
        }
    };

    colStyle.setEditingSupport(styleEditingSupport);

    colLink.setEditingSupport(new DoubleClickEditingSupport(viewerStyleAssignments) {
        @Override
        protected void doEdit(Object value) {
            final Integer groupIndex = getSelectedGroup(
                    (IStructuredSelection) viewerStyleAssignments.getSelection());
            final GrepGroup group = getGroup(groupIndex);

            getShell().getDisplay().asyncExec(new Runnable() {
                public void run() {
                    LinkDialog dlg = new LinkDialog(getShell(), groupIndex < workItem.getGroups().length);
                    dlg.setLink(group.getLink());

                    if (dlg.open() == LinkDialog.OK) {
                        group.setLink(dlg.getLink());
                        viewerStyleAssignments.refresh();
                    }
                }
            });
        }
    });

    cbRemoveOriginalStyle = new Button(panelStyleAssignments, SWT.CHECK);
    cbRemoveOriginalStyle.setText(Messages.ExpressionDialog_remove_original_style);
    cbRemoveOriginalStyle.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 3, 1));

    cbRemoveOriginalStyle.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            workItem.setRemoveOriginalStyle(cbRemoveOriginalStyle.getSelection());
            refreshPreview();
        }
    });

    grepLineStyleListener = new GrepLineStyleListener(getShell(), null);
    grepLineStyleListener.setColorRegistry(colorRegistry);

    labelPreview = new Label(panelStyleAssignments, SWT.NONE);
    labelPreview.setFont(headerFont);
    labelPreview.setText(Messages.ExpressionDialog_preview);
    GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1);
    gridData.verticalIndent = 10;
    labelPreview.setLayoutData(gridData);

    stPreview = new StyledText(panelStyleAssignments, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1);
    gd.heightHint = ((parent.getDisplay().getDPI().y
            * JFaceResources.getTextFont().getFontData()[0].getHeight()) / 72) * 4;
    stPreview.setLayoutData(gd);
    stPreview.addLineStyleListener(grepLineStyleListener);
    stPreview.setFont(JFaceResources.getTextFont());

    menuPreview = new Menu(stPreview);
    miAddExpressionFromPreview = new MenuItem(menuPreview, SWT.PUSH);
    miAddExpressionFromPreview.setText(Messages.ExpressionDialog_use_as_expression);
    miAddExpressionFromPreview.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            setExpression(stPreview.getSelectionText());
        }
    });

    miAddUnlessExpressionFromPreview = new MenuItem(menuPreview, SWT.PUSH);
    miAddUnlessExpressionFromPreview.setText(Messages.ExpressionDialog_use_as_unless_expression);
    miAddUnlessExpressionFromPreview.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            setUnlessExpression(stPreview.getSelectionText());
        }
    });

    miLoadDefault = new MenuItem(menuPreview, SWT.PUSH);
    miLoadDefault.setText(Messages.ExpressionDialog_load_default);
    miLoadDefault.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            doLoadDefaultPreview();
        }
    });

    miSaveDefault = new MenuItem(menuPreview, SWT.PUSH);
    miSaveDefault.setText(Messages.ExpressionDialog_save_default);
    miSaveDefault.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            doSaveDefaultPreview();
        }
    });

    menuPreview.addMenuListener(new MenuAdapter() {
        @Override
        public void menuShown(MenuEvent e) {
            String text = stPreview.getSelectionText();
            miAddExpressionFromPreview.setEnabled(text != null && text.length() > 0);

            super.menuShown(e);
        }
    });

    new MenuItem(menuPreview, SWT.SEPARATOR);
    new PreviewColorHandler(stPreview, menuPreview);

    stPreview.setMenu(menuPreview);

    panelAvailableStyles = new StylesPanel(panelStyleTables, SWT.NONE) {
        @Override
        protected void doStylesSelected(Collection<GrepStyle> styles) {
            btnAssignStyle.setEnabled(styles.size() == 1);

            super.doStylesSelected(styles);
        }

        protected void createButtons(Composite parent) {
            btnAssignStyle = new Button(parent, SWT.PUSH);
            btnAssignStyle.setText(Messages.ExpressionDialog_assign);
            btnAssignStyle.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    doAssignStyle(panelAvailableStyles.getSelectedStyle());
                }
            });

            super.createButtons(parent);
        };
    };

    GridLayout panelAvailableStylesLayout = (GridLayout) panelAvailableStyles.getLayout();
    panelAvailableStylesLayout.marginLeft = panelStyleAssignmentsLayout.marginRight;
    panelAvailableStylesLayout.marginRight = panelStyleAssignmentsLayout.marginLeft;
    panelAvailableStylesLayout.marginWidth = panelStyleAssignmentsLayout.marginWidth;
    panelAvailableStylesLayout.marginHeight = panelStyleAssignmentsLayout.marginHeight;
    panelAvailableStylesLayout.marginTop = panelStyleAssignmentsLayout.marginTop;
    panelAvailableStylesLayout.marginBottom = panelStyleAssignmentsLayout.marginBottom;

    panelAvailableStyles.setIncludeNullStyle(true);
    panelAvailableStyles.addListener(this);

    if (workItem != null) {
        panelAvailableStyles.setRoot(workItem.getRoot());
    }

    textExpression.setFocus();

    return composite;
}