auto import from //depot/cupcake/@132589
This commit is contained in:
@@ -32,7 +32,6 @@ import java.net.Socket;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Stack;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ViewHierarchyLoader {
|
||||
@SuppressWarnings("empty-statement")
|
||||
@@ -110,9 +109,7 @@ public class ViewHierarchyLoader {
|
||||
parent.children.add(lastNode);
|
||||
}
|
||||
}
|
||||
|
||||
updateIndices(scene.getRoot());
|
||||
|
||||
|
||||
} catch (IOException ex) {
|
||||
Exceptions.printStackTrace(ex);
|
||||
} finally {
|
||||
@@ -130,18 +127,10 @@ public class ViewHierarchyLoader {
|
||||
}
|
||||
|
||||
System.out.println("==> DONE");
|
||||
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
private static void updateIndices(ViewNode root) {
|
||||
root.computeIndex();
|
||||
|
||||
for (ViewNode node : root.children) {
|
||||
updateIndices(node);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static int countFrontWhitespace(String line) {
|
||||
int count = 0;
|
||||
while (line.charAt(count) == ' ') {
|
||||
|
||||
@@ -60,25 +60,22 @@ public class ViewHierarchyScene extends GraphScene<ViewNode, String> {
|
||||
|
||||
@Override
|
||||
protected Widget attachNodeWidget(ViewNode node) {
|
||||
Widget widget = createBox(node, node.name, node.id);
|
||||
Widget widget = createBox(node.name, node.id);
|
||||
widget.getActions().addAction(createSelectAction());
|
||||
widget.getActions().addAction(moveAction);
|
||||
widgetLayer.addChild(widget);
|
||||
return widget;
|
||||
}
|
||||
|
||||
private Widget createBox(ViewNode node, String nodeName, String id) {
|
||||
final String shortName = getShortName(nodeName);
|
||||
node.setShortName(shortName);
|
||||
|
||||
GradientWidget box = new GradientWidget(this, node);
|
||||
private Widget createBox(String node, String id) {
|
||||
Widget box = new GradientWidget(this);
|
||||
box.setLayout(LayoutFactory.createVerticalFlowLayout());
|
||||
box.setBorder(BorderFactory.createLineBorder(2, Color.BLACK));
|
||||
box.setOpaque(true);
|
||||
|
||||
LabelWidget label = new LabelWidget(this);
|
||||
label.setFont(getDefaultFont().deriveFont(Font.PLAIN, 12.0f));
|
||||
label.setLabel(shortName);
|
||||
label.setLabel(getShortName(node));
|
||||
label.setBorder(BorderFactory.createEmptyBorder(6, 6, 0, 6));
|
||||
label.setAlignment(LabelWidget.Alignment.CENTER);
|
||||
|
||||
@@ -86,11 +83,9 @@ public class ViewHierarchyScene extends GraphScene<ViewNode, String> {
|
||||
|
||||
label = new LabelWidget(this);
|
||||
label.setFont(getDefaultFont().deriveFont(Font.PLAIN, 10.0f));
|
||||
label.setLabel(getAddress(nodeName));
|
||||
label.setLabel(getAddress(node));
|
||||
label.setBorder(BorderFactory.createEmptyBorder(3, 6, 0, 6));
|
||||
label.setAlignment(LabelWidget.Alignment.CENTER);
|
||||
|
||||
box.addressWidget = label;
|
||||
|
||||
box.addChild(label);
|
||||
|
||||
@@ -141,7 +136,7 @@ public class ViewHierarchyScene extends GraphScene<ViewNode, String> {
|
||||
connection.setTargetAnchor(AnchorFactory.createRectangularAnchor(target));
|
||||
}
|
||||
|
||||
private static class GradientWidget extends Widget implements ViewNode.StateListener {
|
||||
private static class GradientWidget extends Widget {
|
||||
public static final GradientPaint BLUE_EXPERIENCE = new GradientPaint(
|
||||
new Point2D.Double(0, 0),
|
||||
new Color(168, 204, 241),
|
||||
@@ -182,28 +177,15 @@ public class ViewHierarchyScene extends GraphScene<ViewNode, String> {
|
||||
new Color(129, 138, 155),
|
||||
new Point2D.Double(0, 1),
|
||||
new Color(58, 66, 82));
|
||||
public static final GradientPaint NIGHT_GRAY_VERY_LIGHT = new GradientPaint(
|
||||
new Point2D.Double(0, 0),
|
||||
new Color(129, 138, 155, 60),
|
||||
new Point2D.Double(0, 1),
|
||||
new Color(58, 66, 82, 60));
|
||||
|
||||
private static Color UNSELECTED = Color.BLACK;
|
||||
private static Color SELECTED = Color.WHITE;
|
||||
|
||||
private final ViewNode node;
|
||||
|
||||
private LabelWidget addressWidget;
|
||||
|
||||
private boolean isSelected = false;
|
||||
private final GradientPaint selectedGradient = MAC_OSX_SELECTED;
|
||||
private final GradientPaint filteredGradient = RED_XP;
|
||||
private final GradientPaint focusGradient = NIGHT_GRAY_VERY_LIGHT;
|
||||
private GradientPaint gradient = MAC_OSX_SELECTED;
|
||||
|
||||
public GradientWidget(ViewHierarchyScene scene, ViewNode node) {
|
||||
public GradientWidget(ViewHierarchyScene scene) {
|
||||
super(scene);
|
||||
this.node = node;
|
||||
node.setStateListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -211,12 +193,8 @@ public class ViewHierarchyScene extends GraphScene<ViewNode, String> {
|
||||
super.notifyStateChanged(previous, state);
|
||||
isSelected = state.isSelected() || state.isFocused() || state.isWidgetFocused();
|
||||
|
||||
pickChildrenColor();
|
||||
}
|
||||
|
||||
private void pickChildrenColor() {
|
||||
for (Widget child : getChildren()) {
|
||||
child.setForeground(isSelected || node.filtered ? SELECTED : UNSELECTED);
|
||||
child.setForeground(isSelected ? SELECTED : UNSELECTED);
|
||||
}
|
||||
|
||||
repaint();
|
||||
@@ -228,35 +206,14 @@ public class ViewHierarchyScene extends GraphScene<ViewNode, String> {
|
||||
|
||||
Graphics2D g2 = getGraphics();
|
||||
Rectangle bounds = getBounds();
|
||||
|
||||
|
||||
if (!isSelected) {
|
||||
if (!node.filtered) {
|
||||
if (!node.hasFocus) {
|
||||
g2.setColor(Color.WHITE);
|
||||
} else {
|
||||
g2.setPaint(new GradientPaint(bounds.x, bounds.y,
|
||||
focusGradient.getColor1(), bounds.x, bounds.x + bounds.height,
|
||||
focusGradient.getColor2()));
|
||||
}
|
||||
} else {
|
||||
g2.setPaint(new GradientPaint(bounds.x, bounds.y, filteredGradient.getColor1(),
|
||||
bounds.x, bounds.x + bounds.height, filteredGradient.getColor2()));
|
||||
}
|
||||
g2.setColor(Color.WHITE);
|
||||
} else {
|
||||
g2.setPaint(new GradientPaint(bounds.x, bounds.y, selectedGradient.getColor1(),
|
||||
bounds.x, bounds.x + bounds.height, selectedGradient.getColor2()));
|
||||
g2.setPaint(new GradientPaint(bounds.x, bounds.y, gradient.getColor1(),
|
||||
bounds.x, bounds.x + bounds.height, gradient.getColor2()));
|
||||
}
|
||||
g2.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);
|
||||
}
|
||||
|
||||
public void nodeStateChanged(ViewNode node) {
|
||||
pickChildrenColor();
|
||||
}
|
||||
|
||||
public void nodeIndexChanged(ViewNode node) {
|
||||
if (addressWidget != null) {
|
||||
addressWidget.setLabel("#" + node.index + addressWidget.getLabel());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.android.hierarchyviewer.scene;
|
||||
|
||||
import com.android.ddmlib.Device;
|
||||
import com.android.hierarchyviewer.device.Configuration;
|
||||
import com.android.hierarchyviewer.device.Window;
|
||||
import com.android.hierarchyviewer.device.DeviceBridge;
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ViewNode {
|
||||
public String id;
|
||||
@@ -53,15 +52,8 @@ public class ViewNode {
|
||||
public boolean willNotDraw;
|
||||
public boolean hasMargins;
|
||||
|
||||
boolean hasFocus;
|
||||
int index;
|
||||
|
||||
public boolean decoded;
|
||||
public boolean filtered;
|
||||
|
||||
private String shortName;
|
||||
private StateListener listener;
|
||||
|
||||
|
||||
void decode() {
|
||||
id = namedProperties.get("mID").value;
|
||||
|
||||
@@ -81,7 +73,6 @@ public class ViewNode {
|
||||
marginBottom = getInt("layout_bottomMargin", Integer.MIN_VALUE);
|
||||
baseline = getInt("getBaseline()", 0);
|
||||
willNotDraw = getBoolean("willNotDraw()", false);
|
||||
hasFocus = getBoolean("hasFocus()", false);
|
||||
|
||||
hasMargins = marginLeft != Integer.MIN_VALUE &&
|
||||
marginRight != Integer.MIN_VALUE &&
|
||||
@@ -110,33 +101,11 @@ public class ViewNode {
|
||||
return Integer.parseInt(p.value);
|
||||
} catch (NumberFormatException e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public void filter(Pattern pattern) {
|
||||
if (pattern == null || pattern.pattern().length() == 0) {
|
||||
filtered = false;
|
||||
} else {
|
||||
filtered = pattern.matcher(shortName).find() || pattern.matcher(id).find();
|
||||
}
|
||||
listener.nodeStateChanged(this);
|
||||
}
|
||||
|
||||
void computeIndex() {
|
||||
index = parent == null ? 0 : parent.children.indexOf(this);
|
||||
listener.nodeIndexChanged(this);
|
||||
}
|
||||
|
||||
void setShortName(String shortName) {
|
||||
this.shortName = shortName;
|
||||
}
|
||||
|
||||
void setStateListener(StateListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"StringEquality"})
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
@@ -195,9 +164,4 @@ public class ViewNode {
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
||||
interface StateListener {
|
||||
void nodeStateChanged(ViewNode node);
|
||||
void nodeIndexChanged(ViewNode node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,9 +76,6 @@ import javax.swing.ListSelectionModel;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.JTree;
|
||||
import javax.swing.Box;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.text.Document;
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.tree.TreePath;
|
||||
import javax.swing.tree.DefaultTreeCellRenderer;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
@@ -87,8 +84,6 @@ import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
import javax.swing.event.TreeSelectionListener;
|
||||
import javax.swing.event.TreeSelectionEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.BorderLayout;
|
||||
@@ -110,8 +105,6 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class Workspace extends JFrame {
|
||||
@@ -163,8 +156,6 @@ public class Workspace extends JFrame {
|
||||
private JTable windows;
|
||||
private JLabel minZoomLabel;
|
||||
private JLabel maxZoomLabel;
|
||||
private JTextField filterText;
|
||||
private JLabel filterLabel;
|
||||
|
||||
public Workspace() {
|
||||
super("Hierarchy Viewer");
|
||||
@@ -322,33 +313,10 @@ public class Workspace extends JFrame {
|
||||
|
||||
graphViewButton.setSelected(true);
|
||||
|
||||
filterText = new JTextField(20);
|
||||
filterText.putClientProperty("JComponent.sizeVariant", "small");
|
||||
filterText.getDocument().addDocumentListener(new DocumentListener() {
|
||||
public void insertUpdate(DocumentEvent e) {
|
||||
updateFilter(e);
|
||||
}
|
||||
|
||||
public void removeUpdate(DocumentEvent e) {
|
||||
updateFilter(e);
|
||||
}
|
||||
|
||||
public void changedUpdate(DocumentEvent e) {
|
||||
updateFilter(e);
|
||||
}
|
||||
});
|
||||
|
||||
filterLabel = new JLabel("Filter by class or id:");
|
||||
filterLabel.putClientProperty("JComponent.sizeVariant", "small");
|
||||
filterLabel.setBorder(BorderFactory.createEmptyBorder(0, 6, 0, 6));
|
||||
|
||||
leftSide.add(filterLabel);
|
||||
leftSide.add(filterText);
|
||||
|
||||
minZoomLabel = new JLabel();
|
||||
minZoomLabel.setText("20%");
|
||||
minZoomLabel.putClientProperty("JComponent.sizeVariant", "small");
|
||||
minZoomLabel.setBorder(BorderFactory.createEmptyBorder(0, 12, 0, 0));
|
||||
minZoomLabel.setBorder(BorderFactory.createEmptyBorder(0, 6, 0, 0));
|
||||
leftSide.add(minZoomLabel);
|
||||
|
||||
zoomSlider = new JSlider();
|
||||
@@ -389,18 +357,12 @@ public class Workspace extends JFrame {
|
||||
|
||||
statusPanel.add(rightSide, BorderLayout.LINE_END);
|
||||
|
||||
hideStatusBarComponents();
|
||||
|
||||
return statusPanel;
|
||||
}
|
||||
|
||||
private void hideStatusBarComponents() {
|
||||
viewCountLabel.setVisible(false);
|
||||
zoomSlider.setVisible(false);
|
||||
minZoomLabel.setVisible(false);
|
||||
maxZoomLabel.setVisible(false);
|
||||
filterLabel.setVisible(false);
|
||||
filterText.setVisible(false);
|
||||
maxZoomLabel.setVisible(false);
|
||||
|
||||
return statusPanel;
|
||||
}
|
||||
|
||||
private JToolBar buildToolBar() {
|
||||
@@ -551,7 +513,10 @@ public class Workspace extends JFrame {
|
||||
}
|
||||
|
||||
private void toggleGraphView() {
|
||||
showStatusBarComponents();
|
||||
viewCountLabel.setVisible(true);
|
||||
zoomSlider.setVisible(true);
|
||||
minZoomLabel.setVisible(true);
|
||||
maxZoomLabel.setVisible(true);
|
||||
|
||||
screenViewer.stop();
|
||||
mainPanel.remove(pixelPerfectPanel);
|
||||
@@ -561,15 +526,6 @@ public class Workspace extends JFrame {
|
||||
repaint();
|
||||
}
|
||||
|
||||
private void showStatusBarComponents() {
|
||||
viewCountLabel.setVisible(true);
|
||||
zoomSlider.setVisible(true);
|
||||
minZoomLabel.setVisible(true);
|
||||
maxZoomLabel.setVisible(true);
|
||||
filterLabel.setVisible(true);
|
||||
filterText.setVisible(true);
|
||||
}
|
||||
|
||||
private void togglePixelPerfectView() {
|
||||
if (pixelPerfectPanel == null) {
|
||||
pixelPerfectPanel = buildPixelPerfectPanel();
|
||||
@@ -578,7 +534,10 @@ public class Workspace extends JFrame {
|
||||
screenViewer.start();
|
||||
}
|
||||
|
||||
hideStatusBarComponents();
|
||||
viewCountLabel.setVisible(false);
|
||||
zoomSlider.setVisible(false);
|
||||
minZoomLabel.setVisible(false);
|
||||
maxZoomLabel.setVisible(false);
|
||||
|
||||
mainPanel.remove(mainSplitter);
|
||||
mainPanel.add(pixelPerfectPanel, BorderLayout.CENTER);
|
||||
@@ -643,7 +602,10 @@ public class Workspace extends JFrame {
|
||||
graphViewButton.setEnabled(true);
|
||||
pixelPerfectViewButton.setEnabled(true);
|
||||
|
||||
showStatusBarComponents();
|
||||
viewCountLabel.setVisible(true);
|
||||
zoomSlider.setVisible(true);
|
||||
minZoomLabel.setVisible(true);
|
||||
maxZoomLabel.setVisible(true);
|
||||
}
|
||||
|
||||
sceneView = scene.createView();
|
||||
@@ -814,7 +776,10 @@ public class Workspace extends JFrame {
|
||||
pixelPerfectPanel = mainSplitter = null;
|
||||
graphViewButton.setSelected(true);
|
||||
|
||||
hideStatusBarComponents();
|
||||
viewCountLabel.setVisible(false);
|
||||
zoomSlider.setVisible(false);
|
||||
minZoomLabel.setVisible(false);
|
||||
maxZoomLabel.setVisible(false);
|
||||
|
||||
saveMenuItem.setEnabled(false);
|
||||
showDevicesMenuItem.setEnabled(false);
|
||||
@@ -900,34 +865,6 @@ public class Workspace extends JFrame {
|
||||
});
|
||||
}
|
||||
|
||||
private void updateFilter(DocumentEvent e) {
|
||||
final Document document = e.getDocument();
|
||||
try {
|
||||
updateFilteredNodes(document.getText(0, document.getLength()));
|
||||
} catch (BadLocationException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateFilteredNodes(String filterText) {
|
||||
final ViewNode root = scene.getRoot();
|
||||
try {
|
||||
final Pattern pattern = Pattern.compile(filterText, Pattern.CASE_INSENSITIVE);
|
||||
filterNodes(pattern, root);
|
||||
} catch (PatternSyntaxException e) {
|
||||
filterNodes(null, root);
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
|
||||
private void filterNodes(Pattern pattern, ViewNode root) {
|
||||
root.filter(pattern);
|
||||
|
||||
for (ViewNode node : root.children) {
|
||||
filterNodes(pattern, node);
|
||||
}
|
||||
}
|
||||
|
||||
public void beginTask() {
|
||||
progress.setVisible(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user