]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
AWTImage, ImageNode and E4WorkbenchUtils fixes 10/310/1
authorjsimomaa <jani.simomaa@gmail.com>
Tue, 24 Jan 2017 12:32:46 +0000 (14:32 +0200)
committerjsimomaa <jani.simomaa@gmail.com>
Wed, 1 Feb 2017 10:03:17 +0000 (12:03 +0200)
Change-Id: Idff447816036a07df4324be130dc1078b331ba0e

bundles/org.simantics.g2d/src/org/simantics/g2d/image/impl/AWTImage.java
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/ImageNode.java
bundles/org.simantics.ui/src/org/simantics/ui/workbench/e4/E4WorkbenchUtils.java

index e547a663e8e8844024f110485ee85ba81d7ee302..b6c6f891851fbe24673d85a3af3f8decf62077c0 100644 (file)
@@ -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;
     }
 
index df35e968ef41501bd537425e97a513759719d747..36112a15ed265b8344d2d5c14f0eb9e896d4675c 100644 (file)
@@ -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);
     }
index 5299b898124135056d6f4f04c248f2c6b9a2c150..54648e1026e119badb434b87b7bde2463f8608c0 100644 (file)
@@ -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) {