Source Code Cross Referenced for JButtonBar.java in  » Swing-Library » l2fprod-common » com » l2fprod » common » swing » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Swing Library » l2fprod common » com.l2fprod.common.swing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * L2FProd.com Common Components 7.3 License.
003:         *
004:         * Copyright 2005-2007 L2FProd.com
005:         *
006:         * Licensed under the Apache License, Version 2.0 (the "License");
007:         * you may not use this file except in compliance with the License.
008:         * You may obtain a copy of the License at
009:         *
010:         *     http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing, software
013:         * distributed under the License is distributed on an "AS IS" BASIS,
014:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License.
017:         */package com.l2fprod.common.swing;
018:
019:        import com.l2fprod.common.swing.plaf.ButtonBarButtonUI;
020:        import com.l2fprod.common.swing.plaf.ButtonBarUI;
021:        import com.l2fprod.common.swing.plaf.JButtonBarAddon;
022:        import com.l2fprod.common.swing.plaf.LookAndFeelAddons;
023:
024:        import java.awt.Component;
025:        import java.awt.event.ContainerAdapter;
026:        import java.awt.event.ContainerEvent;
027:        import java.awt.event.ContainerListener;
028:        import java.beans.PropertyChangeEvent;
029:        import java.beans.PropertyChangeListener;
030:
031:        import javax.swing.AbstractButton;
032:        import javax.swing.JComponent;
033:        import javax.swing.SwingConstants;
034:
035:        /**
036:         * JButtonBar helps organizing buttons together (as seen in Mozilla Firefox
037:         * or IntelliJ).<br>
038:         *  
039:         * @javabean.class
040:         *          name="JButtonBar"
041:         *          shortDescription="JButtonBar helps organizing buttons together (as seen in Mozilla Firefox or IntelliJ)."
042:         *          stopClass="java.awt.Component"
043:         * 
044:         * @javabean.icons
045:         *          mono16="JButtonBar16-mono.gif"
046:         *          color16="JButtonBar16.gif"
047:         *          mono32="JButtonBar32-mono.gif"
048:         *          color32="JButtonBar32.gif"
049:         */
050:        public class JButtonBar extends JComponent implements  SwingConstants {
051:
052:            public static final String UI_CLASS_ID = "ButtonBarUI";
053:
054:            // ensure at least the default ui is registered
055:            static {
056:                LookAndFeelAddons.contribute(new JButtonBarAddon());
057:            }
058:
059:            public static final String ORIENTATION_CHANGED_KEY = "orientation";
060:
061:            private int orientation;
062:
063:            public JButtonBar() {
064:                this (HORIZONTAL);
065:            }
066:
067:            public JButtonBar(int orientation) {
068:                this .orientation = orientation;
069:                updateUI();
070:                addContainerListener(buttonTracker);
071:            }
072:
073:            /**
074:             * Notification from the <code>UIManager</code> that the L&F has changed.
075:             * Replaces the current UI object with the latest version from the <code>UIManager</code>.
076:             * 
077:             * @see javax.swing.JComponent#updateUI
078:             */
079:            public void updateUI() {
080:                setUI((ButtonBarUI) LookAndFeelAddons.getUI(this ,
081:                        ButtonBarUI.class));
082:            }
083:
084:            /**
085:             * Returns the L&F object that renders this component.
086:             * 
087:             * @return the ButtonBarUI object
088:             * @see #setUI
089:             */
090:            public ButtonBarUI getUI() {
091:                return (ButtonBarUI) ui;
092:            }
093:
094:            /**
095:             * Sets the L&F object that renders this component.
096:             * 
097:             * @param ui the <code>ButtonBarUI</code> L&F object
098:             * @see javax.swing.UIDefaults#getUI
099:             * 
100:             * @beaninfo bound: true hidden: true description: The UI object that
101:             * implements the buttonbar's LookAndFeel.
102:             */
103:            public void setUI(ButtonBarUI ui) {
104:                super .setUI(ui);
105:                Component[] components = getComponents();
106:                // whenever our UI is changed, make sure UI of our buttons is updated.
107:                for (int i = 0, c = components.length; i < c; i++) {
108:                    if (components[i] instanceof  AbstractButton) {
109:                        ui.installButtonBarUI((AbstractButton) components[i]);
110:                    }
111:                }
112:            }
113:
114:            /**
115:             * Returns the name of the L&F class that renders this component.
116:             * 
117:             * @return the string {@link #UI_CLASS_ID}
118:             * @see javax.swing.JComponent#getUIClassID
119:             * @see javax.swing.UIDefaults#getUI
120:             */
121:            public String getUIClassID() {
122:                return UI_CLASS_ID;
123:            }
124:
125:            /**
126:             * Sets the orientation of the bar. The orientation must have either the
127:             * value <code>HORIZONTAL</code> or <code>VERTICAL</code>. If <code>orientation</code>
128:             * is an invalid value, an exception will be thrown.
129:             * 
130:             * @param orientation the new orientation -- either <code>HORIZONTAL</code>
131:             *          or</code> VERTICAL</code>
132:             * @exception IllegalArgumentException if orientation is neither <code>
133:             *              HORIZONTAL</code> nor <code>VERTICAL</code>
134:             * @see #getOrientation @beaninfo description: The current orientation of the
135:             *      bar bound: true preferred: true
136:             */
137:            public void setOrientation(int orientation) {
138:                if (!(orientation == HORIZONTAL || orientation == VERTICAL)) {
139:                    throw new IllegalArgumentException(
140:                            "orientation must be one of: "
141:                                    + "VERTICAL, HORIZONTAL");
142:                }
143:
144:                if (this .orientation != orientation) {
145:                    int oldOrientation = this .orientation;
146:                    this .orientation = orientation;
147:                    firePropertyChange(ORIENTATION_CHANGED_KEY, oldOrientation,
148:                            this .orientation);
149:                }
150:            }
151:
152:            public int getOrientation() {
153:                return orientation;
154:            }
155:
156:            /**
157:             * This listener ensures the UI of buttons added to the JButtonBar gets reset
158:             * everytime it is changed to a pluggable UI which does not implement
159:             * ButtonBarUI.
160:             */
161:            private static PropertyChangeListener uiUpdater = new PropertyChangeListener() {
162:                public void propertyChange(PropertyChangeEvent evt) {
163:                    if (evt.getSource() instanceof  AbstractButton) {
164:                        AbstractButton button = (AbstractButton) evt
165:                                .getSource();
166:                        if (button.getParent() instanceof  JButtonBar
167:                                && !(button.getUI() instanceof  ButtonBarButtonUI)) {
168:                            ((ButtonBarUI) ((JButtonBar) button.getParent()).ui)
169:                                    .installButtonBarUI(button);
170:                        }
171:                    }
172:                }
173:            };
174:
175:            /**
176:             * This listener tracks buttons added to a JButtonBar. When a button is
177:             * added, it updates its UI and ensures further ui changes will be tracked
178:             * too. When the button is removed, it is no longer tracked.
179:             */
180:            private static ContainerListener buttonTracker = new ContainerAdapter() {
181:                public void componentAdded(ContainerEvent e) {
182:                    JButtonBar container = (JButtonBar) e.getContainer();
183:                    if (e.getChild() instanceof  AbstractButton) {
184:                        ((ButtonBarUI) container.ui)
185:                                .installButtonBarUI((AbstractButton) e
186:                                        .getChild());
187:                        ((AbstractButton) e.getChild())
188:                                .addPropertyChangeListener("UI",
189:                                        JButtonBar.uiUpdater);
190:                    }
191:                }
192:
193:                public void componentRemoved(ContainerEvent e) {
194:                    if (e.getChild() instanceof  AbstractButton) {
195:                        ((AbstractButton) e.getChild())
196:                                .removePropertyChangeListener("UI",
197:                                        JButtonBar.uiUpdater);
198:                    }
199:                }
200:            };
201:
202:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.