• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 The Android Open Source Project
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  *      http://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 package com.android.atest.dialog;
17 
18 import com.android.atest.Constants;
19 import com.intellij.openapi.project.Project;
20 import com.intellij.openapi.ui.DialogWrapper;
21 import org.jetbrains.annotations.NotNull;
22 import org.jetbrains.annotations.Nullable;
23 
24 import javax.swing.*;
25 
26 /** The UI of a modal dialog box which shows the summary after Atest execution finishes. */
27 public class MessageDialog extends DialogWrapper {
28 
29     private JPanel mDialogPanel;
30     private JTextPane mTestResult;
31     private JScrollPane mScrollPane;
32 
33     /**
34      * Creates modal {@code DialogWrapper} that can be parent for other windows. The current active
35      * window will be the dialog's parent.
36      *
37      * @param project parent window for the dialog will be calculated based on the focused window
38      *     for the specified {@code project}. This parameter can be {@code null}. In this case
39      *     parent window will be suggested based on the current focused window.
40      * @throws IllegalStateException if the dialog is invoked not on the event dispatch thread.
41      * @see DialogWrapper#DialogWrapper(Project, boolean)
42      */
MessageDialog(@ullable Project project)43     public MessageDialog(@Nullable Project project) {
44         super(project);
45         init();
46         setTitle(Constants.ATEST_NAME);
47     }
48 
49     /**
50      * Sets the message in the dialog.
51      *
52      * @param message the message to be shown.
53      */
setMessage(String message)54     public void setMessage(String message) {
55         mTestResult.setText(message);
56     }
57 
58     /**
59      * Overrides createActions to only show OK button.
60      *
61      * @return dialog actions.
62      */
63     @NotNull
64     @Override
createActions()65     protected Action[] createActions() {
66         return new Action[] {getOKAction()};
67     }
68 
69     /**
70      * Creates panel with dialog options. Options panel is located at the center of the dialog's
71      * content pane. The implementation can return {@code null} value. In this case there will be no
72      * options panel.
73      *
74      * @return center panel.
75      */
76     @Nullable
77     @Override
createCenterPanel()78     protected JComponent createCenterPanel() {
79         return mDialogPanel;
80     }
81 
82     /**
83      * Shows a dialog with the message.
84      *
85      * @param message the message to be shown.
86      */
showMessageDialog(String message)87     public static void showMessageDialog(String message) {
88         MessageDialog dialog = new MessageDialog(null);
89         dialog.setMessage(message);
90         dialog.show();
91     }
92 }
93