• 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.layout.dialog;
17 
18 import com.intellij.openapi.ui.DialogWrapper;
19 import com.intellij.ui.components.JBLabel;
20 import ohos.devtools.views.common.LayoutConstants;
21 import org.apache.logging.log4j.LogManager;
22 import org.apache.logging.log4j.Logger;
23 
24 import javax.annotation.Nullable;
25 import javax.swing.JButton;
26 import javax.swing.JComponent;
27 import javax.swing.JLabel;
28 import javax.swing.JPanel;
29 import javax.swing.Timer;
30 import java.awt.BorderLayout;
31 import java.awt.event.ActionEvent;
32 import java.util.Locale;
33 
34 /**
35  * SystemTuningDialog
36  *
37  * @since 2021/11/22
38  */
39 public class TraceLoadDialog extends DialogWrapper {
40     private static final Logger LOGGER = LogManager.getLogger(TraceLoadDialog.class);
41     private static final int MINUTE_TO_S = 60;
42 
43     private JPanel filePanel;
44     private JBLabel timeJLabel;
45     private Timer timer;
46 
47     private int maxDurationParam = 0;
48     private int hours = 0;
49     private int minutes = 0;
50     private int seconds = 0;
51 
52     /**
53      * SystemTunningDialogEvent
54      *
55      * @param filePanel filePanel
56      * @param timeJLabel timeJLabel
57      * @param maxDurationParam maxDurationParam
58      */
TraceLoadDialog(JPanel filePanel, JBLabel timeJLabel, int maxDurationParam)59     public TraceLoadDialog(JPanel filePanel, JBLabel timeJLabel, int maxDurationParam) {
60         super(true);
61         this.filePanel = filePanel;
62         this.timeJLabel = timeJLabel;
63         this.maxDurationParam = maxDurationParam;
64         init();
65         setTitle("Prompt");
66         setResizable(false);
67     }
68 
69     /**
70      * get timer
71      *
72      * @return Timer
73      */
getTimer()74     public Timer getTimer() {
75         return this.timer;
76     }
77 
78     /**
79      * createCenterPanel
80      *
81      * @return JComponent
82      */
83     @Nullable
84     @Override
createCenterPanel()85     protected JComponent createCenterPanel() {
86         this.offLineTrace();
87         JPanel dialogPanel = new JPanel(new BorderLayout());
88         if (filePanel != null) {
89             dialogPanel.add(filePanel, BorderLayout.CENTER);
90         }
91         return dialogPanel;
92     }
93 
94     @Nullable
95     @Override
createSouthPanel()96     protected JComponent createSouthPanel() {
97         return new JPanel(new BorderLayout());
98     }
99 
100     /**
101      * offLineTrace
102      */
offLineTrace()103     public void offLineTrace() {
104         timer = new Timer(LayoutConstants.NUMBER_THREAD, this::actionPerformed);
105         timer.start();
106     }
107 
108     /**
109      * actionPerformed
110      *
111      * @param actionEvent actionEvent
112      */
actionPerformed(ActionEvent actionEvent)113     public void actionPerformed(ActionEvent actionEvent) {
114         if ((hours * MINUTE_TO_S * MINUTE_TO_S + minutes * MINUTE_TO_S + seconds) > maxDurationParam) {
115             timer.stop();
116             this.doOKAction();
117         }
118         if (seconds <= LayoutConstants.NUMBER_SECONDS) {
119             timeJLabel.setText(" " + String.format(Locale.ENGLISH, "%02d", hours) + ":" + String
120                 .format(Locale.ENGLISH, "%02d", minutes) + ":" + String.format(Locale.ENGLISH, "%02d", seconds));
121             seconds++;
122             if (seconds > LayoutConstants.NUMBER_SECONDS) {
123                 seconds = 0;
124                 minutes++;
125                 if (minutes > LayoutConstants.NUMBER_SECONDS) {
126                     minutes = 0;
127                     hours++;
128                 }
129             }
130         }
131     }
132 
133     /**
134      * set Label Attribute
135      *
136      * @param statusJLabelParam statusJLabelParam
137      * @param durationJLabelParam durationJLabelParam
138      * @param recordingJLabelParam recordingJLabelParam
139      * @param timeJLabelParam timeJLabelParam
140      * @param stopJButton stopJButton
141      */
setLableAttribute(JLabel statusJLabelParam, JLabel durationJLabelParam, JLabel recordingJLabelParam, JLabel timeJLabelParam, JButton stopJButton)142     public void setLableAttribute(JLabel statusJLabelParam, JLabel durationJLabelParam, JLabel recordingJLabelParam,
143         JLabel timeJLabelParam, JButton stopJButton) {
144         statusJLabelParam.setBounds(90, 30, 70, 20);
145         recordingJLabelParam.setBounds(160, 30, 70, 20);
146         durationJLabelParam.setBounds(90, 60, 70, 20);
147         timeJLabelParam.setBounds(160, 60, 70, 20);
148         if (stopJButton != null) {
149             stopJButton.setBounds(120, 110, 70, 20);
150         }
151     }
152 }
153