Skip to content
Snippets Groups Projects
Commit e4caba7a authored by Simon Barner's avatar Simon Barner
Browse files

- Consider both text and image contents in the MeasureItem and PaintItem...

- Consider both text and image contents in the MeasureItem and PaintItem Listener installed in addRowHeightListener()
- Improve documentation
refs 2450
parent cc6ff118
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,7 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.annotation.view.generic;
import static java.lang.Math.max;
import static org.fortiss.tooling.base.ui.annotation.editingsupport.EditingSupportFactory.createEditingSupport;
import static org.fortiss.tooling.base.ui.annotation.labelprovider.LabelProviderFactory.createLabelProvider;
......@@ -37,7 +38,9 @@ import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.window.ToolTip;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
......@@ -74,7 +77,7 @@ import org.fortiss.tooling.base.ui.annotation.view.generic.filter.AnnotationFilt
* @author eder, diewald, barner
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: BBED92F55537563D7EF594EF27F36870
* @ConQAT.Rating YELLOW Hash: 110B3CF77E247F35B410B0280A2EE66C
*/
public class GenericAnnotationView extends AnnotationViewPartBase {
/** Root composite of {@link GenericAnnotationView}. */
......@@ -244,7 +247,9 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
// After contents change, restore row height. It will be adjusted to the new content
// using the TableViewer's SWT.{MeasureItem, PaintItem, EraseItem} listeners installed
// in addRowHeightListener()
// in addRowHeightListener(). This needs to be done here since in the above listeners,
// the table row height can only grow and may not be decreased.
// See <https://bugs.eclipse.org/bugs/show_bug.cgi?id=154341>.
setTableItemHeight(tableViewer.getTable(), defaultRowHeight);
}
......@@ -296,6 +301,11 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
* contents.
*/
private void addRowHeightListener(Table table) {
/*
* NB: MeasureItem, PaintItem and EraseItem are called repeatedly and are hence
* performance critical.
*/
Listener rowHeightListener = new Listener() {
@Override
public void handleEvent(Event event) {
......@@ -303,18 +313,38 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
case SWT.MeasureItem: {
TableItem item = (TableItem)event.item;
String text = item.getText(event.index);
Point size = event.gc.textExtent(text);
event.width = size.x;
event.height = Math.max(event.height, size.y);
Point textSize = event.gc.textExtent(text);
event.width = textSize.x;
event.height = Math.max(event.height, textSize.y);
Image image = item.getImage(event.index);
if(image != null) {
Rectangle imageSize = image.getBounds();
event.width = max(event.width, imageSize.x);
event.height = max(event.height, imageSize.y);
}
break;
}
case SWT.PaintItem: {
TableItem item = (TableItem)event.item;
// Determine maximum content height (considering text and image contents),
// and derive resulting vertical offset
String text = item.getText(event.index);
Point size = event.gc.textExtent(text);
int offset =
event.index == 0 ? Math.max(0, (event.height - size.y) / 2) : 0;
int contentHeight = event.gc.textExtent(text).y;
Image image = item.getImage(event.index);
if(image != null) {
contentHeight = max(contentHeight, image.getBounds().y);
}
int offset = max(0, (event.height - contentHeight) / 2);
// Render content
event.gc.drawText(text, event.x, event.y + offset, true);
if(image != null) {
event.gc.drawImage(image, event.x, event.y + offset);
}
break;
}
case SWT.EraseItem: {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment