From: jsimomaa Date: Tue, 24 Jan 2017 12:32:46 +0000 (+0200) Subject: AWTImage, ImageNode and E4WorkbenchUtils fixes X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F10%2F310%2F1;p=simantics%2Fplatform.git AWTImage, ImageNode and E4WorkbenchUtils fixes Change-Id: Idff447816036a07df4324be130dc1078b331ba0e --- diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/image/impl/AWTImage.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/image/impl/AWTImage.java index e547a663e..b6c6f8918 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/image/impl/AWTImage.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/image/impl/AWTImage.java @@ -34,12 +34,18 @@ public class AWTImage extends AbstractImage implements Image { BufferedImage bi; Rectangle2D rect; + float alpha; - public AWTImage(BufferedImage bi) { + public AWTImage(BufferedImage bi, float alpha) { assert(bi!=null); this.bi = bi; + this.alpha = alpha; rect = new Rectangle2D.Double(bi.getMinX(),bi.getMinY(),bi.getWidth(), bi.getHeight()); } + + public AWTImage(BufferedImage bi) { + this(bi, 1.0f); + } @Override public Rectangle2D getBounds() { @@ -55,6 +61,8 @@ public class AWTImage extends AbstractImage implements Image { public Node init(G2DParentNode parent) { ImageNode node = parent.getOrCreateNode("image", ImageNode.class); node.setImage(bi); + node.setAlpha(alpha); + node.setZIndex(-100); return node; } diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/ImageNode.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/ImageNode.java index df35e968e..36112a15e 100644 --- a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/ImageNode.java +++ b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/ImageNode.java @@ -11,6 +11,8 @@ *******************************************************************************/ package org.simantics.scenegraph.g2d.nodes; +import java.awt.AlphaComposite; +import java.awt.Composite; import java.awt.Graphics2D; import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; @@ -28,6 +30,7 @@ public class ImageNode extends G2DNode { protected Boolean visible = Boolean.TRUE; protected BufferedImage img = null; + protected float alpha = 1.0f; @SyncField("visible") public void setVisible(Boolean visible) { @@ -49,6 +52,10 @@ public class ImageNode extends G2DNode { public void setImage(BufferedImage src) { img = src; } + + public void setAlpha(float alpha) { + this.alpha = alpha; + } @Override public void render(Graphics2D g) { @@ -65,8 +72,15 @@ public class ImageNode extends G2DNode { // Rectangle2D b = parent.getBoundsInLocal(); // g.drawImage(img, (int)b.getMinX(), (int)b.getMinY(), (int)b.getWidth()+(int)b.getMinX(), (int)b.getHeight()+(int)b.getMinY(), 0, 0, img.getWidth(), img.getHeight(), null); // } + + + Composite old = g.getComposite(); + g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f)); + g.drawImage(img, 0, 0, null); + if (old != null) + g.setComposite(old); if (ot != null) g.setTransform(ot); } diff --git a/bundles/org.simantics.ui/src/org/simantics/ui/workbench/e4/E4WorkbenchUtils.java b/bundles/org.simantics.ui/src/org/simantics/ui/workbench/e4/E4WorkbenchUtils.java index 5299b8981..54648e102 100644 --- a/bundles/org.simantics.ui/src/org/simantics/ui/workbench/e4/E4WorkbenchUtils.java +++ b/bundles/org.simantics.ui/src/org/simantics/ui/workbench/e4/E4WorkbenchUtils.java @@ -5,6 +5,7 @@ import java.util.Map; import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.ui.model.application.MApplication; +import org.eclipse.e4.ui.model.application.commands.MCommand; import org.eclipse.e4.ui.model.application.ui.MUIElement; import org.eclipse.e4.ui.model.application.ui.advanced.MArea; import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder; @@ -166,6 +167,17 @@ public class E4WorkbenchUtils { EPartService partService = context.get(EPartService.class); return partService.findPart(partId); } + + public static MCommand getMCommandById(String id) { + IEclipseContext context = PlatformUI.getWorkbench().getService(IEclipseContext.class); + MApplication application = context.get(MApplication.class); + for (MCommand command : application.getCommands()) { + if (id.equals(command.getElementId())) { + return command; + } + } + return null; + } @SuppressWarnings("restriction") public static IEditorPart getActiveIEditorPart(MPart mActiveEditorPart) {