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:descent.internal.ui.preferences.JavaSourcePreviewerUpdater.java

License:Open Source License

/**
 * Creates a Java source preview updater for the given viewer, configuration and preference store.
 *
 * @param viewer the viewer/*from   ww  w  .j a  va 2  s.  c om*/
 * @param configuration the configuration
 * @param preferenceStore the preference store
 */
JavaSourcePreviewerUpdater(final SourceViewer viewer, final JavaSourceViewerConfiguration configuration,
        final IPreferenceStore preferenceStore) {
    Assert.isNotNull(viewer);
    Assert.isNotNull(configuration);
    Assert.isNotNull(preferenceStore);
    final IPropertyChangeListener fontChangeListener = new IPropertyChangeListener() {
        /*
         * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
         */
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(PreferenceConstants.EDITOR_TEXT_FONT)) {
                Font font = JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT);
                viewer.getTextWidget().setFont(font);
            }
        }
    };
    final IPropertyChangeListener propertyChangeListener = new IPropertyChangeListener() {
        /*
         * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
         */
        public void propertyChange(PropertyChangeEvent event) {
            if (configuration.affectsTextPresentation(event)) {
                configuration.handlePropertyChangeEvent(event);
                viewer.invalidateTextPresentation();
            }
        }
    };
    viewer.getTextWidget().addDisposeListener(new DisposeListener() {
        /*
         * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)
         */
        public void widgetDisposed(DisposeEvent e) {
            preferenceStore.removePropertyChangeListener(propertyChangeListener);
            JFaceResources.getFontRegistry().removeListener(fontChangeListener);
        }
    });
    JFaceResources.getFontRegistry().addListener(fontChangeListener);
    preferenceStore.addPropertyChangeListener(propertyChangeListener);
}

From source file:descent.internal.ui.text.java.hover.JavadocHover.java

License:Open Source License

/**
 * Returns the Javadoc hover style sheet with the current Javadoc font from the preferences.
 * @return the updated style sheet//from   ww  w .  ja  v  a 2s . c om
 * @since 3.4
 */
private static String getStyleSheet() {
    if (fgStyleSheet == null)
        fgStyleSheet = loadStyleSheet();
    String css = fgStyleSheet;
    if (css != null) {
        FontData fontData = JFaceResources.getFontRegistry()
                .getFontData(PreferenceConstants.APPEARANCE_JAVADOC_FONT)[0];
        css = HTMLPrinter.convertTopLevelFont(css, fontData);
    }

    return css;
}

From source file:eclipse.spellchecker.preferences.OptionsConfigurationBlock.java

License:Open Source License

protected ExpandableComposite createStyleSection(Composite parent, String label, int nColumns, Key key) {
    ExpandableComposite excomposite = new ExpandableComposite(parent, SWT.NONE,
            ExpandableComposite.TWISTIE | ExpandableComposite.CLIENT_INDENT);
    excomposite.setText(label);/*w  w  w.  j  a  v a 2 s .  c o m*/
    if (key != null) {
        excomposite.setData(key);
    }
    excomposite.setExpanded(false);
    excomposite.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT));
    excomposite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, nColumns, 1));
    excomposite.addExpansionListener(new ExpansionAdapter() {
        @Override
        public void expansionStateChanged(ExpansionEvent e) {
            expandedStateChanged((ExpandableComposite) e.getSource());
        }
    });
    fExpandableComposites.add(excomposite);
    makeScrollableCompositeAware(excomposite);
    return excomposite;
}

From source file:eclipse.testframework.ui.util.FailureDialog.java

License:Open Source License

protected Control createDialogArea(Composite parent) {
    // page group
    Composite composite = (Composite) super.createDialogArea(parent);
    composite.setSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));

    Label label = new Label(composite, SWT.WRAP);
    label.setText("&Enter a note regarding the failure:");

    _text = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    _text.setFont(JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT));
    GridData data = new GridData(GridData.FILL_BOTH);
    data.widthHint = SIZING_TEXT_WIDTH;//from   w  ww .j av  a 2  s.  c o m
    data.heightHint = SIZING_TEXT_HEIGHT;
    _text.setLayoutData(data);

    return composite;
}

