View Javadoc

1   /**
2    * Copyright (C) 2008 Atlassian
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.atlassian.theplugin.idea.config;
18  
19  import com.intellij.uiDesigner.core.GridLayoutManager;
20  import com.intellij.uiDesigner.core.GridConstraints;
21  import com.intellij.util.net.HTTPProxySettingsPanel;
22  import com.intellij.openapi.ui.Messages;
23  import com.jgoodies.forms.layout.FormLayout;
24  import com.jgoodies.forms.layout.CellConstraints;
25  
26  import javax.swing.*;
27  import java.awt.event.*;
28  import java.awt.*;
29  
30  public class HTTPProxyDialog extends JDialog {
31      private JPanel contentPane;
32      private HTTPProxySettingsPanel httpProxyPanel;
33      private JLabel labelInfo;
34      private boolean isOK = false;
35  
36      public HTTPProxyDialog() {
37  
38          $$$setupUI$$$();
39          setContentPane(contentPane);
40          labelInfo.setIcon(Messages.getInformationIcon());
41          setModal(true);
42  
43  // call onCancel() when cross is clicked
44          setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
45          addWindowListener(new WindowAdapter() {
46              public void windowClosing(WindowEvent e) {
47                  onCancel();
48              }
49          });
50  
51  // call onCancel() on ESCAPE
52          contentPane.registerKeyboardAction(new ActionListener() {
53              public void actionPerformed(ActionEvent e) {
54                  onCancel();
55              }
56          }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
57      }
58  
59      public boolean isOK() {
60          return isOK;
61      }
62  
63      public JPanel getRootPanel() {
64          return contentPane;
65      }
66  
67      public HTTPProxySettingsPanel getHttpProxyPanel() {
68          return httpProxyPanel;
69      }
70  
71      private void onOK() {
72          isOK = true;
73          dispose();
74      }
75  
76      private void onCancel() {
77          isOK = false;
78          dispose();
79      }
80  
81      private void createUIComponents() {
82          httpProxyPanel = new HTTPProxySettingsPanel();
83      }
84  
85  
86      /**
87       * Method generated by IntelliJ IDEA GUI Designer
88       * >>> IMPORTANT!! <<<
89       * DO NOT edit this method OR call it in your code!
90       *
91       * @noinspection ALL
92       */
93      private void $$$setupUI$$$() {
94          createUIComponents();
95          contentPane = new JPanel();
96          contentPane.setLayout(new FormLayout("fill:d:grow", "center:d:grow,top:3dlu:noGrow,center:max(d;4px):noGrow"));
97          final JPanel panel1 = new JPanel();
98          panel1.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
99          CellConstraints cc = new CellConstraints();
100         contentPane.add(panel1, cc.xy(1, 3));
101         panel1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), null));
102         final JPanel panel2 = new JPanel();
103         panel2.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
104         panel1.add(panel2, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
105         labelInfo = new JLabel();
106         labelInfo.setFont(new Font(labelInfo.getFont().getName(), labelInfo.getFont().getStyle(), 11));
107         labelInfo.setForeground(new Color(-16777216));
108         labelInfo.setText("Please restart IDEA to apply proxy settings change");
109         panel2.add(labelInfo, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
110         final JPanel panel3 = new JPanel();
111         panel3.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
112         contentPane.add(panel3, cc.xy(1, 1));
113         panel3.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), null));
114         panel3.add(httpProxyPanel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
115     }
116 
117     /**
118      * @noinspection ALL
119      */
120     public JComponent $$$getRootComponent$$$() {
121         return contentPane;
122     }
123 }