Search in sources :

Example 26 with FontData

use of org.eclipse.swt.graphics.FontData in project sling by apache.

the class JcrPropertiesView method createPartControl.

/**
	 * This is a callback that will allow us
	 * to create the viewer and initialize it.
	 */
public void createPartControl(Composite parent) {
    SyncDirManager.registerUpdateListener(new UpdateHandler() {

        @Override
        public void syncDirUpdated(SyncDir syncDir) {
            refreshContent();
        }
    });
    mainControl = new Composite(parent, SWT.NONE);
    final GridLayout gridLayout = new GridLayout(1, true);
    mainControl.setLayout(gridLayout);
    if (getViewSite() != null) {
        titleLabel = new Label(mainControl, SWT.WRAP);
        titleLabel.setText("");
        GridData data = new GridData(GridData.FILL_HORIZONTAL);
        titleLabel.setLayoutData(data);
        Label horizontalLine = new Label(mainControl, SWT.SEPARATOR | SWT.HORIZONTAL);
        data = new GridData(GridData.FILL_HORIZONTAL);
        horizontalLine.setLayoutData(data);
    }
    Font font;
    if (!JFaceResources.getFontRegistry().hasValueFor(TITLE_FONT)) {
        FontData[] fontData = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT).getFontData();
        /* title font is 2pt larger than that used in the tabs. */
        fontData[0].setHeight(fontData[0].getHeight() + 2);
        JFaceResources.getFontRegistry().put(TITLE_FONT, fontData);
    }
    font = JFaceResources.getFont(TITLE_FONT);
    if (titleLabel != null) {
        titleLabel.setFont(font);
    }
    Composite tableParent = new Composite(mainControl, SWT.NONE);
    //        tableParent.setBackground(new Color(Display.getDefault(), 100,20,180));
    GridData tableLayoutData = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    // shrink to min - table settings will resize to correct ratios
    tableLayoutData.widthHint = 1;
    tableLayoutData.heightHint = SWT.DEFAULT;
    tableParent.setLayoutData(tableLayoutData);
    TableColumnLayout tableLayout = new TableColumnLayout() {

        @Override
        protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {
            Point p = super.computeSize(composite, wHint, hHint, flushCache);
            return new Point(p.x, p.y);
        }
    };
    tableParent.setLayout(tableLayout);
    viewer = new TableViewer(tableParent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.HIDE_SELECTION | SWT.FULL_SELECTION);
    TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(viewer, new FocusCellOwnerDrawHighlighter(viewer), new CellNavigationStrategy());
    ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(viewer) {

        @Override
        protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
            resetLastValueEdited();
            return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR) || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
        }
    };
    int features = ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION | ColumnViewerEditor.KEEP_EDITOR_ON_DOUBLE_CLICK;
    TableViewerEditor.create(viewer, focusCellManager, actSupport, features);
    viewer.getTable().setLinesVisible(true);
    viewer.getTable().setHeaderVisible(true);
    viewer.setContentProvider(new ViewContentProvider());
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            final ISelection selection = event.getSelection();
            if (selection instanceof IStructuredSelection) {
                IStructuredSelection iss = (IStructuredSelection) selection;
                if (iss.isEmpty()) {
                    deleteAction.setEnabled(false);
                } else {
                    deleteAction.setEnabled(true);
                }
            } else {
                deleteAction.setEnabled(false);
            }
        }
    });
    CellLabelProvider clp = new JcrCellLabelProvider(viewer);
    TableViewerColumn column0 = new TableViewerColumn(viewer, SWT.NONE);
    column0.getColumn().setText("Name");
    column0.getColumn().setResizable(true);
    column0.getColumn().setWidth(200);
    tableLayout.setColumnData(column0.getColumn(), new ColumnWeightData(30, 140));
    final TableViewerColumn column1 = new TableViewerColumn(viewer, SWT.NONE);
    column1.getColumn().setText("Type");
    column1.getColumn().setResizable(true);
    column1.getColumn().setWidth(300);
    column1.setLabelProvider(clp);
    tableLayout.setColumnData(column1.getColumn(), new ColumnWeightData(10, 80));
    final TableViewerColumn column2 = new TableViewerColumn(viewer, SWT.NONE);
    column2.getColumn().setText("Value");
    column2.getColumn().setResizable(true);
    column2.getColumn().setWidth(300);
    tableLayout.setColumnData(column2.getColumn(), new ColumnWeightData(70, 220));
    final TableViewerColumn column3 = new TableViewerColumn(viewer, SWT.NONE);
    column3.getColumn().setText("Protected");
    column3.getColumn().setResizable(true);
    column3.getColumn().setWidth(300);
    column3.setLabelProvider(clp);
    tableLayout.setColumnData(column3.getColumn(), new ColumnWeightData(5, 57));
    final TableViewerColumn column4 = new TableViewerColumn(viewer, SWT.NONE);
    column4.getColumn().setText("Mandatory");
    column4.getColumn().setResizable(true);
    column4.getColumn().setWidth(300);
    column4.setLabelProvider(clp);
    tableLayout.setColumnData(column4.getColumn(), new ColumnWeightData(5, 62));
    final TableViewerColumn column5 = new TableViewerColumn(viewer, SWT.NONE);
    column5.getColumn().setText("Multiple");
    column5.getColumn().setResizable(true);
    column5.getColumn().setWidth(300);
    column5.setLabelProvider(clp);
    tableLayout.setColumnData(column5.getColumn(), new ColumnWeightData(5, 82));
    final TableViewerColumn column6 = new TableViewerColumn(viewer, SWT.NONE);
    column6.getColumn().setText("Auto Created");
    column6.getColumn().setResizable(true);
    column6.getColumn().setWidth(300);
    column6.setLabelProvider(clp);
    tableLayout.setColumnData(column6.getColumn(), new ColumnWeightData(5, 77));
    column0.setLabelProvider(clp);
    column0.setEditingSupport(new JcrEditingSupport(this, viewer, ColumnId.NAME));
    column1.setLabelProvider(clp);
    column1.setEditingSupport(new JcrEditingSupport(this, viewer, ColumnId.TYPE));
    column2.setLabelProvider(clp);
    column2.setEditingSupport(new JcrEditingSupport(this, viewer, ColumnId.VALUE));
    column5.setEditingSupport(new JcrEditingSupport(this, viewer, ColumnId.MULTIPLE));
    // Create the help context id for the viewer's control
    PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(), "org.apache.sling.ide.eclipse-ui.viewer");
    makeActions();
    hookContextMenu();
    hookDoubleClickAction();
    contributeToActionBars();
    listener = new ISelectionListener() {

        @Override
        public void selectionChanged(IWorkbenchPart part, ISelection selection) {
            if (selection instanceof IStructuredSelection) {
                IStructuredSelection iss = (IStructuredSelection) selection;
                Object firstElem = iss.getFirstElement();
                if (firstElem instanceof JcrNode) {
                    JcrNode jcrNode = (JcrNode) firstElem;
                    setInput(jcrNode);
                    return;
                }
            }
        }
    };
    if (getViewSite() != null) {
        getViewSite().getPage().addSelectionListener(listener);
        final ISelection selection = getViewSite().getPage().getSelection();
        Display.getCurrent().asyncExec(new Runnable() {

            @Override
            public void run() {
                listener.selectionChanged(null, selection);
            }
        });
    }
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Label(org.eclipse.swt.widgets.Label) SyncDir(org.apache.sling.ide.eclipse.ui.nav.model.SyncDir) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Font(org.eclipse.swt.graphics.Font) ISelectionListener(org.eclipse.ui.ISelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) FocusCellOwnerDrawHighlighter(org.eclipse.jface.viewers.FocusCellOwnerDrawHighlighter) ColumnViewerEditorActivationStrategy(org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider) UpdateHandler(org.apache.sling.ide.eclipse.ui.nav.model.UpdateHandler) Composite(org.eclipse.swt.widgets.Composite) FontData(org.eclipse.swt.graphics.FontData) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Point(org.eclipse.swt.graphics.Point) CellNavigationStrategy(org.eclipse.jface.viewers.CellNavigationStrategy) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) Point(org.eclipse.swt.graphics.Point) TableViewerFocusCellManager(org.eclipse.jface.viewers.TableViewerFocusCellManager) JcrNode(org.apache.sling.ide.eclipse.ui.nav.model.JcrNode) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 27 with FontData

