• 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.component;
17 
18 import com.intellij.ui.components.JBBox;
19 import com.intellij.ui.components.JBPanel;
20 import com.intellij.ui.components.JBScrollPane;
21 
22 import java.awt.Cursor;
23 import java.awt.Dimension;
24 import java.awt.event.MouseAdapter;
25 import java.awt.event.MouseEvent;
26 
27 /**
28  * Bottom scroll component
29  *
30  * @since 2021/04/20 12:24
31  */
32 public class BottomScrollPanel extends JBScrollPane {
33     /**
34      * box container
35      */
36     protected JBBox box = JBBox.createHorizontalBox();
37 
38     /**
39      * Constructor
40      */
BottomScrollPanel()41     public BottomScrollPanel() {
42         setBorder(null);
43         setViewportView(box);
44         addMouseListener(new MouseAdapter() {
45             @Override
46             public void mouseEntered(final MouseEvent event) {
47                 super.mouseEntered(event);
48                 setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
49             }
50         });
51     }
52 
53     /**
54      * ChildPanel
55      *
56      * @since 2021/04/20 12:24
57      */
58     public static class ChildPanel extends JBPanel {
59         /**
60          * line height
61          */
62         protected int lineHeight;
63 
64         /**
65          * line width
66          */
67         protected int lineWidth;
68 
69         /**
70          * construct with line width and line height
71          *
72          * @param lineWidth line width
73          * @param lineHeight line height
74          */
ChildPanel(final int lineWidth, final int lineHeight)75         public ChildPanel(final int lineWidth, final int lineHeight) {
76             this.lineHeight = lineHeight;
77             this.lineWidth = lineWidth;
78         }
79 
80         @Override
getMinimumSize()81         public Dimension getMinimumSize() {
82             Dimension dimension = super.getMinimumSize();
83             if (this.lineWidth != 0) {
84                 dimension.width = lineWidth;
85             }
86             dimension.height = lineHeight;
87             return dimension;
88         }
89 
90         @Override
getPreferredSize()91         public Dimension getPreferredSize() {
92             Dimension dimension = super.getPreferredSize();
93             if (this.lineWidth != 0) {
94                 dimension.width = lineWidth;
95             }
96             dimension.height = lineHeight;
97             return dimension;
98         }
99 
100         @Override
getMaximumSize()101         public Dimension getMaximumSize() {
102             Dimension dimension = super.getMaximumSize();
103             if (this.lineWidth != 0) {
104                 dimension.width = lineWidth;
105             }
106             dimension.height = lineHeight;
107             return dimension;
108         }
109     }
110 
111     /**
112      * ChildLineComponent
113      *
114      * @since 2021/04/20 12:24
115      */
116     public static class ChildLineComponent extends ChildPanel {
117         private static final int DEFAULT_LINE_HEIGHT = 27;
118 
119         /**
120          * Monitor whether the mouse is moved into the component
121          */
122         public boolean mouseIn;
123 
124         /**
125          * Constructor
126          */
ChildLineComponent()127         public ChildLineComponent() {
128             super(0, DEFAULT_LINE_HEIGHT);
129             addMouseListener(new MouseAdapter() {
130                 @Override
131                 public void mouseEntered(final MouseEvent event) {
132                     childMouseEntered(event);
133                 }
134 
135                 @Override
136                 public void mouseExited(final MouseEvent event) {
137                     childMouseExited(event);
138                 }
139 
140                 @Override
141                 public void mouseClicked(final MouseEvent event) {
142                     childMouseClicked(event);
143                 }
144             });
145         }
146 
147         /**
148          * Custom mouse events
149          *
150          * @param event mouse event
151          */
childMouseEntered(final MouseEvent event)152         public void childMouseEntered(final MouseEvent event) {
153             setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
154             mouseIn = true;
155             repaint();
156         }
157 
158         /**
159          * Custom mouse events
160          *
161          * @param event mouse event
162          */
childMouseExited(final MouseEvent event)163         public void childMouseExited(final MouseEvent event) {
164             mouseIn = false;
165             repaint();
166         }
167 
168         /**
169          * Custom mouse events
170          *
171          * @param event mouse event
172          */
childMouseClicked(final MouseEvent event)173         public void childMouseClicked(final MouseEvent event) {
174             event.getX();
175         }
176     }
177 }
178