Search in sources :

Example 21 with GC

use of org.eclipse.swt.graphics.GC in project otertool by wuntee.

the class SWTResourceManager method decorateImage.

/**
	 * Returns an {@link Image} composed of a base image decorated by another image.
	 * 
	 * @param baseImage
	 *            the base {@link Image} that should be decorated
	 * @param decorator
	 *            the {@link Image} to decorate the base image
	 * @param corner
	 *            the corner to place decorator image
	 * @return the resulting decorated {@link Image}
	 */
public static Image decorateImage(final Image baseImage, final Image decorator, final int corner) {
    if (corner <= 0 || corner >= LAST_CORNER_KEY) {
        throw new IllegalArgumentException("Wrong decorate corner");
    }
    Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[corner];
    if (cornerDecoratedImageMap == null) {
        cornerDecoratedImageMap = new HashMap<Image, Map<Image, Image>>();
        m_decoratedImageMap[corner] = cornerDecoratedImageMap;
    }
    Map<Image, Image> decoratedMap = cornerDecoratedImageMap.get(baseImage);
    if (decoratedMap == null) {
        decoratedMap = new HashMap<Image, Image>();
        cornerDecoratedImageMap.put(baseImage, decoratedMap);
    }
    //
    Image result = decoratedMap.get(decorator);
    if (result == null) {
        Rectangle bib = baseImage.getBounds();
        Rectangle dib = decorator.getBounds();
        //
        result = new Image(Display.getCurrent(), bib.width, bib.height);
        //
        GC gc = new GC(result);
        gc.drawImage(baseImage, 0, 0);
        if (corner == TOP_LEFT) {
            gc.drawImage(decorator, 0, 0);
        } else if (corner == TOP_RIGHT) {
            gc.drawImage(decorator, bib.width - dib.width, 0);
        } else if (corner == BOTTOM_LEFT) {
            gc.drawImage(decorator, 0, bib.height - dib.height);
        } else if (corner == BOTTOM_RIGHT) {
            gc.drawImage(decorator, bib.width - dib.width, bib.height - dib.height);
        }
        gc.dispose();
        //
        decoratedMap.put(decorator, result);
    }
    return result;
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC) HashMap(java.util.HashMap) Map(java.util.Map)

Example 22 with GC

use of org.eclipse.swt.graphics.GC in project otertool by wuntee.

the class SWTResourceManager method getMissingImage.

/**
	 * @return the small {@link Image} that can be used as placeholder for missing image.
	 */
private static Image getMissingImage() {
    Image image = new Image(Display.getCurrent(), MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE);
    //
    GC gc = new GC(image);
    gc.setBackground(getColor(SWT.COLOR_RED));
    gc.fillRectangle(0, 0, MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE);
    gc.dispose();
    //
    return image;
}
Also used : Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC)

Example 23 with GC

use of org.eclipse.swt.graphics.GC in project lwjgl by LWJGL.

the class FpsStatusLineItem method getWidthHint.

private int getWidthHint(Composite control) {
    if (m_fixedWidth < 0) {
        GC gc = new GC(control);
        gc.setFont(control.getFont());
        m_fixedWidth = gc.getFontMetrics().getAverageCharWidth() * CHAR_WIDTH;
        m_fixedWidth += INDENT * 2;
        gc.dispose();
    }
    return m_fixedWidth;
}
Also used : GC(org.eclipse.swt.graphics.GC)

Example 24 with GC

use of org.eclipse.swt.graphics.GC in project tdi-studio-se by Talend.

the class IconSelectionController method createControl.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.designer.core.ui.editor.properties2.editors.AbstractElementPropertySectionController#createControl()
     */
