4 * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
7 * GiWoong Kim <giwoong.kim@samsung.com>
8 * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 package org.tizen.emulator.skin.layout;
31 import java.util.logging.Logger;
33 import org.eclipse.swt.SWT;
34 import org.eclipse.swt.graphics.Color;
35 import org.eclipse.swt.graphics.GC;
36 import org.eclipse.swt.graphics.Image;
37 import org.eclipse.swt.graphics.RGB;
38 import org.eclipse.swt.widgets.Display;
39 import org.tizen.emulator.skin.log.SkinLogger;
41 public class SkinPatches {
42 private Logger logger =
43 SkinLogger.getSkinLogger(SkinPatches.class).getLogger();
45 private Display display;
46 private String pathImage;
47 private int patchWidth;
48 private int patchHeight;
51 private Image imageLT; /* left-top */
52 private Image imageT; /* middle-top */
53 private Image imageRT; /* right-top */
58 private Image imageLB; /* left-bottom */
60 private Image imageRB;
63 private static final String SKIN_PATCH_IMG_LT = "LT.png";
64 private static final String SKIN_PATCH_IMG_T = "T.png";
65 private static final String SKIN_PATCH_IMG_RT = "RT.png";
67 private static final String SKIN_PATCH_IMG_L = "L.png";
68 private static final String SKIN_PATCH_IMG_R = "R.png";
70 private static final String SKIN_PATCH_IMG_LB = "LB.png";
71 private static final String SKIN_PATCH_IMG_B = "B.png";
72 private static final String SKIN_PATCH_IMG_RB = "RB.png";
74 public SkinPatches(String path) {
75 this.display = Display.getCurrent();
76 this.pathImage = path;
78 loadPatches(pathImage);
81 this.patchWidth = imageLT.getImageData().width;
82 this.patchHeight = imageLT.getImageData().height;
83 logger.info("patch size : " + patchWidth + "x" + patchHeight);
86 public int getPatchWidth() {
90 public int getPatchHeight() {
94 public Image getPatchedImage(int centerPatchWidth, int centerPatchHeight) {
95 int patchedImageWidth = (patchWidth * 2) + centerPatchWidth;
96 int patchedImageHeight = (patchHeight * 2) + centerPatchHeight;
98 Image patchedImage = new Image(display,
99 patchedImageWidth, patchedImageHeight);
101 // TODO: copy alphaData
102 GC gc = new GC(patchedImage);
103 gc.setBackground(display.getSystemColor(SWT.COLOR_MAGENTA));
104 gc.fillRectangle(0, 0, patchedImageWidth, patchedImageHeight);
107 gc.drawImage(imageLT, 0, 0);
108 gc.drawImage(imageT, 0, 0, imageT.getImageData().width, imageT.getImageData().height,
109 patchWidth, 0, centerPatchWidth, patchHeight);
110 gc.drawImage(imageRT, patchWidth + centerPatchWidth, 0);
113 gc.drawImage(imageL, 0, 0, imageL.getImageData().width, imageL.getImageData().height,
114 0, patchHeight, patchWidth, centerPatchHeight);
115 gc.setBackground(new Color(display, new RGB(38, 38, 38)));
116 gc.fillRectangle(patchWidth, patchHeight, centerPatchWidth, centerPatchHeight); /* center */
117 gc.drawImage(imageR, 0, 0, imageR.getImageData().width, imageR.getImageData().height,
118 patchWidth + centerPatchWidth, patchHeight, patchWidth, centerPatchHeight);
121 gc.drawImage(imageLB, 0, patchHeight + centerPatchHeight);
122 gc.drawImage(imageB, 0, 0, imageB.getImageData().width, imageB.getImageData().height,
123 patchWidth, patchHeight + centerPatchHeight, centerPatchWidth, patchHeight);
124 gc.drawImage(imageRB, patchWidth + centerPatchWidth, patchHeight + centerPatchHeight);
131 private void loadPatches(String path) {
132 ClassLoader loader = this.getClass().getClassLoader();
134 imageLT = new Image(display,
135 loader.getResourceAsStream(path + SKIN_PATCH_IMG_LT));
136 logger.info("left-top image is loaded from " +
137 path + SKIN_PATCH_IMG_LT);
138 imageT = new Image(display,
139 loader.getResourceAsStream(path + SKIN_PATCH_IMG_T));
140 imageRT = new Image(display,
141 loader.getResourceAsStream(path + SKIN_PATCH_IMG_RT));
143 imageL = new Image(display,
144 loader.getResourceAsStream(path + SKIN_PATCH_IMG_L));
145 imageR = new Image(display,
146 loader.getResourceAsStream(path + SKIN_PATCH_IMG_R));
148 imageLB = new Image(display,
149 loader.getResourceAsStream(path + SKIN_PATCH_IMG_LB));
150 imageB = new Image(display,
151 loader.getResourceAsStream(path + SKIN_PATCH_IMG_B));
152 imageRB = new Image(display,
153 loader.getResourceAsStream(path + SKIN_PATCH_IMG_RB));
156 public void freePatches() {