@@ -42,10 +42,6 @@ public AbstractConvertAction(EquatePlugin plugin, String actionName, boolean isS
42
42
this .isSigned = isSigned ;
43
43
setPopupMenuData (new MenuData (new String [] { "Convert" , "" }, "Convert" ));
44
44
setEnabled (true );
45
- JMenuItem item = new JMenuItem ();
46
- Font font = item .getFont ();
47
- metrics = plugin .getTool ().getActiveWindow ().getFontMetrics (font );
48
-
49
45
}
50
46
51
47
@ Override
@@ -132,14 +128,28 @@ protected final boolean isSignedChoice() {
132
128
return isSigned ;
133
129
}
134
130
131
+ private int stringWidth (String s ) {
132
+ if (metrics == null ) {
133
+ JMenuItem item = new JMenuItem ();
134
+ Font font = item .getFont ();
135
+ metrics = plugin .getTool ().getActiveWindow ().getFontMetrics (font );
136
+ }
137
+ int w = metrics .stringWidth (s );
138
+ if (w == 0 ) {
139
+ // use default computation if metrics report 0
140
+ return 10 * s .length ();
141
+ }
142
+ return w ;
143
+ }
144
+
135
145
String getStandardLengthString (String baseString ) {
136
- int baseWidth = metrics . stringWidth (baseString );
137
- int spaceWidth = metrics . stringWidth (" " );
146
+ int baseWidth = stringWidth (baseString );
147
+ int spaceWidth = stringWidth (" " );
138
148
int paddingSize = (140 - baseWidth ) / spaceWidth ;
139
149
if (paddingSize <= 0 ) {
140
150
return baseString ;
141
151
}
142
- StringBuffer buf = new StringBuffer (baseString );
152
+ StringBuilder buf = new StringBuilder (baseString );
143
153
for (int i = 0 ; i < paddingSize ; i ++) {
144
154
buf .append (" " );
145
155
}
0 commit comments