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.event; 17 18 import com.intellij.icons.AllIcons; 19 import com.intellij.openapi.util.IconLoader; 20 import ohos.devtools.datasources.utils.session.service.SessionManager; 21 import ohos.devtools.services.cpu.CpuDataCache; 22 import ohos.devtools.services.diskio.DiskIoDataCache; 23 import ohos.devtools.services.memory.memoryservice.MemoryDataCache; 24 import ohos.devtools.views.applicationtrace.AppTracePanel; 25 import ohos.devtools.views.charts.model.ChartStandard; 26 import ohos.devtools.views.charts.utils.ChartUtils; 27 import ohos.devtools.views.common.ColorConstants; 28 import ohos.devtools.views.common.Constant; 29 import ohos.devtools.views.common.LayoutConstants; 30 import ohos.devtools.views.common.UtConstant; 31 import ohos.devtools.views.common.customcomp.CustomComboBox; 32 import ohos.devtools.views.common.customcomp.CustomJButton; 33 import ohos.devtools.views.common.customcomp.CustomJLabel; 34 import ohos.devtools.views.layout.TaskPanel; 35 import ohos.devtools.views.layout.chartview.CountingThread; 36 import ohos.devtools.views.layout.chartview.PerformanceIndexPopupMenu; 37 import ohos.devtools.views.layout.chartview.ProfilerChartsView; 38 import ohos.devtools.views.layout.chartview.SubSessionListJBPanel; 39 import ohos.devtools.views.layout.chartview.TaskScenePanelChart; 40 import ohos.devtools.views.layout.dialog.ExportFileChooserDialog; 41 import ohos.devtools.views.layout.dialog.SampleDialog; 42 import ohos.devtools.views.perftrace.PerfTracePanel; 43 44 import javax.swing.BorderFactory; 45 import javax.swing.JButton; 46 import javax.swing.JLabel; 47 import javax.swing.JLayeredPane; 48 import javax.swing.JPanel; 49 import javax.swing.JSplitPane; 50 import javax.swing.SwingUtilities; 51 import javax.swing.UIManager; 52 import java.awt.BorderLayout; 53 import java.awt.Color; 54 import java.awt.Component; 55 import java.awt.Container; 56 import java.awt.Font; 57 import java.awt.event.ActionEvent; 58 import java.awt.event.ActionListener; 59 import java.awt.event.ComponentAdapter; 60 import java.awt.event.ComponentEvent; 61 import java.awt.event.MouseAdapter; 62 import java.awt.event.MouseEvent; 63 import java.util.List; 64 import java.util.Objects; 65 66 /** 67 * 任务场景面板图事件类 68 * 69 * @since 2021/11/22 70 */ 71 public class TaskScenePanelChartEvent { 72 private static final int NUM_2 = 2; 73 private static final int NUM_10 = 10; 74 private static final Long ABNORMAL = -1L; 75 76 private boolean flagLeft = false; 77 private boolean flag = false; 78 private Container obj = null; 79 private boolean buttonAvailable = true; 80 private boolean resultDelete = false; 81 private long stopTime = -1; 82 83 /** 84 * 点击删除 85 * 86 * @param taskScenePanelChart taskScenePanelChart 87 */ clickDelete(TaskScenePanelChart taskScenePanelChart)88 public void clickDelete(TaskScenePanelChart taskScenePanelChart) { 89 taskScenePanelChart.getJButtonDelete().addActionListener(new ActionListener() { 90 /** 91 * actionPerformed 92 * 93 * @param event event 94 */ 95 @Override 96 public void actionPerformed(ActionEvent event) { 97 if (taskScenePanelChart.isGreyFlag()) { 98 return; 99 } 100 long localSessionId = taskScenePanelChart.getJButtonDelete().getSessionId(); 101 Font font = new Font("", 0, LayoutConstants.SIXTEEN); 102 UIManager.put("OptionPane.messageFont", font); 103 if (localSessionId < 0) { 104 new SampleDialog("prompt", "Please select the task to delete first !").show(); 105 return; 106 } 107 SampleDialog sampleDialogWrapper = 108 new SampleDialog("prompt", "Are you sure you want to delete this task ?"); 109 boolean flags = sampleDialogWrapper.showAndGet(); 110 if (flags) { 111 // 调用SessionManager的删除sessionId 112 if (!SessionManager.getInstance().endSession(localSessionId)) { 113 return; 114 } 115 CountingThread countingThread = taskScenePanelChart.getCounting(); 116 countingThread.setStopFlag(true); 117 // 容器中销毁char和Session的panel 118 // 删除界面cards的Session 119 deleteSession(localSessionId, taskScenePanelChart); 120 // 删除界面char 121 deleteChart(localSessionId, taskScenePanelChart); 122 // After deleting the chart list, there are sub options that should be displayed 123 List<SubSessionListJBPanel> list = taskScenePanelChart.getDumpOrHookSessionList(); 124 if (list.size() > 0) { 125 taskScenePanelChart.showSubSessionList(list); 126 } 127 taskScenePanelChart.getJButtonDelete().setSessionId(ABNORMAL); 128 taskScenePanelChart.repaint(); 129 // 清除sessionid,保存trace文件时根据这个判断是否可以保存 130 taskScenePanelChart.getjButtonSave().setSessionId(0); 131 taskScenePanelChart.getjButtonRun() 132 .setIcon(IconLoader.getIcon("/images/breakpoint_grey.png", getClass())); 133 taskScenePanelChart.getjButtonStop().setIcon(AllIcons.Process.ProgressResumeHover); 134 resultDelete = true; 135 clearTimeCounting(taskScenePanelChart); 136 } 137 } 138 }); 139 } 140 141 /** 142 * Delete interface chart 143 * 144 * @param localSessionId localSessionId 145 * @param taskScenePanelChart taskScenePanelChart 146 */ deleteChart(long localSessionId, TaskScenePanelChart taskScenePanelChart)147 private void deleteChart(long localSessionId, TaskScenePanelChart taskScenePanelChart) { 148 Component[] carts = taskScenePanelChart.getCards().getComponents(); 149 for (Component cart : carts) { 150 if (cart instanceof JPanel) { 151 Component[] jcardsPanels = ((JPanel) cart).getComponents(); 152 for (Component item : jcardsPanels) { 153 ProfilerChartsView profilerView = null; 154 if (item instanceof ProfilerChartsView) { 155 profilerView = (ProfilerChartsView) item; 156 if (profilerView.getSessionId() == localSessionId) { 157 ((JPanel) cart).remove(profilerView); 158 } 159 } 160 } 161 } 162 } 163 } 164 165 /** 166 * Delete Session 167 * 168 * @param localSessionId localSessionId 169 * @param taskScenePanelChart taskScenePanelChart 170 */ deleteSession(long localSessionId, TaskScenePanelChart taskScenePanelChart)171 private void deleteSession(long localSessionId, TaskScenePanelChart taskScenePanelChart) { 172 JPanel jScrollCardsPanelInner = taskScenePanelChart.getJScrollCardsPanelInner(); 173 Component[] innerJpanel = jScrollCardsPanelInner.getComponents(); 174 for (Component inner : innerJpanel) { 175 Component[] innerLable = null; 176 if (inner instanceof JPanel) { 177 innerLable = ((JPanel) inner).getComponents(); 178 for (Component item : innerLable) { 179 if (item instanceof CustomJLabel && localSessionId == ((CustomJLabel) item).getSessionId()) { 180 jScrollCardsPanelInner.remove(inner); 181 } 182 } 183 } 184 } 185 } 186 187 /** 188 * clickUpAndNext 189 * 190 * @param taskScenePanelChart taskScenePanelChart 191 */ clickUpAndNext(TaskScenePanelChart taskScenePanelChart)192 public void clickUpAndNext(TaskScenePanelChart taskScenePanelChart) { 193 // 给上一个页面按钮添加点击事件 194 taskScenePanelChart.getjButtonUp().addActionListener(new ActionListener() { 195 @Override 196 public void actionPerformed(ActionEvent exception) { 197 if (Constant.jtasksTab.getSelectedIndex() > 0) { 198 Constant.jtasksTab.setSelectedIndex(Constant.jtasksTab.getSelectedIndex() - 1); 199 } 200 } 201 }); 202 // 给下一个页面按钮添加点击事件 203 taskScenePanelChart.getjButtonNext().addActionListener(new ActionListener() { 204 @Override 205 public void actionPerformed(ActionEvent exception) { 206 if (Constant.jtasksTab.getSelectedIndex() != Constant.jtasksTab.getTabCount() - 1) { 207 Constant.jtasksTab.setSelectedIndex(Constant.jtasksTab.getSelectedIndex() + 1); 208 } 209 } 210 }); 211 } 212 213 /** 214 * saveButtonAddClick 215 * 216 * @param labelSave labelSave 217 * @param name name 218 */ saveButtonAddClick(CustomJLabel labelSave, String name)219 public void saveButtonAddClick(CustomJLabel labelSave, String name) { 220 labelSave.addMouseListener(new MouseAdapter() { 221 @Override 222 public void mouseClicked(MouseEvent mouseEvent) { 223 String fileType = ""; 224 if (name.contains("Native Heap")) { 225 fileType = "nativeHeap"; 226 } else { 227 fileType = "hprof"; 228 } 229 ExportFileChooserDialog fileChooserDialogWrapper = new ExportFileChooserDialog("Export As", fileType); 230 boolean showAndGet = fileChooserDialogWrapper.showAndGet(); 231 if (showAndGet) { 232 String exportFileName = labelSave.getName(); 233 boolean saveResult = 234 SessionManager.getInstance().exportDumpOrHookFile(exportFileName, fileChooserDialogWrapper); 235 if (saveResult) { 236 new SampleDialog("prompt", "Save Successfully !").show(); 237 } else { 238 new SampleDialog("prompt", "Save failure !").show(); 239 } 240 } 241 } 242 243 @Override 244 public void mouseEntered(MouseEvent event) { 245 labelSave.setBorder(BorderFactory.createTitledBorder("")); 246 } 247 248 @Override 249 public void mouseExited(MouseEvent event) { 250 labelSave.setBorder(null); 251 } 252 }); 253 } 254 255 /** 256 * dumpPanelAddClick 257 * 258 * @param dumpPanel dumpPanel 259 * @param taskScenePanelChart taskScenePanelChart 260 */ sessionListPanelAddClick(SubSessionListJBPanel dumpPanel, TaskScenePanelChart taskScenePanelChart)261 public void sessionListPanelAddClick(SubSessionListJBPanel dumpPanel, TaskScenePanelChart taskScenePanelChart) { 262 dumpPanel.addMouseListener(new MouseAdapter() { 263 @Override 264 public void mouseClicked(MouseEvent mouseEvent) { 265 taskScenePanelChart.setButtonEnable(true, dumpPanel.getPanelName()); 266 if (dumpPanel.getPanelName().contains("traceApp") || dumpPanel.getPanelName().contains("nativePerf")) { 267 Component[] components = taskScenePanelChart.getCards().getComponents(); 268 for (Component component : components) { 269 if (component instanceof AppTracePanel || component instanceof PerfTracePanel) { 270 taskScenePanelChart.getCards().remove(component); 271 } 272 } 273 if (dumpPanel.getPanelName().contains("traceApp")) { 274 taskScenePanelChart 275 .showAppTrace(dumpPanel.getDbPath(), taskScenePanelChart.getjButtonRun().getSessionId()); 276 } 277 if (dumpPanel.getPanelName().contains("nativePerf")) { 278 taskScenePanelChart.showPerfTrace(dumpPanel.getDbPath()); 279 } 280 taskScenePanelChart.setButtonEnable(true, dumpPanel.getDbPath()); 281 } else { 282 taskScenePanelChart.getCardLayout().show(taskScenePanelChart.getCards(), dumpPanel.getPanelName()); 283 } 284 taskScenePanelChart.setGreyFlag(true); 285 dumpPanel.setBackground(ColorConstants.SELECTED_COLOR); 286 dumpPanel.getHosJLabel().setForeground(ColorConstants.FONT_COLOR); 287 if (Objects.nonNull(dumpPanel.getTimeJLabel())) { 288 dumpPanel.getTimeJLabel().setForeground(ColorConstants.FONT_COLOR); 289 } 290 } 291 292 @Override 293 public void mouseEntered(MouseEvent event) { 294 } 295 296 @Override 297 public void mouseExited(MouseEvent event) { 298 } 299 }); 300 } 301 stopTask(ProfilerChartsView profilerView, CustomJButton stopButton, TaskScenePanelChart taskScenePanelChart)302 private void stopTask(ProfilerChartsView profilerView, CustomJButton stopButton, 303 TaskScenePanelChart taskScenePanelChart) { 304 profilerView.getPublisher().stopRefresh(false); 305 // Re-refresh the status of the app after stopping 306 stopButton.setIcon(IconLoader.getIcon("/images/breakpoint.png", getClass())); 307 taskScenePanelChart.getjButtonStop().setIcon(AllIcons.Process.ProgressResumeHover); 308 buttonAvailable = false; 309 CountingThread countingThread = taskScenePanelChart.getCounting(); 310 countingThread.setStopFlag(true); 311 stopButton.setToolTipText("Start"); 312 boolean endFlag = SessionManager.getInstance().endSession(stopButton.getSessionId()); 313 if (!endFlag) { 314 stopButton.setIcon(IconLoader.getIcon("/images/breakpoint_grey.png", getClass())); 315 taskScenePanelChart.setGreyFlag(true); 316 taskScenePanelChart.getJButtonDelete().setIcon(IconLoader.getIcon("/images/gc_grey.png", getClass())); 317 new SampleDialog("prompt", "Failed to stop this session. Exit and try again.").show(); 318 return; 319 } 320 // Clear cache of all monitor items 321 MemoryDataCache.getInstance().clearCacheBySession(stopButton.getSessionId()); 322 CpuDataCache.getInstance().clearCacheBySession(stopButton.getSessionId()); 323 DiskIoDataCache.getInstance().clearCacheBySession(stopButton.getSessionId()); 324 profilerView.setStop(true); 325 profilerView.setPause(true); 326 } 327 startTask(ProfilerChartsView profilerView, CustomJButton stopButton, TaskScenePanelChart taskScenePanelChart)328 private void startTask(ProfilerChartsView profilerView, CustomJButton stopButton, 329 TaskScenePanelChart taskScenePanelChart) { 330 stopButton.setIcon(AllIcons.Debugger.Db_set_breakpoint); 331 taskScenePanelChart.getjButtonStop().setIcon(AllIcons.Process.ProgressPauseHover); 332 buttonAvailable = true; 333 stopButton.setToolTipText("Stop"); 334 // Set the icon change after the pause button is clicked Open the session to get data 335 long sessionId = stopButton.getSessionId(); 336 SessionManager sessionManager = SessionManager.getInstance(); 337 boolean startFlag = sessionManager.startSession(sessionId, true); 338 if (!startFlag) { 339 stopButton.setIcon(IconLoader.getIcon("/images/breakpoint_grey.png", getClass())); 340 taskScenePanelChart.setGreyFlag(true); 341 taskScenePanelChart.getJButtonDelete().setIcon(IconLoader.getIcon("/images/gc_grey.png", getClass())); 342 new SampleDialog("prompt", "Failed to start this session. Exit and try again.").show(); 343 return; 344 } 345 sessionManager.fetchData(sessionId); 346 if (profilerView.getPublisher().isDisplayScrollbar()) { 347 profilerView.removeScrollbar(); 348 } 349 JLabel jTextArea = taskScenePanelChart.getjTextArea(); 350 CountingThread counting = new CountingThread(jTextArea); 351 taskScenePanelChart.setCounting(counting); 352 counting.start(); 353 // Clear the selected time after restarting 354 profilerView.getPublisher().getStandard().clearAllSelectedRanges(); 355 profilerView.showLoading(); 356 profilerView.setStop(false); 357 profilerView.setPause(false); 358 } 359 360 /** 361 * clickRunAndStop 362 * 363 * @param taskScenePanelChart taskScenePanelChart 364 * @param profilerView profilerView 365 */ clickRunAndStop(TaskScenePanelChart taskScenePanelChart, ProfilerChartsView profilerView)366 public void clickRunAndStop(TaskScenePanelChart taskScenePanelChart, ProfilerChartsView profilerView) { 367 CustomJButton stopButton = taskScenePanelChart.getjButtonRun(); 368 stopButton.addActionListener(new ActionListener() { 369 @Override 370 public void actionPerformed(ActionEvent exception) { 371 if (taskScenePanelChart.isGreyFlag()) { 372 return; 373 } 374 if (resultDelete) { 375 return; 376 } 377 if (profilerView.isLoading()) { 378 return; 379 } 380 if (!profilerView.isStop()) { 381 stopTask(profilerView, stopButton, taskScenePanelChart); 382 stopTime = System.currentTimeMillis(); 383 } else { 384 if (System.currentTimeMillis() - stopTime >= 1000) { 385 startTask(profilerView, stopButton, taskScenePanelChart); 386 } 387 } 388 } 389 }); 390 pauseButtonEvent(taskScenePanelChart, profilerView); 391 } 392 393 /** 394 * Pause button event 395 * 396 * @param taskScenePanelChart taskScenePanelChart 397 * @param profilerView profilerView 398 */ pauseButtonEvent(TaskScenePanelChart taskScenePanelChart, ProfilerChartsView profilerView)399 private void pauseButtonEvent(TaskScenePanelChart taskScenePanelChart, ProfilerChartsView profilerView) { 400 taskScenePanelChart.getjButtonStop().addActionListener(new ActionListener() { 401 @Override 402 public void actionPerformed(ActionEvent exception) { 403 if (taskScenePanelChart.isGreyFlag()) { 404 return; 405 } 406 if (resultDelete) { 407 return; 408 } 409 if (profilerView.isLoading()) { 410 return; 411 } 412 if (buttonAvailable) { 413 if (!profilerView.isPause()) { 414 taskScenePanelChart.getjButtonStop().setIcon(AllIcons.Process.ProgressResumeHover); 415 taskScenePanelChart.getjButtonStop().setToolTipText("Start"); 416 profilerView.getPublisher().pauseRefresh(); 417 profilerView.setPause(true); 418 } else { 419 taskScenePanelChart.getjButtonStop().setIcon(AllIcons.Process.ProgressPauseHover); 420 taskScenePanelChart.getjButtonStop().setToolTipText("Suspend"); 421 profilerView.getPublisher().restartRefresh(); 422 profilerView.setPause(false); 423 } 424 } 425 } 426 }); 427 } 428 429 /** 430 * splitPaneChange 431 * 432 * @param taskScenePanelChart taskScenePanelChart 433 * @param numberSum numberSum 434 */ splitPaneChange(TaskScenePanelChart taskScenePanelChart, int numberSum)435 public void splitPaneChange(TaskScenePanelChart taskScenePanelChart, int numberSum) { 436 taskScenePanelChart.getSplitPane().addPropertyChangeListener(new java.beans.PropertyChangeListener() { 437 /** 438 * propertyChange 439 * 440 * @param evt evt 441 */ 442 public void propertyChange(java.beans.PropertyChangeEvent evt) { 443 if (evt.getPropertyName().equals(JSplitPane.DIVIDER_LOCATION_PROPERTY)) { 444 int numEvt = 0; 445 for (int index = 0; index < numberSum; index++) { 446 JPanel jPanel = null; 447 Object objNew = taskScenePanelChart.getJScrollCardsPanelInner().getComponentAt(0, numEvt); 448 if (objNew instanceof JPanel) { 449 jPanel = (JPanel) objNew; 450 if (Integer.parseInt(evt.getNewValue().toString()) 451 < LayoutConstants.SESSION_LIST_DIVIDER_WIDTH) { 452 jPanel.setBounds(0, numEvt, LayoutConstants.SESSION_LIST_DIVIDER_WIDTH, 453 LayoutConstants.SIXTY); 454 } else { 455 jPanel.setBounds(0, numEvt, LayoutConstants.SESSION_LIST_DIVIDER_WIDTH + Integer 456 .parseInt(evt.getNewValue().toString()) 457 - LayoutConstants.SESSION_LIST_DIVIDER_WIDTH, LayoutConstants.SIXTY); 458 } 459 460 numEvt += LayoutConstants.SIXTY; 461 jPanel.updateUI(); 462 jPanel.repaint(); 463 } 464 } 465 } 466 } 467 }); 468 } 469 470 /** 471 * clickLeft 472 * 473 * @param taskScenePanelChart taskScenePanelChart 474 * @param hosJLabelList hosJLabelList 475 */ clickLeft(TaskScenePanelChart taskScenePanelChart, List<CustomJLabel> hosJLabelList)476 public void clickLeft(TaskScenePanelChart taskScenePanelChart, List<CustomJLabel> hosJLabelList) { 477 taskScenePanelChart.getjButtonLeft().addActionListener(new ActionListener() { 478 @Override 479 public void actionPerformed(ActionEvent exception) { 480 if (!flagLeft) { 481 taskScenePanelChart.getSplitPane().setDividerLocation(1); 482 taskScenePanelChart.getSplitPane().updateUI(); 483 taskScenePanelChart.getSplitPane().repaint(); 484 flagLeft = true; 485 } else { 486 if (hosJLabelList.size() > 0 && hosJLabelList.get(0).isOnline()) { 487 taskScenePanelChart.getSplitPane() 488 .setDividerLocation(LayoutConstants.SESSION_LIST_DIVIDER_WIDTH); 489 } else { 490 taskScenePanelChart.getSplitPane().setDividerLocation(LayoutConstants.NUM_200); 491 } 492 flagLeft = false; 493 taskScenePanelChart.getSplitPane().updateUI(); 494 taskScenePanelChart.getSplitPane().repaint(); 495 } 496 } 497 }); 498 taskScenePanelChart.addComponentListener(new ComponentAdapter() { 499 /** 500 * componentResized 501 * 502 * @param exception exception 503 */ 504 public void componentResized(ComponentEvent exception) { 505 if (flagLeft) { 506 taskScenePanelChart.getSplitPane().setDividerLocation(1); 507 taskScenePanelChart.getSplitPane().updateUI(); 508 taskScenePanelChart.getSplitPane().repaint(); 509 flagLeft = true; 510 } else { 511 taskScenePanelChart.getSplitPane() 512 .setDividerLocation(taskScenePanelChart.getSplitPane().getDividerLocation()); 513 taskScenePanelChart.getSplitPane().updateUI(); 514 taskScenePanelChart.getSplitPane().repaint(); 515 } 516 } 517 }); 518 } 519 520 /** 521 * bindSessionId 522 * 523 * @param taskScenePanelChart taskScenePanelChart 524 * @param jLabelRight jLabelRight 525 * @param jMultiplePanel jMultiplePanel 526 */ bindSessionId(TaskScenePanelChart taskScenePanelChart, CustomJLabel jLabelRight, JPanel jMultiplePanel)527 private void bindSessionId(TaskScenePanelChart taskScenePanelChart, CustomJLabel jLabelRight, 528 JPanel jMultiplePanel) { 529 taskScenePanelChart.getjButtonRun().setSessionId(jLabelRight.getSessionId()); 530 taskScenePanelChart.getjButtonStop().setSessionId(jLabelRight.getSessionId()); 531 taskScenePanelChart.getjButtonSave().setSessionId(jLabelRight.getSessionId()); 532 taskScenePanelChart.getjButtonSave().setDeviceName(jLabelRight.getDeviceName()); 533 taskScenePanelChart.getjButtonSave().setProcessName(jLabelRight.getProcessName()); 534 taskScenePanelChart.getJButtonDelete().setSessionId(jLabelRight.getSessionId()); 535 taskScenePanelChart.getJButtonDelete().setDeviceName(jLabelRight.getDeviceName()); 536 taskScenePanelChart.getJButtonDelete().setProcessName(jLabelRight.getProcessName()); 537 taskScenePanelChart.getConfigButton().setSessionId(jLabelRight.getSessionId()); 538 taskScenePanelChart.getjButtonLeft().setSessionId(jLabelRight.getSessionId()); 539 taskScenePanelChart.getjComboBox().setSessionId(jLabelRight.getSessionId()); 540 taskScenePanelChart.getTimeJComboBox().setSessionId(jLabelRight.getSessionId()); 541 taskScenePanelChart.getJScrollCardsPanelInner().remove(jMultiplePanel); 542 taskScenePanelChart.getJScrollCardsPanelInner().repaint(); 543 } 544 545 /** 546 * clickEvery 547 * 548 * @param taskScenePanelChart taskScenePanelChart 549 * @param jLabelRight jLabelRight 550 * @param numberSum numberSum 551 * @param jLabelSelect jLabelSelect 552 * @param jMultiplePanel jMultiplePanel 553 */ clickEvery(TaskScenePanelChart taskScenePanelChart, CustomJLabel jLabelRight, int numberSum, String jLabelSelect, JPanel jMultiplePanel)554 public void clickEvery(TaskScenePanelChart taskScenePanelChart, CustomJLabel jLabelRight, int numberSum, 555 String jLabelSelect, JPanel jMultiplePanel) { 556 jLabelRight.addMouseListener(new MouseAdapter() { 557 @Override 558 public void mouseClicked(MouseEvent mouseEvent) { 559 // 绑定sessionId 560 bindSessionId(taskScenePanelChart, jLabelRight, jMultiplePanel); 561 // 获取其他jlabel设置背景色 562 Component[] component = taskScenePanelChart.getJScrollCardsPanelInner().getComponents(); 563 for (Component componentEvery : component) { 564 JPanel jPanelEvery = null; 565 if (componentEvery instanceof JPanel) { 566 jPanelEvery = (JPanel) componentEvery; 567 Component[] componentjPanelEvery = jPanelEvery.getComponents(); 568 for (Component componentjPanelEverySet : componentjPanelEvery) { 569 JLabel jLabelEvery = null; 570 if (componentjPanelEverySet instanceof JLabel) { 571 jLabelEvery = (JLabel) componentjPanelEverySet; 572 jLabelEvery.setBackground(ColorConstants.BLACK_COLOR); 573 jLabelEvery.setForeground(Color.gray); 574 } 575 } 576 } 577 } 578 taskScenePanelChart.getJScrollCardsPanelInner().add(jMultiplePanel); 579 taskScenePanelChart.getJScrollCardsPanelInner().repaint(); 580 jLabelRight.setBackground(ColorConstants.SELECTED_COLOR); 581 if (jLabelRight.getLeft() != null) { 582 jLabelRight.getLeft().setBackground(ColorConstants.SELECTED_COLOR); 583 } 584 jLabelRight.setForeground(Color.white); 585 // 循环确定擦片布局显示哪个页面 586 showCurrentView(numberSum, taskScenePanelChart); 587 taskScenePanelChart.setButtonEnable(false, ""); 588 taskScenePanelChart.setGreyFlag(false); 589 // Replace the content of the tab with the content of the clicked device information 590 replaceDevicesInfo(jLabelSelect); 591 } 592 }); 593 } 594 showCurrentView(int numberSum, TaskScenePanelChart taskScenePanelChart)595 private void showCurrentView(int numberSum, TaskScenePanelChart taskScenePanelChart) { 596 int numY = 0; 597 for (int index = 0; index < numberSum; index++) { 598 JPanel jPanel = null; 599 Object innerObj = taskScenePanelChart.getJScrollCardsPanelInner().getComponentAt(0, numY); 600 if (innerObj instanceof JPanel) { 601 jPanel = (JPanel) innerObj; 602 numY += LayoutConstants.HEIGHT; 603 Color colorBack = jPanel.getComponent(0).getBackground(); 604 if (colorBack == ColorConstants.SELECTED_COLOR) { 605 if (jPanel.getComponent(0) instanceof CustomJLabel) { 606 CustomJLabel customJLabel = (CustomJLabel) jPanel.getComponent(0); 607 if (Objects.nonNull(customJLabel.getCardName())) { 608 taskScenePanelChart.getCardLayout() 609 .show(taskScenePanelChart.getCards(), customJLabel.getCardName()); 610 } else { 611 taskScenePanelChart.getCardLayout() 612 .show(taskScenePanelChart.getCards(), "card" + index); 613 taskScenePanelChart.add(taskScenePanelChart.getPanelTop(), BorderLayout.NORTH); 614 } 615 } 616 } 617 } 618 } 619 } 620 621 /** 622 * Replace device information 623 * 624 * @param jLabelSelect Selected jLabel 625 */ replaceDevicesInfo(String jLabelSelect)626 private void replaceDevicesInfo(String jLabelSelect) { 627 JPanel jCompent = null; 628 Object tabComObj = Constant.jtasksTab.getTabComponentAt(Constant.jtasksTab.getSelectedIndex()); 629 if (tabComObj instanceof JPanel) { 630 jCompent = (JPanel) tabComObj; 631 JPanel jCompentLeft = null; 632 Object componentObj = jCompent.getComponent(0); 633 if (componentObj instanceof JPanel) { 634 jCompentLeft = (JPanel) componentObj; 635 Object leftObj = jCompentLeft.getComponent(0); 636 if (leftObj instanceof JLabel) { 637 ((JLabel) leftObj).setText(jLabelSelect); 638 } 639 } 640 } 641 } 642 643 /** 644 * 按钮增加点击时间触发时间刻度的选择 645 * 646 * @param jComboBox jComboBox 647 * @param profilerView profilerView 648 */ clickZoomEvery(CustomComboBox jComboBox, ProfilerChartsView profilerView)649 public void clickZoomEvery(CustomComboBox jComboBox, ProfilerChartsView profilerView) { 650 jComboBox.addItemListener(event -> { 651 long sessionId = jComboBox.getSessionId(); 652 int newSizeTime = 0; 653 if (event.getStateChange() == 1) { 654 // 获取点击时间选择的时间刻度间隔 655 String[] msTime = jComboBox.getSelectedItem().toString().split("m"); 656 newSizeTime = Integer.parseInt(msTime[0]); 657 } 658 ChartStandard standard = profilerView.getPublisher().getStandard(); 659 if (standard != null) { 660 checkNewTime(standard, newSizeTime, profilerView); 661 } 662 }); 663 } 664 665 /** 666 * 检查频率切换后的时间是否需要修正 667 * 668 * @param standard ChartStandard 669 * @param newSizeTime 新的时间大小 670 * @param view ProfilerChartsView 671 */ checkNewTime(ChartStandard standard, int newSizeTime, ProfilerChartsView view)672 private void checkNewTime(ChartStandard standard, int newSizeTime, ProfilerChartsView view) { 673 int oldStart = standard.getDisplayRange().getStartTime(); 674 // 获取刻度间隔对应的最小时间单位值 675 int minSize = ChartUtils.divideInt(newSizeTime, NUM_10) * NUM_2; 676 // 刷新绘图标准的最大展示时间和最小时间单位 677 int newMaxDisplay = newSizeTime * NUM_10; 678 int lastTime = (int) (standard.getLastTimestamp() - standard.getFirstTimestamp()); 679 680 int newStart; 681 int newEnd; 682 // 场景1:频率切换后oldStart + newDisplay超过了lastTime,这时要修正start 683 if (oldStart + newMaxDisplay > lastTime) { 684 newStart = Math.max(lastTime - newMaxDisplay, 0); 685 newEnd = lastTime; 686 } else { 687 // 场景2:切换后oldStart + newDisplay未超过lastTime,说明可以正常显示,无需修正start 688 newStart = oldStart; 689 newEnd = oldStart + newMaxDisplay; 690 } 691 692 view.getPublisher().msTimeZoom(newMaxDisplay, minSize, newStart, newEnd); 693 // 如果newDisplay > lastTime,这时候要隐藏滚动条 694 if (newMaxDisplay > lastTime) { 695 view.removeScrollbar(); 696 view.revalidate(); 697 } else { 698 if (view.getHorizontalBar() == null) { 699 view.initScrollbar(); 700 } 701 view.getHorizontalBar().resizeAndReposition(); 702 } 703 } 704 705 /** 706 * showSuspension 707 * 708 * @param taskScenePanelChart taskScenePanelChart 709 * @param jTaskPanel jTaskPanel 710 * @param jButtonSuspen jButtonSuspen 711 */ showSuspension(TaskScenePanelChart taskScenePanelChart, TaskPanel jTaskPanel, JButton jButtonSuspen)712 public void showSuspension(TaskScenePanelChart taskScenePanelChart, TaskPanel jTaskPanel, JButton jButtonSuspen) { 713 jButtonSuspen.addActionListener(new ActionListener() { 714 /** 715 * actionPerformed 716 * 717 * @param exception exception 718 */ 719 @Override 720 public void actionPerformed(ActionEvent exception) { 721 if (!flag) { 722 taskScenePanelChart.getjPanelSuspension().setBackground(Color.RED); 723 taskScenePanelChart.getjPanelSuspension().setBounds( 724 LayoutConstants.WINDOW_HEIGHT + (jTaskPanel.getWidth() - LayoutConstants.WINDOW_WIDTH), 725 LayoutConstants.DEVICES_WIDTH + (jTaskPanel.getHeight() - LayoutConstants.WINDOW_HEIGHT), 726 LayoutConstants.WIDTHSUPEN, LayoutConstants.DEVICE_PRO_WIDTH); 727 jTaskPanel.add(taskScenePanelChart.getjPanelSuspension(), JLayeredPane.DRAG_LAYER); 728 flag = true; 729 jTaskPanel.repaint(); 730 } else { 731 jTaskPanel.remove(taskScenePanelChart.getjPanelSuspension()); 732 flag = false; 733 jTaskPanel.repaint(); 734 } 735 } 736 }); 737 } 738 739 /** 740 * setSceneSize 741 * 742 * @param jTaskPanel jTaskPanel 743 * @param taskScenePanelChart taskScenePanelChart 744 */ setSceneSize(TaskPanel jTaskPanel, TaskScenePanelChart taskScenePanelChart)745 public void setSceneSize(TaskPanel jTaskPanel, TaskScenePanelChart taskScenePanelChart) { 746 jTaskPanel.addComponentListener(new ComponentAdapter() { 747 /** 748 * componentResized 749 * 750 * @param event event 751 */ 752 public void componentResized(ComponentEvent event) { 753 int width = jTaskPanel.getWidth(); 754 int height = jTaskPanel.getHeight(); 755 taskScenePanelChart.getjPanelSuspension() 756 .setBounds(LayoutConstants.WINDOW_HEIGHT + (width - LayoutConstants.WINDOW_WIDTH), 757 LayoutConstants.DEVICES_WIDTH + (height - LayoutConstants.WINDOW_HEIGHT), 758 LayoutConstants.WIDTHSUPEN, LayoutConstants.DEVICE_PRO_WIDTH); 759 } 760 }); 761 } 762 763 /** 764 * Memory新增配置项 765 * 766 * @param taskScenePanelChart taskScenePanelChart 767 * @param profilerView profilerView 768 */ clickConfig(TaskScenePanelChart taskScenePanelChart, ProfilerChartsView profilerView)769 public void clickConfig(TaskScenePanelChart taskScenePanelChart, ProfilerChartsView profilerView) { 770 obj = taskScenePanelChart; 771 } 772 773 /** 774 * click Performance analysis index configuration 775 * 776 * @param configButton configButton 777 * @param itemMenu itemMenu 778 */ clickIndexConfig(CustomJButton configButton, PerformanceIndexPopupMenu itemMenu)779 public void clickIndexConfig(CustomJButton configButton, PerformanceIndexPopupMenu itemMenu) { 780 configButton.addMouseListener(new MouseAdapter() { 781 @Override 782 public void mouseClicked(MouseEvent mouseEvent) { 783 itemMenu.showItemMenu(mouseEvent); 784 } 785 }); 786 } 787 788 /** 789 * click save 790 * 791 * @param jButton jButton 792 * @param taskScenePanelChart taskScenePanelChart 793 */ clickSave(CustomJButton jButton, TaskScenePanelChart taskScenePanelChart)794 public void clickSave(CustomJButton jButton, TaskScenePanelChart taskScenePanelChart) { 795 jButton.addActionListener(new ActionListener() { 796 /** 797 * actionPerformed 798 * 799 * @param event event 800 */ 801 @Override 802 public void actionPerformed(ActionEvent event) { 803 if (taskScenePanelChart.isGreyFlag()) { 804 return; 805 } 806 if (jButton.getSessionId() == 0) { 807 new SampleDialog("prompt", "Please select a process record !").show(); 808 return; 809 } 810 ExportFileChooserDialog fileChooserDialogWrapper = 811 new ExportFileChooserDialog("Export As", UtConstant.FILE_TYPE_TRACE); 812 boolean showAndGet = fileChooserDialogWrapper.showAndGet(); 813 if (showAndGet) { 814 fileChooserDialogWrapper.saveDataToFile(jButton); 815 } 816 } 817 }); 818 } 819 clearTimeCounting(TaskScenePanelChart taskScenePanelChart)820 private void clearTimeCounting(TaskScenePanelChart taskScenePanelChart) { 821 JLabel jTextArea = taskScenePanelChart.getjTextArea(); 822 while (taskScenePanelChart.getCounting().isAlive()) { 823 SwingUtilities.invokeLater(new Runnable() { 824 /** 825 * run 826 */ 827 public void run() { 828 jTextArea.setText("Run 1 of 1 | 00:00:00"); 829 } 830 }); 831 } 832 SwingUtilities.invokeLater(new Runnable() { 833 /** 834 * run 835 */ 836 public void run() { 837 jTextArea.setText("Run 1 of 1 | 00:00:00"); 838 } 839 }); 840 } 841 } 842