• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     https://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package traceviewer.ui.tracks
18 
19 import traceviewer.ui.ThemeColors
20 import traceviewer.ui.RenderState
21 import trebuchet.model.ThreadModel
22 import trebuchet.model.base.SliceGroup
23 import javax.swing.BorderFactory
24 import javax.swing.BoxLayout
25 import javax.swing.JPanel
26 
27 class MultiLineTrack(thread: ThreadModel, renderState: RenderState) : JPanel() {
28     init {
29         isOpaque = true
30         layout = BoxLayout(this, BoxLayout.PAGE_AXIS)
31         border = BorderFactory.createEmptyBorder(4, 0, 0, 0)
32         background = ThemeColors.SliceTrackBackground
33         if (thread.schedSlices.isNotEmpty()) {
34             add(SchedTrack(thread.schedSlices, renderState))
35         }
36         val rows = RowCreater(thread.slices).rows
<lambda>null37         rows.forEach {
38             add(SliceTrack(it, renderState))
39         }
40     }
41 
42     class RowCreater constructor(slices: List<SliceGroup>) {
43         val rows = mutableListOf<MutableList<SliceGroup>>()
44         var index = -1
45 
46         init {
47             push()
<lambda>null48             slices.forEach { addSlice(it) }
49         }
50 
51         val row: MutableList<SliceGroup> get() = rows[index]
52 
pushnull53         fun push() {
54             index++
55             while (index >= rows.size) rows.add(mutableListOf())
56         }
57 
popnull58         fun pop() {
59             index--
60         }
61 
addSlicenull62         fun addSlice(slice: SliceGroup) {
63             row.add(slice)
64             if (slice.children.isNotEmpty()) {
65                 push()
66                 slice.children.forEach { addSlice(it) }
67                 pop()
68             }
69         }
70     }
71 }