Search in sources :

Example 1 with ClassInstance

use of com.android.tools.perflib.heap.ClassInstance in project android by JetBrains.

the class ViewBitmapAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    ClassInstance selectedClassInstance = e.getData(InstancesTreeView.SELECTED_CLASS_INSTANCE);
    if (selectedClassInstance == null) {
        return;
    }
    try {
        BufferedImage img = BitmapDecoder.getBitmap(new HprofBitmapProvider(selectedClassInstance));
        final JComponent comp;
        if (img != null) {
            comp = ImageEditorManagerImpl.createImageEditorUI(img);
        } else {
            String errorMessage = AndroidBundle.message("android.profiler.hprof.actions.view.bitmap.fail");
            comp = new JLabel(errorMessage, Messages.getErrorIcon(), SwingConstants.CENTER);
        }
        Project project = e.getData(CommonDataKeys.PROJECT);
        JBPopup popup = DebuggerUIUtil.createValuePopup(project, comp, null);
        JFrame frame = WindowManager.getInstance().getFrame(project);
        Dimension frameSize = frame.getSize();
        Dimension size = new Dimension(frameSize.width / 2, frameSize.height / 2);
        popup.setSize(size);
        popup.show(new RelativePoint(frame, new Point(size.width / 2, size.height / 2)));
    } catch (Exception ignored) {
    }
}
Also used : RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) BufferedImage(java.awt.image.BufferedImage) Project(com.intellij.openapi.project.Project) JBPopup(com.intellij.openapi.ui.popup.JBPopup) ClassInstance(com.android.tools.perflib.heap.ClassInstance) HprofBitmapProvider(com.android.tools.perflib.heap.memoryanalyzer.HprofBitmapProvider)

Example 2 with ClassInstance

use of com.android.tools.perflib.heap.ClassInstance in project android by JetBrains.

the class ViewBitmapAction method update.

@Override
public void update(AnActionEvent e) {
    ClassInstance selectedClassInstance = e.getData(InstancesTreeView.SELECTED_CLASS_INSTANCE);
    Presentation presentation = e.getPresentation();
    if (selectedClassInstance != null) {
        boolean isBitmap = HprofBitmapProvider.canGetBitmapFromInstance(selectedClassInstance);
        if (isBitmap) {
            presentation.setEnabled(true);
            return;
        }
    }
    presentation.setEnabled(false);
}
Also used : Presentation(com.intellij.openapi.actionSystem.Presentation) ClassInstance(com.android.tools.perflib.heap.ClassInstance)

Aggregations

ClassInstance (com.android.tools.perflib.heap.ClassInstance)2 HprofBitmapProvider (com.android.tools.perflib.heap.memoryanalyzer.HprofBitmapProvider)1 Presentation (com.intellij.openapi.actionSystem.Presentation)1 Project (com.intellij.openapi.project.Project)1 JBPopup (com.intellij.openapi.ui.popup.JBPopup)1 RelativePoint (com.intellij.ui.awt.RelativePoint)1 BufferedImage (java.awt.image.BufferedImage)1