Source Code Cross Referenced for ButtonPanel.java in  » Swing-Library » jide-common » com » jidesoft » 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 » jide common » com.jidesoft.swing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#)ButtonPanel.java
003:         *
004:         * Copyright 2002-2003 JIDE Software. All rights reserved.
005:         */
006:        package com.jidesoft.swing;
007:
008:        import javax.swing.*;
009:        import java.awt.*;
010:
011:        /**
012:         * ButtonPanel can have a collection of buttons. And it will make all buttons to
013:         * have the same size to make them looks better.
014:         *
015:         * @deprecated replaced by ButtonPanel under com.jidesoft.dialog.
016:         */
017:
018:        public class ButtonPanel extends JPanel {
019:
020:            /**
021:             * The default horizontal spacing.
022:             */
023:            public static final int DEFAULT_SPACING = 4;
024:
025:            /**
026:             * The actual panel that have those buttons.
027:             */
028:            private JPanel _buttons;
029:
030:            /**
031:             * Constructs a new <code>ButtonPanel</code> with the default horizontal
032:             * spacing and right alignment.
033:             */
034:
035:            public ButtonPanel() {
036:                this (SwingConstants.RIGHT, DEFAULT_SPACING);
037:            }
038:
039:            /**
040:             * Constructs a new <code>ButtonPanel</code> with default horizontal
041:             * spacing and the given alignment.
042:             *
043:             * @param alignment the alignment of the buttons. It can be one of <code>SwingConstants.LEFT</code> or
044:             *                  <code>SwingConstants.RIGHT</code> or <code>SwingConstants.TOP</code> or
045:             *                  <code>SwingConstants.BOTTOM</code>.
046:             */
047:
048:            public ButtonPanel(int alignment) {
049:                this (alignment, DEFAULT_SPACING);
050:            }
051:
052:            /**
053:             * Constructs a new <code>ButtonPanel</code> with the given horizontal
054:             * spacing and alignment.
055:             *
056:             * @param spacing   The gridSize of the gap (in pixels) to place between buttons
057:             *                  horizontally.
058:             * @param alignment the alignment of the buttons. It can be one of <code>SwingConstants.LEFT</code> or
059:             *                  <code>SwingConstants.RIGHT</code> or <code>SwingConstants.TOP</code> or
060:             *                  <code>SwingConstants.BOTTOM</code>.
061:             */
062:
063:            public ButtonPanel(int alignment, int spacing) {
064:                if (alignment != SwingConstants.LEFT
065:                        && alignment != SwingConstants.RIGHT
066:                        && alignment != SwingConstants.TOP
067:                        && alignment != SwingConstants.BOTTOM) {
068:                    throw new IllegalArgumentException("Invalid alignment");
069:                }
070:
071:                setLayout(new BorderLayout());
072:
073:                _buttons = new NullPanel();
074:
075:                if (alignment == SwingConstants.TOP
076:                        || alignment == SwingConstants.BOTTOM)
077:                    _buttons.setLayout(new GridLayout(0, 1, 0, spacing));
078:                else
079:                    _buttons.setLayout(new GridLayout(1, 0, spacing, 0));
080:
081:                switch (alignment) {
082:                case SwingConstants.LEFT:
083:                    add(_buttons, BorderLayout.WEST);
084:                    break;
085:                case SwingConstants.RIGHT:
086:                    add(_buttons, BorderLayout.EAST);
087:                    break;
088:                case SwingConstants.TOP:
089:                    add(_buttons, BorderLayout.NORTH);
090:                    break;
091:                case SwingConstants.BOTTOM:
092:                    add(_buttons, BorderLayout.SOUTH);
093:                    break;
094:                }
095:            }
096:
097:            /**
098:             * Adds a button to <code>ButtonPanel</code>.
099:             *
100:             * @param button button to be added.
101:             */
102:
103:            public void addButton(AbstractButton button) {
104:                if (button.getParent() != _buttons) {
105:                    _buttons.add(button);
106:                }
107:            }
108:
109:            /**
110:             * Adds a button to <code>ButtonPanel</code> at the specified position.
111:             *
112:             * @param button button to add.
113:             * @param pos    position at which to add the button. The value 0 denotes
114:             *               the first position, and -1 denotes the last position.
115:             * @throws IllegalArgumentException If the value of
116:             *                                  <code>pos</code> is invalid.
117:             */
118:
119:            public void addButton(AbstractButton button, int pos)
120:                    throws IllegalArgumentException {
121:                if (button.getParent() != _buttons) {
122:                    _buttons.add(button, pos);
123:                }
124:            }
125:
126:            /**
127:             * Removes a button from the <code>ButtonPanel</code>.
128:             *
129:             * @param button button to remove.
130:             */
131:
132:            public void removeButton(AbstractButton button) {
133:                if (button.getParent() == _buttons) {
134:                    _buttons.remove(button);
135:                }
136:            }
137:
138:            /**
139:             * Removes a button from the <code>ButtonPanel</code> at the specified position.
140:             *
141:             * @param position position of the button to remove, where 0 denotes the
142:             *                 first position.
143:             */
144:
145:            public void removeButton(int position) {
146:                _buttons.remove(position);
147:            }
148:
149:            /**
150:             * Gets the button at the specified position in the
151:             * <code>ButtonPanel</code>.
152:             *
153:             * @param position position of the button.
154:             * @return button at the specified position.
155:             */
156:
157:            public AbstractButton getButton(int position) {
158:                return ((AbstractButton) _buttons.getComponent(position));
159:            }
160:
161:            /**
162:             * Gets the number of buttons in this <code>ButtonPanel</code>.
163:             *
164:             * @return the number of buttons.
165:             */
166:
167:            public int getButtonCount() {
168:                return (_buttons.getComponentCount());
169:            }
170:
171:            /**
172:             * Gets the actual panel that has the buttons. We expose this method so
173:             * that user can customize the panel such as the background. Please don't
174:             * try to add non-button component to it.
175:             *
176:             * @return the actual button panel.
177:             */
178:            public JPanel getButtons() {
179:                return _buttons;
180:            }
181:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.