Code style settings UI: "Set from" button moved to tabs
authorRustam.Vishnyakov <rustam.vishnyakov@gmail.com>
Tue, 24 Jan 2012 15:40:07 +0000 (19:40 +0400)
committerRustam.Vishnyakov <rustam.vishnyakov@gmail.com>
Thu, 2 Feb 2012 08:47:09 +0000 (12:47 +0400)
platform/lang-impl/src/com/intellij/application/options/TabbedLanguageCodeStylePanel.java

index 429361079c9c3d81a6e99416b7c46a83ea80052e..d0732dd73fab5b78fbdb925605a18747e56fe120 100644 (file)
@@ -55,6 +55,7 @@ public abstract class TabbedLanguageCodeStylePanel extends CodeStyleAbstractPane
   private JPanel myPanel;
   private JTabbedPane myTabbedPane;
   private PredefinedCodeStyle[] myPredefinedCodeStyles;
+  private PopupMenu myCopyFromMenu;
 
   protected TabbedLanguageCodeStylePanel(@Nullable Language language, CodeStyleSettings currentSettings, CodeStyleSettings settings) {
     super(language, currentSettings, settings);
@@ -132,21 +133,27 @@ public abstract class TabbedLanguageCodeStylePanel extends CodeStyleAbstractPane
     myTabbedPane.setEnabledAt(dummyIndex, false);
     JPanel setFromPanel = new JPanel();
     setFromPanel.setBorder(BorderFactory.createEtchedBorder());
-    setFromPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 10,0));
-    JLabel setFromLabel = new JLabel("Set from...");
+    setFromPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 0));
+    final JLabel setFromLabel = new JLabel("Set from...");
     setFromPanel.add(setFromLabel);
-    final PopupMenu copyMenu = new PopupMenu();
-    setFromLabel.add(copyMenu);
     setFromLabel.setIcon(COPY_ICON);
-    setupCopyFromMenu(copyMenu);
     setFromLabel.addMouseListener(new MouseAdapter() {
       @Override
       public void mousePressed(MouseEvent e) {
-          copyMenu.show(e.getComponent(), e.getX(), e.getY());
+        initCopyFromMenu(setFromLabel);
+        myCopyFromMenu.show(e.getComponent(), e.getX(), e.getY());
       }
     });
     myTabbedPane.setTabComponentAt(dummyIndex, setFromPanel);
   }
+  
+  private void initCopyFromMenu(JComponent parent) {
+    if (myCopyFromMenu == null) {
+      myCopyFromMenu = new PopupMenu();
+      parent.add(myCopyFromMenu);
+      setupCopyFromMenu(myCopyFromMenu);
+    }
+  }
 
   /**
    * Adds a tab with the given CodeStyleAbstractPanel. Tab title is taken from getTabTitle() method.