Search in sources :

Example 21 with Font

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

the class MatchViewPart method createPartControl.

@Override
public void createPartControl(Composite parent) {
    GridLayout parentGl = new GridLayout(1, false);
    parentGl.marginWidth = 0;
    parentGl.marginHeight = 0;
    parent.setLayout(parentGl);
    final Composite composite = new Composite(parent, SWT.NONE);
    GridLayout compositeGl = new GridLayout(1, false);
    compositeGl.marginBottom = -1;
    compositeGl.marginLeft = -1;
    compositeGl.marginRight = -1;
    compositeGl.marginTop = 0;
    compositeGl.marginWidth = 0;
    compositeGl.marginHeight = 0;
    compositeGl.verticalSpacing = 0;
    composite.setLayout(compositeGl);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    // sourceText = new StyledText(composite, SWT.BORDER | SWT.V_SCROLL | SWT.READ_ONLY);
    // GridData sTextGd = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
    // Font f = JFaceResources.getFont(net.heartsome.cat.ts.ui.Constants.MATCH_VIEWER_TEXT_FONT);
    // sourceText.setFont(f);
    // int lineH = sourceText.getLineHeight() * 3;
    // sTextGd.heightHint = lineH;
    // sTextGd.minimumHeight = lineH;
    // sourceText.setLayoutData(sTextGd);
    SashForm sashForm = new SashForm(composite, SWT.VERTICAL);
    sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    sourceText = new SegmentViewer(sashForm, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.READ_ONLY | SWT.V_SCROLL, null);
    StyledText srcTextControl = sourceText.getTextWidget();
    srcTextControl.setLineSpacing(net.heartsome.cat.ts.ui.Constants.SEGMENT_LINE_SPACING);
    srcTextControl.setLeftMargin(net.heartsome.cat.ts.ui.Constants.SEGMENT_LEFT_MARGIN);
    srcTextControl.setRightMargin(net.heartsome.cat.ts.ui.Constants.SEGMENT_RIGHT_MARGIN);
    srcTextControl.setTopMargin(net.heartsome.cat.ts.ui.Constants.SEGMENT_TOP_MARGIN);
    srcTextControl.setBottomMargin(net.heartsome.cat.ts.ui.Constants.SEGMENT_TOP_MARGIN);
    srcTextControl.setFont(JFaceResources.getFont(net.heartsome.cat.ts.ui.Constants.MATCH_VIEWER_TEXT_FONT));
    sourceText.setSource("");
    sourceColunmCellRenderer.setSegmentViewer(sourceText);
    GridData sTextGd = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
    Font f = JFaceResources.getFont(net.heartsome.cat.ts.ui.Constants.MATCH_VIEWER_TEXT_FONT);
    srcTextControl.setFont(f);
    int lineH = srcTextControl.getLineHeight() * 2;
    sTextGd.heightHint = lineH;
    sTextGd.minimumHeight = lineH;
    srcTextControl.setLayoutData(sTextGd);
    net.heartsome.cat.ts.ui.innertag.tagstyle.TagStyleConfigurator.configure(sourceText);
    gridTable = new Grid(sashForm, SWT.BORDER | SWT.V_SCROLL);
    gridTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    gridTable.setHeaderVisible(false);
    gridTable.setAutoHeight(true);
    gridTable.setRowsResizeable(true);
    gridTable.setData("selectedBgColor", selectedBgColor);
    final GridColumn sourceCln = new GridColumn(gridTable, SWT.NONE);
    sourceColunmCellRenderer.setFont(JFaceResources.getFont(net.heartsome.cat.ts.ui.Constants.MATCH_VIEWER_TEXT_FONT));
    sourceCln.setCellRenderer(sourceColunmCellRenderer);
    sourceCln.setText(Messages.getString("view.MatchViewPart.sourceCln"));
    sourceCln.setWordWrap(true);
    sourceCln.setAlignment(SWT.CENTER);
    sourceCln.setResizeable(false);
    final GridColumn typeCln = new GridColumn(gridTable, SWT.NONE);
    typeColumnCellRenderer.setVerticalAlignment(SWT.CENTER);
    typeCln.setCellRenderer(typeColumnCellRenderer);
    typeCln.setText(Messages.getString("view.MatchViewPart.typeCln"));
    typeCln.setWordWrap(true);
    typeCln.setAlignment(SWT.CENTER);
    typeCln.setResizeable(false);
    final GridColumn targetCln = new GridColumn(gridTable, SWT.NONE);
    targetColumnCellRenderer.setFont(JFaceResources.getFont(net.heartsome.cat.ts.ui.Constants.MATCH_VIEWER_TEXT_FONT));
    targetCln.setCellRenderer(targetColumnCellRenderer);
    targetCln.setText(Messages.getString("view.MatchViewPart.targetCln"));
    targetCln.setWordWrap(true);
    targetCln.setAlignment(SWT.CENTER);
    targetCln.setResizeable(false);
    // 设置可复制功能
    copyEnable = new GridCopyEnable(gridTable);
    sourceColunmCellRenderer.setCopyEnable(copyEnable);
    targetColumnCellRenderer.setCopyEnable(copyEnable);
    Composite statusComposite = new Composite(composite, SWT.NONE);
    GridLayout statusComptGridLayout = new GridLayout(2, false);
    statusComptGridLayout.marginBottom = -1;
    statusComptGridLayout.marginLeft = -1;
    statusComptGridLayout.marginRight = -1;
    statusComptGridLayout.marginTop = -1;
    statusComptGridLayout.marginWidth = 0;
    statusComptGridLayout.marginHeight = 0;
    statusComposite.setLayout(statusComptGridLayout);
    statusComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    tipLabel = new CLabel(statusComposite, SWT.NONE);
    tipLabel.setAlignment(SWT.LEFT);
    infoLabel = new CLabel(statusComposite, SWT.NONE);
    GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
    gd.heightHint = 20;
    infoLabel.setLayoutData(gd);
    infoLabel.setAlignment(SWT.RIGHT);
    // 设置列宽按比例4.5:1:4.5
    composite.addControlListener(new ControlAdapter() {

        public void controlResized(ControlEvent e) {
            Rectangle area = composite.getClientArea();
            Point preferredSize = gridTable.computeSize(SWT.DEFAULT, SWT.DEFAULT);
            // - 2 * gridTable.getBorderWidth();
            int width = area.width;
            if (preferredSize.y > area.height + gridTable.getHeaderHeight()) {
                Point vBarSize = gridTable.getVerticalBar().getSize();
                width -= vBarSize.x;
            }
            gridTable.setSize(area.width, area.height);
            width = width - 42;
            sourceCln.setWidth((int) (width * 0.5));
            typeCln.setWidth(42);
            targetCln.setWidth((int) (width * 0.5));
        }
    });
    gridTable.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            StyledText text = sourceText.getTextWidget();
            text.setText(text.getText());
            updateActionState();
            GridItem[] selItems = gridTable.getSelection();
            if (selItems.length != 1) {
                return;
            }
            GridItem item = selItems[0];
            setMatchMessage(infoLabelImage, item.getData("info").toString(), item.getData("infoTooltip").toString());
            composite.layout();
        }
    });
    gridTable.addListener(SWT.MouseDoubleClick, new Listener() {

        public void handleEvent(Event event) {
            menuMgr.acceptMatchAction.run();
        }
    });
    createActions();
    sashForm.setWeights(new int[] { 3, 8 });
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) SegmentViewer(net.heartsome.cat.ts.ui.innertag.SegmentViewer) StyledText(org.eclipse.swt.custom.StyledText) ISelectionListener(org.eclipse.ui.ISelectionListener) Listener(org.eclipse.swt.widgets.Listener) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) Composite(org.eclipse.swt.widgets.Composite) ControlAdapter(org.eclipse.swt.events.ControlAdapter) Grid(org.eclipse.nebula.widgets.grid.Grid) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font) Point(org.eclipse.swt.graphics.Point) SashForm(org.eclipse.swt.custom.SashForm) GridLayout(org.eclipse.swt.layout.GridLayout) GridItem(org.eclipse.nebula.widgets.grid.GridItem) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridColumn(org.eclipse.nebula.widgets.grid.GridColumn) GridCopyEnable(net.heartsome.cat.ts.ui.grid.GridCopyEnable) ControlEvent(org.eclipse.swt.events.ControlEvent)

