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); } }
/** * 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); } }
@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; }
@Override public Point textExtent ( final String string ) { final Dimension result = TextUtilities.INSTANCE.getTextExtents ( string, this.g.getFont () ); return new Point ( result.width, result.height ); }
/** * * 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; }
/** * 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(); }
/** * 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; }
/** * 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; }
/** * 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; }