- Image file name in plugin is changed.
- Refactoring VMButton painter.(Added common class)
- Added custom vm button image for default use.
Change-Id: I32c969ae38f2de91c95b9f4c36b1495a5d2426b0
Signed-off-by: minkee.lee <minkee.lee@samsung.com>
import java.io.IOException;
import java.io.InputStream;
+import java.net.URL;
import java.net.URLClassLoader;
import java.util.HashMap;
import java.util.Map;
import org.tizen.emulator.manager.platform.ProfileList;
import org.tizen.emulator.manager.resources.ImageResources;
import org.tizen.emulator.manager.resources.ImageType;
+import org.tizen.emulator.manager.ui.dialog.MessageDialog;
+import org.tizen.emulator.manager.vms.SKIN_SHAPE;
public enum PluginImageResources {
VM_IMAGE_NOMAL("emulator_list_image_nml"),
this.frames = new HashMap<String, ImageData[]>();
}
- public Image getImage(String platformName, String shape) {
- String group = platformName;
- if (shape != null && !shape.isEmpty()) {
- group += "-" + shape;
- }
- return getImage(group);
+ public Image getImage(String platformName) {
+ return getImage(platformName, null);
}
// TODO
- public Image getImage(String platformName) {
- Image i = image.get(platformName);
+ public Image getImage(String platformName, SKIN_SHAPE shape) {
+ String prefix = platformName;
+ if (shape != null) {
+ prefix += "-" + shape.toString();
+ }
+ Image i = image.get(prefix);
if (i == null) {
switch(this.type) {
case GIF:
- i = ImageRegistry.getGifImage(name, platformName);
+ i = ImageRegistry.getGifImage(name, platformName, shape);
break;
case PNG:
- i = ImageRegistry.getPngImage(name, platformName);
+ i = ImageRegistry.getPngImage(name, platformName, shape);
}
- image.put(platformName, i);
+ image.put(prefix, i);
}
return i;
}
}
}
- public static Image getPngImage(String name, String platformName) {
- return getImage(name, platformName, "png");
+ public static Image getPngImage(String name, String platformName, SKIN_SHAPE skinShape) {
+ return getImage(name, platformName, skinShape, "png");
}
- public static Image getGifImage(String name, String platformName) {
- return getImage(name, platformName, "gif");
+ public static Image getGifImage(String name, String platformName, SKIN_SHAPE skinShape) {
+ return getImage(name, platformName, skinShape, "gif");
}
private static URLClassLoader findLoader(String platformName) {
}
return null;
}
- public static Image getImage(String name, String platformName, String extension) {
- Image i = map.get(name+platformName);
- loader = findLoader(platformName);
- if (i == null && loader != null) {
- InputStream is = loader.getResourceAsStream("res/" + platformName + "_" + name + "." + extension);
- if (is != null) {
- i = new Image(Display.getCurrent(), is);
- map.put(name+platformName, i);
- try {
- is.close();
- } catch (IOException e) {
- EMLogger.getLogger().warning(e.getMessage());
+ public static Image getImage(String name, String platformName, SKIN_SHAPE skinShape, String extension) {
+ String shape = "";
+ if (skinShape != null) {
+ shape = skinShape.toString();
+ }
+ Image i = map.get(name + platformName + shape);
+
+ // Get image from plugin resource.
+ if (i == null) {
+ loader = findLoader(platformName);
+ if (loader != null) {
+ InputStream is = null;
+ URL url = loader.findResource("res/" + shape + "_" + name + "." + extension);
+ if (url == null) {
+ // remove shape prefix
+ url = loader.findResource("res/" + name + "." + extension);
+ }
+ if (url != null) {
+ try {
+ is = url.openStream();
+ } catch (IOException e) {
+ EMLogger.getLogger().warning(e.getMessage());
+ }
+ }
+ if (is != null) {
+ i = new Image(Display.getCurrent(), is);
+ map.put(name + platformName + shape, i);
+ try {
+ is.close();
+ } catch (IOException e) {
+ EMLogger.getLogger().warning(e.getMessage());
+ }
}
}
}
+ // Get image from common resource.
if (i == null){
i = ImageResources.getImage(name, extension);
}
+ if (i == null) {
+ final String fileInfo = name + "." + extension + " (" + platformName + ")";
+ Display.getCurrent().asyncExec(new Runnable() {
+ public void run() {
+ new MessageDialog().openWarningDialog("Failed to load image resources : \n"
+ + fileInfo);
+ }
+ });
+ }
+
return i;
}
--- /dev/null
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * JiHye Kim <jihye424.kim@samsung.com>
+ * Minkee Lee <minkee.lee@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * Sangho Park <sangho1206.park@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.emulator.manager.ui.widgets;
+
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Canvas;
+import org.tizen.emulator.manager.platform.Skin;
+import org.tizen.emulator.manager.plugin.PluginImageResources;
+import org.tizen.emulator.manager.vms.SKIN_SHAPE;
+
+public abstract class CommonVMButtonPainter implements PaintListener {
+
+ protected int BUTTON_X_OFFSET = 2;
+ protected int BUTTON_Y_OFFSET = 3;
+ protected int TEXT_X_POINT = 50 + BUTTON_X_OFFSET;
+ protected int TEXT_Y_POINT = 36 + BUTTON_Y_OFFSET;
+ protected int TEXT_Y_GAP = 18;
+ protected int TEXT_RE_X_POINT = 26 + BUTTON_X_OFFSET;
+ protected int TITLE_Y_OFFSET = 6;
+ protected int LAUNCH_BUTTON_LEFT_OFFSET = 13;
+ protected int LAUNCH_BUTTON_BOTTOM_OFFSET = 13;
+ protected int TITLE_X_OFFSET = 9;
+
+ public abstract void drawButtonText(GC gc, Rectangle rect, VMButton button);
+
+ @Override
+ public void paintControl(PaintEvent e) {
+ VMButton button = (VMButton) e.widget;
+ WSTATE state = button.currentState();
+ Image image = button.getImage(state);
+
+ if (image == null) {
+ return;
+ }
+
+ SKIN_SHAPE skinShape = null;
+ if (button.getProperty() != null) {
+ Skin skin = button.getProperty().getPropertyValue().skin;
+ if (skin != null) {
+ skinShape = skin.getSkinShape();
+ }
+ }
+
+ if (button.getProperty() != null) {
+ if (button.getProperty().isRunning()) {
+ button.getLaunchButton().setEnabled(false);
+ } else {
+ button.getLaunchButton().setEnabled(true);
+ }
+
+ // If VM is custom,
+ if (!button.getProperty().getPropertyValue().isStandard) {
+ if (state == WSTATE.HOVER || state == WSTATE.SELECTED_HOVER) {
+ image = PluginImageResources.VM_IMAGE_CUSTOM_HOVER
+ .getImage(button.getPlatformName(), skinShape);
+ } else {
+ image = PluginImageResources.VM_IMAGE_CUSTOM_NORMAL
+ .getImage(button.getPlatformName(), skinShape);
+ }
+ }
+ }
+
+ if (image == null) {
+ return;
+ }
+
+ Rectangle rect = ((Canvas) e.widget).getClientArea();
+ GC gc = e.gc;
+
+ gc.setBackground(button.getBackgroundColor(button.currentState()));
+ gc.fillRectangle(rect);
+ gc.drawImage(image, rect.x + BUTTON_X_OFFSET, rect.y + BUTTON_Y_OFFSET);
+ if (button.isSelection()) {
+ Image selectionImage = PluginImageResources.VM_IMAGE_SELECTED
+ .getImage(button.getPlatformName(), skinShape);
+ if (selectionImage == null) {
+ return;
+ }
+ gc.drawImage(selectionImage, rect.x, rect.y);
+ }
+ drawButtonText(gc, rect, button);
+ }
+
+ public int getLaunchButtonLeftOffset() {
+ return LAUNCH_BUTTON_LEFT_OFFSET;
+ }
+
+ public int getLaunchButtonBottomOffset() {
+ return LAUNCH_BUTTON_BOTTOM_OFFSET;
+ }
+
+ public int getTitleOffset() {
+ return TITLE_X_OFFSET;
+ }
+}
private VMProperty property = null;
protected ImageButton launchButton = null;
protected String platformName;
+ private SKIN_SHAPE skinShape = null;
private int BUTTON_WIDTH = 106;
private int BUTTON_HEIGHT = 146;
private int launchButtonLeftOffset;
private int launchButtonBottomOffset;
+ private int titleOffset;
+
public VMButton(Composite parent, int style, Platform platform, VMProperty property) {
super(parent, style);
this.property = property;
if (item != null) {
this.setPainListener((PaintListener)item.createInstance());
- launchButtonLeftOffset = ((IVMButtonPainter)item.createInstance()).getLaunchButtonLeftOffset();
- launchButtonBottomOffset = ((IVMButtonPainter)item.createInstance()).getLaunchButtonBottomOffset();
+ launchButtonLeftOffset = ((CommonVMButtonPainter)item.createInstance()).getLaunchButtonLeftOffset();
+ launchButtonBottomOffset = ((CommonVMButtonPainter)item.createInstance()).getLaunchButtonBottomOffset();
+ titleOffset = ((CommonVMButtonPainter)item.createInstance()).getTitleOffset();
} else {
this.setPainListener(VMButtonPaintListener);
launchButtonLeftOffset = 13;
launchButtonBottomOffset = 13;
+ titleOffset = 9;
}
settingImage();
}
private void settingImage() {
- String shape="";
if (button.getProperty() != null) {
Skin skin = button.getProperty().getPropertyValue().skin;
- if (skin != null && skin.getSkinShape() == SKIN_SHAPE.CIRCLE) {
- shape = skin.getSkinShape().toString();
+ if (skin != null) {
+ skinShape = skin.getSkinShape();
}
}
for (WSTATE s : WSTATE.values()) {
- images.add(s.getId(), PluginImageResources.VM_IMAGE_NOMAL.getImage(platformName, shape));
+ images.add(s.getId(), PluginImageResources.VM_IMAGE_NOMAL.getImage(platformName, skinShape));
}
BUTTON_WIDTH = images.get(0).getImageData().width;
BUTTON_HEIGHT = images.get(0).getImageData().height;
- images.set(WSTATE.HOVER.getId(), PluginImageResources.VM_IMAGE_HOVER.getImage(platformName, shape));
- images.set(WSTATE.SELECTED_HOVER.getId(), PluginImageResources.VM_IMAGE_HOVER.getImage(platformName, shape));
+ images.set(WSTATE.HOVER.getId(), PluginImageResources.VM_IMAGE_HOVER.getImage(platformName, skinShape));
+ images.set(WSTATE.SELECTED_HOVER.getId(), PluginImageResources.VM_IMAGE_HOVER.getImage(platformName, skinShape));
}
@Override
}
private void settingLaunchButton() {
- Image image = PluginImageResources.BUTTON_LAUNCH_NOMAL.getImage(platformName);
- Image pushImage = PluginImageResources.BUTTON_LAUNCH_PUSH.getImage(platformName);
+ Image image = PluginImageResources.BUTTON_LAUNCH_NOMAL.getImage(platformName, skinShape);
+ Image pushImage = PluginImageResources.BUTTON_LAUNCH_PUSH.getImage(platformName, skinShape);
LAUNCH_BUTTON_WIDTH = image.getImageData().width;
LAUNCH_BUTTON_HEIGHT = image.getImageData().height;
launchButton = new ImageButton(this, SWT.PUSH);
launchButton.setImages(image,
- PluginImageResources.BUTTON_LAUNCH_HOVER.getImage(platformName),
+ PluginImageResources.BUTTON_LAUNCH_HOVER.getImage(platformName, skinShape),
pushImage,
pushImage,
pushImage,
pushImage,
- PluginImageResources.BUTTON_LAUNCH_DISABLE.getImage(platformName));
+ PluginImageResources.BUTTON_LAUNCH_DISABLE.getImage(platformName, skinShape));
FormData data = new FormData();
//data.top = new FormAttachment(0, 119 + H_OFFSET);
}
private String title = "";
- private static int TITLE_OFFSET = 10;
private int title_x = 10;
private static String omit = "...";
Point p = null;
p = gc.textExtent(property.getName(), SWT.DRAW_MNEMONIC);
- if (p.x < (BUTTON_WIDTH - 14)) {
- title_x = ((BUTTON_WIDTH - 14 - p.x) / 2) + TITLE_OFFSET;
+ if (p.x < (BUTTON_WIDTH - (titleOffset * 2))) {
+ title_x = ((BUTTON_WIDTH - p.x) / 2);
title = property.getName();
} else {
- title_x = TITLE_OFFSET;
+ title_x = titleOffset;
String name = property.getName();
- while (p.x > ((BUTTON_WIDTH - 26) - omitLen)) {
+ while (p.x > ((BUTTON_WIDTH - (titleOffset * 2)) - omitLen)) {
name = name.substring(0, name.length() - 1);
p = gc.textExtent(name, SWT.DRAW_MNEMONIC);
}
gc.fillRectangle(rect);
gc.drawImage(image, rect.x + W_OFFSET, rect.y + H_OFFSET);
if (isSelection()) {
- gc.drawImage(PluginImageResources.VM_IMAGE_SELECTED.getImage(platformName), rect.x, rect.y);
+ gc.drawImage(PluginImageResources.VM_IMAGE_SELECTED.getImage(platformName, null), rect.x, rect.y);
}
drawButtonText(gc, rect);
}