1 /* 2 * @(#)Quaqua14PantherTabbedPaneUI.java 1.1.1 2006-09-16 3 * 4 * Copyright (c) 2006 Werner Randelshofer 5 * Staldenmattweg 2, Immensee, CH-6405, Switzerland. 6 * All rights reserved. 7 * 8 * The copyright of this software is owned by Werner Randelshofer. 9 * You may not use, copy or modify this software, except in 10 * accordance with the license agreement you entered into with 11 * Werner Randelshofer. For details see accompanying license terms. 12 */ 13 14 package ch.randelshofer.quaqua.panther; 15 16 import ch.randelshofer.quaqua.util.NavigatableTabbedPaneUI; 17 import ch.randelshofer.quaqua.QuaquaManager; 18 import ch.randelshofer.quaqua.jaguar.*; 19 import java.awt.*; 20 import java.awt.event.*; 21 import java.beans.*; 22 import javax.swing.*; 23 import javax.swing.event.*; 24 import javax.swing.plaf.*; 25 import javax.swing.plaf.basic.*; 26 /** 27 * The Quaqua14PantherTabbedPaneUI uses to the Quaqua13JaguarTabbedPaneUI for 28 * the WRAP_TAB_LAYOUT policy and the Quaqua14PantherScrollTabbedPaneUI for 29 * the SCROLL_TAB_LAYOUT policy. 30 * 31 * @author Werner Randelshofer 32 * @version 1.1.1 2006-09-16 Use Quaqua14JaguarTabbedPaneUI instead of 33 * Quaqua13JaguarTabbedPaneUI. 34 * <br>1.1 2006-09-04 Fixed keyboard navigation problems. 35 * <br>1.0 February 5, 2006 Created. 36 */ 37 public class Quaqua14PantherTabbedPaneUI extends TabbedPaneUI 38 implements NavigatableTabbedPaneUI { 39 private JTabbedPane tabPane; 40 private TabbedPaneUI currentUI; 41 private PropertyChangeListener propertyChangeListener; 42 //private FocusListener focusListener; 43 44 /** 45 * Creates a new instance. 46 */ Quaqua14PantherTabbedPaneUI()47 public Quaqua14PantherTabbedPaneUI() { 48 } 49 createUI(JComponent c)50 public static ComponentUI createUI(JComponent c) { 51 return new Quaqua14PantherTabbedPaneUI(); 52 } 53 installUI(JComponent c)54 public void installUI(JComponent c) { 55 this.tabPane = (JTabbedPane) c; 56 57 // Tag the tabbed pane with a client property in order to prevent 58 // that we are getting in an endless loop, when the layout policy 59 // of the tabbed pane is changed. 60 if (tabPane.getClientProperty("Quaqua.TabbedPane.tabLayoutPolicy") == null) { 61 tabPane.putClientProperty("Quaqua.TabbedPane.tabLayoutPolicy", UIManager.get("TabbedPane.tabLayoutPolicy")); 62 tabPane.setTabLayoutPolicy(UIManager.getInt("TabbedPane.tabLayoutPolicy")); 63 } 64 65 66 if (tabPane.getTabLayoutPolicy() == JTabbedPane.WRAP_TAB_LAYOUT) { 67 Quaqua13JaguarTabbedPaneUI qjtpui = (Quaqua13JaguarTabbedPaneUI) Quaqua14JaguarTabbedPaneUI.createUI(c); 68 qjtpui.setPropertyPrefix("TabbedPane.wrap."); 69 currentUI = qjtpui; 70 71 } else { 72 Quaqua14PantherScrollTabbedPaneUI qptpui = (Quaqua14PantherScrollTabbedPaneUI) Quaqua14PantherScrollTabbedPaneUI.createUI(c); 73 qptpui.setPropertyPrefix("TabbedPane.scroll."); 74 currentUI = qptpui; 75 } 76 currentUI.installUI(c); 77 78 tabPane.setRequestFocusEnabled(QuaquaManager.getBoolean("TabbedPane.requestFocusEnabled")); 79 80 //installComponents(); 81 //installDefaults(); 82 installListeners(); 83 //installKeyboardActions(); 84 } 85 uninstallUI(JComponent c)86 public void uninstallUI(JComponent c) { 87 //uninstallKeyboardActions(); 88 uninstallListeners(); 89 //uninstallDefaults(); 90 //uninstallComponents(); 91 92 if (currentUI != null) { 93 currentUI.uninstallUI(c); 94 } 95 96 this.tabPane = null; 97 } 98 installListeners()99 protected void installListeners() { 100 if ((propertyChangeListener = createPropertyChangeListener()) != null) { 101 tabPane.addPropertyChangeListener(propertyChangeListener); 102 } 103 /* 104 if ((focusListener = createFocusListener()) != null) { 105 tabPane.addFocusListener(focusListener); 106 }*/ 107 } 108 uninstallListeners()109 protected void uninstallListeners() { 110 if (propertyChangeListener != null) { 111 tabPane.removePropertyChangeListener(propertyChangeListener); 112 propertyChangeListener = null; 113 } 114 /* 115 if (focusListener != null) { 116 tabPane.removeFocusListener(focusListener); 117 focusListener = null; 118 }*/ 119 } 120 createPropertyChangeListener()121 protected PropertyChangeListener createPropertyChangeListener() { 122 return new PropertyChangeHandler(); 123 } 124 /* 125 protected FocusListener createFocusListener() { 126 return new FocusHandler(); 127 }*/ 128 129 getTabBounds(JTabbedPane pane, int index)130 public Rectangle getTabBounds(JTabbedPane pane, int index) { 131 return currentUI.getTabBounds(pane, index); 132 } 133 getTabRunCount(JTabbedPane pane)134 public int getTabRunCount(JTabbedPane pane) { 135 return currentUI.getTabRunCount(pane); 136 } 137 tabForCoordinate(JTabbedPane pane, int x, int y)138 public int tabForCoordinate(JTabbedPane pane, int x, int y) { 139 return currentUI.tabForCoordinate(pane, x, y); 140 } paint(Graphics g, JComponent c)141 public void paint(Graphics g, JComponent c) { 142 currentUI.paint(g, c); 143 } navigateSelectedTab(int direction)144 public void navigateSelectedTab(int direction) { 145 ((NavigatableTabbedPaneUI) currentUI).navigateSelectedTab(direction); 146 } 147 getIndexForMnemonic(int mnemonic)148 public Integer getIndexForMnemonic(int mnemonic) { 149 return ((NavigatableTabbedPaneUI) currentUI).getIndexForMnemonic(mnemonic); 150 } 151 requestFocusForVisibleComponent()152 public boolean requestFocusForVisibleComponent() { 153 return ((NavigatableTabbedPaneUI) currentUI).requestFocusForVisibleComponent(); 154 } 155 156 /** 157 * This inner class is marked "public" due to a compiler bug. 158 * This class should be treated as a "protected" inner class. 159 * Instantiate it only within subclasses of BasicTabbedPaneUI. 160 */ 161 public class PropertyChangeHandler implements PropertyChangeListener { propertyChange(PropertyChangeEvent e)162 public void propertyChange(PropertyChangeEvent e) { 163 JTabbedPane pane = (JTabbedPane)e.getSource(); 164 String name = e.getPropertyName(); 165 if (name.equals("tabLayoutPolicy")) { 166 Quaqua14PantherTabbedPaneUI.this.uninstallUI(pane); 167 Quaqua14PantherTabbedPaneUI.this.installUI(pane); 168 } 169 } 170 } 171 } 172