summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorPawel Piech2013-04-10 12:07:34 (EDT)
committer Mike Rennie2013-04-10 12:07:34 (EDT)
commit3b201b43045552d0e18ce87bcf22863bf44f099d (patch)
tree213491c76a722b5c5c3292cf44a95ef11cc207e9
parent0c1629b0924ffd2bb1f7ed8f919f9fab1866a151 (diff)
downloadeclipse.platform.ui-3b201b43045552d0e18ce87bcf22863bf44f099d.zip
eclipse.platform.ui-3b201b43045552d0e18ce87bcf22863bf44f099d.tar.gz
eclipse.platform.ui-3b201b43045552d0e18ce87bcf22863bf44f099d.tar.bz2
Bug 291245 - [Viewers] StyledCellLabelProvider.paint(...) does not
respect column alignment
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StyledCellLabelProvider.java14
-rw-r--r--tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/viewers/interactive/StyledCellLabelProviderTests.java50
2 files changed, 53 insertions, 11 deletions
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StyledCellLabelProvider.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StyledCellLabelProvider.java
index c0bae3a..9791559 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StyledCellLabelProvider.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StyledCellLabelProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 IBM Corporation and others.
+ * Copyright (c) 2007, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Michael Krkoska - initial API and implementation (bug 188333)
+ * Pawel Piech - Bug 291245 - [Viewers] StyledCellLabelProvider.paint(...) does not respect column alignment
*******************************************************************************/
package org.eclipse.jface.viewers;
@@ -43,8 +44,6 @@ import org.eclipse.swt.widgets.Event;
*/
public abstract class StyledCellLabelProvider extends OwnerDrawLabelProvider {
-
-
/**
* Style constant for indicating that the styled colors are to be applied
* even it the viewer's item is selected. Default is not to apply colors.
@@ -365,11 +364,20 @@ public abstract class StyledCellLabelProvider extends OwnerDrawLabelProvider {
Rectangle layoutBounds = textLayout.getBounds();
+ int style = viewer.getColumnViewerOwner(cell.getColumnIndex()).getStyle();
int x = textBounds.x;
+ if ((style & SWT.RIGHT) != 0) {
+ x = textBounds.x + textBounds.width - textLayout.getBounds().width;
+ } else if ((style & SWT.CENTER) != 0) {
+ x = textBounds.x + (textBounds.width - textLayout.getBounds().width)/2;
+ }
int y = textBounds.y
+ Math.max(0, (textBounds.height - layoutBounds.height) / 2);
+ Rectangle saveClipping = gc.getClipping();
+ gc.setClipping(textBounds);
textLayout.draw(gc, x, y);
+ gc.setClipping(saveClipping);
}
if (drawFocus(event)) {
diff --git a/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/viewers/interactive/StyledCellLabelProviderTests.java b/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/viewers/interactive/StyledCellLabelProviderTests.java
index 351b795..b087531 100644
--- a/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/viewers/interactive/StyledCellLabelProviderTests.java
+++ b/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/viewers/interactive/StyledCellLabelProviderTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 IBM Corporation and others.
+ * Copyright (c) 2007, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Michael Krkoska - initial API and implementation (bug 188333)
+ * Pawel Piech - Bug 291245 - [Viewers] StyledCellLabelProvider.paint(...) does not respect column alignment
*******************************************************************************/
package org.eclipse.jface.tests.viewers.interactive;
@@ -16,13 +17,15 @@ import java.text.MessageFormat;
import org.eclipse.jface.preference.JFacePreferences;
import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.viewers.CellLabelProvider;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.StyledCellLabelProvider;
import org.eclipse.jface.viewers.StyledString;
+import org.eclipse.jface.viewers.StyledString.Styler;
import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerCell;
-import org.eclipse.jface.viewers.StyledString.Styler;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
@@ -80,6 +83,7 @@ public class StyledCellLabelProviderTests {
}
protected boolean useBold;
+ protected TableViewerColumn column;
public StyledCellLabelProviderTests() {
}
@@ -110,9 +114,23 @@ public class StyledCellLabelProviderTests {
final Button boldButton = new Button(composite, SWT.CHECK);
boldButton.setText("use bold");
+ final Button leftButton = new Button(composite, SWT.RADIO);
+ leftButton.setText("align left");
+ leftButton.setSelection(true);
+ final Button centerButton = new Button(composite, SWT.RADIO);
+ centerButton.setText("align center");
+ final Button rightButton = new Button(composite, SWT.RADIO);
+ rightButton.setText("align right");
+
final TableViewer tableViewer= new TableViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
+ tableViewer.getTable().setHeaderVisible(true);
+ FontData[] boldFontData= getModifiedFontData(tableViewer.getTable().getFont().getFontData(), SWT.BOLD);
+ Font boldFont = new Font(Display.getCurrent(), boldFontData);
+ final ExampleLabelProvider labelProvider= new ExampleLabelProvider(boldFont);
- boldButton.addSelectionListener(new SelectionAdapter(){
+ createColumn(tableViewer, SWT.LEFT, labelProvider);
+
+ boldButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
useBold = boldButton.getSelection();
tableViewer.refresh();
@@ -124,15 +142,23 @@ public class StyledCellLabelProviderTests {
tableViewer.refresh();
}
};
-
- FontData[] boldFontData= getModifiedFontData(tableViewer.getTable().getFont().getFontData(), SWT.BOLD);
- Font boldFont = new Font(Display.getCurrent(), boldFontData);
- final ExampleLabelProvider labelProvider= new ExampleLabelProvider(boldFont);
+ SelectionAdapter adapter = new SelectionAdapter(){
+ public void widgetSelected(SelectionEvent e) {
+ if (((Button)e.getSource()).getSelection()) {
+ column.getColumn().dispose();
+ int style = e.getSource() == leftButton ? SWT.LEFT : (e.getSource() == centerButton ? SWT.CENTER : SWT.RIGHT);
+ createColumn(tableViewer, style, labelProvider);
+ }
+ }
+ };
+ leftButton.addSelectionListener(adapter);
+ centerButton.addSelectionListener(adapter);
+ rightButton.addSelectionListener(adapter);
+
TestContentProvider contentProvider= new TestContentProvider();
tableViewer.setContentProvider(contentProvider);
- tableViewer.setLabelProvider(labelProvider);
stylingButton.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e) {
@@ -149,6 +175,14 @@ public class StyledCellLabelProviderTests {
return composite;
}
+ private void createColumn(TableViewer viewer, int style, CellLabelProvider labelProvider) {
+ column = new TableViewerColumn(viewer, style);
+ column.getColumn().setWidth(200);
+ column.getColumn().setText("Column");
+ column.setLabelProvider(labelProvider);
+ viewer.refresh();
+ }
+
boolean timerOn = false;
long startTime;
int numOperations;