Java Code Examples for org.eclipse.draw2d.FigureUtilities#getTextExtents()
The following examples show how to use
org.eclipse.draw2d.FigureUtilities#getTextExtents() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RoundScaleTickLabels.java From nebula with Eclipse Public License 2.0 | 6 votes |
/** * Updates the the draw area of each label. */ private void updateTickLabelAreas() { int labelRadius; tickLabelAreas.clear(); for(int i=0; i<tickLabelPositions.size(); i++) { Dimension ls = FigureUtilities.getTextExtents(tickLabels.get(i), scale.getFont()); if(scale.getTickLabelSide() == LabelSide.Primary) labelRadius = (int) (scale.getRadius() + RoundScaleTickMarks.MAJOR_TICK_LENGTH + RoundScale.SPACE_BTW_MARK_LABEL + ls.width/2.0 * Math.abs(Math.cos(tickLabelPositions.get(i))) + ls.height/2.0 * Math.abs(Math.sin(tickLabelPositions.get(i)))); else labelRadius = (int) (scale.getRadius() - RoundScaleTickMarks.MAJOR_TICK_LENGTH - RoundScale.SPACE_BTW_MARK_LABEL - ls.width/2.0 * Math.abs(Math.cos(tickLabelPositions.get(i))) - ls.height/2.0 * Math.abs(Math.sin(tickLabelPositions.get(i)))); Point lp = new PolarPoint(labelRadius, tickLabelPositions.get(i)).toRelativePoint( scale.getBounds()); tickLabelAreas.add(new Rectangle(lp.x - ls.width/2, lp.y - ls.height/2, ls.width, ls.height)); } }
Example 2
Source File: ShowDragInfomationProcessor.java From birt with Eclipse Public License 1.0 | 6 votes |
public void updateInfomation(String label, Point p) { if (labelFigure == null) { return; } labelFigure.setText( label ); Dimension size = FigureUtilities.getTextExtents( label, labelFigure.getFont( ) ); //Insets insets = getInfomationLabel( ).getInsets( ); Insets insets = INSETS; Dimension newSize = size.getCopy( ).expand( insets.getWidth( ), insets.getHeight( ) ) ; if (size.width > maxWidth) { maxWidth = size.width; } else { newSize = new Dimension(maxWidth, size.height).expand( insets.getWidth( ), insets.getHeight( ) ); } labelFigure.setSize( newSize); setLabelLocation( p ); adjustLocation( p ); }
Example 3
Source File: LinearScaleTickLabels.java From nebula with Eclipse Public License 2.0 | 6 votes |
/** * Draw the Y tick. To be overridden if needed. * * @param graphics * the graphics context */ protected void drawYTick(Graphics graphics) { // draw tick labels graphics.setFont(scale.getFont()); int fontHeight = ticks.getMaxHeight(); for (int i = 0; i < ticks.getPositions().size(); i++) { if (ticks.getLabels().isEmpty()) { break; } if (ticks.isVisible(i)) { String label = ticks.getLabel(i); int x = 0; if (ticks.getLabel(0).startsWith(MINUS) && !label.startsWith(MINUS)) { x += FigureUtilities.getTextExtents(MINUS, getFont()).width; } int y = (int) Math.ceil(scale.getLength() - ticks.getPosition(i) - fontHeight / 2.0); graphics.drawText(label, x, y); } } }
Example 4
Source File: EditorDragGuidePolicy.java From birt with Eclipse Public License 1.0 | 6 votes |
protected void updateInfomation(String label) { if (infoLabel == null) { return; } infoLabel.setText( label ); Dimension size = FigureUtilities.getTextExtents( label, infoLabel.getFont( ) ); //Insets insets = getInfomationLabel( ).getInsets( ); Insets insets = INSETS; Dimension newSize = size.getCopy( ).expand( insets.getWidth( ), insets.getHeight( ) ) ; if (size.width > maxWidth) { maxWidth = size.width; } else { newSize = new Dimension(maxWidth, size.height).expand( insets.getWidth( ), insets.getHeight( ) ); } infoLabel.setSize( newSize); setLabelLocation( ); adjustLocation( ); }
Example 5
Source File: LinearScaledMarker.java From nebula with Eclipse Public License 2.0 | 6 votes |
/** * updates marker elements of ticks */ public void updateMarkerElements() { labels = new String[markersMap.size()]; markerColorsList.clear(); markerValues = new double[markersMap.size()]; markerLabelDimensions = new Dimension[markersMap.size()]; markerPositions = new int[markerValues.length]; int i = 0; for (String label : markersMap.keySet()) { labels[i] = label; markerValues[i] = markersMap.get(label).value; markerPositions[i] = scale.getValuePosition(markerValues[i], true); markerLabelDimensions[i] = FigureUtilities.getTextExtents(label, getFont()); markerColorsList.add(XYGraphMediaFactory.getInstance().getColor(markersMap.get(label).color)); i++; } }
Example 6
Source File: LinearScaledMarker.java From nebula with Eclipse Public License 2.0 | 6 votes |
@Override public Dimension getPreferredSize(int wHint, int hHint) { updateTick(); Dimension size = new Dimension(wHint, hHint); if (scale.isHorizontal()) { size.width = scale.getSize().width; size.height = FigureUtilities.getTextExtents("dummy", getFont()).height + GAP_BTW_MARK_LABEL + TICK_LENGTH; } else { updateTickLabelMaxLength(); size.width = (int) tickLabelMaxLength + GAP_BTW_MARK_LABEL + TICK_LENGTH; size.height = scale.getSize().height; } return size; }
Example 7
Source File: LinearScaleTicks.java From nebula with Eclipse Public License 2.0 | 6 votes |
/** * If it has enough space to draw the tick label */ private boolean hasSpaceToDraw(int previousPosition, int tickLabelPosition, String previousTickLabel, String tickLabel) { Dimension tickLabelSize = FigureUtilities.getTextExtents(tickLabel, scale.getFont()); Dimension previousTickLabelSize = FigureUtilities.getTextExtents(previousTickLabel, scale.getFont()); int interval = tickLabelPosition - previousPosition; int textLength = (int) (scale.isHorizontal() ? (tickLabelSize.width / 2.0 + previousTickLabelSize.width / 2.0) : tickLabelSize.height); boolean noLapOnPrevoius = true; boolean noLapOnEnd = true; // if it is not the end tick label if (tickLabelPosition != tickLabelPositions.get(tickLabelPositions.size() - 1)) { noLapOnPrevoius = interval > (textLength + TICK_LABEL_GAP); Dimension endTickLabelSize = FigureUtilities.getTextExtents(tickLabels.get(tickLabels.size() - 1), scale.getFont()); interval = tickLabelPositions.get(tickLabelPositions.size() - 1) - tickLabelPosition; textLength = (int) (scale.isHorizontal() ? (tickLabelSize.width / 2.0 + endTickLabelSize.width / 2.0) : tickLabelSize.height); noLapOnEnd = interval > textLength + TICK_LABEL_GAP; } return noLapOnPrevoius && noLapOnEnd; }
Example 8
Source File: LinearScaleTicks.java From nebula with Eclipse Public License 2.0 | 6 votes |
/** * Gets max length of tick label. */ private void updateTickLabelMaxLengthAndHeight() { int maxLength = 0; int maxHeight = 0; for (int i = 0; i < tickLabels.size(); i++) { if (tickLabelVisibilities.size() > i && tickLabelVisibilities.get(i)) { Dimension p = FigureUtilities.getTextExtents(tickLabels.get(i), scale.getFont()); if (tickLabels.get(0).startsWith(MINUS) && !tickLabels.get(i).startsWith(MINUS)) { p.width += FigureUtilities.getTextExtents(MINUS, scale.getFont()).width; } if (p.width > maxLength) { maxLength = p.width; } if (p.height > maxHeight) { maxHeight = p.height; } } } tickLabelMaxLength = maxLength; tickLabelMaxHeight = maxHeight; }
Example 9
Source File: Axis.java From nebula with Eclipse Public License 2.0 | 6 votes |
@Override public Dimension getPreferredSize(final int wHint, final int hHint) { final Dimension d = super.getPreferredSize(wHint, hHint); if (isVisible()) { if (title != null) { if (isHorizontal()) d.height += FigureUtilities.getTextExtents(title, titleFont).height; else d.width += FigureUtilities.getTextExtents(title, titleFont).height; } } else { // Not visible, flatten it to use zero height resp. width if (isHorizontal()) d.height = 0; else d.width = 0; } return d; }
Example 10
Source File: Legend.java From nebula with Eclipse Public License 2.0 | 6 votes |
private int drawLegendOrComputeHeight(Graphics graphics, int upperMargin, boolean draw) { int hPos = bounds.x + INNER_GAP; int vPos = bounds.y + INNER_GAP + upperMargin; int i = 0; int totalHeight = ICON_WIDTH + INNER_GAP; for (Trace trace : traceList) { if (!trace.isVisible()) continue; int hwidth = OUT_GAP + ICON_WIDTH + INNER_GAP + +FigureUtilities.getTextExtents(trace.getName(), font==null?super.getFont():font).width; int hEnd = hPos + hwidth; if (hEnd > (bounds.x + bounds.width) && i > 0) { hPos = bounds.x + INNER_GAP; vPos += ICON_WIDTH + INNER_GAP; totalHeight += ICON_WIDTH + INNER_GAP; hEnd = hPos + hwidth; } if (draw) { drawTraceLegend(trace, graphics, hPos, vPos); } hPos = hEnd; i++; } return totalHeight; }
Example 11
Source File: TableViewGraphicalNodeEditPolicy.java From ermaster-b with Apache License 2.0 | 5 votes |
@Override public void showTargetFeedback(Request request) { ERDiagram diagram = ERModelUtil.getDiagram(this.getHost().getRoot().getContents()); if (diagram.isTooltip()) { ZoomManager zoomManager = ((ScalableFreeformRootEditPart) this .getHost().getRoot()).getZoomManager(); double zoom = zoomManager.getZoom(); TableView tableView = (TableView) this.getHost().getModel(); Rectangle tableBounds = this.getHostFigure().getBounds(); String name = TableViewEditPart.getTableViewName(tableView, diagram); Label label = new Label(); label.setText(name); label.setBorder(new SimpleRaisedBorder()); label.setBackgroundColor(ColorConstants.orange); label.setOpaque(true); Dimension dim = FigureUtilities.getTextExtents(name, Display .getCurrent().getSystemFont()); label.setBounds(new Rectangle((int) (zoom * (tableBounds.x + 33)), (int) (zoom * (tableBounds.y + 5)), (int) (dim.width * 1.5), 20)); this.addFeedback(label); } super.showTargetFeedback(request); }
Example 12
Source File: TableViewGraphicalNodeEditPolicy.java From erflute with Apache License 2.0 | 5 votes |
@Override public void showTargetFeedback(Request request) { final ERDiagram diagram = ERModelUtil.getDiagram(getHost().getRoot().getContents()); if (diagram.isTooltip()) { final ZoomManager zoomManager = ((ScalableFreeformRootEditPart) getHost().getRoot()).getZoomManager(); final double zoom = zoomManager.getZoom(); final TableView tableView = (TableView) getHost().getModel(); final Rectangle tableBounds = getHostFigure().getBounds(); final String name = TableViewEditPart.getTableViewName(tableView, diagram); final Label label = new Label(); label.setText(name); label.setBorder(new SimpleRaisedBorder()); label.setBackgroundColor(ColorConstants.orange); label.setOpaque(true); final Dimension dim = FigureUtilities.getTextExtents(name, Display.getCurrent().getSystemFont()); label.setBounds(new Rectangle( (int) (zoom * (tableBounds.x + 33)), (int) (zoom * (tableBounds.y + 5)), (int) (dim.width * 1.5), 20)); addFeedback(label); } super.showTargetFeedback(request); }
Example 13
Source File: TableViewGraphicalNodeEditPolicy.java From ermasterr with Apache License 2.0 | 5 votes |
@Override public void showTargetFeedback(final Request request) { final ERDiagram diagram = (ERDiagram) getHost().getRoot().getContents().getModel(); if (diagram.isTooltip()) { final ZoomManager zoomManager = ((ScalableFreeformRootEditPart) getHost().getRoot()).getZoomManager(); final double zoom = zoomManager.getZoom(); final TableView tableView = (TableView) getHost().getModel(); final Rectangle tableBounds = getHostFigure().getBounds(); final String name = TableViewEditPart.getTableViewName(tableView, diagram); final Label label = new Label(); label.setText(name); label.setBorder(new SimpleRaisedBorder()); label.setBackgroundColor(ColorConstants.orange); label.setOpaque(true); final Dimension dim = FigureUtilities.getTextExtents(name, Display.getCurrent().getSystemFont()); label.setBounds(new Rectangle((int) (zoom * (tableBounds.x + 33)), (int) (zoom * (tableBounds.y + 5)), (int) (dim.width * 1.5), 20)); addFeedback(label); } super.showTargetFeedback(request); }
Example 14
Source File: Legend.java From nebula with Eclipse Public License 2.0 | 5 votes |
@Override public Dimension getPreferredSize(int wHint, int hHint) { int maxWidth = 0; int hEnd = INNER_GAP; int height = ICON_WIDTH + INNER_GAP; // int i=0; for (Trace trace : traceList) { if (!trace.isVisible()) continue; hEnd = hEnd + OUT_GAP + ICON_WIDTH + INNER_GAP + +FigureUtilities.getTextExtents(trace.getName(), font==null?super.getFont():font).width; if (hEnd > wHint) { hEnd = INNER_GAP + OUT_GAP + ICON_WIDTH + INNER_GAP + +FigureUtilities.getTextExtents(trace.getName(), font==null?super.getFont():font).width; height += ICON_WIDTH + INNER_GAP; } if (maxWidth < hEnd) maxWidth = hEnd; } if (preferredHeight != -1) { height=preferredHeight; } return new Dimension(maxWidth, height); }
Example 15
Source File: LinearScale.java From nebula with Eclipse Public License 2.0 | 5 votes |
/** * Calculate dimension of a textual form of object * * @param obj * object * @return dimension */ @Override public Dimension getDimension(Object obj) { if (obj == null) return new Dimension(); if (obj instanceof String) return FigureUtilities.getTextExtents((String) obj, getFont()); return FigureUtilities.getTextExtents(format(obj), getFont()); }
Example 16
Source File: LinearScaledMarker.java From nebula with Eclipse Public License 2.0 | 5 votes |
/** * Gets max length of tick label. */ private void updateTickLabelMaxLength() { int maxLength = 0; for (int i = 0; i < labels.length; i++) { Dimension p = FigureUtilities.getTextExtents(labels[i], scale.getFont()); if (p.width > maxLength) { maxLength = p.width; } } tickLabelMaxLength = maxLength; }
Example 17
Source File: LinearScaleTickLabels.java From nebula with Eclipse Public License 2.0 | 5 votes |
/** * Draw the X tick. To be overridden if needed. * * @param graphics * the graphics context */ protected void drawXTick(Graphics graphics) { // draw tick labels graphics.setFont(scale.getFont()); for (int i = 0; i < ticks.getPositions().size(); i++) { if (ticks.isVisible(i) == true) { String text = ticks.getLabel(i); int fontWidth = FigureUtilities.getTextExtents(text, getFont()).width; int x = (int) Math.ceil(ticks.getLabelPosition(i) - fontWidth / 2.0);// + // offset); graphics.drawText(text, x, 0); } } }
Example 18
Source File: ThermometerFigure.java From nebula with Eclipse Public License 2.0 | 5 votes |
@Override protected void fillShape(Graphics graphics) { graphics.setAntialias(SWT.ON); boolean support3D = false; if(effect3D) support3D = GraphicsUtil.testPatternSupported(graphics); if(effect3D && support3D){ graphics.setBackgroundColor(fillColor); super.fillShape(graphics); //int l = (int) ((bounds.width - lineWidth)*0.293/2); Pattern backPattern = null; backPattern = GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(), bounds.x + lineWidth, bounds.y + lineWidth, bounds.x+bounds.width-lineWidth, bounds.y+bounds.height-lineWidth, WHITE_COLOR,255, fillColor, 0); graphics.setBackgroundPattern(backPattern); super.fillShape(graphics); backPattern.dispose(); }else{ graphics.setBackgroundColor(fillColor); super.fillShape(graphics); } String valueString = getValueText(); Dimension valueSize = FigureUtilities.getTextExtents(valueString, getFont()); if(valueSize.width < bounds.width) { graphics.setForegroundColor(contrastFillColor); graphics.drawText(valueString, new Point( bounds.x + bounds.width/2 - valueSize.width/2, bounds.y + bounds.height/2 - valueSize.height/2)); } }
Example 19
Source File: Axis.java From nebula with Eclipse Public License 2.0 | 4 votes |
@Override protected void paintClientArea(final Graphics graphics) { // Don't do anything when hidden if (!isVisible()) return; super.paintClientArea(graphics); // graphics.pushState(); if (title != null) { graphics.setFont(titleFont); final Dimension titleSize = FigureUtilities.getTextExtents(title, titleFont); if (isHorizontal()) { if (getTickLabelSide() == LabelSide.Primary) graphics.drawText(title, bounds.x + bounds.width / 2 - titleSize.width / 2, bounds.y + bounds.height - titleSize.height); else graphics.drawText(title, bounds.x + bounds.width / 2 - titleSize.width / 2, bounds.y); } else { final int w = titleSize.height; final int h = titleSize.width + 1; if (getTickLabelSide() == LabelSide.Primary) { GraphicsUtil.drawVerticalText(graphics, title, bounds.x, bounds.y + bounds.height / 2 - h / 2, false); } else { GraphicsUtil.drawVerticalText(graphics, title, bounds.x + bounds.width - w, bounds.y + bounds.height / 2 - h / 2, true); } } } // graphics.popState(); // Show the start/end cursor or the 'rubberband' of a zoom operation? if (armed && end != null && start != null) { switch (zoomType) { case RUBBERBAND_ZOOM: case HORIZONTAL_ZOOM: case VERTICAL_ZOOM: case DYNAMIC_ZOOM: graphics.setLineStyle(SWTConstants.LINE_DOT); graphics.setLineWidth(1); graphics.setForegroundColor(revertBackColor); graphics.drawRectangle(start.x, start.y, end.x - start.x - 1, end.y - start.y - 1); break; default: break; } } }
Example 20
Source File: VerticalLabel.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
/** * Fix the issues in the ImageUtilities where the size of the image is the * ascent of the font instead of being its height. * * Also uses the GC for the rotation. * * The biggest issue is the very idea of using an image. The size of the * font should be given by the mapmode, not in absolute device pixel as it * does look ugly when zooming in. * * * @param string * the String to be rendered * @param font * the font * @param foreground * the text's color * @param background * the background color * @param useGCTransform * true to use the Transform on the GC object. * false to rely on the homemade algorithm. Transform seems to * not be supported in eclipse-3.2 except on windows. * It is working on macos-3.3M3. * @return an Image which must be disposed */ public Image createRotatedImageOfString(Graphics g, String string, Font font, Color foreground, Color background, boolean useGCTransform) { Display display = Display.getCurrent(); if (display == null) { SWT.error(SWT.ERROR_THREAD_INVALID_ACCESS); } List<FontData> fontDatas = new ArrayList<FontData>(); // take all font datas, mac and linux specific for (FontData data : font.getFontData()) { FontData data2 = new FontData(data.getName(), (int) (data.getHeight() * g.getAbsoluteScale()), data.getStyle()); fontDatas.add(data2); } // create the new font Font zoomedFont = new Font(display, fontDatas.toArray(new FontData[fontDatas.size()])); // get the dimension in this font Dimension strDim = FigureUtilities .getTextExtents(string, zoomedFont); if (strDim.width == 0 || strDim.height == 0) { strDim = FigureUtilities .getTextExtents(string, font); } Image srcImage = useGCTransform ? new Image(display, strDim.height, strDim.width) : new Image(display, strDim.width, strDim.height); GC gc = new GC(srcImage); if (useGCTransform) { Transform transform = new Transform(display); transform.rotate(-90); gc.setTransform(transform); } gc.setFont(zoomedFont); gc.setForeground(foreground); gc.setBackground(background); gc.fillRectangle(gc.getClipping()); gc.drawText(string, gc.getClipping().x, gc.getClipping().y // - metrics.getLeading() ); gc.dispose(); if (useGCTransform) { srcImage.dispose(); zoomedFont.dispose(); return srcImage; } disposeImage(); Image rotated = ImageUtilities.createRotatedImage(srcImage); srcImage.dispose(); zoomedFont.dispose(); return rotated; }