Example usage for org.eclipse.jface.preference PreferenceConverter getDefaultFontData

List of usage examples for org.eclipse.jface.preference PreferenceConverter getDefaultFontData

Introduction

In this page you can find the example usage for org.eclipse.jface.preference PreferenceConverter getDefaultFontData.

Prototype

public static FontData getDefaultFontData(IPreferenceStore store, String name) 

Source Link

Document

Returns a single default value for the font-valued preference with the given name in the given preference store.

Usage

From source file:com.iw.plugins.spindle.editors.SummarySourceViewer.java

License:Mozilla Public License

private void initializeWidgetFont(StyledText styledText) {
    IPreferenceStore store = getPreferenceStore();
    if (store != null) {

        FontData data = null;/*  www . j av a 2 s.c  o  m*/

        if (store.contains(JFaceResources.TEXT_FONT) && !store.isDefault(JFaceResources.TEXT_FONT)) {
            data = PreferenceConverter.getFontData(store, JFaceResources.TEXT_FONT);
        } else {
            data = PreferenceConverter.getDefaultFontData(store, JFaceResources.TEXT_FONT);
        }

        if (data != null) {
            Font font = new Font(styledText.getDisplay(), data);
            styledText.setFont(font);

            if (currentFont != null)
                currentFont.dispose();

            currentFont = font;
            return;
        }
    }

    // if all the preferences failed
    styledText.setFont(JFaceResources.getTextFont());
}

From source file:fede.workspace.eclipse.java.fields.JDISourceViewer.java

License:Apache License

/**
* Updates the viewer's font to match the preferences.
*///from   ww w.  jav a  2 s.c o m
private void updateViewerFont() {
    IPreferenceStore store = getPreferenceStore();
    if (store != null) {
        FontData data = null;
        if (store.contains(JFaceResources.TEXT_FONT) && !store.isDefault(JFaceResources.TEXT_FONT)) {
            data = PreferenceConverter.getFontData(store, JFaceResources.TEXT_FONT);
        } else {
            data = PreferenceConverter.getDefaultFontData(store, JFaceResources.TEXT_FONT);
        }
        if (data != null) {
            Font font = new Font(getTextWidget().getDisplay(), data);
            applyFont(font);
            if (getFont() != null) {
                getFont().dispose();
            }
            setFont(font);
            return;
        }
    }
    // if all the preferences failed
    applyFont(JFaceResources.getTextFont());
}

From source file:net.openchrom.xxd.processor.supplier.rscripting.ui.code.ConsoleCommands.java

License:Open Source License

