aboutsummaryrefslogtreecommitdiffstats
path: root/hierarchyviewer2/libs
diff options
context:
space:
mode:
authorKonstantin Lopyrev <klopyrev@google.com>2010-08-25 12:17:49 -0700
committerKonstantin Lopyrev <klopyrev@google.com>2010-08-27 09:09:02 -0700
commit285f39916682c0f70a8dc9ccd930affa37365b97 (patch)
treecfa5b242487f389250f2afe8e25cb8a1704c4ff8 /hierarchyviewer2/libs
parent9e792a08b994786c022519f6ee95de5939cf7eed (diff)
downloadsdk-285f39916682c0f70a8dc9ccd930affa37365b97.zip
sdk-285f39916682c0f70a8dc9ccd930affa37365b97.tar.gz
sdk-285f39916682c0f70a8dc9ccd930affa37365b97.tar.bz2
Commentary, getting rid of bad about image, and some clean-up.
Change-Id: I9dad056de8e7e208f156bbedbced47dd49b61fcb
Diffstat (limited to 'hierarchyviewer2/libs')
-rw-r--r--hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/device/DeviceBridge.java2
-rw-r--r--hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/models/DeviceSelectionModel.java11
-rw-r--r--hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/CaptureDisplay.java3
-rw-r--r--hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/DeviceSelector.java4
-rw-r--r--hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/LayoutViewer.java4
-rw-r--r--hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/PixelPerfect.java6
-rw-r--r--hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/PixelPerfectLoupe.java1
-rw-r--r--hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/PropertyViewer.java3
-rw-r--r--hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/TreeView.java276
-rw-r--r--hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/TreeViewOverview.java5
-rw-r--r--hierarchyviewer2/libs/hierarchyviewerlib/src/resources/images/about-small.jpgbin467 -> 1578 bytes
-rw-r--r--hierarchyviewer2/libs/hierarchyviewerlib/src/resources/images/about.jpgbin27144 -> 17237 bytes
12 files changed, 169 insertions, 146 deletions
diff --git a/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/device/DeviceBridge.java b/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/device/DeviceBridge.java
index 54ea9f8..9e91375 100644
--- a/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/device/DeviceBridge.java
+++ b/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/device/DeviceBridge.java
@@ -357,7 +357,7 @@ public class DeviceBridge {
}
}
// Automatic refreshing of windows was added in protocol version 3.
- // Before, the user needed to specify explicitely that he wants to
+ // Before, the user needed to specify explicitly that he wants to
// get the focused window, which was done using a special type of
// window with hash code -1.
if (serverInfo.protocolVersion < 3) {
diff --git a/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/models/DeviceSelectionModel.java b/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/models/DeviceSelectionModel.java
index d8a9a4f..8888642 100644
--- a/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/models/DeviceSelectionModel.java
+++ b/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/models/DeviceSelectionModel.java
@@ -110,18 +110,11 @@ public class DeviceSelectionModel {
public void updateFocusedWindow(IDevice device, int focusedWindow) {
Integer oldValue = null;
synchronized (deviceMap) {
- // A value of -1 means that no window has focus. This is a strange
- // transitive state in the window manager service.
- if (focusedWindow == -1) {
- oldValue = focusedWindowHashes.remove(device);
- } else {
- oldValue = focusedWindowHashes.put(device, new Integer(focusedWindow));
- }
+ oldValue = focusedWindowHashes.put(device, new Integer(focusedWindow));
}
// Only notify if the values are different. It would be cool if Java
// containers accepted basic types like int.
- if ((oldValue == null && focusedWindow != -1)
- || (oldValue != null && oldValue.intValue() != focusedWindow)) {
+ if (oldValue == null || (oldValue != null && oldValue.intValue() != focusedWindow)) {
notifyFocusChanged(device);
}
}
diff --git a/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/CaptureDisplay.java b/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/CaptureDisplay.java
index 5d4c481..3c2c356 100644
--- a/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/CaptureDisplay.java
+++ b/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/CaptureDisplay.java
@@ -94,14 +94,12 @@ public class CaptureDisplay {
shell.setLayout(gridLayout);
buttonBar = new Composite(shell, SWT.NONE);
- // buttonBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL);
rowLayout.pack = true;
rowLayout.center = true;
buttonBar.setLayout(rowLayout);
Composite buttons = new Composite(buttonBar, SWT.NONE);
buttons.setLayout(new FillLayout());
- // buttons.setLayoutData(new RowData());
onWhite = new Button(buttons, SWT.TOGGLE);
onWhite.setText("On White");
@@ -112,7 +110,6 @@ public class CaptureDisplay {
onBlack.addSelectionListener(blackSelectionListener);
showExtras = new Button(buttonBar, SWT.CHECK);
- // showExtras.setLayoutData(new RowData());
showExtras.setText("Show Extras");
showExtras.addSelectionListener(extrasSelectionListener);
diff --git a/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/DeviceSelector.java b/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/DeviceSelector.java
index 2a11df1..1aded6b 100644
--- a/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/DeviceSelector.java
+++ b/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/DeviceSelector.java
@@ -202,7 +202,8 @@ public class DeviceSelector extends Composite implements WindowChangeListener, S
}
};
- // HACK TO GET RID OF AN ERROR
+ // If the window gets too small, hide the data, otherwise SWT throws an
+ // ERROR.
private ControlListener controlListener = new ControlAdapter() {
private boolean noInput = false;
@@ -272,7 +273,6 @@ public class DeviceSelector extends Composite implements WindowChangeListener, S
}
public void widgetDefaultSelected(SelectionEvent e) {
- // TODO: Double click to open view hierarchy
Object selection = ((TreeItem) e.item).getData();
if (selection instanceof IDevice) {
HierarchyViewerDirector.getDirector().loadPixelPerfectData((IDevice) selection);
diff --git a/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/LayoutViewer.java b/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/LayoutViewer.java
index 458bae6..6ae086d 100644
--- a/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/LayoutViewer.java
+++ b/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/LayoutViewer.java
@@ -259,6 +259,9 @@ public class LayoutViewer extends Canvas implements TreeChangeListener {
int y2 =
Math.min(parentClipping.y + parentClipping.height, top + node.viewNode.height
+ (int) Math.ceil(0.3 / scale));
+
+ // Clipping is weird... You set it to -5 and it comes out 17 or
+ // something.
if (x2 <= x1 || y2 <= y1) {
return;
}
@@ -321,6 +324,7 @@ public class LayoutViewer extends Canvas implements TreeChangeListener {
doRedraw();
}
+ // Note the syncExec and then synchronized... It avoids deadlock
public void treeChanged() {
Display.getDefault().syncExec(new Runnable() {
public void run() {
diff --git a/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/PixelPerfect.java b/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/PixelPerfect.java
index 05b9679..242270b 100644
--- a/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/PixelPerfect.java
+++ b/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/PixelPerfect.java
@@ -208,10 +208,7 @@ public class PixelPerfect extends ScrolledComposite implements ImageChangeListen
}
if (selectedNode != null) {
- // There are a few quirks here. First of all, margins
- // are sometimes negative or positive numbers... Yet,
- // they are always treated as positive.
- // Secondly, if the screen is in landscape mode, the
+ // If the screen is in landscape mode, the
// coordinates are backwards.
int leftShift = 0;
int topShift = 0;
@@ -339,6 +336,7 @@ public class PixelPerfect extends ScrolledComposite implements ImageChangeListen
doRedraw();
}
+ // Note the syncExec and then synchronized... It avoids deadlock
public void treeChanged() {
Display.getDefault().syncExec(new Runnable() {
public void run() {
diff --git a/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/PixelPerfectLoupe.java b/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/PixelPerfectLoupe.java
index 5497a3f..b5ad13a 100644
--- a/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/PixelPerfectLoupe.java
+++ b/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/PixelPerfectLoupe.java
@@ -293,6 +293,7 @@ public class PixelPerfectLoupe extends Canvas implements ImageChangeListener {
}
}
+ // Note the syncExec and then synchronized... It avoids deadlock
public void imageLoaded() {
Display.getDefault().syncExec(new Runnable() {
public void run() {
diff --git a/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/PropertyViewer.java b/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/PropertyViewer.java
index 0b76909..d7c5b1a 100644
--- a/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/PropertyViewer.java
+++ b/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/PropertyViewer.java
@@ -230,7 +230,8 @@ public class PropertyViewer extends Composite implements TreeChangeListener {
}
};
- // HACK TO GET RID OF AN ERROR
+ // If the window gets too small, hide the data, otherwise SWT throws an
+ // ERROR.
private ControlListener controlListener = new ControlAdapter() {
private boolean noInput = false;
diff --git a/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/TreeView.java b/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/TreeView.java
index f4e9019..b7d9303 100644
--- a/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/TreeView.java
+++ b/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/TreeView.java
@@ -112,6 +112,37 @@ public class TreeView extends Canvas implements TreeChangeListener {
private DrawableViewNode lastDrawnSelectedViewNode;
+ // The profile-image box needs to be moved to,
+ // so add some dragging leeway.
+ private static final int DRAG_LEEWAY = 220;
+
+ // Profile-image box constants
+ private static final int RECT_WIDTH = 190;
+
+ private static final int RECT_HEIGHT = 224;
+
+ private static final int BUTTON_RIGHT_OFFSET = 5;
+
+ private static final int BUTTON_TOP_OFFSET = 5;
+
+ private static final int IMAGE_WIDTH = 125;
+
+ private static final int IMAGE_HEIGHT = 120;
+
+ private static final int IMAGE_OFFSET = 6;
+
+ private static final int IMAGE_ROUNDING = 8;
+
+ private static final int RECTANGLE_SIZE = 5;
+
+ private static final int TEXT_SIDE_OFFSET = 8;
+
+ private static final int TEXT_TOP_OFFSET = 4;
+
+ private static final int TEXT_SPACING = 2;
+
+ private static final int TEXT_ROUNDING = 20;
+
public TreeView(Composite parent) {
super(parent, SWT.NONE);
@@ -164,8 +195,7 @@ public class TreeView extends Canvas implements TreeChangeListener {
synchronized (TreeView.this) {
if (tree != null && viewport != null) {
- // I don't know what the best behaviour is... This seems
- // like a good idea.
+ // Keep the center in the same place.
Point viewCenter =
new Point(viewport.x + viewport.width / 2, viewport.y + viewport.height
/ 2);
@@ -196,10 +226,12 @@ public class TreeView extends Canvas implements TreeChangeListener {
}
break;
case SWT.ARROW_UP:
- int levelsOut = 0;
+
+ // On up and down, it is cool to go up and down only
+ // the leaf nodes.
+ // It goes well with the layout viewer
DrawableViewNode currentNode = selectedNode;
while (currentNode.parent != null && currentNode.viewNode.index == 0) {
- levelsOut++;
currentNode = currentNode.parent;
}
if (currentNode.parent != null) {
@@ -211,7 +243,6 @@ public class TreeView extends Canvas implements TreeChangeListener {
currentNode =
currentNode.children
.get(currentNode.children.size() - 1);
- levelsOut--;
}
}
if (selectionChanged) {
@@ -219,12 +250,10 @@ public class TreeView extends Canvas implements TreeChangeListener {
}
break;
case SWT.ARROW_DOWN:
- levelsOut = 0;
currentNode = selectedNode;
while (currentNode.parent != null
&& currentNode.viewNode.index + 1 == currentNode.parent.children
.size()) {
- levelsOut++;
currentNode = currentNode.parent;
}
if (currentNode.parent != null) {
@@ -234,7 +263,6 @@ public class TreeView extends Canvas implements TreeChangeListener {
.get(currentNode.viewNode.index + 1);
while (currentNode.children.size() != 0) {
currentNode = currentNode.children.get(0);
- levelsOut--;
}
}
if (selectionChanged) {
@@ -245,6 +273,9 @@ public class TreeView extends Canvas implements TreeChangeListener {
DrawableViewNode rightNode = null;
double mostOverlap = 0;
final int N = selectedNode.children.size();
+
+ // We consider all the children and pick the one
+ // who's tree overlaps the most.
for (int i = 0; i < N; i++) {
DrawableViewNode child = selectedNode.children.get(i);
DrawableViewNode topMostChild = child;
@@ -305,12 +336,16 @@ public class TreeView extends Canvas implements TreeChangeListener {
synchronized (TreeView.this) {
if (tree != null && viewport != null) {
Point pt = transformPoint(e.x, e.y);
+
+ // Ignore profiling rectangle, except for...
if (selectedRectangleLocation != null
&& pt.x >= selectedRectangleLocation.x
&& pt.x < selectedRectangleLocation.x + selectedRectangleLocation.width
&& pt.y >= selectedRectangleLocation.y
&& pt.y < selectedRectangleLocation.y
+ selectedRectangleLocation.height) {
+
+ // the small button!
if ((pt.x - buttonCenter.x) * (pt.x - buttonCenter.x)
+ (pt.y - buttonCenter.y) * (pt.y - buttonCenter.y) <= (BUTTON_SIZE * BUTTON_SIZE) / 4) {
buttonClicked = true;
@@ -319,6 +354,8 @@ public class TreeView extends Canvas implements TreeChangeListener {
return;
}
draggedNode = tree.getSelected(pt.x, pt.y);
+
+ // Update the selection.
if (draggedNode != null && draggedNode != selectedNode) {
selectedNode = draggedNode;
selectionChanged = true;
@@ -326,9 +363,12 @@ public class TreeView extends Canvas implements TreeChangeListener {
} else if (draggedNode != null) {
alreadySelectedOnMouseDown = true;
}
+
+ // Can't drag the root.
if (draggedNode == tree) {
draggedNode = null;
}
+
if (draggedNode != null) {
lastPoint = pt;
} else {
@@ -351,11 +391,18 @@ public class TreeView extends Canvas implements TreeChangeListener {
synchronized (TreeView.this) {
if (tree != null && viewport != null && lastPoint != null) {
if (draggedNode == null) {
+ // The viewport moves.
handleMouseDrag(new Point(e.x, e.y));
viewportChanged = true;
} else {
+ // The nodes move.
handleMouseDrag(transformPoint(e.x, e.y));
}
+
+ // Deselect on the second click...
+ // This is in the mouse up, because mouse up happens after a
+ // double click event.
+ // During a double click, we don't want to deselect.
Point pt = transformPoint(e.x, e.y);
DrawableViewNode mouseUpOn = tree.getSelected(pt.x, pt.y);
if (mouseUpOn != null && mouseUpOn == selectedNode
@@ -367,6 +414,8 @@ public class TreeView extends Canvas implements TreeChangeListener {
draggedNode = null;
redraw = true;
}
+
+ // Just clicked the button here.
if (buttonClicked) {
HierarchyViewerDirector.getDirector().showCapture(getShell(),
selectedNode.viewNode);
@@ -374,6 +423,8 @@ public class TreeView extends Canvas implements TreeChangeListener {
redrawButton = true;
}
}
+
+ // Complicated.
if (viewportChanged) {
model.setViewport(viewport);
} else if (redraw) {
@@ -418,6 +469,8 @@ public class TreeView extends Canvas implements TreeChangeListener {
};
private void handleMouseDrag(Point pt) {
+
+ // Case 1: a node is dragged. DrawableViewNode knows how to handle this.
if (draggedNode != null) {
if (lastPoint.y - pt.y != 0) {
nodeMoved = true;
@@ -426,42 +479,42 @@ public class TreeView extends Canvas implements TreeChangeListener {
lastPoint = pt;
return;
}
+
+ // Case 2: the viewport is dragged. We have to make sure we respect the
+ // bounds - don't let the user drag way out... + some leeway for the
+ // profiling box.
double xDif = (lastPoint.x - pt.x) / zoom;
double yDif = (lastPoint.y - pt.y) / zoom;
- if (viewport.width > tree.bounds.width) {
- if (xDif < 0 && viewport.x + viewport.width > tree.bounds.x + tree.bounds.width) {
- viewport.x =
- Math.max(viewport.x + xDif, tree.bounds.x + tree.bounds.width
- - viewport.width);
- } else if (xDif > 0 && viewport.x < tree.bounds.x) {
- viewport.x = Math.min(viewport.x + xDif, tree.bounds.x);
+ double treeX = tree.bounds.x - DRAG_LEEWAY;
+ double treeY = tree.bounds.y - DRAG_LEEWAY;
+ double treeWidth = tree.bounds.width + 2 * DRAG_LEEWAY;
+ double treeHeight = tree.bounds.height + 2 * DRAG_LEEWAY;
+
+ if (viewport.width > treeWidth) {
+ if (xDif < 0 && viewport.x + viewport.width > treeX + treeWidth) {
+ viewport.x = Math.max(viewport.x + xDif, treeX + treeWidth - viewport.width);
+ } else if (xDif > 0 && viewport.x < treeX) {
+ viewport.x = Math.min(viewport.x + xDif, treeX);
}
} else {
- if (xDif < 0 && viewport.x > tree.bounds.x) {
- viewport.x = Math.max(viewport.x + xDif, tree.bounds.x);
- } else if (xDif > 0 && viewport.x + viewport.width < tree.bounds.x + tree.bounds.width) {
- viewport.x =
- Math.min(viewport.x + xDif, tree.bounds.x + tree.bounds.width
- - viewport.width);
+ if (xDif < 0 && viewport.x > treeX) {
+ viewport.x = Math.max(viewport.x + xDif, treeX);
+ } else if (xDif > 0 && viewport.x + viewport.width < treeX + treeWidth) {
+ viewport.x = Math.min(viewport.x + xDif, treeX + treeWidth - viewport.width);
}
}
- if (viewport.height > tree.bounds.height) {
- if (yDif < 0 && viewport.y + viewport.height > tree.bounds.y + tree.bounds.height) {
- viewport.y =
- Math.max(viewport.y + yDif, tree.bounds.y + tree.bounds.height
- - viewport.height);
- } else if (yDif > 0 && viewport.y < tree.bounds.y) {
- viewport.y = Math.min(viewport.y + yDif, tree.bounds.y);
+ if (viewport.height > treeHeight) {
+ if (yDif < 0 && viewport.y + viewport.height > treeY + treeHeight) {
+ viewport.y = Math.max(viewport.y + yDif, treeY + treeHeight - viewport.height);
+ } else if (yDif > 0 && viewport.y < treeY) {
+ viewport.y = Math.min(viewport.y + yDif, treeY);
}
} else {
- if (yDif < 0 && viewport.y > tree.bounds.y) {
- viewport.y = Math.max(viewport.y + yDif, tree.bounds.y);
- } else if (yDif > 0
- && viewport.y + viewport.height < tree.bounds.y + tree.bounds.height) {
- viewport.y =
- Math.min(viewport.y + yDif, tree.bounds.y + tree.bounds.height
- - viewport.height);
+ if (yDif < 0 && viewport.y > treeY) {
+ viewport.y = Math.max(viewport.y + yDif, treeY);
+ } else if (yDif > 0 && viewport.y + viewport.height < treeY + treeHeight) {
+ viewport.y = Math.min(viewport.y + yDif, treeY + treeHeight - viewport.height);
}
}
lastPoint = pt;
@@ -496,6 +549,8 @@ public class TreeView extends Canvas implements TreeChangeListener {
e.gc.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
e.gc.fillRectangle(0, 0, getBounds().width, getBounds().height);
if (tree != null && viewport != null) {
+
+ // Easy stuff!
e.gc.setTransform(transform);
e.gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
Path connectionPath = new Path(Display.getDefault());
@@ -503,24 +558,25 @@ public class TreeView extends Canvas implements TreeChangeListener {
e.gc.drawPath(connectionPath);
connectionPath.dispose();
+ // Draw the profiling box.
if (selectedNode != null) {
- int RECT_WIDTH = 155;
- int RECT_HEIGHT = 224;
+ // Draw the little triangle
int x = selectedNode.left + DrawableViewNode.NODE_WIDTH / 2;
int y = (int) selectedNode.top + 4;
e.gc.setBackground(boxColor);
e.gc.fillPolygon(new int[] {
x, y, x - 15, y - 15, x + 15, y - 15
});
+
+ // Draw the rectangle and update the location.
y -= 10 + RECT_HEIGHT;
- e.gc.fillRoundRectangle(x - RECT_WIDTH / 2, y, RECT_WIDTH, RECT_HEIGHT, 15,
- 15);
+ e.gc.fillRoundRectangle(x - RECT_WIDTH / 2, y, RECT_WIDTH, RECT_HEIGHT, 30,
+ 30);
selectedRectangleLocation =
new Rectangle(x - RECT_WIDTH / 2, y, RECT_WIDTH, RECT_HEIGHT);
- int BUTTON_RIGHT_OFFSET = 1;
- int BUTTON_TOP_OFFSET = 2;
+ // Draw the button
buttonCenter =
new Point(x - BUTTON_RIGHT_OFFSET + (RECT_WIDTH - BUTTON_SIZE) / 2,
y + BUTTON_TOP_OFFSET + BUTTON_SIZE / 2);
@@ -538,23 +594,23 @@ public class TreeView extends Canvas implements TreeChangeListener {
e.gc.fillOval(x + RECT_WIDTH / 2 - BUTTON_RIGHT_OFFSET - BUTTON_SIZE, y
+ BUTTON_TOP_OFFSET, BUTTON_SIZE, BUTTON_SIZE);
- int RECTANGLE_SIZE = 5;
-
e.gc.drawRectangle(x - BUTTON_RIGHT_OFFSET
+ (RECT_WIDTH - BUTTON_SIZE - RECTANGLE_SIZE) / 2 - 1, y
+ BUTTON_TOP_OFFSET + (BUTTON_SIZE - RECTANGLE_SIZE) / 2,
RECTANGLE_SIZE + 1, RECTANGLE_SIZE);
y += 15;
- int IMAGE_WIDTH = 125;
- int IMAGE_HEIGHT = 120;
-
- int IMAGE_OFFSET = 6;
- int IMAGE_ROUNDING = 8;
+ // If there is an image, draw it.
if (selectedNode.viewNode.image != null
- && selectedNode.viewNode.image.getBounds().height != 0
- && selectedNode.viewNode.image.getBounds().width != 0) {
+ && selectedNode.viewNode.image.getBounds().height != 1
+ && selectedNode.viewNode.image.getBounds().width != 1) {
+
+ // Scaling the image to the right size takes lots of
+ // time, so we want to do it only once.
+
+ // If the selection changed, get rid of the old
+ // image.
if (lastDrawnSelectedViewNode != selectedNode) {
if (scaledSelectedImage != null) {
scaledSelectedImage.dispose();
@@ -562,6 +618,7 @@ public class TreeView extends Canvas implements TreeChangeListener {
}
lastDrawnSelectedViewNode = selectedNode;
}
+
if (scaledSelectedImage == null) {
double ratio =
1.0 * selectedNode.viewNode.image.getBounds().width
@@ -578,8 +635,12 @@ public class TreeView extends Canvas implements TreeChangeListener {
.getBounds().height);
newWidth = (int) (newHeight * ratio);
}
- newWidth = Math.max(newWidth, 1);
- newHeight = Math.max(newHeight, 1);
+
+ // Interesting note... We make the image twice
+ // the needed size so that there is better
+ // resolution under zoom.
+ newWidth = Math.max(newWidth * 2, 1);
+ newHeight = Math.max(newHeight * 2, 1);
scaledSelectedImage =
new Image(Display.getDefault(), newWidth, newHeight);
GC gc = new GC(scaledSelectedImage);
@@ -591,18 +652,42 @@ public class TreeView extends Canvas implements TreeChangeListener {
newWidth, newHeight);
gc.dispose();
}
+
+ // Draw the background rectangle
e.gc.setBackground(textBackgroundColor);
- e.gc.fillRoundRectangle(x - scaledSelectedImage.getBounds().width / 2
+ e.gc.fillRoundRectangle(x - scaledSelectedImage.getBounds().width / 4
- IMAGE_OFFSET, y
- + (IMAGE_HEIGHT - scaledSelectedImage.getBounds().height) / 2
- - IMAGE_OFFSET, scaledSelectedImage.getBounds().width + 2
- * IMAGE_OFFSET, scaledSelectedImage.getBounds().height + 2
- * IMAGE_OFFSET, IMAGE_ROUNDING, IMAGE_ROUNDING);
- e.gc.drawImage(scaledSelectedImage, x
- - scaledSelectedImage.getBounds().width / 2, y
- + (IMAGE_HEIGHT - scaledSelectedImage.getBounds().height) / 2);
+ + (IMAGE_HEIGHT - scaledSelectedImage.getBounds().height / 2)
+ / 2 - IMAGE_OFFSET, scaledSelectedImage.getBounds().width / 2
+ + 2 * IMAGE_OFFSET, scaledSelectedImage.getBounds().height / 2
+ + 2 * IMAGE_OFFSET, IMAGE_ROUNDING, IMAGE_ROUNDING);
+
+ // Under max zoom, we want the image to be
+ // untransformed. So, get back to the identity
+ // transform.
+ int imageX = x - scaledSelectedImage.getBounds().width / 4;
+ int imageY =
+ y + (IMAGE_HEIGHT - scaledSelectedImage.getBounds().height / 2)
+ / 2;
+
+ Transform untransformedTransform = new Transform(Display.getDefault());
+ e.gc.setTransform(untransformedTransform);
+ float[] pt = new float[] {
+ imageX, imageY
+ };
+ transform.transform(pt);
+ e.gc.drawImage(scaledSelectedImage, 0, 0, scaledSelectedImage
+ .getBounds().width, scaledSelectedImage.getBounds().height,
+ (int) pt[0], (int) pt[1], (int) (scaledSelectedImage
+ .getBounds().width
+ * zoom / 2),
+ (int) (scaledSelectedImage.getBounds().height * zoom / 2));
+ untransformedTransform.dispose();
+ e.gc.setTransform(transform);
}
+ // Text stuff
+
y += IMAGE_HEIGHT;
y += 10;
Font font = getFont(8, false);
@@ -629,11 +714,6 @@ public class TreeView extends Canvas implements TreeChangeListener {
.format(selectedNode.viewNode.drawTime)
+ " ms" : "n/a");
- int TEXT_SIDE_OFFSET = 8;
- int TEXT_TOP_OFFSET = 4;
- int TEXT_SPACING = 2;
- int TEXT_ROUNDING = 20;
-
org.eclipse.swt.graphics.Point titleExtent = e.gc.stringExtent(text);
org.eclipse.swt.graphics.Point measureExtent =
e.gc.stringExtent(measureText);
@@ -678,67 +758,6 @@ public class TreeView extends Canvas implements TreeChangeListener {
selectedRectangleLocation = null;
buttonCenter = null;
}
-
- /*
- * Transform tempTransform = new
- * Transform(Display.getDefault());
- * e.gc.setTransform(tempTransform);
- * e.gc.setBackground(Display
- * .getDefault().getSystemColor(SWT.COLOR_GRAY));
- * e.gc.setForeground
- * (Display.getDefault().getSystemColor(SWT.COLOR_RED)); //
- * Draw the number of views. String viewsString =
- * Integer.toString(tree.viewNode.viewCount) + " view"; if
- * (tree.viewNode.viewCount != 1) { viewsString += 's'; }
- * org.eclipse.swt.graphics.Point stringExtent =
- * e.gc.stringExtent(viewsString); e.gc.fillRectangle(0,
- * getBounds().height - stringExtent.y - 4, stringExtent.x +
- * 4, stringExtent.y + 4); e.gc.drawText(viewsString, 2,
- * getBounds().height - stringExtent.y - 2);
- * DrawableViewNode profiledNode =
- * (tree.viewNode.protocolVersion < 3) ? tree :
- * selectedNode; // Draw the profiling stuff if
- * (profiledNode != null &&
- * profiledNode.viewNode.measureTime != -1) { DecimalFormat
- * formatter = new DecimalFormat("0.000"); String
- * measureString = "Measure:"; String measureTimeString =
- * formatter.format(profiledNode.viewNode.measureTime) +
- * " ms"; String layoutString = "Layout:"; String
- * layoutTimeString =
- * formatter.format(profiledNode.viewNode.layoutTime) +
- * " ms"; String drawString = "Draw:"; String drawTimeString
- * = formatter.format(profiledNode.viewNode.drawTime) +
- * " ms"; org.eclipse.swt.graphics.Point measureExtent =
- * e.gc.stringExtent(measureString);
- * org.eclipse.swt.graphics.Point measureTimeExtent =
- * e.gc.stringExtent(measureTimeString);
- * org.eclipse.swt.graphics.Point layoutExtent =
- * e.gc.stringExtent(layoutString);
- * org.eclipse.swt.graphics.Point layoutTimeExtent =
- * e.gc.stringExtent(layoutTimeString);
- * org.eclipse.swt.graphics.Point drawExtent =
- * e.gc.stringExtent(drawString);
- * org.eclipse.swt.graphics.Point drawTimeExtent =
- * e.gc.stringExtent(drawTimeString); int letterHeight =
- * e.gc.getFontMetrics().getHeight(); int width =
- * Math.max(measureExtent.x, Math.max(layoutExtent.x,
- * drawExtent.x)) + Math.max(measureTimeExtent.x, Math.max(
- * layoutTimeExtent.x, drawTimeExtent.x)) + 8; int height =
- * 3 * letterHeight + 8; int x = getBounds().width - width;
- * int y = getBounds().height - height;
- * e.gc.fillRectangle(x, y, width, height); x += 2; y += 2;
- * e.gc.drawText(measureString, x, y); y += letterHeight +
- * 2; e.gc.drawText(layoutString, x, y); y += letterHeight +
- * 2; e.gc.drawText(drawString, x, y); x = getBounds().width
- * - measureTimeExtent.x - 2; y = getBounds().height -
- * height + 2; e.gc.drawText(measureTimeString, x, y); x =
- * getBounds().width - layoutTimeExtent.x - 2; y +=
- * letterHeight + 2; e.gc.drawText(layoutTimeString, x, y);
- * x = getBounds().width - drawTimeExtent.x - 2; y +=
- * letterHeight + 2; e.gc.drawText(drawTimeString, x, y); }
- * tempTransform.dispose();
- */
-
}
}
}
@@ -904,6 +923,8 @@ public class TreeView extends Canvas implements TreeChangeListener {
transform.translate((float) -tree.bounds.x, (float) -tree.bounds.y);
Path connectionPath = new Path(Display.getDefault());
GC gc = new GC(image);
+
+ // Can't use Display.getDefault().getSystemColor in a non-UI thread.
Color white = new Color(Display.getDefault(), 255, 255, 255);
Color black = new Color(Display.getDefault(), 0, 0, 0);
gc.setForeground(white);
@@ -939,6 +960,8 @@ public class TreeView extends Canvas implements TreeChangeListener {
});
}
+ // Fickle behaviour... When a new tree is loaded, the model doesn't know
+ // about the viewport until it passes through here.
public void treeChanged() {
Display.getDefault().syncExec(new Runnable() {
public void run() {
@@ -975,6 +998,7 @@ public class TreeView extends Canvas implements TreeChangeListener {
}
}
+ // Note the syncExec and then synchronized... It avoids deadlock
public void viewportChanged() {
Display.getDefault().syncExec(new Runnable() {
public void run() {
diff --git a/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/TreeViewOverview.java b/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/TreeViewOverview.java
index 9a44694..ee84ccb 100644
--- a/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/TreeViewOverview.java
+++ b/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/ui/TreeViewOverview.java
@@ -134,6 +134,10 @@ public class TreeViewOverview extends Canvas implements TreeChangeListener {
dragging = false;
redraw = true;
handleMouseEvent(transformPoint(e.x, e.y));
+
+ // Update bounds and transform only on mouse up. That way,
+ // you don't get confusing behaviour during mouse drag and
+ // it snaps neatly at the end
setBounds();
setTransform();
}
@@ -270,6 +274,7 @@ public class TreeViewOverview extends Canvas implements TreeChangeListener {
});
}
+ // Note the syncExec and then synchronized... It avoids deadlock
public void treeChanged() {
Display.getDefault().syncExec(new Runnable() {
public void run() {
diff --git a/hierarchyviewer2/libs/hierarchyviewerlib/src/resources/images/about-small.jpg b/hierarchyviewer2/libs/hierarchyviewerlib/src/resources/images/about-small.jpg
index 72ecabc..6fe9291 100644
--- a/hierarchyviewer2/libs/hierarchyviewerlib/src/resources/images/about-small.jpg
+++ b/hierarchyviewer2/libs/hierarchyviewerlib/src/resources/images/about-small.jpg
Binary files differ
diff --git a/hierarchyviewer2/libs/hierarchyviewerlib/src/resources/images/about.jpg b/hierarchyviewer2/libs/hierarchyviewerlib/src/resources/images/about.jpg
index 2183168..8e10514 100644
--- a/hierarchyviewer2/libs/hierarchyviewerlib/src/resources/images/about.jpg
+++ b/hierarchyviewer2/libs/hierarchyviewerlib/src/resources/images/about.jpg
Binary files differ