-package org.simantics.browsing.ui.nattable;\r
-\r
-import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;\r
-import org.eclipse.nebula.widgets.nattable.layer.ILayer;\r
-import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;\r
-import org.eclipse.nebula.widgets.nattable.painter.cell.BackgroundPainter;\r
-import org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter;\r
-import org.eclipse.nebula.widgets.nattable.painter.cell.ImagePainter;\r
-import org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand;\r
-import org.eclipse.nebula.widgets.nattable.resize.command.RowResizeCommand;\r
-import org.eclipse.nebula.widgets.nattable.style.CellStyleAttributes;\r
-import org.eclipse.nebula.widgets.nattable.style.CellStyleUtil;\r
-import org.eclipse.nebula.widgets.nattable.style.IStyle;\r
-import org.eclipse.swt.graphics.GC;\r
-import org.eclipse.swt.graphics.Image;\r
-import org.eclipse.swt.graphics.Rectangle;\r
-\r
-/**\r
- * Modified org.eclipse.nebula.widgets.nattable.painter.cell.ImagePainter, which does not allow setting wrapped painter\r
- * \r
- * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
- *\r
- */\r
-public class GEIconPainter extends BackgroundPainter {\r
- \r
- protected boolean calculateByWidth;\r
- protected boolean calculateByHeight;\r
- \r
- public GEIconPainter(ICellPainter painter) {\r
- super(painter);\r
- }\r
- \r
- @Override\r
- public int getPreferredWidth(ILayerCell cell, GC gc, IConfigRegistry configRegistry) {\r
- Image image = getImage(cell, configRegistry);\r
- if (image != null) {\r
- return image.getBounds().width;\r
- } else {\r
- return 0;\r
- }\r
- }\r
-\r
- @Override\r
- public int getPreferredHeight(ILayerCell cell, GC gc, IConfigRegistry configRegistry) {\r
- Image image = getImage(cell, configRegistry);\r
- if (image != null) {\r
- return image.getBounds().height;\r
- } else {\r
- return 0;\r
- }\r
- }\r
-\r
- @Override\r
- public ICellPainter getCellPainterAt(int x, int y, ILayerCell cell, GC gc,\r
- Rectangle bounds, IConfigRegistry configRegistry) {\r
-\r
- Image image = getImage(cell, configRegistry);\r
- if (image != null) {\r
- Rectangle imageBounds = image.getBounds();\r
- IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);\r
- int x0 = bounds.x\r
- + CellStyleUtil.getHorizontalAlignmentPadding(\r
- cellStyle, bounds, imageBounds.width);\r
- int y0 = bounds.y\r
- + CellStyleUtil.getVerticalAlignmentPadding(\r
- cellStyle, bounds, imageBounds.height);\r
- if (x >= x0 && x < x0 + imageBounds.width\r
- && y >= y0 && y < y0 + imageBounds.height) {\r
- return super.getCellPainterAt(x, y, cell, gc, bounds, configRegistry);\r
- }\r
- }\r
- return null;\r
- }\r
-\r
- @Override\r
- public void paintCell(ILayerCell cell, GC gc, Rectangle bounds, IConfigRegistry configRegistry) {\r
- \r
- \r
- Image image = getImage(cell, configRegistry);\r
- if (image != null) {\r
- Rectangle imageBounds = image.getBounds();\r
- IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);\r
-\r
- int contentHeight = imageBounds.height;\r
- if (this.calculateByHeight && (contentHeight > bounds.height)) {\r
- int contentToCellDiff = (cell.getBounds().height - bounds.height);\r
- ILayer layer = cell.getLayer();\r
- layer.doCommand(new RowResizeCommand(\r
- layer,\r
- cell.getRowPosition(),\r
- contentHeight + contentToCellDiff));\r
- }\r
-\r
- int contentWidth = imageBounds.width;\r
- if (this.calculateByWidth && (contentWidth > bounds.width)) {\r
- int contentToCellDiff = (cell.getBounds().width - bounds.width);\r
- ILayer layer = cell.getLayer();\r
- layer.doCommand(new ColumnResizeCommand(\r
- layer,\r
- cell.getColumnPosition(),\r
- contentWidth + contentToCellDiff));\r
- }\r
- int px = CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, bounds, imageBounds.width);\r
- int py = CellStyleUtil.getVerticalAlignmentPadding(cellStyle, bounds, imageBounds.height);\r
- Rectangle b = new Rectangle(bounds.x + px + imageBounds.width, bounds.y, bounds.width - px - imageBounds.width, bounds.height);\r
- super.paintCell(cell, gc, b, configRegistry);\r
- gc.drawImage(\r
- image,\r
- bounds.x + px,\r
- bounds.y + py);\r
- } else {\r
- super.paintCell(cell, gc, bounds, configRegistry);\r
- }\r
- }\r
- \r
-// @Override\r
-// public Rectangle getWrappedPainterBounds(ILayerCell cell, GC gc, Rectangle bounds, IConfigRegistry configRegistry) {\r
-// Image image = getImage(cell, configRegistry);\r
-// if (image != null) {\r
-// Rectangle imageBounds = image.getBounds();\r
-// IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);\r
-// int px = CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, bounds, imageBounds.width);\r
-// int py = CellStyleUtil.getVerticalAlignmentPadding(cellStyle, bounds, imageBounds.height);\r
-// Rectangle b = new Rectangle(bounds.x + px + imageBounds.width, bounds.y, bounds.width - px - imageBounds.width, bounds.height);\r
-// return b;\r
-// \r
-// }\r
-// return super.getWrappedPainterBounds(cell, gc, bounds, configRegistry);\r
-// }\r
-\r
- /**\r
- *\r
- * @param cell\r
- * The {@link ILayerCell} for which this {@link ImagePainter} is\r
- * called.\r
- * @param configRegistry\r
- * The current {@link IConfigRegistry} to retrieve the cell style\r
- * information from.\r
- * @return The {@link Image} that should be painted by this\r
- * {@link ImagePainter}.\r
- */\r
- protected Image getImage(ILayerCell cell, IConfigRegistry configRegistry) {\r
- return CellStyleUtil.getCellStyle(cell, configRegistry).getAttributeValue(CellStyleAttributes.IMAGE);\r
- }\r
-\r
- /**\r
- * @return <code>true</code> if this {@link ImagePainter} is resizing the\r
- * cell width to show the whole configured image, <code>false</code>\r
- * if the cell width is not touched by this painter.\r
- */\r
- public boolean isCalculateByWidth() {\r
- return this.calculateByWidth;\r
- }\r
-\r
- /**\r
- * Configure whether the {@link ImagePainter} should calculate the cell\r
- * dimensions by containing image width. This means the <b>width</b> of the\r
- * cell is calculated by image width.\r
- *\r
- * @param calculateByWidth\r
- * <code>true</code> to calculate and modify the cell dimension\r
- * according to the image width, <code>false</code> to not\r
- * modifying the cell dimensions.\r
- */\r
- public void setCalculateByWidth(boolean calculateByWidth) {\r
- this.calculateByWidth = calculateByWidth;\r
- }\r
-\r
- /**\r
- * @return <code>true</code> if this {@link ImagePainter} is resizing the\r
- * cell height to show the whole configured image,\r
- * <code>false</code> if the cell height is not touched by this\r
- * painter.\r
- */\r
- public boolean isCalculateByHeight() {\r
- return this.calculateByHeight;\r
- }\r
-\r
- /**\r
- * Configure whether the {@link ImagePainter} should calculate the cell\r
- * dimensions by containing image height. This means the <b>height</b> of\r
- * the cell is calculated by image height.\r
- *\r
- * @param calculateByHeight\r
- * <code>true</code> to calculate and modify the cell dimension\r
- * according to the image height, <code>false</code> to not\r
- * modifying the cell dimensions.\r
- */\r
- public void setCalculateByHeight(boolean calculateByHeight) {\r
- this.calculateByHeight = calculateByHeight;\r
- }\r
-\r
-}\r
+package org.simantics.browsing.ui.nattable;
+
+import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
+import org.eclipse.nebula.widgets.nattable.layer.ILayer;
+import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
+import org.eclipse.nebula.widgets.nattable.painter.cell.BackgroundPainter;
+import org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter;
+import org.eclipse.nebula.widgets.nattable.painter.cell.ImagePainter;
+import org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand;
+import org.eclipse.nebula.widgets.nattable.resize.command.RowResizeCommand;
+import org.eclipse.nebula.widgets.nattable.style.CellStyleAttributes;
+import org.eclipse.nebula.widgets.nattable.style.CellStyleUtil;
+import org.eclipse.nebula.widgets.nattable.style.IStyle;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Rectangle;
+
+/**
+ * Modified org.eclipse.nebula.widgets.nattable.painter.cell.ImagePainter, which does not allow setting wrapped painter
+ *
+ * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
+ *
+ */
+public class GEIconPainter extends BackgroundPainter {
+
+ protected boolean calculateByWidth;
+ protected boolean calculateByHeight;
+
+ public GEIconPainter(ICellPainter painter) {
+ super(painter);
+ }
+
+ @Override
+ public int getPreferredWidth(ILayerCell cell, GC gc, IConfigRegistry configRegistry) {
+ Image image = getImage(cell, configRegistry);
+ if (image != null) {
+ return image.getBounds().width;
+ } else {
+ return 0;
+ }
+ }
+
+ @Override
+ public int getPreferredHeight(ILayerCell cell, GC gc, IConfigRegistry configRegistry) {
+ Image image = getImage(cell, configRegistry);
+ if (image != null) {
+ return image.getBounds().height;
+ } else {
+ return 0;
+ }
+ }
+
+ @Override
+ public ICellPainter getCellPainterAt(int x, int y, ILayerCell cell, GC gc,
+ Rectangle bounds, IConfigRegistry configRegistry) {
+
+ Image image = getImage(cell, configRegistry);
+ if (image != null) {
+ Rectangle imageBounds = image.getBounds();
+ IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
+ int x0 = bounds.x
+ + CellStyleUtil.getHorizontalAlignmentPadding(
+ cellStyle, bounds, imageBounds.width);
+ int y0 = bounds.y
+ + CellStyleUtil.getVerticalAlignmentPadding(
+ cellStyle, bounds, imageBounds.height);
+ if (x >= x0 && x < x0 + imageBounds.width
+ && y >= y0 && y < y0 + imageBounds.height) {
+ return super.getCellPainterAt(x, y, cell, gc, bounds, configRegistry);
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public void paintCell(ILayerCell cell, GC gc, Rectangle bounds, IConfigRegistry configRegistry) {
+
+
+ Image image = getImage(cell, configRegistry);
+ if (image != null) {
+ Rectangle imageBounds = image.getBounds();
+ IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
+
+ int contentHeight = imageBounds.height;
+ if (this.calculateByHeight && (contentHeight > bounds.height)) {
+ int contentToCellDiff = (cell.getBounds().height - bounds.height);
+ ILayer layer = cell.getLayer();
+ layer.doCommand(new RowResizeCommand(
+ layer,
+ cell.getRowPosition(),
+ contentHeight + contentToCellDiff));
+ }
+
+ int contentWidth = imageBounds.width;
+ if (this.calculateByWidth && (contentWidth > bounds.width)) {
+ int contentToCellDiff = (cell.getBounds().width - bounds.width);
+ ILayer layer = cell.getLayer();
+ layer.doCommand(new ColumnResizeCommand(
+ layer,
+ cell.getColumnPosition(),
+ contentWidth + contentToCellDiff));
+ }
+ int px = CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, bounds, imageBounds.width);
+ int py = CellStyleUtil.getVerticalAlignmentPadding(cellStyle, bounds, imageBounds.height);
+ Rectangle b = new Rectangle(bounds.x + px + imageBounds.width, bounds.y, bounds.width - px - imageBounds.width, bounds.height);
+ super.paintCell(cell, gc, b, configRegistry);
+ gc.drawImage(
+ image,
+ bounds.x + px,
+ bounds.y + py);
+ } else {
+ super.paintCell(cell, gc, bounds, configRegistry);
+ }
+ }
+
+// @Override
+// public Rectangle getWrappedPainterBounds(ILayerCell cell, GC gc, Rectangle bounds, IConfigRegistry configRegistry) {
+// Image image = getImage(cell, configRegistry);
+// if (image != null) {
+// Rectangle imageBounds = image.getBounds();
+// IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
+// int px = CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, bounds, imageBounds.width);
+// int py = CellStyleUtil.getVerticalAlignmentPadding(cellStyle, bounds, imageBounds.height);
+// Rectangle b = new Rectangle(bounds.x + px + imageBounds.width, bounds.y, bounds.width - px - imageBounds.width, bounds.height);
+// return b;
+//
+// }
+// return super.getWrappedPainterBounds(cell, gc, bounds, configRegistry);
+// }
+
+ /**
+ *
+ * @param cell
+ * The {@link ILayerCell} for which this {@link ImagePainter} is
+ * called.
+ * @param configRegistry
+ * The current {@link IConfigRegistry} to retrieve the cell style
+ * information from.
+ * @return The {@link Image} that should be painted by this
+ * {@link ImagePainter}.
+ */
+ protected Image getImage(ILayerCell cell, IConfigRegistry configRegistry) {
+ return CellStyleUtil.getCellStyle(cell, configRegistry).getAttributeValue(CellStyleAttributes.IMAGE);
+ }
+
+ /**
+ * @return <code>true</code> if this {@link ImagePainter} is resizing the
+ * cell width to show the whole configured image, <code>false</code>
+ * if the cell width is not touched by this painter.
+ */
+ public boolean isCalculateByWidth() {
+ return this.calculateByWidth;
+ }
+
+ /**
+ * Configure whether the {@link ImagePainter} should calculate the cell
+ * dimensions by containing image width. This means the <b>width</b> of the
+ * cell is calculated by image width.
+ *
+ * @param calculateByWidth
+ * <code>true</code> to calculate and modify the cell dimension
+ * according to the image width, <code>false</code> to not
+ * modifying the cell dimensions.
+ */
+ public void setCalculateByWidth(boolean calculateByWidth) {
+ this.calculateByWidth = calculateByWidth;
+ }
+
+ /**
+ * @return <code>true</code> if this {@link ImagePainter} is resizing the
+ * cell height to show the whole configured image,
+ * <code>false</code> if the cell height is not touched by this
+ * painter.
+ */
+ public boolean isCalculateByHeight() {
+ return this.calculateByHeight;
+ }
+
+ /**
+ * Configure whether the {@link ImagePainter} should calculate the cell
+ * dimensions by containing image height. This means the <b>height</b> of
+ * the cell is calculated by image height.
+ *
+ * @param calculateByHeight
+ * <code>true</code> to calculate and modify the cell dimension
+ * according to the image height, <code>false</code> to not
+ * modifying the cell dimensions.
+ */
+ public void setCalculateByHeight(boolean calculateByHeight) {
+ this.calculateByHeight = calculateByHeight;
+ }
+
+}