Skip to content

Commit

Permalink
adopt standard platform check utility
Browse files Browse the repository at this point in the history
1.Make use of standard utility function for platform check wherever
applicable.
2.standardize field naming conventions
  • Loading branch information
elsazac authored and mickaelistria committed Jan 8, 2024
1 parent 250ff89 commit 13ef592
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@
* @since 3.4
*/
public abstract class AbstractColumnLayout extends Layout {
private static int COLUMN_TRIM;
private static int columnTrim;
static {
if (Util.isWindows()) {
COLUMN_TRIM = 4;
columnTrim = 4;
} else if (Util.isMac()) {
COLUMN_TRIM = 24;
columnTrim = 24;
} else {
COLUMN_TRIM = 3;
columnTrim = 3;
}
}

Expand Down Expand Up @@ -342,14 +342,14 @@ protected abstract ColumnLayoutData getLayoutData(Scrollable tableTree,
protected abstract void updateColumnData(Widget column);

/**
* The number of extra pixels taken as horizontal trim by the table column.
* To ensure there are N pixels available for the content of the column,
* assign N+COLUMN_TRIM for the column width.
* The number of extra pixels taken as horizontal trim by the table column. To
* ensure there are N pixels available for the content of the column, assign
* N+columnTrim for the column width.
*
* @return the trim used by the columns
* @since 3.4
*/
protected int getColumnTrim() {
return COLUMN_TRIM;
return columnTrim;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@
public class TableLayout extends Layout {

/**
* The number of extra pixels taken as horizontal trim by the table column.
* To ensure there are N pixels available for the content of the column,
* assign N+COLUMN_TRIM for the column width.
* The number of extra pixels taken as horizontal trim by the table column. To
* ensure there are N pixels available for the content of the column, assign
* N+columnTrim for the column width.
*
* @since 3.1
*/
private static int COLUMN_TRIM;
private static int columnTrim;

static {
if (Util.isWindows()) {
COLUMN_TRIM = 4;
columnTrim = 4;
} else if (Util.isMac()) {
COLUMN_TRIM = 24;
columnTrim = 24;
} else {
COLUMN_TRIM = 3;
columnTrim = 3;
}
}

Expand Down Expand Up @@ -118,7 +118,7 @@ public Point computeSize(Composite c, int wHint, int hHint, boolean flush) {
ColumnPixelData col = (ColumnPixelData) layoutData;
width += col.width;
if (col.addTrim) {
width += COLUMN_TRIM;
width += columnTrim;
}
} else if (layoutData instanceof ColumnWeightData) {
ColumnWeightData col = (ColumnWeightData) layoutData;
Expand Down Expand Up @@ -169,7 +169,7 @@ public void layout(Composite c, boolean flush) {
ColumnPixelData cpd = (ColumnPixelData) col;
int pixels = cpd.width;
if (cpd.addTrim) {
pixels += COLUMN_TRIM;
pixels += columnTrim;
}
widths[i] = pixels;
fixedWidth += pixels;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.util.ArrayList;
import java.util.List;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
Expand All @@ -27,6 +26,7 @@

import org.eclipse.core.runtime.Assert;

import org.eclipse.jface.util.Util;
import org.eclipse.jface.viewers.ColumnLayoutData;
import org.eclipse.jface.viewers.ColumnPixelData;
import org.eclipse.jface.viewers.ColumnWeightData;
Expand All @@ -44,33 +44,27 @@ final class ColumnLayout extends Layout {
private static final String RECALCULATE_LAYOUT= "recalculateKey"; //$NON-NLS-1$

/**
* The number of extra pixels taken as horizontal trim by the table column.
* To ensure there are N pixels available for the content of the column,
* assign N+COLUMN_TRIM for the column width.
* The number of extra pixels taken as horizontal trim by the table column. To
* ensure there are N pixels available for the content of the column, assign
* N+columnTrim for the column width.
* <p>
* XXX: Should either switch to use
* {@link org.eclipse.jface.layout.TableColumnLayout} or get API from JFace
* or SWT, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=218483
* {@link org.eclipse.jface.layout.TableColumnLayout} or get API from JFace or
* SWT, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=218483
* </p>
*
* @since 3.1
*/
private static int COLUMN_TRIM;
private static int columnTrim;
static {
String platform= SWT.getPlatform();
switch (platform) {
case "win32": //$NON-NLS-1$
COLUMN_TRIM= 4;
break;
case "carbon": //$NON-NLS-1$
COLUMN_TRIM= 24;
break;
default:
COLUMN_TRIM= 3;
break;
if (Util.isWindows()) {
columnTrim = 4;
} else if (Util.isMac()) {
columnTrim = 24;
} else {
columnTrim = 3;
}
}

private List<ColumnLayoutData> columns= new ArrayList<>();

/**
Expand All @@ -93,7 +87,7 @@ private Point computeTableSize(Table table, int wHint, int hHint) {
ColumnPixelData col= (ColumnPixelData) layoutData;
width += col.width;
if (col.addTrim) {
width += COLUMN_TRIM;
width += columnTrim;
}
} else if (layoutData instanceof ColumnWeightData) {
ColumnWeightData col= (ColumnWeightData) layoutData;
Expand Down Expand Up @@ -126,7 +120,7 @@ private void layoutTable(final Table table, final int width, final Rectangle are
ColumnPixelData cpd= (ColumnPixelData) col;
int pixels= cpd.width;
if (cpd.addTrim) {
pixels += COLUMN_TRIM;
pixels += columnTrim;
}
widths[i]= pixels;
fixedWidth += pixels;
Expand Down

0 comments on commit 13ef592

Please sign in to comment.