Skip to content

Commit

Permalink
Simplify TextSizeUtilFacade.textExtent's interface
Browse files Browse the repository at this point in the history
  • Loading branch information
HiromuHota committed Jan 1, 2021
1 parent 2130bc3 commit df3d864
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
package org.apache.hop.ui.hopgui;

import org.eclipse.rap.rwt.internal.textsize.TextSizeUtil;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Display;

public class TextSizeUtilFacadeImpl extends TextSizeUtilFacade {

@Override
Point textExtentInternal(Font font, String text, int wrapWidth) {
return TextSizeUtil.textExtent( font, text, wrapWidth );
Point textExtentInternal(String text) {
return TextSizeUtil.stringExtent(Display.getCurrent().getSystemFont(), text);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.hop.ui.hopgui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
Expand All @@ -27,10 +26,10 @@
public class TextSizeUtilFacadeImpl extends TextSizeUtilFacade {

@Override
Point textExtentInternal( Font font, String text, int wrapWidth ) {
Image dummyImage = new Image( Display.getCurrent(), 50, 10 );
GC dummyGC = new GC( dummyImage );
Point point = dummyGC.textExtent( text, SWT.DRAW_TAB | SWT.DRAW_DELIMITER );
Point textExtentInternal(String text) {
Image dummyImage = new Image(Display.getCurrent(), 50, 10);
GC dummyGC = new GC(dummyImage);
Point point = dummyGC.textExtent(text, SWT.DRAW_TAB | SWT.DRAW_DELIMITER);
dummyImage.dispose();
dummyGC.dispose();
return point;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private void addToolbarWidgets( Composite parent, GuiToolbarItem toolbarItem ) {
private int calculateComboWidth( Combo combo ) {
int maxWidth = combo.getSize().x;
for ( String item : combo.getItems() ) {
int width = TextSizeUtilFacade.textExtent(Display.getCurrent().getSystemFont(), item, Integer.MAX_VALUE).x;
int width = TextSizeUtilFacade.textExtent(item).x;
if ( width > maxWidth ) {
maxWidth = width;
}
Expand Down
6 changes: 3 additions & 3 deletions ui/src/main/java/org/apache/hop/ui/core/widget/TableView.java
Original file line number Diff line number Diff line change
Expand Up @@ -2232,7 +2232,7 @@ private void setColumnWidthBasedOnTextField( final int colnr, final boolean useV
}
String str = getTextWidgetValue( colnr );

int strmax = TextSizeUtilFacade.textExtent( getFont(), str, 0 ).x + 20;
int strmax = TextSizeUtilFacade.textExtent(str).x + 20;
int colmax = tablecolumn[ colnr ].getWidth();
if ( strmax > colmax ) {
tablecolumn[ colnr ].setWidth( strmax + 30 );
Expand Down Expand Up @@ -2480,7 +2480,7 @@ public void optWidth( boolean header, int nrLines ) {
TableColumn tc = table.getColumn( c );
int max = 0;
if ( header ) {
max = TextSizeUtilFacade.textExtent( getFont(), tc.getText(), 0 ).x;
max = TextSizeUtilFacade.textExtent(tc.getText()).x;

// Check if the column has a sorted mark set. In that case, we need the
// header to be a bit wider...
Expand Down Expand Up @@ -2530,7 +2530,7 @@ public void optWidth( boolean header, int nrLines ) {
}

for ( String str : columnStrings ) {
int len = TextSizeUtilFacade.textExtent( getFont(), str == null ? "" : str, 0 ).x;
int len = TextSizeUtilFacade.textExtent(str == null ? "" : str).x;
if ( len > max ) {
max = len;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.apache.hop.ui.hopgui;

import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Point;

public abstract class TextSizeUtilFacade {
Expand All @@ -26,8 +25,8 @@ public abstract class TextSizeUtilFacade {
IMPL = (TextSizeUtilFacade) ImplementationLoader.newInstance( TextSizeUtilFacade.class );
}

public static Point textExtent( Font font, String text, int wrapWidth ) {
return IMPL.textExtentInternal( font, text, wrapWidth );
public static Point textExtent(String text) {
return IMPL.textExtentInternal(text);
}
abstract Point textExtentInternal( Font font, String text, int wrapWidth );
abstract Point textExtentInternal(String text);
}

0 comments on commit df3d864

Please sign in to comment.