// Path: src/main/java/com/intellij/plugins/bodhi/pmd/core/PMDViolation.java
// public class PMDViolation implements HasPositionInFile {
// 
//     private final RuleViolation ruleViolation;
//     private final String positionText;
//     private final String classAndMethodMsg;
//     private final String packageMsg;
// 
//     /**
//      * Creates a PMDViolation which wraps the IRuleViolation given.
//      *
//      * @param violation the violation
//      */
//     public PMDViolation(RuleViolation violation) {
//         this.ruleViolation = violation;
//         this.positionText = "(" + violation.getBeginLine() + ", " + violation.getBeginColumn() + ") ";
//         String fileName = violation.getFilename();
//         int startIndex = fileName.lastIndexOf(File.separatorChar);
//         String className = violation.getClassName();
//         if (className == null || className.length() == 0) {
//             if (startIndex != -1) {
//                 className = fileName.substring(startIndex + 1, fileName.indexOf('.', startIndex));
//             }
//         }
//         String methodName = violation.getMethodName();
//         if (methodName == null) {
//             methodName = "";
//         }
//         if (methodName.length() > 0) {
//             methodName = "." + methodName + "()";
//         }
//         String packageName = violation.getPackageName();
//         this.packageMsg = (packageName != null && packageName.trim().length() > 0) ? (" in " + packageName) : "";
//         this.classAndMethodMsg = className + methodName;
//     }
// 
//     @Override
//     public String getFilename() {
//         return ruleViolation.getFilename();
//     }
// 
//     @Override
//     public int getBeginLine() {
//         return ruleViolation.getBeginLine();
//     }
// 
//     @Override
//     public int getBeginColumn() {
//         return ruleViolation.getBeginColumn();
//     }
// 
//     public int getEndLine() {
//         return ruleViolation.getEndLine();
//     }
// 
//     public int getEndColumn() {
//         return ruleViolation.getEndColumn();
//     }
// 
//     private Rule getRule() {
//         return ruleViolation.getRule();
//     }
// 
//     public String getDescription() {
//         return ruleViolation.getDescription();
//     }
// 
//     public String getPackageName() {
//         return ruleViolation.getPackageName();
//     }
// 
//     public String getMethodName() {
//         return ruleViolation.getMethodName();
//     }
// 
//     public String getClassName() {
//         return ruleViolation.getClassName();
//     }
// 
//     public boolean isSuppressed() {
//         return ruleViolation.isSuppressed();
//     }
// 
//     public String getVariableName() {
//         return ruleViolation.getVariableName();
//     }
// 
//     public String getPositionText() {
//         return this.positionText;
//     }
// 
//     public String getExternalUrl() {
//         return getRule().getExternalInfoUrl();
//     }
// 
//     public String getClassAndMethodMsg() {
//         return classAndMethodMsg;
//     }
// 
//     public String getPackageMsg() {
//         return packageMsg;
//     }
// 
//     public String getToolTip() {
//         return getDescription();
//     }
// 
//     public String getRuleName() {
//         return getRule().getName();
//     }
// 
//     public String getRulePriorityName() {
//         return getRule().getPriority().getName();
//     }
// 
//     public String toString() {
//         return getPackageName() + "." + getClassName() + "." + getMethodName() + " at (" + getBeginLine() + "," + getBeginColumn() + ")";
//     }
// }


import com.intellij.openapi.util.IconLoader;
import com.intellij.plugins.bodhi.pmd.core.PMDViolation;
import com.intellij.ui.ColoredTreeCellRenderer;
import javax.swing.*;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
package com.intellij.plugins.bodhi.pmd.tree;



/**
 * A Custom Cell renderer that will render the user objects of this plugin
 * correctly. It extends the ColoredTreeCellRenderer to make use of the text
 * attributes.
 *
 * @author bodhi
 * @version 1.2
 */
public class PMDCellRenderer extends ColoredTreeCellRenderer {

    //Default tree icons
    static Icon CLOSED_ICON;
    static Icon OPEN_ICON;
    public static final Icon ERROR = IconLoader.getIcon("/compiler/error.png");
    public static final Icon WARN = IconLoader.getIcon("/compiler/warning.png");
    public static final Icon INFO = IconLoader.getIcon("/compiler/information.png");

    private static final Map<String, Icon> prioToIcon;

    //Try to load idea specific icons for the tree.
    static {
        CLOSED_ICON = IconLoader.getIcon("/nodes/TreeClosed.png");
        OPEN_ICON = IconLoader.getIcon("/nodes/TreeOpen.png");

        Map<String, Icon> attrs = new HashMap<>();
        attrs.put("Medium", WARN);
        attrs.put("Medium High", WARN);
        attrs.put("High", ERROR);
        attrs.put("Medium Low", INFO);
        attrs.put("Low", INFO);
        prioToIcon = Collections.unmodifiableMap(attrs);
    }