use of org.eclipse.swt.graphics.FontData in project cogtool by cogtool.

the class SEFrameChooserView method layOutView.

protected void layOutView(Shell parent) {
    title = new Label(parent, SWT.CENTER);
    title.setText(L10N.get("SE.PickStartFrame", "Select the Start Frame for this Script"));
    // Increase the size of the instruction line.
    // TODO:mlh fix this (use FontUtils?)!
    FontData font = new FontData("Lucida Grande", 18, 0);
    title.setFont(new Font(null, font));
    // Set up the layouts
    FormData data = new FormData();
    data.top = new FormAttachment(title, 0, SWT.CENTER);
    data.right = new FormAttachment(100, 0);
    data.left = new FormAttachment(0, 0);
    title.setLayoutData(data);
    data = new FormData();
    data.top = new FormAttachment(title, 5, SWT.BOTTOM);
    data.bottom = new FormAttachment(100, 0);
    data.left = new FormAttachment(0, 5);
    data.right = new FormAttachment(100, 0);
    editor.setLayoutData(data);
}
Also used : FormData(org.eclipse.swt.layout.FormData) FontData(org.eclipse.swt.graphics.FontData) Label(org.eclipse.swt.widgets.Label) Font(org.eclipse.swt.graphics.Font) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 28 with FontData

