import org.eclipse.swt.graphics.Color;
-public enum ColorKind {
+public enum ColorKind implements ResourceKind {
WHITE(255, 255, 255),
BLACK(0, 0, 0),
RED(255, 0, 0),
package org.tizen.emulator.manager.renewal.resources;
-import java.util.HashMap;
-import java.util.Map;
-
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;
private static ColorRegistry rootRegistry = new ColorRegistry();
public static Color get(ColorKind kind) {
- return rootRegistry.getColor(kind);
+ return rootRegistry.get(kind);
}
public static Color get(Platform platform, ColorKind kind) {
}
}
-final class ColorRegistry {
- private final Map<ColorKind, Color> colors = new HashMap<ColorKind, Color>();
-
+final class ColorRegistry extends ResourceRegistry<ColorKind, Color> {
ColorRegistry() {}
- Color getColor(ColorKind kind) {
- Color c = colors.get(kind);
-
- if (c == null) {
- c = new Color(Display.getCurrent(), new RGB(kind.r, kind.g, kind.b));
-
- colors.put(kind, c);
- }
-
- return c;
- }
-
- void dispose() {
- for (Color c : colors.values()) {
- c.dispose();
- }
+ @Override
+ Color getInternal(ColorKind kind) {
+ return new Color(Display.getCurrent(), new RGB(kind.r, kind.g, kind.b));
}
}
\ No newline at end of file
import org.eclipse.swt.widgets.Display;
import org.tizen.emulator.manager.EmulatorManager;
-public enum FontKind {
+public enum FontKind implements ResourceKind {
DEFAULT_FONT_8("default_font_8", 8, SWT.NORMAL),
DEFAULT_FONT_9("default_font_9", 9, SWT.NORMAL),
DEFAULT_FONT_10("default_font_10", 10, SWT.NORMAL),
package org.tizen.emulator.manager.renewal.resources;
-import java.util.HashMap;
-import java.util.Map;
-
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.widgets.Display;
public static Font get(FontKind kind) {
- return rootRegistry.getFont(kind);
+ return rootRegistry.get(kind);
}
public static Font get(Platform platform, FontKind kind) {
}
}
-final class FontRegistry {
- private final Map<FontKind, Font> fonts = new HashMap<FontKind, Font>();
-
+final class FontRegistry extends ResourceRegistry<FontKind, Font> {
FontRegistry() {}
- Font getFont(FontKind kind) {
- Font f = fonts.get(kind);
-
- if (f == null) {
- f = new Font(Display.getCurrent(), new FontData(kind.fontName, kind.size, kind.style));
-
- fonts.put(kind, f);
- }
-
- return f;
- }
-
- void dispose() {
- for (Font f : fonts.values()) {
- f.dispose();
- }
+ @Override
+ Font getInternal(FontKind kind) {
+ return new Font(Display.getCurrent(), new FontData(kind.fontName, kind.size, kind.style));
}
}
\ No newline at end of file
package org.tizen.emulator.manager.renewal.resources;
-public enum ImageKind {
+public enum ImageKind implements ResourceKind {
// 9p button disable
BTN_DISABLE_B("9p_btn_disable_b"),
BTN_DISABLE_L("9p_btn_disable_l"),
import java.io.IOException;
import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
public static Image get(ImageKind kind) {
- return rootRegistry.getImage(kind);
+ return rootRegistry.get(kind);
}
public static Image get(Platform platform, ImageKind kind) {
platform.setImageRegistry(new ImageRegistry(platform));
}
- return ((ImageRegistry)platform.getImageRegistry()).getImage(kind);
+ return ((ImageRegistry)platform.getImageRegistry()).get(kind);
}
public static void dispose() {
}
}
-final class ImageRegistry {
- private final Map<ImageKind, Image> images = new HashMap<ImageKind, Image>();
+final class ImageRegistry extends ResourceRegistry<ImageKind, Image> {
private final Platform platform;
+
ImageRegistry(Platform platform) {
// If platform is null, we will use root class loader.
this.platform = platform;
}
- Image getImage(ImageKind kind) {
- Image i = images.get(kind);
-
- if (i == null) {
- InputStream is = ResourceLoader.load(kind.name + "." + kind.type, platform); //$NON-NLS-1$ //$NON-NLS-2$
- if (is != null) {
- i = new Image(Display.getCurrent(), is);
- try {
- is.close();
- } catch (IOException e) {
- EMLogger.getLogger().info(e.getMessage());
- }
- }
+ @Override
+ Image getInternal(ImageKind kind) {
+ Image i = null;
- if (i == null) {
- i = Display.getCurrent().getSystemImage(SWT.ICON_WARNING);
+ InputStream is = ResourceLoader.load(kind.name + "." + kind.type, platform); //$NON-NLS-1$ //$NON-NLS-2$
+ if (is != null) {
+ i = new Image(Display.getCurrent(), is);
+ try {
+ is.close();
+ } catch (IOException e) {
+ EMLogger.getLogger().info(e.getMessage());
}
+ }
- images.put(kind, i);
+ if (i == null) {
+ i = Display.getCurrent().getSystemImage(SWT.ICON_WARNING);
}
return i;
}
- void dispose() {
- for (Image i : images.values()) {
- i.dispose();
- }
- }
-
@Deprecated
static Image getImage(ImageResource res, ImageType type) {
Image i = null;
--- /dev/null
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2016 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>
+ *
+ * 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.renewal.resources;
+
+interface ResourceKind {
+ // empty interface
+}
--- /dev/null
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2016 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>
+ *
+ * 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.renewal.resources;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.swt.graphics.Resource;
+
+public abstract class ResourceRegistry<K extends ResourceKind, T extends Resource> {
+ protected final Map<K, T> resources = new HashMap<K, T>();
+
+
+ ResourceRegistry() {}
+
+ T get(K kind) {
+ T r = resources.get(kind);
+
+ if (r == null) {
+ r = getInternal(kind);
+
+ resources.put(kind, r);
+ }
+
+ return r;
+ }
+
+ abstract T getInternal(K kind);
+
+ void dispose() {
+ for (T r : resources.values()) {
+ r.dispose();
+ }
+ }
+}