src/macosx/classes/com/apple/laf/AquaTabbedPaneUI.java

Print this page


   1 /*
   2  * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 970             }
 971 
 972             popup.addPopupMenuListener(new PopupMenuListener() {
 973                 public void popupMenuCanceled(final PopupMenuEvent e) { }
 974                 public void popupMenuWillBecomeVisible(final PopupMenuEvent e) { }
 975 
 976                 public void popupMenuWillBecomeInvisible(final PopupMenuEvent e) {
 977                     pressedTab = -3;
 978                     tabPane.repaint(visibleTabState.getLeftScrollTabRect());
 979                     tabPane.repaint(visibleTabState.getRightScrollTabRect());
 980                 }
 981             });
 982         }
 983 
 984         JMenuItem createMenuItem(final int i) {
 985             final Component component = getTabComponentAt(i);
 986             final JMenuItem menuItem;
 987             if (component == null) {
 988                 menuItem = new JMenuItem(tabPane.getTitleAt(i), tabPane.getIconAt(i));
 989             } else {
 990                 menuItem = new JMenuItem() {

 991                     public void paintComponent(final Graphics g) {
 992                         super.paintComponent(g);
 993                         final Dimension size = component.getSize();
 994                         component.setSize(getSize());
 995                         component.validate();
 996                         component.paint(g);
 997                         component.setSize(size);
 998                     }
 999 
1000                     public Dimension getPreferredSize() {
1001                         return component.getPreferredSize();
1002                     }
1003                 };

1004             }
1005 
1006             final Color background = tabPane.getBackgroundAt(i);
1007             if (!(background instanceof UIResource)) {
1008                 menuItem.setBackground(background);
1009             }
1010 
1011             menuItem.setForeground(tabPane.getForegroundAt(i));
1012             // for <rdar://problem/3520267> make sure to disable items that are disabled in the tab.
1013             if (!tabPane.isEnabledAt(i)) menuItem.setEnabled(false);
1014 
1015             final int fOffset = i;
1016             menuItem.addActionListener(new ActionListener() {
1017                 public void actionPerformed(final ActionEvent ae) {
1018                     boolean visible = isTabVisible(fOffset);
1019                     tabPane.setSelectedIndex(fOffset);
1020                     if (!visible) {
1021                         popupSelectionChanged = true;
1022                         tabPane.invalidate();
1023                         tabPane.repaint();


   1 /*
   2  * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 970             }
 971 
 972             popup.addPopupMenuListener(new PopupMenuListener() {
 973                 public void popupMenuCanceled(final PopupMenuEvent e) { }
 974                 public void popupMenuWillBecomeVisible(final PopupMenuEvent e) { }
 975 
 976                 public void popupMenuWillBecomeInvisible(final PopupMenuEvent e) {
 977                     pressedTab = -3;
 978                     tabPane.repaint(visibleTabState.getLeftScrollTabRect());
 979                     tabPane.repaint(visibleTabState.getRightScrollTabRect());
 980                 }
 981             });
 982         }
 983 
 984         JMenuItem createMenuItem(final int i) {
 985             final Component component = getTabComponentAt(i);
 986             final JMenuItem menuItem;
 987             if (component == null) {
 988                 menuItem = new JMenuItem(tabPane.getTitleAt(i), tabPane.getIconAt(i));
 989             } else {
 990                 @SuppressWarnings("serial") // anonymous class
 991                 JMenuItem tmp = new JMenuItem() {
 992                     public void paintComponent(final Graphics g) {
 993                         super.paintComponent(g);
 994                         final Dimension size = component.getSize();
 995                         component.setSize(getSize());
 996                         component.validate();
 997                         component.paint(g);
 998                         component.setSize(size);
 999                     }
1000 
1001                     public Dimension getPreferredSize() {
1002                         return component.getPreferredSize();
1003                     }
1004                 };
1005                 menuItem = tmp;
1006             }
1007 
1008             final Color background = tabPane.getBackgroundAt(i);
1009             if (!(background instanceof UIResource)) {
1010                 menuItem.setBackground(background);
1011             }
1012 
1013             menuItem.setForeground(tabPane.getForegroundAt(i));
1014             // for <rdar://problem/3520267> make sure to disable items that are disabled in the tab.
1015             if (!tabPane.isEnabledAt(i)) menuItem.setEnabled(false);
1016 
1017             final int fOffset = i;
1018             menuItem.addActionListener(new ActionListener() {
1019                 public void actionPerformed(final ActionEvent ae) {
1020                     boolean visible = isTabVisible(fOffset);
1021                     tabPane.setSelectedIndex(fOffset);
1022                     if (!visible) {
1023                         popupSelectionChanged = true;
1024                         tabPane.invalidate();
1025                         tabPane.repaint();