use of org.eclipse.swt.graphics.FontData in project cogtool by cogtool.

the class SWTTextEditor method repaintTextEditor.

public void repaintTextEditor(double scale) {
    if (getVisible()) {
        IFigure f = (IFigure) getData();
        Rectangle bounds = f.getBounds();
        if (f instanceof ScalableInteractiveRectangle) {
            bounds = PrecisionUtilities.getDraw2DRectangle(bounds.x / scale, bounds.y / scale, bounds.width / scale, bounds.height / scale);
        }
        ensureLayout();
        int offset = OSUtils.MACOSX ? -2 : 1;
        // jcorn - The above conditional flag may not be necessary since
        //         our switch to SWT 3.2
        // TODO: Look into whether or not this conditional is required
        //offset = 1;
        int x = computeX(bounds, scale, offset);
        int y = computeY(bounds, scale, offset);
        setLocation(x, y);
        int width = computeWidth(bounds, scale, offset);
        int height = computeHeight(bounds, scale, offset);
        setSize(width, height);
        // TODO figure out whether getFontToUse() can reasonably
        //      return null; it has done so in some non-reproducible
        //      cases, but I don't yet know whether that is a bug, or if
        //      the bug was that were assuming that it was non-null. Given
        //      this code already appears to say "only set the font if there
        //      is non-zero length font data," it would appear that the
        //      right thing to do is skip the code if there isn't any font
        //      or font data, but with my limited knowledge of what's
        //      going on here I'm a little worried....
        // Was: FontData[] fontData = getFontToUse().getFontData();
        Font font = getFontToUse();
        if (font == null) {
            return;
        }
        FontData[] fontData = font.getFontData();
        if (fontData == null) {
            return;
        }
        if (fontData.length > 0) {
            String fontName = fontData[0].getName();
            int fontStyle = fontData[0].getStyle();
            FontData newFontData = new FontData(fontName, computeFontHeight(height, scale, offset), fontStyle);
            setFont(new Font(WindowUtil.GLOBAL_DISPLAY, newFontData));
        }
    }
}
Also used : FontData(org.eclipse.swt.graphics.FontData) Rectangle(org.eclipse.draw2d.geometry.Rectangle) ScalableInteractiveRectangle(edu.cmu.cs.hcii.cogtool.view.ScalableInteractiveRectangle) ScalableInteractiveRectangle(edu.cmu.cs.hcii.cogtool.view.ScalableInteractiveRectangle) Font(org.eclipse.swt.graphics.Font) IFigure(org.eclipse.draw2d.IFigure)

Example 29 with FontData

use of org.eclipse.swt.graphics.FontData in project translationstudio8 by heartsome.

the class HSFontSettingComposite method createContent.

