Search in sources :

Example 6 with ColoredTreeCellRenderer

use of com.intellij.ui.ColoredTreeCellRenderer in project android by JetBrains.

the class AppTrace method generateTopdownTree.

// Convert a HNode tree into an AppStat tree (better suited for rendition in a ColumnTree).
private JComponent generateTopdownTree(HNode<MethodUsage> graph) {
    AppStatTreeNode top = new AppStatTreeNode();
    // Intentionally discard first child
    graph = graph.getFirstChild();
    convertGraphToTree(graph, top);
    JTree tree = new JTree(top);
    JComponent topdownColumnTree = new ColumnTreeBuilder(tree).addColumn(new ColumnTreeBuilder.ColumnBuilder().setName("Method").setRenderer(new ColoredTreeCellRenderer() {

        @Override
        public void customizeCellRenderer(@NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            AppStatTreeNode node = (AppStatTreeNode) value;
            append(generateNameForColumn(node.getMethodNamespace(), node.getMethodName(), getSeparator()));
        }
    })).addColumn(new ColumnTreeBuilder.ColumnBuilder().setName("Inclusive stats").setRenderer(new ColoredTreeCellRenderer() {

        @Override
        public void customizeCellRenderer(@NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            AppStatTreeNode node = (AppStatTreeNode) value;
            append(String.format("%2.1f%%", node.getPercentageInclusive() * 100));
        }
    })).addColumn(new ColumnTreeBuilder.ColumnBuilder().setName("Exclusive stats").setRenderer(new ColoredTreeCellRenderer() {

        @Override
        public void customizeCellRenderer(@NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            AppStatTreeNode node = (AppStatTreeNode) value;
            append(String.format("%2.1f%%", node.getPercentageExclusive() * 100));
        }
    })).build();
    return topdownColumnTree;
}
Also used : AppStatTreeNode(com.android.tools.idea.monitor.ui.cpu.view.AppStatTreeNode) ColoredTreeCellRenderer(com.intellij.ui.ColoredTreeCellRenderer) ColumnTreeBuilder(com.android.tools.adtui.common.ColumnTreeBuilder) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with ColoredTreeCellRenderer

use of com.intellij.ui.ColoredTreeCellRenderer in project android by JetBrains.

the class LicenseAgreementStep method init.

@Override
public void init() {
    super.init();
    myChangeTree.setModel(myTreeModel);
    myChangeTree.setShowsRootHandles(false);
    myLicenseTextField.setEditable(false);
    // Initialize radio buttons
    ButtonGroup group = new ButtonGroup();
    group.add(myDeclineRadioButton);
    group.add(myAcceptRadioButton);
    myDeclineRadioButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            myAcceptances.put(myCurrentLicense, Boolean.FALSE);
            invokeUpdate(null);
            myChangeTree.repaint();
        }
    });
    myAcceptRadioButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            myAcceptances.put(myCurrentLicense, Boolean.TRUE);
            invokeUpdate(null);
            myChangeTree.repaint();
        }
    });
    myChangeTree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            DefaultMutableTreeNode selected = (DefaultMutableTreeNode) myChangeTree.getLastSelectedPathComponent();
            if (selected != null && selected.isRoot()) {
                return;
            }
            if (selected != null && !selected.isLeaf()) {
                License license = (License) selected.getUserObject();
                myLicenseTextField.setText(license.getValue());
                myCurrentLicense = license.getId();
            } else if (selected != null && !selected.isRoot()) {
                Change change = (Change) selected.getUserObject();
                myLicenseTextField.setText(change.license.getValue());
                myCurrentLicense = change.license.getId();
            }
            if (myAcceptances.get(myCurrentLicense)) {
                myAcceptRadioButton.setSelected(true);
            } else {
                myDeclineRadioButton.setSelected(true);
            }
            myLicenseTextField.setCaretPosition(0);
        }
    });
    myChangeTree.setCellRenderer(new ColoredTreeCellRenderer() {

        @Override
        public void customizeCellRenderer(@NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            if (row == 0) {
                append("Licenses", SimpleTextAttributes.REGULAR_ATTRIBUTES);
                return;
            }
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
            if (!leaf) {
                License license = (License) node.getUserObject();
                appendLicenseText(license, license.getId());
            } else {
                Change change = (Change) node.getUserObject();
                if (change == null) {
                    return;
                }
                appendLicenseText(change.license, change.toString());
                setIcon(change.getIcon());
            }
        }

        private void appendLicenseText(@Nullable License license, String text) {
            boolean notAccepted = license != null && !myAcceptances.get(license.getId());
            if (notAccepted) {
                append("*", SimpleTextAttributes.ERROR_ATTRIBUTES);
                append(text, SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
            } else {
                append(text, SimpleTextAttributes.REGULAR_ATTRIBUTES);
            }
        }
    });
    setChanges(createChangesList());
}
Also used : ColoredTreeCellRenderer(com.intellij.ui.ColoredTreeCellRenderer) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ActionEvent(java.awt.event.ActionEvent) TreeSelectionListener(javax.swing.event.TreeSelectionListener) ActionListener(java.awt.event.ActionListener) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 8 with ColoredTreeCellRenderer

