/* Log snapshot */
public static final int SNAPSHOT_IMAGE_PATH_INDEX = 12;
+ public static final int SNAPSHOT_ROTATE_INDEX = 13;
/* Log UserInterface Scene Transforms : 8 */
public static final int USER_INTERFACE_SCENE_TRANSFORMS_LIST_SCENE_NAME_INDEX = 12;
if (Integer.parseInt(logId) == LogCenterConstants.LOG_SCREENSHOT) {
String remoteImgPath = new String(
slicedLog[LogCenterConstants.SNAPSHOT_IMAGE_PATH_INDEX]);
- processImage(remoteImgPath);
+ String rotate = new String(
+ slicedLog[LogCenterConstants.SNAPSHOT_ROTATE_INDEX]);
+ processImage(remoteImgPath, rotate);
}
pushLog(logId, slicedLog, logPack);
CallStackManager.getInstance().makeCallstackWithoutBacktrace(
updateLog(logPack);
}
- private void processImage(final String from) {
+ private void processImage(final String from, String rotate) {
final String fileName = getImageName(from);
final String to = AnalyzerManager.getProject().getSavePath()
+ File.separator + AnalyzerConstants.IMAGE_FOLDER_NAME
+ File.separator + fileName;
+ final int angle = Integer.parseInt(rotate);
new Thread(null, new Runnable() {
@Override
+ File.separator
+ AnalyzerConstants.SMALL_IMAGE_FOLDER_NAME
+ File.separator + fileName;
- ImageUtil.resize(to, to, DEFAULT_IMG_WIDTH,
- DEFAULT_IMG_HEIGHT);
- ImageUtil.resize(to, smallImagePath, SMALL_IMG_WIDTH,
- SMALL_IMG_HEIGHT);
+ ImageUtil.transform(to, to, DEFAULT_IMG_WIDTH,
+ DEFAULT_IMG_HEIGHT, angle);
+ if (angle == 90 || angle == 270) {
+ ImageUtil.resize(to, smallImagePath, SMALL_IMG_HEIGHT,
+ SMALL_IMG_WIDTH);
+ } else {
+ ImageUtil.resize(to, smallImagePath, SMALL_IMG_WIDTH,
+ SMALL_IMG_HEIGHT);
+ }
} else {
System.out.println("Failed to get '" + from + "' file"); //$NON-NLS-1$ //$NON-NLS-2$
}
int childShellWidth = 0;
int childShellHeight = 0;
private int state = MOUSE_EXIT;
+ private int imageState = SnapshotConstants.IMAGE_TYPE_NORMAL;
private boolean mouseDown = false;
private int currentImageIndex = 0;
private boolean leftEnable = false;
Rectangle bounds = canvas.getClientArea();
int ix = 1, iy = 1;
+ int width = SnapshotConstants.MIN_IMAGE_WIDTH;
+ int height = SnapshotConstants.MIN_IMAGE_HEIGHT;
if (imgData.imgHeight > imgData.imgWidth) {
ix = (bounds.width - defaultChildWidth * 2) / 2;
+
} else {
- iy = (bounds.height - defaultChildHeight * 2) / 2;
+ width = SnapshotConstants.MIN_IMAGE_HEIGHT;
+ height = SnapshotConstants.MIN_IMAGE_WIDTH;
+ iy = (bounds.height - defaultChildWidth * 2) / 2;
}
imgData.gc.drawImage(image, 0, 0, imgData.imgWidth, imgData.imgHeight,
- ix, iy, SnapshotConstants.MIN_IMAGE_WIDTH,
- SnapshotConstants.MIN_IMAGE_HEIGHT);
+ ix, iy, width, height);
if (state == MOUSE_LEFT && leftEnable) {
imgData.gc.drawImage(ImageResources.SNAPSHOT_LEFT_HOVER, 0, 0);
} else if (state == MOUSE_RIGHT && rightEnable) {
setImage(img);
currentImageIndex = index;
canvas.redraw();
+ Rectangle rect = img.getBounds();
+ int imgType = SnapshotConstants.IMAGE_TYPE_NORMAL;
+ if (rect.width > rect.height) {
+ imgType = SnapshotConstants.IMAGE_TYPE_WIDE;
+ } else {
+ imgType = SnapshotConstants.IMAGE_TYPE_NORMAL;
+ }
if (childShell != null) {
- popup.redraw();
+ if (imageState != imgType) {
+ childShell.close();
+ childShell = null;
+ if (imgType == SnapshotConstants.IMAGE_TYPE_WIDE) {
+ childShellWidth = defaultShellMaxHeight;
+ childShellHeight = defaultShellMaxWidth;
+ } else {
+ childShellWidth = defaultShellMaxWidth;
+ childShellHeight = defaultShellMaxHeight;
+ }
+ openChildShell(false);
+ imageState = imgType;
+ } else {
+ popup.redraw();
+ }
}
}
}
setButtonCondition();
if (childShell == null) {
- openChildShell();
+ openChildShell(true);
}
} else if (event.type == SWT.MouseExit) {
if (childShell != null) {
widgetSelected(imgInfo.getTime());
}
- private void openChildShell() {
+ private void setShellSizes(int type) {
+ imageState = type;
+ if (type == SnapshotConstants.IMAGE_TYPE_WIDE) {
+ shellMaxHeight = defaultShellMaxWidth;
+ shellMaxWidth = defaultShellMaxHeight;
+ childWidth = defaultChildHeight;
+ childHeight = defaultChildWidth;
+ childShellWidth = defaultChildHeight;
+ childShellHeight = defaultChildWidth;
+ } else {
+ shellMaxHeight = defaultShellMaxHeight;
+ shellMaxWidth = defaultShellMaxWidth;
+ childWidth = defaultChildWidth;
+ childHeight = defaultChildHeight;
+ childShellWidth = defaultChildWidth;
+ childShellHeight = defaultChildHeight;
+ }
+ }
+
+ private void setChildShellSizes(int type) {
+ if (type == SnapshotConstants.IMAGE_TYPE_WIDE) {
+ shellMaxHeight = defaultShellMaxWidth;
+ shellMaxWidth = defaultShellMaxHeight;
+ childWidth = defaultChildHeight;
+ childHeight = defaultChildWidth;
+ } else {
+ shellMaxHeight = defaultShellMaxHeight;
+ shellMaxWidth = defaultShellMaxWidth;
+ childWidth = defaultChildWidth;
+ childHeight = defaultChildHeight;
+ }
+ }
+
+ private void openChildShell(boolean enableAnimation) {
if (null == image) {
return;
- } else {
+ } else if (enableAnimation) {
Rectangle rect = image.getBounds();
if (rect.width > rect.height) {
- shellMaxHeight = defaultShellMaxWidth;
- shellMaxWidth = defaultShellMaxHeight;
- childWidth = defaultChildHeight;
- childHeight = defaultChildWidth;
- childShellWidth = defaultChildHeight;
- childShellHeight = defaultChildWidth;
+ setShellSizes(SnapshotConstants.IMAGE_TYPE_WIDE);
} else {
- shellMaxHeight = defaultShellMaxHeight;
- shellMaxWidth = defaultShellMaxWidth;
- childWidth = defaultChildWidth;
- childHeight = defaultChildHeight;
- childShellWidth = defaultChildWidth;
- childShellHeight = defaultChildHeight;
+ setShellSizes(SnapshotConstants.IMAGE_TYPE_NORMAL);
}
}
childShell = new Shell(parent.getShell(), SWT.ON_TOP);
imageData.imgWidth = iw;
imageData.imgHeight = ih;
+ if (iw > ih) {
+ setChildShellSizes(SnapshotConstants.IMAGE_TYPE_WIDE);
+ } else {
+ setChildShellSizes(SnapshotConstants.IMAGE_TYPE_NORMAL);
+ }
Rectangle rects = popup.getBounds();
int cw = rects.width - 2;
int ch = rects.height - 2;
}
});
childShell.open();
- if (timer != null) {
- timer.cancel();
- timer = null;
- }
- timer = new Timer();
- timer.schedule(new TimerTask() {
- @Override
- public void run() {
- Display.getDefault().syncExec(new Runnable() {
- @Override
- public void run() {
- if (null == childShell
- || childShellWidth >= defaultShellMaxWidth) {
- if (timer != null) {
- timer.cancel();
- timer = null;
- }
- if (null != childShell && !childShell.isDisposed()) {
- childShell.redraw();
+
+ if (enableAnimation) {
+ if (timer != null) {
+ timer.cancel();
+ timer = null;
+ }
+ timer = new Timer();
+ timer.schedule(new TimerTask() {
+ @Override
+ public void run() {
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ if (null == childShell
+ || childShellWidth >= shellMaxWidth) {
+ if (timer != null) {
+ timer.cancel();
+ timer = null;
+ }
+ if (null != childShell
+ && !childShell.isDisposed()) {
+ childShell.redraw();
+ }
+ return;
}
- return;
+ int x = (shellMaxWidth - childWidth) / 3;
+ int y = (shellMaxHeight - childHeight) / 3;
+ childShellWidth += x;
+ childShellHeight += y;
+
+ childShellWidth = (childShellWidth > shellMaxWidth) ? shellMaxWidth
+ : childShellWidth;
+ childShellHeight = (childShellHeight > shellMaxHeight) ? shellMaxHeight
+ : childShellHeight;
+
+ childShell.setSize(childShellWidth,
+ childShellHeight);
+ Point p = canvas.toDisplay(0, 0);
+ childShell.setLocation(p.x - childShellWidth, p.y);
+ childShell.redraw();
}
- int x = (shellMaxWidth - childWidth) / 3;
- int y = (shellMaxHeight - childHeight) / 3;
- childShellWidth += x;
- childShellHeight += y;
-
- childShellWidth = (childShellWidth > defaultShellMaxWidth) ? defaultShellMaxWidth
- : childShellWidth;
- childShellHeight = (childShellHeight > defaultShellMaxHeight) ? defaultShellMaxHeight
- : childShellHeight;
-
- childShell.setSize(childShellWidth, childShellHeight);
- Point p = canvas.toDisplay(0, 0);
- childShell.setLocation(p.x - childShellWidth, p.y);
- childShell.redraw();
- }
- });
- }
- }, 10, 10);
+ });
+ }
+ }, 10, 10);
+ }
}
}
import javax.imageio.ImageIO;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.ImageData;
-
public class ImageUtil {
- public static void resize(String originFilePath, String newFilePath, int width,
- int height) {
+ public static void resize(String originFilePath, String newFilePath,
+ int width, int height) {
resize(originFilePath, newFilePath, width, height, null);
}
- public static void resize(String originFilePath, String newFilePath, int width,
- int height, Color color) {
+ public static void resize(String originFilePath, String newFilePath,
+ int width, int height, Color color) {
BufferedImage bufferedImage = null;
BufferedImage targetBufferedImage = null;
BufferedImage.TYPE_INT_RGB);
Graphics g = targetBufferedImage.getGraphics();
g.drawImage(scaledImage, 0, 0, null);
+
+ // color is outline
if (null != color) {
g.setColor(color);
g.drawLine(0, 0, 0, 49);
}
}
+ public static void transform(String originFilePath, String newFilePath,
+ int width, int height, int angle) {
+ BufferedImage bufferedImage = null;
+ BufferedImage targetBufferedImage = null;
+
+ File image = new File(originFilePath);
+ File destImage = new File(newFilePath);
+
+ try {
+ bufferedImage = ImageIO.read(image);
+ if (null == bufferedImage) {
+ return;
+ }
+ bufferedImage.getGraphics();
+
+ Image scaledImage = bufferedImage.getScaledInstance(width, height,
+ Image.SCALE_DEFAULT);
+
+ targetBufferedImage = new BufferedImage(width, height,
+ BufferedImage.TYPE_INT_RGB);
+ Graphics g = targetBufferedImage.getGraphics();
+ g.drawImage(scaledImage, 0, 0, null);
+ g.dispose();
+
+ BufferedImage outputBufferedImage = targetBufferedImage;
+ if (angle == 90) {
+ outputBufferedImage = rotateRight(targetBufferedImage);
+ } else if (angle == 270) {
+ outputBufferedImage = rotateLeft(targetBufferedImage);
+ } else if (angle == 180) {
+ outputBufferedImage = rotateRight(targetBufferedImage);
+ outputBufferedImage = rotateRight(outputBufferedImage);
+ }
+ ImageIO.write(outputBufferedImage, "PNG", destImage); //$NON-NLS-1$
+ } catch (IOException io) {
+ io.getStackTrace();
+ }
+ }
+
// FIXME : refactoring
- public static ImageData rotate(ImageData srcData, int direction) {
- int bytesPerPixel = srcData.bytesPerLine / srcData.width;
- int destBytesPerLine = (direction == SWT.DOWN) ? srcData.width
- * bytesPerPixel : srcData.height * bytesPerPixel;
- byte[] newData = new byte[(direction == SWT.DOWN) ? srcData.height
- * destBytesPerLine : srcData.width * destBytesPerLine];
- int width = 0, height = 0;
- for (int srcY = 0; srcY < srcData.height; srcY++) {
- for (int srcX = 0; srcX < srcData.width; srcX++) {
- int destX = 0, destY = 0, destIndex = 0, srcIndex = 0;
- switch (direction) {
- case SWT.LEFT: // left 90 degrees
- destX = srcY;
- destY = srcData.width - srcX - 1;
- width = srcData.height;
- height = srcData.width;
- break;
- case SWT.RIGHT: // right 90 degrees
- destX = srcData.height - srcY - 1;
- destY = srcX;
- width = srcData.height;
- height = srcData.width;
- break;
- case SWT.DOWN: // 180 degrees
- destX = srcData.width - srcX - 1;
- destY = srcData.height - srcY - 1;
- width = srcData.width;
- height = srcData.height;
- break;
- }
- destIndex = (destY * destBytesPerLine)
- + (destX * bytesPerPixel);
- srcIndex = (srcY * srcData.bytesPerLine)
- + (srcX * bytesPerPixel);
- System.arraycopy(srcData.data, srcIndex, newData, destIndex,
- bytesPerPixel);
+ public static BufferedImage rotateRight(BufferedImage input) {
+ int width = input.getWidth();
+ int height = input.getHeight();
+ BufferedImage output = new BufferedImage(height, width, input.getType());
+ for (int i = 0; i < width; i++) {
+ for (int ii = 0; ii < height; ii++) {
+ output.setRGB(height - ii - 1, i, input.getRGB(i, ii));
}
}
- // destBytesPerLine is used as scanlinePad to ensure that no padding is
- // required
- return new ImageData(width, height, srcData.depth, srcData.palette,
- srcData.scanlinePad, newData);
+ return output;
}
- public static ImageData flip(ImageData srcData, boolean vertical) {
- int bytesPerPixel = srcData.bytesPerLine / srcData.width;
- int destBytesPerLine = srcData.width * bytesPerPixel;
- byte[] newData = new byte[srcData.data.length];
- for (int srcY = 0; srcY < srcData.height; srcY++) {
- for (int srcX = 0; srcX < srcData.width; srcX++) {
- int destX = 0, destY = 0, destIndex = 0, srcIndex = 0;
- if (vertical) {
- destX = srcX;
- destY = srcData.height - srcY - 1;
- } else {
- destX = srcData.width - srcX - 1;
- destY = srcY;
- }
- destIndex = (destY * destBytesPerLine)
- + (destX * bytesPerPixel);
- srcIndex = (srcY * srcData.bytesPerLine)
- + (srcX * bytesPerPixel);
- System.arraycopy(srcData.data, srcIndex, newData, destIndex,
- bytesPerPixel);
+ public static BufferedImage rotateLeft(BufferedImage input) {
+ int width = input.getWidth();
+ int height = input.getHeight();
+ BufferedImage output = new BufferedImage(height, width, input.getType());
+ for (int i = 0; i < width; i++) {
+ for (int ii = 0; ii < height; ii++) {
+ output.setRGB(ii, width - i - 1, input.getRGB(i, ii));
}
}
- // destBytesPerLine is used as scanlinePad to ensure that no padding is
- // required
- return new ImageData(srcData.width, srcData.height, srcData.depth,
- srcData.palette, srcData.scanlinePad, newData);
+ return output;
}
}