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;
}
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());
}
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);
}
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);
}
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);
}
Aggregations