Source Code Cross Referenced for ButtonExample.java in  » Swing-Library » wings3 » wingset » 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 » wings3 » wingset 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2000,2005 wingS development team.
003:         *
004:         * This file is part of wingS (http://wingsframework.org).
005:         *
006:         * wingS is free software; you can redistribute it and/or modify
007:         * it under the terms of the GNU Lesser General Public License
008:         * as published by the Free Software Foundation; either version 2.1
009:         * of the License, or (at your option) any later version.
010:         *
011:         * Please see COPYING for the complete licence.
012:         */
013:        package wingset;
014:
015:        import org.wings.*;
016:        import org.wings.script.JavaScriptListener;
017:        import org.wings.script.JavaScriptEvent;
018:
019:        import java.awt.event.ActionEvent;
020:        import java.awt.event.ActionListener;
021:        import java.util.Iterator;
022:
023:        /**
024:         * @author <a href="mailto:haaf@mercatis.de">Armin Haaf</a>
025:         */
026:        public class ButtonExample extends WingSetPane {
027:            final static int[] textHPos = new int[] { SConstants.LEFT,
028:                    SConstants.CENTER, SConstants.RIGHT };
029:            final static int[] textVPos = new int[] { SConstants.TOP,
030:                    SConstants.CENTER, SConstants.BOTTOM };
031:
032:            // icons
033:            private static final SIcon icon = new SResourceIcon(
034:                    "org/wings/icons/star.png");
035:            private static final SIcon disabledIcon = new SResourceIcon(
036:                    "org/wings/icons/star_disabled.png");
037:            private static final SIcon pressedIcon = new SResourceIcon(
038:                    "org/wings/icons/star.png");
039:            private static final SIcon rolloverIcon = new SResourceIcon(
040:                    "org/wings/icons/star.png");
041:
042:            // pressed label & handler
043:            private final SLabel reportLabel = new SLabel("No button pressed");
044:            private final ActionListener action = new ActionListener() {
045:                public void actionPerformed(ActionEvent e) {
046:                    reportLabel.setText("<html>Button <b>'"
047:                            + e.getActionCommand() + "'</b> pressed");
048:                }
049:            };
050:
051:            // button control itself
052:            private ButtonControls controls;
053:            private SButton[] buttons;
054:            private SGridLayout grid;
055:            private SPanel gridPanel;
056:
057:            protected SComponent createControls() {
058:                controls = new ButtonControls();
059:                return controls;
060:            }
061:
062:            public SComponent createExample() {
063:                SContainer example = createButtonExample();
064:
065:                final SButton defaultButton = new SButton();
066:                defaultButton.addActionListener(action);
067:                defaultButton.setActionCommand("Default Button (Enter key)");
068:                return example;
069:            }
070:
071:            private SContainer createButtonExample() {
072:                buttons = new SButton[9];
073:
074:                for (int i = 0; i < buttons.length; i++) {
075:                    final String buttonName = "Text " + (i + 1);
076:                    SButton button = buttons[i] = new SButton(buttonName);
077:                    button.setShowAsFormComponent(true);
078:                    button.setActionCommand(button.getText());
079:
080:                    button.setToolTipText("Button " + (i + 1));
081:                    button.setName("bu" + (i + 1));
082:                    button.setVerticalTextPosition(textVPos[(i / 3) % 3]);
083:                    button.setHorizontalTextPosition(textHPos[i % 3]);
084:                    button.setActionCommand(buttonName);
085:                    controls.addControllable(button);
086:                }
087:
088:                updateIconUsage(true);
089:
090:                grid = new SGridLayout(3);
091:                gridPanel = new SPanel(grid);
092:                grid.setHgap(10);
093:                grid.setVgap(10);
094:
095:                for (int i = 0; i < buttons.length; i++) {
096:                    buttons[i].addActionListener(action);
097:                    gridPanel.add(buttons[i]);
098:                }
099:
100:                final SPanel panel = new SPanel(new SGridLayout(2, 1, 0, 20));
101:                panel.add(gridPanel);
102:                panel.add(reportLabel);
103:
104:                addSomeConfirmDialogues();
105:
106:                return panel;
107:            }
108:
109:            /**
110:             * Register and use some <code>JavaScriptEvent.ON_CLICK</code> listeners to react on button click.
111:             * This tests the feature that return false aborts the button submit.
112:             */
113:            private void addSomeConfirmDialogues() {
114:                for (int i = 0; i < 3; i++) {
115:                    buttons[i].addScriptListener(new JavaScriptListener(
116:                            JavaScriptEvent.ON_CLICK,
117:                            "return window.confirm('Please confirm click of button "
118:                                    + (i + 1) + "');"));
119:                }
120:            }
121:
122:            /**
123:             * Use some icons in buttons or not.
124:             */
125:            private void updateIconUsage(boolean useIcons) {
126:                for (int i = 0; i < buttons.length; i++) {
127:                    final SButton button = buttons[i];
128:                    if (i != 4) {
129:                        button.setIcon(useIcons ? icon : null);
130:                        button.setDisabledIcon(useIcons ? disabledIcon : null);
131:                        button.setRolloverIcon(useIcons ? rolloverIcon : null);
132:                        button.setPressedIcon(useIcons ? pressedIcon : null);
133:                    }
134:                }
135:            }
136:
137:            /**
138:             * Update {@link SComponent#setEnabled(boolean)}
139:             */
140:            private void updateEnabled(boolean allEnabled) {
141:                for (int i = 0; i < buttons.length; i++) {
142:                    buttons[i].setEnabled(allEnabled || Math.random() > 0.3);
143:                }
144:            }
145:
146:            /**
147:             * The additional control toolbar for the button example
148:             */
149:            private class ButtonControls extends ComponentControls {
150:                private STextField iconTextGap = new STextField("4");
151:
152:                public ButtonControls() {
153:                    formComponentCheckBox.setSelected(true);
154:                    formComponentCheckBox
155:                            .addActionListener(new ActionListener() {
156:                                public void actionPerformed(ActionEvent e) {
157:                                    grid.setBorder(formComponentCheckBox
158:                                            .isSelected() ? 0 : 1);
159:                                    gridPanel.reload();
160:                                }
161:                            });
162:
163:                    final SCheckBox useImages = new SCheckBox("Use Icons");
164:                    useImages.setSelected(true);
165:                    useImages
166:                            .addActionListener(new java.awt.event.ActionListener() {
167:                                public void actionPerformed(ActionEvent e) {
168:                                    updateIconUsage(useImages.isSelected());
169:                                }
170:                            });
171:                    addControl(useImages);
172:
173:                    final SCheckBox disableSomeButtons = new SCheckBox(
174:                            "Disable a few buttons");
175:                    disableSomeButtons
176:                            .addActionListener(new java.awt.event.ActionListener() {
177:                                public void actionPerformed(ActionEvent e) {
178:                                    updateEnabled(!disableSomeButtons
179:                                            .isSelected());
180:                                }
181:                            });
182:
183:                    iconTextGap.addActionListener(new ActionListener() {
184:                        public void actionPerformed(ActionEvent e) {
185:                            for (Iterator iterator = getControllables()
186:                                    .iterator(); iterator.hasNext();) {
187:                                SAbstractIconTextCompound component = (SAbstractIconTextCompound) iterator
188:                                        .next();
189:                                try {
190:                                    component.setIconTextGap(Integer
191:                                            .parseInt(iconTextGap.getText()));
192:                                } catch (NumberFormatException invalidNumber) {
193:                                    component.setIconTextGap(0);
194:                                }
195:                            }
196:                        }
197:                    });
198:                    addControl(new SLabel(""));
199:                    addControl(disableSomeButtons);
200:                    addControl(new SLabel("iconTextGap"));
201:                    addControl(iconTextGap);
202:                }
203:            }
204:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.