X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.utils.ui%2Fsrc%2Forg%2Fsimantics%2Futils%2Fui%2Fgfx%2FCompositionImageDescriptor.java;fp=bundles%2Forg.simantics.utils.ui%2Fsrc%2Forg%2Fsimantics%2Futils%2Fui%2Fgfx%2FCompositionImageDescriptor.java;h=d96c2a2c12d3aa703500ac6803a4539096b0a7d1;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=35d49392ba048fba334df905d55456ff264c0b95;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/gfx/CompositionImageDescriptor.java b/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/gfx/CompositionImageDescriptor.java index 35d49392b..d96c2a2c1 100644 --- a/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/gfx/CompositionImageDescriptor.java +++ b/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/gfx/CompositionImageDescriptor.java @@ -1,160 +1,160 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -/* - * 27.12.2006 - */ -package org.simantics.utils.ui.gfx; - -import java.util.Collection; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.ImageData; -import org.eclipse.swt.graphics.PaletteData; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.RGB; -import org.simantics.utils.datastructures.Array; - -/** - * CompositionImageDescriptor is image description that composes - * multiple images into one image. - *

- * - * @author Toni Kalajainen - */ -@SuppressWarnings("deprecation") -public class CompositionImageDescriptor extends ImageDescriptor { - - public static final PaletteData DEFAULT_PALETTEDATA = - new PaletteData(0x00ff0000, 0x0000ff00, 0x000000ff); - - public static ImageDescriptor compose(ImageDescriptor ... imageDescriptors) { - if (imageDescriptors.length == 1) - return imageDescriptors[0]; - return new CompositionImageDescriptor(imageDescriptors); - } - - public static ImageDescriptor compose(Collection imageDescriptors) { - int size = imageDescriptors.size(); - if (size == 1) - return imageDescriptors.iterator().next(); - return new CompositionImageDescriptor(imageDescriptors.toArray(new ImageDescriptor[size])); - } - - ImageCache cache = ImageCache.getInstance(); - final Array ids; - Point size; - - public CompositionImageDescriptor(ImageDescriptor[] ids) { - this.ids = new Array(ids); - // Make sure that the argument is valid - assert (this.ids.size() > 0); - for (ImageDescriptor id : ids) - assert (id != null); - } - - public CompositionImageDescriptor(Array ids) { - this.ids = ids; - // Make sure that the argument is valid - assert (this.ids.size() > 0); - for (ImageDescriptor id : ids.toArray()) - assert (id != null); - } - - @Override - public ImageData getImageData() { - ImageDescriptor [] _ids = ids.toArray(); - if (_ids.length==1) - return cache.getImage(_ids[0]).getImageData(); - - Point s = getSize(); - PaletteData palette = DEFAULT_PALETTEDATA; - ImageData id = new ImageData(s.x, s.y, 24, palette); - id.setAlpha(0,0,0); - for (int i=0; i<_ids.length; i++) - { - ImageData layer = ImageCache.getInstance().getImage(_ids[i]).getImageData(); - int width = Math.min(s.x, layer.width); - int height = Math.min(s.y, layer.height); - PaletteData layerPaletteData = layer.palette; - if (layer.getTransparencyType()==SWT.TRANSPARENCY_MASK || - layer.getTransparencyType()==SWT.TRANSPARENCY_PIXEL) - { - ImageData mask = layer.getTransparencyMask(); - for (int y=0; ywidth) width = w; - int h = i.getImageData().height; - if (h>height) height = h; - } - return new Point(width, height); - } - - protected Point getSize() { - if (size==null) size = _countSize(); - return size; - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof CompositionImageDescriptor)) - return false; - CompositionImageDescriptor other = (CompositionImageDescriptor) obj; - return other.ids.equals(ids); - } - - @Override - public int hashCode() { - return ids.hashCode(); - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +/* + * 27.12.2006 + */ +package org.simantics.utils.ui.gfx; + +import java.util.Collection; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.graphics.PaletteData; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.RGB; +import org.simantics.utils.datastructures.Array; + +/** + * CompositionImageDescriptor is image description that composes + * multiple images into one image. + *

+ * + * @author Toni Kalajainen + */ +@SuppressWarnings("deprecation") +public class CompositionImageDescriptor extends ImageDescriptor { + + public static final PaletteData DEFAULT_PALETTEDATA = + new PaletteData(0x00ff0000, 0x0000ff00, 0x000000ff); + + public static ImageDescriptor compose(ImageDescriptor ... imageDescriptors) { + if (imageDescriptors.length == 1) + return imageDescriptors[0]; + return new CompositionImageDescriptor(imageDescriptors); + } + + public static ImageDescriptor compose(Collection imageDescriptors) { + int size = imageDescriptors.size(); + if (size == 1) + return imageDescriptors.iterator().next(); + return new CompositionImageDescriptor(imageDescriptors.toArray(new ImageDescriptor[size])); + } + + ImageCache cache = ImageCache.getInstance(); + final Array ids; + Point size; + + public CompositionImageDescriptor(ImageDescriptor[] ids) { + this.ids = new Array(ids); + // Make sure that the argument is valid + assert (this.ids.size() > 0); + for (ImageDescriptor id : ids) + assert (id != null); + } + + public CompositionImageDescriptor(Array ids) { + this.ids = ids; + // Make sure that the argument is valid + assert (this.ids.size() > 0); + for (ImageDescriptor id : ids.toArray()) + assert (id != null); + } + + @Override + public ImageData getImageData() { + ImageDescriptor [] _ids = ids.toArray(); + if (_ids.length==1) + return cache.getImage(_ids[0]).getImageData(); + + Point s = getSize(); + PaletteData palette = DEFAULT_PALETTEDATA; + ImageData id = new ImageData(s.x, s.y, 24, palette); + id.setAlpha(0,0,0); + for (int i=0; i<_ids.length; i++) + { + ImageData layer = ImageCache.getInstance().getImage(_ids[i]).getImageData(); + int width = Math.min(s.x, layer.width); + int height = Math.min(s.y, layer.height); + PaletteData layerPaletteData = layer.palette; + if (layer.getTransparencyType()==SWT.TRANSPARENCY_MASK || + layer.getTransparencyType()==SWT.TRANSPARENCY_PIXEL) + { + ImageData mask = layer.getTransparencyMask(); + for (int y=0; ywidth) width = w; + int h = i.getImageData().height; + if (h>height) height = h; + } + return new Point(width, height); + } + + protected Point getSize() { + if (size==null) size = _countSize(); + return size; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof CompositionImageDescriptor)) + return false; + CompositionImageDescriptor other = (CompositionImageDescriptor) obj; + return other.ids.equals(ids); + } + + @Override + public int hashCode() { + return ids.hashCode(); + } + +}