@Override
public Control createControl(final Composite subComposite, final IElementParameter param, final int numInRow, final int nbInRow, final int top, final Control lastControl) {
    this.curParameter = param;
    FormData data;
    //$NON-NLS-1$        
    Button btnEdit = getWidgetFactory().createButton(subComposite, "", SWT.PUSH);
    btnEdit.setImage(ImageProvider.getImage(CoreUIPlugin.getImageDescriptor(DOTS_BUTTON)));
    data = new FormData();
    data.left = new FormAttachment(0, 120);
    data.top = new FormAttachment(0, top);
    data.height = STANDARD_HEIGHT - 2;
    btnEdit.setLayoutData(data);
    btnEdit.setData(NAME, ICON_SELECTION);
    btnEdit.setData(PARAMETER_NAME, param.getName());
    btnEdit.setEnabled(!param.isReadOnly());
    btnEdit.addSelectionListener(listenerSelection);
    DecoratedField dField = new DecoratedField(subComposite, SWT.NONE, new IControlCreator() {

        @Override
        public Control createControl(Composite parent, int style) {
            return new Label(parent, style);
        }
    });
    // revert btn
    Button btnRevert = getWidgetFactory().createButton(subComposite, Messages.getString("IconSelectionController.Revert"), //$NON-NLS-1$
    SWT.PUSH);
    data = new FormData();
    data.left = new FormAttachment(btnEdit, 5);
    data.top = new FormAttachment(0, top);
    data.height = STANDARD_HEIGHT - 2;
    btnRevert.setLayoutData(data);
    btnRevert.setData(NAME, ICON_REVERT);
    btnRevert.setData(PARAMETER_NAME, param.getName());
    btnRevert.setEnabled(!param.isReadOnly());
    btnRevert.addSelectionListener(listenerSelection);
    if (param.isRequired()) {
        FieldDecoration decoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED);
        dField.addFieldDecoration(decoration, SWT.RIGHT | SWT.TOP, false);
    }
    if (param.isRepositoryValueUsed()) {
        FieldDecoration decoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
        //$NON-NLS-1$
        decoration.setDescription(Messages.getString("FileController.decoration.description"));
        dField.addFieldDecoration(decoration, SWT.RIGHT | SWT.BOTTOM, false);
    }
    Control cLayout = dField.getLayoutControl();
    filePathText = (Label) dField.getControl();
    String file = (String) elem.getPropertyValue(PARAMETER_NAME);
    if (file != null) {
    // ImageData imageData = new ImageData(file);
    // image = new Image(composite.getShell().getDisplay(), imageData);
    // filePathText.setImage(image);
    }
    CLabel labelLabel = getWidgetFactory().createCLabel(subComposite, param.getDisplayName(), 0);
    data = new FormData();
    if (lastControl != null) {
        data.left = new FormAttachment(lastControl, 0);
    } else {
        data.left = new FormAttachment((((numInRow - 1) * MAX_PERCENT) / nbInRow), 0);
    }
    data.top = new FormAttachment(0, top);
    labelLabel.setLayoutData(data);
    if (numInRow != 1) {
        labelLabel.setAlignment(SWT.RIGHT);
    }
    // **************************
    data = new FormData();
    int currentLabelWidth = 50;
    GC gc = new GC(labelLabel);
    Point labelSize = gc.stringExtent(param.getDisplayName());
    gc.dispose();
    if ((labelSize.x + ITabbedPropertyConstants.HSPACE) > currentLabelWidth) {
        currentLabelWidth = labelSize.x + ITabbedPropertyConstants.HSPACE;
    }
    if (numInRow == 1) {
        if (lastControl != null) {
            data.left = new FormAttachment(lastControl, currentLabelWidth);
        } else {
            data.left = new FormAttachment(0, currentLabelWidth);
        }
    } else {
        data.left = new FormAttachment(labelLabel, 0, SWT.RIGHT);
    }
    data.top = new FormAttachment(btnEdit, 0, SWT.CENTER);
    data.height = 34;
    data.width = 30;
    cLayout.setLayoutData(data);
    Point initialSize = dField.getLayoutControl().computeSize(SWT.DEFAULT, SWT.DEFAULT);
    dynamicProperty.setCurRowSize(initialSize.y + ITabbedPropertyConstants.VSPACE);
    return btnEdit;
}
Also used : FormData(org.eclipse.swt.layout.FormData) CLabel(org.eclipse.swt.custom.CLabel) Composite(org.eclipse.swt.widgets.Composite) FieldDecoration(org.eclipse.jface.fieldassist.FieldDecoration) CLabel(org.eclipse.swt.custom.CLabel) Label(org.eclipse.swt.widgets.Label) DecoratedField(org.eclipse.jface.fieldassist.DecoratedField) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) IControlCreator(org.eclipse.jface.fieldassist.IControlCreator) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) GC(org.eclipse.swt.graphics.GC) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 25 with GC

use of org.eclipse.swt.graphics.GC in project tdi-studio-se by Talend.

the class DbTypeListController method createControl.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.designer.core.ui.editor.properties2.editors.AbstractElementPropertySectionController#createControl()
     */