From source file:edu.rice.cs.drjava.plugins.eclipse.views.InteractionsController.java

License:BSD License

/**
 * Glue together the given model and view.
 * @param model EclipseInteractionsModel to handle the interpreter
 * @param adapter DocumentAdapter that the document uses
 * @param view InteractionsView in the view
 *///w  w  w .ja va2s.  com
public InteractionsController(EclipseInteractionsModel model, SWTDocumentAdapter adapter,
        InteractionsView view) {
    _model = model;
    _adapter = adapter;
    _doc = model.getDocument();
    _view = view;
    _enabled = true;

    // Initialize preferences
    Preferences prefs = EclipsePlugin.getDefault().getPluginPreferences();
    //IPreferenceStore store = EclipsePlugin.getDefault().getPreferenceStore();
    _preferenceListener = new PrefChangeListener();
    _jfacePreferenceListener = new JFacePrefChangeListener();
    prefs.addPropertyChangeListener(_preferenceListener);
    //store.addPropertyChangeListener(_preferenceListener);
    JFaceResources.getFontRegistry().addListener(_jfacePreferenceListener);
    _updateJFacePreferences();
    _updatePreferences();

    // Put the caret at the end
    _view.getTextPane().setCaretOffset(_doc.getLength());
    _addDocumentStyles();
    _setupModel();
    _setupView();
}

From source file:edu.rice.cs.drjava.plugins.eclipse.views.InteractionsController.java

License:BSD License

/** Cleans up any resources this controller created, as well as the model. */
public void dispose() {
    _model.dispose();//from   w ww.j a  v  a 2 s.  com
    _colorRed.dispose();
    _colorDarkRed.dispose();
    _colorDarkGreen.dispose();
    _colorDarkBlue.dispose();
    _colorYellow.dispose();
    ///_clipboard.dispose();

    // Remove preference listener
    Preferences store = EclipsePlugin.getDefault().getPluginPreferences();
    //IPreferenceStore store = EclipsePlugin.getDefault().getPreferenceStore();
    store.removePropertyChangeListener(_preferenceListener);
    JFaceResources.getFontRegistry().removeListener(_jfacePreferenceListener);
}

From source file:edu.tsinghua.lumaqq.resource.Resources.java

License:Open Source License

/**
 * ?singleton?/*from  w  w  w. j a va 2  s  . co m*/
 */
private Resources() {
    // ?
    registry = new ImageRegistry(Display.getCurrent());
    // ?
    FontData fd = new FontData("", 9, SWT.NORMAL);
    JFaceResources.getFontRegistry().put(LUMAQQ_DEFAULT_FONT, new FontData[] { fd });
}

From source file:edu.tsinghua.lumaqq.resource.Resources.java

License:Open Source License

/**
 * @return
 *       ?
 */
public Font getItalicDefaultFont() {
    return JFaceResources.getFontRegistry().getItalic(LUMAQQ_DEFAULT_FONT);
}

From source file:edu.tsinghua.lumaqq.ui.BorderStyler.java

License:Open Source License

/**
 * shell//from  w w  w . j  av  a  2  s. c  o  m
 * 
 * @param shell
 * @return
 *       
 */