Example 22 with Font

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

the class NewFolderDialogOfHs method createFolderNameGroup.

/**
		 * Creates the folder name specification controls.
		 *
		 * @param parent the parent composite
		 */
private void createFolderNameGroup(Composite parent) {
    Font font = parent.getFont();
    // project specification group
    Composite folderGroup = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    folderGroup.setLayout(layout);
    folderGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    // new folder label
    Label folderLabel = new Label(folderGroup, SWT.NONE);
    folderLabel.setFont(font);
    folderLabel.setText(IDEWorkbenchMessages.NewFolderDialog_nameLabel);
    // new folder name entry field
    folderNameField = new Text(folderGroup, SWT.BORDER);
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
    folderNameField.setLayoutData(data);
    folderNameField.setFont(font);
    folderNameField.addListener(SWT.Modify, new Listener() {

        public void handleEvent(Event event) {
            validateLinkedResource();
        }
    });
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Listener(org.eclipse.swt.widgets.Listener) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Text(org.eclipse.swt.widgets.Text) Font(org.eclipse.swt.graphics.Font)

Example 23 with Font

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

the class ConcordanceSearchDialog method createResultsStyle.

private TextStyle createResultsStyle() {
    background = new Color(Display.getCurrent(), 0x19, 0x19, 0x70);
    foreground = new Color(Display.getCurrent(), 0xff, 0xff, 0xff);
    FontData fontData = JFaceResources.getDefaultFont().getFontData()[0];
    fontData.setStyle(fontData.getStyle());
    rsFont = new Font(Display.getDefault(), fontData);
    TextStyle style = new TextStyle(rsFont, foreground, background);
    return style;
}
Also used : TextStyle(org.eclipse.swt.graphics.TextStyle) Color(org.eclipse.swt.graphics.Color) FontData(org.eclipse.swt.graphics.FontData) Font(org.eclipse.swt.graphics.Font)

Example 24 with Font

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

the class TextPainterWithPadding method setFont.

public void setFont(Font font) {
    TextLayout layout = new TextLayout(Display.getDefault());
    try {
        if (font != null) {
            this.font = font;
            Font boldFont = getFont(SWT.BOLD), italicFont = getFont(SWT.ITALIC), boldItalicFont = getFont(SWT.BOLD | SWT.ITALIC);
            layout.setText("    ");
            layout.setFont(font);
            layout.setStyle(new TextStyle(font, null, null), 0, 0);
            layout.setStyle(new TextStyle(boldFont, null, null), 1, 1);
            layout.setStyle(new TextStyle(italicFont, null, null), 2, 2);
            layout.setStyle(new TextStyle(boldItalicFont, null, null), 3, 3);
            FontMetrics metrics = layout.getLineMetrics(0);
            ascent = metrics.getAscent() + metrics.getLeading();
            descent = metrics.getDescent();
            boldFont.dispose();
            italicFont.dispose();
            boldItalicFont.dispose();
            boldFont = italicFont = boldItalicFont = null;
        }
        layout.dispose();
        layout = new TextLayout(Display.getDefault());
        layout.setFont(this.font);
        StringBuffer tabBuffer = new StringBuffer(tabSize);
        for (int i = 0; i < tabSize; i++) {
            tabBuffer.append(' ');
        }
        layout.setText(tabBuffer.toString());
        tabWidth = layout.getBounds().width;
        layout.dispose();
    } finally {
        if (layout != null && !layout.isDisposed()) {
            layout.dispose();
        }
    }
}
Also used : TextStyle(org.eclipse.swt.graphics.TextStyle) FontMetrics(org.eclipse.swt.graphics.FontMetrics) Font(org.eclipse.swt.graphics.Font) Point(org.eclipse.swt.graphics.Point) TextLayout(org.eclipse.swt.graphics.TextLayout)

Example 25 with Font

use of org.eclipse.swt.graphics.Font in project azure-tools-for-java by Microsoft.

the class AzureViewDockerDialog method setTextField.

private void setTextField(Text textField, String text) {
    textField.setText(text != null ? text : "-unknown-");
    textField.setEditable(false);
    //		textField.setBackground(AzureDockerUIResources.getColor(37)); // SWT.COLOR_TRANSPARENT
    FontDescriptor boldDescriptor = FontDescriptor.createFrom(textField.getFont()).setStyle(SWT.BOLD);
    Font boldFont = boldDescriptor.createFont(textField.getDisplay());
    textField.setFont(boldFont);
}
Also used : Font(org.eclipse.swt.graphics.Font) FontDescriptor(org.eclipse.jface.resource.FontDescriptor)

Aggregations

Font (org.eclipse.swt.graphics.Font)113 FontData (org.eclipse.swt.graphics.FontData)38 Composite (org.eclipse.swt.widgets.Composite)29 GridData (org.eclipse.swt.layout.GridData)27 GridLayout (org.eclipse.swt.layout.GridLayout)25 Color (org.eclipse.swt.graphics.Color)20 Label (org.eclipse.swt.widgets.Label)17 Point (org.eclipse.swt.graphics.Point)14 SelectionEvent (org.eclipse.swt.events.SelectionEvent)11 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)10 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)9 FormData (org.eclipse.swt.layout.FormData)9 Text (org.eclipse.swt.widgets.Text)9 Rectangle (org.eclipse.swt.graphics.Rectangle)8 FormAttachment (org.eclipse.swt.layout.FormAttachment)8 Button (org.eclipse.swt.widgets.Button)8 StyledText (org.eclipse.swt.custom.StyledText)6 CLabel (org.eclipse.swt.custom.CLabel)5 FillLayout (org.eclipse.swt.layout.FillLayout)5 ColorStyledText (org.talend.commons.ui.swt.colorstyledtext.ColorStyledText)5