    public void customizeCellRenderer(JTree tree,
                                      Object value,
                                      boolean selected,
                                      boolean expanded,
                                      boolean leaf,
                                      int row,
                                      boolean hasFocus) {
        if (value instanceof BasePMDNode) {
            ((BasePMDNode)value).render(this, expanded);
        }
    }

// Path: src/main/java/com/intellij/plugins/bodhi/pmd/core/PMDViolation.java
// public class PMDViolation implements HasPositionInFile {
// 
//     private final RuleViolation ruleViolation;
//     private final String positionText;
//     private final String classAndMethodMsg;
//     private final String packageMsg;
// 
//     /**
//      * Creates a PMDViolation which wraps the IRuleViolation given.
//      *
//      * @param violation the violation
//      */
//     public PMDViolation(RuleViolation violation) {
//         this.ruleViolation = violation;
//         this.positionText = "(" + violation.getBeginLine() + ", " + violation.getBeginColumn() + ") ";
//         String fileName = violation.getFilename();
//         int startIndex = fileName.lastIndexOf(File.separatorChar);
//         String className = violation.getClassName();
//         if (className == null || className.length() == 0) {
//             if (startIndex != -1) {
//                 className = fileName.substring(startIndex + 1, fileName.indexOf('.', startIndex));
//             }
//         }
//         String methodName = violation.getMethodName();
//         if (methodName == null) {
//             methodName = "";
//         }
//         if (methodName.length() > 0) {
//             methodName = "." + methodName + "()";
//         }
//         String packageName = violation.getPackageName();
//         this.packageMsg = (packageName != null && packageName.trim().length() > 0) ? (" in " + packageName) : "";
//         this.classAndMethodMsg = className + methodName;
//     }
// 
//     @Override
//     public String getFilename() {
//         return ruleViolation.getFilename();
//     }
// 
//     @Override
//     public int getBeginLine() {
//         return ruleViolation.getBeginLine();
//     }
// 
//     @Override
//     public int getBeginColumn() {
//         return ruleViolation.getBeginColumn();
//     }
// 
//     public int getEndLine() {
//         return ruleViolation.getEndLine();
//     }
// 
//     public int getEndColumn() {
//         return ruleViolation.getEndColumn();
//     }
// 
//     private Rule getRule() {
//         return ruleViolation.getRule();
//     }
// 
//     public String getDescription() {
//         return ruleViolation.getDescription();
//     }
// 
//     public String getPackageName() {
//         return ruleViolation.getPackageName();
//     }
// 
//     public String getMethodName() {
//         return ruleViolation.getMethodName();
//     }
// 
//     public String getClassName() {
//         return ruleViolation.getClassName();
//     }
// 
//     public boolean isSuppressed() {
//         return ruleViolation.isSuppressed();
//     }
// 
//     public String getVariableName() {
//         return ruleViolation.getVariableName();
//     }
// 
//     public String getPositionText() {
//         return this.positionText;
//     }
// 
//     public String getExternalUrl() {
//         return getRule().getExternalInfoUrl();
//     }
// 
//     public String getClassAndMethodMsg() {
//         return classAndMethodMsg;
//     }
// 
//     public String getPackageMsg() {
//         return packageMsg;
//     }
// 
//     public String getToolTip() {
//         return getDescription();
//     }
// 
//     public String getRuleName() {
//         return getRule().getName();
//     }
// 
//     public String getRulePriorityName() {
//         return getRule().getPriority().getName();
//     }
// 
//     public String toString() {
//         return getPackageName() + "." + getClassName() + "." + getMethodName() + " at (" + getBeginLine() + "," + getBeginColumn() + ")";
//     }
// }


// Path: src/main/java/com/intellij/plugins/bodhi/pmd/tree/PMDCellRenderer.java
import com.intellij.openapi.util.IconLoader;
import com.intellij.plugins.bodhi.pmd.core.PMDViolation;
import com.intellij.ui.ColoredTreeCellRenderer;
import javax.swing.*;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

package com.intellij.plugins.bodhi.pmd.tree;



/**
 * A Custom Cell renderer that will render the user objects of this plugin
 * correctly. It extends the ColoredTreeCellRenderer to make use of the text
 * attributes.
 *
 * @author bodhi
 * @version 1.2
 */
public class PMDCellRenderer extends ColoredTreeCellRenderer {

    //Default tree icons
    static Icon CLOSED_ICON;
    static Icon OPEN_ICON;
    public static final Icon ERROR = IconLoader.getIcon("/compiler/error.png");
    public static final Icon WARN = IconLoader.getIcon("/compiler/warning.png");
    public static final Icon INFO = IconLoader.getIcon("/compiler/information.png");

    private static final Map<String, Icon> prioToIcon;

    //Try to load idea specific icons for the tree.
    static {
        CLOSED_ICON = IconLoader.getIcon("/nodes/TreeClosed.png");
        OPEN_ICON = IconLoader.getIcon("/nodes/TreeOpen.png");

        Map<String, Icon> attrs = new HashMap<>();
        attrs.put("Medium", WARN);
        attrs.put("Medium High", WARN);
        attrs.put("High", ERROR);
        attrs.put("Medium Low", INFO);
        attrs.put("Low", INFO);
        prioToIcon = Collections.unmodifiableMap(attrs);
    }

    public void customizeCellRenderer(JTree tree,
                                      Object value,
                                      boolean selected,
                                      boolean expanded,
                                      boolean leaf,
                                      int row,
                                      boolean hasFocus) {
        if (value instanceof BasePMDNode) {
            ((BasePMDNode)value).render(this, expanded);
        }
    }

    public void setIconForViolationPrio(PMDViolation violation) {