public class GeneralPurposeSkinComposer implements ISkinComposer {
private static final String PATCH_IMAGES_PATH = "images/emul-window/";
+ private static final String TOGGLE_BUTTON_NORMAL_IMG = "arrow_nml.png";
+ private static final String TOGGLE_BUTTON_HOVER_IMG = "arrow_hover.png";
+ private static final String TOGGLE_BUTTON_PUSHED_IMG = "arrow_pushed.png";
+
+ private static final int PAIR_TAG_POSITION_X = 26;
+ private static final int PAIR_TAG_POSITION_Y = 13;
+ private static final int PAIR_TAG_POSITION_WIDTH = 8;
+ private static final int PAIR_TAG_POSITION_HEIGHT = 8;
private Logger logger = SkinLogger.getSkinLogger(
GeneralPurposeSkinComposer.class).getLogger();
private EmulatorConfig config;
private EmulatorSkin skin;
private Shell shell;
- private Canvas lcdCanvas;
+ private Canvas displayCanvas;
+ private Color backgroundColor;
private CustomButton toggleButton;
private EmulatorSkinState currentState;
this.grabPosition = new Point(0, 0);
this.frameMaker = new SkinPatches(PATCH_IMAGES_PATH);
+ this.backgroundColor = new Color(shell.getDisplay(), new RGB(38, 38, 38));
}
@Override
public Canvas compose() {
- lcdCanvas = new Canvas(shell, SWT.EMBEDDED); //TODO:
+ displayCanvas = new Canvas(shell, SWT.EMBEDDED); //TODO:
int x = config.getSkinPropertyInt(SkinPropertiesConstants.WINDOW_X,
EmulatorConfig.DEFAULT_WINDOW_X);
int scale = SkinUtil.getValidScale(config);
short rotationId = EmulatorConfig.DEFAULT_WINDOW_ROTATION;
- composeInternal(lcdCanvas, x, y, scale, rotationId);
+ composeInternal(displayCanvas, x, y, scale, rotationId);
logger.info("resolution : " + currentState.getCurrentResolution() +
", scale : " + scale);
- return lcdCanvas;
+ return displayCanvas;
}
@Override
- public void composeInternal(Canvas lcdCanvas,
+ public void composeInternal(Canvas displayCanvas,
final int x, final int y, int scale, short rotationId) {
//shell.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_BLACK));
String emulatorName = SkinUtil.makeEmulatorName(config);
shell.setText(emulatorName);
- lcdCanvas.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_BLACK));
+ displayCanvas.setBackground(
+ shell.getDisplay().getSystemColor(SWT.COLOR_BLACK));
if (SwtUtil.isWindowsPlatform()) {
shell.setImage(imageRegistry.getIcon(IconName.EMULATOR_TITLE_ICO));
/* load image for toggle button of key window */
ClassLoader loader = this.getClass().getClassLoader();
Image imageNormal = new Image(shell.getDisplay(),
- loader.getResourceAsStream(PATCH_IMAGES_PATH + "arrow_nml.png"));
+ loader.getResourceAsStream(PATCH_IMAGES_PATH + TOGGLE_BUTTON_NORMAL_IMG));
Image imageHover = new Image(shell.getDisplay(),
- loader.getResourceAsStream(PATCH_IMAGES_PATH + "arrow_hover.png"));
+ loader.getResourceAsStream(PATCH_IMAGES_PATH + TOGGLE_BUTTON_HOVER_IMG));
Image imagePushed = new Image(shell.getDisplay(),
- loader.getResourceAsStream(PATCH_IMAGES_PATH + "arrow_pushed.png"));
+ loader.getResourceAsStream(PATCH_IMAGES_PATH + TOGGLE_BUTTON_PUSHED_IMG));
/* create a toggle button of key window */
toggleButton = new CustomButton(shell, SWT.DRAW_TRANSPARENT | SWT.NO_FOCUS,
imageNormal, imageHover, imagePushed);
- toggleButton.setBackground(
- new Color(shell.getDisplay(), new RGB(0x1f, 0x1f, 0x1f)));
+ toggleButton.setBackground(backgroundColor);
toggleButton.addMouseListener(new MouseListener() {
@Override
/* make a pair tag circle */
skin.pairTagCanvas = new Canvas(shell, SWT.NO_FOCUS);
- skin.pairTagCanvas.setBackground(
- new Color(shell.getDisplay(), new RGB(38, 38, 38)));
+ skin.pairTagCanvas.setBackground(backgroundColor);
skin.pairTagCanvas.addPaintListener(new PaintListener() {
@Override
if (skin.colorPairTag != null) {
e.gc.setBackground(skin.colorPairTag);
e.gc.setAntialias(SWT.ON);
- e.gc.fillOval(0, 0, 8, 8);
+ e.gc.fillOval(
+ 0, 0, PAIR_TAG_POSITION_WIDTH, PAIR_TAG_POSITION_HEIGHT);
}
}
});
/* create a progress bar for booting status */
skin.bootingProgress = new CustomProgressBar(shell, SWT.NONE);
- skin.bootingProgress.setBackground(
- new Color(shell.getDisplay(), new RGB(38, 38, 38)));
+ skin.bootingProgress.setBackground(backgroundColor);
arrangeSkin(scale, rotationId);
currentState.setCurrentAngle(SkinRotation.getAngle(rotationId));
/* arrange the display */
- Rectangle lcdBounds = adjustLcdGeometry(lcdCanvas,
+ Rectangle displayBounds = adjustLcdGeometry(displayCanvas,
currentState.getCurrentResolutionWidth(),
currentState.getCurrentResolutionHeight(), scale, rotationId);
- if (lcdBounds == null) {
+ if (displayBounds == null) {
logger.severe("Failed to lcd information for phone shape skin.");
SkinUtil.openMessage(shell, null,
"Failed to read lcd information for phone shape skin.\n" +
SWT.ICON_ERROR, config);
System.exit(-1);
}
- logger.info("lcd bounds : " + lcdBounds);
+ logger.info("display bounds : " + displayBounds);
- currentState.setDisplayBounds(lcdBounds);
- lcdCanvas.setBounds(lcdBounds);
+ currentState.setDisplayBounds(displayBounds);
+ displayCanvas.setBounds(displayBounds);
/* arrange the skin image */
Image tempImage = null;
}
currentState.setCurrentImage(
- frameMaker.getPatchedImage(lcdBounds.width, lcdBounds.height));
+ frameMaker.getPatchedImage(displayBounds.width, displayBounds.height));
if (tempImage != null) {
tempImage.dispose();
}
/* arrange the toggle button of key window */
- toggleButton.setBounds(lcdBounds.x + lcdBounds.width,
- lcdBounds.y + (lcdBounds.height / 2) - (toggleButton.getImageSize().y / 2),
+ toggleButton.setBounds(displayBounds.x + displayBounds.width,
+ displayBounds.y + (displayBounds.height / 2) - (toggleButton.getImageSize().y / 2),
toggleButton.getImageSize().x, toggleButton.getImageSize().y);
/* arrange the progress bar */
if (skin.bootingProgress != null) {
- skin.bootingProgress.setBounds(lcdBounds.x,
- lcdBounds.y + lcdBounds.height + 1, lcdBounds.width, 2);
+ skin.bootingProgress.setBounds(displayBounds.x,
+ displayBounds.y + displayBounds.height + 1, displayBounds.width, 2);
}
/* custom window shape */
trimPatchedShell(shell, currentState.getCurrentImage());
/* arrange the pair tag */
- skin.pairTagCanvas.setBounds(26, 13, 8, 8);
+ skin.pairTagCanvas.setBounds(
+ PAIR_TAG_POSITION_X, PAIR_TAG_POSITION_Y,
+ PAIR_TAG_POSITION_WIDTH, PAIR_TAG_POSITION_HEIGHT);
/* set window size */
if (currentState.getCurrentImage() != null) {
@Override
public Rectangle adjustLcdGeometry(
- Canvas lcdCanvas, int resolutionW, int resolutionH,
+ Canvas displayCanvas, int resolutionW, int resolutionH,
int scale, short rotationId) {
Rectangle lcdBounds = new Rectangle(
int r = shell.getDisplay().getSystemColor(SWT.COLOR_MAGENTA).getRed();
int g = shell.getDisplay().getSystemColor(SWT.COLOR_MAGENTA).getGreen();
int b = shell.getDisplay().getSystemColor(SWT.COLOR_MAGENTA).getBlue();
- int colorKey;
+ int colorKey = 0;
if (SwtUtil.isWindowsPlatform()) {
colorKey = r << 24 | g << 16 | b << 8;
// }
//
// FormData dataComposite = new FormData();
-// dataComposite.left = new FormAttachment(lcdCanvas, 0);
+// dataComposite.left = new FormAttachment(displayCanvas, 0);
// dataComposite.top = new FormAttachment(0, 0);
// compositeBase.setLayoutData(dataComposite);
// }
skin.pairTagCanvas.dispose();
}
+ if (backgroundColor != null) {
+ backgroundColor.dispose();
+ }
+
frameMaker.freePatches();
}
}
private Image imageRB;
// TODO: configurable
- private static final String filenameLT = "LT.png";
- private static final String filenameT = "T.png";
- private static final String filenameRT = "RT.png";
+ private static final String SKIN_PATCH_IMG_LT = "LT.png";
+ private static final String SKIN_PATCH_IMG_T = "T.png";
+ private static final String SKIN_PATCH_IMG_RT = "RT.png";
- private static final String filenameL = "L.png";
- private static final String filenameR = "R.png";
+ private static final String SKIN_PATCH_IMG_L = "L.png";
+ private static final String SKIN_PATCH_IMG_R = "R.png";
- private static final String filenameLB = "LB.png";
- private static final String filenameB = "B.png";
- private static final String filenameRB = "RB.png";
+ private static final String SKIN_PATCH_IMG_LB = "LB.png";
+ private static final String SKIN_PATCH_IMG_B = "B.png";
+ private static final String SKIN_PATCH_IMG_RB = "RB.png";
public SkinPatches(String path) {
this.display = Display.getCurrent();
ClassLoader loader = this.getClass().getClassLoader();
imageLT = new Image(display,
- loader.getResourceAsStream(path + filenameLT));
- logger.info("left-top image is loaded from " + path + filenameLT);
+ loader.getResourceAsStream(path + SKIN_PATCH_IMG_LT));
+ logger.info("left-top image is loaded from " +
+ path + SKIN_PATCH_IMG_LT);
imageT = new Image(display,
- loader.getResourceAsStream(path + filenameT));
+ loader.getResourceAsStream(path + SKIN_PATCH_IMG_T));
imageRT = new Image(display,
- loader.getResourceAsStream(path + filenameRT));
+ loader.getResourceAsStream(path + SKIN_PATCH_IMG_RT));
imageL = new Image(display,
- loader.getResourceAsStream(path + filenameL));
+ loader.getResourceAsStream(path + SKIN_PATCH_IMG_L));
imageR = new Image(display,
- loader.getResourceAsStream(path + filenameR));
+ loader.getResourceAsStream(path + SKIN_PATCH_IMG_R));
imageLB = new Image(display,
- loader.getResourceAsStream(path + filenameLB));
+ loader.getResourceAsStream(path + SKIN_PATCH_IMG_LB));
imageB = new Image(display,
- loader.getResourceAsStream(path + filenameB));
+ loader.getResourceAsStream(path + SKIN_PATCH_IMG_B));
imageRB = new Image(display,
- loader.getResourceAsStream(path + filenameRB));
+ loader.getResourceAsStream(path + SKIN_PATCH_IMG_RB));
}
public void freePatches() {