public Menu getMenu(Control parent) {

    if (fMenu != null) {
        fMenu.dispose();/* www  . j  av a  2  s .  c  om*/
    }
    fMenu = new Menu(parent);
    fMenu = new Menu(parent);
    MenuItem menuItem42 = new MenuItem(fMenu, SWT.PUSH);
    menuItem42.setText("Start Native R");
    menuItem42.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {

            startR();
        }

        public void widgetDefaultSelected(SelectionEvent e) {

        }
    });
    new MenuItem(fMenu, SWT.SEPARATOR);
    /*
     * MenuItem menuItem5 = new MenuItem(fMenu, SWT.PUSH);
     * menuItem5.setText("Console Output");
     * menuItem5.addSelectionListener(new SelectionListener() {
     * public void widgetSelected(SelectionEvent e) {
     * exitShellProcess();
     * setConsoleColor();
     * IOConsole ioConsole = participant.getIoc();
     * participant.interpreterSelection = "-";
     * ioConsole.clearConsole();
     * participant.ignore = true;
     * ioConsole.getInputStream().appendData(System.getProperty("line.separator"));
     * participant.styledText.setEditable(false);
     * }
     * public void widgetDefaultSelected(SelectionEvent e) {
     * }
     * });
     */
    MenuItem menuItem4 = new MenuItem(fMenu, SWT.PUSH);
    menuItem4.setText("Stop Native R Process");
    menuItem4.addSelectionListener(new SelectionListener() {

        public void selectionChanged(SelectionChangedEvent event) {

        }

        public void widgetSelected(SelectionEvent e) {

            ConsolePageParticipant cpp = ConsolePageParticipant.getConsolePageParticipantInstance();
            String selectionConsole = ConsolePageParticipant.getInterpreterSelection();
            new Thread() {

                @Override
                public void run() {

                    if (selectionConsole.equals("R")) {
                        if (cpp.getRProcess() != null) {
                            try {
                                cpp.getRProcess().destroy();
                                RConnection con = RServe.getConnection();
                                if (con != null) {
                                    con.close();
                                    RServe.setConnection(null);
                                    RServe.setRrunning(false);
                                }
                            } catch (Exception e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                            cpp.setRProcess(null);
                        }
                    }
                }
            }.start();
            MsgDialog.message("Process terminated!");
        }

        public void widgetDefaultSelected(SelectionEvent e) {

        }
    });
    MenuItem menuItem51 = new MenuItem(fMenu, SWT.PUSH);
    menuItem51.setText("Stop All Native R Processes");
    menuItem51.addSelectionListener(new SelectionListener() {

        public void selectionChanged(SelectionChangedEvent event) {

        }

        public void widgetSelected(SelectionEvent e) {

            boolean destroy = MsgDialog
                    .decision("Should all running Rterm (Windows) or R (Linux, Mac) processes be destroyed?\n"
                            + "If you you confirm all Rterm, R processes on the OS will be terminated!\n"
                            + "Use only if no other Rterm, R instances are running!");
            if (destroy) {
                if (Util.getOS().equals("Windows")) {
                    TerminateRserve.killProcessRtermWindows();
                } else if (Util.getOS().equals("Linux")) {
                    TerminateRserve.killProcessRtermLinux();
                } else if (Util.getOS().equals("Mac")) {
                    TerminateRserve.killProcessRtermMac();
                }
                ConsolePageParticipant cpp = ConsolePageParticipant.getConsolePageParticipantInstance();
                String selectionConsole = ConsolePageParticipant.getInterpreterSelection();
                if (selectionConsole.equals("R")) {
                    if (cpp.getRProcess() != null) {
                        try {
                            cpp.getRProcess().destroy();
                            RConnection con = RServe.getConnection();
                            if (con != null) {
                                con.close();
                                RServe.setConnection(null);
                                RServe.setRrunning(false);
                            }
                        } catch (Exception e2) {
                            // TODO Auto-generated catch block
                            e2.printStackTrace();
                        }
                        cpp.setRProcess(null);
                    }
                    MsgDialog.message("Terminated R process!");
                } else {
                    MsgDialog.message("Please select the R console to terminate the process");
                }
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {

        }
    });
    new MenuItem(fMenu, SWT.SEPARATOR);
    MenuItem menuEncoding = new MenuItem(fMenu, SWT.CASCADE);
    menuEncoding.setText("Change Text Encoding");
    final Menu menuScripts = new Menu(menuEncoding);
    menuEncoding.setMenu(menuScripts);
    menuScripts.addMenuListener(new MenuListener() {

        public void menuHidden(MenuEvent e) {

        }

        @Override
        public void menuShown(MenuEvent e) {

            // plugins_ = new MenuItem[Menus.getPlugins().length];
            MenuItem[] menuItems = menuScripts.getItems();
            // Only delete the plugins menu items and menus!
            for (int i = 0; i < menuItems.length; i++) {
                if (menuItems[i] != null) {
                    menuItems[i].dispose();
                }
            }
            MenuItem item1 = new MenuItem(menuScripts, SWT.NONE);
            final Charset cs = Charset.defaultCharset();
            item1.setText("System Encoding");
            item1.addSelectionListener(new SelectionListener() {

                public void widgetSelected(SelectionEvent e) {

                    IPreferenceStore store = Activator.getDefault().getPreferenceStore();
                    store.setValue("Console_Encoding", cs.displayName());
                    MsgDialog.message("Encoding set to " + Charset.defaultCharset());
                }

                public void widgetDefaultSelected(SelectionEvent e) {

                }
            });
            MenuItem item2 = new MenuItem(menuScripts, SWT.NONE);
            item2.setText("Reset Encoding");
            item2.addSelectionListener(new SelectionListener() {

                public void widgetSelected(SelectionEvent e) {

                    IPreferenceStore store = Activator.getDefault().getPreferenceStore();
                    String os = Util.getOS();
                    if (os.equals("Windows")) {
                        store.setValue("Console_Encoding", "CP850");
                        MsgDialog.message("Encoding set to CP850");
                    } else if (os.equals("Linux")) {
                        store.setValue("Console_Encoding", "UTF-8");
                        MsgDialog.message("Encoding set to UTF-8");
                    } else if (os.equals("Mac")) {
                        store.setValue("Console_Encoding", "UTF-8");
                        MsgDialog.message("Encoding set to UTF-8");
                    }
                }

                public void widgetDefaultSelected(SelectionEvent e) {

                }
            });
            MenuItem item3 = new MenuItem(menuScripts, SWT.NONE);
            item3.setText("Custom Encoding");
            item3.addSelectionListener(new SelectionListener() {

                public void widgetSelected(SelectionEvent e) {

                    IPreferenceStore store = Activator.getDefault().getPreferenceStore();
                    InputDialog dlg = new InputDialog(Util.getShell(), "", "Enter Encoding",
                            store.getString("Console_Encoding"), null);
                    if (dlg.open() == Window.OK) {
                        // User clicked OK; update the label with the input
                        store.setValue("Console_Encoding", dlg.getValue());
                        MsgDialog.message("Encoding set to " + dlg.getValue());
                    }
                }

                @Override
                public void widgetDefaultSelected(SelectionEvent e) {

                }
            });
            for (int i = 0; i < encoding.length; i++) {
                final int count = i;
                MenuItem item = new MenuItem(menuScripts, SWT.NONE);
                item.setText(encoding[i]);
                item.addSelectionListener(new SelectionListener() {

                    public void widgetSelected(SelectionEvent e) {

                        IPreferenceStore store = Activator.getDefault().getPreferenceStore();
                        store.setValue("Console_Encoding", encoding[count]);
                        MsgDialog.message("Encoding set to " + encoding[count]);
                    }

                    public void widgetDefaultSelected(SelectionEvent e) {

                    }
                });
            }
        }
    });
    MenuItem itemSetFont = new MenuItem(fMenu, SWT.PUSH);
    itemSetFont.setText("Font Settings");
    itemSetFont.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {

            IPreferenceStore store = Activator.getDefault().getPreferenceStore();
            FontData defaultFont = PreferenceConverter.getDefaultFontData(store, "PluginShellFonts");
            StyledText styledText = (StyledText) participant.page.getControl();
            FontDialog fd = new FontDialog(new Shell(), SWT.NONE);
            fd.setText("Select Font");
            fd.setRGB(new RGB(0, 0, 0));
            if (defaultFont != null) {
                fd.setFontData(defaultFont);
            }
            FontData newFont = fd.open();
            if (newFont == null)
                return;
            styledText.setFont(new Font(Display.getDefault(), newFont));
            PreferenceConverter.setValue(store, "PluginShellFonts", newFont);
        }

        public void widgetDefaultSelected(SelectionEvent e) {

        }
    });
    /*
     * menuItem5.addSelectionListener(new SelectionListener() {
     * public void selectionChanged(SelectionChangedEvent event) {
     * }
     * public void widgetSelected(SelectionEvent e) {
     * }
     * public void widgetDefaultSelected(SelectionEvent e) {
     * } });
     */
    return fMenu;
}

From source file:org.eclipse.papyrus.infra.gmfdiag.preferences.jface.preference.FontFieldEditor.java

License:Open Source License

/**
 * @see org.eclipse.jface.preference.FieldEditor#doLoadDefault()
 *//* w w w  .ja  va  2 s .c o m*/
@Override
protected void doLoadDefault() {
    fontData = PreferenceConverter.getDefaultFontData(getPreferenceStore(), getPreferenceName());
    initFontData();
}