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

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

Introduction

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

Prototype

public static Font getTextFont() 

Source Link

Document

Returns JFace's text font.

Usage

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)
 *///from   ww w. ja va2  s.  com
@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;
}

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

License:Open Source License

/**
 * @see name.schedenig.eclipse.grepconsole.view.items.links.LinkPanel#init()
 *///w  w  w  . j  a v  a2  s . co  m
@Override
protected void init() {
    super.init();

    new GridLayoutBuilder(this, 2, false).setMargins(0).apply();

    labelLanguage = new Label(this, SWT.NONE);
    labelLanguage.setText(Messages.ScriptLinkPanel_language);
    labelLanguage.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));

    comboLanguage = new Combo(this, SWT.DROP_DOWN);// new Text(this, SWT.NONE);
    comboLanguage.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));

    comboLanguage.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            ((ScriptLink) getLink()).setLanguage(comboLanguage.getText());
        }
    });

    labelCode = new Label(this, SWT.NONE);
    labelCode.setText(Messages.ScriptLinkPanel_code);
    labelCode.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 2, 1));

    textCode = new Text(this, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    textCode.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    textCode.setFont(JFaceResources.getTextFont());
    textCode.setToolTipText(Messages.ScriptLinkPanel_parameters_tooltip);

    textCode.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            ((ScriptLink) getLink()).setCode(textCode.getText());
        }
    });

    ScriptEngineManager factory = new ScriptEngineManager();

    for (ScriptEngineFactory f : factory.getEngineFactories()) {
        for (String s : f.getNames()) {
            comboLanguage.add(s);
        }
    }
}

From source file:name.schedenig.eclipse.grepconsole.view.styles.StylePanel.java

License:Open Source License

/**
 * Initialises the GUI.//  w ww  . j a  va 2  s. c o  m
 */
private void init() {
    headerFont = JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT);
    colorRegistry = new ColorRegistry(Activator.getDefault().getColorRegistry());

    new GridLayoutBuilder(this, 3, false).apply();

    labelName = new Label(this, SWT.NONE);
    labelName.setText(Messages.StylePanel_name);
    labelName.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));

    textName = new Text(this, SWT.BORDER);
    textName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));

    panelCheckboxes = new Composite(this, SWT.NONE);
    RowLayout panelCheckboxesLayout = new RowLayout();
    panelCheckboxesLayout.marginWidth = panelCheckboxesLayout.marginHeight = 0;
    panelCheckboxesLayout.marginLeft = panelCheckboxesLayout.marginRight = 0;
    panelCheckboxesLayout.marginTop = panelCheckboxesLayout.marginBottom = 0;

    panelCheckboxes.setLayout(panelCheckboxesLayout);
    panelCheckboxes.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 3, 1));

    cbBold = new Button(panelCheckboxes, SWT.CHECK);
    cbBold.setText(Messages.StylePanel_bold);
    cbBold.addSelectionListener(selectionListener);

    cbItalic = new Button(panelCheckboxes, SWT.CHECK);
    cbItalic.setText(Messages.StylePanel_italic);
    cbItalic.addSelectionListener(selectionListener);

    cpForeground = new ColorPickerLine(this);
    cpForeground.setText(Messages.StylePanel_foreground);
    cpForeground.setDialogTitle(Messages.StylePanel_title_foreground);
    cpForeground.addListener(colorChangeListener);

    cpBackground = new ColorPickerLine(this);
    cpBackground.setText(Messages.StylePanel_background);
    cpBackground.setDialogTitle(Messages.StylePanel_title_background);
    cpBackground.addListener(colorChangeListener);

    cpUnderline = new ColorPickerLine(this);
    cpUnderline.setText(Messages.StylePanel_underline);
    cpUnderline.setDialogTitle(Messages.StylePanel_title_underline);
    cpUnderline.setColorMandatory(false);
    cpUnderline.addListener(colorChangeListener);

    cpStrikethrough = new ColorPickerLine(this);
    cpStrikethrough.setText(Messages.StylePanel_strikethrough);
    cpStrikethrough.setDialogTitle(Messages.StylePanel_title_strikethrough);
    cpStrikethrough.setColorMandatory(false);
    cpStrikethrough.addListener(colorChangeListener);

    cpBorder = new ColorPickerLine(this);
    cpBorder.setText(Messages.StylePanel_border);
    cpBorder.setDialogTitle(Messages.StylePanel_title_border);
    cpBorder.setColorMandatory(false);
    cpBorder.addListener(colorChangeListener);

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

    final String unstyledText = Messages.StylePanel_unstyled_preview;
    final String styledText = Messages.StylePanel_styled_preview;

    stPreview = new StyledText(this, SWT.BORDER);
    stPreview.setText(unstyledText + "\n" + styledText + "\n" + unstyledText); //$NON-NLS-1$ //$NON-NLS-2$
    stPreview.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true, 3, 1));
    stPreview.setFont(JFaceResources.getTextFont());
    stPreview.setEditable(false);

    new PreviewColorHandler(stPreview);

    stPreview.addLineStyleListener(new LineStyleListener() {
        @Override
        public void lineGetStyle(LineStyleEvent event) {
            if (event.lineOffset == unstyledText.length() + 1) {
                StyleRange style = new StyleRange();
                style.start = event.lineOffset;
                style.length = event.lineText.length();
                fillStyleRange(style);
                event.styles = new StyleRange[] { style };
            }
        }
    });

    refresh();
}

