Java 类org.eclipse.draw2d.TextUtilities 实例源码

项目:Hydrograph    文件:UiConverterUtil.java   
private void adjustComponentFigure(Component component) {
    Font font = new Font( Display.getDefault(), ModelConstants.labelFont, 10,
            SWT.NORMAL );
    int labelLength = TextUtilities.INSTANCE.getStringExtents(component.getComponentLabel().getLabelContents(), font).width;
    if(labelLength >= ModelConstants.compLabelOneLineLengthLimit && component.getSize().height<96 ){
        component.setSize(new Dimension(component.getSize().width, component.getSize().height + ModelConstants.componentOneLineLabelMargin));
        ComponentLabel componentLabel = component.getComponentLabel();
        componentLabel.setSize(new Dimension(componentLabel.getSize().width, componentLabel.getSize().height + ModelConstants.componentOneLineLabelMargin));
        component.setComponentLabelMargin(ModelConstants.componentTwoLineLabelMargin);
    }
}
项目:Hydrograph    文件:ComponentLabelFigure.java   
/**
 * Sets the text of the TextFlow to the given value.
 * 
 * @param newText
 *            the new text value.
 */
public void setText(String newText) {
    textFlow.setText(newText);
    Dimension lineDimensions = TextUtilities.INSTANCE.getStringExtents(textFlow.getText(), getFont());
    if(lineDimensions.width >= ELTFigureConstants.compLabelOneLineLengthLimitForText)
    {
        getBounds().setSize(ELTFigureConstants.compLabelOneLineLengthLimitForText, ELTFigureConstants.componentTwoLineLabelMargin);
    }else if(lineDimensions.width < ELTFigureConstants.compLabelOneLineLengthLimitForText){
        getBounds().setSize(ELTFigureConstants.compLabelOneLineLengthLimitForText, ELTFigureConstants.componentOneLineLabelMargin);
    }
}
项目:statecharts    文件:SyntaxColoringLabel.java   
@Override
public FlowUtilitiesEx getFlowUtilities() {
    if (flowUtilities == null) {
        flowUtilities = new FlowUtilitiesEx(MapModeUtil.getMapMode(this)) {
            @Override
            protected TextUtilities getTextUtilities() {
                if (textUtilities == null) {
                    textUtilities = new StyleTextUtilities(MapModeUtil.getMapMode(StyledTextFlow.this));
                }
                return textUtilities;
            }
        };
    }
    return flowUtilities;
}
项目:neoscada    文件:Draw2DGraphics.java   
@Override
public Point textExtent ( final String string )
{
    final Dimension result = TextUtilities.INSTANCE.getTextExtents ( string, this.g.getFont () );
    return new Point ( result.width, result.height );
}
项目:Hydrograph    文件:Container.java   
/**
 * 
 * Add a component to this graph.
 * 
 * @param component
 *            the component
 * @return true, if the component was successfully added, false otherwise
 *
 */
