Source Code Cross Referenced for SButtonGroup.java in  » J2EE » Sofia » com » salmonllc » 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 » J2EE » Sofia » com.salmonllc.swing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.salmonllc.swing;
002:
003:        //** Copyright Statement ***************************************************
004:        //The Salmon Open Framework for Internet Applications (SOFIA)
005:        // Copyright (C) 1999 - 2002, Salmon LLC
006:        //
007:        // This program is free software; you can redistribute it and/or
008:        // modify it under the terms of the GNU General Public License version 2
009:        // as published by the Free Software Foundation;
010:        //
011:        // This program is distributed in the hope that it will be useful,
012:        // but WITHOUT ANY WARRANTY; without even the implied warranty of
013:        // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014:        // GNU General Public License for more details.
015:        //
016:        // You should have received a copy of the GNU General Public License
017:        // along with this program; if not, write to the Free Software
018:        // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
019:        //
020:        // For more information please visit http://www.salmonllc.com
021:        //** End Copyright Statement ***************************************************
022:
023:        import com.salmonllc.swing.events.ValueChangedEvent;
024:        import com.salmonllc.swing.events.ValueChangedListener;
025:        import com.salmonllc.sql.DataStoreBuffer;
026:        import com.salmonllc.sql.ModelChangedListener;
027:        import com.salmonllc.sql.ModelChangedEvent;
028:
029:        import javax.swing.*;
030:        import java.util.Enumeration;
031:        import java.awt.*;
032:
033:        /**
034:         * SOFIA implementation of a Radio Button Group. It lets you bind the group to a datastore column. The button group is a non visual component. You must create the SComponent buttons individually and use this to group them and bind them to a datastore column.
035:         */
036:
037:        public class SButtonGroup extends ButtonGroup implements  SComponent,
038:                ModelChangedListener {
039:            String _col;
040:            DataStoreBuffer _ds;
041:            SComponentHelper _helper;
042:
043:            /**
044:             * Creates a new button group bound to a datastore columm
045:             * @param ds The DataStore to bind to
046:             * @param col The column to bind to
047:             */
048:            public SButtonGroup(DataStoreBuffer ds, String col) {
049:                _ds = ds;
050:                _col = col;
051:                _ds.addModelChangedListener(this );
052:                _helper = new SComponentHelper(this );
053:            }
054:
055:            /**
056:             * This method is used by the framework and should not be called directly
057:             */
058:            public ValueChangedEvent generateValueChangedEvent() {
059:                try {
060:                    if (_ds == null)
061:                        return null;
062:                    else {
063:                        String newValue = getText();
064:                        return new ValueChangedEvent(this , _ds
065:                                .getFormattedString(_col), newValue, _ds, _ds
066:                                .getRow(), _ds.getColumnIndex(_col));
067:
068:                    }
069:                } catch (Exception e) {
070:                    e.printStackTrace();
071:                    return null;
072:                }
073:            }
074:
075:            /**
076:             * Returns the helper for this component.
077:             */
078:            public SComponentHelper getHelper() {
079:                return _helper;
080:            }
081:
082:            /**
083:             * Returns the value of the selected radio button as a string
084:             */
085:            public String getText() {
086:                Enumeration e = getElements();
087:                while (e.hasMoreElements()) {
088:                    AbstractButton b = (AbstractButton) e.nextElement();
089:                    if (b.isSelected()) {
090:                        if (b instanceof  SRadioButton)
091:                            return ((SRadioButton) b).getOption().getKey();
092:                        else if (b instanceof  SGroupedToggleButton)
093:                            return ((SGroupedToggleButton) b).getOption()
094:                                    .getKey();
095:                        else
096:                            return b.getActionCommand();
097:                    }
098:                }
099:                return null;
100:            }
101:
102:            /**
103:             * Sets the text value for the group and selects the appropriate button
104:             */
105:            public void setText(String text) {
106:                Enumeration e = getElements();
107:                boolean found = false;
108:                AbstractButton nullOption = null;
109:
110:                while (e.hasMoreElements()) {
111:                    AbstractButton b = (AbstractButton) e.nextElement();
112:                    String key = null;
113:                    if (b instanceof  SRadioButton)
114:                        key = ((SRadioButton) b).getOption().getKey();
115:                    else if (b instanceof  SGroupedToggleButton)
116:                        key = ((SGroupedToggleButton) b).getOption().getKey();
117:                    else
118:                        key = b.getActionCommand();
119:                    if (key == null)
120:                        nullOption = b;
121:                    if (SComponentHelper.valuesEqual(key, text)) {
122:                        b.setSelected(true);
123:                        found = true;
124:                        break;
125:                    }
126:                }
127:
128:                if ((!found) && nullOption != null)
129:                    nullOption.setSelected(true);
130:            }
131:
132:            /**
133:             * Part of the model changed listener implementation. Do not call directly
134:             */
135:            public void modelChanged(ModelChangedEvent evt) {
136:                _helper.setDataDirty(true);
137:                try {
138:                    setText(_ds.getFormattedString(_col));
139:                } catch (Exception ex) {
140:                    setText(null);
141:                }
142:                _helper.setDataDirty(false);
143:            }
144:
145:            /**
146:             * Adds all the buttons in the panel to the group
147:             */
148:            public void add(JPanel c) {
149:                Component comp[] = c.getComponents();
150:                if (comp != null) {
151:                    for (int i = 0; i < comp.length; i++) {
152:                        if (comp[i] instanceof  AbstractButton)
153:                            add((AbstractButton) comp[i]);
154:                    }
155:                }
156:            }
157:
158:            /**
159:             * Adds a single button to the group
160:             */
161:            public void add(AbstractButton b) {
162:                super .add(b);
163:                b.addActionListener(_helper);
164:            }
165:
166:            /**
167:             * This method adds a listener the will be notified when the value in this component changes.
168:             * @param l The listener to add.
169:             */
170:            public void addValueChangedListener(ValueChangedListener l) {
171:                _helper.addValueChangedListener(l);
172:            }
173:
174:            /**
175:             * This method removes a listener from the list that will be notified if the text in the component changes.
176:             * @param l The listener to remove.
177:             */
178:            public void removeValueChangedListener(ValueChangedListener l) {
179:                _helper.removeValueChangedListener(l);
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.