• 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 ohos.devtools.views.trace.DField;
19 import ohos.devtools.views.trace.fragment.graph.AbstractGraph;
20 import ohos.devtools.views.trace.util.ColorUtils;
21 import ohos.devtools.views.trace.util.Utils;
22 
23 import java.awt.Color;
24 import java.awt.Graphics2D;
25 import java.awt.Rectangle;
26 import java.awt.event.MouseEvent;
27 
28 /**
29  * AsyncEvent
30  *
31  * @since 2021/6/29 10:55
32  */
33 public class AsyncEvent extends AbstractGraph {
34     @DField(name = "id")
35     private Integer id;
36     @DField(name = "startTime")
37     private Long startTime;
38     @DField(name = "dur")
39     private Long duration;
40     @DField(name = "pid")
41     private Integer pid;
42     @DField(name = "name")
43     private String name;
44     @DField(name = "cookie")
45     private Integer cookie;
46     @DField(name = "depth")
47     private Integer depth;
48     private IEventListener eventListener;
49 
50     /**
51      * Gets the value of depth .
52      *
53      * @return the value of java.lang.Integer
54      */
getDepth()55     public Integer getDepth() {
56         return depth;
57     }
58 
59     /**
60      * Sets the depth .
61      * <p>You can use getDepth() to get the value of depth</p>
62      *
63      * @param depth depth
64      */
setDepth(Integer depth)65     public void setDepth(Integer depth) {
66         this.depth = depth;
67     }
68 
69     /**
70      * Gets the value of cookie .
71      *
72      * @return the value of java.lang.Integer
73      */
getCookie()74     public Integer getCookie() {
75         return cookie;
76     }
77 
78     /**
79      * Sets the cookie .
80      * <p>You can use getCookie() to get the value of cookie</p>
81      *
82      * @param cookie cookie
83      */
setCookie(Integer cookie)84     public void setCookie(Integer cookie) {
85         this.cookie = cookie;
86     }
87 
88     /**
89      * Gets the value of id .
90      *
91      * @return the value of java.lang.Integer
92      */
getId()93     public Integer getId() {
94         return id;
95     }
96 
97     /**
98      * Sets the id .
99      * <p>You can use getId() to get the value of id</p>
100      *
101      * @param id id
102      */
setId(Integer id)103     public void setId(Integer id) {
104         this.id = id;
105     }
106 
107     /**
108      * Gets the value of startTime .
109      *
110      * @return the value of java.lang.Long
111      */
getStartTime()112     public Long getStartTime() {
113         return startTime;
114     }
115 
116     /**
117      * Sets the startTime .
118      * <p>You can use getStartTime() to get the value of startTime</p>
119      *
120      * @param startTime startTime
121      */
setStartTime(Long startTime)122     public void setStartTime(Long startTime) {
123         this.startTime = startTime;
124     }
125 
126     /**
127      * Gets the value of duration .
128      *
129      * @return the value of java.lang.Long
130      */
getDuration()131     public Long getDuration() {
132         return duration;
133     }
134 
135     /**
136      * Sets the duration .
137      * <p>You can use getDuration() to get the value of duration</p>
138      *
139      * @param duration duration
140      */
setDuration(Long duration)141     public void setDuration(Long duration) {
142         this.duration = duration;
143     }
144 
145     /**
146      * Gets the value of pid .
147      *
148      * @return the value of java.lang.Integer
149      */
getPid()150     public Integer getPid() {
151         return pid;
152     }
153 
154     /**
155      * Sets the pid .
156      * <p>You can use getPid() to get the value of pid</p>
157      *
158      * @param pid pid
159      */
setPid(Integer pid)160     public void setPid(Integer pid) {
161         this.pid = pid;
162     }
163 
164     /**
165      * Gets the value of name .
166      *
167      * @return the value of java.lang.String
168      */
getName()169     public String getName() {
170         return name;
171     }
172 
173     /**
174      * Sets the name .
175      * <p>You can use getName() to get the value of name</p>
176      *
177      * @param name name
178      */
setName(String name)179     public void setName(String name) {
180         this.name = name;
181     }
182 
183     @Override
draw(Graphics2D graphics)184     public void draw(Graphics2D graphics) {
185         graphics.setColor(ColorUtils.colorForTid(pid));
186         Rectangle rectangle = new Rectangle(Utils.getX(rect), Utils.getY(rect), rect.width, rect.height);
187         graphics.fillRect(Utils.getX(rectangle), Utils.getY(rectangle), rectangle.width, rectangle.height);
188         graphics.setColor(Color.WHITE);
189         drawString(graphics, rectangle, name, Placement.CENTER_LINE);
190     }
191 
192     @Override
onFocus(MouseEvent event)193     public void onFocus(MouseEvent event) {
194     }
195 
196     @Override
onBlur(MouseEvent event)197     public void onBlur(MouseEvent event) {
198     }
199 
200     @Override
onClick(MouseEvent event)201     public void onClick(MouseEvent event) {
202         if (this.eventListener != null) {
203             eventListener.click(event, this);
204         }
205     }
206 
207     @Override
onMouseMove(MouseEvent event)208     public void onMouseMove(MouseEvent event) {
209     }
210 
211     /**
212      * Set up the event listener
213      *
214      * @param listener listener
215      */
setEventListener(final IEventListener listener)216     public void setEventListener(final IEventListener listener) {
217         this.eventListener = listener;
218     }
219 
220     /**
221      * listener
222      */
223     public interface IEventListener {
224         /**
225          * Click event
226          *
227          * @param event event
228          * @param data data
229          */
click(MouseEvent event, AsyncEvent data)230         void click(MouseEvent event, AsyncEvent data);
231 
232         /**
233          * Focus cancel event
234          *
235          * @param event event
236          * @param data data
237          */
blur(MouseEvent event, AsyncEvent data)238         void blur(MouseEvent event, AsyncEvent data);
239 
240         /**
241          * Focus acquisition event
242          *
243          * @param event event
244          * @param data data
245          */
focus(MouseEvent event, AsyncEvent data)246         void focus(MouseEvent event, AsyncEvent data);
247 
248         /**
249          * Mouse movement event
250          *
251          * @param event event
252          * @param data data
253          */
mouseMove(MouseEvent event, AsyncEvent data)254         void mouseMove(MouseEvent event, AsyncEvent data);
255     }
256 }
257