Skip to content

Package: FigureUtilities

FigureUtilities

nameinstructionbranchcomplexitylinemethod
getGC()
M: 0 C: 14
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
getTextDimension(String, Font)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
getTextWidth(String, Font)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
setFont(Font)
M: 0 C: 16
100%
M: 2 C: 4
67%
M: 2 C: 2
50%
M: 0 C: 5
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2016 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Johannes Faltermeier - initial API and implementation
13: ******************************************************************************/
14: /*******************************************************************************
15: * Copyright (c) 2000, 2010 IBM Corporation and others.
16: * All rights reserved. This program and the accompanying materials
17: * are made available under the terms of the Eclipse Public License 2.0
18: * which accompanies this distribution, and is available at
19: * https://www.eclipse.org/legal/epl-2.0/
20: *
21: * SPDX-License-Identifier: EPL-2.0
22: *
23: * Contributors:
24: * IBM Corporation - initial API and implementation
25: *******************************************************************************/
26: package org.eclipse.emf.ecp.view.internal.table.swt;
27:
28: import org.eclipse.swt.graphics.Font;
29: import org.eclipse.swt.graphics.GC;
30: import org.eclipse.swt.widgets.Shell;
31:
32: /**
33: * Based on org.eclipse.draw2d.FigureUtilities .
34: */
35: public final class FigureUtilities {
36:
37:         private static GC gc;
38:         private static Font appliedFont;
39:
40:         private FigureUtilities() {
41:                 // util
42:         }
43:
44:         /**
45:          * Returns the GC used for various utilities. Advanced graphics must not be
46:          * switched on by clients using this GC.
47:          *
48:          * @return the GC
49:          */
50:         private static GC getGC() {
51:•                if (gc == null) {
52:                         gc = new GC(new Shell());
53:                         appliedFont = gc.getFont();
54:                 }
55:                 return gc;
56:         }
57:
58:         /**
59:          * Returns the dimensions of the String <i>s</i> using the font <i>f</i>.
60:          * Tab expansion and carriage return processing are performed.
61:          *
62:          * @param s
63:          * the string
64:          * @param f
65:          * the font
66:          * @return the text's dimensions
67:          * @see GC#textExtent(String)
68:          */
69:         public static org.eclipse.swt.graphics.Point getTextDimension(String s,
70:                 Font f) {
71:                 setFont(f);
72:                 return getGC().textExtent(s);
73:         }
74:
75:         /**
76:          * Returns the width of <i>s</i> in Font <i>f</i>.
77:          *
78:          * @param s
79:          * the string
80:          * @param f
81:          * the font
82:          * @return the width
83:          */
84:         public static int getTextWidth(String s, Font f) {
85:                 return getTextDimension(s, f).x;
86:         }
87:
88:         /**
89:          * Sets Font to passed value.
90:          *
91:          * @param f
92:          * the new font
93:          */
94:         private static void setFont(Font f) {
95:•                if (appliedFont == f || f != null && f.equals(appliedFont)) {
96:                         return;
97:                 }
98:                 getGC().setFont(f);
99:                 appliedFont = f;
100:         }
101:
102: }