01: package net.sourceforge.squirrel_sql.client.gui.builders;
02:
03: /*
04: * Copyright (C) 2001-2003 Colin Bell
05: * colbell@users.sourceforge.net
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation; either
10: * version 2.1 of the License, or (at your option) any later version.
11: *
12: * This library is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this library; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20: */
21: import java.beans.PropertyChangeEvent;
22: import java.beans.PropertyChangeListener;
23:
24: import javax.swing.*;
25:
26: import net.sourceforge.squirrel_sql.client.preferences.SquirrelPreferences;
27: import net.sourceforge.squirrel_sql.client.IApplication;
28:
29: class SquirrelTabbedPane extends JTabbedPane {
30: private SquirrelPreferences _prefs;
31:
32: private PropsListener _prefsListener;
33:
34: //private IApplication _app;
35: //private static boolean _jdk14SrollWarningWasIssued = false;
36:
37: /** Convenient way to refer to Application Preferences property names. */
38: private interface IAppPrefPropertynames extends
39: SquirrelPreferences.IPropertyNames {
40: // Empty block.
41: }
42:
43: SquirrelTabbedPane(SquirrelPreferences prefs, IApplication app) {
44: super ();
45:
46: if (prefs == null) {
47: throw new IllegalArgumentException(
48: "SquirrelPreferences == null");
49: }
50: _prefs = prefs;
51: //_app = app;
52:
53: int tabLayoutPolicy = _prefs.getUseScrollableTabbedPanes() ? JTabbedPane.SCROLL_TAB_LAYOUT
54: : JTabbedPane.WRAP_TAB_LAYOUT;
55: setTabLayoutPolicy(tabLayoutPolicy);
56: }
57:
58: /**
59: * Component is being added to its parent so add a property change
60: * listener to application perferences.
61: */
62: public void addNotify() {
63: super .addNotify();
64: _prefsListener = new PropsListener();
65: _prefs.addPropertyChangeListener(_prefsListener);
66: propertiesHaveChanged(null);
67: }
68:
69: /**
70: * Component is being removed from its parent so remove the property change
71: * listener from the application perferences.
72: */
73: public void removeNotify() {
74: super .removeNotify();
75: if (_prefsListener != null) {
76: _prefs.removePropertyChangeListener(_prefsListener);
77: _prefsListener = null;
78: }
79: }
80:
81: private void propertiesHaveChanged(String propName) {
82: if (propName == null
83: || propName
84: .equals(IAppPrefPropertynames.SCROLLABLE_TABBED_PANES)) {
85: int tabLayoutPolicy = _prefs.getUseScrollableTabbedPanes() ? JTabbedPane.SCROLL_TAB_LAYOUT
86: : JTabbedPane.WRAP_TAB_LAYOUT;
87: setTabLayoutPolicy(tabLayoutPolicy);
88: }
89: }
90:
91: private final class PropsListener implements PropertyChangeListener {
92: public void propertyChange(PropertyChangeEvent evt) {
93: propertiesHaveChanged(evt.getPropertyName());
94: }
95: }
96: }
|