@Override
public Control createControl(final Composite subComposite, final IElementParameter param, final int numInRow, final int nbInRow, final int top, final Control lastControl) {
    this.curParameter = param;
    this.paramFieldType = param.getFieldType();
    DecoratedField dField = new DecoratedField(subComposite, SWT.BORDER, cbCtrl);
    if (param.isRequired()) {
        FieldDecoration decoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED);
        dField.addFieldDecoration(decoration, SWT.RIGHT | SWT.TOP, false);
    }
    Control cLayout = dField.getLayoutControl();
    CCombo combo = (CCombo) dField.getControl();
    FormData data;
    combo.setEditable(false);
    cLayout.setBackground(subComposite.getBackground());
    combo.setEnabled(!param.isReadOnly());
    combo.addSelectionListener(listenerSelection);
    if (elem instanceof Node) {
        combo.setToolTipText(VARIABLE_TOOLTIP + param.getVariableName());
    }
    CLabel labelLabel = getWidgetFactory().createCLabel(subComposite, param.getDisplayName());
    data = new FormData();
    if (lastControl != null) {
        data.left = new FormAttachment(lastControl, 0);
    } else {
        data.left = new FormAttachment((((numInRow - 1) * MAX_PERCENT) / nbInRow), 0);
    }
    data.top = new FormAttachment(0, top);
    labelLabel.setLayoutData(data);
    if (numInRow != 1) {
        labelLabel.setAlignment(SWT.RIGHT);
    }
    // *********************
    data = new FormData();
    int currentLabelWidth = STANDARD_LABEL_WIDTH;
    GC gc = new GC(labelLabel);
    Point labelSize = gc.stringExtent(param.getDisplayName());
    gc.dispose();
    if ((labelSize.x + ITabbedPropertyConstants.HSPACE) > currentLabelWidth) {
        currentLabelWidth = labelSize.x + ITabbedPropertyConstants.HSPACE;
    }
    if (numInRow == 1) {
        if (lastControl != null) {
            data.left = new FormAttachment(lastControl, currentLabelWidth);
        } else {
            data.left = new FormAttachment(0, currentLabelWidth);
        }
    } else {
        data.left = new FormAttachment(labelLabel, 0, SWT.RIGHT);
    }
    data.top = new FormAttachment(0, top);
    cLayout.setLayoutData(data);
    Point initialSize = dField.getLayoutControl().computeSize(SWT.DEFAULT, SWT.DEFAULT);
    // **********************
    hashCurControls.put(param.getName(), combo);
    updateData();
    // this.dynamicTabbedPropertySection.updateColumnList(null);
    dynamicProperty.setCurRowSize(initialSize.y + ITabbedPropertyConstants.VSPACE);
    return cLayout;
}
Also used : FormData(org.eclipse.swt.layout.FormData) CLabel(org.eclipse.swt.custom.CLabel) Control(org.eclipse.swt.widgets.Control) CCombo(org.eclipse.swt.custom.CCombo) FieldDecoration(org.eclipse.jface.fieldassist.FieldDecoration) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) DecoratedField(org.eclipse.jface.fieldassist.DecoratedField) Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) FormAttachment(org.eclipse.swt.layout.FormAttachment) Point(org.eclipse.swt.graphics.Point)

Aggregations

GC (org.eclipse.swt.graphics.GC)122 Point (org.eclipse.swt.graphics.Point)90 FormAttachment (org.eclipse.swt.layout.FormAttachment)46 FormData (org.eclipse.swt.layout.FormData)46 CLabel (org.eclipse.swt.custom.CLabel)42 Node (org.talend.designer.core.ui.editor.nodes.Node)39 Control (org.eclipse.swt.widgets.Control)31 Rectangle (org.eclipse.swt.graphics.Rectangle)29 DecoratedField (org.eclipse.jface.fieldassist.DecoratedField)28 FieldDecoration (org.eclipse.jface.fieldassist.FieldDecoration)27 Image (org.eclipse.swt.graphics.Image)27 Button (org.eclipse.swt.widgets.Button)24 Composite (org.eclipse.swt.widgets.Composite)18 CCombo (org.eclipse.swt.custom.CCombo)16 Text (org.eclipse.swt.widgets.Text)12 SelectionEvent (org.eclipse.swt.events.SelectionEvent)11 GridData (org.eclipse.swt.layout.GridData)11 SelectAllTextControlCreator (org.talend.designer.core.ui.editor.properties.controllers.creator.SelectAllTextControlCreator)11 INode (org.talend.core.model.process.INode)10 Label (org.eclipse.swt.widgets.Label)9