Source Code Cross Referenced for JLabeledRadio.java in  » Testing » jakarta-jmeter » org » apache » jorphan » gui » 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 » Testing » jakarta jmeter » org.apache.jorphan.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *   http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         * 
017:         */
018:
019:        package org.apache.jorphan.gui;
020:
021:        import java.awt.event.ActionEvent;
022:        import java.awt.event.ActionListener;
023:        import java.util.ArrayList;
024:        import java.util.Enumeration;
025:        import java.util.LinkedList;
026:        import java.util.List;
027:
028:        import javax.swing.ButtonGroup;
029:        import javax.swing.JComponent;
030:        import javax.swing.JLabel;
031:        import javax.swing.JPanel;
032:        import javax.swing.JRadioButton;
033:        import javax.swing.event.ChangeEvent;
034:        import javax.swing.event.ChangeListener;
035:
036:        /**
037:         * @author pete
038:         * 
039:         * JLabeledRadio will create a set of Radio buttons with a label.
040:         */
041:        public class JLabeledRadio extends JPanel implements  JLabeledField,
042:                ActionListener {
043:
044:            private JLabel mLabel = new JLabel();
045:
046:            private ButtonGroup bGroup = new ButtonGroup();
047:
048:            private ArrayList mChangeListeners = new ArrayList(3);
049:
050:            /**
051:             * 
052:             */
053:            public JLabeledRadio() {
054:                super ();
055:                this .add(mLabel);
056:            }
057:
058:            public JLabeledRadio(String label, String[] items) {
059:                mLabel.setText(label);
060:                init(items, null);
061:            }
062:
063:            public JLabeledRadio(String label, String[] items,
064:                    String selectedItem) {
065:                mLabel.setText(label);
066:                init(items, selectedItem);
067:            }
068:
069:            /**
070:             * Method is responsible for creating the JRadioButtons and adding them to
071:             * the ButtonGroup.
072:             * 
073:             * @param items
074:             */
075:            private void init(String[] items, String selected) {
076:                this .add(mLabel);
077:                for (int idx = 0; idx < items.length; idx++) {
078:                    JRadioButton btn = new JRadioButton(items[idx]);
079:                    btn.setActionCommand(items[idx]);
080:                    btn.addActionListener(this );
081:                    // add the button to the button group
082:                    this .bGroup.add(btn);
083:                    // add the button
084:                    this .add(btn);
085:                    if (selected != null && selected.equals(items[idx])) {
086:                        btn.setSelected(true);
087:                    }
088:                }
089:            }
090:
091:            /**
092:             * setItems will set the radio button items. The implementation first
093:             * removes the old JRadioButton, then it creates new ones.
094:             * 
095:             * @param items
096:             */
097:            public void setItems(String[] items) {
098:                Enumeration en = this .bGroup.getElements();
099:                while (en.hasMoreElements()) {
100:                    JComponent comp = (JComponent) en.nextElement();
101:                    this .bGroup.remove((JRadioButton) comp);
102:                    this .remove(comp);
103:                }
104:                init(items, null);
105:            }
106:
107:            /**
108:             * The implementation will get the Text value from the selected radio button
109:             * in the JButtonGroup.
110:             */
111:            public String getText() {
112:                return this .bGroup.getSelection().getActionCommand();
113:            }
114:
115:            /**
116:             * The implementation will iterate through the radio buttons and find the
117:             * match. It then sets it to selected and sets all other radion buttons as
118:             * not selected.
119:             */
120:            public void setText(String text) {
121:                Enumeration en = this .bGroup.getElements();
122:                while (en.hasMoreElements()) {
123:                    JRadioButton jrb = (JRadioButton) en.nextElement();
124:                    if (jrb.getText().equals(text)) {
125:                        this .bGroup.setSelected(jrb.getModel(), true);
126:                    } else {
127:                        this .bGroup.setSelected(jrb.getModel(), false);
128:                    }
129:                }
130:            }
131:
132:            /*
133:             * (non-Javadoc)
134:             * 
135:             * @see org.apache.jorphan.gui.JLabeledField#setLabel(java.lang.String)
136:             */
137:            public void setLabel(String pLabel) {
138:                this .mLabel.setText(pLabel);
139:            }
140:
141:            /*
142:             * (non-Javadoc)
143:             * 
144:             * @see org.apache.jorphan.gui.JLabeledField#addChangeListener(javax.swing.event.ChangeListener)
145:             */
146:            public void addChangeListener(ChangeListener pChangeListener) {
147:                this .mChangeListeners.add(pChangeListener);
148:            }
149:
150:            /**
151:             * Notify all registered change listeners that the text in the text field
152:             * has changed.
153:             */
154:            private void notifyChangeListeners() {
155:                ChangeEvent ce = new ChangeEvent(this );
156:                for (int index = 0; index < mChangeListeners.size(); index++) {
157:                    ((ChangeListener) mChangeListeners.get(index))
158:                            .stateChanged(ce);
159:                }
160:            }
161:
162:            /**
163:             * Method will return all the label and JRadioButtons. ButtonGroup is
164:             * excluded from the list.
165:             */
166:            public List getComponentList() {
167:                List comps = new LinkedList();
168:                comps.add(mLabel);
169:                Enumeration en = this .bGroup.getElements();
170:                while (en.hasMoreElements()) {
171:                    comps.add(en.nextElement());
172:                }
173:                return comps;
174:            }
175:
176:            /**
177:             * When a radio button is clicked, an ActionEvent is triggered.
178:             */
179:            public void actionPerformed(ActionEvent e) {
180:                this.notifyChangeListeners();
181:            }
182:
183:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.