Source Code Cross Referenced for MnemonicSetter.java in  » Mail-Clients » columba-1.4 » org » columba » core » gui » base » 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 » Mail Clients » columba 1.4 » org.columba.core.gui.base 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //The contents of this file are subject to the Mozilla Public License Version 1.1
002:        //(the "License"); you may not use this file except in compliance with the 
003:        //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004:        //
005:        //Software distributed under the License is distributed on an "AS IS" basis,
006:        //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
007:        //for the specific language governing rights and
008:        //limitations under the License.
009:        //
010:        //The Original Code is "The Columba Project"
011:        //
012:        //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013:        //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003. 
014:        //
015:        //All Rights Reserved.
016:        package org.columba.core.gui.base;
017:
018:        import javax.swing.AbstractButton;
019:        import javax.swing.JLabel;
020:
021:        /**
022:         * This class contains utility methods to set text on buttons, checkboxes,
023:         * menus, menuitems and labels with mnemonics. The mnemonics is to be specified
024:         * using the & character in the display text just before the mnemonic character.
025:         * <br>
026:         * The first & character in the display text is used to define the mnemonic.
027:         * Please be aware of this when trying to set display texts containing a &
028:         * character.
029:         * 
030:         * @author Karl Peder Olesen (karlpeder)
031:         */
032:        public class MnemonicSetter {
033:            /**
034:             * Sets the text of a menu, menuitem, button or checkbox. If a & character
035:             * is found, it is used to define the mnemonic. Else the text is set just as
036:             * if the setText method of the component was called.
037:             * 
038:             * @param component
039:             *            Menu, menuitem, button or checkbox to handle
040:             * @param text
041:             *            Displaytext, possibly including & for mnemonic specification
042:             */
043:            public static void setTextWithMnemonic(AbstractButton component,
044:                    String text) {
045:                // search for mnemonic
046:                int index = text.indexOf("&");
047:
048:                if ((index != -1) && ((index + 1) < text.length())) {
049:                    // mnemonic found
050:                    // ...and not at the end of the string (which doesn't make sence)
051:                    char mnemonic = text.charAt(index + 1);
052:
053:                    StringBuffer buf = new StringBuffer();
054:
055:                    // if mnemonic is first character of this string
056:                    if (index == 0) {
057:                        buf.append(text.substring(1));
058:                    } else {
059:                        buf.append(text.substring(0, index));
060:                        buf.append(text.substring(index + 1));
061:                    }
062:
063:                    // set display text
064:                    component.setText(buf.toString());
065:
066:                    // set mnemonic
067:                    component.setMnemonic(mnemonic);
068:                    component.setDisplayedMnemonicIndex(index);
069:                } else {
070:                    // no mnemonic found - just set the text on the menu item
071:                    component.setText(text);
072:                }
073:            }
074:
075:            /**
076:             * Sets the text of a label including mnemonic. <br>
077:             * Same functionality as
078:             * 
079:             * @see setTextWithMnemonic
080:             * 
081:             * @param label
082:             *            Label to handle
083:             * @param text
084:             *            Displaytext, possibly including & for mnemonic specification
085:             */
086:            public static void setTextWithMnemonic(JLabel label, String text) {
087:                // search for mnemonic
088:                int index = text.indexOf("&");
089:
090:                if ((index != -1) && ((index + 1) < text.length())) {
091:                    // mnemonic found
092:                    // ...and not at the end of the string (which doesn't make sence)
093:                    char mnemonic = text.charAt(index + 1);
094:
095:                    StringBuffer buf = new StringBuffer();
096:
097:                    // if mnemonic is first character of this string
098:                    if (index == 0) {
099:                        buf.append(text.substring(1));
100:                    } else {
101:                        buf.append(text.substring(0, index));
102:                        buf.append(text.substring(index + 1));
103:                    }
104:
105:                    // set display text
106:                    label.setText(buf.toString());
107:
108:                    // set mnemonic
109:                    label.setDisplayedMnemonic(mnemonic);
110:                    label.setDisplayedMnemonicIndex(index);
111:                } else {
112:                    // no mnemonic found - just set the text on the menu item
113:                    label.setText(text);
114:                }
115:            }
116:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.