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; 17 18 import com.intellij.openapi.ui.ComboBox; 19 import com.intellij.ui.JBColor; 20 import com.intellij.ui.components.JBLabel; 21 import com.intellij.ui.components.JBPanel; 22 import net.miginfocom.swing.MigLayout; 23 import ohos.devtools.datasources.utils.device.entity.DeviceIPPortInfo; 24 import ohos.devtools.datasources.utils.process.entity.ProcessInfo; 25 import ohos.devtools.datasources.utils.profilerlog.ProfilerLogManager; 26 import ohos.devtools.views.common.LayoutConstants; 27 import ohos.devtools.views.common.UtConstant; 28 import ohos.devtools.views.common.customcomp.CustomSearchComBox; 29 import org.apache.logging.log4j.LogManager; 30 import org.apache.logging.log4j.Logger; 31 32 import javax.swing.DefaultComboBoxModel; 33 import java.awt.Font; 34 import java.util.Vector; 35 36 /** 37 * DistributedDeviceProcessPanel 38 * 39 * @since 2021/10/25 40 */ 41 public class DistributedDeviceProcessPanel extends JBPanel { 42 private static final Logger LOGGER = LogManager.getLogger(DistributedDeviceProcessPanel.class); 43 private ComboBox<DeviceIPPortInfo> deviceComboBox; 44 private Vector<DeviceIPPortInfo> vector; 45 private CustomSearchComBox customSearchComBox; 46 47 /** 48 * DistributedDeviceProcessPanel 49 * 50 * @param deviceId deviceId 51 * @param deviceIPPortInfo deviceIPPortInfo 52 * @param processInfo processInfo 53 */ DistributedDeviceProcessPanel(int deviceId, DeviceIPPortInfo deviceIPPortInfo, ProcessInfo processInfo)54 public DistributedDeviceProcessPanel(int deviceId, DeviceIPPortInfo deviceIPPortInfo, ProcessInfo processInfo) { 55 this.setLayout(new MigLayout("insets 5 5 0 0")); 56 this.setOpaque(false); 57 JBPanel deviceTitlePanel = initDeviceTitlePanel(deviceId); 58 this.add(deviceTitlePanel, "wrap, span"); 59 ComboBox<String> deviceConnectTypeComboBox = new ComboBox<String>(); 60 deviceConnectTypeComboBox.addItem(LayoutConstants.USB); 61 deviceComboBox = new ComboBox<>(); 62 deviceComboBox.addItem(deviceIPPortInfo); 63 this.add(deviceConnectTypeComboBox, "width 30%"); 64 this.add(deviceComboBox, "wrap, width 68%"); 65 JBLabel applicationDesLabel = new JBLabel("Application"); 66 this.add(applicationDesLabel, "wrap, span 2"); 67 customSearchComBox = new CustomSearchComBox(deviceId, false); 68 String processName = processInfo.getProcessName() + "(" + processInfo.getProcessId() + ")"; 69 customSearchComBox.getSelectedProcessTextFiled().setText(processName); 70 this.add(customSearchComBox, "wrap, span 2, width 99%"); 71 } 72 73 /** 74 * DistributedDeviceProcessPanel 75 * 76 * @param deviceId deviceId 77 * @param deviceIPPortInfo deviceIPPortInfo 78 */ DistributedDeviceProcessPanel(int deviceId, DeviceIPPortInfo deviceIPPortInfo)79 public DistributedDeviceProcessPanel(int deviceId, DeviceIPPortInfo deviceIPPortInfo) { 80 this.setLayout(new MigLayout("insets 5 5 0 0", "[][]", "[][][][]")); 81 this.setOpaque(false); 82 JBPanel deviceTitlePanel = initDeviceTitlePanel(deviceId); 83 this.add(deviceTitlePanel, "wrap, span"); 84 ComboBox<String> deviceConnectTypeComboBox = new ComboBox<String>(); 85 deviceConnectTypeComboBox.addItem(LayoutConstants.USB); 86 deviceConnectTypeComboBox.setName(UtConstant.UT_DEVICE_PROCESS_PANEL_CONNECT_TYPE); 87 deviceComboBox = new ComboBox<>(); 88 deviceComboBox.addItem(deviceIPPortInfo); 89 deviceComboBox.setName(UtConstant.UT_DEVICE_PROCESS_PANEL_DEVICE_NAME); 90 this.add(deviceConnectTypeComboBox, "width 30%"); 91 this.add(deviceComboBox, "wrap, width 68%"); 92 JBLabel applicationDesLabel = new JBLabel("Application"); 93 this.add(applicationDesLabel, "wrap, span 2"); 94 customSearchComBox = new CustomSearchComBox(deviceId, false); 95 this.add(customSearchComBox, "wrap, span 2, width 99%"); 96 } 97 98 /** 99 * DistributedDeviceProcessPanel 100 * 101 * @param deviceId deviceId 102 * @param isDistributedPanel isDistributedPanel 103 */ DistributedDeviceProcessPanel(int deviceId, boolean isDistributedPanel)104 public DistributedDeviceProcessPanel(int deviceId, boolean isDistributedPanel) { 105 this.setLayout(new MigLayout("insets 5 5 0 0")); 106 this.setOpaque(false); 107 JBPanel deviceTitlePanel = initDeviceTitlePanel(deviceId); 108 this.add(deviceTitlePanel, "wrap, span"); 109 ComboBox<String> deviceConnectTypeComboBox = new ComboBox<String>(); 110 deviceConnectTypeComboBox.addItem(LayoutConstants.USB); 111 deviceConnectTypeComboBox.setName(UtConstant.UT_DEVICE_GPU_CONNECT_TYPE); 112 deviceComboBox = new ComboBox<>(); 113 deviceComboBox.setName(UtConstant.UT_DEVICE_GPU_DEVICE_NAME); 114 this.add(deviceConnectTypeComboBox, "width 30%"); 115 this.add(deviceComboBox, "wrap, width 68%"); 116 JBLabel applicationDesLabel = new JBLabel("Application"); 117 this.add(applicationDesLabel, "wrap, span 2"); 118 customSearchComBox = new CustomSearchComBox(deviceId, isDistributedPanel); 119 this.add(customSearchComBox, "wrap, span 2, width 99%"); 120 } 121 122 /** 123 * initDeviceTitlePanel 124 * 125 * @param index index 126 * @return JBPanel 127 */ initDeviceTitlePanel(int index)128 private JBPanel initDeviceTitlePanel(int index) { 129 if (ProfilerLogManager.isInfoEnabled()) { 130 LOGGER.info("initDeviceTitlePanel"); 131 } 132 JBPanel firstDeviceTitlePanel = new JBPanel(new MigLayout("insets 0 0 5 0", "[]15[]push", "20[fill,fill]")); 133 firstDeviceTitlePanel.setOpaque(false); 134 JBLabel firstDeviceTitle = new JBLabel("Device 0" + index); 135 firstDeviceTitle.setFont(new Font("Helvetica", Font.BOLD, 16)); 136 firstDeviceTitle.setForeground(JBColor.foreground().brighter()); 137 JBLabel deviceLabel = new JBLabel("Device"); 138 deviceLabel.setFont(new Font("PingFang SC", Font.PLAIN, 14)); 139 firstDeviceTitlePanel.add(firstDeviceTitle, "wrap"); 140 firstDeviceTitlePanel.add(deviceLabel); 141 return firstDeviceTitlePanel; 142 } 143 144 /** 145 * getSearchComBox 146 * 147 * @return CustomSearchComBox 148 */ getSearchComBox()149 public CustomSearchComBox getSearchComBox() { 150 return customSearchComBox; 151 } 152 153 /** 154 * getDeviceComboBox 155 * 156 * @return ComboBox 157 */ getDeviceComboBox()158 public ComboBox<DeviceIPPortInfo> getDeviceComboBox() { 159 return deviceComboBox; 160 } 161 162 /** 163 * refreshDeviceItem 164 * 165 * @param vector vector 166 */ refreshDeviceItem(Vector<DeviceIPPortInfo> vector)167 public void refreshDeviceItem(Vector<DeviceIPPortInfo> vector) { 168 deviceComboBox.setModel(new DefaultComboBoxModel(vector)); 169 this.vector = vector; 170 } 171 172 /** 173 * getVector 174 * 175 * @return Vector 176 */ getVector()177 public Vector<DeviceIPPortInfo> getVector() { 178 if (vector == null) { 179 return new Vector<>(); 180 } 181 return vector; 182 } 183 }