From source file:name.schedenig.eclipse.grepconsole.view.styles.StylesPanel.java

License:Open Source License

/**
 * Initialises the GUI./* w  w w. j  av  a  2  s. c  o  m*/
 */
protected void init() {
    addDisposeListener(new DisposeListener() {
        @Override
        public void widgetDisposed(DisposeEvent e) {
            onDispose();
        }
    });

    colorRegistry = new ColorRegistry(Activator.getDefault().getColorRegistry());

    new GridLayoutBuilder(this, 1, true).setMargins(0).apply();

    table = new Table(this, SWT.BORDER | SWT.MULTI);
    table.setHeaderVisible(true);
    table.setLinesVisible(false);
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1));

    viewer = new TableViewer(table);
    viewer.setContentProvider(new StyleContentProvider(false));
    viewer.setComparator(new StyleComparator());

    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            doStylesSelected(getSelectedStyles());
        }
    });

    viewer.addDoubleClickListener(new IDoubleClickListener() {
        @Override
        public void doubleClick(DoubleClickEvent event) {
            doStyleDoubleClicked(getSelectedStyle((IStructuredSelection) event.getSelection()));
        }
    });

    TableViewerColumn colAvailableStyle = new TableViewerColumn(viewer, SWT.LEFT);
    colAvailableStyle.getColumn().setText(Messages.StylesPanel_available_styles);
    colAvailableStyle.getColumn().setWidth(150);
    colAvailableStyle.setLabelProvider(new StyleLabelProvider(viewer));

    table.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (e.character == SWT.DEL) {
                doDeleteStyles();
                e.doit = false;
            } else if (e.keyCode == SWT.F2) {
                doEditStyle();
                e.doit = false;
            }
        }
    });

    stPreview = new StyledText(this, SWT.BORDER);
    stPreview.setText(Messages.StylesPanel_style_preview);
    stPreview.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 4, 1));
    stPreview.setFont(JFaceResources.getTextFont());

    new PreviewColorHandler(stPreview);

    stPreview.addLineStyleListener(new LineStyleListener() {
        @Override
        public void lineGetStyle(LineStyleEvent event) {
            GrepStyle grepStyle = getSelectedStyle();

            if (grepStyle != null) {
                StyleRange style = new StyleRange();
                style.start = event.lineOffset;
                style.length = event.lineText.length();
                fillStyleRange(style, grepStyle);
                event.styles = new StyleRange[] { style };
            }
        }
    });

    ColumnViewerToolTipSupport.enableFor(viewer);

    panelButtons = new Composite(this, SWT.NONE);
    panelButtons.setLayout(new FillLayout(SWT.HORIZONTAL));
    panelButtons.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));

    createButtons(panelButtons);

    if (root != null) {
        viewer.setInput(root);
    }
}

From source file:net.bioclipse.scripting.ui.views.ScriptingConsoleView.java

License:Open Source License

