1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 package ohos.devtools.views.layout.chartview.memory.nativehook; 17 18 import com.intellij.icons.AllIcons; 19 import ohos.devtools.services.memory.nativebean.HookDataBean; 20 21 import javax.swing.JTree; 22 import javax.swing.tree.DefaultMutableTreeNode; 23 import javax.swing.tree.DefaultTreeCellRenderer; 24 import java.awt.Component; 25 26 /** 27 * NativeHookTreeTableRenderer 28 * 29 * @since 2021/10/25 30 */ 31 public class NativeHookTreeTableRenderer extends DefaultTreeCellRenderer { 32 33 /** 34 * HookDataBeanEnum 35 */ 36 public enum HookDataBeanEnum { 37 HEAP_ENUM, CALLSTACK_ENUM, MALLOC_ENUM; 38 } 39 40 @Override getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)41 public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, 42 boolean leaf, int row, boolean hasFocus) { 43 super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); 44 if (value instanceof DefaultMutableTreeNode) { 45 Object userObject = ((DefaultMutableTreeNode) value).getUserObject(); 46 if (userObject instanceof HookDataBean) { 47 HookDataBean node = (HookDataBean) userObject; 48 switch (node.getBeanEnum()) { 49 case HEAP_ENUM: 50 setIcon(AllIcons.Actions.ModuleDirectory); 51 break; 52 case MALLOC_ENUM: 53 setIcon(AllIcons.Debugger.Db_array); 54 break; 55 default: 56 setIcon(AllIcons.Nodes.Method); 57 } 58 } 59 } 60 return this; 61 } 62 } 63