use of com.intellij.ui.ColoredTreeCellRenderer in project android by JetBrains.

the class VariantCheckboxTreeCellRenderer method appendVariant.

protected void appendVariant(@NotNull String variant) {
    ColoredTreeCellRenderer textRenderer = getTextRenderer();
    textRenderer.append(variant, REGULAR_ITALIC_ATTRIBUTES);
    textRenderer.setIcon(AndroidIcons.Variant);
}
Also used : ColoredTreeCellRenderer(com.intellij.ui.ColoredTreeCellRenderer)

Example 9 with ColoredTreeCellRenderer

use of com.intellij.ui.ColoredTreeCellRenderer in project android by JetBrains.

the class LayersTree method createCellRenderer.

private void createCellRenderer() {
    ColoredTreeCellRenderer renderer = new LayerTreeCellRenderer();
    renderer.setBorder(BorderFactory.createEmptyBorder(1, 1, 0, 0));
    setCellRenderer(renderer);
}
Also used : ColoredTreeCellRenderer(com.intellij.ui.ColoredTreeCellRenderer)

Example 10 with ColoredTreeCellRenderer

use of com.intellij.ui.ColoredTreeCellRenderer in project android by JetBrains.

the class NlOldPalettePanel method createCellRenderer.

private void createCellRenderer(@NotNull JTree tree) {
    ColoredTreeCellRenderer renderer = new ColoredTreeCellRenderer() {

        @Override
        public void customizeCellRenderer(@NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
            Object content = node.getUserObject();
            if (content instanceof Palette.Item) {
                Palette.Item item = (Palette.Item) content;
                BufferedImage image = null;
                if (!needsLibraryLoad(item) && myMode == Mode.PREVIEW && myConfiguration != null) {
                    image = myIconFactory.getImage(item, myConfiguration, getScale(item));
                }
                if (image != null) {
                    setIcon(new JBImageIcon(image));
                    setToolTipText(item.getTitle());
                } else if (needsLibraryLoad(item)) {
                    Icon icon = item.getIcon();
                    Icon download = AllIcons.Actions.Download;
                    int factor = SystemInfo.isAppleJvm ? 2 : 1;
                    image = UIUtil.createImage(factor * (download.getIconWidth() + icon.getIconWidth() + ICON_SPACER), factor * icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
                    Graphics2D g2 = (Graphics2D) image.getGraphics();
                    g2.scale(factor, factor);
                    icon.paintIcon(myTree, g2, 0, 0);
                    download.paintIcon(myTree, g2, icon.getIconWidth() + ICON_SPACER, 0);
                    g2.dispose();
                    append(item.getTitle());
                    setIcon(new JBImageIcon(ImageUtils.convertToRetinaIgnoringFailures(image)));
                } else {
                    append(item.getTitle());
                    setIcon(item.getIcon());
                }
            } else if (content instanceof Palette.Group) {
                Palette.Group group = (Palette.Group) content;
                append(group.getName());
                setIcon(AllIcons.Nodes.Folder);
            }
        }
    };
    renderer.setBorder(BorderFactory.createEmptyBorder(1, 1, 0, 0));
    tree.setCellRenderer(renderer);
}
Also used : ColoredTreeCellRenderer(com.intellij.ui.ColoredTreeCellRenderer) NotNull(org.jetbrains.annotations.NotNull) BufferedImage(java.awt.image.BufferedImage) DnDTransferItem(com.android.tools.idea.uibuilder.model.DnDTransferItem) JBImageIcon(com.intellij.util.ui.JBImageIcon) JBImageIcon(com.intellij.util.ui.JBImageIcon)

Aggregations

ColoredTreeCellRenderer (com.intellij.ui.ColoredTreeCellRenderer)11 NotNull (org.jetbrains.annotations.NotNull)6 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)3 ColumnTreeBuilder (com.android.tools.adtui.common.ColumnTreeBuilder)2 AppStatTreeNode (com.android.tools.idea.monitor.ui.cpu.view.AppStatTreeNode)2 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)2 TreeSelectionListener (javax.swing.event.TreeSelectionListener)2 Nullable (org.jetbrains.annotations.Nullable)2 License (com.android.repository.api.License)1 DnDTransferItem (com.android.tools.idea.uibuilder.model.DnDTransferItem)1 Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 PsiManager (com.intellij.psi.PsiManager)1 JBImageIcon (com.intellij.util.ui.JBImageIcon)1 ConfigFileSearcher (com.intellij.xml.config.ConfigFileSearcher)1 ConfigFilesTreeBuilder (com.intellij.xml.config.ConfigFilesTreeBuilder)1 IndexedRelevantResource (com.intellij.xml.index.IndexedRelevantResource)1 XsdNamespaceBuilder (com.intellij.xml.index.XsdNamespaceBuilder)1