/**
 * This is a callback that will allow us to create the view and
 * initialize it./*w ww.j a va 2  s.co m*/
 */
public void createPartControl(Composite parent) {
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    parent.setLayout(layout);

    output = new Text(parent, SWT.READ_ONLY | SWT.MULTI | SWT.V_SCROLL | SWT.BORDER | SWT.WRAP);
    output.setFont(JFaceResources.getTextFont());
    GridData outputData = new GridData(GridData.FILL_BOTH);
    output.setBackground(new Color(parent.getDisplay(), 0xFF, 0xFF, 0xFF));
    output.setLayoutData(outputData);
    output.addKeyListener(new KeyListener() {
        public void keyPressed(KeyEvent e) {
            if (e.character != '\0' && e.stateMask == 0) {
                e.doit = false;
                input.setText(input.getText() + e.character);
                input.setSelection(input.getText().length());
                input.setFocus();
            } else if (actionTable.containsKey(e.keyCode)) {
                input.setFocus();
                handleKey(e);
            }
            // "Paste" forwarding.
            // SWT.MOD1 is Ctrl or Command as appropriate based on the
            // platform. That funny '&' is a bitop. See the JLS.
            else if ((Character.toLowerCase(e.character) == 'v' || e.keyCode == 'v')
                    && (e.stateMask & SWT.MOD1) != 0) {
                input.setFocus();
                input.paste();
            } else if (Character.toLowerCase(e.character) == 'c' && (e.stateMask & SWT.MOD1) != 0) {
                // We'll want to let this one pass through, so that
                // the output can do copying as it should.
                // Added because of #1076, shk3++.
            }
        }

        public void keyReleased(KeyEvent _) {
        }
    });

    input = new Text(parent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
    input.setFont(JFaceResources.getTextFont());
    input.addKeyListener(new KeyListener() {
        public void keyPressed(KeyEvent e) {
            handleKey(e);
            if (e.keyCode == SWT.TAB) {
                e.doit = false;
                tabComplete();
            }
        }

        public void keyReleased(KeyEvent _) {
        }
    });
    input.addTraverseListener(new TraverseListener() {
        public void keyTraversed(TraverseEvent e) {
            if (e.detail == SWT.TRAVERSE_TAB_NEXT) {
                e.doit = false;
            }
        }
    });
    GridData inputData = new GridData(GridData.FILL_HORIZONTAL);
    inputData.heightHint = 20;
    input.setLayoutData(inputData);

    hookContextMenu();
    enableResourceDropSupport();
}

From source file:net.bioclipse.scripting.ui.views.ScriptingConsoleView.java

License:Open Source License

/**
 * Prints a piece of text to the console. The text ends up before the
 * active command line./*from  w  w  w.  j av a2 s .  c o m*/
 * 
 * @param message the text to be printed
 */
public void printMessage(String message) {

    if (message == null)
        return;

    // Non-printable characters are removed because people have complained
    // of seeing them. See http://en.wikipedia.org/wiki/Robustness_Principle
    // for more information. Also, feel free to add other disturbing non-
    // printables here.
    message = message.replaceAll("\u0008", "");
    // R has a tendency to output newlines as "\r\n". Bringing those in line
    // here. If you read the below code and think that it could be
    // shortened to one call, you're probably not taking R's chunking into
    // account.
    message = message.replaceAll("\r", "");
    message = message.replaceAll("\n", NEWLINE);

    final String printme = message;

    Display.getDefault().asyncExec(new Runnable() {
        public void run() {
            synchronized (output) {
                if (output.isDisposed())
                    return;
                output.append(printme);
                output.setFont(JFaceResources.getTextFont());
                output.redraw();
            }
        }
    });
}

From source file:net.mldonkey.g2gui.view.pref.PreferenceLoader.java

License:Open Source License

/**
 * @param preferenceStore//from w ww  . j av a  2 s . c om
 * @return
 */
static IPreferenceStore setDefaults( IPreferenceStore preferenceStore ) {
    Display display = Display.getDefault();
    preferenceStore.setDefault( "initialized", false );
    preferenceStore.setDefault( "windowMaximized", false );
    preferenceStore.setDefault( "coolbarLocked", true );
    preferenceStore.setDefault( "toolbarSmallButtons", false );
    preferenceStore.setDefault( "flatInterface", false );
    preferenceStore.setDefault( "useGraident", true );
    preferenceStore.setDefault( "allClients", false);
    preferenceStore.setDefault( "splashScreen", true );
        
    PreferenceConverter.setDefault( preferenceStore, "windowBounds", new Rectangle(0,0,640,480) );
        
    PreferenceConverter.setDefault( preferenceStore, "consoleBackground",
                                    display.getSystemColor( SWT.COLOR_LIST_BACKGROUND ).getRGB() );
    PreferenceConverter.setDefault( preferenceStore, "consoleForeground",
                                    display.getSystemColor( SWT.COLOR_LIST_FOREGROUND ).getRGB() );
    PreferenceConverter.setDefault( preferenceStore, "consoleHighlight",
                                    display.getSystemColor( SWT.COLOR_LIST_SELECTION ).getRGB() );
    PreferenceConverter.setDefault( preferenceStore, "consoleInputBackground",
                                    display.getSystemColor( SWT.COLOR_LIST_BACKGROUND ).getRGB() );
    PreferenceConverter.setDefault( preferenceStore, "consoleInputForeground",
                                    display.getSystemColor( SWT.COLOR_LIST_FOREGROUND ).getRGB() );
    PreferenceConverter.setDefault( preferenceStore, "consoleFontData",
                                    JFaceResources.getTextFont().getFontData() );
             
  PreferenceConverter.setDefault( preferenceStore, "downloadsBackgroundColor", display.getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB() );               
    PreferenceConverter.setDefault( preferenceStore, "downloadsAvailableFileColor", display.getSystemColor( SWT.COLOR_BLACK ).getRGB() );
  PreferenceConverter.setDefault( preferenceStore, "downloadsUnAvailableFileColor", new RGB(128,128,128) );
  PreferenceConverter.setDefault( preferenceStore, "downloadsDownloadedFileColor", display.getSystemColor( SWT.COLOR_BLUE ).getRGB() );
  PreferenceConverter.setDefault( preferenceStore, "downloadsQueuedFileColor", display.getSystemColor( SWT.COLOR_GRAY ).getRGB() );
  PreferenceConverter.setDefault( preferenceStore, "downloadsPausedFileColor", display.getSystemColor( SWT.COLOR_DARK_RED ).getRGB() );
  PreferenceConverter.setDefault( preferenceStore, "downloadsRateAbove20FileColor", new RGB(0,160,0) );
  PreferenceConverter.setDefault( preferenceStore, "downloadsRateAbove10FileColor", new RGB(0,140,0) );
  PreferenceConverter.setDefault( preferenceStore, "downloadsRateAbove0FileColor", new RGB(0,110,0) );
               
  PreferenceConverter.setDefault( preferenceStore, "graphUploadsColor1", display.getSystemColor( SWT.COLOR_BLUE ).getRGB() );
  PreferenceConverter.setDefault( preferenceStore, "graphUploadsColor2", new RGB(0,0,125) );
  PreferenceConverter.setDefault( preferenceStore, "graphDownloadsColor1", display.getSystemColor( SWT.COLOR_GREEN ).getRGB() );
  PreferenceConverter.setDefault( preferenceStore, "graphDownloadsColor2", new RGB(0,125,0) );
  PreferenceConverter.setDefault( preferenceStore, "graphBackgroundColor", display.getSystemColor( SWT.COLOR_BLACK ).getRGB() );
  PreferenceConverter.setDefault( preferenceStore, "graphGridColor", new RGB(0,128,64) );
  PreferenceConverter.setDefault( preferenceStore, "graphTextColor", display.getSystemColor( SWT.COLOR_WHITE ).getRGB() );
  PreferenceConverter.setDefault( preferenceStore, "graphLabelBackgroundColor", display.getSystemColor( SWT.COLOR_WHITE ).getRGB() );
  PreferenceConverter.setDefault( preferenceStore, "graphLabelLineColor", display.getSystemColor( SWT.COLOR_YELLOW ).getRGB() );
  PreferenceConverter.setDefault( preferenceStore, "graphLabelTextColor", display.getSystemColor( SWT.COLOR_BLACK ).getRGB() );
            
      
  preferenceStore.setDefault( "defaultWebBrowser", "");
    preferenceStore.setDefault( "hostname", "localhost" );
    preferenceStore.setDefault( "username", "admin" );
    preferenceStore.setDefault( "password", "" );
    preferenceStore.setDefault( "port", "4001" );
    preferenceStore.setDefault( "advancedMode", false );
    preferenceStore.setDefault( "searchFilterPornography", false );
    preferenceStore.setDefault( "searchFilterProfanity", false );
    preferenceStore.setDefault( "maintainSortOrder", false );
    preferenceStore.setDefault( "updateDelay", 0 );
    preferenceStore.setDefault( "useGradient", true );
    preferenceStore.setDefault( "displayNodes", false );
    preferenceStore.setDefault( "displayChunkGraphs", false );
    preferenceStore.setDefault( "displayGridLines", true );
    preferenceStore.setDefault( "tableCellEditors", false );
    preferenceStore.setDefault( "displayTableColors" , true );
    preferenceStore.setDefault( "displayFontAA" , false );
    preferenceStore.setDefault( "coreExecutable", "" );
    preferenceStore.setDefault( "useCombo", false );
    preferenceStore.setDefault( "minimizeOnClose", false );
    preferenceStore.setDefault( "dragAndDrop", true );
    preferenceStore.setDefault( "pollUpStats", true );
  preferenceStore.setDefault( "running", false );
  preferenceStore.setDefault( "allowMultipleInstances", false );
  preferenceStore.setDefault( "downloadsFilterQueued", false );
  preferenceStore.setDefault( "downloadsFilterPaused", false );
      
  preferenceStore.setDefault( "graphSashOrientation", SWT.HORIZONTAL );
  preferenceStore.setDefault( "graphSashMaximized", -1 );
      
  preferenceStore.setDefault( "clientSashOrientation", SWT.HORIZONTAL );
  preferenceStore.setDefault( "clientSashMaximized", 0 );
      
  preferenceStore.setDefault( "transferSashOrientation", SWT.VERTICAL );
  preferenceStore.setDefault( "transferSashMaximized", -1 );
      
  preferenceStore.setDefault( "uploadsSashOrientation", SWT.HORIZONTAL );
  preferenceStore.setDefault( "uploadsSashMaximized", -1 );
      
  PreferenceConverter.setDefault( preferenceStore, "viewerFontData", JFaceResources.getDefaultFont().getFontData() );     
      
  preferenceStore.setDefault( G2GuiResources.getString( "ENS_NOT_CONNECTED" ), false );      
  preferenceStore.setDefault( G2GuiResources.getString( "ENS_CONNECTING" ), false );      
  preferenceStore.setDefault( G2GuiResources.getString( "ENS_CONNECTED_INITIATING" ), false );      
  preferenceStore.setDefault( G2GuiResources.getString( "ENS_CONNECTED_DOWNLOADING" ), false );      
  preferenceStore.setDefault( G2GuiResources.getString( "ENS_CONNECTED" ), false );      
  preferenceStore.setDefault( G2GuiResources.getString( "ENS_CONNECTED_AND_QUEUED" ), false );      
  preferenceStore.setDefault( G2GuiResources.getString( "ENS_NEW_HOST" ), false );      
  preferenceStore.setDefault( G2GuiResources.getString( "ENS_REMOVE_HOST" ), false );      
  preferenceStore.setDefault( G2GuiResources.getString( "ENS_BLACK_LISTED" ), false );      
  preferenceStore.setDefault( G2GuiResources.getString( "ENS_NOT_CONNECTED_WAS_QUEUED" ), false );      
      
  // set the default filter for server tab to connected, connecting and connection initiated
  preferenceStore.setDefault( Enum.getPrefName( EnumState.CONNECTED, ServerPaneListener.class ), true );
  preferenceStore.setDefault( Enum.getPrefName( EnumState.CONNECTING, ServerPaneListener.class ), true );
  preferenceStore.setDefault( Enum.getPrefName( EnumState.CONNECTED_INITIATING, ServerPaneListener.class ), true );

  preferenceStore.setDefault( "searchSashWeights", "1,5" );

  preferenceStore.setDefault( "UploadersPaneListenerBestFit", "-1" );
  preferenceStore.setDefault( "ClientPaneListenerBestFit", "-1" );
  preferenceStore.setDefault( "UploadPaneListenerBestFit", "-1" );
  preferenceStore.setDefault( "DownloadPaneListenerBestFit", "-1" );
  preferenceStore.setDefault( "ServerPaneListenerBestFit", "-1" );
      
  // we want this in the g2gui.pref file without a frontend in the gui
  preferenceStore.setDefault( "WEBSERVICE.URL.BITZI", "http://bitzi.com/lookup/" );
  preferenceStore.setDefault( "WEBSERVICE.URL.FILEDONKEY", "http://www.filedonkey.com/file.html?md4=" );
  preferenceStore.setDefault( "WEBSERVICE.URL.DONKEYFAKES", "http://donkeyfakes.gambri.net/index.php?action=search&ed2k=" );
      
    return preferenceStore;
}

From source file:net.mldonkey.g2gui.view.search.LiquidToolTip.java

License:Open Source License

public void create(Event e) {
    ResultInfo aResult = getResult(e);//from   w  ww.j  a v a2s. c  o  m
    if (aResult == null)
        return;

    shell = new Shell(parent.getShell(), SWT.ON_TOP);
    shell.setLayout(WidgetFactory.createGridLayout(1, 2, 2, 0, 0, false));
    shell.setBackground(backGround);

    this.title = createCLabel(shell);
    this.title.setImage(aResult.getToolTipImage());
    this.title.setText(aResult.getName());

    createSeparator(shell);

    this.details = createLabel(shell);
    this.details.setText(aResult.getToolTipString());

    if (aResult.getNames().length > 1) {
        this.altNames = createLabel(shell);
        ((Label) this.altNames).setText(aResult.getSortedNamesPreview());
    }

    createSeparator(shell);

    Label aLabel = createLabel(shell);
    aLabel.setFont(JFaceResources.getTextFont());
    aLabel.setText("Press F2 for focus");

    setupShell(e);

    // we need focus on the parent to listen for "F2"
    parent.forceFocus();
}

From source file:net.mldonkey.g2gui.view.search.Search.java

License:Open Source License

/**
 * Creates a blank input field for search strings
 * @param group The Group to display the box in
 * @param aString The Box header//from w  w  w .  java2  s.  com
 */
protected Combo createInputBox(Composite group, String aString) {
    /* the box label */
    GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    Label label = new Label(group, SWT.NONE);
    label.setLayoutData(gridData);
    label.setText(aString);

    /* the box */
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    Combo combo = new MyCombo(group, SWT.SINGLE | SWT.BORDER);
    combo.setLayoutData(gridData);
    combo.setFont(JFaceResources.getTextFont());
    combo.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            tab.setSearchButton();
            if (e.character == SWT.CR) {
                performSearch();
            }
        }
    });
    if (core.getNetworkInfoMap().getEnabledAndSearchable() == 0) {
        combo.setText(G2GuiResources.getString("S_UNAVAILABLE"));
        combo.setEnabled(false);
    }
    return combo;
}

From source file:net.sf.eclipsefp.haskell.ui.internal.preferences.editor.SyntaxPreviewer.java

License:Open Source License

/**
 * show arbitrary content//from  www . jav  a  2  s .  c  o m
 * @param parent the UI parent
 * @param store the preferences store to get color preferences from
 * @param config the source viewer configuration
 * @param content the document contents
 */
public SyntaxPreviewer(final Composite parent, final IPreferenceStore store,
        final SourceViewerConfiguration config, final String content) {
    super(parent, null, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
    this.store = store;

    this.config = config;
    if (config instanceof HaskellSourceViewerConfiguration) {
        ((HaskellSourceViewerConfiguration) config).setPreferenceStore(store);
    }
    configure(config);
    //done after configure so that the text invalidation is done after the scanner manager being notified
    initializePropertyListener();
    setEditable(false);
    getTextWidget().setFont(JFaceResources.getTextFont());

    IDocument document = new Document(content);
    setupDocument(document, IDocumentExtension3.DEFAULT_PARTITIONING);
    setDocument(document);
}