public boolean addChild(Component component) {
    String compNewName=generateUniqueComponentName(component);
    String componentId= generateUniqueComponentId(component);
    if(component != null){
        if (canAddSubjobToCanvas(component.getComponentName())
            && components.add(component)) {
        component.setParent(this);

        //Check length and increment height
        Font font = new Font( Display.getDefault(), ModelConstants.labelFont, 10,
                SWT.NORMAL );
        int labelLength = TextUtilities.INSTANCE.getStringExtents(compNewName, font).width;
        ComponentLabel componentLabel = component.getComponentLabel();
        if(labelLength >= ModelConstants.compLabelOneLineLengthLimit && component.getSize().height<96 && labelLength!=97){
            component.setSize(new Dimension(component.getSize().width, component.getSize().height + ModelConstants.componentOneLineLabelMargin));
            componentLabel.setSize(new Dimension(componentLabel.getSize().width, componentLabel.getSize().height + ModelConstants.componentOneLineLabelMargin));
            component.setComponentLabelMargin(ModelConstants.componentTwoLineLabelMargin);
        }
        else{
            if(labelLength<ModelConstants.compLabelOneLineLengthLimit){
                if(!(component.getSize().height>96)){
            component.setSize(new Dimension(component.getSize().width,80));
                }
                else{
                    component.setSize(new Dimension(component.getSize().width,component.getSize().height));
                }
            }
        }

        component.setComponentLabel(compNewName);
        component.setComponentId(componentId);

        if (component.isNewInstance()) {
            component.setNewInstance(false);
        }
        firePropertyChange(CHILD_ADDED_PROP, null, component);
        updateSubjobVersion();
        return true;
        }
    }
    return false;
}
项目:Hydrograph    文件:ComponentFigure.java   
/**
 * Instantiates a new component figure.
 * 
 * @param portDetails
 *            the port details
 * @param cIconPath
 *            the canvas icon path
 * @param label
 *            Label to be displayed on component
 * @param acronym
 *            Acronym to be displayed on component
 * @param linkedHashMap
 *            the properties of components
 */

    public ComponentFigure(Component component, String cIconPath, String label, String acronym,
            LinkedHashMap<String, Object> properties) {
    this.canvasIconPath = XMLConfigUtil.CONFIG_FILES_PATH + cIconPath;
    this.acronym = acronym;
    this.componentProperties = properties;
    layout = new XYLayout();
    setLayoutManager(layout);

    labelFont = new Font(Display.getDefault(), ELTFigureConstants.labelFont, 9, SWT.NORMAL);
    int labelLength = TextUtilities.INSTANCE.getStringExtents(label, labelFont).width;

    if (labelLength >= ELTFigureConstants.compLabelOneLineLengthLimitForText) {
        this.componentLabelMargin = ELTFigureConstants.componentTwoLineLabelMargin;
        this.incrementedHeight = true;
    } else if (labelLength < ELTFigureConstants.compLabelOneLineLengthLimitForText) {
        this.componentLabelMargin = ELTFigureConstants.componentOneLineLabelMargin;
        this.incrementedHeight = false;
    }

    canvasIcon = new Image(null, canvasIconPath);
    this.component=component;
    connectionAnchors = new HashMap<String, FixedConnectionAnchor>();
    inputConnectionAnchors = new ArrayList<FixedConnectionAnchor>();
    outputConnectionAnchors = new ArrayList<FixedConnectionAnchor>();

    setInitialColor();
    setComponentColorAndBorder();

    for (PortDetails pDetail : component.getPortDetails()) {
        setPortCount(pDetail);
        setHeight(totalPortsAtLeftSide, totalPortsAtRightSide);
        setWidth(totalPortsAtBottonSide);
    }

    acronymFont = new Font(Display.getDefault(), ELTFigureConstants.labelFont, 8, SWT.BOLD);
    setFont(acronymFont);
    setForegroundColor(org.eclipse.draw2d.ColorConstants.black);

    componentCanvas = getComponentCanvas();
    attachMouseListener();
}
项目:NEXCORE-UML-Modeler    文件:CollapsedLabel.java   
/**
 * Gets the <code>TextUtilities</code> instance to be used in measurement
 * calculations.
 * 
 * @return a <code>TextUtilities</code> instance
 * @since 3.4
 */
public TextUtilities getTextUtilities() {
    return TextUtilities.INSTANCE;
}
项目:gef-gwt    文件:FlowUtilities.java   
/**
 * Returns an instance of a <code>TextUtililities</code> class on which text
 * calculations can be performed. Clients may override to customize.
 * 
 * @return the <code>TextUtililities</code> instance
 * @since 3.4
 */
protected TextUtilities getTextUtilities() {
    return TextUtilities.INSTANCE;
}
项目:gef-gwt    文件:TextFlow.java   
/**
 * Gets the <code>TextUtilities</code> instance to be used in measurement
 * calculations.
 * 
 * @return a <code>TextUtilities</code> instance
 * @since 3.4
 */
protected TextUtilities getTextUtilities() {
    return TextUtilities.INSTANCE;
}