• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.trace.bean;
17 
18 import com.intellij.ui.JBColor;
19 import ohos.devtools.views.trace.DField;
20 import ohos.devtools.views.trace.component.AnalystPanel;
21 import ohos.devtools.views.trace.fragment.graph.AbstractGraph;
22 import ohos.devtools.views.trace.util.ColorUtils;
23 import ohos.devtools.views.trace.util.Utils;
24 
25 import java.awt.Color;
26 import java.awt.Graphics2D;
27 import java.awt.Rectangle;
28 import java.awt.RenderingHints;
29 import java.awt.event.MouseEvent;
30 import java.util.Locale;
31 
32 /**
33  * Method entity class
34  *
35  * @since 2021/04/22 12:25
36  */
37 public class FunctionBean extends AbstractGraph {
38     @DField(name = "tid")
39     private Integer tid;
40 
41     @DField(name = "threadName")
42     private String threadName;
43 
44     @DField(name = "is_main_thread")
45     private Integer isMainThread;
46 
47     @DField(name = "track_id")
48     private Integer trackId;
49 
50     @DField(name = "startTs")
51     private Long startTime;
52 
53     @DField(name = "dur")
54     private Long duration;
55 
56     @DField(name = "funName")
57     private String funName;
58 
59     @DField(name = "depth")
60     private Integer depth;
61 
62     @DField(name = "argsetid")
63     private Integer argSetId;
64 
65     private String category;
66 
67     private boolean isSelected; // Whether to be selected
68     private IEventListener eventListener;
69 
70     /**
71      * Gets the value of argSetId .
72      *
73      * @return the value of int
74      */
getArgSetId()75     public Integer getArgSetId() {
76         return argSetId;
77     }
78 
79     /**
80      * Sets the argSetId .You can use getArgSetId() to get the value of argSetId
81      *
82      * @param argSetId argSetId
83      */
setArgSetId(Integer argSetId)84     public void setArgSetId(Integer argSetId) {
85         this.argSetId = argSetId;
86     }
87 
88     /**
89      * Gets the value of tid .
90      *
91      * @return the value of int
92      */
getTid()93     public Integer getTid() {
94         return tid;
95     }
96 
97     /**
98      * Sets the tid .You can use getTid() to get the value of tid
99      *
100      * @param pTid pTid
101      */
setTid(final Integer pTid)102     public void setTid(final Integer pTid) {
103         this.tid = pTid;
104     }
105 
106     /**
107      * Gets the value of threadName .
108      *
109      * @return the value of java.lang.String
110      */
getThreadName()111     public String getThreadName() {
112         return threadName;
113     }
114 
115     /**
116      * Sets the threadName .You can use getThreadName() to get the value of threadName
117      *
118      * @param name name
119      */
setThreadName(final String name)120     public void setThreadName(final String name) {
121         this.threadName = name;
122     }
123 
124     /**
125      * Gets the value of isMainThread .
126      *
127      * @return the value of int
128      */
getIsMainThread()129     public Integer getIsMainThread() {
130         return isMainThread;
131     }
132 
133     /**
134      * Sets the isMainThread .You can use getIsMainThread() to get the value of isMainThread
135      *
136      * @param mainThread mainThread
137      */
setIsMainThread(final Integer mainThread)138     public void setIsMainThread(final Integer mainThread) {
139         this.isMainThread = mainThread;
140     }
141 
142     /**
143      * Gets the value of trackId .
144      *
145      * @return the value of int
146      */
getTrackId()147     public Integer getTrackId() {
148         return trackId;
149     }
150 
151     /**
152      * Sets the trackId .You can use getTrackId() to get the value of trackId
153      *
154      * @param id id
155      */
setTrackId(final Integer id)156     public void setTrackId(final Integer id) {
157         this.trackId = id;
158     }
159 
160     /**
161      * Gets the value of startTime .
162      *
163      * @return the value of long
164      */
getStartTime()165     public Long getStartTime() {
166         return startTime;
167     }
168 
169     /**
170      * Sets the startTime .You can use getStartTime() to get the value of startTime
171      *
172      * @param time time
173      */
setStartTime(final Long time)174     public void setStartTime(final Long time) {
175         this.startTime = time;
176     }
177 
178     /**
179      * Gets the value of duration .
180      *
181      * @return the value of long
182      */
getDuration()183     public Long getDuration() {
184         return duration;
185     }
186 
187     /**
188      * Sets the duration .
189      * <p>You can use getDuration() to get the value of duration</p>
190      *
191      * @param dur dur
192      */
setDuration(final Long dur)193     public void setDuration(final Long dur) {
194         this.duration = dur;
195     }
196 
197     /**
198      * Gets the value of funName .
199      *
200      * @return the value of java.lang.String
201      */
getFunName()202     public String getFunName() {
203         return funName;
204     }
205 
206     /**
207      * Sets the funName .
208      * <p>You can use getFunName() to get the value of funName</p>
209      *
210      * @param name name
211      */
setFunName(final String name)212     public void setFunName(final String name) {
213         this.funName = name;
214     }
215 
216     /**
217      * Gets the value of depth .
218      *
219      * @return the value of int
220      */
getDepth()221     public Integer getDepth() {
222         return depth;
223     }
224 
225     /**
226      * Sets the depth .
227      * <p>You can use getDepth() to get the value of depth</p>
228      *
229      * @param dep dep
230      */
setDepth(final Integer dep)231     public void setDepth(final Integer dep) {
232         this.depth = dep;
233     }
234 
235     /**
236      * Gets the value of category .
237      *
238      * @return the value of java.lang.String
239      */
getCategory()240     public String getCategory() {
241         return category;
242     }
243 
244     /**
245      * Sets the category .
246      * <p>You can use getCategory() to get the value of category</p>
247      *
248      * @param cate cate
249      */
setCategory(final String cate)250     public void setCategory(final String cate) {
251         this.category = cate;
252     }
253 
254     /**
255      * Gets the value of isSelected .
256      *
257      * @return the value of boolean
258      */
isSelected()259     public boolean isSelected() {
260         return isSelected;
261     }
262 
263     /**
264      * Sets the isSelected .
265      * <p>You can use getSelected() to get the value of isSelected</p>
266      *
267      * @param selected selected
268      */
setSelected(final boolean selected)269     public void setSelected(final boolean selected) {
270         this.isSelected = selected;
271     }
272 
273     /**
274      * Draw the corresponding shape according to the brush
275      *
276      * @param graphics graphics
277      */
278     @Override
draw(final Graphics2D graphics)279     public void draw(final Graphics2D graphics) {
280         if ((duration == null || duration == 0)) {
281             if (isBinder()) {
282                 int pointX = Utils.getX(rect);
283                 int pointY = Utils.getY(rect);
284                 graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
285                 graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
286                 final int[] xArray;
287                 final int[] yArray;
288                 if (isSelected) {
289                     xArray = new int[] {pointX, pointX + 8, pointX, pointX - 8};
290                     yArray = new int[] {pointY - 2, pointY - 2 + 24, pointY - 2 + 16, pointY - 2 + 24};
291                     graphics.setColor(JBColor.foreground().brighter());
292                 } else {
293                     xArray = new int[] {pointX, pointX + 6, pointX, pointX - 6};
294                     yArray = new int[] {pointY, pointY + 20, pointY + 14, pointY + 20};
295                     graphics.setColor(JBColor.foreground().darker());
296                 }
297                 graphics.fillPolygon(xArray, yArray, xArray.length);
298                 rect.width = 8;
299             }
300         } else {
301             if (isSelected) {
302                 graphics.setColor(Color.black);
303                 graphics.fillRect(Utils.getX(rect), Utils.getY(rect), rect.width, rect.height);
304                 graphics.setColor(ColorUtils.FUNC_COLOR[depth % ColorUtils.FUNC_COLOR.length]);
305                 graphics.fillRect(Utils.getX(rect) + 1, Utils.getY(rect) + 1, rect.width - 2, rect.height - 2);
306                 graphics.setColor(Color.white);
307                 Rectangle rectangle = new Rectangle();
308                 rectangle.setRect(rect.getX() + 1, rect.getY() + 1, rect.getWidth() - 2, rect.getHeight() - 2);
309                 drawString(graphics, rectangle, funName, Placement.CENTER_LINE);
310             } else {
311                 graphics.setColor(ColorUtils.FUNC_COLOR[depth % ColorUtils.FUNC_COLOR.length]);
312                 graphics.fillRect(Utils.getX(rect), Utils.getY(rect), rect.width, rect.height);
313                 graphics.setColor(Color.white);
314                 drawString(graphics, rect, funName, Placement.CENTER_LINE);
315             }
316         }
317     }
318 
319     /**
320      * is binder
321      *
322      * @return the value of boolean
323      */
isBinder()324     public boolean isBinder() {
325         if (funName != null && (funName.toLowerCase(Locale.ENGLISH).startsWith("binder transaction") || funName
326             .toLowerCase(Locale.ENGLISH).startsWith("binder async"))) {
327             return true;
328         } else {
329             return false;
330         }
331     }
332 
333     /**
334      * Focus acquisition event
335      *
336      * @param event event
337      */
338     @Override
onFocus(final MouseEvent event)339     public void onFocus(final MouseEvent event) {
340         if (eventListener != null) {
341             eventListener.focus(event, this);
342         }
343     }
344 
345     /**
346      * Focus cancel event
347      *
348      * @param event event
349      */
350     @Override
onBlur(final MouseEvent event)351     public void onBlur(final MouseEvent event) {
352         if (eventListener != null) {
353             eventListener.blur(event, this);
354         }
355     }
356 
357     /**
358      * Click event
359      *
360      * @param event event
361      */
362     @Override
onClick(final MouseEvent event)363     public void onClick(final MouseEvent event) {
364         if (eventListener != null) {
365             AnalystPanel.clicked = true;
366             eventListener.click(event, this);
367         }
368     }
369 
370     /**
371      * Mouse movement event
372      *
373      * @param event event
374      */
375     @Override
onMouseMove(final MouseEvent event)376     public void onMouseMove(final MouseEvent event) {
377         if (edgeInspect(event)) {
378             if (eventListener != null) {
379                 eventListener.mouseMove(event, this);
380             }
381         }
382     }
383 
384     /**
385      * Set up the event listener
386      *
387      * @param listener listener
388      */
setEventListener(final IEventListener listener)389     public void setEventListener(final IEventListener listener) {
390         this.eventListener = listener;
391     }
392 
393     /**
394      * listener
395      */
396     public interface IEventListener {
397         /**
398          * Click event
399          *
400          * @param event event
401          * @param data data
402          */
click(MouseEvent event, FunctionBean data)403         void click(MouseEvent event, FunctionBean data);
404 
405         /**
406          * Focus cancel event
407          *
408          * @param event event
409          * @param data data
410          */
blur(MouseEvent event, FunctionBean data)411         void blur(MouseEvent event, FunctionBean data);
412 
413         /**
414          * Focus acquisition event
415          *
416          * @param event event
417          * @param data data
418          */
focus(MouseEvent event, FunctionBean data)419         void focus(MouseEvent event, FunctionBean data);
420 
421         /**
422          * Mouse movement event
423          *
424          * @param event event
425          * @param data data
426          */
mouseMove(MouseEvent event, FunctionBean data)427         void mouseMove(MouseEvent event, FunctionBean data);
428     }
429 }
430