public Composite decorateShell(Shell s) {
    shell = s;
    shell.setData(STYLER, this);

    // layout
    GridLayout layout = new GridLayout(3, false);
    layout.marginHeight = layout.marginWidth = layout.verticalSpacing = layout.horizontalSpacing = 0;
    shell.setLayout(layout);

    Composite leftTop = new Composite(shell, SWT.NONE | SWT.NO_BACKGROUND);
    if (resizable)
        leftTop.setCursor(display.getSystemCursor(SWT.CURSOR_SIZENWSE));
    GridData gd = new GridData();
    gd.widthHint = gd.heightHint = 5;
    leftTop.setLayoutData(gd);
    leftTop.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            Rectangle bound = ((Control) e.getSource()).getBounds();
            int i = 0;
            for (Color c : Colors.MAINSHELL_BORDERS) {
                e.gc.setForeground(c);
                e.gc.drawLine(i, i, bound.width, i);
                e.gc.drawLine(i, i, i, bound.height);
                i++;
            }
        }
    });
    if (resizable) {
        leftTop.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseDown(MouseEvent e) {
                Control control = (Control) e.getSource();
                Point loc = control.toDisplay(e.x, e.y);
                downX = loc.x;
                downY = loc.y;
            }

            @Override
            public void mouseUp(MouseEvent e) {
                Control control = (Control) e.getSource();
                Point loc = control.toDisplay(e.x, e.y);
                int dx = downX - loc.x;
                int dy = downY - loc.y;
                if (dx == 0 && dy == 0)
                    return;
                Rectangle bound = shell.getBounds();
                bound.x -= dx;
                bound.y -= dy;
                bound.width += dx;
                bound.height += dy;
                setShellBound(bound);
            }
        });
    }

    top = new Label(shell, SWT.LEFT);
    if (resizable)
        top.setCursor(display.getSystemCursor(SWT.CURSOR_SIZENS));
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.heightHint = 5;
    top.setLayoutData(gd);
    top.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            Rectangle bound = ((Control) e.getSource()).getBounds();
            int i = 0;
            for (Color c : Colors.MAINSHELL_BORDERS) {
                e.gc.setForeground(c);
                e.gc.drawLine(0, i, bound.width, i);
                i++;
            }
        }
    });
    if (resizable) {
        top.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseDown(MouseEvent e) {
                Control control = (Control) e.getSource();
                downY = control.toDisplay(e.x, e.y).y;
            }

            @Override
            public void mouseUp(MouseEvent e) {
                Control control = (Control) e.getSource();
                int newY = control.toDisplay(e.x, e.y).y;
                int dy = downY - newY;
                if (dy == 0)
                    return;
                Rectangle bound = shell.getBounds();
                bound.y -= dy;
                bound.height += dy;
                setShellBound(bound);
            }
        });
    }

    Composite rightTop = new Composite(shell, SWT.NONE | SWT.NO_BACKGROUND);
    if (resizable)
        rightTop.setCursor(display.getSystemCursor(SWT.CURSOR_SIZENESW));
    gd = new GridData();
    gd.widthHint = gd.heightHint = 5;
    rightTop.setLayoutData(gd);
    rightTop.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            Rectangle bound = ((Control) e.getSource()).getBounds();
            int i = 0;
            for (Color c : Colors.MAINSHELL_BORDERS) {
                e.gc.setForeground(c);
                e.gc.drawLine(bound.width - i - 1, i, 0, i);
                e.gc.drawLine(bound.width - i - 1, i, bound.width - i - 1, bound.height);
                i++;
            }
        }
    });
    if (resizable) {
        rightTop.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseDown(MouseEvent e) {
                Control control = (Control) e.getSource();
                Point loc = control.toDisplay(e.x, e.y);
                downX = loc.x;
                downY = loc.y;
            }

            @Override
            public void mouseUp(MouseEvent e) {
                Control control = (Control) e.getSource();
                Point loc = control.toDisplay(e.x, e.y);
                int dx = loc.x - downX;
                int dy = downY - loc.y;
                if (dx == 0 && dy == 0)
                    return;
                Rectangle bound = shell.getBounds();
                bound.y -= dy;
                bound.width += dx;
                bound.height += dy;
                setShellBound(bound);
            }
        });
    }

    left = new Label(shell, SWT.LEFT);
    gd = new GridData(GridData.FILL_VERTICAL);
    gd.widthHint = 5;
    gd.verticalSpan = 2;
    left.setLayoutData(gd);
    if (resizable)
        left.setCursor(display.getSystemCursor(SWT.CURSOR_SIZEWE));
    left.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            Rectangle bound = ((Control) e.getSource()).getBounds();
            int i = 0;
            for (Color c : Colors.MAINSHELL_BORDERS) {
                e.gc.setForeground(c);
                e.gc.drawLine(i, 0, i, bound.height);
                i++;
            }
        }
    });
    if (resizable) {
        left.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseDown(MouseEvent e) {
                Control control = (Control) e.getSource();
                downX = control.toDisplay(e.x, e.y).x;
            }

            @Override
            public void mouseUp(MouseEvent e) {
                Control control = (Control) e.getSource();
                int newX = control.toDisplay(e.x, e.y).x;
                int dx = downX - newX;
                if (dx == 0)
                    return;
                Rectangle bound = shell.getBounds();
                bound.x -= dx;
                bound.width += dx;
                setShellBound(bound);
            }
        });
    }

    topDown = new Composite(shell, SWT.LEFT);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.heightHint = 23;
    topDown.setLayoutData(gd);
    topDown.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            Rectangle bound = ((Control) e.getSource()).getBounds();
            e.gc.setForeground(Colors.MAINSHELL_TITLE_TOP);
            e.gc.setBackground(Colors.MAINSHELL_TITLE_BOTTOM);
            e.gc.fillGradientRectangle(0, 0, bound.width, bound.height, true);

            e.gc.setForeground(Colors.MAINSHELL_TITLE_SEPARATOR_TOP);
            e.gc.drawLine(2, 19, bound.width - 2, 19);
            e.gc.setForeground(Colors.MAINSHELL_TITLE_SEPARATOR_BOTTOM);
            e.gc.drawLine(2, 20, bound.width - 2, 20);

            Image image = shell.getImage();
            Rectangle imgBound = (image == null) ? new Rectangle(0, 0, 16, 16) : image.getBounds();
            if (image != null) {
                e.gc.drawImage(image, 2, (18 - imgBound.height) >> 1);
            }

            String text = shell.getText();
            if (text != null) {
                String name = JFaceResources.getDefaultFont().getFontData()[0].getName();
                e.gc.setForeground(Colors.WHITE);
                e.gc.setFont(JFaceResources.getFontRegistry().getBold(name));
                Point extent = e.gc.textExtent(text);
                e.gc.drawString(text, imgBound.width + 7, (18 - extent.y) >> 1, true);
            }
        }
    });
    topDown.setLayout(new FormLayout());
    topDown.addMouseListener(new MouseListener() {
        public void mouseDown(MouseEvent e) {
            downX = e.x;
            downY = e.y;
            isMove = true;
            fireMouseDownEvent(e);
        }

        public void mouseUp(MouseEvent e) {
            isMove = false;
            fireMouseUpEvent(e);
        }

        public void mouseDoubleClick(MouseEvent e) {
            if (maximizeWhenDoubleClick && showMaxButton)
                doMaximize();
        }
    });
    topDown.addMouseMoveListener(new MouseMoveListener() {
        public void mouseMove(MouseEvent e) {
            if (isMove) {
                Point loc = shell.getLocation();
                int x = loc.x + e.x - downX;
                int y = loc.y + e.y - downY;
                shell.setLocation(x, y);
            }
        }
    });

    // 
    Label lblClose = new Label(topDown, SWT.CENTER);
    lblClose.setImage(res.getImage(Resources.bmpCloseNormal));
    FormData fd = new FormData();
    fd.top = new FormAttachment(0, 0);
    fd.bottom = new FormAttachment(0, 16);
    fd.right = new FormAttachment(100, -2);
    fd.left = new FormAttachment(100, -19);
    lblClose.setLayoutData(fd);
    lblClose.addMouseTrackListener(new MouseTrackAdapter() {
        @Override
        public void mouseEnter(MouseEvent e) {
            Label lbl = (Label) e.getSource();
            lbl.setImage(res.getImage(Resources.bmpCloseHover));
        }

        @Override
        public void mouseExit(MouseEvent e) {
            Label lbl = (Label) e.getSource();
            lbl.setImage(res.getImage(Resources.bmpCloseNormal));
        }
    });
    lblClose.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseDown(MouseEvent e) {
            Label lbl = (Label) e.getSource();
            lbl.setImage(res.getImage(Resources.bmpCloseDown));
        }

        @Override
        public void mouseUp(MouseEvent e) {
            if (checkMinimizeWhenClose && main != null) {
                if (main.getOptionHelper().isMinimizeWhenClose()) {
                    Label lbl = (Label) e.getSource();
                    lbl.setImage(res.getImage(Resources.bmpCloseHover));

                    shell.setMinimized(true);
                    shell.setVisible(false);
                } else
                    shell.close();
            } else
                shell.close();
        }
    });

    Label referenceLabel = lblClose;

    // 
    if (showMaxButton) {
        lblMax = new Label(topDown, SWT.CENTER);
        lblMax.setImage(res.getImage(Resources.bmpMaxNormal));
        fd = new FormData();
        fd.top = new FormAttachment(0, 0);
        fd.bottom = new FormAttachment(0, 16);
        fd.right = new FormAttachment(referenceLabel, 0, SWT.LEFT);
        fd.left = new FormAttachment(referenceLabel, -17, SWT.LEFT);
        lblMax.setLayoutData(fd);
        lblMax.addMouseTrackListener(new MouseTrackAdapter() {
            @Override
            public void mouseEnter(MouseEvent e) {
                Label lbl = (Label) e.getSource();
                lbl.setImage(shell.getMaximized() ? res.getImage(Resources.bmpRestoreHover)
                        : res.getImage(Resources.bmpMaxHover));
            }

            @Override
            public void mouseExit(MouseEvent e) {
                Label lbl = (Label) e.getSource();
                lbl.setImage(shell.getMaximized() ? res.getImage(Resources.bmpRestoreNormal)
                        : res.getImage(Resources.bmpMaxNormal));
            }
        });
        lblMax.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseDown(MouseEvent e) {
                Label lbl = (Label) e.getSource();
                lbl.setImage(shell.getMaximized() ? res.getImage(Resources.bmpRestoreDown)
                        : res.getImage(Resources.bmpMaxDown));
            }

            @Override
            public void mouseUp(MouseEvent e) {
                doMaximize();
            }
        });

        referenceLabel = lblMax;
    }

    // ?
    if (showMinButton) {
        Label lblMin = new Label(topDown, SWT.CENTER);
        lblMin.setImage(res.getImage(Resources.bmpMinNormal));
        fd = new FormData();
        fd.top = new FormAttachment(0, 0);
        fd.bottom = new FormAttachment(0, 16);
        fd.right = new FormAttachment(referenceLabel, 0, SWT.LEFT);
        fd.left = new FormAttachment(referenceLabel, -16, SWT.LEFT);
        lblMin.setLayoutData(fd);
        lblMin.addMouseTrackListener(new MouseTrackAdapter() {
            @Override
            public void mouseEnter(MouseEvent e) {
                Label lbl = (Label) e.getSource();
                lbl.setImage(res.getImage(Resources.bmpMinHover));
            }

            @Override
            public void mouseExit(MouseEvent e) {
                Label lbl = (Label) e.getSource();
                lbl.setImage(res.getImage(Resources.bmpMinNormal));
            }
        });
        lblMin.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseDown(MouseEvent e) {
                Label lbl = (Label) e.getSource();
                lbl.setImage(res.getImage(Resources.bmpMinDown));
            }

            @Override
            public void mouseUp(MouseEvent e) {
                Label lbl = (Label) e.getSource();
                lbl.setImage(res.getImage(Resources.bmpMinHover));
                shell.setMinimized(true);
                if (hideWhenMinimize)
                    shell.setVisible(false);
            }
        });

        referenceLabel = lblMin;
    }

    // 
    if (showPlusButton) {
        Label lblPlus = new Label(topDown, SWT.CENTER);
        lblPlus.setImage(res.getImage(Resources.bmpPlusNormal));
        fd = new FormData();
        fd.top = new FormAttachment(0, 0);
        fd.bottom = new FormAttachment(0, 16);
        fd.right = new FormAttachment(referenceLabel, -1, SWT.LEFT);
        fd.left = new FormAttachment(referenceLabel, -17, SWT.LEFT);
        lblPlus.setLayoutData(fd);
        lblPlus.addMouseTrackListener(new MouseTrackAdapter() {
            @Override
            public void mouseEnter(MouseEvent e) {
                Label lbl = (Label) e.getSource();
                lbl.setImage(res.getImage(Resources.bmpPlusHover));
            }

            @Override
            public void mouseExit(MouseEvent e) {
                Label lbl = (Label) e.getSource();
                lbl.setImage(res.getImage(Resources.bmpPlusNormal));
            }
        });
        lblPlus.addMouseListener(new MouseListener() {
            public void mouseDown(MouseEvent e) {
                Label lbl = (Label) e.getSource();
                lbl.setImage(res.getImage(Resources.bmpPlusDown));
                if (plusMouseListener != null)
                    plusMouseListener.mouseDown(e);
            }

            public void mouseDoubleClick(MouseEvent e) {
                if (plusMouseListener != null)
                    plusMouseListener.mouseDoubleClick(e);
            }

            public void mouseUp(MouseEvent e) {
                Label lbl = (Label) e.getSource();
                lbl.setImage(res.getImage(Resources.bmpPlusHover));
                if (plusMouseListener != null)
                    plusMouseListener.mouseUp(e);
            }
        });
    }

    right = new Label(shell, SWT.LEFT);
    gd = new GridData(GridData.FILL_VERTICAL);
    gd.widthHint = 5;
    gd.verticalSpan = 2;
    right.setLayoutData(gd);
    if (resizable)
        right.setCursor(display.getSystemCursor(SWT.CURSOR_SIZEWE));
    right.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            Rectangle bound = ((Control) e.getSource()).getBounds();
            int i = 4;
            for (Color c : Colors.MAINSHELL_BORDERS) {
                e.gc.setForeground(c);
                e.gc.drawLine(i, 0, i, bound.height);
                i--;
            }
        }
    });
    if (resizable) {
        right.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseDown(MouseEvent e) {
                Control control = (Control) e.getSource();
                downX = control.toDisplay(e.x, e.y).x;
            }

            @Override
            public void mouseUp(MouseEvent e) {
                Control control = (Control) e.getSource();
                int newX = control.toDisplay(e.x, e.y).x;
                int dx = newX - downX;
                if (dx == 0)
                    return;
                Point size = shell.getSize();
                size.x += dx;
                setShellSize(size);
            }
        });
    }

    center = new Composite(shell, SWT.NONE);
    center.setLayoutData(new GridData(GridData.FILL_BOTH));
    layout = new GridLayout();
    layout.marginHeight = layout.marginWidth = layout.horizontalSpacing = layout.verticalSpacing = 0;
    center.setLayout(layout);

    Composite leftBottom = new Composite(shell, SWT.NONE | SWT.NO_BACKGROUND);
    if (resizable)
        leftBottom.setCursor(display.getSystemCursor(SWT.CURSOR_SIZENESW));
    gd = new GridData();
    gd.widthHint = gd.heightHint = 5;
    leftBottom.setLayoutData(gd);
    leftBottom.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            Rectangle bound = ((Control) e.getSource()).getBounds();
            int i = 0;
            for (Color c : Colors.MAINSHELL_BORDERS) {
                e.gc.setForeground(c);
                e.gc.drawLine(i, bound.height - i - 1, i, 0);
                e.gc.drawLine(i, bound.height - i - 1, bound.width, bound.height - i - 1);
                i++;
            }
        }
    });
    if (resizable) {
        leftBottom.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseDown(MouseEvent e) {
                Control control = (Control) e.getSource();
                Point loc = control.toDisplay(e.x, e.y);
                downX = loc.x;
                downY = loc.y;
            }

            @Override
            public void mouseUp(MouseEvent e) {
                Control control = (Control) e.getSource();
                Point loc = control.toDisplay(e.x, e.y);
                int dx = downX - loc.x;
                int dy = loc.y - downY;
                if (dx == 0 && dy == 0)
                    return;
                Rectangle bound = shell.getBounds();
                bound.x -= dx;
                bound.width += dx;
                bound.height += dy;
                setShellBound(bound);
            }
        });
    }

    bottom = new Label(shell, SWT.LEFT);
    if (resizable)
        bottom.setCursor(display.getSystemCursor(SWT.CURSOR_SIZENS));
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.heightHint = 5;
    bottom.setLayoutData(gd);
    bottom.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            Rectangle bound = ((Control) e.getSource()).getBounds();
            int i = 0;
            for (Color c : Colors.MAINSHELL_BORDERS) {
                e.gc.setForeground(c);
                e.gc.drawLine(0, 5 - i - 1, bound.width, 5 - i - 1);
                i++;
            }
        }
    });
    if (resizable) {
        bottom.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseDown(MouseEvent e) {
                Control control = (Control) e.getSource();
                downY = control.toDisplay(e.x, e.y).y;
            }

            @Override
            public void mouseUp(MouseEvent e) {
                Control control = (Control) e.getSource();
                int newY = control.toDisplay(e.x, e.y).y;
                int dy = newY - downY;
                if (dy == 0)
                    return;
                Point size = shell.getSize();
                size.y += dy;
                setShellSize(size);
            }
        });
    }

    Composite rightBottom = new Composite(shell, SWT.NONE | SWT.NO_BACKGROUND);
    if (resizable)
        rightBottom.setCursor(display.getSystemCursor(SWT.CURSOR_SIZENWSE));
    gd = new GridData();
    gd.widthHint = gd.heightHint = 5;
    rightBottom.setLayoutData(gd);
    rightBottom.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            Rectangle bound = ((Control) e.getSource()).getBounds();
            int i = 0;
            for (Color c : Colors.MAINSHELL_BORDERS) {
                e.gc.setForeground(c);
                e.gc.drawLine(bound.width - i - 1, bound.height - i - 1, bound.width - i - 1, 0);
                e.gc.drawLine(bound.width - i - 1, bound.height - i - 1, 0, bound.height - i - 1);
                i++;
            }
        }
    });
    if (resizable) {
        rightBottom.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseDown(MouseEvent e) {
                Control control = (Control) e.getSource();
                Point loc = control.toDisplay(e.x, e.y);
                downX = loc.x;
                downY = loc.y;
            }

            @Override
            public void mouseUp(MouseEvent e) {
                Control control = (Control) e.getSource();
                Point loc = control.toDisplay(e.x, e.y);
                int dx = loc.x - downX;
                int dy = loc.y - downY;
                if (dx == 0 && dy == 0)
                    return;
                Point size = shell.getSize();
                size.x += dx;
                size.y += dy;
                setShellSize(size);
            }
        });
    }

    return center;
}

From source file:edu.tsinghua.lumaqq.widgets.rich.LineStyler.java

License:Open Source License

public Font getLineFont(int lineIndex) {
    LineStyle style = getLineStyle(lineIndex);
    String symbolic = style.getFontString();
    Font f = JFaceResources.getFont(symbolic);
    if (f == JFaceResources.getDefaultFont()) {
        FontData[] fd = style.createFontData();
        JFaceResources.getFontRegistry().put(symbolic, fd);
    }/*  ww w.ja  v  a  2s. c o  m*/
    return JFaceResources.getFont(symbolic);
}