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; 17 18 import com.intellij.openapi.util.IconLoader; 19 import com.intellij.ui.JBColor; 20 import com.intellij.ui.components.JBLabel; 21 import com.intellij.ui.components.JBPanel; 22 import com.intellij.ui.components.JBTabbedPane; 23 import net.miginfocom.swing.MigLayout; 24 import ohos.devtools.datasources.utils.profilerlog.ProfilerLogManager; 25 import ohos.devtools.views.common.Constant; 26 import ohos.devtools.views.common.UtConstant; 27 import org.apache.logging.log4j.LogManager; 28 import org.apache.logging.log4j.Logger; 29 30 import javax.swing.SwingConstants; 31 import java.awt.Font; 32 import java.awt.event.MouseEvent; 33 import java.awt.event.MouseListener; 34 35 /** 36 * WelcomePanel class 37 * 38 * @since 2021/10/25 39 */ 40 public class WelcomePanel extends JBPanel implements MouseListener { 41 private static final Logger LOGGER = LogManager.getLogger(WelcomePanel.class); 42 private static final String NEW_BUTTON_STR = " + New Task"; 43 private static final String WELCOME_TITLE_STR = "Welcome HosProfiler"; 44 private static final String WELCOME_TIP_STR = "Click New Task Button to process or load a capture"; 45 46 private JBLabel newTaskBtn; 47 private JBPanel newTaskBgPanel; 48 private JBLabel picImg; 49 private JBLabel welcomeTitleLabel; 50 private JBLabel welcomeTipLabel; 51 52 /** 53 * WelcomePanel 54 */ WelcomePanel()55 public WelcomePanel() { 56 initComponents(); 57 } 58 59 /** 60 * initComponents 61 */ initComponents()62 private void initComponents() { 63 if (ProfilerLogManager.isInfoEnabled()) { 64 LOGGER.info("initComponents"); 65 } 66 setLayout(new MigLayout("inset 0", "[grow,fill]", "[fill,fill]push[]push")); 67 // init newTaskBtn 68 newTaskBtn = new JBLabel(NEW_BUTTON_STR, JBLabel.CENTER); 69 newTaskBtn.setOpaque(true); 70 newTaskBtn.setBackground(JBColor.background().darker()); 71 newTaskBtn.setBounds(20, 6, 117, 20); 72 newTaskBtn.setName(UtConstant.UT_WELCOME_PANEL_NEW_TASK_BTN); 73 // init newTaskBgPanel 74 newTaskBgPanel = new JBPanel(null); 75 newTaskBgPanel.setBackground(JBColor.background()); 76 newTaskBgPanel.add(newTaskBtn); 77 // init tip 78 picImg = new JBLabel(); 79 picImg.setIcon(IconLoader.getIcon("/images/pic.png", getClass())); 80 picImg.setHorizontalAlignment(SwingConstants.CENTER); 81 picImg.setVerticalAlignment(SwingConstants.CENTER); 82 welcomeTitleLabel = new JBLabel(); 83 welcomeTitleLabel.setText(WELCOME_TITLE_STR); 84 welcomeTitleLabel.setFont(new Font(Font.DIALOG, Font.BOLD, 24)); 85 welcomeTitleLabel.setOpaque(false); 86 welcomeTitleLabel.setForeground(JBColor.foreground().brighter()); 87 welcomeTitleLabel.setHorizontalAlignment(SwingConstants.CENTER); 88 welcomeTipLabel = new JBLabel(); 89 welcomeTipLabel.setText(WELCOME_TIP_STR); 90 welcomeTipLabel.setFont(new Font(Font.DIALOG, Font.PLAIN, 14)); 91 welcomeTipLabel.setForeground(JBColor.foreground().darker()); 92 welcomeTipLabel.setOpaque(false); 93 welcomeTipLabel.setHorizontalAlignment(SwingConstants.CENTER); 94 JBPanel containPanel = new JBPanel(new MigLayout("inset 0", "[grow,fill]", "[fill,fill]")); 95 containPanel.add(picImg, "wrap"); 96 containPanel.add(welcomeTitleLabel, "wrap, height 30!"); 97 containPanel.add(welcomeTipLabel, "wrap, height 30!"); 98 containPanel.setBackground(JBColor.background().darker()); 99 containPanel.setOpaque(true); 100 // add the Component 101 add(newTaskBgPanel, "wrap, height 30!"); 102 add(containPanel, "center"); 103 setBackground(JBColor.background().darker()); 104 setOpaque(true); 105 newTaskBtn.addMouseListener(this); 106 } 107 108 /** 109 * mouseClicked 110 * 111 * @param event MouseEvent 112 */ 113 @Override mouseClicked(MouseEvent event)114 public void mouseClicked(MouseEvent event) { 115 Object parentComponent = getParent(); 116 if (parentComponent instanceof JBPanel) { 117 JBPanel containerPanel = (JBPanel) parentComponent; 118 if (Constant.jtasksTab == null || Constant.jtasksTab.getTabCount() == 0) { 119 Constant.jtasksTab = new JBTabbedPane(); 120 } 121 new TaskPanel(containerPanel, this); 122 setVisible(false); 123 containerPanel.updateUI(); 124 containerPanel.repaint(); 125 } 126 } 127 128 /** 129 * mousePressed 130 * 131 * @param event MouseEvent 132 */ 133 @Override mousePressed(MouseEvent event)134 public void mousePressed(MouseEvent event) { 135 } 136 137 /** 138 * mouseReleased 139 * 140 * @param event MouseEvent 141 */ 142 @Override mouseReleased(MouseEvent event)143 public void mouseReleased(MouseEvent event) { 144 } 145 146 /** 147 * mouseEntered 148 * 149 * @param event MouseEvent 150 */ 151 @Override mouseEntered(MouseEvent event)152 public void mouseEntered(MouseEvent event) { 153 } 154 155 /** 156 * mouseExited 157 * 158 * @param event MouseEvent 159 */ 160 @Override mouseExited(MouseEvent event)161 public void mouseExited(MouseEvent event) { 162 } 163 164 /** 165 * getNewTaskBtn 166 * 167 * @return JBLabel 168 */ getNewTaskBtn()169 public JBLabel getNewTaskBtn() { 170 return newTaskBtn; 171 } 172 } 173