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.applicationtrace; 17 18 import com.intellij.ui.IdeBorderFactory; 19 import com.intellij.ui.SideBorder; 20 import com.intellij.ui.components.JBPanel; 21 import com.intellij.ui.components.JBTabbedPane; 22 import com.intellij.util.ui.JBInsets; 23 import net.miginfocom.swing.MigLayout; 24 import ohos.devtools.views.applicationtrace.analysis.AllThreadPanel; 25 import ohos.devtools.views.applicationtrace.analysis.AnalysisEnum; 26 import ohos.devtools.views.applicationtrace.analysis.OtherFunctionPanel; 27 import ohos.devtools.views.applicationtrace.analysis.OtherThreadPanel; 28 import ohos.devtools.views.applicationtrace.bean.Func; 29 import ohos.devtools.views.perftrace.PerfData; 30 import ohos.devtools.views.perftrace.bean.PrefFunc; 31 import ohos.devtools.views.trace.EventDispatcher; 32 import ohos.devtools.views.trace.EventPanel; 33 import ohos.devtools.views.trace.TracePanel; 34 35 import java.util.ArrayList; 36 import java.util.List; 37 38 /** 39 * DataPanel 40 * 41 * @since 2021/5/13 13:22 42 */ 43 public class DataPanel extends EventPanel { 44 /** 45 * enum analysis 46 */ 47 public static AnalysisEnum analysisEnum; 48 49 private JBTabbedPane analysisTab; 50 private List<Integer> currentTids = new ArrayList<>(); 51 private OtherFunctionPanel otherFunctionPanel; 52 private OtherThreadPanel otherThreadPanel; 53 54 /** 55 * construction 56 * 57 * @param analysisEnum analysisEnum 58 */ DataPanel(AnalysisEnum analysisEnum)59 public DataPanel(AnalysisEnum analysisEnum) { 60 setLayout(new MigLayout("inset 0", "[grow,fill]", "[grow,fill]")); 61 analysisTab = new JBTabbedPane(); 62 analysisTab.setBorder(IdeBorderFactory.createBorder(SideBorder.NONE)); 63 analysisTab.setTabComponentInsets(JBInsets.create(0, 0)); 64 this.analysisEnum = analysisEnum; 65 initComp(); 66 } 67 initComp()68 private void initComp() { 69 removeAll(); 70 analysisTab.removeAll(); 71 analysisTab.addTab("Analysis", new JBPanel<>()); 72 analysisTab.addTab("All Threads", new AllThreadPanel(analysisEnum)); 73 otherThreadPanel = new OtherThreadPanel(analysisEnum); 74 analysisTab.setEnabledAt(0, false); 75 analysisTab.setSelectedIndex(1); 76 otherFunctionPanel = new OtherFunctionPanel(); 77 add(analysisTab, "growx,pushx"); 78 EventDispatcher.addClickListener(node -> { 79 String tabName = ""; 80 if (node instanceof Func) { 81 tabName = ((Func) node).getFuncName(); 82 } else { 83 if (node instanceof PrefFunc) { 84 tabName = ((PrefFunc) node).getFuncName(); 85 } 86 } 87 if (tabName != null && tabName.length() > 20) { 88 tabName = tabName.substring(0, 20) + "..."; 89 } 90 if (analysisTab.getTabCount() == 3) { 91 analysisTab.remove(analysisTab.getTabCount() - 1); 92 } 93 analysisTab.addTab(tabName, otherFunctionPanel); 94 analysisTab.setSelectedIndex(analysisTab.getTabCount() - 1); 95 }); 96 } 97 98 @Override change(long startNS, long endNS, List<Integer> threadIds)99 public void change(long startNS, long endNS, List<Integer> threadIds) { 100 if (threadIds.size() == 0) { 101 if (analysisTab.getTabCount() == 3) { 102 analysisTab.remove(analysisTab.getTabCount() - 1); 103 } 104 } else { 105 if (analysisTab.getTabCount() == 3) { 106 if (analysisTab.getComponentAt(analysisTab.getTabCount() - 1) instanceof OtherFunctionPanel) { 107 analysisTab.remove(analysisTab.getTabCount() - 1); 108 analysisTab.addTab(createTabName(threadIds), otherThreadPanel); 109 } else { 110 if (!threadIds.equals(currentTids)) { 111 analysisTab.setTitleAt(analysisTab.getTabCount() - 1, createTabName(threadIds)); 112 } 113 } 114 } else { 115 analysisTab.addTab(createTabName(threadIds), otherThreadPanel); 116 } 117 } 118 analysisTab.setSelectedIndex(analysisTab.getTabCount() - 1); 119 } 120 121 @Override change(long startNS, long endNS, long scale)122 public void change(long startNS, long endNS, long scale) { 123 if (analysisTab.getTabCount() != 3) { 124 change(startNS, endNS, TracePanel.currentSelectThreadIds); 125 } 126 } 127 createTabName(List<Integer> ids)128 private String createTabName(List<Integer> ids) { 129 if (ids.size() == 1 && ids.get(0) != null) { 130 String name = null; 131 if (analysisEnum.equals(AnalysisEnum.APP)) { 132 if (AllData.threadNames != null) { 133 name = AllData.threadNames.get(ids.get(0)); 134 } 135 } else { 136 if (PerfData.getThreadNames() != null) { 137 name = PerfData.getThreadNames().get(ids.get(0)); 138 } 139 } 140 if (name != null && name.length() > 20) { 141 name = name.substring(0, 20) + "..."; 142 } 143 return name == null ? "" : name; 144 } else { 145 return ids.size() + " Threads"; 146 } 147 } 148 } 149