Cleanup: NotNull/Nullable
[idea/community.git] / java / debugger / impl / src / com / intellij / debugger / ui / breakpoints / MethodBreakpointPropertiesPanel.java
1 /*
2  * Copyright 2000-2016 JetBrains s.r.o.
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
17 package com.intellij.debugger.ui.breakpoints;
18
19 import com.intellij.debugger.DebuggerBundle;
20 import com.intellij.ui.IdeBorderFactory;
21 import com.intellij.util.ui.DialogUtil;
22 import com.intellij.util.ui.JBUI;
23 import com.intellij.xdebugger.breakpoints.XBreakpoint;
24 import com.intellij.xdebugger.breakpoints.ui.XBreakpointCustomPropertiesPanel;
25 import com.intellij.xdebugger.impl.breakpoints.XBreakpointBase;
26 import org.jetbrains.annotations.NotNull;
27 import org.jetbrains.java.debugger.breakpoints.properties.JavaMethodBreakpointProperties;
28
29 import javax.swing.*;
30 import java.awt.*;
31 import java.awt.event.ActionEvent;
32 import java.awt.event.ActionListener;
33
34 public class MethodBreakpointPropertiesPanel extends XBreakpointCustomPropertiesPanel<XBreakpoint<JavaMethodBreakpointProperties>> {
35   private JCheckBox myEmulatedCheckBox;
36   private JCheckBox myWatchEntryCheckBox;
37   private JCheckBox myWatchExitCheckBox;
38
39   //public MethodBreakpointPropertiesPanel(final Project project, boolean compact) {
40   //  super(project, MethodBreakpoint.CATEGORY, compact);
41   //}
42
43
44   @NotNull
45   @Override
46   public JComponent getComponent() {
47     JPanel _panel, _panel0;
48
49     myEmulatedCheckBox = new JCheckBox(DebuggerBundle.message("label.method.breakpoint.properties.panel.emulated"));
50     myWatchEntryCheckBox = new JCheckBox(DebuggerBundle.message("label.method.breakpoint.properties.panel.method.entry"));
51     myWatchExitCheckBox = new JCheckBox(DebuggerBundle.message("label.method.breakpoint.properties.panel.method.exit"));
52     DialogUtil.registerMnemonic(myWatchEntryCheckBox);
53     DialogUtil.registerMnemonic(myWatchExitCheckBox);
54
55
56     Box watchBox = Box.createVerticalBox();
57     _panel = JBUI.Panels.simplePanel();
58     _panel.add(myEmulatedCheckBox, BorderLayout.NORTH);
59     watchBox.add(_panel);
60     _panel = new JPanel(new BorderLayout());
61     _panel.add(myWatchEntryCheckBox, BorderLayout.NORTH);
62     watchBox.add(_panel);
63     _panel = new JPanel(new BorderLayout());
64     _panel.add(myWatchExitCheckBox, BorderLayout.NORTH);
65     watchBox.add(_panel);
66
67     _panel = new JPanel(new BorderLayout());
68     _panel0 = new JPanel(new BorderLayout());
69     _panel0.add(watchBox, BorderLayout.CENTER);
70     _panel0.add(Box.createHorizontalStrut(3), BorderLayout.WEST);
71     _panel0.add(Box.createHorizontalStrut(3), BorderLayout.EAST);
72     _panel.add(_panel0, BorderLayout.NORTH);
73     _panel.setBorder(IdeBorderFactory.createTitledBorder(DebuggerBundle.message("label.group.watch.events"), true));
74
75     ActionListener listener = new ActionListener() {
76       @Override
77       public void actionPerformed(ActionEvent e) {
78         JCheckBox toCheck = null;
79         if (!myWatchEntryCheckBox.isSelected() && !myWatchExitCheckBox.isSelected()) {
80           Object source = e.getSource();
81           if (myWatchEntryCheckBox.equals(source)) {
82             toCheck = myWatchExitCheckBox;
83           }
84           else if (myWatchExitCheckBox.equals(source)) {
85             toCheck = myWatchEntryCheckBox;
86           }
87           if (toCheck != null) {
88             toCheck.setSelected(true);
89           }
90         }
91       }
92     };
93     myWatchEntryCheckBox.addActionListener(listener);
94     myWatchExitCheckBox.addActionListener(listener);
95
96     return _panel;
97   }
98
99   @Override
100   public void loadFrom(@NotNull XBreakpoint<JavaMethodBreakpointProperties> breakpoint) {
101     myEmulatedCheckBox.setSelected(breakpoint.getProperties().EMULATED);
102
103     myWatchEntryCheckBox.setSelected(breakpoint.getProperties().WATCH_ENTRY);
104     myWatchExitCheckBox.setSelected(breakpoint.getProperties().WATCH_EXIT);
105   }
106
107   @Override
108   public void saveTo(@NotNull XBreakpoint<JavaMethodBreakpointProperties> breakpoint) {
109     boolean changed = breakpoint.getProperties().EMULATED != myEmulatedCheckBox.isSelected();
110     breakpoint.getProperties().EMULATED = myEmulatedCheckBox.isSelected();
111     changed = breakpoint.getProperties().WATCH_ENTRY != myWatchEntryCheckBox.isSelected() || changed;
112     breakpoint.getProperties().WATCH_ENTRY = myWatchEntryCheckBox.isSelected();
113     changed = breakpoint.getProperties().WATCH_EXIT != myWatchExitCheckBox.isSelected() || changed;
114     breakpoint.getProperties().WATCH_EXIT = myWatchExitCheckBox.isSelected();
115     if (changed) {
116       ((XBreakpointBase)breakpoint).fireBreakpointChanged();
117     }
118   }
119 }