public void createContent() {
    if (this.title != null && title.length() != 0) {
        Label titleLabel = new Label(this, SWT.NONE);
        titleLabel.setText(title);
        GridData titleLabelGridData = new GridData();
        titleLabelGridData.horizontalSpan = 2;
        titleLabelGridData.horizontalAlignment = GridData.CENTER;
        titleLabel.setLayoutData(titleLabelGridData);
    }
    Label lblFontName = new Label(this, SWT.NONE);
    lblFontName.setText(Messages.getString("HSFontSettingComposite.fontNameLabel"));
    fontNameComboViewer = new ComboViewer(this);
    fontNameComboViewer.setContentProvider(new ArrayContentProvider());
    Combo fontNameCombo = fontNameComboViewer.getCombo();
    GridData fnGd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    fontNameCombo.setLayoutData(fnGd);
    fontNameComboViewer.setInput(getSystemFonts());
    Label lblFontSize = new Label(this, SWT.NONE);
    lblFontSize.setText(Messages.getString("HSFontSettingComposite.fontSizeLabel"));
    fontSizeComboViewer = new ComboViewer(this);
    fontSizeComboViewer.setContentProvider(new ArrayContentProvider());
    Combo fontSize = fontSizeComboViewer.getCombo();
    fontSize.setLayoutData(fnGd);
    fontSizeComboViewer.setInput(new Integer[] { 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36 });
    Label lblFontPreview = new Label(this, SWT.None);
    lblFontPreview.setText(Messages.getString("HSFontSettingComposite.fontPreViewLabel"));
    previewFontText = new Label(this, SWT.READ_ONLY | SWT.BORDER);
    previewFontText.setText("abcdefg ABCDEFG");
    GridData previewFontTextGridData = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    previewFontTextGridData.heightHint = 50;
    previewFontText.setLayoutData(previewFontTextGridData);
    fontNameComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            String strFontName = fontNameComboViewer.getCombo().getText();
            String intFontSize = fontSizeComboViewer.getCombo().getText();
            if (strFontName == null || intFontSize == null || strFontName.length() == 0 || intFontSize.length() == 0) {
                return;
            }
            FontData fd = JFaceResources.getDefaultFont().getFontData()[0];
            fd.setName(strFontName);
            fd.setHeight(Integer.parseInt(intFontSize));
            if (previewFont != null && !previewFont.isDisposed()) {
                previewFont.dispose();
            }
            previewFont = new Font(Display.getDefault(), fd);
            previewFontText.setFont(previewFont);
        }
    });
    fontSizeComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            String strFontName = fontNameComboViewer.getCombo().getText();
            String intFontSize = fontSizeComboViewer.getCombo().getText();
            if (strFontName == null || intFontSize == null || strFontName.length() == 0 || intFontSize.length() == 0) {
                return;
            }
            FontData fd = JFaceResources.getDefaultFont().getFontData()[0];
            fd.setName(strFontName);
            fd.setHeight(Integer.parseInt(intFontSize));
            if (previewFont != null && !previewFont.isDisposed()) {
                previewFont.dispose();
            }
            previewFont = new Font(Display.getDefault(), fd);
            previewFontText.setFont(previewFont);
        }
    });
}
Also used : ComboViewer(org.eclipse.jface.viewers.ComboViewer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) FontData(org.eclipse.swt.graphics.FontData) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) Combo(org.eclipse.swt.widgets.Combo) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Font(org.eclipse.swt.graphics.Font)

Example 30 with FontData

use of org.eclipse.swt.graphics.FontData in project translationstudio8 by heartsome.

the class HSFontSettingComposite method initFont.

public void initFont(String name, int size) {
    fontNameComboViewer.setSelection(new StructuredSelection(name));
    fontSizeComboViewer.setSelection(new StructuredSelection(size));
    FontData fd = new FontData();
    fd.setName(name);
    fd.setHeight(size);
    if (previewFont != null && !previewFont.isDisposed()) {
        previewFont.dispose();
    }
    previewFont = new Font(Display.getDefault(), fd);
    previewFontText.setFont(previewFont);
}
Also used : FontData(org.eclipse.swt.graphics.FontData) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Font(org.eclipse.swt.graphics.Font)

Aggregations

FontData (org.eclipse.swt.graphics.FontData)70 Font (org.eclipse.swt.graphics.Font)38 FontStyle (org.eclipse.gmf.runtime.notation.FontStyle)14 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)11 GridData (org.eclipse.swt.layout.GridData)11 GridLayout (org.eclipse.swt.layout.GridLayout)9 Composite (org.eclipse.swt.widgets.Composite)9 Point (org.eclipse.swt.graphics.Point)8 Label (org.eclipse.swt.widgets.Label)8 Text (org.eclipse.swt.widgets.Text)5 ColorStyledText (org.talend.commons.ui.swt.colorstyledtext.ColorStyledText)5 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 Color (org.eclipse.swt.graphics.Color)4 GC (org.eclipse.swt.graphics.GC)4 IFigure (org.eclipse.draw2d.IFigure)3 Dimension (org.eclipse.draw2d.geometry.Dimension)3 DecoratedField (org.eclipse.jface.fieldassist.DecoratedField)3 FormAttachment (org.eclipse.swt.layout.FormAttachment)3 FormData (org.eclipse.swt.layout.FormData)3